From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753046AbcHUDHW (ORCPT ); Sat, 20 Aug 2016 23:07:22 -0400 Received: from mirror2.csie.ntu.edu.tw ([140.112.30.76]:48402 "EHLO wens.csie.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752269AbcHUDHU (ORCPT ); Sat, 20 Aug 2016 23:07:20 -0400 From: Chen-Yu Tsai To: Lee Jones , Rob Herring , Mark Rutland , Liam Girdwood , Mark Brown , Maxime Ripard Cc: Chen-Yu Tsai , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com Subject: [PATCH 3/9] regulator: core: Try full range when adjusting regulators to constraints Date: Sun, 21 Aug 2016 10:11:19 +0800 Message-Id: <20160821021125.1521-4-wens@csie.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160821021125.1521-1-wens@csie.org> References: <20160821021125.1521-1-wens@csie.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently when we try to bring regulator in bounds of its constraints, we pick either the minimum or maximum voltage as the target. This fails if the regulator range is not continuous, and the target voltage is not an exact value the regulator can achieve, i.e. the target is not aligned to the step of the regulator. Instead pass the full range of the constraints, and have the regulator core work out a suitable voltage within. Fixes: ("regulator: core: Ensure we are at least in bounds for our constraints") Signed-off-by: Chen-Yu Tsai --- drivers/regulator/core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index db320e8fa865..86f69c92ce7a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -897,13 +897,9 @@ static int machine_constraints_voltage(struct regulator_dev *rdev, target_min = current_uV; target_max = current_uV; - if (current_uV < rdev->constraints->min_uV) { + if (current_uV < rdev->constraints->min_uV || + current_uV > rdev->constraints->max_uV) { target_min = rdev->constraints->min_uV; - target_max = rdev->constraints->min_uV; - } - - if (current_uV > rdev->constraints->max_uV) { - target_min = rdev->constraints->max_uV; target_max = rdev->constraints->max_uV; } -- 2.9.3