aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2013-02-19 07:42:47 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-02-19 07:42:47 -0500
commitc7b094828bc1b83eb507f43ebc8f9f8abfb3ec22 (patch)
treed342df2f47304199e49e2c1601329ed320067eb6 /drivers/regulator
parent800d290182ddea3d1e79b57711c15639f72f3185 (diff)
parente69995d3bfbdc8d30ae3548c69f669139791b739 (diff)
Merge remote-tracking branch 'regulator/topic/lp8788' into regulator-next
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/lp8788-buck.c41
-rw-r--r--drivers/regulator/lp8788-ldo.c133
2 files changed, 46 insertions, 128 deletions
diff --git a/drivers/regulator/lp8788-buck.c b/drivers/regulator/lp8788-buck.c
index aef3f2b0c5ea..97891a7ea7b2 100644
--- a/drivers/regulator/lp8788-buck.c
+++ b/drivers/regulator/lp8788-buck.c
@@ -103,16 +103,6 @@ static const int lp8788_buck_vtbl[] = {
103 1950000, 2000000, 103 1950000, 2000000,
104}; 104};
105 105
106static const u8 buck1_vout_addr[] = {
107 LP8788_BUCK1_VOUT0, LP8788_BUCK1_VOUT1,
108 LP8788_BUCK1_VOUT2, LP8788_BUCK1_VOUT3,
109};
110
111static const u8 buck2_vout_addr[] = {
112 LP8788_BUCK2_VOUT0, LP8788_BUCK2_VOUT1,
113 LP8788_BUCK2_VOUT2, LP8788_BUCK2_VOUT3,
114};
115
116static void lp8788_buck1_set_dvs(struct lp8788_buck *buck) 106static void lp8788_buck1_set_dvs(struct lp8788_buck *buck)
117{ 107{
118 struct lp8788_buck1_dvs *dvs = (struct lp8788_buck1_dvs *)buck->dvs; 108 struct lp8788_buck1_dvs *dvs = (struct lp8788_buck1_dvs *)buck->dvs;
@@ -235,7 +225,7 @@ static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck,
235 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); 225 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val);
236 idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S; 226 idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S;
237 } 227 }
238 addr = buck1_vout_addr[idx]; 228 addr = LP8788_BUCK1_VOUT0 + idx;
239 break; 229 break;
240 case BUCK2: 230 case BUCK2:
241 if (mode == EXTPIN) { 231 if (mode == EXTPIN) {
@@ -258,7 +248,7 @@ static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck,
258 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); 248 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val);
259 idx = (val & LP8788_BUCK2_DVS_M) >> LP8788_BUCK2_DVS_S; 249 idx = (val & LP8788_BUCK2_DVS_M) >> LP8788_BUCK2_DVS_S;
260 } 250 }
261 addr = buck2_vout_addr[idx]; 251 addr = LP8788_BUCK2_VOUT0 + idx;
262 break; 252 break;
263 default: 253 default:
264 goto err; 254 goto err;
@@ -429,7 +419,8 @@ static struct regulator_desc lp8788_buck_desc[] = {
429 }, 419 },
430}; 420};
431 421
432static int lp8788_dvs_gpio_request(struct lp8788_buck *buck, 422static int lp8788_dvs_gpio_request(struct platform_device *pdev,
423 struct lp8788_buck *buck,
433 enum lp8788_buck_id id) 424 enum lp8788_buck_id id)
434{ 425{
435 struct lp8788_platform_data *pdata = buck->lp->pdata; 426 struct lp8788_platform_data *pdata = buck->lp->pdata;
@@ -440,7 +431,7 @@ static int lp8788_dvs_gpio_request(struct lp8788_buck *buck,
440 switch (id) { 431 switch (id) {
441 case BUCK1: 432 case BUCK1:
442 gpio = pdata->buck1_dvs->gpio; 433 gpio = pdata->buck1_dvs->gpio;
443 ret = devm_gpio_request_one(buck->lp->dev, gpio, DVS_LOW, 434 ret = devm_gpio_request_one(&pdev->dev, gpio, DVS_LOW,
444 b1_name); 435 b1_name);
445 if (ret) 436 if (ret)
446 return ret; 437 return ret;
@@ -448,9 +439,9 @@ static int lp8788_dvs_gpio_request(struct lp8788_buck *buck,
448 buck->dvs = pdata->buck1_dvs; 439 buck->dvs = pdata->buck1_dvs;
449 break; 440 break;
450 case BUCK2: 441 case BUCK2:
451 for (i = 0 ; i < LP8788_NUM_BUCK2_DVS ; i++) { 442 for (i = 0; i < LP8788_NUM_BUCK2_DVS; i++) {
452 gpio = pdata->buck2_dvs->gpio[i]; 443 gpio = pdata->buck2_dvs->gpio[i];
453 ret = devm_gpio_request_one(buck->lp->dev, gpio, 444 ret = devm_gpio_request_one(&pdev->dev, gpio,
454 DVS_LOW, b2_name[i]); 445 DVS_LOW, b2_name[i]);
455 if (ret) 446 if (ret)
456 return ret; 447 return ret;
@@ -464,7 +455,8 @@ static int lp8788_dvs_gpio_request(struct lp8788_buck *buck,
464 return 0; 455 return 0;
465} 456}
466 457
467static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) 458static int lp8788_init_dvs(struct platform_device *pdev,
459 struct lp8788_buck *buck, enum lp8788_buck_id id)
468{ 460{
469 struct lp8788_platform_data *pdata = buck->lp->pdata; 461 struct lp8788_platform_data *pdata = buck->lp->pdata;
470 u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M }; 462 u8 mask[] = { LP8788_BUCK1_DVS_SEL_M, LP8788_BUCK2_DVS_SEL_M };
@@ -472,7 +464,7 @@ static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
472 u8 default_dvs_mode[] = { LP8788_BUCK1_DVS_I2C, LP8788_BUCK2_DVS_I2C }; 464 u8 default_dvs_mode[] = { LP8788_BUCK1_DVS_I2C, LP8788_BUCK2_DVS_I2C };
473 465
474 /* no dvs for buck3, 4 */ 466 /* no dvs for buck3, 4 */
475 if (id == BUCK3 || id == BUCK4) 467 if (id > BUCK2)
476 return 0; 468 return 0;
477 469
478 /* no dvs platform data, then dvs will be selected by I2C registers */ 470 /* no dvs platform data, then dvs will be selected by I2C registers */
@@ -483,7 +475,7 @@ static int lp8788_init_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
483 (id == BUCK2 && !pdata->buck2_dvs)) 475 (id == BUCK2 && !pdata->buck2_dvs))
484 goto set_default_dvs_mode; 476 goto set_default_dvs_mode;
485 477
486 if (lp8788_dvs_gpio_request(buck, id)) 478 if (lp8788_dvs_gpio_request(pdev, buck, id))
487 goto set_default_dvs_mode; 479 goto set_default_dvs_mode;
488 480
489 return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id], 481 return lp8788_update_bits(buck->lp, LP8788_BUCK_DVS_SEL, mask[id],
@@ -503,17 +495,20 @@ static int lp8788_buck_probe(struct platform_device *pdev)
503 struct regulator_dev *rdev; 495 struct regulator_dev *rdev;
504 int ret; 496 int ret;
505 497
506 buck = devm_kzalloc(lp->dev, sizeof(struct lp8788_buck), GFP_KERNEL); 498 if (id >= LP8788_NUM_BUCKS)
499 return -EINVAL;
500
501 buck = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_buck), GFP_KERNEL);
507 if (!buck) 502 if (!buck)
508 return -ENOMEM; 503 return -ENOMEM;
509 504
510 buck->lp = lp; 505 buck->lp = lp;
511 506
512 ret = lp8788_init_dvs(buck, id); 507 ret = lp8788_init_dvs(pdev, buck, id);
513 if (ret) 508 if (ret)
514 return ret; 509 return ret;
515 510
516 cfg.dev = lp->dev; 511 cfg.dev = pdev->dev.parent;
517 cfg.init_data = lp->pdata ? lp->pdata->buck_data[id] : NULL; 512 cfg.init_data = lp->pdata ? lp->pdata->buck_data[id] : NULL;
518 cfg.driver_data = buck; 513 cfg.driver_data = buck;
519 cfg.regmap = lp->regmap; 514 cfg.regmap = lp->regmap;
@@ -521,7 +516,7 @@ static int lp8788_buck_probe(struct platform_device *pdev)
521 rdev = regulator_register(&lp8788_buck_desc[id], &cfg); 516 rdev = regulator_register(&lp8788_buck_desc[id], &cfg);
522 if (IS_ERR(rdev)) { 517 if (IS_ERR(rdev)) {
523 ret = PTR_ERR(rdev); 518 ret = PTR_ERR(rdev);
524 dev_err(lp->dev, "BUCK%d regulator register err = %d\n", 519 dev_err(&pdev->dev, "BUCK%d regulator register err = %d\n",
525 id + 1, ret); 520 id + 1, ret);
526 return ret; 521 return ret;
527 } 522 }
diff --git a/drivers/regulator/lp8788-ldo.c b/drivers/regulator/lp8788-ldo.c
index 3792741708ce..cd5a14ad9263 100644
--- a/drivers/regulator/lp8788-ldo.c
+++ b/drivers/regulator/lp8788-ldo.c
@@ -88,11 +88,6 @@
88#define ENABLE GPIOF_OUT_INIT_HIGH 88#define ENABLE GPIOF_OUT_INIT_HIGH
89#define DISABLE GPIOF_OUT_INIT_LOW 89#define DISABLE GPIOF_OUT_INIT_LOW
90 90
91enum lp8788_enable_mode {
92 REGISTER,
93 EXTPIN,
94};
95
96enum lp8788_ldo_id { 91enum lp8788_ldo_id {
97 DLDO1, 92 DLDO1,
98 DLDO2, 93 DLDO2,
@@ -189,114 +184,38 @@ static enum lp8788_ldo_id lp8788_aldo_id[] = {
189 ALDO10, 184 ALDO10,
190}; 185};
191 186
192/* DLDO 7, 9 and 11, ALDO 1 ~ 5 and 7
193 : can be enabled either by external pin or by i2c register */
194static enum lp8788_enable_mode
195lp8788_get_ldo_enable_mode(struct lp8788_ldo *ldo, enum lp8788_ldo_id id)
196{
197 int ret;
198 u8 val, mask;
199
200 ret = lp8788_read_byte(ldo->lp, LP8788_EN_SEL, &val);
201 if (ret)
202 return ret;
203
204 switch (id) {
205 case DLDO7:
206 mask = LP8788_EN_SEL_DLDO7_M;
207 break;
208 case DLDO9:
209 case DLDO11:
210 mask = LP8788_EN_SEL_DLDO911_M;
211 break;
212 case ALDO1:
213 mask = LP8788_EN_SEL_ALDO1_M;
214 break;
215 case ALDO2 ... ALDO4:
216 mask = LP8788_EN_SEL_ALDO234_M;
217 break;
218 case ALDO5:
219 mask = LP8788_EN_SEL_ALDO5_M;
220 break;
221 case ALDO7:
222 mask = LP8788_EN_SEL_ALDO7_M;
223 break;
224 default:
225 return REGISTER;
226 }
227
228 return val & mask ? EXTPIN : REGISTER;
229}
230
231static int lp8788_ldo_ctrl_by_extern_pin(struct lp8788_ldo *ldo, int pinstate)
232{
233 struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
234
235 if (!pin)
236 return -EINVAL;
237
238 if (gpio_is_valid(pin->gpio))
239 gpio_set_value(pin->gpio, pinstate);
240
241 return 0;
242}
243
244static int lp8788_ldo_is_enabled_by_extern_pin(struct lp8788_ldo *ldo)
245{
246 struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
247
248 if (!pin)
249 return -EINVAL;
250
251 return gpio_get_value(pin->gpio) ? 1 : 0;
252}
253
254static int lp8788_ldo_enable(struct regulator_dev *rdev) 187static int lp8788_ldo_enable(struct regulator_dev *rdev)
255{ 188{
256 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); 189 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
257 enum lp8788_ldo_id id = rdev_get_id(rdev);
258 enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id);
259 190
260 switch (mode) { 191 if (ldo->en_pin) {
261 case EXTPIN: 192 gpio_set_value(ldo->en_pin->gpio, ENABLE);
262 return lp8788_ldo_ctrl_by_extern_pin(ldo, ENABLE); 193 return 0;
263 case REGISTER: 194 } else {
264 return regulator_enable_regmap(rdev); 195 return regulator_enable_regmap(rdev);
265 default:
266 return -EINVAL;
267 } 196 }
268} 197}
269 198
270static int lp8788_ldo_disable(struct regulator_dev *rdev) 199static int lp8788_ldo_disable(struct regulator_dev *rdev)
271{ 200{
272 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); 201 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
273 enum lp8788_ldo_id id = rdev_get_id(rdev);
274 enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id);
275 202
276 switch (mode) { 203 if (ldo->en_pin) {
277 case EXTPIN: 204 gpio_set_value(ldo->en_pin->gpio, DISABLE);
278 return lp8788_ldo_ctrl_by_extern_pin(ldo, DISABLE); 205 return 0;
279 case REGISTER: 206 } else {
280 return regulator_disable_regmap(rdev); 207 return regulator_disable_regmap(rdev);
281 default:
282 return -EINVAL;
283 } 208 }
284} 209}
285 210
286static int lp8788_ldo_is_enabled(struct regulator_dev *rdev) 211static int lp8788_ldo_is_enabled(struct regulator_dev *rdev)
287{ 212{
288 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev); 213 struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
289 enum lp8788_ldo_id id = rdev_get_id(rdev);
290 enum lp8788_enable_mode mode = lp8788_get_ldo_enable_mode(ldo, id);
291 214
292 switch (mode) { 215 if (ldo->en_pin)
293 case EXTPIN: 216 return gpio_get_value(ldo->en_pin->gpio) ? 1 : 0;
294 return lp8788_ldo_is_enabled_by_extern_pin(ldo); 217 else
295 case REGISTER:
296 return regulator_is_enabled_regmap(rdev); 218 return regulator_is_enabled_regmap(rdev);
297 default:
298 return -EINVAL;
299 }
300} 219}
301 220
302static int lp8788_ldo_enable_time(struct regulator_dev *rdev) 221static int lp8788_ldo_enable_time(struct regulator_dev *rdev)
@@ -616,10 +535,11 @@ static struct regulator_desc lp8788_aldo_desc[] = {
616 }, 535 },
617}; 536};
618 537
619static int lp8788_gpio_request_ldo_en(struct lp8788_ldo *ldo, 538static int lp8788_gpio_request_ldo_en(struct platform_device *pdev,
539 struct lp8788_ldo *ldo,
620 enum lp8788_ext_ldo_en_id id) 540 enum lp8788_ext_ldo_en_id id)
621{ 541{
622 struct device *dev = ldo->lp->dev; 542 struct device *dev = &pdev->dev;
623 struct lp8788_ldo_enable_pin *pin = ldo->en_pin; 543 struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
624 int ret, gpio, pinstate; 544 int ret, gpio, pinstate;
625 char *name[] = { 545 char *name[] = {
@@ -647,7 +567,8 @@ static int lp8788_gpio_request_ldo_en(struct lp8788_ldo *ldo,
647 return ret; 567 return ret;
648} 568}
649 569
650static int lp8788_config_ldo_enable_mode(struct lp8788_ldo *ldo, 570static int lp8788_config_ldo_enable_mode(struct platform_device *pdev,
571 struct lp8788_ldo *ldo,
651 enum lp8788_ldo_id id) 572 enum lp8788_ldo_id id)
652{ 573{
653 int ret; 574 int ret;
@@ -693,9 +614,11 @@ static int lp8788_config_ldo_enable_mode(struct lp8788_ldo *ldo,
693 614
694 ldo->en_pin = pdata->ldo_pin[enable_id]; 615 ldo->en_pin = pdata->ldo_pin[enable_id];
695 616
696 ret = lp8788_gpio_request_ldo_en(ldo, enable_id); 617 ret = lp8788_gpio_request_ldo_en(pdev, ldo, enable_id);
697 if (ret) 618 if (ret) {
619 ldo->en_pin = NULL;
698 goto set_default_ldo_enable_mode; 620 goto set_default_ldo_enable_mode;
621 }
699 622
700 return ret; 623 return ret;
701 624
@@ -712,16 +635,16 @@ static int lp8788_dldo_probe(struct platform_device *pdev)
712 struct regulator_dev *rdev; 635 struct regulator_dev *rdev;
713 int ret; 636 int ret;
714 637
715 ldo = devm_kzalloc(lp->dev, sizeof(struct lp8788_ldo), GFP_KERNEL); 638 ldo = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_ldo), GFP_KERNEL);
716 if (!ldo) 639 if (!ldo)
717 return -ENOMEM; 640 return -ENOMEM;
718 641
719 ldo->lp = lp; 642 ldo->lp = lp;
720 ret = lp8788_config_ldo_enable_mode(ldo, lp8788_dldo_id[id]); 643 ret = lp8788_config_ldo_enable_mode(pdev, ldo, lp8788_dldo_id[id]);
721 if (ret) 644 if (ret)
722 return ret; 645 return ret;
723 646
724 cfg.dev = lp->dev; 647 cfg.dev = pdev->dev.parent;
725 cfg.init_data = lp->pdata ? lp->pdata->dldo_data[id] : NULL; 648 cfg.init_data = lp->pdata ? lp->pdata->dldo_data[id] : NULL;
726 cfg.driver_data = ldo; 649 cfg.driver_data = ldo;
727 cfg.regmap = lp->regmap; 650 cfg.regmap = lp->regmap;
@@ -729,7 +652,7 @@ static int lp8788_dldo_probe(struct platform_device *pdev)
729 rdev = regulator_register(&lp8788_dldo_desc[id], &cfg); 652 rdev = regulator_register(&lp8788_dldo_desc[id], &cfg);
730 if (IS_ERR(rdev)) { 653 if (IS_ERR(rdev)) {
731 ret = PTR_ERR(rdev); 654 ret = PTR_ERR(rdev);
732 dev_err(lp->dev, "DLDO%d regulator register err = %d\n", 655 dev_err(&pdev->dev, "DLDO%d regulator register err = %d\n",
733 id + 1, ret); 656 id + 1, ret);
734 return ret; 657 return ret;
735 } 658 }
@@ -768,16 +691,16 @@ static int lp8788_aldo_probe(struct platform_device *pdev)
768 struct regulator_dev *rdev; 691 struct regulator_dev *rdev;
769 int ret; 692 int ret;
770 693
771 ldo = devm_kzalloc(lp->dev, sizeof(struct lp8788_ldo), GFP_KERNEL); 694 ldo = devm_kzalloc(&pdev->dev, sizeof(struct lp8788_ldo), GFP_KERNEL);
772 if (!ldo) 695 if (!ldo)
773 return -ENOMEM; 696 return -ENOMEM;
774 697
775 ldo->lp = lp; 698 ldo->lp = lp;
776 ret = lp8788_config_ldo_enable_mode(ldo, lp8788_aldo_id[id]); 699 ret = lp8788_config_ldo_enable_mode(pdev, ldo, lp8788_aldo_id[id]);
777 if (ret) 700 if (ret)
778 return ret; 701 return ret;
779 702
780 cfg.dev = lp->dev; 703 cfg.dev = pdev->dev.parent;
781 cfg.init_data = lp->pdata ? lp->pdata->aldo_data[id] : NULL; 704 cfg.init_data = lp->pdata ? lp->pdata->aldo_data[id] : NULL;
782 cfg.driver_data = ldo; 705 cfg.driver_data = ldo;
783 cfg.regmap = lp->regmap; 706 cfg.regmap = lp->regmap;
@@ -785,7 +708,7 @@ static int lp8788_aldo_probe(struct platform_device *pdev)
785 rdev = regulator_register(&lp8788_aldo_desc[id], &cfg); 708 rdev = regulator_register(&lp8788_aldo_desc[id], &cfg);
786 if (IS_ERR(rdev)) { 709 if (IS_ERR(rdev)) {
787 ret = PTR_ERR(rdev); 710 ret = PTR_ERR(rdev);
788 dev_err(lp->dev, "ALDO%d regulator register err = %d\n", 711 dev_err(&pdev->dev, "ALDO%d regulator register err = %d\n",
789 id + 1, ret); 712 id + 1, ret);
790 return ret; 713 return ret;
791 } 714 }