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/slab.h>
24 #include <linux/gpio.h>
25 #include <linux/mfd/tps65910.h>
26 #include <linux/regulator/of_regulator.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 millivolts */
35 static const u16 VIO_VSEL_table[] = {
36 1500, 1800, 2500, 3300,
39 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
41 /* supported VDD3 voltages in millivolts */
42 static const u16 VDD3_VSEL_table[] = {
46 /* supported VDIG1 voltages in millivolts */
47 static const u16 VDIG1_VSEL_table[] = {
48 1200, 1500, 1800, 2700,
51 /* supported VDIG2 voltages in millivolts */
52 static const u16 VDIG2_VSEL_table[] = {
53 1000, 1100, 1200, 1800,
56 /* supported VPLL voltages in millivolts */
57 static const u16 VPLL_VSEL_table[] = {
58 1000, 1100, 1800, 2500,
61 /* supported VDAC voltages in millivolts */
62 static const u16 VDAC_VSEL_table[] = {
63 1800, 2600, 2800, 2850,
66 /* supported VAUX1 voltages in millivolts */
67 static const u16 VAUX1_VSEL_table[] = {
68 1800, 2500, 2800, 2850,
71 /* supported VAUX2 voltages in millivolts */
72 static const u16 VAUX2_VSEL_table[] = {
73 1800, 2800, 2900, 3300,
76 /* supported VAUX33 voltages in millivolts */
77 static const u16 VAUX33_VSEL_table[] = {
78 1800, 2000, 2800, 3300,
81 /* supported VMMC voltages in millivolts */
82 static const u16 VMMC_VSEL_table[] = {
83 1800, 2800, 3000, 3300,
91 const u16 *voltage_table;
95 static struct tps_info tps65910_regs[] = {
98 .enable_time_us = 2200,
104 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
105 .voltage_table = VIO_VSEL_table,
106 .enable_time_us = 350,
112 .enable_time_us = 350,
118 .enable_time_us = 350,
124 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
125 .voltage_table = VDD3_VSEL_table,
126 .enable_time_us = 200,
132 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
133 .voltage_table = VDIG1_VSEL_table,
134 .enable_time_us = 100,
140 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
141 .voltage_table = VDIG2_VSEL_table,
142 .enable_time_us = 100,
148 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
149 .voltage_table = VPLL_VSEL_table,
150 .enable_time_us = 100,
156 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
157 .voltage_table = VDAC_VSEL_table,
158 .enable_time_us = 100,
164 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
165 .voltage_table = VAUX1_VSEL_table,
166 .enable_time_us = 100,
172 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
173 .voltage_table = VAUX2_VSEL_table,
174 .enable_time_us = 100,
180 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
181 .voltage_table = VAUX33_VSEL_table,
182 .enable_time_us = 100,
188 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
189 .voltage_table = VMMC_VSEL_table,
190 .enable_time_us = 100,
194 static struct tps_info tps65911_regs[] = {
197 .enable_time_us = 2200,
203 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
204 .voltage_table = VIO_VSEL_table,
205 .enable_time_us = 350,
212 .enable_time_us = 350,
219 .enable_time_us = 350,
226 .enable_time_us = 900,
233 .enable_time_us = 420,
240 .enable_time_us = 420,
247 .enable_time_us = 230,
254 .enable_time_us = 230,
261 .enable_time_us = 230,
268 .enable_time_us = 230,
275 .enable_time_us = 230,
282 .enable_time_us = 230,
286 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
287 static unsigned int tps65910_ext_sleep_control[] = {
289 EXT_CONTROL_REG_BITS(VIO, 1, 0),
290 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
291 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
292 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
293 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
294 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
295 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
296 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
297 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
298 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
299 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
300 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
303 static unsigned int tps65911_ext_sleep_control[] = {
305 EXT_CONTROL_REG_BITS(VIO, 1, 0),
306 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
307 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
308 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
309 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
310 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
311 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
312 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
313 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
314 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
315 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
316 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
319 struct tps65910_reg {
320 struct regulator_desc *desc;
321 struct tps65910 *mfd;
322 struct regulator_dev **rdev;
323 struct tps_info **info;
327 int (*get_ctrl_reg)(int);
328 unsigned int *ext_sleep_control;
329 unsigned int board_ext_control[TPS65910_NUM_REGS];
332 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
337 err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
344 static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
346 return pmic->mfd->write(pmic->mfd, reg, 1, &val);
349 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
350 u8 set_mask, u8 clear_mask)
354 mutex_lock(&pmic->mutex);
356 data = tps65910_read(pmic, reg);
358 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
365 err = tps65910_write(pmic, reg, data);
367 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
370 mutex_unlock(&pmic->mutex);
374 static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
378 mutex_lock(&pmic->mutex);
380 data = tps65910_read(pmic, reg);
382 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
384 mutex_unlock(&pmic->mutex);
388 static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
392 mutex_lock(&pmic->mutex);
394 err = tps65910_write(pmic, reg, val);
396 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
398 mutex_unlock(&pmic->mutex);
402 static int tps65910_get_ctrl_register(int id)
405 case TPS65910_REG_VRTC:
406 return TPS65910_VRTC;
407 case TPS65910_REG_VIO:
409 case TPS65910_REG_VDD1:
410 return TPS65910_VDD1;
411 case TPS65910_REG_VDD2:
412 return TPS65910_VDD2;
413 case TPS65910_REG_VDD3:
414 return TPS65910_VDD3;
415 case TPS65910_REG_VDIG1:
416 return TPS65910_VDIG1;
417 case TPS65910_REG_VDIG2:
418 return TPS65910_VDIG2;
419 case TPS65910_REG_VPLL:
420 return TPS65910_VPLL;
421 case TPS65910_REG_VDAC:
422 return TPS65910_VDAC;
423 case TPS65910_REG_VAUX1:
424 return TPS65910_VAUX1;
425 case TPS65910_REG_VAUX2:
426 return TPS65910_VAUX2;
427 case TPS65910_REG_VAUX33:
428 return TPS65910_VAUX33;
429 case TPS65910_REG_VMMC:
430 return TPS65910_VMMC;
436 static int tps65911_get_ctrl_register(int id)
439 case TPS65910_REG_VRTC:
440 return TPS65910_VRTC;
441 case TPS65910_REG_VIO:
443 case TPS65910_REG_VDD1:
444 return TPS65910_VDD1;
445 case TPS65910_REG_VDD2:
446 return TPS65910_VDD2;
447 case TPS65911_REG_VDDCTRL:
448 return TPS65911_VDDCTRL;
449 case TPS65911_REG_LDO1:
450 return TPS65911_LDO1;
451 case TPS65911_REG_LDO2:
452 return TPS65911_LDO2;
453 case TPS65911_REG_LDO3:
454 return TPS65911_LDO3;
455 case TPS65911_REG_LDO4:
456 return TPS65911_LDO4;
457 case TPS65911_REG_LDO5:
458 return TPS65911_LDO5;
459 case TPS65911_REG_LDO6:
460 return TPS65911_LDO6;
461 case TPS65911_REG_LDO7:
462 return TPS65911_LDO7;
463 case TPS65911_REG_LDO8:
464 return TPS65911_LDO8;
470 static int tps65910_enable_time(struct regulator_dev *dev)
472 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
473 int id = rdev_get_id(dev);
474 return pmic->info[id]->enable_time_us;
477 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
479 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
480 struct tps65910 *mfd = pmic->mfd;
481 int reg, value, id = rdev_get_id(dev);
483 reg = pmic->get_ctrl_reg(id);
488 case REGULATOR_MODE_NORMAL:
489 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
491 case REGULATOR_MODE_IDLE:
492 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
493 return tps65910_set_bits(mfd, reg, value);
494 case REGULATOR_MODE_STANDBY:
495 return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
501 static unsigned int tps65910_get_mode(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_reg_read(pmic, reg);
514 if (!(value & LDO_ST_ON_BIT))
515 return REGULATOR_MODE_STANDBY;
516 else if (value & LDO_ST_MODE_BIT)
517 return REGULATOR_MODE_IDLE;
519 return REGULATOR_MODE_NORMAL;
522 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
524 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
525 int id = rdev_get_id(dev);
526 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
529 case TPS65910_REG_VDD1:
530 opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
531 mult = tps65910_reg_read(pmic, TPS65910_VDD1);
532 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
533 srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
534 sr = opvsel & VDD1_OP_CMD_MASK;
535 opvsel &= VDD1_OP_SEL_MASK;
536 srvsel &= VDD1_SR_SEL_MASK;
539 case TPS65910_REG_VDD2:
540 opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
541 mult = tps65910_reg_read(pmic, TPS65910_VDD2);
542 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
543 srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
544 sr = opvsel & VDD2_OP_CMD_MASK;
545 opvsel &= VDD2_OP_SEL_MASK;
546 srvsel &= VDD2_SR_SEL_MASK;
549 case TPS65911_REG_VDDCTRL:
550 opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
551 srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
552 sr = opvsel & VDDCTRL_OP_CMD_MASK;
553 opvsel &= VDDCTRL_OP_SEL_MASK;
554 srvsel &= VDDCTRL_SR_SEL_MASK;
559 /* multiplier 0 == 1 but 2,3 normal */
564 /* normalise to valid range */
567 if (srvsel > vselmax)
572 /* normalise to valid range*/
575 if (opvsel > vselmax)
582 static int tps65910_get_voltage_sel(struct regulator_dev *dev)
584 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
585 int reg, value, id = rdev_get_id(dev);
587 reg = pmic->get_ctrl_reg(id);
591 value = tps65910_reg_read(pmic, reg);
596 case TPS65910_REG_VIO:
597 case TPS65910_REG_VDIG1:
598 case TPS65910_REG_VDIG2:
599 case TPS65910_REG_VPLL:
600 case TPS65910_REG_VDAC:
601 case TPS65910_REG_VAUX1:
602 case TPS65910_REG_VAUX2:
603 case TPS65910_REG_VAUX33:
604 case TPS65910_REG_VMMC:
605 value &= LDO_SEL_MASK;
606 value >>= LDO_SEL_SHIFT;
615 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
617 return 5 * 1000 * 1000;
620 static int tps65911_get_voltage_sel(struct regulator_dev *dev)
622 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
623 int id = rdev_get_id(dev);
626 reg = pmic->get_ctrl_reg(id);
628 value = tps65910_reg_read(pmic, reg);
631 case TPS65911_REG_LDO1:
632 case TPS65911_REG_LDO2:
633 case TPS65911_REG_LDO4:
634 value &= LDO1_SEL_MASK;
635 value >>= LDO_SEL_SHIFT;
637 case TPS65911_REG_LDO3:
638 case TPS65911_REG_LDO5:
639 case TPS65911_REG_LDO6:
640 case TPS65911_REG_LDO7:
641 case TPS65911_REG_LDO8:
642 value &= LDO3_SEL_MASK;
643 value >>= LDO_SEL_SHIFT;
645 case TPS65910_REG_VIO:
646 value &= LDO_SEL_MASK;
647 value >>= LDO_SEL_SHIFT;
656 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
659 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
660 int id = rdev_get_id(dev), vsel;
664 case TPS65910_REG_VDD1:
665 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
668 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
670 tps65910_modify_bits(pmic, TPS65910_VDD1,
671 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
672 VDD1_VGAIN_SEL_MASK);
673 tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
675 case TPS65910_REG_VDD2:
676 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
679 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
681 tps65910_modify_bits(pmic, TPS65910_VDD2,
682 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
683 VDD1_VGAIN_SEL_MASK);
684 tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
686 case TPS65911_REG_VDDCTRL:
688 tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
694 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
697 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
698 int reg, id = rdev_get_id(dev);
700 reg = pmic->get_ctrl_reg(id);
705 case TPS65910_REG_VIO:
706 case TPS65910_REG_VDIG1:
707 case TPS65910_REG_VDIG2:
708 case TPS65910_REG_VPLL:
709 case TPS65910_REG_VDAC:
710 case TPS65910_REG_VAUX1:
711 case TPS65910_REG_VAUX2:
712 case TPS65910_REG_VAUX33:
713 case TPS65910_REG_VMMC:
714 return tps65910_modify_bits(pmic, reg,
715 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
721 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
724 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
725 int reg, id = rdev_get_id(dev);
727 reg = pmic->get_ctrl_reg(id);
732 case TPS65911_REG_LDO1:
733 case TPS65911_REG_LDO2:
734 case TPS65911_REG_LDO4:
735 return tps65910_modify_bits(pmic, reg,
736 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
737 case TPS65911_REG_LDO3:
738 case TPS65911_REG_LDO5:
739 case TPS65911_REG_LDO6:
740 case TPS65911_REG_LDO7:
741 case TPS65911_REG_LDO8:
742 return tps65910_modify_bits(pmic, reg,
743 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
744 case TPS65910_REG_VIO:
745 return tps65910_modify_bits(pmic, reg,
746 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
753 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
756 int volt, mult = 1, id = rdev_get_id(dev);
759 case TPS65910_REG_VDD1:
760 case TPS65910_REG_VDD2:
761 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
762 volt = VDD1_2_MIN_VOLT +
763 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
765 case TPS65911_REG_VDDCTRL:
766 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
773 return volt * 100 * mult;
776 static int tps65910_list_voltage(struct regulator_dev *dev,
779 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
780 int id = rdev_get_id(dev), voltage;
782 if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
785 if (selector >= pmic->info[id]->n_voltages)
788 voltage = pmic->info[id]->voltage_table[selector] * 1000;
793 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
795 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
796 int step_mv = 0, id = rdev_get_id(dev);
799 case TPS65911_REG_LDO1:
800 case TPS65911_REG_LDO2:
801 case TPS65911_REG_LDO4:
802 /* The first 5 values of the selector correspond to 1V */
810 case TPS65911_REG_LDO3:
811 case TPS65911_REG_LDO5:
812 case TPS65911_REG_LDO6:
813 case TPS65911_REG_LDO7:
814 case TPS65911_REG_LDO8:
815 /* The first 3 values of the selector correspond to 1V */
823 case TPS65910_REG_VIO:
824 return pmic->info[id]->voltage_table[selector] * 1000;
829 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
832 static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev,
833 unsigned int old_selector, unsigned int new_selector)
835 int id = rdev_get_id(dev);
836 int old_volt, new_volt;
838 old_volt = tps65910_list_voltage_dcdc(dev, old_selector);
842 new_volt = tps65910_list_voltage_dcdc(dev, new_selector);
846 /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
848 case TPS65910_REG_VDD1:
849 case TPS65910_REG_VDD2:
850 return DIV_ROUND_UP(abs(old_volt - new_volt), 12500);
851 case TPS65911_REG_VDDCTRL:
852 return DIV_ROUND_UP(abs(old_volt - new_volt), 5000);
857 /* Regulator ops (except VRTC) */
858 static struct regulator_ops tps65910_ops_dcdc = {
859 .is_enabled = regulator_is_enabled_regmap,
860 .enable = regulator_enable_regmap,
861 .disable = regulator_disable_regmap,
862 .enable_time = tps65910_enable_time,
863 .set_mode = tps65910_set_mode,
864 .get_mode = tps65910_get_mode,
865 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
866 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
867 .set_voltage_time_sel = tps65910_set_voltage_dcdc_time_sel,
868 .list_voltage = tps65910_list_voltage_dcdc,
871 static struct regulator_ops tps65910_ops_vdd3 = {
872 .is_enabled = regulator_is_enabled_regmap,
873 .enable = regulator_enable_regmap,
874 .disable = regulator_disable_regmap,
875 .enable_time = tps65910_enable_time,
876 .set_mode = tps65910_set_mode,
877 .get_mode = tps65910_get_mode,
878 .get_voltage = tps65910_get_voltage_vdd3,
879 .list_voltage = tps65910_list_voltage,
882 static struct regulator_ops tps65910_ops = {
883 .is_enabled = regulator_is_enabled_regmap,
884 .enable = regulator_enable_regmap,
885 .disable = regulator_disable_regmap,
886 .enable_time = tps65910_enable_time,
887 .set_mode = tps65910_set_mode,
888 .get_mode = tps65910_get_mode,
889 .get_voltage_sel = tps65910_get_voltage_sel,
890 .set_voltage_sel = tps65910_set_voltage_sel,
891 .list_voltage = tps65910_list_voltage,
894 static struct regulator_ops tps65911_ops = {
895 .is_enabled = regulator_is_enabled_regmap,
896 .enable = regulator_enable_regmap,
897 .disable = regulator_disable_regmap,
898 .enable_time = tps65910_enable_time,
899 .set_mode = tps65910_set_mode,
900 .get_mode = tps65910_get_mode,
901 .get_voltage_sel = tps65911_get_voltage_sel,
902 .set_voltage_sel = tps65911_set_voltage_sel,
903 .list_voltage = tps65911_list_voltage,
906 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
907 int id, int ext_sleep_config)
909 struct tps65910 *mfd = pmic->mfd;
910 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
911 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
915 * Regulator can not be control from multiple external input EN1, EN2
918 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
920 en_count = ((ext_sleep_config &
921 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
922 en_count += ((ext_sleep_config &
923 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
924 en_count += ((ext_sleep_config &
925 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
926 en_count += ((ext_sleep_config &
927 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
930 "External sleep control flag is not proper\n");
935 pmic->board_ext_control[id] = ext_sleep_config;
937 /* External EN1 control */
938 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
939 ret = tps65910_set_bits(mfd,
940 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
942 ret = tps65910_clear_bits(mfd,
943 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
946 "Error in configuring external control EN1\n");
950 /* External EN2 control */
951 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
952 ret = tps65910_set_bits(mfd,
953 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
955 ret = tps65910_clear_bits(mfd,
956 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
959 "Error in configuring external control EN2\n");
963 /* External EN3 control for TPS65910 LDO only */
964 if ((tps65910_chip_id(mfd) == TPS65910) &&
965 (id >= TPS65910_REG_VDIG1)) {
966 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
967 ret = tps65910_set_bits(mfd,
968 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
970 ret = tps65910_clear_bits(mfd,
971 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
974 "Error in configuring external control EN3\n");
979 /* Return if no external control is selected */
980 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
981 /* Clear all sleep controls */
982 ret = tps65910_clear_bits(mfd,
983 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
985 ret = tps65910_clear_bits(mfd,
986 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
989 "Error in configuring SLEEP register\n");
994 * For regulator that has separate operational and sleep register make
995 * sure that operational is used and clear sleep register to turn
996 * regulator off when external control is inactive
998 if ((id == TPS65910_REG_VDD1) ||
999 (id == TPS65910_REG_VDD2) ||
1000 ((id == TPS65911_REG_VDDCTRL) &&
1001 (tps65910_chip_id(mfd) == TPS65911))) {
1002 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
1003 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
1004 int opvsel = tps65910_reg_read(pmic, op_reg_add);
1005 int srvsel = tps65910_reg_read(pmic, sr_reg_add);
1006 if (opvsel & VDD1_OP_CMD_MASK) {
1007 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
1008 ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
1011 "Error in configuring op register\n");
1015 ret = tps65910_reg_write(pmic, sr_reg_add, 0);
1017 dev_err(mfd->dev, "Error in settting sr register\n");
1022 ret = tps65910_clear_bits(mfd,
1023 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
1025 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
1026 ret = tps65910_set_bits(mfd,
1027 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1029 ret = tps65910_clear_bits(mfd,
1030 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
1034 "Error in configuring SLEEP register\n");
1041 static struct of_regulator_match tps65910_matches[] = {
1042 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
1043 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
1044 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
1045 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
1046 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
1047 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
1048 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
1049 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
1050 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
1051 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
1052 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
1053 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
1054 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
1057 static struct of_regulator_match tps65911_matches[] = {
1058 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
1059 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
1060 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
1061 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
1062 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
1063 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
1064 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
1065 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
1066 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
1067 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
1068 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
1069 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
1070 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
1073 static struct tps65910_board *tps65910_parse_dt_reg_data(
1074 struct platform_device *pdev,
1075 struct of_regulator_match **tps65910_reg_matches)
1077 struct tps65910_board *pmic_plat_data;
1078 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1079 struct device_node *np = pdev->dev.parent->of_node;
1080 struct device_node *regulators;
1081 struct of_regulator_match *matches;
1083 int idx = 0, ret, count;
1085 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
1088 if (!pmic_plat_data) {
1089 dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
1093 regulators = of_find_node_by_name(np, "regulators");
1095 dev_err(&pdev->dev, "regulator node not found\n");
1099 switch (tps65910_chip_id(tps65910)) {
1101 count = ARRAY_SIZE(tps65910_matches);
1102 matches = tps65910_matches;
1105 count = ARRAY_SIZE(tps65911_matches);
1106 matches = tps65911_matches;
1109 dev_err(&pdev->dev, "Invalid tps chip version\n");
1113 ret = of_regulator_match(pdev->dev.parent, regulators, matches, count);
1115 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1120 *tps65910_reg_matches = matches;
1122 for (idx = 0; idx < count; idx++) {
1123 if (!matches[idx].init_data || !matches[idx].of_node)
1126 pmic_plat_data->tps65910_pmic_init_data[idx] =
1127 matches[idx].init_data;
1129 ret = of_property_read_u32(matches[idx].of_node,
1130 "ti,regulator-ext-sleep-control", &prop);
1132 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1135 return pmic_plat_data;
1138 static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1139 struct platform_device *pdev,
1140 struct of_regulator_match **tps65910_reg_matches)
1142 *tps65910_reg_matches = NULL;
1147 static __devinit int tps65910_probe(struct platform_device *pdev)
1149 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1150 struct regulator_config config = { };
1151 struct tps_info *info;
1152 struct regulator_init_data *reg_data;
1153 struct regulator_dev *rdev;
1154 struct tps65910_reg *pmic;
1155 struct tps65910_board *pmic_plat_data;
1156 struct of_regulator_match *tps65910_reg_matches = NULL;
1159 pmic_plat_data = dev_get_platdata(tps65910->dev);
1160 if (!pmic_plat_data && tps65910->dev->of_node)
1161 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1162 &tps65910_reg_matches);
1164 if (!pmic_plat_data) {
1165 dev_err(&pdev->dev, "Platform data not found\n");
1169 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1171 dev_err(&pdev->dev, "Memory allocation failed for pmic\n");
1175 mutex_init(&pmic->mutex);
1176 pmic->mfd = tps65910;
1177 platform_set_drvdata(pdev, pmic);
1179 /* Give control of all register to control port */
1180 tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1181 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1183 switch(tps65910_chip_id(tps65910)) {
1185 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1186 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1187 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1188 info = tps65910_regs;
1191 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1192 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1193 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1194 info = tps65911_regs;
1197 dev_err(&pdev->dev, "Invalid tps chip version\n");
1201 pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1202 sizeof(struct regulator_desc), GFP_KERNEL);
1204 dev_err(&pdev->dev, "Memory alloc fails for desc\n");
1208 pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1209 sizeof(struct tps_info *), GFP_KERNEL);
1211 dev_err(&pdev->dev, "Memory alloc fails for info\n");
1215 pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1216 sizeof(struct regulator_dev *), GFP_KERNEL);
1218 dev_err(&pdev->dev, "Memory alloc fails for rdev\n");
1222 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1225 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1227 /* Regulator API handles empty constraints but not NULL
1232 /* Register the regulators */
1233 pmic->info[i] = info;
1235 pmic->desc[i].name = info->name;
1236 pmic->desc[i].id = i;
1237 pmic->desc[i].n_voltages = info->n_voltages;
1239 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1240 pmic->desc[i].ops = &tps65910_ops_dcdc;
1241 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1242 VDD1_2_NUM_VOLT_COARSE;
1243 } else if (i == TPS65910_REG_VDD3) {
1244 if (tps65910_chip_id(tps65910) == TPS65910)
1245 pmic->desc[i].ops = &tps65910_ops_vdd3;
1247 pmic->desc[i].ops = &tps65910_ops_dcdc;
1249 if (tps65910_chip_id(tps65910) == TPS65910)
1250 pmic->desc[i].ops = &tps65910_ops;
1252 pmic->desc[i].ops = &tps65911_ops;
1255 err = tps65910_set_ext_sleep_config(pmic, i,
1256 pmic_plat_data->regulator_ext_sleep_control[i]);
1258 * Failing on regulator for configuring externally control
1259 * is not a serious issue, just throw warning.
1262 dev_warn(tps65910->dev,
1263 "Failed to initialise ext control config\n");
1265 pmic->desc[i].type = REGULATOR_VOLTAGE;
1266 pmic->desc[i].owner = THIS_MODULE;
1267 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1268 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1270 config.dev = tps65910->dev;
1271 config.init_data = reg_data;
1272 config.driver_data = pmic;
1273 config.regmap = tps65910->regmap;
1275 if (tps65910_reg_matches)
1276 config.of_node = tps65910_reg_matches[i].of_node;
1278 rdev = regulator_register(&pmic->desc[i], &config);
1280 dev_err(tps65910->dev,
1281 "failed to register %s regulator\n",
1283 err = PTR_ERR(rdev);
1284 goto err_unregister_regulator;
1287 /* Save regulator for cleanup */
1288 pmic->rdev[i] = rdev;
1292 err_unregister_regulator:
1294 regulator_unregister(pmic->rdev[i]);
1298 static int __devexit tps65910_remove(struct platform_device *pdev)
1300 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1303 for (i = 0; i < pmic->num_regulators; i++)
1304 regulator_unregister(pmic->rdev[i]);
1309 static void tps65910_shutdown(struct platform_device *pdev)
1311 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1315 * Before bootloader jumps to kernel, it makes sure that required
1316 * external control signals are in desired state so that given rails
1317 * can be configure accordingly.
1318 * If rails are configured to be controlled from external control
1319 * then before shutting down/rebooting the system, the external
1320 * control configuration need to be remove from the rails so that
1321 * its output will be available as per register programming even
1322 * if external controls are removed. This is require when the POR
1323 * value of the control signals are not in active state and before
1324 * bootloader initializes it, the system requires the rail output
1325 * to be active for booting.
1327 for (i = 0; i < pmic->num_regulators; i++) {
1332 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1335 "Error in clearing external control\n");
1339 static struct platform_driver tps65910_driver = {
1341 .name = "tps65910-pmic",
1342 .owner = THIS_MODULE,
1344 .probe = tps65910_probe,
1345 .remove = __devexit_p(tps65910_remove),
1346 .shutdown = tps65910_shutdown,
1349 static int __init tps65910_init(void)
1351 return platform_driver_register(&tps65910_driver);
1353 subsys_initcall(tps65910_init);
1355 static void __exit tps65910_cleanup(void)
1357 platform_driver_unregister(&tps65910_driver);
1359 module_exit(tps65910_cleanup);
1361 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1362 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1363 MODULE_LICENSE("GPL v2");
1364 MODULE_ALIAS("platform:tps65910-pmic");