Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1162961imm; Fri, 28 Sep 2018 13:09:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV62iZCMVuRawAU9mEYVX3P5S6JrEH7t3+g1UCovhlC2tOl4ZBMGziV0wUY/ZyWWj/aZMi5MU X-Received: by 2002:a62:1dc2:: with SMTP id d185-v6mr148540pfd.219.1538165392940; Fri, 28 Sep 2018 13:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538165392; cv=none; d=google.com; s=arc-20160816; b=LrI8Cou4o7cV2uCGAsXASlJ9V1ok/xRQXFbyJQldTLxpNExqbZW9xkaHJbGKiO1s/n yyypyKAGktwt1FYMK7+RfDJiZ9+4JFIhB77ebB1LaUzdWYe1fOE9Q58534CKCCkQZtRt qnzI6Fr/uV17pfYGWR73vftTn3Xirb+jlltZmBYMQSpIRTjnr4DqsyjAZBEKUcrWBODT xL+wbbtYsh2w95AErv2j+254gX0guqiu8kCLF6LzH2DeGGfpZy16PWxHlX/0img6POvY i6ncaw+wcTB4bFU2/ApAnn4FPQPmvVaKvKrV/DxZ5TJlNoApYvrNkFrpnsh78EsIe2cV 2cVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:content-language:in-reply-to :user-agent:content-transfer-encoding:mime-version:references :message-id:lines:date:subject:from:to; bh=n+3Rk+UYwaASXOgUiBKyc9xr1KIVO9+e0SuvE5Th8Rs=; b=PRPAFWFrAqS9ybmYh3nL2JCp1fnBxKTauwgr6b7hgcXJys+IvzLd+6lJFugyyddf3G QE8fVtoQX4FJSdAZh+gaHrF1m+Ax+C1p2nH88qR94a3s5Rth0pyJCESbE1RjNtrJVgRg YBSGVui4bRK/lBzwgHBY1Ak/Tc2I/9v8hYHik6hwAhXPdRwLkwjq6lbdjY6QhG+N6VPa aDBInoVffkFYko/QkaJgdd1BIoekyJ5JXx5R2ey3Le+oaZiWY/GtHB4p7FYElLmQ/aHO xBN6d4nK6N5BBk76Rj645NFQL2gTK6+EwC3gaXSJ7G2PhrQB38XgLwEIsC6UZMzl22Wu IAYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si6296968pln.137.2018.09.28.13.09.37; Fri, 28 Sep 2018 13:09:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbeI2Ces (ORCPT + 99 others); Fri, 28 Sep 2018 22:34:48 -0400 Received: from [195.159.176.226] ([195.159.176.226]:41437 "EHLO blaine.gmane.org" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1726496AbeI2Ces (ORCPT ); Fri, 28 Sep 2018 22:34:48 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1g5z2g-0002Mf-AM for linux-kernel@vger.kernel.org; Fri, 28 Sep 2018 22:07:14 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: linux-kernel@vger.kernel.org From: Dmitry Osipenko Subject: Re: [PATCH] regulator: core: Pass max_uV value to regulator_set_voltage_rdev Date: Fri, 28 Sep 2018 23:09:17 +0300 Lines: 143 Message-ID: <95655644-ef41-f5bd-7e8e-a257d48cd020@gmail.com> References: <20180615112916.GK112168@atomide.com> <1529330913-11152-1-git-send-email-m.purski@samsung.com> <20180702080505.GN112168@atomide.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@blaine.gmane.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 In-Reply-To: <20180702080505.GN112168@atomide.com> Content-Language: en-US Cc: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/2/18 11:05 AM, Tony Lindgren wrote: > * Maciej Purski [180618 14:11]: >> If the regulator is not coupled, balance_voltage() should preserve >> its desired max uV, instead of setting the exact value like in >> coupled regulators case. >> >> Remove debugs, which are not necessary for now. > > Sorry for the delay in testing. I gave your series with this one > a quick boot test on beagleboard-x15 and now the output is > different. So instead of just hanging it seems to be stuck in > some eternal loop see below. Hello guys, I'm working on the CPUFreq driver for NVIDIA Tegra and it requires the coupled-regulators functionality, hence I'm interested in getting the coupled regulators series finalized ASAP and want to help with it. It looks to me that the infinite-loop problem is caused by the voltage value that is getting rounded-up by the driver because it isn't aligned to the uV_step. IIUC, uV_step is relevant only for the "linear" regulators and hence we can't simply set the best_delta to uV_step to solve the problem. Other solution could be to bail out of the loop once regulator sets value equal to the "desired". Tony, could you please give a try to the patch below? Do the following: 1) git cherry-pick 696861761a58d8c93605b5663824929fb6540f16 2) git cherry-pick 456e7cdf3b1a14e2606b8b687385ab2e3f23a49a 3) Apply this patch: From 7928aecb3af9d367dd3c085972349aaa16318c1b Mon Sep 17 00:00:00 2001 From: Dmitry Osipenko Date: Fri, 28 Sep 2018 21:49:20 +0300 Subject: [PATCH] Fixup regulator_balance_voltage() --- drivers/regulator/core.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 282511508698..4a386fe9f26a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -3187,7 +3187,8 @@ static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, return ret; } -static int regulator_get_optimal_voltage(struct regulator_dev *rdev) +static int regulator_get_optimal_voltage(struct regulator_dev *rdev, + int *min_uV, int *max_uV) { struct coupling_desc *c_desc = &rdev->coupling_desc; struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; @@ -3211,7 +3212,9 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev) * by consumers. */ if (n_coupled == 1) { - ret = desired_min_uV; + *min_uV = desired_min_uV; + *max_uV = desired_max_uV; + ret = 1; goto out; } @@ -3285,8 +3288,10 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev) ret = -EINVAL; goto out; } - ret = possible_uV; + ret = (possible_uV == desired_min_uV); + *min_uV = possible_uV; + *max_uV = desired_max_uV; out: return ret; } @@ -3298,7 +3303,8 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, struct regulator_dev *best_rdev; struct coupling_desc *c_desc = &rdev->coupling_desc; int n_coupled; - int i, best_delta, best_uV, ret = 1; + int i, best_delta, best_min_uV, best_max_uV, ret = 1; + bool last = false; c_rdevs = c_desc->coupled_rdevs; n_coupled = c_desc->n_coupled; @@ -3314,9 +3320,10 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, * Find the best possible voltage change on each loop. Leave the loop * if there isn't any possible change. */ - while (1) { + while (!last) { best_delta = 0; - best_uV = 0; + best_min_uV = 0; + best_max_uV = 0; best_rdev = NULL; /* @@ -3330,24 +3337,26 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, * max_spread constraint in order to balance * the coupled voltages. */ - int optimal_uV, current_uV; + int optimal_uV, optimal_max_uV, current_uV; - optimal_uV = regulator_get_optimal_voltage(c_rdevs[i]); - if (optimal_uV < 0) { - ret = optimal_uV; + ret = regulator_get_optimal_voltage(c_rdevs[i], + &optimal_uV, + &optimal_max_uV); + if (ret < 0) goto out; - } current_uV = _regulator_get_voltage(c_rdevs[i]); if (current_uV < 0) { - ret = optimal_uV; + ret = current_uV; goto out; } if (abs(best_delta) < abs(optimal_uV - current_uV)) { best_delta = optimal_uV - current_uV; best_rdev = c_rdevs[i]; - best_uV = optimal_uV; + best_min_uV = optimal_uV; + best_max_uV = optimal_max_uV; + last = (best_rdev == rdev && ret > 0); } } @@ -3357,8 +3366,8 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, goto out; } - ret = regulator_set_voltage_rdev(best_rdev, best_uV, - best_uV, state); + ret = regulator_set_voltage_rdev(best_rdev, best_min_uV, + best_max_uV, state); if (ret < 0) goto out; -- 2.19.0