Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1412106 > unrolled thread

[RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range

Started bySrinivas Kandagatla <srinivas.kandagatla@linaro.org>
First post2016-06-02 12:30 +0200
Last post2016-06-02 14:00 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2016-06-02 12:30 +0200
    Re: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in  list_voltage_linear_range Mark Brown <broonie@kernel.org> - 2016-06-02 13:10 +0200
      Re: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in  list_voltage_linear_range Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2016-06-02 14:00 +0200

#1412106 — [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range

FromSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Date2016-06-02 12:30 +0200
Subject[RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range
Message-ID<rFy2Z-4Jw-15@gated-at.bofh.it>
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 <srinivas.kandagatla@linaro.org>
---

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 <linux/delay.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
+#include <linux/regulator/machine.h>
 #include <linux/regulator/driver.h>
 #include <linux/module.h>

@@ -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

[toc] | [next] | [standalone]


#1412132 — Re: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range

FromMark Brown <broonie@kernel.org>
Date2016-06-02 13:10 +0200
SubjectRe: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range
Message-ID<rFyFI-5bR-29@gated-at.bofh.it>
In reply to#1412106

[Multipart message — attachments visible in raw view] — view raw

On Thu, Jun 02, 2016 at 11:23:14AM +0100, Srinivas Kandagatla wrote:
> 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.

...

> 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.

Why are you making this change?  The obvious problem here is that drivers
should not be looking at constraints - it would be silly to duplicate
constraint enforcing code in individual drivers and would lead to
inconsistent performance of constraints.  This is why we do this in the
core, in _regulator_list_voltage(), which means that if this change has
any effect there's something else going on that needs to be
investigated.

[toc] | [prev] | [next] | [standalone]


#1412159 — Re: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range

FromSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Date2016-06-02 14:00 +0200
SubjectRe: [RFC PATCH v1 1/3] regulator: helpers: consider constriants in list_voltage_linear_range
Message-ID<rFzs6-5tU-25@gated-at.bofh.it>
In reply to#1412132

On 02/06/16 12:05, Mark Brown wrote:
> On Thu, Jun 02, 2016 at 11:23:14AM +0100, Srinivas Kandagatla wrote:
>> 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.
>
> ...
>
>> 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.
>
> Why are you making this change?  The obvious problem here is that drivers
> should not be looking at constraints - it would be silly to duplicate
> constraint enforcing code in individual drivers and would lead to
> inconsistent performance of constraints.  This is why we do this in the
> core, in _regulator_list_voltage(),
Yep, you are right, I should have looked into _regulator_list_voltage() 
in more carefully, it already has this check in place.

--srini

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web