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,
89 const unsigned int *voltage_table;
93 static struct tps_info tps65910_regs[] = {
96 .enable_time_us = 2200,
100 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
101 .voltage_table = VIO_VSEL_table,
102 .enable_time_us = 350,
106 .enable_time_us = 350,
110 .enable_time_us = 350,
114 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
115 .voltage_table = VDD3_VSEL_table,
116 .enable_time_us = 200,
120 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
121 .voltage_table = VDIG1_VSEL_table,
122 .enable_time_us = 100,
126 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
127 .voltage_table = VDIG2_VSEL_table,
128 .enable_time_us = 100,
132 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
133 .voltage_table = VPLL_VSEL_table,
134 .enable_time_us = 100,
138 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
139 .voltage_table = VDAC_VSEL_table,
140 .enable_time_us = 100,
144 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
145 .voltage_table = VAUX1_VSEL_table,
146 .enable_time_us = 100,
150 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
151 .voltage_table = VAUX2_VSEL_table,
152 .enable_time_us = 100,
156 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
157 .voltage_table = VAUX33_VSEL_table,
158 .enable_time_us = 100,
162 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
163 .voltage_table = VMMC_VSEL_table,
164 .enable_time_us = 100,
168 static struct tps_info tps65911_regs[] = {
171 .enable_time_us = 2200,
175 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
176 .voltage_table = VIO_VSEL_table,
177 .enable_time_us = 350,
182 .enable_time_us = 350,
187 .enable_time_us = 350,
192 .enable_time_us = 900,
197 .enable_time_us = 420,
202 .enable_time_us = 420,
207 .enable_time_us = 230,
212 .enable_time_us = 230,
217 .enable_time_us = 230,
222 .enable_time_us = 230,
227 .enable_time_us = 230,
232 .enable_time_us = 230,
236 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
237 static unsigned int tps65910_ext_sleep_control[] = {
239 EXT_CONTROL_REG_BITS(VIO, 1, 0),
240 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
241 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
242 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
243 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
244 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
245 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
246 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
247 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
248 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
249 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
250 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
253 static unsigned int tps65911_ext_sleep_control[] = {
255 EXT_CONTROL_REG_BITS(VIO, 1, 0),
256 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
257 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
258 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
259 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
260 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
261 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
262 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
263 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
264 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
265 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
266 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
269 struct tps65910_reg {
270 struct regulator_desc *desc;
271 struct tps65910 *mfd;
272 struct regulator_dev **rdev;
273 struct tps_info **info;
277 int (*get_ctrl_reg)(int);
278 unsigned int *ext_sleep_control;
279 unsigned int board_ext_control[TPS65910_NUM_REGS];
282 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
287 err = tps65910_reg_read(pmic->mfd, reg, &val);
294 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
295 u8 set_mask, u8 clear_mask)
299 mutex_lock(&pmic->mutex);
301 data = tps65910_read(pmic, reg);
303 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
310 err = tps65910_reg_write(pmic->mfd, reg, data);
312 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
315 mutex_unlock(&pmic->mutex);
319 static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
323 mutex_lock(&pmic->mutex);
325 data = tps65910_read(pmic, reg);
327 dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg);
329 mutex_unlock(&pmic->mutex);
333 static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
337 mutex_lock(&pmic->mutex);
339 err = tps65910_reg_write(pmic->mfd, reg, val);
341 dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
343 mutex_unlock(&pmic->mutex);
347 static int tps65910_get_ctrl_register(int id)
350 case TPS65910_REG_VRTC:
351 return TPS65910_VRTC;
352 case TPS65910_REG_VIO:
354 case TPS65910_REG_VDD1:
355 return TPS65910_VDD1;
356 case TPS65910_REG_VDD2:
357 return TPS65910_VDD2;
358 case TPS65910_REG_VDD3:
359 return TPS65910_VDD3;
360 case TPS65910_REG_VDIG1:
361 return TPS65910_VDIG1;
362 case TPS65910_REG_VDIG2:
363 return TPS65910_VDIG2;
364 case TPS65910_REG_VPLL:
365 return TPS65910_VPLL;
366 case TPS65910_REG_VDAC:
367 return TPS65910_VDAC;
368 case TPS65910_REG_VAUX1:
369 return TPS65910_VAUX1;
370 case TPS65910_REG_VAUX2:
371 return TPS65910_VAUX2;
372 case TPS65910_REG_VAUX33:
373 return TPS65910_VAUX33;
374 case TPS65910_REG_VMMC:
375 return TPS65910_VMMC;
381 static int tps65911_get_ctrl_register(int id)
384 case TPS65910_REG_VRTC:
385 return TPS65910_VRTC;
386 case TPS65910_REG_VIO:
388 case TPS65910_REG_VDD1:
389 return TPS65910_VDD1;
390 case TPS65910_REG_VDD2:
391 return TPS65910_VDD2;
392 case TPS65911_REG_VDDCTRL:
393 return TPS65911_VDDCTRL;
394 case TPS65911_REG_LDO1:
395 return TPS65911_LDO1;
396 case TPS65911_REG_LDO2:
397 return TPS65911_LDO2;
398 case TPS65911_REG_LDO3:
399 return TPS65911_LDO3;
400 case TPS65911_REG_LDO4:
401 return TPS65911_LDO4;
402 case TPS65911_REG_LDO5:
403 return TPS65911_LDO5;
404 case TPS65911_REG_LDO6:
405 return TPS65911_LDO6;
406 case TPS65911_REG_LDO7:
407 return TPS65911_LDO7;
408 case TPS65911_REG_LDO8:
409 return TPS65911_LDO8;
415 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
417 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
418 struct tps65910 *mfd = pmic->mfd;
419 int reg, value, id = rdev_get_id(dev);
421 reg = pmic->get_ctrl_reg(id);
426 case REGULATOR_MODE_NORMAL:
427 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
429 case REGULATOR_MODE_IDLE:
430 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
431 return tps65910_reg_set_bits(mfd, reg, value);
432 case REGULATOR_MODE_STANDBY:
433 return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
439 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
441 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
442 int reg, value, id = rdev_get_id(dev);
444 reg = pmic->get_ctrl_reg(id);
448 value = tps65910_reg_read_locked(pmic, reg);
452 if (!(value & LDO_ST_ON_BIT))
453 return REGULATOR_MODE_STANDBY;
454 else if (value & LDO_ST_MODE_BIT)
455 return REGULATOR_MODE_IDLE;
457 return REGULATOR_MODE_NORMAL;
460 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
462 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
463 int id = rdev_get_id(dev);
464 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
467 case TPS65910_REG_VDD1:
468 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
469 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
470 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
471 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
472 sr = opvsel & VDD1_OP_CMD_MASK;
473 opvsel &= VDD1_OP_SEL_MASK;
474 srvsel &= VDD1_SR_SEL_MASK;
477 case TPS65910_REG_VDD2:
478 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
479 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
480 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
481 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
482 sr = opvsel & VDD2_OP_CMD_MASK;
483 opvsel &= VDD2_OP_SEL_MASK;
484 srvsel &= VDD2_SR_SEL_MASK;
487 case TPS65911_REG_VDDCTRL:
488 opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
489 srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
490 sr = opvsel & VDDCTRL_OP_CMD_MASK;
491 opvsel &= VDDCTRL_OP_SEL_MASK;
492 srvsel &= VDDCTRL_SR_SEL_MASK;
497 /* multiplier 0 == 1 but 2,3 normal */
502 /* normalise to valid range */
505 if (srvsel > vselmax)
510 /* normalise to valid range*/
513 if (opvsel > vselmax)
520 static int tps65910_get_voltage_sel(struct regulator_dev *dev)
522 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
523 int reg, value, id = rdev_get_id(dev);
525 reg = pmic->get_ctrl_reg(id);
529 value = tps65910_reg_read_locked(pmic, reg);
534 case TPS65910_REG_VIO:
535 case TPS65910_REG_VDIG1:
536 case TPS65910_REG_VDIG2:
537 case TPS65910_REG_VPLL:
538 case TPS65910_REG_VDAC:
539 case TPS65910_REG_VAUX1:
540 case TPS65910_REG_VAUX2:
541 case TPS65910_REG_VAUX33:
542 case TPS65910_REG_VMMC:
543 value &= LDO_SEL_MASK;
544 value >>= LDO_SEL_SHIFT;
553 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
555 return dev->desc->volt_table[0];
558 static int tps65911_get_voltage_sel(struct regulator_dev *dev)
560 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
561 int id = rdev_get_id(dev);
564 reg = pmic->get_ctrl_reg(id);
566 value = tps65910_reg_read_locked(pmic, reg);
569 case TPS65911_REG_LDO1:
570 case TPS65911_REG_LDO2:
571 case TPS65911_REG_LDO4:
572 value &= LDO1_SEL_MASK;
573 value >>= LDO_SEL_SHIFT;
575 case TPS65911_REG_LDO3:
576 case TPS65911_REG_LDO5:
577 case TPS65911_REG_LDO6:
578 case TPS65911_REG_LDO7:
579 case TPS65911_REG_LDO8:
580 value &= LDO3_SEL_MASK;
581 value >>= LDO_SEL_SHIFT;
583 case TPS65910_REG_VIO:
584 value &= LDO_SEL_MASK;
585 value >>= LDO_SEL_SHIFT;
594 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
597 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
598 int id = rdev_get_id(dev), vsel;
602 case TPS65910_REG_VDD1:
603 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
606 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
608 tps65910_modify_bits(pmic, TPS65910_VDD1,
609 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
610 VDD1_VGAIN_SEL_MASK);
611 tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
613 case TPS65910_REG_VDD2:
614 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
617 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
619 tps65910_modify_bits(pmic, TPS65910_VDD2,
620 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
621 VDD1_VGAIN_SEL_MASK);
622 tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
624 case TPS65911_REG_VDDCTRL:
626 tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
632 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
635 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
636 int reg, id = rdev_get_id(dev);
638 reg = pmic->get_ctrl_reg(id);
643 case TPS65910_REG_VIO:
644 case TPS65910_REG_VDIG1:
645 case TPS65910_REG_VDIG2:
646 case TPS65910_REG_VPLL:
647 case TPS65910_REG_VDAC:
648 case TPS65910_REG_VAUX1:
649 case TPS65910_REG_VAUX2:
650 case TPS65910_REG_VAUX33:
651 case TPS65910_REG_VMMC:
652 return tps65910_modify_bits(pmic, reg,
653 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
659 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
662 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
663 int reg, id = rdev_get_id(dev);
665 reg = pmic->get_ctrl_reg(id);
670 case TPS65911_REG_LDO1:
671 case TPS65911_REG_LDO2:
672 case TPS65911_REG_LDO4:
673 return tps65910_modify_bits(pmic, reg,
674 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
675 case TPS65911_REG_LDO3:
676 case TPS65911_REG_LDO5:
677 case TPS65911_REG_LDO6:
678 case TPS65911_REG_LDO7:
679 case TPS65911_REG_LDO8:
680 return tps65910_modify_bits(pmic, reg,
681 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
682 case TPS65910_REG_VIO:
683 return tps65910_modify_bits(pmic, reg,
684 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
691 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
694 int volt, mult = 1, id = rdev_get_id(dev);
697 case TPS65910_REG_VDD1:
698 case TPS65910_REG_VDD2:
699 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
700 volt = VDD1_2_MIN_VOLT +
701 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
703 case TPS65911_REG_VDDCTRL:
704 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
711 return volt * 100 * mult;
714 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
716 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
717 int step_mv = 0, id = rdev_get_id(dev);
720 case TPS65911_REG_LDO1:
721 case TPS65911_REG_LDO2:
722 case TPS65911_REG_LDO4:
723 /* The first 5 values of the selector correspond to 1V */
731 case TPS65911_REG_LDO3:
732 case TPS65911_REG_LDO5:
733 case TPS65911_REG_LDO6:
734 case TPS65911_REG_LDO7:
735 case TPS65911_REG_LDO8:
736 /* The first 3 values of the selector correspond to 1V */
744 case TPS65910_REG_VIO:
745 return pmic->info[id]->voltage_table[selector];
750 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
753 /* Regulator ops (except VRTC) */
754 static struct regulator_ops tps65910_ops_dcdc = {
755 .is_enabled = regulator_is_enabled_regmap,
756 .enable = regulator_enable_regmap,
757 .disable = regulator_disable_regmap,
758 .set_mode = tps65910_set_mode,
759 .get_mode = tps65910_get_mode,
760 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
761 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
762 .set_voltage_time_sel = regulator_set_voltage_time_sel,
763 .list_voltage = tps65910_list_voltage_dcdc,
766 static struct regulator_ops tps65910_ops_vdd3 = {
767 .is_enabled = regulator_is_enabled_regmap,
768 .enable = regulator_enable_regmap,
769 .disable = regulator_disable_regmap,
770 .set_mode = tps65910_set_mode,
771 .get_mode = tps65910_get_mode,
772 .get_voltage = tps65910_get_voltage_vdd3,
773 .list_voltage = regulator_list_voltage_table,
776 static struct regulator_ops tps65910_ops = {
777 .is_enabled = regulator_is_enabled_regmap,
778 .enable = regulator_enable_regmap,
779 .disable = regulator_disable_regmap,
780 .set_mode = tps65910_set_mode,
781 .get_mode = tps65910_get_mode,
782 .get_voltage_sel = tps65910_get_voltage_sel,
783 .set_voltage_sel = tps65910_set_voltage_sel,
784 .list_voltage = regulator_list_voltage_table,
787 static struct regulator_ops tps65911_ops = {
788 .is_enabled = regulator_is_enabled_regmap,
789 .enable = regulator_enable_regmap,
790 .disable = regulator_disable_regmap,
791 .set_mode = tps65910_set_mode,
792 .get_mode = tps65910_get_mode,
793 .get_voltage_sel = tps65911_get_voltage_sel,
794 .set_voltage_sel = tps65911_set_voltage_sel,
795 .list_voltage = tps65911_list_voltage,
798 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
799 int id, int ext_sleep_config)
801 struct tps65910 *mfd = pmic->mfd;
802 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
803 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
807 * Regulator can not be control from multiple external input EN1, EN2
810 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
812 en_count = ((ext_sleep_config &
813 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
814 en_count += ((ext_sleep_config &
815 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
816 en_count += ((ext_sleep_config &
817 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
818 en_count += ((ext_sleep_config &
819 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
822 "External sleep control flag is not proper\n");
827 pmic->board_ext_control[id] = ext_sleep_config;
829 /* External EN1 control */
830 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
831 ret = tps65910_reg_set_bits(mfd,
832 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
834 ret = tps65910_reg_clear_bits(mfd,
835 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
838 "Error in configuring external control EN1\n");
842 /* External EN2 control */
843 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
844 ret = tps65910_reg_set_bits(mfd,
845 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
847 ret = tps65910_reg_clear_bits(mfd,
848 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
851 "Error in configuring external control EN2\n");
855 /* External EN3 control for TPS65910 LDO only */
856 if ((tps65910_chip_id(mfd) == TPS65910) &&
857 (id >= TPS65910_REG_VDIG1)) {
858 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
859 ret = tps65910_reg_set_bits(mfd,
860 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
862 ret = tps65910_reg_clear_bits(mfd,
863 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
866 "Error in configuring external control EN3\n");
871 /* Return if no external control is selected */
872 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
873 /* Clear all sleep controls */
874 ret = tps65910_reg_clear_bits(mfd,
875 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
877 ret = tps65910_reg_clear_bits(mfd,
878 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
881 "Error in configuring SLEEP register\n");
886 * For regulator that has separate operational and sleep register make
887 * sure that operational is used and clear sleep register to turn
888 * regulator off when external control is inactive
890 if ((id == TPS65910_REG_VDD1) ||
891 (id == TPS65910_REG_VDD2) ||
892 ((id == TPS65911_REG_VDDCTRL) &&
893 (tps65910_chip_id(mfd) == TPS65911))) {
894 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
895 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
896 int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
897 int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
898 if (opvsel & VDD1_OP_CMD_MASK) {
899 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
900 ret = tps65910_reg_write_locked(pmic, op_reg_add,
904 "Error in configuring op register\n");
908 ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
910 dev_err(mfd->dev, "Error in settting sr register\n");
915 ret = tps65910_reg_clear_bits(mfd,
916 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
918 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
919 ret = tps65910_reg_set_bits(mfd,
920 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
922 ret = tps65910_reg_clear_bits(mfd,
923 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
927 "Error in configuring SLEEP register\n");
934 static struct of_regulator_match tps65910_matches[] = {
935 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
936 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
937 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
938 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
939 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
940 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
941 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
942 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
943 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
944 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
945 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
946 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
947 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
950 static struct of_regulator_match tps65911_matches[] = {
951 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
952 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
953 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
954 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
955 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
956 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
957 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
958 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
959 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
960 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
961 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
962 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
963 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
966 static struct tps65910_board *tps65910_parse_dt_reg_data(
967 struct platform_device *pdev,
968 struct of_regulator_match **tps65910_reg_matches)
970 struct tps65910_board *pmic_plat_data;
971 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
972 struct device_node *np = pdev->dev.parent->of_node;
973 struct device_node *regulators;
974 struct of_regulator_match *matches;
976 int idx = 0, ret, count;
978 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
981 if (!pmic_plat_data) {
982 dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
986 regulators = of_find_node_by_name(np, "regulators");
988 dev_err(&pdev->dev, "regulator node not found\n");
992 switch (tps65910_chip_id(tps65910)) {
994 count = ARRAY_SIZE(tps65910_matches);
995 matches = tps65910_matches;
998 count = ARRAY_SIZE(tps65911_matches);
999 matches = tps65911_matches;
1002 dev_err(&pdev->dev, "Invalid tps chip version\n");
1006 ret = of_regulator_match(pdev->dev.parent, regulators, matches, count);
1008 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1013 *tps65910_reg_matches = matches;
1015 for (idx = 0; idx < count; idx++) {
1016 if (!matches[idx].init_data || !matches[idx].of_node)
1019 pmic_plat_data->tps65910_pmic_init_data[idx] =
1020 matches[idx].init_data;
1022 ret = of_property_read_u32(matches[idx].of_node,
1023 "ti,regulator-ext-sleep-control", &prop);
1025 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1028 return pmic_plat_data;
1031 static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1032 struct platform_device *pdev,
1033 struct of_regulator_match **tps65910_reg_matches)
1035 *tps65910_reg_matches = NULL;
1040 static __devinit int tps65910_probe(struct platform_device *pdev)
1042 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1043 struct regulator_config config = { };
1044 struct tps_info *info;
1045 struct regulator_init_data *reg_data;
1046 struct regulator_dev *rdev;
1047 struct tps65910_reg *pmic;
1048 struct tps65910_board *pmic_plat_data;
1049 struct of_regulator_match *tps65910_reg_matches = NULL;
1052 pmic_plat_data = dev_get_platdata(tps65910->dev);
1053 if (!pmic_plat_data && tps65910->dev->of_node)
1054 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1055 &tps65910_reg_matches);
1057 if (!pmic_plat_data) {
1058 dev_err(&pdev->dev, "Platform data not found\n");
1062 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1064 dev_err(&pdev->dev, "Memory allocation failed for pmic\n");
1068 mutex_init(&pmic->mutex);
1069 pmic->mfd = tps65910;
1070 platform_set_drvdata(pdev, pmic);
1072 /* Give control of all register to control port */
1073 tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1074 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1076 switch(tps65910_chip_id(tps65910)) {
1078 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1079 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1080 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1081 info = tps65910_regs;
1084 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1085 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1086 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1087 info = tps65911_regs;
1090 dev_err(&pdev->dev, "Invalid tps chip version\n");
1094 pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1095 sizeof(struct regulator_desc), GFP_KERNEL);
1097 dev_err(&pdev->dev, "Memory alloc fails for desc\n");
1101 pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1102 sizeof(struct tps_info *), GFP_KERNEL);
1104 dev_err(&pdev->dev, "Memory alloc fails for info\n");
1108 pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1109 sizeof(struct regulator_dev *), GFP_KERNEL);
1111 dev_err(&pdev->dev, "Memory alloc fails for rdev\n");
1115 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1118 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1120 /* Regulator API handles empty constraints but not NULL
1125 /* Register the regulators */
1126 pmic->info[i] = info;
1128 pmic->desc[i].name = info->name;
1129 pmic->desc[i].id = i;
1130 pmic->desc[i].n_voltages = info->n_voltages;
1131 pmic->desc[i].enable_time = info->enable_time_us;
1133 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1134 pmic->desc[i].ops = &tps65910_ops_dcdc;
1135 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1136 VDD1_2_NUM_VOLT_COARSE;
1137 pmic->desc[i].ramp_delay = 12500;
1138 } else if (i == TPS65910_REG_VDD3) {
1139 if (tps65910_chip_id(tps65910) == TPS65910) {
1140 pmic->desc[i].ops = &tps65910_ops_vdd3;
1141 pmic->desc[i].volt_table = info->voltage_table;
1143 pmic->desc[i].ops = &tps65910_ops_dcdc;
1144 pmic->desc[i].ramp_delay = 5000;
1147 if (tps65910_chip_id(tps65910) == TPS65910) {
1148 pmic->desc[i].ops = &tps65910_ops;
1149 pmic->desc[i].volt_table = info->voltage_table;
1151 pmic->desc[i].ops = &tps65911_ops;
1155 err = tps65910_set_ext_sleep_config(pmic, i,
1156 pmic_plat_data->regulator_ext_sleep_control[i]);
1158 * Failing on regulator for configuring externally control
1159 * is not a serious issue, just throw warning.
1162 dev_warn(tps65910->dev,
1163 "Failed to initialise ext control config\n");
1165 pmic->desc[i].type = REGULATOR_VOLTAGE;
1166 pmic->desc[i].owner = THIS_MODULE;
1167 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1168 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1170 config.dev = tps65910->dev;
1171 config.init_data = reg_data;
1172 config.driver_data = pmic;
1173 config.regmap = tps65910->regmap;
1175 if (tps65910_reg_matches)
1176 config.of_node = tps65910_reg_matches[i].of_node;
1178 rdev = regulator_register(&pmic->desc[i], &config);
1180 dev_err(tps65910->dev,
1181 "failed to register %s regulator\n",
1183 err = PTR_ERR(rdev);
1184 goto err_unregister_regulator;
1187 /* Save regulator for cleanup */
1188 pmic->rdev[i] = rdev;
1192 err_unregister_regulator:
1194 regulator_unregister(pmic->rdev[i]);
1198 static int __devexit tps65910_remove(struct platform_device *pdev)
1200 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1203 for (i = 0; i < pmic->num_regulators; i++)
1204 regulator_unregister(pmic->rdev[i]);
1209 static void tps65910_shutdown(struct platform_device *pdev)
1211 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1215 * Before bootloader jumps to kernel, it makes sure that required
1216 * external control signals are in desired state so that given rails
1217 * can be configure accordingly.
1218 * If rails are configured to be controlled from external control
1219 * then before shutting down/rebooting the system, the external
1220 * control configuration need to be remove from the rails so that
1221 * its output will be available as per register programming even
1222 * if external controls are removed. This is require when the POR
1223 * value of the control signals are not in active state and before
1224 * bootloader initializes it, the system requires the rail output
1225 * to be active for booting.
1227 for (i = 0; i < pmic->num_regulators; i++) {
1232 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1235 "Error in clearing external control\n");
1239 static struct platform_driver tps65910_driver = {
1241 .name = "tps65910-pmic",
1242 .owner = THIS_MODULE,
1244 .probe = tps65910_probe,
1245 .remove = __devexit_p(tps65910_remove),
1246 .shutdown = tps65910_shutdown,
1249 static int __init tps65910_init(void)
1251 return platform_driver_register(&tps65910_driver);
1253 subsys_initcall(tps65910_init);
1255 static void __exit tps65910_cleanup(void)
1257 platform_driver_unregister(&tps65910_driver);
1259 module_exit(tps65910_cleanup);
1261 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1262 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1263 MODULE_LICENSE("GPL v2");
1264 MODULE_ALIAS("platform:tps65910-pmic");