From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932529AbcFBKY3 (ORCPT ); Thu, 2 Jun 2016 06:24:29 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:35787 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751232AbcFBKXo (ORCPT ); Thu, 2 Jun 2016 06:23:44 -0400 From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, Mark Brown Cc: linux-kernel@vger.kernel.org, Liam Girdwood , linux-arm-msm@vger.kernel.org, Srinivas Kandagatla Subject: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range Date: Thu, 2 Jun 2016 11:23:14 +0100 Message-Id: <1464862996-3147-2-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1464862996-3147-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1464862996-3147-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Regulator drivers can have linear range which is according to the regualtor hardware spec, however the board level device tree files can restrict this range by adding constriants. These constriants are not considered in the exsiting code, which gives false supported voltage range to the consumers. Fix this by adding constriants check in the helper function. Signed-off-by: Srinivas Kandagatla --- For now I have added this support for regulator_list_voltage_linear_range() If it makes sense we can extend this to other list voltage helpers too. drivers/regulator/helpers.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index bcf38fd..379b2b3 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -374,7 +375,7 @@ int regulator_list_voltage_linear_range(struct regulator_dev *rdev, unsigned int selector) { const struct regulator_linear_range *range; - int i; + int i, v; if (!rdev->desc->n_linear_ranges) { BUG_ON(!rdev->desc->n_linear_ranges); @@ -389,8 +390,13 @@ int regulator_list_voltage_linear_range(struct regulator_dev *rdev, continue; selector -= range->min_sel; + v = range->min_uV + (range->uV_step * selector); - return range->min_uV + (range->uV_step * selector); + if (v < rdev->constraints->min_uV || + v > rdev->constraints->max_uV) + return -EINVAL; + else + return v; } return -EINVAL; -- 2.8.2