Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1317516imm; Fri, 28 Sep 2018 16:18:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV622SVrTU/zkZlGelJ/7x0j+QtGzZGI/I4/gD7cx+ntbflHRQnXEKaT83hYHvMeyUOVrJNAa X-Received: by 2002:a62:c186:: with SMTP id i128-v6mr727923pfg.248.1538176700549; Fri, 28 Sep 2018 16:18:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538176700; cv=none; d=google.com; s=arc-20160816; b=qrUqHjghfWPrxZMKRF1AhKglfvlY9gfydT7VbvBXkKJEvEUAB/DyZVOw2G8ThSiGWA ZtIr3FXi4+10vQf22S7Krmma8LUqYobQZuiUVBnmAU2DFQ5Sj6BXsgqJOOAwDoftn6TX 5uCq5dUFAFSKUEl+4qBCjiGrKv/2UMpI+FUSnpd6gGGxfjyESM5IJ6wNB1B/oTIvrK0n ULByJweTeod7ThpFgBVl5Po+/NF/yp+3Q4Sl5odXZgrZip0k7j68o7jlMrX+M7q3NDS1 MSXZZVLANm1o8mI044EKj4CU4FNUYjjPrfHvy/adzKWruUP2UpTwW3zrn7YC6cns3Kmn fuLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=WWWKJ1zlBbt4lU1sunTBciSft97pJ2WUkNeHtfMiXu0=; b=sDpzJsU420mRCUmlUQTDOc06czYv0Z0kDJJx+NH2oiuh/RKhM2BVdPp3r7oSGfNMo5 BWI+DuZDN6X9UD0e4FjVEwWlxaNFdfbzCmhervrJ9x1BAm+YyXUojiC3SCza/S1sjfB0 a6JmuCmhMIQhaTczuoX4qoXxotI+BHKnHfanZLYH1MMHt7b1qVsAShw0ZDUkWlcQfYq5 SSU7pHkDYuLFaNMumrhZBiEfJ9n+yG9DTagMFzAFcoil76eRjMTgKksBEJpWlFlwRCvY 58xCxNkxuNh0mLWbR9LjHcgWlYnjXjUaL9n9VrPxs2Z67qfyiCVLX/sW56cFEDdypozY Uk9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k+jxCCgi; 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=pass (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 p14-v6si5805183plo.363.2018.09.28.16.17.44; Fri, 28 Sep 2018 16:18:20 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k+jxCCgi; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbeI2Fnk (ORCPT + 99 others); Sat, 29 Sep 2018 01:43:40 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:38835 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726492AbeI2Fnk (ORCPT ); Sat, 29 Sep 2018 01:43:40 -0400 Received: by mail-lf1-f68.google.com with SMTP id g89-v6so6149137lfl.5; Fri, 28 Sep 2018 16:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=WWWKJ1zlBbt4lU1sunTBciSft97pJ2WUkNeHtfMiXu0=; b=k+jxCCgiAzV4yJN89AHry7Ebjs6vHKKOWRKS9gU8yAWLkAkd5rSJOf8NizMVGSOGT1 bxBXqub8gu/LGHZs9od/KxCTDNO85YefCdHXLRJJaSwFDSIa6TKJHG3AJqKxOBHy/8DM mQHLRyJ/YgfT/GAT432YT1VOHaTeA1hwy20wNthBhQrcUOLDL+FHJgXs1MSXd8QtNwmp 9s9RP1WSs7l27OHq5lZ28hZiMvLujQT/pkgxGuZ9TCnzR6HnugCvaaw7XdJI/r86sdX7 ZoZTVWiPiCoClcJYVGbPPy9pEZL+bkhTj26ieD6M18mfWhlbKXzDDYXbs4BjqFKrtUtH AgtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WWWKJ1zlBbt4lU1sunTBciSft97pJ2WUkNeHtfMiXu0=; b=UrZYZ2oc/FrcHqy7cUmzjbrxQUK4bRYRso9Rh41v5w2vPr86C5UWkiZ+taE2atUDk8 +zgsOkcjjg1FHmNJYHsy8jdkDItAksl1ojV/n9nLMxZSLXB5KFmRmGCzuh8zI+9ckDjp 7ZTmkhxlhzEewejg2SXh1KaRTmzLsr5tbtUDSRqkLb4dA+fm/xQjyFuY5myYgU8+6h/I PT6UPkjEs1KSXCZQo/+c0OVYPK5w+v+sF8vk3N31xFED/2RxIrRTHZsJpe/9J0EP6yHQ U1ZY9v05gxjGuHtbT9ed2yRgVqatObSg2L9c1iQEwKgGaR6kFl6Udjn8TbyK98hPV5Ki NZmA== X-Gm-Message-State: ABuFfoi8y/8ofyFZet/FVrIdVi9gstzzlQUgGySSTvABUH/ml2v8UkmS A6AYnNZ8kOHoF2aWUx9q7uo= X-Received: by 2002:a19:c44f:: with SMTP id u76-v6mr334394lff.141.1538176657621; Fri, 28 Sep 2018 16:17:37 -0700 (PDT) Received: from [192.168.2.145] ([109.252.91.213]) by smtp.googlemail.com with ESMTPSA id h27-v6sm1270761lfl.31.2018.09.28.16.17.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 16:17:36 -0700 (PDT) Subject: Re: [PATCH] regulator: core: Pass max_uV value to regulator_set_voltage_rdev To: Tony Lindgren Cc: Maciej Purski , Mark Brown , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, Carlos Hernandez , Marek Szyprowski References: <20180615112916.GK112168@atomide.com> <1529330913-11152-1-git-send-email-m.purski@samsung.com> <20180702080505.GN112168@atomide.com> <95655644-ef41-f5bd-7e8e-a257d48cd020@gmail.com> <20180928202251.GM5662@atomide.com> <2c0132ff-ea0f-f19e-ebfb-a0d077565d2c@gmail.com> <20180928224109.GS5662@atomide.com> From: Dmitry Osipenko Message-ID: Date: Sat, 29 Sep 2018 02:17:35 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180928224109.GS5662@atomide.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/29/18 1:41 AM, Tony Lindgren wrote: > * Dmitry Osipenko [180928 22:31]: >> On 9/28/18 11:22 PM, Tony Lindgren wrote: >>> * Dmitry Osipenko [180928 20:13]: >>>> 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: >>> >>> Seems to be getting closer, system boots up and starts >>> init, but then I start getting tons of this on beagle-x15: >> >> Tony, could you please try this one? Fixed couple more bugs, should be good now. > > I'm still getting these errors after init: Thank you very much again, seems I got what's wrong with your case. The ti-abb-regulator driver sets the "abb->current_info_idx = -EINVAL" on probe and that value is getting updated only after the first voltage change, hence _regulator_get_voltage() returns -22. Please try this patch: From 2f10c29547778499f614b363a7756a40099bfa5a 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() v3 --- drivers/regulator/core.c | 91 ++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 282511508698..d0edb66b37a2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -105,7 +105,7 @@ static int _notifier_call_chain(struct regulator_dev *rdev, unsigned long event, void *data); static int _regulator_do_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV); -static int regulator_balance_voltage(struct regulator_dev *rdev, +static int regulator_balance_voltage(struct regulator *regulator, suspend_state_t state); static int regulator_set_voltage_rdev(struct regulator_dev *rdev, int min_uV, int max_uV, @@ -2330,7 +2330,7 @@ int regulator_enable(struct regulator *regulator) ret = _regulator_enable(rdev); /* balance only if there are regulators coupled */ if (rdev->coupling_desc.n_coupled > 1) - regulator_balance_voltage(rdev, PM_SUSPEND_ON); + regulator_balance_voltage(regulator, PM_SUSPEND_ON); regulator_unlock_dependent(rdev); if (ret != 0 && rdev->supply) @@ -2440,7 +2440,7 @@ int regulator_disable(struct regulator *regulator) regulator_lock_dependent(rdev); ret = _regulator_disable(rdev); if (rdev->coupling_desc.n_coupled > 1) - regulator_balance_voltage(rdev, PM_SUSPEND_ON); + regulator_balance_voltage(regulator, PM_SUSPEND_ON); regulator_unlock_dependent(rdev); if (ret == 0 && rdev->supply) @@ -2494,7 +2494,7 @@ int regulator_force_disable(struct regulator *regulator) regulator->uA_load = 0; ret = _regulator_force_disable(regulator->rdev); if (rdev->coupling_desc.n_coupled > 1) - regulator_balance_voltage(rdev, PM_SUSPEND_ON); + regulator_balance_voltage(regulator, PM_SUSPEND_ON); regulator_unlock_dependent(rdev); if (rdev->supply) @@ -3099,12 +3099,8 @@ static int regulator_set_voltage_unlocked(struct regulator *regulator, voltage->min_uV = min_uV; voltage->max_uV = max_uV; - ret = regulator_check_consumers(rdev, &min_uV, &max_uV, state); - if (ret < 0) - goto out2; - /* for not coupled regulators this will just set the voltage */ - ret = regulator_balance_voltage(rdev, state); + ret = regulator_balance_voltage(regulator, state); if (ret < 0) goto out2; @@ -3187,7 +3183,10 @@ 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 *regulator, + struct regulator_dev *rdev, + int *min_uV, int *max_uV, + suspend_state_t state) { struct coupling_desc *c_desc = &rdev->coupling_desc; struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; @@ -3198,20 +3197,29 @@ static int regulator_get_optimal_voltage(struct regulator_dev *rdev) int i, ret; /* If consumers don't provide any demands, set voltage to min_uV */ - desired_min_uV = rdev->constraints->min_uV; - desired_max_uV = rdev->constraints->max_uV; - ret = regulator_check_consumers(rdev, - &desired_min_uV, - &desired_max_uV, PM_SUSPEND_ON); - if (ret < 0) - goto out; + if (regulator->rdev == rdev) { + desired_min_uV = regulator->voltage[state].min_uV; + desired_max_uV = regulator->voltage[state].max_uV; + + ret = regulator_check_consumers(rdev, + &desired_min_uV, + &desired_max_uV, + state); + if (ret < 0) + goto out; + } else { + desired_min_uV = rdev->constraints->min_uV; + desired_max_uV = rdev->constraints->max_uV; + } /* * If there are no coupled regulators, simply set the voltage demanded * by consumers. */ - if (n_coupled == 1) { - ret = desired_min_uV; + if (n_coupled == 1 || state != PM_SUSPEND_ON) { + *min_uV = desired_min_uV; + *max_uV = desired_max_uV; + ret = 1; goto out; } @@ -3285,20 +3293,24 @@ 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; } -static int regulator_balance_voltage(struct regulator_dev *rdev, +static int regulator_balance_voltage(struct regulator *regulator, suspend_state_t state) { + struct regulator_dev *rdev = regulator->rdev; struct regulator_dev **c_rdevs; 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 +3326,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 +3343,30 @@ 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 = 0; - optimal_uV = regulator_get_optimal_voltage(c_rdevs[i]); - if (optimal_uV < 0) { - ret = optimal_uV; + ret = regulator_get_optimal_voltage(regulator, + c_rdevs[i], + &optimal_uV, + &optimal_max_uV, + state); + if (ret < 0) goto out; - } - current_uV = _regulator_get_voltage(c_rdevs[i]); - if (current_uV < 0) { - ret = optimal_uV; - goto out; + if (n_coupled > 1) { + current_uV = _regulator_get_voltage(c_rdevs[i]); + if (current_uV < 0) { + 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 +3376,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