* [PATCH RFC v2] regulator: core: Add regulator_map_voltage_ascend() API
@ 2013-04-18 2:34 Axel Lin
2013-04-18 11:15 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2013-04-18 2:34 UTC (permalink / raw)
To: Mark Brown; +Cc: Liam Girdwood, linux-kernel
A lot of regulator hardware has ascendant voltage list.
This patch adds regulator_map_voltage_ascend() and export it.
Drivers that have ascendant voltage list can use this as their map_voltage()
operation, this is more efficient than default regulator_map_voltage_iterate()
function.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
v2:
Since the voltage list is in ascendant order, and we iterate the list from the
smallest voltage. So it is safe to break out if the voltage is greater than max_uV.
drivers/regulator/core.c | 31 +++++++++++++++++++++++++++++++
include/linux/regulator/driver.h | 2 ++
2 files changed, 33 insertions(+)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 23df943..944d172 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2265,6 +2265,37 @@ int regulator_map_voltage_iterate(struct regulator_dev *rdev,
EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
/**
+ * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
+ *
+ * @rdev: Regulator to operate on
+ * @min_uV: Lower bound for voltage
+ * @max_uV: Upper bound for voltage
+ *
+ * Drivers that have ascendant voltage list can use this as their
+ * map_voltage() operation.
+ */
+int regulator_map_voltage_ascend(struct regulator_dev *rdev,
+ int min_uV, int max_uV)
+{
+ int i, ret;
+
+ for (i = 0; i < rdev->desc->n_voltages; i++) {
+ ret = rdev->desc->ops->list_voltage(rdev, i);
+ if (ret < 0)
+ continue;
+
+ if (ret > max_uV)
+ break;
+
+ if (ret >= min_uV && ret <= max_uV)
+ return i;
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
+
+/**
* regulator_map_voltage_linear - map_voltage() for simple linear mappings
*
* @rdev: Regulator to operate on
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 5e2d13d..6700cc9 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -332,6 +332,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
int min_uV, int max_uV);
int regulator_map_voltage_iterate(struct regulator_dev *rdev,
int min_uV, int max_uV);
+int regulator_map_voltage_ascend(struct regulator_dev *rdev,
+ int min_uV, int max_uV);
int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
int regulator_is_enabled_regmap(struct regulator_dev *rdev);
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RFC v2] regulator: core: Add regulator_map_voltage_ascend() API
2013-04-18 2:34 [PATCH RFC v2] regulator: core: Add regulator_map_voltage_ascend() API Axel Lin
@ 2013-04-18 11:15 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2013-04-18 11:15 UTC (permalink / raw)
To: Axel Lin; +Cc: Liam Girdwood, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 676 bytes --]
On Thu, Apr 18, 2013 at 10:34:49AM +0800, Axel Lin wrote:
> A lot of regulator hardware has ascendant voltage list.
> This patch adds regulator_map_voltage_ascend() and export it.
>
> Drivers that have ascendant voltage list can use this as their map_voltage()
> operation, this is more efficient than default regulator_map_voltage_iterate()
> function.
I've applied this since it's a good API to have and it'll let people
build drivers on it. It does seem like if we know the list is sorted we
ought to be able to take advantage of that to do better than a linear
scan. Not sure it's worth bothering though as these tend not to have
that many values to map.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-04-18 11:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-18 2:34 [PATCH RFC v2] regulator: core: Add regulator_map_voltage_ascend() API Axel Lin
2013-04-18 11:15 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox