2 * tps65910.c -- TI tps65910
4 * Copyright 2010 Texas Instruments Inc.
6 * Author: Graeme Gregory <gg@slimlogic.co.uk>
7 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/err.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/regulator/machine.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/gpio.h>
26 #include <linux/mfd/tps65910.h>
28 #define TPS65910_SUPPLY_STATE_ENABLED 0x1
29 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
30 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
31 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
32 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
34 /* supported VIO voltages in milivolts */
35 static const u16 VIO_VSEL_table[] = {
36 1500, 1800, 2500, 3300,
39 /* TPS65910 VDD1 and VDD2 */
40 /* value round off 12.5 is made as 12 */
41 static const u16 VDD1_VSEL_table[] = {
42 0, 600, 600, 600, 612, 625, 637, 650,
43 662, 675, 687, 700, 712, 725, 737, 750,
44 762, 775, 787, 800, 812, 825, 837, 850,
45 862, 875, 887, 900, 912, 925, 937, 950,
46 962, 975, 987, 1000, 1012, 1025, 1037, 1050,
47 1062, 1075, 1087, 1100, 1112, 1125, 1137, 1150,
48 1162, 1175, 1187, 1200, 1212, 1225, 1237, 1250,
49 1262, 1275, 1287, 1300, 1312, 1325, 1337, 1350,
50 1362, 1375, 1387, 1400, 1412, 1425, 1437, 1450,
51 1462, 1475, 1487, 1500,
54 static const u16 VDD2_VSEL_table[] = {
55 0, 600, 600, 600, 612, 625, 637, 650,
56 662, 675, 687, 700, 712, 725, 737, 750,
57 762, 775, 787, 800, 812, 825, 837, 850,
58 862, 875, 887, 900, 912, 925, 937, 950,
59 962, 975, 987, 1000, 1012, 1025, 1037, 1050,
60 1062, 1075, 1087, 1100, 1112, 1125, 1137, 1150,
61 1162, 1175, 1187, 1200, 1212, 1225, 1237, 1250,
62 1262, 1275, 1287, 1300, 1312, 1325, 1337, 1350,
63 1362, 1375, 1387, 1400, 1412, 1425, 1437, 1450,
64 1462, 1475, 1487, 1500,
68 static const u16 VDD3_VSEL_table[] = {
73 /* supported VDIG1 voltages in milivolts */
74 static const u16 VDIG1_VSEL_table[] = {
75 1200, 1500, 1800, 2700,
78 /* supported VDIG2 voltages in milivolts */
79 static const u16 VDIG2_VSEL_table[] = {
80 1000, 1100, 1200, 1800,
83 /* supported VPLL voltages in milivolts */
84 static const u16 VPLL_VSEL_table[] = {
85 1000, 1100, 1800, 2500,
88 /* supported VDAC voltages in milivolts */
89 static const u16 VDAC_VSEL_table[] = {
90 1800, 2600, 2800, 2850,
93 /* supported VAUX1 voltages in milivolts */
94 static const u16 VAUX1_VSEL_table[] = {
95 1800, 2500, 2800, 2850,
98 /* supported VAUX2 voltages in milivolts */
99 static const u16 VAUX2_VSEL_table[] = {
100 1800, 2800, 2900, 3300,
103 /* supported VAUX33 voltages in milivolts */
104 static const u16 VAUX33_VSEL_table[] = {
105 1800, 2000, 2800, 3300,
108 /* supported VMMC voltages in milivolts */
109 static const u16 VMMC_VSEL_table[] = {
110 1800, 2800, 3000, 3300,
118 const u16 *voltage_table;
122 static struct tps_info tps65910_regs[] = {
125 .enable_time_us = 2200,
131 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
132 .voltage_table = VIO_VSEL_table,
133 .enable_time_us = 350,
139 .n_voltages = ARRAY_SIZE(VDD1_VSEL_table),
140 .voltage_table = VDD1_VSEL_table,
141 .enable_time_us = 350,
147 .n_voltages = ARRAY_SIZE(VDD2_VSEL_table),
148 .voltage_table = VDD2_VSEL_table,
149 .enable_time_us = 350,
155 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
156 .voltage_table = VDD3_VSEL_table,
157 .enable_time_us = 200,
163 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
164 .voltage_table = VDIG1_VSEL_table,
165 .enable_time_us = 100,
171 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
172 .voltage_table = VDIG2_VSEL_table,
173 .enable_time_us = 100,
179 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
180 .voltage_table = VPLL_VSEL_table,
181 .enable_time_us = 100,
187 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
188 .voltage_table = VDAC_VSEL_table,
189 .enable_time_us = 100,
195 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
196 .voltage_table = VAUX1_VSEL_table,
197 .enable_time_us = 100,
203 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
204 .voltage_table = VAUX2_VSEL_table,
205 .enable_time_us = 100,
211 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
212 .voltage_table = VAUX33_VSEL_table,
213 .enable_time_us = 100,
219 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
220 .voltage_table = VMMC_VSEL_table,
221 .enable_time_us = 100,
225 static struct tps_info tps65911_regs[] = {
228 .enable_time_us = 2200,
234 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
235 .voltage_table = VIO_VSEL_table,
236 .enable_time_us = 350,
243 .enable_time_us = 350,
250 .enable_time_us = 350,
257 .enable_time_us = 900,
264 .enable_time_us = 420,
271 .enable_time_us = 420,
278 .enable_time_us = 230,
285 .enable_time_us = 230,
292 .enable_time_us = 230,
299 .enable_time_us = 230,
306 .enable_time_us = 230,
313 .enable_time_us = 230,
317 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
318 static unsigned int tps65910_ext_sleep_control[] = {
320 EXT_CONTROL_REG_BITS(VIO, 1, 0),
321 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
322 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
323 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
324 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
325 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
326 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
327 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
328 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
329 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
330 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
331 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
334 static unsigned int tps65911_ext_sleep_control[] = {
336 EXT_CONTROL_REG_BITS(VIO, 1, 0),
337 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
338 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
339 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
340 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
341 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
342 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
343 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
344 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
345 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
346 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
347 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
350 struct tps65910_reg {
351 struct regulator_desc *desc;
352 struct tps65910 *mfd;
353 struct regulator_dev **rdev;
354 struct tps_info **info;
358 int (*get_ctrl_reg)(int);
359 unsigned int *ext_sleep_control;
360 unsigned int board_ext_control[TPS65910_NUM_REGS];
363 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
368 err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
375 static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
377 return pmic->mfd->write(pmic->mfd, reg, 1, &val);
380 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
381 u8 set_mask, u8 clear_mask)
385 mutex_lock(&pmic->mutex);
387 data = tps65910_read(pmic, reg);
389 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
396 err = tps65910_write(pmic, reg, data);
398 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
401 mutex_unlock(&pmic->mutex);
405 static int tps65910_pmic_reg_read(struct tps65910_reg *pmic, u8 reg)
409 mutex_lock(&pmic->mutex);
411 data = tps65910_read(pmic, reg);
413 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
415 mutex_unlock(&pmic->mutex);
419 static int tps65910_pmic_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
423 mutex_lock(&pmic->mutex);
425 err = tps65910_write(pmic, reg, val);
427 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
429 mutex_unlock(&pmic->mutex);
433 static int tps65910_get_ctrl_register(int id)
436 case TPS65910_REG_VRTC:
437 return TPS65910_VRTC;
438 case TPS65910_REG_VIO:
440 case TPS65910_REG_VDD1:
441 return TPS65910_VDD1;
442 case TPS65910_REG_VDD2:
443 return TPS65910_VDD2;
444 case TPS65910_REG_VDD3:
445 return TPS65910_VDD3;
446 case TPS65910_REG_VDIG1:
447 return TPS65910_VDIG1;
448 case TPS65910_REG_VDIG2:
449 return TPS65910_VDIG2;
450 case TPS65910_REG_VPLL:
451 return TPS65910_VPLL;
452 case TPS65910_REG_VDAC:
453 return TPS65910_VDAC;
454 case TPS65910_REG_VAUX1:
455 return TPS65910_VAUX1;
456 case TPS65910_REG_VAUX2:
457 return TPS65910_VAUX2;
458 case TPS65910_REG_VAUX33:
459 return TPS65910_VAUX33;
460 case TPS65910_REG_VMMC:
461 return TPS65910_VMMC;
467 static int tps65911_get_ctrl_register(int id)
470 case TPS65910_REG_VRTC:
471 return TPS65910_VRTC;
472 case TPS65910_REG_VIO:
474 case TPS65910_REG_VDD1:
475 return TPS65910_VDD1;
476 case TPS65910_REG_VDD2:
477 return TPS65910_VDD2;
478 case TPS65911_REG_VDDCTRL:
479 return TPS65911_VDDCTRL;
480 case TPS65911_REG_LDO1:
481 return TPS65911_LDO1;
482 case TPS65911_REG_LDO2:
483 return TPS65911_LDO2;
484 case TPS65911_REG_LDO3:
485 return TPS65911_LDO3;
486 case TPS65911_REG_LDO4:
487 return TPS65911_LDO4;
488 case TPS65911_REG_LDO5:
489 return TPS65911_LDO5;
490 case TPS65911_REG_LDO6:
491 return TPS65911_LDO6;
492 case TPS65911_REG_LDO7:
493 return TPS65911_LDO7;
494 case TPS65911_REG_LDO8:
495 return TPS65911_LDO8;
501 static int tps65910_is_enabled(struct regulator_dev *dev)
503 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
504 int reg, value, id = rdev_get_id(dev);
506 reg = pmic->get_ctrl_reg(id);
510 value = tps65910_pmic_reg_read(pmic, reg);
514 return value & TPS65910_SUPPLY_STATE_ENABLED;
517 static int tps65910_enable(struct regulator_dev *dev)
519 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
520 struct tps65910 *mfd = pmic->mfd;
521 int reg, id = rdev_get_id(dev);
523 reg = pmic->get_ctrl_reg(id);
527 return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
530 static int tps65910_disable(struct regulator_dev *dev)
532 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
533 struct tps65910 *mfd = pmic->mfd;
534 int reg, id = rdev_get_id(dev);
536 reg = pmic->get_ctrl_reg(id);
540 return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
543 static int tps65910_enable_time(struct regulator_dev *dev)
545 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
546 int id = rdev_get_id(dev);
547 return pmic->info[id]->enable_time_us;
550 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
552 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
553 struct tps65910 *mfd = pmic->mfd;
554 int reg, value, id = rdev_get_id(dev);
556 reg = pmic->get_ctrl_reg(id);
561 case REGULATOR_MODE_NORMAL:
562 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
564 case REGULATOR_MODE_IDLE:
565 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
566 return tps65910_set_bits(mfd, reg, value);
567 case REGULATOR_MODE_STANDBY:
568 return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
574 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
576 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
577 int reg, value, id = rdev_get_id(dev);
579 reg = pmic->get_ctrl_reg(id);
583 value = tps65910_pmic_reg_read(pmic, reg);
587 if (!(value & LDO_ST_ON_BIT))
588 return REGULATOR_MODE_STANDBY;
589 else if (value & LDO_ST_MODE_BIT)
590 return REGULATOR_MODE_IDLE;
592 return REGULATOR_MODE_NORMAL;
595 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
597 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
598 int id = rdev_get_id(dev);
599 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
602 case TPS65910_REG_VDD1:
603 opvsel = tps65910_pmic_reg_read(pmic, TPS65910_VDD1_OP);
604 mult = tps65910_pmic_reg_read(pmic, TPS65910_VDD1);
605 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
606 srvsel = tps65910_pmic_reg_read(pmic, TPS65910_VDD1_SR);
607 sr = opvsel & VDD1_OP_CMD_MASK;
608 opvsel &= VDD1_OP_SEL_MASK;
609 srvsel &= VDD1_SR_SEL_MASK;
612 case TPS65910_REG_VDD2:
613 opvsel = tps65910_pmic_reg_read(pmic, TPS65910_VDD2_OP);
614 mult = tps65910_pmic_reg_read(pmic, TPS65910_VDD2);
615 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
616 srvsel = tps65910_pmic_reg_read(pmic, TPS65910_VDD2_SR);
617 sr = opvsel & VDD2_OP_CMD_MASK;
618 opvsel &= VDD2_OP_SEL_MASK;
619 srvsel &= VDD2_SR_SEL_MASK;
622 case TPS65911_REG_VDDCTRL:
623 opvsel = tps65910_pmic_reg_read(pmic, TPS65911_VDDCTRL_OP);
624 srvsel = tps65910_pmic_reg_read(pmic, TPS65911_VDDCTRL_SR);
625 sr = opvsel & VDDCTRL_OP_CMD_MASK;
626 opvsel &= VDDCTRL_OP_SEL_MASK;
627 srvsel &= VDDCTRL_SR_SEL_MASK;
632 /* multiplier 0 == 1 but 2,3 normal */
637 /* normalise to valid range */
640 if (srvsel > vselmax)
645 /* normalise to valid range*/
648 if (opvsel > vselmax)
655 static int tps65910_get_voltage(struct regulator_dev *dev)
657 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
658 int reg, value, id = rdev_get_id(dev), voltage = 0;
660 reg = pmic->get_ctrl_reg(id);
664 value = tps65910_pmic_reg_read(pmic, reg);
669 case TPS65910_REG_VIO:
670 case TPS65910_REG_VDIG1:
671 case TPS65910_REG_VDIG2:
672 case TPS65910_REG_VPLL:
673 case TPS65910_REG_VDAC:
674 case TPS65910_REG_VAUX1:
675 case TPS65910_REG_VAUX2:
676 case TPS65910_REG_VAUX33:
677 case TPS65910_REG_VMMC:
678 value &= LDO_SEL_MASK;
679 value >>= LDO_SEL_SHIFT;
685 voltage = pmic->info[id]->voltage_table[value] * 1000;
690 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
692 return 5 * 1000 * 1000;
695 static int tps65911_get_voltage(struct regulator_dev *dev)
697 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
698 int step_mv, id = rdev_get_id(dev);
701 reg = pmic->get_ctrl_reg(id);
703 value = tps65910_pmic_reg_read(pmic, reg);
706 case TPS65911_REG_LDO1:
707 case TPS65911_REG_LDO2:
708 case TPS65911_REG_LDO4:
709 value &= LDO1_SEL_MASK;
710 value >>= LDO_SEL_SHIFT;
711 /* The first 5 values of the selector correspond to 1V */
719 case TPS65911_REG_LDO3:
720 case TPS65911_REG_LDO5:
721 case TPS65911_REG_LDO6:
722 case TPS65911_REG_LDO7:
723 case TPS65911_REG_LDO8:
724 value &= LDO3_SEL_MASK;
725 value >>= LDO_SEL_SHIFT;
726 /* The first 3 values of the selector correspond to 1V */
734 case TPS65910_REG_VIO:
735 value &= LDO_SEL_MASK;
736 value >>= LDO_SEL_SHIFT;
737 return pmic->info[id]->voltage_table[value] * 1000;
742 return (LDO_MIN_VOLT + value * step_mv) * 1000;
745 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
748 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
749 int id = rdev_get_id(dev), vsel;
753 case TPS65910_REG_VDD1:
754 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
757 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
759 tps65910_modify_bits(pmic, TPS65910_VDD1,
760 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
761 VDD1_VGAIN_SEL_MASK);
762 tps65910_pmic_reg_write(pmic, TPS65910_VDD1_OP, vsel);
764 case TPS65910_REG_VDD2:
765 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
768 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
770 tps65910_modify_bits(pmic, TPS65910_VDD2,
771 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
772 VDD1_VGAIN_SEL_MASK);
773 tps65910_pmic_reg_write(pmic, TPS65910_VDD2_OP, vsel);
775 case TPS65911_REG_VDDCTRL:
777 tps65910_pmic_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
783 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
786 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
787 int reg, id = rdev_get_id(dev);
789 reg = pmic->get_ctrl_reg(id);
794 case TPS65910_REG_VIO:
795 case TPS65910_REG_VDIG1:
796 case TPS65910_REG_VDIG2:
797 case TPS65910_REG_VPLL:
798 case TPS65910_REG_VDAC:
799 case TPS65910_REG_VAUX1:
800 case TPS65910_REG_VAUX2:
801 case TPS65910_REG_VAUX33:
802 case TPS65910_REG_VMMC:
803 return tps65910_modify_bits(pmic, reg,
804 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
810 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
813 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
814 int reg, id = rdev_get_id(dev);
816 reg = pmic->get_ctrl_reg(id);
821 case TPS65911_REG_LDO1:
822 case TPS65911_REG_LDO2:
823 case TPS65911_REG_LDO4:
824 return tps65910_modify_bits(pmic, reg,
825 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
826 case TPS65911_REG_LDO3:
827 case TPS65911_REG_LDO5:
828 case TPS65911_REG_LDO6:
829 case TPS65911_REG_LDO7:
830 case TPS65911_REG_LDO8:
831 return tps65910_modify_bits(pmic, reg,
832 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
833 case TPS65910_REG_VIO:
834 return tps65910_modify_bits(pmic, reg,
835 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
842 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
845 int volt, mult = 1, id = rdev_get_id(dev);
848 case TPS65910_REG_VDD1:
849 case TPS65910_REG_VDD2:
850 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
851 volt = VDD1_2_MIN_VOLT +
852 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
854 case TPS65911_REG_VDDCTRL:
855 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
862 return volt * 100 * mult;
865 static int tps65910_list_voltage(struct regulator_dev *dev,
868 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
869 int id = rdev_get_id(dev), voltage;
871 if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
874 if (selector >= pmic->info[id]->n_voltages)
877 voltage = pmic->info[id]->voltage_table[selector] * 1000;
882 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
884 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
885 int step_mv = 0, id = rdev_get_id(dev);
888 case TPS65911_REG_LDO1:
889 case TPS65911_REG_LDO2:
890 case TPS65911_REG_LDO4:
891 /* The first 5 values of the selector correspond to 1V */
899 case TPS65911_REG_LDO3:
900 case TPS65911_REG_LDO5:
901 case TPS65911_REG_LDO6:
902 case TPS65911_REG_LDO7:
903 case TPS65911_REG_LDO8:
904 /* The first 3 values of the selector correspond to 1V */
912 case TPS65910_REG_VIO:
913 return pmic->info[id]->voltage_table[selector] * 1000;
918 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
921 static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev,
922 unsigned int old_selector, unsigned int new_selector)
924 int id = rdev_get_id(dev);
925 int old_volt, new_volt;
927 old_volt = tps65910_list_voltage_dcdc(dev, old_selector);
931 new_volt = tps65910_list_voltage_dcdc(dev, new_selector);
935 /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
937 case TPS65910_REG_VDD1:
938 case TPS65910_REG_VDD2:
939 return DIV_ROUND_UP(abs(old_volt - new_volt)*2, 12500);
940 case TPS65911_REG_VDDCTRL:
941 return DIV_ROUND_UP(abs(old_volt - new_volt), 5000);
946 /* Regulator ops (except VRTC) */
947 static struct regulator_ops tps65910_ops_dcdc = {
948 .is_enabled = tps65910_is_enabled,
949 .enable = tps65910_enable,
950 .disable = tps65910_disable,
951 .enable_time = tps65910_enable_time,
952 .set_mode = tps65910_set_mode,
953 .get_mode = tps65910_get_mode,
954 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
955 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
956 .set_voltage_time_sel = tps65910_set_voltage_dcdc_time_sel,
957 .list_voltage = tps65910_list_voltage_dcdc,
960 static struct regulator_ops tps65910_ops_vdd3 = {
961 .is_enabled = tps65910_is_enabled,
962 .enable = tps65910_enable,
963 .disable = tps65910_disable,
964 .enable_time = tps65910_enable_time,
965 .set_mode = tps65910_set_mode,
966 .get_mode = tps65910_get_mode,
967 .get_voltage = tps65910_get_voltage_vdd3,
968 .list_voltage = tps65910_list_voltage,
971 static struct regulator_ops tps65910_ops = {
972 .is_enabled = tps65910_is_enabled,
973 .enable = tps65910_enable,
974 .disable = tps65910_disable,
975 .enable_time = tps65910_enable_time,
976 .set_mode = tps65910_set_mode,
977 .get_mode = tps65910_get_mode,
978 .get_voltage = tps65910_get_voltage,
979 .set_voltage_sel = tps65910_set_voltage_sel,
980 .list_voltage = tps65910_list_voltage,
983 static struct regulator_ops tps65911_ops = {
984 .is_enabled = tps65910_is_enabled,
985 .enable = tps65910_enable,
986 .disable = tps65910_disable,
987 .enable_time = tps65910_enable_time,
988 .set_mode = tps65910_set_mode,
989 .get_mode = tps65910_get_mode,
990 .get_voltage = tps65911_get_voltage,
991 .set_voltage_sel = tps65911_set_voltage_sel,
992 .list_voltage = tps65911_list_voltage,
995 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
996 int id, int ext_sleep_config)
998 struct tps65910 *mfd = pmic->mfd;
999 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
1000 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
1004 * Regulator can not be control from multiple external input EN1, EN2
1007 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
1009 en_count = ((ext_sleep_config &
1010 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
1011 en_count += ((ext_sleep_config &
1012 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
1013 en_count += ((ext_sleep_config &
1014 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
1015 en_count += ((ext_sleep_config &
1016 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
1019 "External sleep control flag is not proper\n");
1024 pmic->board_ext_control[id] = ext_sleep_config;
1026 /* External EN1 control */
1027 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
1028 ret = tps65910_set_bits(mfd,
1029 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
1031 ret = tps65910_clear_bits(mfd,
1032 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
1035 "Error in configuring external control EN1\n");
1039 /* External EN2 control */
1040 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
1041 ret = tps65910_set_bits(mfd,
1042 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
1044 ret = tps65910_clear_bits(mfd,
1045 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
1048 "Error in configuring external control EN2\n");
1052 /* External EN3 control for TPS65910 LDO only */
1053 if ((tps65910_chip_id(mfd) == TPS65910) &&
1054 (id >= TPS65910_REG_VDIG1)) {
1055 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
1056 ret = tps65910_set_bits(mfd,
1057 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
1059 ret = tps65910_clear_bits(mfd,
1060 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
1063 "Error in configuring external control EN3\n");
1068 /* Return if no external control is selected */
1069 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
1070 /* Clear all sleep controls */
1071 ret = tps65910_clear_bits(mfd,
1072 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
1074 ret = tps65910_clear_bits(mfd,
1075 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1078 "Error in configuring SLEEP register\n");
1083 * For regulator that has separate operational and sleep register make
1084 * sure that operational is used and clear sleep register to turn
1085 * regulator off when external control is inactive
1087 if ((id == TPS65910_REG_VDD1) ||
1088 (id == TPS65910_REG_VDD2) ||
1089 ((id == TPS65911_REG_VDDCTRL) &&
1090 (tps65910_chip_id(mfd) == TPS65911))) {
1091 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
1092 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
1093 int opvsel = tps65910_pmic_reg_read(pmic, op_reg_add);
1094 int srvsel = tps65910_pmic_reg_read(pmic, sr_reg_add);
1095 if (opvsel & VDD1_OP_CMD_MASK) {
1096 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
1097 ret = tps65910_pmic_reg_write(pmic, op_reg_add, reg_val);
1100 "Error in configuring op register\n");
1104 ret = tps65910_pmic_reg_write(pmic, sr_reg_add, 0);
1106 dev_err(mfd->dev, "Error in settting sr register\n");
1111 ret = tps65910_clear_bits(mfd,
1112 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
1114 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
1115 ret = tps65910_set_bits(mfd,
1116 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1118 ret = tps65910_clear_bits(mfd,
1119 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1123 "Error in configuring SLEEP register\n");
1128 static __devinit int tps65910_probe(struct platform_device *pdev)
1130 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1131 struct tps_info *info;
1132 struct regulator_init_data *reg_data;
1133 struct regulator_dev *rdev;
1134 struct tps65910_reg *pmic;
1135 struct tps65910_board *pmic_plat_data;
1138 pmic_plat_data = dev_get_platdata(tps65910->dev);
1139 if (!pmic_plat_data)
1142 pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
1146 mutex_init(&pmic->mutex);
1147 pmic->mfd = tps65910;
1148 platform_set_drvdata(pdev, pmic);
1150 /* Give control of all register to control port */
1151 tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1152 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1154 switch(tps65910_chip_id(tps65910)) {
1156 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1157 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1158 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1159 info = tps65910_regs;
1162 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1163 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1164 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1165 info = tps65911_regs;
1168 pr_err("Invalid tps chip version\n");
1173 pmic->desc = kcalloc(pmic->num_regulators,
1174 sizeof(struct regulator_desc), GFP_KERNEL);
1180 pmic->info = kcalloc(pmic->num_regulators,
1181 sizeof(struct tps_info *), GFP_KERNEL);
1187 pmic->rdev = kcalloc(pmic->num_regulators,
1188 sizeof(struct regulator_dev *), GFP_KERNEL);
1194 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1197 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1199 /* Regulator API handles empty constraints but not NULL
1204 /* Register the regulators */
1205 pmic->info[i] = info;
1207 pmic->desc[i].name = info->name;
1208 pmic->desc[i].id = i;
1209 pmic->desc[i].n_voltages = info->n_voltages;
1211 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1212 pmic->desc[i].ops = &tps65910_ops_dcdc;
1213 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1214 VDD1_2_NUM_VOLT_COARSE;
1215 } else if (i == TPS65910_REG_VDD3) {
1216 if (tps65910_chip_id(tps65910) == TPS65910)
1217 pmic->desc[i].ops = &tps65910_ops_vdd3;
1219 pmic->desc[i].ops = &tps65910_ops_dcdc;
1221 if (tps65910_chip_id(tps65910) == TPS65910)
1222 pmic->desc[i].ops = &tps65910_ops;
1224 pmic->desc[i].ops = &tps65911_ops;
1227 err = tps65910_set_ext_sleep_config(pmic, i,
1228 pmic_plat_data->regulator_ext_sleep_control[i]);
1230 * Failing on regulator for configuring externally control
1231 * is not a serious issue, just throw warning.
1234 dev_warn(tps65910->dev,
1235 "Failed to initialise ext control config\n");
1237 pmic->desc[i].type = REGULATOR_VOLTAGE;
1238 pmic->desc[i].owner = THIS_MODULE;
1240 rdev = regulator_register(&pmic->desc[i],
1241 tps65910->dev, reg_data, pmic);
1243 dev_err(tps65910->dev,
1244 "failed to register %s regulator\n",
1246 err = PTR_ERR(rdev);
1247 goto err_unregister_regulator;
1250 /* Save regulator for cleanup */
1251 pmic->rdev[i] = rdev;
1255 err_unregister_regulator:
1257 regulator_unregister(pmic->rdev[i]);
1268 static int __devexit tps65910_remove(struct platform_device *pdev)
1270 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1273 for (i = 0; i < pmic->num_regulators; i++)
1274 regulator_unregister(pmic->rdev[i]);
1283 static void tps65910_shutdown(struct platform_device *pdev)
1285 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1289 * Before bootloader jumps to kernel, it makes sure that required
1290 * external control signals are in desired state so that given rails
1291 * can be configure accordingly.
1292 * If rails are configured to be controlled from external control
1293 * then before shutting down/rebooting the system, the external
1294 * control configuration need to be remove from the rails so that
1295 * its output will be available as per register programming even
1296 * if external controls are removed. This is require when the POR
1297 * value of the control signals are not in active state and before
1298 * bootloader initializes it, the system requires the rail output
1299 * to be active for booting.
1301 for (i = 0; i < pmic->num_regulators; i++) {
1306 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1309 "Error in clearing external control\n");
1313 static struct platform_driver tps65910_driver = {
1315 .name = "tps65910-pmic",
1316 .owner = THIS_MODULE,
1318 .probe = tps65910_probe,
1319 .remove = __devexit_p(tps65910_remove),
1320 .shutdown = tps65910_shutdown,
1323 static int __init tps65910_init(void)
1325 return platform_driver_register(&tps65910_driver);
1327 subsys_initcall_sync(tps65910_init);
1329 static void __exit tps65910_cleanup(void)
1331 platform_driver_unregister(&tps65910_driver);
1333 module_exit(tps65910_cleanup);
1335 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1336 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1337 MODULE_LICENSE("GPL v2");
1338 MODULE_ALIAS("platform:tps65910-pmic");