diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2010-11-10 09:38:29 -0500 |
---|---|---|
committer | Liam Girdwood <lrg@slimlogic.co.uk> | 2011-01-12 09:32:59 -0500 |
commit | 3a93f2a9f4d8f73d74c0e552feb68a10f778a219 (patch) | |
tree | 8a9f503f2f061ad3fe9712b0986b0da346f4c8d2 /drivers/regulator/max1586.c | |
parent | 63cee946148821bca42be10130b061c2d0f5af7e (diff) |
regulator: Report actual configured voltage to set_voltage()
Change the interface used by set_voltage() to report the selected value
to the regulator core in terms of a selector used by list_voltage().
This allows the regulator core to know the voltage that was chosen
without having to do an explict get_voltage(), which would be much more
expensive as it will generally access hardware.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator/max1586.c')
-rw-r--r-- | drivers/regulator/max1586.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index 559cfa271a44..3f49512c5134 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c | |||
@@ -63,12 +63,12 @@ static int max1586_v3_calc_voltage(struct max1586_data *max1586, | |||
63 | return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL); | 63 | return max1586->min_uV + (selector * range_uV / MAX1586_V3_MAX_VSEL); |
64 | } | 64 | } |
65 | 65 | ||
66 | static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV) | 66 | static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV, |
67 | unsigned *selector) | ||
67 | { | 68 | { |
68 | struct max1586_data *max1586 = rdev_get_drvdata(rdev); | 69 | struct max1586_data *max1586 = rdev_get_drvdata(rdev); |
69 | struct i2c_client *client = max1586->client; | 70 | struct i2c_client *client = max1586->client; |
70 | unsigned range_uV = max1586->max_uV - max1586->min_uV; | 71 | unsigned range_uV = max1586->max_uV - max1586->min_uV; |
71 | unsigned selector; | ||
72 | u8 v3_prog; | 72 | u8 v3_prog; |
73 | 73 | ||
74 | if (min_uV > max1586->max_uV || max_uV < max1586->min_uV) | 74 | if (min_uV > max1586->max_uV || max_uV < max1586->min_uV) |
@@ -76,15 +76,15 @@ static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV) | |||
76 | if (min_uV < max1586->min_uV) | 76 | if (min_uV < max1586->min_uV) |
77 | min_uV = max1586->min_uV; | 77 | min_uV = max1586->min_uV; |
78 | 78 | ||
79 | selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL + | 79 | *selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL + |
80 | range_uV - 1) / range_uV; | 80 | range_uV - 1) / range_uV; |
81 | if (max1586_v3_calc_voltage(max1586, selector) > max_uV) | 81 | if (max1586_v3_calc_voltage(max1586, *selector) > max_uV) |
82 | return -EINVAL; | 82 | return -EINVAL; |
83 | 83 | ||
84 | dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", | 84 | dev_dbg(&client->dev, "changing voltage v3 to %dmv\n", |
85 | max1586_v3_calc_voltage(max1586, selector) / 1000); | 85 | max1586_v3_calc_voltage(max1586, *selector) / 1000); |
86 | 86 | ||
87 | v3_prog = I2C_V3_SELECT | (u8) selector; | 87 | v3_prog = I2C_V3_SELECT | (u8) *selector; |
88 | return i2c_smbus_write_byte(client, v3_prog); | 88 | return i2c_smbus_write_byte(client, v3_prog); |
89 | } | 89 | } |
90 | 90 | ||
@@ -110,10 +110,10 @@ static int max1586_v6_calc_voltage(unsigned selector) | |||
110 | return voltages_uv[selector]; | 110 | return voltages_uv[selector]; |
111 | } | 111 | } |
112 | 112 | ||
113 | static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV) | 113 | static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV, |
114 | unsigned int *selector) | ||
114 | { | 115 | { |
115 | struct i2c_client *client = rdev_get_drvdata(rdev); | 116 | struct i2c_client *client = rdev_get_drvdata(rdev); |
116 | unsigned selector; | ||
117 | u8 v6_prog; | 117 | u8 v6_prog; |
118 | 118 | ||
119 | if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV) | 119 | if (min_uV < MAX1586_V6_MIN_UV || min_uV > MAX1586_V6_MAX_UV) |
@@ -122,21 +122,21 @@ static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV) | |||
122 | return -EINVAL; | 122 | return -EINVAL; |
123 | 123 | ||
124 | if (min_uV < 1800000) | 124 | if (min_uV < 1800000) |
125 | selector = 0; | 125 | *selector = 0; |
126 | else if (min_uV < 2500000) | 126 | else if (min_uV < 2500000) |
127 | selector = 1; | 127 | *selector = 1; |
128 | else if (min_uV < 3000000) | 128 | else if (min_uV < 3000000) |
129 | selector = 2; | 129 | *selector = 2; |
130 | else if (min_uV >= 3000000) | 130 | else if (min_uV >= 3000000) |
131 | selector = 3; | 131 | *selector = 3; |
132 | 132 | ||
133 | if (max1586_v6_calc_voltage(selector) > max_uV) | 133 | if (max1586_v6_calc_voltage(*selector) > max_uV) |
134 | return -EINVAL; | 134 | return -EINVAL; |
135 | 135 | ||
136 | dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", | 136 | dev_dbg(&client->dev, "changing voltage v6 to %dmv\n", |
137 | max1586_v6_calc_voltage(selector) / 1000); | 137 | max1586_v6_calc_voltage(*selector) / 1000); |
138 | 138 | ||
139 | v6_prog = I2C_V6_SELECT | (u8) selector; | 139 | v6_prog = I2C_V6_SELECT | (u8) *selector; |
140 | return i2c_smbus_write_byte(client, v6_prog); | 140 | return i2c_smbus_write_byte(client, v6_prog); |
141 | } | 141 | } |
142 | 142 | ||