Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751687AbdISOgC (ORCPT ); Tue, 19 Sep 2017 10:36:02 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:55967 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751165AbdISOf7 (ORCPT ); Tue, 19 Sep 2017 10:35:59 -0400 X-AuditID: cbfec7f4-f79ab6d000003290-96-59c12b4c240d Subject: Re: [PATCH 1/2] regulator: core: Add coupled regulators mechanism To: Mark Brown Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Liam Girdwood , Rob Herring , Mark Rutland , Marek Szyprowski , Bartlomiej Zolnierkiewicz From: Maciej Purski Message-id: <8ac4fa17-43ed-7a4d-d086-6ad81d97900e@samsung.com> Date: Tue, 19 Sep 2017 16:35:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-version: 1.0 In-reply-to: <20170919130944.ldoskrm54tx2oemd@sirena.co.uk> Content-type: text/plain; charset="windows-1252"; format="flowed" Content-transfer-encoding: 7bit Content-language: en-US X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrEKsWRmVeSWpSXmKPExsWy7djPc7o+2gcjDZb+57XYOGM9q8XUh0/Y LOYfOcdq8e1KB5PF5V1z2CzWHrnLbrH0+kUmi9a9R9gdODzWzFvD6LFz1l12j02rOtk8+ras YvT4vEkugDWKyyYlNSezLLVI3y6BK2NS42mmgjOKFT+f3mZtYPwq1cXIwSEhYCLx4W1sFyMn kCkmceHeerYuRi4OIYGljBJ715xihHA+M0qcnzOdCaLKROLFzLvMEIlljBKvHu6BannGKLFq 4hZ2kCphAS+JXW97WEBsEQFliavf97KAFDELTGSSuPBnMRPIbjYBLYk17fEgNbwCdhLf1n9i BrFZBFQlXjw+yghiiwpESGz7PoMNokZQ4sfke2AzOQWsJRa97wPbxSzgKPFg0U5WCFteYvOa t8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sdjBTiTUmsrEotyo8vKs1JLT7EKM3BoiTO27tndaSQQHpi SWp2ampBahFMlomDU6qBMaxeZP3DyY+7e52u3F/JeHgi21HO45ZVsr1s3tE5v/o23OZb91zJ +g77Tt+w+i0WrSrztjPJzD+71m/acbVzbodYah5xmfAdeir1MvWIVPPVSfqPD3b9Mrn8cIcG R49P6YS+aYkuYam1uRZbA2o+3v+7Sepxs+W2tXai8scvM+ksktg6o8WxXomlOCPRUIu5qDgR AJ9LFJiMAgAA X-CMS-MailID: 20170919143555eucas1p2b4d241e4240cd46d1deef6dabcedc9fd X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Global-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTU=?= CMS-TYPE: 201P X-CMS-RootMailID: 20170918084022eucas1p1398f18c5c90535ce484e3952fae80882 X-RootMTR: 20170918084022eucas1p1398f18c5c90535ce484e3952fae80882 References: <1505723992-11772-1-git-send-email-m.purski@samsung.com> <1505723992-11772-2-git-send-email-m.purski@samsung.com> <20170919130944.ldoskrm54tx2oemd@sirena.co.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4202 Lines: 96 On 09/19/2017 03:09 PM, Mark Brown wrote: > On Mon, Sep 18, 2017 at 10:39:51AM +0200, Maciej Purski wrote: >> On Odroid XU3/4 and other Exynos5422 based boards there is a case, that >> different devices on the board are supplied by different regulators >> with non-fixed voltages. If one of these devices temporarily requires >> higher voltage, there might occur a situation that the spread between >> two devices' voltages is so high, that there is a risk of changing >> 'high' and 'low' states on the interconnection between devices powered >> by those two regulators. >> >> Keeping spread between those voltages below defined max_spread should >> be handled by the framework. Information required to do so is obtained >> from the device tree. On each voltage change the core should find the >> best voltages which suit all consumers' demands and max_spread. >> Then set them for a coupled regulator also. > This leads me none the wiser as to how this will be implemented which > makes this rather hard to review, especially since this appears to have > a lot of random refactoring mixed in with it. Sorry. I'll document it better in the next version. > >> +static int regulator_set_voltage_safe(struct regulator_dev *rdev, >> + int min_uV, int max_uV); > Why would we want a way to set voltages that isn't safe? This function is extracted from original regulator_set_voltage_unlocked(). It contains code responsible for calling do_set_voltage on the given regulator and its ancestors (if needed). This function is called both from regulator_set_voltage_unlocked(), from where it was extracted and from my new function regulator_set_coupled_voltage(). I added this in order to avoid code duplication. I agree that the name might not be adequate. What name would you find more suitable? > >> @@ -2181,6 +2183,8 @@ static int _regulator_enable(struct regulator_dev *rdev) >> /* Fallthrough on positive return values - already enabled */ >> } >> >> + if (rdev->coupled_desc) >> + rdev->coupled_desc->enable_count++; >> rdev->use_count++; >> >> return 0; > There's no locking here, and we appear to take no action when these > counts change - do we need to bother with this at all? Variable enable_count is used for checking if both regulators are enabled and there's a need for using the coupling mechanism. It is checked in regulator_set_coupled_voltage_unlocked(), where the mutex is already locked. I think that locking it here would be useful. Thanks. > >> + /* check if changing voltage won't interfere with other >> + * consumers' demands >> + */ >> ret = regulator_check_consumers(rdev, &min_uV, &max_uV); >> if (ret < 0) >> goto out2; > These extra comments that are being added are pretty much all readouts > of the name of the function that's being called (and many of them are > misformatted)... > >> +static int regulator_set_voltage_safe(struct regulator_dev *rdev, int min_uV, >> + int max_uV) >> +{ > ...which is a bit ironic given that this isn't documented at all :/ Everything will be documented better in the next version. > >> +static int regulator_set_coupled_voltage(struct coupled_reg_desc *c_desc) >> +{ >> + struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; >> + int max_spread = c_desc->max_spread; >> + int best_volt[2] = { }; >> + int actual_volt[2]; >> + int min_volt, max_volt; >> + int ret = 0, i, max; >> + int ready = 0; >> + >> + /* Get voltages desired by all consumers of the coupled regulator */ >> + for (i = 0; i < 2; i++) { > It appears we can't couple more than two regulators? We can couple just two regulators. We have never found any case for coupling more than two regulators. Limiting the mechanism to just two regulators simplifies algorithm a little bit. Would you prefer it working for more than two regulators also even if there isn't any use case? > >> + max_volt = max(best_volt[0], best_volt[1]); >> + min_volt = min(best_volt[0], best_volt[1]); > So the maximum and minimum are the *least* constrained? > >> + max_possible = actual_volt[(i + 1) % 2] + max_spread; >> + min_possible = actual_volt[(i + 1) % 2] - max_spread; > I'm lost, this magic array indexing is just illegible.