diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-03-12 00:11:46 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-03-12 06:50:46 -0400 |
commit | fc56911bc6468c165894e0ca985b1130bb537955 (patch) | |
tree | 1df848f9b0cbc50c29f72c9c3f842fc5d59d5b0c | |
parent | dce7304f4b8ea9e12c1bd58747f16f579c4d7b2d (diff) |
regulator: Merge tps65217_pmic_ldo234_ops and tps65217_pmic_dcdc_ops to tps65217_pmic_ops
Most callback functions implementation for tps65217_pmic_ldo234_ops and
tps65217_pmic_dcdc_ops are the same except the rid range checking.
This patch uses tps65217_pmic_ops for all DCDCx, LDO2, LDO3, and LDO4.
And rework tps65217_pmic_set_voltage to make it can be called for
DCDCx, LDO2, LDO3, and LDO4.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r-- | drivers/regulator/tps65217-regulator.c | 259 |
1 files changed, 72 insertions, 187 deletions
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 15f2fa0bb005..e39521b42772 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c | |||
@@ -151,166 +151,69 @@ static struct tps_info tps65217_pmic_regs[] = { | |||
151 | TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK), | 151 | TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK), |
152 | }; | 152 | }; |
153 | 153 | ||
154 | static int tps65217_pmic_dcdc_is_enabled(struct regulator_dev *dev) | 154 | static int tps65217_pmic_is_enabled(struct regulator_dev *dev) |
155 | { | 155 | { |
156 | int ret; | 156 | int ret; |
157 | struct tps65217 *tps = rdev_get_drvdata(dev); | 157 | struct tps65217 *tps = rdev_get_drvdata(dev); |
158 | unsigned int data, dcdc = rdev_get_id(dev); | 158 | unsigned int data, rid = rdev_get_id(dev); |
159 | 159 | ||
160 | if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) | 160 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
161 | return -EINVAL; | 161 | return -EINVAL; |
162 | 162 | ||
163 | ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); | 163 | ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); |
164 | if (ret) | 164 | if (ret) |
165 | return ret; | 165 | return ret; |
166 | 166 | ||
167 | return (data & tps->info[dcdc]->enable_mask) ? 1 : 0; | 167 | return (data & tps->info[rid]->enable_mask) ? 1 : 0; |
168 | } | 168 | } |
169 | 169 | ||
170 | static int tps65217_pmic_ldo_is_enabled(struct regulator_dev *dev) | 170 | static int tps65217_pmic_enable(struct regulator_dev *dev) |
171 | { | 171 | { |
172 | int ret; | ||
173 | struct tps65217 *tps = rdev_get_drvdata(dev); | 172 | struct tps65217 *tps = rdev_get_drvdata(dev); |
174 | unsigned int data, ldo = rdev_get_id(dev); | 173 | unsigned int rid = rdev_get_id(dev); |
175 | 174 | ||
176 | if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) | 175 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
177 | return -EINVAL; | ||
178 | |||
179 | ret = tps65217_reg_read(tps, TPS65217_REG_ENABLE, &data); | ||
180 | if (ret) | ||
181 | return ret; | ||
182 | |||
183 | return (data & tps->info[ldo]->enable_mask) ? 1 : 0; | ||
184 | } | ||
185 | |||
186 | static int tps65217_pmic_dcdc_enable(struct regulator_dev *dev) | ||
187 | { | ||
188 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
189 | unsigned int dcdc = rdev_get_id(dev); | ||
190 | |||
191 | if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) | ||
192 | return -EINVAL; | 176 | return -EINVAL; |
193 | 177 | ||
194 | /* Enable the regulator and password protection is level 1 */ | 178 | /* Enable the regulator and password protection is level 1 */ |
195 | return tps65217_set_bits(tps, TPS65217_REG_ENABLE, | 179 | return tps65217_set_bits(tps, TPS65217_REG_ENABLE, |
196 | tps->info[dcdc]->enable_mask, | 180 | tps->info[rid]->enable_mask, |
197 | tps->info[dcdc]->enable_mask, | 181 | tps->info[rid]->enable_mask, |
198 | TPS65217_PROTECT_L1); | 182 | TPS65217_PROTECT_L1); |
199 | } | 183 | } |
200 | 184 | ||
201 | static int tps65217_pmic_dcdc_disable(struct regulator_dev *dev) | 185 | static int tps65217_pmic_disable(struct regulator_dev *dev) |
202 | { | 186 | { |
203 | struct tps65217 *tps = rdev_get_drvdata(dev); | 187 | struct tps65217 *tps = rdev_get_drvdata(dev); |
204 | unsigned int dcdc = rdev_get_id(dev); | 188 | unsigned int rid = rdev_get_id(dev); |
205 | 189 | ||
206 | if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) | 190 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
207 | return -EINVAL; | 191 | return -EINVAL; |
208 | 192 | ||
209 | /* Disable the regulator and password protection is level 1 */ | 193 | /* Disable the regulator and password protection is level 1 */ |
210 | return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, | 194 | return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, |
211 | tps->info[dcdc]->enable_mask, TPS65217_PROTECT_L1); | 195 | tps->info[rid]->enable_mask, TPS65217_PROTECT_L1); |
212 | } | ||
213 | |||
214 | static int tps65217_pmic_ldo_enable(struct regulator_dev *dev) | ||
215 | { | ||
216 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
217 | unsigned int ldo = rdev_get_id(dev); | ||
218 | |||
219 | if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) | ||
220 | return -EINVAL; | ||
221 | |||
222 | /* Enable the regulator and password protection is level 1 */ | ||
223 | return tps65217_set_bits(tps, TPS65217_REG_ENABLE, | ||
224 | tps->info[ldo]->enable_mask, | ||
225 | tps->info[ldo]->enable_mask, | ||
226 | TPS65217_PROTECT_L1); | ||
227 | } | ||
228 | |||
229 | static int tps65217_pmic_ldo_disable(struct regulator_dev *dev) | ||
230 | { | ||
231 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
232 | unsigned int ldo = rdev_get_id(dev); | ||
233 | |||
234 | if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) | ||
235 | return -EINVAL; | ||
236 | |||
237 | /* Disable the regulator and password protection is level 1 */ | ||
238 | return tps65217_clear_bits(tps, TPS65217_REG_ENABLE, | ||
239 | tps->info[ldo]->enable_mask, TPS65217_PROTECT_L1); | ||
240 | } | ||
241 | |||
242 | static int tps65217_pmic_dcdc_get_voltage_sel(struct regulator_dev *dev) | ||
243 | { | ||
244 | int ret; | ||
245 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
246 | unsigned int selector, dcdc = rdev_get_id(dev); | ||
247 | |||
248 | if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) | ||
249 | return -EINVAL; | ||
250 | |||
251 | ret = tps65217_reg_read(tps, tps->info[dcdc]->set_vout_reg, &selector); | ||
252 | if (ret) | ||
253 | return ret; | ||
254 | |||
255 | selector &= tps->info[dcdc]->set_vout_mask; | ||
256 | |||
257 | return selector; | ||
258 | } | 196 | } |
259 | 197 | ||
260 | static int tps65217_pmic_dcdc_set_voltage(struct regulator_dev *dev, | 198 | static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev) |
261 | int min_uV, int max_uV, unsigned *selector) | ||
262 | { | 199 | { |
263 | int ret; | 200 | int ret; |
264 | struct tps65217 *tps = rdev_get_drvdata(dev); | 201 | struct tps65217 *tps = rdev_get_drvdata(dev); |
265 | unsigned int dcdc = rdev_get_id(dev); | 202 | unsigned int selector, rid = rdev_get_id(dev); |
266 | |||
267 | if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) | ||
268 | return -EINVAL; | ||
269 | 203 | ||
270 | if (min_uV < tps->info[dcdc]->min_uV | 204 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
271 | || min_uV > tps->info[dcdc]->max_uV) | ||
272 | return -EINVAL; | 205 | return -EINVAL; |
273 | 206 | ||
274 | if (max_uV < tps->info[dcdc]->min_uV | 207 | ret = tps65217_reg_read(tps, tps->info[rid]->set_vout_reg, &selector); |
275 | || max_uV > tps->info[dcdc]->max_uV) | ||
276 | return -EINVAL; | ||
277 | |||
278 | ret = tps->info[dcdc]->uv_to_vsel(min_uV, selector); | ||
279 | if (ret) | 208 | if (ret) |
280 | return ret; | 209 | return ret; |
281 | 210 | ||
282 | /* Set the voltage based on vsel value and write protect level is 2 */ | 211 | selector &= tps->info[rid]->set_vout_mask; |
283 | ret = tps65217_set_bits(tps, tps->info[dcdc]->set_vout_reg, | ||
284 | tps->info[dcdc]->set_vout_mask, | ||
285 | *selector, TPS65217_PROTECT_L2); | ||
286 | if (ret) | ||
287 | return ret; | ||
288 | |||
289 | /* Set GO bit to initiate voltage transistion */ | ||
290 | return tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, | ||
291 | TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, | ||
292 | TPS65217_PROTECT_L2); | ||
293 | } | ||
294 | |||
295 | static int tps65217_pmic_ldo_get_voltage_sel(struct regulator_dev *dev) | ||
296 | { | ||
297 | int ret; | ||
298 | struct tps65217 *tps = rdev_get_drvdata(dev); | ||
299 | unsigned int selector, ldo = rdev_get_id(dev); | ||
300 | |||
301 | if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) | ||
302 | return -EINVAL; | ||
303 | |||
304 | ret = tps65217_reg_read(tps, tps->info[ldo]->set_vout_reg, &selector); | ||
305 | if (ret) | ||
306 | return ret; | ||
307 | |||
308 | selector &= tps->info[ldo]->set_vout_mask; | ||
309 | 212 | ||
310 | return selector; | 213 | return selector; |
311 | } | 214 | } |
312 | 215 | ||
313 | static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev, | 216 | static int tps65217_pmic_ldo1_set_voltage_sel(struct regulator_dev *dev, |
314 | unsigned selector) | 217 | unsigned selector) |
315 | { | 218 | { |
316 | struct tps65217 *tps = rdev_get_drvdata(dev); | 219 | struct tps65217 *tps = rdev_get_drvdata(dev); |
@@ -328,112 +231,95 @@ static int tps65217_pmic_ldo_set_voltage_sel(struct regulator_dev *dev, | |||
328 | selector, TPS65217_PROTECT_L2); | 231 | selector, TPS65217_PROTECT_L2); |
329 | } | 232 | } |
330 | 233 | ||
331 | static int tps65217_pmic_ldo_set_voltage(struct regulator_dev *dev, | 234 | static int tps65217_pmic_set_voltage(struct regulator_dev *dev, |
332 | int min_uV, int max_uV, unsigned *selector) | 235 | int min_uV, int max_uV, unsigned *selector) |
333 | { | 236 | { |
334 | int ret; | 237 | int ret; |
335 | struct tps65217 *tps = rdev_get_drvdata(dev); | 238 | struct tps65217 *tps = rdev_get_drvdata(dev); |
336 | unsigned int ldo = rdev_get_id(dev); | 239 | unsigned int rid = rdev_get_id(dev); |
337 | 240 | ||
338 | if (ldo < TPS65217_LDO_2 || ldo > TPS65217_LDO_4) | 241 | /* LDO1 implements set_voltage_sel callback */ |
242 | if (rid == TPS65217_LDO_1) | ||
339 | return -EINVAL; | 243 | return -EINVAL; |
340 | 244 | ||
341 | if (min_uV < tps->info[ldo]->min_uV | 245 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
342 | || min_uV > tps->info[ldo]->max_uV) | ||
343 | return -EINVAL; | 246 | return -EINVAL; |
344 | 247 | ||
345 | if (max_uV < tps->info[ldo]->min_uV | 248 | if (min_uV < tps->info[rid]->min_uV |
346 | || max_uV > tps->info[ldo]->max_uV) | 249 | || min_uV > tps->info[rid]->max_uV) |
347 | return -EINVAL; | 250 | return -EINVAL; |
348 | 251 | ||
349 | ret = tps->info[ldo]->uv_to_vsel(min_uV, selector); | 252 | if (max_uV < tps->info[rid]->min_uV |
253 | || max_uV > tps->info[rid]->max_uV) | ||
254 | return -EINVAL; | ||
255 | |||
256 | ret = tps->info[rid]->uv_to_vsel(min_uV, selector); | ||
350 | if (ret) | 257 | if (ret) |
351 | return ret; | 258 | return ret; |
352 | 259 | ||
353 | /* Set the voltage based on vsel value and write protect level is 2 */ | 260 | /* Set the voltage based on vsel value and write protect level is 2 */ |
354 | return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg, | 261 | ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, |
355 | tps->info[ldo]->set_vout_mask, | 262 | tps->info[rid]->set_vout_mask, |
356 | *selector, TPS65217_PROTECT_L2); | 263 | *selector, TPS65217_PROTECT_L2); |
357 | } | 264 | |
358 | 265 | /* Set GO bit for DCDCx to initiate voltage transistion */ | |
359 | static int tps65217_pmic_dcdc_list_voltage(struct regulator_dev *dev, | 266 | switch (rid) { |
360 | unsigned selector) | 267 | case TPS65217_DCDC_1 ... TPS65217_DCDC_3: |
361 | { | 268 | ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, |
362 | struct tps65217 *tps = rdev_get_drvdata(dev); | 269 | TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, |
363 | unsigned int dcdc = rdev_get_id(dev); | 270 | TPS65217_PROTECT_L2); |
364 | 271 | break; | |
365 | if (dcdc < TPS65217_DCDC_1 || dcdc > TPS65217_DCDC_3) | 272 | } |
366 | return -EINVAL; | ||
367 | |||
368 | if (selector >= tps->info[dcdc]->table_len) | ||
369 | return -EINVAL; | ||
370 | 273 | ||
371 | return tps->info[dcdc]->vsel_to_uv(selector); | 274 | return ret; |
372 | } | 275 | } |
373 | 276 | ||
374 | static int tps65217_pmic_ldo_list_voltage(struct regulator_dev *dev, | 277 | static int tps65217_pmic_list_voltage(struct regulator_dev *dev, |
375 | unsigned selector) | 278 | unsigned selector) |
376 | { | 279 | { |
377 | struct tps65217 *tps = rdev_get_drvdata(dev); | 280 | struct tps65217 *tps = rdev_get_drvdata(dev); |
378 | unsigned int ldo = rdev_get_id(dev); | 281 | unsigned int rid = rdev_get_id(dev); |
379 | 282 | ||
380 | if (ldo < TPS65217_LDO_1 || ldo > TPS65217_LDO_4) | 283 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
381 | return -EINVAL; | 284 | return -EINVAL; |
382 | 285 | ||
383 | if (selector >= tps->info[ldo]->table_len) | 286 | if (selector >= tps->info[rid]->table_len) |
384 | return -EINVAL; | 287 | return -EINVAL; |
385 | 288 | ||
386 | if (tps->info[ldo]->table) | 289 | if (tps->info[rid]->table) |
387 | return tps->info[ldo]->table[selector]; | 290 | return tps->info[rid]->table[selector]; |
388 | 291 | ||
389 | return tps->info[ldo]->vsel_to_uv(selector); | 292 | return tps->info[rid]->vsel_to_uv(selector); |
390 | } | 293 | } |
391 | 294 | ||
392 | /* Operations permitted on DCDCx */ | 295 | /* Operations permitted on DCDCx, LDO2, LDO3 and LDO4 */ |
393 | static struct regulator_ops tps65217_pmic_dcdc_ops = { | 296 | static struct regulator_ops tps65217_pmic_ops = { |
394 | .is_enabled = tps65217_pmic_dcdc_is_enabled, | 297 | .is_enabled = tps65217_pmic_is_enabled, |
395 | .enable = tps65217_pmic_dcdc_enable, | 298 | .enable = tps65217_pmic_enable, |
396 | .disable = tps65217_pmic_dcdc_disable, | 299 | .disable = tps65217_pmic_disable, |
397 | .get_voltage_sel = tps65217_pmic_dcdc_get_voltage_sel, | 300 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, |
398 | .set_voltage = tps65217_pmic_dcdc_set_voltage, | 301 | .set_voltage = tps65217_pmic_set_voltage, |
399 | .list_voltage = tps65217_pmic_dcdc_list_voltage, | 302 | .list_voltage = tps65217_pmic_list_voltage, |
400 | }; | 303 | }; |
401 | 304 | ||
402 | /* Operations permitted on LDO1 */ | 305 | /* Operations permitted on LDO1 */ |
403 | static struct regulator_ops tps65217_pmic_ldo1_ops = { | 306 | static struct regulator_ops tps65217_pmic_ldo1_ops = { |
404 | .is_enabled = tps65217_pmic_ldo_is_enabled, | 307 | .is_enabled = tps65217_pmic_is_enabled, |
405 | .enable = tps65217_pmic_ldo_enable, | 308 | .enable = tps65217_pmic_enable, |
406 | .disable = tps65217_pmic_ldo_disable, | 309 | .disable = tps65217_pmic_disable, |
407 | .get_voltage_sel = tps65217_pmic_ldo_get_voltage_sel, | 310 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, |
408 | .set_voltage_sel = tps65217_pmic_ldo_set_voltage_sel, | 311 | .set_voltage_sel = tps65217_pmic_ldo1_set_voltage_sel, |
409 | .list_voltage = tps65217_pmic_ldo_list_voltage, | 312 | .list_voltage = tps65217_pmic_list_voltage, |
410 | }; | ||
411 | |||
412 | /* Operations permitted on LDO2, LDO3 and LDO4 */ | ||
413 | static struct regulator_ops tps65217_pmic_ldo234_ops = { | ||
414 | .is_enabled = tps65217_pmic_ldo_is_enabled, | ||
415 | .enable = tps65217_pmic_ldo_enable, | ||
416 | .disable = tps65217_pmic_ldo_disable, | ||
417 | .get_voltage_sel = tps65217_pmic_ldo_get_voltage_sel, | ||
418 | .set_voltage = tps65217_pmic_ldo_set_voltage, | ||
419 | .list_voltage = tps65217_pmic_ldo_list_voltage, | ||
420 | }; | 313 | }; |
421 | 314 | ||
422 | static struct regulator_desc regulators[] = { | 315 | static struct regulator_desc regulators[] = { |
423 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, | 316 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), |
424 | tps65217_pmic_dcdc_ops, 64), | 317 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), |
425 | TPS65217_REGULATOR("DCDC2",TPS65217_DCDC_2, | 318 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), |
426 | tps65217_pmic_dcdc_ops, 64), | 319 | TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16), |
427 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, | 320 | TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64), |
428 | tps65217_pmic_dcdc_ops, 64), | 321 | TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32), |
429 | TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, | 322 | TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32), |
430 | tps65217_pmic_ldo1_ops, 16), | ||
431 | TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, | ||
432 | tps65217_pmic_ldo234_ops, 64), | ||
433 | TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, | ||
434 | tps65217_pmic_ldo234_ops, 32), | ||
435 | TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, | ||
436 | tps65217_pmic_ldo234_ops, 32), | ||
437 | }; | 323 | }; |
438 | 324 | ||
439 | static int __devinit tps65217_regulator_probe(struct platform_device *pdev) | 325 | static int __devinit tps65217_regulator_probe(struct platform_device *pdev) |
@@ -486,7 +372,6 @@ static void __exit tps65217_regulator_exit(void) | |||
486 | } | 372 | } |
487 | module_exit(tps65217_regulator_exit); | 373 | module_exit(tps65217_regulator_exit); |
488 | 374 | ||
489 | |||
490 | MODULE_AUTHOR("AnilKumar Ch <anilkumar@ti.com>"); | 375 | MODULE_AUTHOR("AnilKumar Ch <anilkumar@ti.com>"); |
491 | MODULE_DESCRIPTION("TPS65217 voltage regulator driver"); | 376 | MODULE_DESCRIPTION("TPS65217 voltage regulator driver"); |
492 | MODULE_ALIAS("platform:tps65217-pmic"); | 377 | MODULE_ALIAS("platform:tps65217-pmic"); |