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 microvolts */
35 static const unsigned int VIO_VSEL_table[] = {
36 1500000, 1800000, 2500000, 3300000,
39 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
41 /* supported VDD3 voltages in microvolts */
42 static const unsigned int VDD3_VSEL_table[] = {
46 /* supported VDIG1 voltages in microvolts */
47 static const unsigned int VDIG1_VSEL_table[] = {
48 1200000, 1500000, 1800000, 2700000,
51 /* supported VDIG2 voltages in microvolts */
52 static const unsigned int VDIG2_VSEL_table[] = {
53 1000000, 1100000, 1200000, 1800000,
56 /* supported VPLL voltages in microvolts */
57 static const unsigned int VPLL_VSEL_table[] = {
58 1000000, 1100000, 1800000, 2500000,
61 /* supported VDAC voltages in microvolts */
62 static const unsigned int VDAC_VSEL_table[] = {
63 1800000, 2600000, 2800000, 2850000,
66 /* supported VAUX1 voltages in microvolts */
67 static const unsigned int VAUX1_VSEL_table[] = {
68 1800000, 2500000, 2800000, 2850000,
71 /* supported VAUX2 voltages in microvolts */
72 static const unsigned int VAUX2_VSEL_table[] = {
73 1800000, 2800000, 2900000, 3300000,
76 /* supported VAUX33 voltages in microvolts */
77 static const unsigned int VAUX33_VSEL_table[] = {
78 1800000, 2000000, 2800000, 3300000,
81 /* supported VMMC voltages in microvolts */
82 static const unsigned int VMMC_VSEL_table[] = {
83 1800000, 2800000, 3000000, 3300000,
90 const unsigned int *voltage_table;
94 static struct tps_info tps65910_regs[] = {
98 .enable_time_us = 2200,
103 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
104 .voltage_table = VIO_VSEL_table,
105 .enable_time_us = 350,
110 .enable_time_us = 350,
115 .enable_time_us = 350,
119 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
120 .voltage_table = VDD3_VSEL_table,
121 .enable_time_us = 200,
126 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
127 .voltage_table = VDIG1_VSEL_table,
128 .enable_time_us = 100,
133 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
134 .voltage_table = VDIG2_VSEL_table,
135 .enable_time_us = 100,
140 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
141 .voltage_table = VPLL_VSEL_table,
142 .enable_time_us = 100,
147 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
148 .voltage_table = VDAC_VSEL_table,
149 .enable_time_us = 100,
154 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
155 .voltage_table = VAUX1_VSEL_table,
156 .enable_time_us = 100,
161 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
162 .voltage_table = VAUX2_VSEL_table,
163 .enable_time_us = 100,
168 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
169 .voltage_table = VAUX33_VSEL_table,
170 .enable_time_us = 100,
175 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
176 .voltage_table = VMMC_VSEL_table,
177 .enable_time_us = 100,
181 static struct tps_info tps65911_regs[] = {
185 .enable_time_us = 2200,
190 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
191 .voltage_table = VIO_VSEL_table,
192 .enable_time_us = 350,
198 .enable_time_us = 350,
204 .enable_time_us = 350,
209 .enable_time_us = 900,
215 .enable_time_us = 420,
221 .enable_time_us = 420,
227 .enable_time_us = 230,
233 .enable_time_us = 230,
239 .enable_time_us = 230,
245 .enable_time_us = 230,
251 .enable_time_us = 230,
257 .enable_time_us = 230,
261 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
262 static unsigned int tps65910_ext_sleep_control[] = {
264 EXT_CONTROL_REG_BITS(VIO, 1, 0),
265 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
266 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
267 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
268 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
269 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
270 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
271 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
272 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
273 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
274 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
275 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
278 static unsigned int tps65911_ext_sleep_control[] = {
280 EXT_CONTROL_REG_BITS(VIO, 1, 0),
281 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
282 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
283 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
284 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
285 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
286 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
287 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
288 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
289 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
290 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
291 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
294 struct tps65910_reg {
295 struct regulator_desc *desc;
296 struct tps65910 *mfd;
297 struct regulator_dev **rdev;
298 struct tps_info **info;
302 int (*get_ctrl_reg)(int);
303 unsigned int *ext_sleep_control;
304 unsigned int board_ext_control[TPS65910_NUM_REGS];
307 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
312 err = tps65910_reg_read(pmic->mfd, reg, &val);
319 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
320 u8 set_mask, u8 clear_mask)
324 mutex_lock(&pmic->mutex);
326 data = tps65910_read(pmic, reg);
328 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
335 err = tps65910_reg_write(pmic->mfd, reg, data);
337 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
340 mutex_unlock(&pmic->mutex);
344 static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
348 mutex_lock(&pmic->mutex);
350 data = tps65910_read(pmic, reg);
352 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
354 mutex_unlock(&pmic->mutex);
358 static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
362 mutex_lock(&pmic->mutex);
364 err = tps65910_reg_write(pmic->mfd, reg, val);
366 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
368 mutex_unlock(&pmic->mutex);
372 static int tps65910_get_ctrl_register(int id)
375 case TPS65910_REG_VRTC:
376 return TPS65910_VRTC;
377 case TPS65910_REG_VIO:
379 case TPS65910_REG_VDD1:
380 return TPS65910_VDD1;
381 case TPS65910_REG_VDD2:
382 return TPS65910_VDD2;
383 case TPS65910_REG_VDD3:
384 return TPS65910_VDD3;
385 case TPS65910_REG_VDIG1:
386 return TPS65910_VDIG1;
387 case TPS65910_REG_VDIG2:
388 return TPS65910_VDIG2;
389 case TPS65910_REG_VPLL:
390 return TPS65910_VPLL;
391 case TPS65910_REG_VDAC:
392 return TPS65910_VDAC;
393 case TPS65910_REG_VAUX1:
394 return TPS65910_VAUX1;
395 case TPS65910_REG_VAUX2:
396 return TPS65910_VAUX2;
397 case TPS65910_REG_VAUX33:
398 return TPS65910_VAUX33;
399 case TPS65910_REG_VMMC:
400 return TPS65910_VMMC;
406 static int tps65911_get_ctrl_register(int id)
409 case TPS65910_REG_VRTC:
410 return TPS65910_VRTC;
411 case TPS65910_REG_VIO:
413 case TPS65910_REG_VDD1:
414 return TPS65910_VDD1;
415 case TPS65910_REG_VDD2:
416 return TPS65910_VDD2;
417 case TPS65911_REG_VDDCTRL:
418 return TPS65911_VDDCTRL;
419 case TPS65911_REG_LDO1:
420 return TPS65911_LDO1;
421 case TPS65911_REG_LDO2:
422 return TPS65911_LDO2;
423 case TPS65911_REG_LDO3:
424 return TPS65911_LDO3;
425 case TPS65911_REG_LDO4:
426 return TPS65911_LDO4;
427 case TPS65911_REG_LDO5:
428 return TPS65911_LDO5;
429 case TPS65911_REG_LDO6:
430 return TPS65911_LDO6;
431 case TPS65911_REG_LDO7:
432 return TPS65911_LDO7;
433 case TPS65911_REG_LDO8:
434 return TPS65911_LDO8;
440 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
442 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
443 struct tps65910 *mfd = pmic->mfd;
444 int reg, value, id = rdev_get_id(dev);
446 reg = pmic->get_ctrl_reg(id);
451 case REGULATOR_MODE_NORMAL:
452 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
454 case REGULATOR_MODE_IDLE:
455 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
456 return tps65910_reg_set_bits(mfd, reg, value);
457 case REGULATOR_MODE_STANDBY:
458 return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
464 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
466 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
467 int reg, value, id = rdev_get_id(dev);
469 reg = pmic->get_ctrl_reg(id);
473 value = tps65910_reg_read_locked(pmic, reg);
477 if (!(value & LDO_ST_ON_BIT))
478 return REGULATOR_MODE_STANDBY;
479 else if (value & LDO_ST_MODE_BIT)
480 return REGULATOR_MODE_IDLE;
482 return REGULATOR_MODE_NORMAL;
485 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
487 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
488 int id = rdev_get_id(dev);
489 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
492 case TPS65910_REG_VDD1:
493 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
494 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
495 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
496 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
497 sr = opvsel & VDD1_OP_CMD_MASK;
498 opvsel &= VDD1_OP_SEL_MASK;
499 srvsel &= VDD1_SR_SEL_MASK;
502 case TPS65910_REG_VDD2:
503 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
504 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
505 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
506 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
507 sr = opvsel & VDD2_OP_CMD_MASK;
508 opvsel &= VDD2_OP_SEL_MASK;
509 srvsel &= VDD2_SR_SEL_MASK;
512 case TPS65911_REG_VDDCTRL:
513 opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
514 srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
515 sr = opvsel & VDDCTRL_OP_CMD_MASK;
516 opvsel &= VDDCTRL_OP_SEL_MASK;
517 srvsel &= VDDCTRL_SR_SEL_MASK;
522 /* multiplier 0 == 1 but 2,3 normal */
527 /* normalise to valid range */
530 if (srvsel > vselmax)
535 /* normalise to valid range*/
538 if (opvsel > vselmax)
545 static int tps65910_get_voltage_sel(struct regulator_dev *dev)
547 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
548 int reg, value, id = rdev_get_id(dev);
550 reg = pmic->get_ctrl_reg(id);
554 value = tps65910_reg_read_locked(pmic, reg);
559 case TPS65910_REG_VIO:
560 case TPS65910_REG_VDIG1:
561 case TPS65910_REG_VDIG2:
562 case TPS65910_REG_VPLL:
563 case TPS65910_REG_VDAC:
564 case TPS65910_REG_VAUX1:
565 case TPS65910_REG_VAUX2:
566 case TPS65910_REG_VAUX33:
567 case TPS65910_REG_VMMC:
568 value &= LDO_SEL_MASK;
569 value >>= LDO_SEL_SHIFT;
578 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
580 return dev->desc->volt_table[0];
583 static int tps65911_get_voltage_sel(struct regulator_dev *dev)
585 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
586 int id = rdev_get_id(dev);
589 reg = pmic->get_ctrl_reg(id);
591 value = tps65910_reg_read_locked(pmic, reg);
594 case TPS65911_REG_LDO1:
595 case TPS65911_REG_LDO2:
596 case TPS65911_REG_LDO4:
597 value &= LDO1_SEL_MASK;
598 value >>= LDO_SEL_SHIFT;
600 case TPS65911_REG_LDO3:
601 case TPS65911_REG_LDO5:
602 case TPS65911_REG_LDO6:
603 case TPS65911_REG_LDO7:
604 case TPS65911_REG_LDO8:
605 value &= LDO3_SEL_MASK;
606 value >>= LDO_SEL_SHIFT;
608 case TPS65910_REG_VIO:
609 value &= LDO_SEL_MASK;
610 value >>= LDO_SEL_SHIFT;
619 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
622 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
623 int id = rdev_get_id(dev), vsel;
627 case TPS65910_REG_VDD1:
628 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
631 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
633 tps65910_modify_bits(pmic, TPS65910_VDD1,
634 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
635 VDD1_VGAIN_SEL_MASK);
636 tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
638 case TPS65910_REG_VDD2:
639 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
642 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
644 tps65910_modify_bits(pmic, TPS65910_VDD2,
645 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
646 VDD1_VGAIN_SEL_MASK);
647 tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
649 case TPS65911_REG_VDDCTRL:
651 tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
657 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
660 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
661 int reg, id = rdev_get_id(dev);
663 reg = pmic->get_ctrl_reg(id);
668 case TPS65910_REG_VIO:
669 case TPS65910_REG_VDIG1:
670 case TPS65910_REG_VDIG2:
671 case TPS65910_REG_VPLL:
672 case TPS65910_REG_VDAC:
673 case TPS65910_REG_VAUX1:
674 case TPS65910_REG_VAUX2:
675 case TPS65910_REG_VAUX33:
676 case TPS65910_REG_VMMC:
677 return tps65910_modify_bits(pmic, reg,
678 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
684 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
687 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
688 int reg, id = rdev_get_id(dev);
690 reg = pmic->get_ctrl_reg(id);
695 case TPS65911_REG_LDO1:
696 case TPS65911_REG_LDO2:
697 case TPS65911_REG_LDO4:
698 return tps65910_modify_bits(pmic, reg,
699 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
700 case TPS65911_REG_LDO3:
701 case TPS65911_REG_LDO5:
702 case TPS65911_REG_LDO6:
703 case TPS65911_REG_LDO7:
704 case TPS65911_REG_LDO8:
705 return tps65910_modify_bits(pmic, reg,
706 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
707 case TPS65910_REG_VIO:
708 return tps65910_modify_bits(pmic, reg,
709 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
716 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
719 int volt, mult = 1, id = rdev_get_id(dev);
722 case TPS65910_REG_VDD1:
723 case TPS65910_REG_VDD2:
724 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
725 volt = VDD1_2_MIN_VOLT +
726 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
728 case TPS65911_REG_VDDCTRL:
729 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
736 return volt * 100 * mult;
739 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
741 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
742 int step_mv = 0, id = rdev_get_id(dev);
745 case TPS65911_REG_LDO1:
746 case TPS65911_REG_LDO2:
747 case TPS65911_REG_LDO4:
748 /* The first 5 values of the selector correspond to 1V */
756 case TPS65911_REG_LDO3:
757 case TPS65911_REG_LDO5:
758 case TPS65911_REG_LDO6:
759 case TPS65911_REG_LDO7:
760 case TPS65911_REG_LDO8:
761 /* The first 3 values of the selector correspond to 1V */
769 case TPS65910_REG_VIO:
770 return pmic->info[id]->voltage_table[selector];
775 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
778 /* Regulator ops (except VRTC) */
779 static struct regulator_ops tps65910_ops_dcdc = {
780 .is_enabled = regulator_is_enabled_regmap,
781 .enable = regulator_enable_regmap,
782 .disable = regulator_disable_regmap,
783 .set_mode = tps65910_set_mode,
784 .get_mode = tps65910_get_mode,
785 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
786 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
787 .set_voltage_time_sel = regulator_set_voltage_time_sel,
788 .list_voltage = tps65910_list_voltage_dcdc,
791 static struct regulator_ops tps65910_ops_vdd3 = {
792 .is_enabled = regulator_is_enabled_regmap,
793 .enable = regulator_enable_regmap,
794 .disable = regulator_disable_regmap,
795 .set_mode = tps65910_set_mode,
796 .get_mode = tps65910_get_mode,
797 .get_voltage = tps65910_get_voltage_vdd3,
798 .list_voltage = regulator_list_voltage_table,
801 static struct regulator_ops tps65910_ops = {
802 .is_enabled = regulator_is_enabled_regmap,
803 .enable = regulator_enable_regmap,
804 .disable = regulator_disable_regmap,
805 .set_mode = tps65910_set_mode,
806 .get_mode = tps65910_get_mode,
807 .get_voltage_sel = tps65910_get_voltage_sel,
808 .set_voltage_sel = tps65910_set_voltage_sel,
809 .list_voltage = regulator_list_voltage_table,
812 static struct regulator_ops tps65911_ops = {
813 .is_enabled = regulator_is_enabled_regmap,
814 .enable = regulator_enable_regmap,
815 .disable = regulator_disable_regmap,
816 .set_mode = tps65910_set_mode,
817 .get_mode = tps65910_get_mode,
818 .get_voltage_sel = tps65911_get_voltage_sel,
819 .set_voltage_sel = tps65911_set_voltage_sel,
820 .list_voltage = tps65911_list_voltage,
823 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
824 int id, int ext_sleep_config)
826 struct tps65910 *mfd = pmic->mfd;
827 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
828 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
832 * Regulator can not be control from multiple external input EN1, EN2
835 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
837 en_count = ((ext_sleep_config &
838 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
839 en_count += ((ext_sleep_config &
840 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
841 en_count += ((ext_sleep_config &
842 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
843 en_count += ((ext_sleep_config &
844 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
847 "External sleep control flag is not proper\n");
852 pmic->board_ext_control[id] = ext_sleep_config;
854 /* External EN1 control */
855 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
856 ret = tps65910_reg_set_bits(mfd,
857 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
859 ret = tps65910_reg_clear_bits(mfd,
860 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
863 "Error in configuring external control EN1\n");
867 /* External EN2 control */
868 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
869 ret = tps65910_reg_set_bits(mfd,
870 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
872 ret = tps65910_reg_clear_bits(mfd,
873 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
876 "Error in configuring external control EN2\n");
880 /* External EN3 control for TPS65910 LDO only */
881 if ((tps65910_chip_id(mfd) == TPS65910) &&
882 (id >= TPS65910_REG_VDIG1)) {
883 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
884 ret = tps65910_reg_set_bits(mfd,
885 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
887 ret = tps65910_reg_clear_bits(mfd,
888 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
891 "Error in configuring external control EN3\n");
896 /* Return if no external control is selected */
897 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
898 /* Clear all sleep controls */
899 ret = tps65910_reg_clear_bits(mfd,
900 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
902 ret = tps65910_reg_clear_bits(mfd,
903 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
906 "Error in configuring SLEEP register\n");
911 * For regulator that has separate operational and sleep register make
912 * sure that operational is used and clear sleep register to turn
913 * regulator off when external control is inactive
915 if ((id == TPS65910_REG_VDD1) ||
916 (id == TPS65910_REG_VDD2) ||
917 ((id == TPS65911_REG_VDDCTRL) &&
918 (tps65910_chip_id(mfd) == TPS65911))) {
919 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
920 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
921 int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
922 int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
923 if (opvsel & VDD1_OP_CMD_MASK) {
924 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
925 ret = tps65910_reg_write_locked(pmic, op_reg_add,
929 "Error in configuring op register\n");
933 ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
935 dev_err(mfd->dev, "Error in settting sr register\n");
940 ret = tps65910_reg_clear_bits(mfd,
941 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
943 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
944 ret = tps65910_reg_set_bits(mfd,
945 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
947 ret = tps65910_reg_clear_bits(mfd,
948 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
952 "Error in configuring SLEEP register\n");
959 static struct of_regulator_match tps65910_matches[] = {
960 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
961 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
962 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
963 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
964 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
965 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
966 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
967 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
968 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
969 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
970 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
971 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
972 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
975 static struct of_regulator_match tps65911_matches[] = {
976 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
977 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
978 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
979 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
980 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
981 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
982 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
983 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
984 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
985 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
986 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
987 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
988 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
991 static struct tps65910_board *tps65910_parse_dt_reg_data(
992 struct platform_device *pdev,
993 struct of_regulator_match **tps65910_reg_matches)
995 struct tps65910_board *pmic_plat_data;
996 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
997 struct device_node *np = pdev->dev.parent->of_node;
998 struct device_node *regulators;
999 struct of_regulator_match *matches;
1001 int idx = 0, ret, count;
1003 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
1006 if (!pmic_plat_data) {
1007 dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
1011 regulators = of_find_node_by_name(np, "regulators");
1013 dev_err(&pdev->dev, "regulator node not found\n");
1017 switch (tps65910_chip_id(tps65910)) {
1019 count = ARRAY_SIZE(tps65910_matches);
1020 matches = tps65910_matches;
1023 count = ARRAY_SIZE(tps65911_matches);
1024 matches = tps65911_matches;
1027 dev_err(&pdev->dev, "Invalid tps chip version\n");
1031 ret = of_regulator_match(pdev->dev.parent, regulators, matches, count);
1033 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1038 *tps65910_reg_matches = matches;
1040 for (idx = 0; idx < count; idx++) {
1041 struct tps_info *info = matches[idx].driver_data;
1042 char in_supply[32]; /* 32 is max size of property name */
1044 if (!matches[idx].init_data || !matches[idx].of_node)
1047 pmic_plat_data->tps65910_pmic_init_data[idx] =
1048 matches[idx].init_data;
1050 ret = of_property_read_u32(matches[idx].of_node,
1051 "ti,regulator-ext-sleep-control", &prop);
1053 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1055 if (info->vin_name) {
1056 snprintf(in_supply, 32, "%s-supply", info->vin_name);
1057 if (of_find_property(np, in_supply, 0))
1058 pmic_plat_data->input_supply[idx] =
1063 return pmic_plat_data;
1066 static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1067 struct platform_device *pdev,
1068 struct of_regulator_match **tps65910_reg_matches)
1070 *tps65910_reg_matches = NULL;
1075 static __devinit int tps65910_probe(struct platform_device *pdev)
1077 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1078 struct regulator_config config = { };
1079 struct tps_info *info;
1080 struct regulator_init_data *reg_data;
1081 struct regulator_dev *rdev;
1082 struct tps65910_reg *pmic;
1083 struct tps65910_board *pmic_plat_data;
1084 struct of_regulator_match *tps65910_reg_matches = NULL;
1087 pmic_plat_data = dev_get_platdata(tps65910->dev);
1088 if (!pmic_plat_data && tps65910->dev->of_node)
1089 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1090 &tps65910_reg_matches);
1092 if (!pmic_plat_data) {
1093 dev_err(&pdev->dev, "Platform data not found\n");
1097 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1099 dev_err(&pdev->dev, "Memory allocation failed for pmic\n");
1103 mutex_init(&pmic->mutex);
1104 pmic->mfd = tps65910;
1105 platform_set_drvdata(pdev, pmic);
1107 /* Give control of all register to control port */
1108 tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1109 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1111 switch(tps65910_chip_id(tps65910)) {
1113 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1114 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1115 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1116 info = tps65910_regs;
1119 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1120 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1121 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1122 info = tps65911_regs;
1125 dev_err(&pdev->dev, "Invalid tps chip version\n");
1129 pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1130 sizeof(struct regulator_desc), GFP_KERNEL);
1132 dev_err(&pdev->dev, "Memory alloc fails for desc\n");
1136 pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1137 sizeof(struct tps_info *), GFP_KERNEL);
1139 dev_err(&pdev->dev, "Memory alloc fails for info\n");
1143 pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1144 sizeof(struct regulator_dev *), GFP_KERNEL);
1146 dev_err(&pdev->dev, "Memory alloc fails for rdev\n");
1150 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1153 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1155 /* Regulator API handles empty constraints but not NULL
1160 /* Register the regulators */
1161 pmic->info[i] = info;
1163 pmic->desc[i].name = info->name;
1164 pmic->desc[i].supply_name = pmic_plat_data->input_supply[i];
1165 pmic->desc[i].id = i;
1166 pmic->desc[i].n_voltages = info->n_voltages;
1167 pmic->desc[i].enable_time = info->enable_time_us;
1169 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1170 pmic->desc[i].ops = &tps65910_ops_dcdc;
1171 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1172 VDD1_2_NUM_VOLT_COARSE;
1173 pmic->desc[i].ramp_delay = 12500;
1174 } else if (i == TPS65910_REG_VDD3) {
1175 if (tps65910_chip_id(tps65910) == TPS65910) {
1176 pmic->desc[i].ops = &tps65910_ops_vdd3;
1177 pmic->desc[i].volt_table = info->voltage_table;
1179 pmic->desc[i].ops = &tps65910_ops_dcdc;
1180 pmic->desc[i].ramp_delay = 5000;
1183 if (tps65910_chip_id(tps65910) == TPS65910) {
1184 pmic->desc[i].ops = &tps65910_ops;
1185 pmic->desc[i].volt_table = info->voltage_table;
1187 pmic->desc[i].ops = &tps65911_ops;
1191 err = tps65910_set_ext_sleep_config(pmic, i,
1192 pmic_plat_data->regulator_ext_sleep_control[i]);
1194 * Failing on regulator for configuring externally control
1195 * is not a serious issue, just throw warning.
1198 dev_warn(tps65910->dev,
1199 "Failed to initialise ext control config\n");
1201 pmic->desc[i].type = REGULATOR_VOLTAGE;
1202 pmic->desc[i].owner = THIS_MODULE;
1203 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1204 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1206 config.dev = tps65910->dev;
1207 config.init_data = reg_data;
1208 config.driver_data = pmic;
1209 config.regmap = tps65910->regmap;
1211 if (tps65910_reg_matches)
1212 config.of_node = tps65910_reg_matches[i].of_node;
1214 rdev = regulator_register(&pmic->desc[i], &config);
1216 dev_err(tps65910->dev,
1217 "failed to register %s regulator\n",
1219 err = PTR_ERR(rdev);
1220 goto err_unregister_regulator;
1223 /* Save regulator for cleanup */
1224 pmic->rdev[i] = rdev;
1228 err_unregister_regulator:
1230 regulator_unregister(pmic->rdev[i]);
1234 static int __devexit tps65910_remove(struct platform_device *pdev)
1236 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1239 for (i = 0; i < pmic->num_regulators; i++)
1240 regulator_unregister(pmic->rdev[i]);
1245 static void tps65910_shutdown(struct platform_device *pdev)
1247 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1251 * Before bootloader jumps to kernel, it makes sure that required
1252 * external control signals are in desired state so that given rails
1253 * can be configure accordingly.
1254 * If rails are configured to be controlled from external control
1255 * then before shutting down/rebooting the system, the external
1256 * control configuration need to be remove from the rails so that
1257 * its output will be available as per register programming even
1258 * if external controls are removed. This is require when the POR
1259 * value of the control signals are not in active state and before
1260 * bootloader initializes it, the system requires the rail output
1261 * to be active for booting.
1263 for (i = 0; i < pmic->num_regulators; i++) {
1268 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1271 "Error in clearing external control\n");
1275 static struct platform_driver tps65910_driver = {
1277 .name = "tps65910-pmic",
1278 .owner = THIS_MODULE,
1280 .probe = tps65910_probe,
1281 .remove = __devexit_p(tps65910_remove),
1282 .shutdown = tps65910_shutdown,
1285 static int __init tps65910_init(void)
1287 return platform_driver_register(&tps65910_driver);
1289 subsys_initcall(tps65910_init);
1291 static void __exit tps65910_cleanup(void)
1293 platform_driver_unregister(&tps65910_driver);
1295 module_exit(tps65910_cleanup);
1297 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1298 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1299 MODULE_LICENSE("GPL v2");
1300 MODULE_ALIAS("platform:tps65910-pmic");