aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2012-11-26 21:24:33 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-11-27 15:07:40 -0500
commit33234e791de2ac3ea915158e042907748191cabd (patch)
treed1e0da62abf0a744526457e434b23456e8ea4be5
parent9489e9dcae718d5fde988e4a684a0f55b5f94d17 (diff)
regulator: core: Allow specific minimal selector for starting linear mapping
Some drivers (at least 3 drivers) have such variant of linear mapping that the first few selectors are invalid and the reset are linear mapping. Let's support this case in core. This patch adds linear_min_sel in struct regulator_desc, so we can allow specific minimal selector for starting linear mapping. Then extends regulator_[map|list]_voltage_linear() to support this feature. Note that for selectors less than min_linear_index, we need count them to n_voltages so regulator_list_voltage() won't fail while checking the boundary for selector before calling list_voltage callback. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--drivers/regulator/core.c6
-rw-r--r--include/linux/regulator/driver.h2
2 files changed, 8 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e872c8be080e..02a249b024b3 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1897,6 +1897,10 @@ int regulator_list_voltage_linear(struct regulator_dev *rdev,
1897{ 1897{
1898 if (selector >= rdev->desc->n_voltages) 1898 if (selector >= rdev->desc->n_voltages)
1899 return -EINVAL; 1899 return -EINVAL;
1900 if (selector < rdev->desc->linear_min_sel)
1901 return 0;
1902
1903 selector -= rdev->desc->linear_min_sel;
1900 1904
1901 return rdev->desc->min_uV + (rdev->desc->uV_step * selector); 1905 return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
1902} 1906}
@@ -2120,6 +2124,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
2120 if (ret < 0) 2124 if (ret < 0)
2121 return ret; 2125 return ret;
2122 2126
2127 ret += rdev->desc->linear_min_sel;
2128
2123 /* Map back into a voltage to verify we're still in bounds */ 2129 /* Map back into a voltage to verify we're still in bounds */
2124 voltage = rdev->desc->ops->list_voltage(rdev, ret); 2130 voltage = rdev->desc->ops->list_voltage(rdev, ret);
2125 if (voltage < min_uV || voltage > max_uV) 2131 if (voltage < min_uV || voltage > max_uV)
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index 7932a3bf21bd..d9ce98a5028b 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -185,6 +185,7 @@ enum regulator_type {
185 * 185 *
186 * @min_uV: Voltage given by the lowest selector (if linear mapping) 186 * @min_uV: Voltage given by the lowest selector (if linear mapping)
187 * @uV_step: Voltage increase with each selector (if linear mapping) 187 * @uV_step: Voltage increase with each selector (if linear mapping)
188 * @linear_min_sel: Minimal selector for starting linear mapping
188 * @ramp_delay: Time to settle down after voltage change (unit: uV/us) 189 * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
189 * @volt_table: Voltage mapping table (if table based mapping) 190 * @volt_table: Voltage mapping table (if table based mapping)
190 * 191 *
@@ -207,6 +208,7 @@ struct regulator_desc {
207 208
208 unsigned int min_uV; 209 unsigned int min_uV;
209 unsigned int uV_step; 210 unsigned int uV_step;
211 unsigned int linear_min_sel;
210 unsigned int ramp_delay; 212 unsigned int ramp_delay;
211 213
212 const unsigned int *volt_table; 214 const unsigned int *volt_table;