aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/max8660.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-05-15 09:43:29 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-05-15 13:35:42 -0400
commit5eb3394f86cda9fc2e66df79ff19086552f0d83e (patch)
treea1a732842197d1955e32435ac8eab2fdacf9eb9a /drivers/regulator/max8660.c
parent9392c4f06ad81b3fe8c3af0027c337e4222e73db (diff)
regulator: max8660: Convert to set_voltage_sel and regulator_map_voltage_linear
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/max8660.c')
-rw-r--r--drivers/regulator/max8660.c71
1 files changed, 15 insertions, 56 deletions
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index 93bcfc8d58ee..8d531742f593 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -135,27 +135,13 @@ static int max8660_dcdc_get_voltage_sel(struct regulator_dev *rdev)
135 return selector; 135 return selector;
136} 136}
137 137
138static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV, 138static int max8660_dcdc_set_voltage_sel(struct regulator_dev *rdev,
139 unsigned int *s) 139 unsigned int selector)
140{ 140{
141 struct max8660 *max8660 = rdev_get_drvdata(rdev); 141 struct max8660 *max8660 = rdev_get_drvdata(rdev);
142 u8 reg, selector, bits; 142 u8 reg, bits;
143 int ret; 143 int ret;
144 144
145 if (min_uV < MAX8660_DCDC_MIN_UV || min_uV > MAX8660_DCDC_MAX_UV)
146 return -EINVAL;
147 if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV)
148 return -EINVAL;
149
150 selector = DIV_ROUND_UP(min_uV - MAX8660_DCDC_MIN_UV,
151 MAX8660_DCDC_STEP);
152
153 ret = regulator_list_voltage_linear(rdev, selector);
154 if (ret < 0 || ret > max_uV)
155 return -EINVAL;
156
157 *s = selector;
158
159 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; 145 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
160 ret = max8660_write(max8660, reg, 0, selector); 146 ret = max8660_write(max8660, reg, 0, selector);
161 if (ret) 147 if (ret)
@@ -169,7 +155,8 @@ static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV,
169static struct regulator_ops max8660_dcdc_ops = { 155static struct regulator_ops max8660_dcdc_ops = {
170 .is_enabled = max8660_dcdc_is_enabled, 156 .is_enabled = max8660_dcdc_is_enabled,
171 .list_voltage = regulator_list_voltage_linear, 157 .list_voltage = regulator_list_voltage_linear,
172 .set_voltage = max8660_dcdc_set, 158 .map_voltage = regulator_map_voltage_linear,
159 .set_voltage_sel = max8660_dcdc_set_voltage_sel,
173 .get_voltage_sel = max8660_dcdc_get_voltage_sel, 160 .get_voltage_sel = max8660_dcdc_get_voltage_sel,
174}; 161};
175 162
@@ -186,27 +173,12 @@ static int max8660_ldo5_get_voltage_sel(struct regulator_dev *rdev)
186 return selector; 173 return selector;
187} 174}
188 175
189static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV, 176static int max8660_ldo5_set_voltage_sel(struct regulator_dev *rdev,
190 unsigned int *s) 177 unsigned int selector)
191{ 178{
192 struct max8660 *max8660 = rdev_get_drvdata(rdev); 179 struct max8660 *max8660 = rdev_get_drvdata(rdev);
193 u8 selector;
194 int ret; 180 int ret;
195 181
196 if (min_uV < MAX8660_LDO5_MIN_UV || min_uV > MAX8660_LDO5_MAX_UV)
197 return -EINVAL;
198 if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV)
199 return -EINVAL;
200
201 selector = DIV_ROUND_UP(min_uV - MAX8660_LDO5_MIN_UV,
202 MAX8660_LDO5_STEP);
203
204 ret = regulator_list_voltage_linear(rdev, selector);
205 if (ret < 0 || ret > max_uV)
206 return -EINVAL;
207
208 *s = selector;
209
210 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector); 182 ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector);
211 if (ret) 183 if (ret)
212 return ret; 184 return ret;
@@ -217,7 +189,8 @@ static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV,
217 189
218static struct regulator_ops max8660_ldo5_ops = { 190static struct regulator_ops max8660_ldo5_ops = {
219 .list_voltage = regulator_list_voltage_linear, 191 .list_voltage = regulator_list_voltage_linear,
220 .set_voltage = max8660_ldo5_set, 192 .map_voltage = regulator_map_voltage_linear,
193 .set_voltage_sel = max8660_ldo5_set_voltage_sel,
221 .get_voltage_sel = max8660_ldo5_get_voltage_sel, 194 .get_voltage_sel = max8660_ldo5_get_voltage_sel,
222}; 195};
223 196
@@ -257,31 +230,16 @@ static int max8660_ldo67_get_voltage_sel(struct regulator_dev *rdev)
257 return selector; 230 return selector;
258} 231}
259 232
260static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, 233static int max8660_ldo67_set_voltage_sel(struct regulator_dev *rdev,
261 int max_uV, unsigned int *s) 234 unsigned int selector)
262{ 235{
263 struct max8660 *max8660 = rdev_get_drvdata(rdev); 236 struct max8660 *max8660 = rdev_get_drvdata(rdev);
264 u8 selector;
265 int ret;
266
267 if (min_uV < MAX8660_LDO67_MIN_UV || min_uV > MAX8660_LDO67_MAX_UV)
268 return -EINVAL;
269 if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV)
270 return -EINVAL;
271
272 selector = DIV_ROUND_UP(min_uV - MAX8660_LDO67_MIN_UV,
273 MAX8660_LDO67_STEP);
274
275 ret = regulator_list_voltage_linear(rdev, selector);
276 if (ret < 0 || ret > max_uV)
277 return -EINVAL;
278
279 *s = selector;
280 237
281 if (rdev_get_id(rdev) == MAX8660_V6) 238 if (rdev_get_id(rdev) == MAX8660_V6)
282 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector); 239 return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector);
283 else 240 else
284 return max8660_write(max8660, MAX8660_L12VCR, 0x0f, selector << 4); 241 return max8660_write(max8660, MAX8660_L12VCR, 0x0f,
242 selector << 4);
285} 243}
286 244
287static struct regulator_ops max8660_ldo67_ops = { 245static struct regulator_ops max8660_ldo67_ops = {
@@ -289,8 +247,9 @@ static struct regulator_ops max8660_ldo67_ops = {
289 .enable = max8660_ldo67_enable, 247 .enable = max8660_ldo67_enable,
290 .disable = max8660_ldo67_disable, 248 .disable = max8660_ldo67_disable,
291 .list_voltage = regulator_list_voltage_linear, 249 .list_voltage = regulator_list_voltage_linear,
250 .map_voltage = regulator_map_voltage_linear,
292 .get_voltage_sel = max8660_ldo67_get_voltage_sel, 251 .get_voltage_sel = max8660_ldo67_get_voltage_sel,
293 .set_voltage = max8660_ldo67_set, 252 .set_voltage_sel = max8660_ldo67_set_voltage_sel,
294}; 253};
295 254
296static const struct regulator_desc max8660_reg[] = { 255static const struct regulator_desc max8660_reg[] = {