1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * tps65910.c -- TI tps65910
5 * Copyright 2010 Texas Instruments Inc.
7 * Author: Graeme Gregory <gg@slimlogic.co.uk>
8 * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/err.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/regulator/machine.h>
19 #include <linux/slab.h>
20 #include <linux/gpio.h>
21 #include <linux/mfd/tps65910.h>
22 #include <linux/regulator/of_regulator.h>
24 #define TPS65910_SUPPLY_STATE_ENABLED 0x1
25 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
26 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
27 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
28 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
30 /* supported VIO voltages in microvolts */
31 static const unsigned int VIO_VSEL_table[] = {
32 1500000, 1800000, 2500000, 3300000,
35 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
37 /* supported VRTC voltages in microvolts */
38 static const unsigned int VRTC_VSEL_table[] = {
42 /* supported VDD3 voltages in microvolts */
43 static const unsigned int VDD3_VSEL_table[] = {
47 /* supported VDIG1 voltages in microvolts */
48 static const unsigned int VDIG1_VSEL_table[] = {
49 1200000, 1500000, 1800000, 2700000,
52 /* supported VDIG2 voltages in microvolts */
53 static const unsigned int VDIG2_VSEL_table[] = {
54 1000000, 1100000, 1200000, 1800000,
57 /* supported VPLL voltages in microvolts */
58 static const unsigned int VPLL_VSEL_table[] = {
59 1000000, 1100000, 1800000, 2500000,
62 /* supported VDAC voltages in microvolts */
63 static const unsigned int VDAC_VSEL_table[] = {
64 1800000, 2600000, 2800000, 2850000,
67 /* supported VAUX1 voltages in microvolts */
68 static const unsigned int VAUX1_VSEL_table[] = {
69 1800000, 2500000, 2800000, 2850000,
72 /* supported VAUX2 voltages in microvolts */
73 static const unsigned int VAUX2_VSEL_table[] = {
74 1800000, 2800000, 2900000, 3300000,
77 /* supported VAUX33 voltages in microvolts */
78 static const unsigned int VAUX33_VSEL_table[] = {
79 1800000, 2000000, 2800000, 3300000,
82 /* supported VMMC voltages in microvolts */
83 static const unsigned int VMMC_VSEL_table[] = {
84 1800000, 2800000, 3000000, 3300000,
87 /* supported BBCH voltages in microvolts */
88 static const unsigned int VBB_VSEL_table[] = {
89 3000000, 2520000, 3150000, 5000000,
96 const unsigned int *voltage_table;
100 static struct tps_info tps65910_regs[] = {
104 .n_voltages = ARRAY_SIZE(VRTC_VSEL_table),
105 .voltage_table = VRTC_VSEL_table,
106 .enable_time_us = 2200,
111 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
112 .voltage_table = VIO_VSEL_table,
113 .enable_time_us = 350,
118 .enable_time_us = 350,
123 .enable_time_us = 350,
127 .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
128 .voltage_table = VDD3_VSEL_table,
129 .enable_time_us = 200,
134 .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
135 .voltage_table = VDIG1_VSEL_table,
136 .enable_time_us = 100,
141 .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
142 .voltage_table = VDIG2_VSEL_table,
143 .enable_time_us = 100,
148 .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
149 .voltage_table = VPLL_VSEL_table,
150 .enable_time_us = 100,
155 .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
156 .voltage_table = VDAC_VSEL_table,
157 .enable_time_us = 100,
162 .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
163 .voltage_table = VAUX1_VSEL_table,
164 .enable_time_us = 100,
169 .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
170 .voltage_table = VAUX2_VSEL_table,
171 .enable_time_us = 100,
176 .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
177 .voltage_table = VAUX33_VSEL_table,
178 .enable_time_us = 100,
183 .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
184 .voltage_table = VMMC_VSEL_table,
185 .enable_time_us = 100,
190 .n_voltages = ARRAY_SIZE(VBB_VSEL_table),
191 .voltage_table = VBB_VSEL_table,
195 static struct tps_info tps65911_regs[] = {
199 .enable_time_us = 2200,
204 .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
205 .voltage_table = VIO_VSEL_table,
206 .enable_time_us = 350,
212 .enable_time_us = 350,
218 .enable_time_us = 350,
223 .enable_time_us = 900,
229 .enable_time_us = 420,
235 .enable_time_us = 420,
241 .enable_time_us = 230,
247 .enable_time_us = 230,
253 .enable_time_us = 230,
259 .enable_time_us = 230,
265 .enable_time_us = 230,
271 .enable_time_us = 230,
275 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
276 static unsigned int tps65910_ext_sleep_control[] = {
278 EXT_CONTROL_REG_BITS(VIO, 1, 0),
279 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
280 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
281 EXT_CONTROL_REG_BITS(VDD3, 1, 3),
282 EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
283 EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
284 EXT_CONTROL_REG_BITS(VPLL, 0, 6),
285 EXT_CONTROL_REG_BITS(VDAC, 0, 7),
286 EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
287 EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
288 EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
289 EXT_CONTROL_REG_BITS(VMMC, 0, 0),
292 static unsigned int tps65911_ext_sleep_control[] = {
294 EXT_CONTROL_REG_BITS(VIO, 1, 0),
295 EXT_CONTROL_REG_BITS(VDD1, 1, 1),
296 EXT_CONTROL_REG_BITS(VDD2, 1, 2),
297 EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
298 EXT_CONTROL_REG_BITS(LDO1, 0, 1),
299 EXT_CONTROL_REG_BITS(LDO2, 0, 2),
300 EXT_CONTROL_REG_BITS(LDO3, 0, 7),
301 EXT_CONTROL_REG_BITS(LDO4, 0, 6),
302 EXT_CONTROL_REG_BITS(LDO5, 0, 3),
303 EXT_CONTROL_REG_BITS(LDO6, 0, 0),
304 EXT_CONTROL_REG_BITS(LDO7, 0, 5),
305 EXT_CONTROL_REG_BITS(LDO8, 0, 4),
308 struct tps65910_reg {
309 struct regulator_desc *desc;
310 struct tps65910 *mfd;
311 struct regulator_dev **rdev;
312 struct tps_info **info;
315 int (*get_ctrl_reg)(int);
316 unsigned int *ext_sleep_control;
317 unsigned int board_ext_control[TPS65910_NUM_REGS];
320 static int tps65910_get_ctrl_register(int id)
323 case TPS65910_REG_VRTC:
324 return TPS65910_VRTC;
325 case TPS65910_REG_VIO:
327 case TPS65910_REG_VDD1:
328 return TPS65910_VDD1;
329 case TPS65910_REG_VDD2:
330 return TPS65910_VDD2;
331 case TPS65910_REG_VDD3:
332 return TPS65910_VDD3;
333 case TPS65910_REG_VDIG1:
334 return TPS65910_VDIG1;
335 case TPS65910_REG_VDIG2:
336 return TPS65910_VDIG2;
337 case TPS65910_REG_VPLL:
338 return TPS65910_VPLL;
339 case TPS65910_REG_VDAC:
340 return TPS65910_VDAC;
341 case TPS65910_REG_VAUX1:
342 return TPS65910_VAUX1;
343 case TPS65910_REG_VAUX2:
344 return TPS65910_VAUX2;
345 case TPS65910_REG_VAUX33:
346 return TPS65910_VAUX33;
347 case TPS65910_REG_VMMC:
348 return TPS65910_VMMC;
349 case TPS65910_REG_VBB:
350 return TPS65910_BBCH;
356 static int tps65911_get_ctrl_register(int id)
359 case TPS65910_REG_VRTC:
360 return TPS65910_VRTC;
361 case TPS65910_REG_VIO:
363 case TPS65910_REG_VDD1:
364 return TPS65910_VDD1;
365 case TPS65910_REG_VDD2:
366 return TPS65910_VDD2;
367 case TPS65911_REG_VDDCTRL:
368 return TPS65911_VDDCTRL;
369 case TPS65911_REG_LDO1:
370 return TPS65911_LDO1;
371 case TPS65911_REG_LDO2:
372 return TPS65911_LDO2;
373 case TPS65911_REG_LDO3:
374 return TPS65911_LDO3;
375 case TPS65911_REG_LDO4:
376 return TPS65911_LDO4;
377 case TPS65911_REG_LDO5:
378 return TPS65911_LDO5;
379 case TPS65911_REG_LDO6:
380 return TPS65911_LDO6;
381 case TPS65911_REG_LDO7:
382 return TPS65911_LDO7;
383 case TPS65911_REG_LDO8:
384 return TPS65911_LDO8;
390 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
392 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
393 struct regmap *regmap = rdev_get_regmap(dev);
394 int reg, id = rdev_get_id(dev);
396 reg = pmic->get_ctrl_reg(id);
401 case REGULATOR_MODE_NORMAL:
402 return regmap_update_bits(regmap, reg,
403 LDO_ST_MODE_BIT | LDO_ST_ON_BIT,
405 case REGULATOR_MODE_IDLE:
406 return regmap_set_bits(regmap, reg,
407 LDO_ST_ON_BIT | LDO_ST_MODE_BIT);
408 case REGULATOR_MODE_STANDBY:
409 return regmap_clear_bits(regmap, reg, LDO_ST_ON_BIT);
415 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
417 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
418 struct regmap *regmap = rdev_get_regmap(dev);
419 int ret, reg, value, id = rdev_get_id(dev);
421 reg = pmic->get_ctrl_reg(id);
425 ret = regmap_read(regmap, reg, &value);
429 if (!(value & LDO_ST_ON_BIT))
430 return REGULATOR_MODE_STANDBY;
431 else if (value & LDO_ST_MODE_BIT)
432 return REGULATOR_MODE_IDLE;
434 return REGULATOR_MODE_NORMAL;
437 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
439 struct regmap *regmap = rdev_get_regmap(dev);
440 int ret, id = rdev_get_id(dev);
441 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
444 case TPS65910_REG_VDD1:
445 ret = regmap_read(regmap, TPS65910_VDD1_OP, &opvsel);
448 ret = regmap_read(regmap, TPS65910_VDD1, &mult);
451 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
452 ret = regmap_read(regmap, TPS65910_VDD1_SR, &srvsel);
455 sr = opvsel & VDD1_OP_CMD_MASK;
456 opvsel &= VDD1_OP_SEL_MASK;
457 srvsel &= VDD1_SR_SEL_MASK;
460 case TPS65910_REG_VDD2:
461 ret = regmap_read(regmap, TPS65910_VDD2_OP, &opvsel);
464 ret = regmap_read(regmap, TPS65910_VDD2, &mult);
467 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
468 ret = regmap_read(regmap, TPS65910_VDD2_SR, &srvsel);
471 sr = opvsel & VDD2_OP_CMD_MASK;
472 opvsel &= VDD2_OP_SEL_MASK;
473 srvsel &= VDD2_SR_SEL_MASK;
476 case TPS65911_REG_VDDCTRL:
477 ret = regmap_read(regmap, TPS65911_VDDCTRL_OP, &opvsel);
480 ret = regmap_read(regmap, TPS65911_VDDCTRL_SR, &srvsel);
483 sr = opvsel & VDDCTRL_OP_CMD_MASK;
484 opvsel &= VDDCTRL_OP_SEL_MASK;
485 srvsel &= VDDCTRL_SR_SEL_MASK;
490 /* multiplier 0 == 1 but 2,3 normal */
495 /* normalise to valid range */
498 if (srvsel > vselmax)
503 /* normalise to valid range*/
506 if (opvsel > vselmax)
513 static int tps65910_get_voltage_sel(struct regulator_dev *dev)
515 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
516 struct regmap *regmap = rdev_get_regmap(dev);
517 int ret, reg, value, id = rdev_get_id(dev);
519 reg = pmic->get_ctrl_reg(id);
523 ret = regmap_read(regmap, reg, &value);
528 case TPS65910_REG_VIO:
529 case TPS65910_REG_VDIG1:
530 case TPS65910_REG_VDIG2:
531 case TPS65910_REG_VPLL:
532 case TPS65910_REG_VDAC:
533 case TPS65910_REG_VAUX1:
534 case TPS65910_REG_VAUX2:
535 case TPS65910_REG_VAUX33:
536 case TPS65910_REG_VMMC:
537 value &= LDO_SEL_MASK;
538 value >>= LDO_SEL_SHIFT;
540 case TPS65910_REG_VBB:
541 value &= BBCH_BBSEL_MASK;
542 value >>= BBCH_BBSEL_SHIFT;
551 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
553 return dev->desc->volt_table[0];
556 static int tps65911_get_voltage_sel(struct regulator_dev *dev)
558 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
559 struct regmap *regmap = rdev_get_regmap(dev);
560 int ret, id = rdev_get_id(dev);
561 unsigned int value, reg;
563 reg = pmic->get_ctrl_reg(id);
565 ret = regmap_read(regmap, reg, &value);
570 case TPS65911_REG_LDO1:
571 case TPS65911_REG_LDO2:
572 case TPS65911_REG_LDO4:
573 value &= LDO1_SEL_MASK;
574 value >>= LDO_SEL_SHIFT;
576 case TPS65911_REG_LDO3:
577 case TPS65911_REG_LDO5:
578 case TPS65911_REG_LDO6:
579 case TPS65911_REG_LDO7:
580 case TPS65911_REG_LDO8:
581 value &= LDO3_SEL_MASK;
582 value >>= LDO_SEL_SHIFT;
584 case TPS65910_REG_VIO:
585 value &= LDO_SEL_MASK;
586 value >>= LDO_SEL_SHIFT;
595 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
598 struct regmap *regmap = rdev_get_regmap(dev);
599 int id = rdev_get_id(dev), vsel;
603 case TPS65910_REG_VDD1:
604 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
607 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
609 regmap_update_bits(regmap, TPS65910_VDD1, VDD1_VGAIN_SEL_MASK,
610 dcdc_mult << VDD1_VGAIN_SEL_SHIFT);
611 regmap_write(regmap, 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 regmap_update_bits(regmap, TPS65910_VDD2, VDD1_VGAIN_SEL_MASK,
620 dcdc_mult << VDD2_VGAIN_SEL_SHIFT);
621 regmap_write(regmap, TPS65910_VDD2_OP, vsel);
623 case TPS65911_REG_VDDCTRL:
625 regmap_write(regmap, 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 struct regmap *regmap = rdev_get_regmap(dev);
637 int reg, id = rdev_get_id(dev);
639 reg = pmic->get_ctrl_reg(id);
644 case TPS65910_REG_VIO:
645 case TPS65910_REG_VDIG1:
646 case TPS65910_REG_VDIG2:
647 case TPS65910_REG_VPLL:
648 case TPS65910_REG_VDAC:
649 case TPS65910_REG_VAUX1:
650 case TPS65910_REG_VAUX2:
651 case TPS65910_REG_VAUX33:
652 case TPS65910_REG_VMMC:
653 return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
654 selector << LDO_SEL_SHIFT);
655 case TPS65910_REG_VBB:
656 return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
657 selector << BBCH_BBSEL_SHIFT);
663 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
666 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
667 struct regmap *regmap = rdev_get_regmap(dev);
668 int reg, id = rdev_get_id(dev);
670 reg = pmic->get_ctrl_reg(id);
675 case TPS65911_REG_LDO1:
676 case TPS65911_REG_LDO2:
677 case TPS65911_REG_LDO4:
678 return regmap_update_bits(regmap, reg, LDO1_SEL_MASK,
679 selector << LDO_SEL_SHIFT);
680 case TPS65911_REG_LDO3:
681 case TPS65911_REG_LDO5:
682 case TPS65911_REG_LDO6:
683 case TPS65911_REG_LDO7:
684 case TPS65911_REG_LDO8:
685 return regmap_update_bits(regmap, reg, LDO3_SEL_MASK,
686 selector << LDO_SEL_SHIFT);
687 case TPS65910_REG_VIO:
688 return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
689 selector << LDO_SEL_SHIFT);
690 case TPS65910_REG_VBB:
691 return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
692 selector << BBCH_BBSEL_SHIFT);
699 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
702 int volt, mult = 1, id = rdev_get_id(dev);
705 case TPS65910_REG_VDD1:
706 case TPS65910_REG_VDD2:
707 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
708 volt = VDD1_2_MIN_VOLT +
709 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
711 case TPS65911_REG_VDDCTRL:
712 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
719 return volt * 100 * mult;
722 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
724 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
725 int step_mv = 0, id = rdev_get_id(dev);
728 case TPS65911_REG_LDO1:
729 case TPS65911_REG_LDO2:
730 case TPS65911_REG_LDO4:
731 /* The first 5 values of the selector correspond to 1V */
739 case TPS65911_REG_LDO3:
740 case TPS65911_REG_LDO5:
741 case TPS65911_REG_LDO6:
742 case TPS65911_REG_LDO7:
743 case TPS65911_REG_LDO8:
744 /* The first 3 values of the selector correspond to 1V */
752 case TPS65910_REG_VIO:
753 return pmic->info[id]->voltage_table[selector];
758 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
761 /* Regulator ops (except VRTC) */
762 static const struct regulator_ops tps65910_ops_dcdc = {
763 .is_enabled = regulator_is_enabled_regmap,
764 .enable = regulator_enable_regmap,
765 .disable = regulator_disable_regmap,
766 .set_mode = tps65910_set_mode,
767 .get_mode = tps65910_get_mode,
768 .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
769 .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
770 .set_voltage_time_sel = regulator_set_voltage_time_sel,
771 .list_voltage = tps65910_list_voltage_dcdc,
772 .map_voltage = regulator_map_voltage_ascend,
775 static const struct regulator_ops tps65910_ops_vdd3 = {
776 .is_enabled = regulator_is_enabled_regmap,
777 .enable = regulator_enable_regmap,
778 .disable = regulator_disable_regmap,
779 .set_mode = tps65910_set_mode,
780 .get_mode = tps65910_get_mode,
781 .get_voltage = tps65910_get_voltage_vdd3,
782 .list_voltage = regulator_list_voltage_table,
783 .map_voltage = regulator_map_voltage_ascend,
786 static const struct regulator_ops tps65910_ops_vbb = {
787 .is_enabled = regulator_is_enabled_regmap,
788 .enable = regulator_enable_regmap,
789 .disable = regulator_disable_regmap,
790 .set_mode = tps65910_set_mode,
791 .get_mode = tps65910_get_mode,
792 .get_voltage_sel = tps65910_get_voltage_sel,
793 .set_voltage_sel = tps65910_set_voltage_sel,
794 .list_voltage = regulator_list_voltage_table,
795 .map_voltage = regulator_map_voltage_iterate,
798 static const struct regulator_ops tps65910_ops = {
799 .is_enabled = regulator_is_enabled_regmap,
800 .enable = regulator_enable_regmap,
801 .disable = regulator_disable_regmap,
802 .set_mode = tps65910_set_mode,
803 .get_mode = tps65910_get_mode,
804 .get_voltage_sel = tps65910_get_voltage_sel,
805 .set_voltage_sel = tps65910_set_voltage_sel,
806 .list_voltage = regulator_list_voltage_table,
807 .map_voltage = regulator_map_voltage_ascend,
810 static const struct regulator_ops tps65911_ops = {
811 .is_enabled = regulator_is_enabled_regmap,
812 .enable = regulator_enable_regmap,
813 .disable = regulator_disable_regmap,
814 .set_mode = tps65910_set_mode,
815 .get_mode = tps65910_get_mode,
816 .get_voltage_sel = tps65911_get_voltage_sel,
817 .set_voltage_sel = tps65911_set_voltage_sel,
818 .list_voltage = tps65911_list_voltage,
819 .map_voltage = regulator_map_voltage_ascend,
822 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
823 int id, int ext_sleep_config)
825 struct tps65910 *mfd = pmic->mfd;
826 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
827 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
831 * Regulator can not be control from multiple external input EN1, EN2
834 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
836 en_count = ((ext_sleep_config &
837 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
838 en_count += ((ext_sleep_config &
839 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
840 en_count += ((ext_sleep_config &
841 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
842 en_count += ((ext_sleep_config &
843 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
846 "External sleep control flag is not proper\n");
851 pmic->board_ext_control[id] = ext_sleep_config;
853 /* External EN1 control */
854 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
855 ret = regmap_set_bits(mfd->regmap,
856 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
858 ret = regmap_clear_bits(mfd->regmap,
859 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
862 "Error in configuring external control EN1\n");
866 /* External EN2 control */
867 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
868 ret = regmap_set_bits(mfd->regmap,
869 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
871 ret = regmap_clear_bits(mfd->regmap,
872 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
875 "Error in configuring external control EN2\n");
879 /* External EN3 control for TPS65910 LDO only */
880 if ((tps65910_chip_id(mfd) == TPS65910) &&
881 (id >= TPS65910_REG_VDIG1)) {
882 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
883 ret = regmap_set_bits(mfd->regmap,
884 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
886 ret = regmap_clear_bits(mfd->regmap,
887 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
890 "Error in configuring external control EN3\n");
895 /* Return if no external control is selected */
896 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
897 /* Clear all sleep controls */
898 ret = regmap_clear_bits(mfd->regmap,
899 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
901 ret = regmap_clear_bits(mfd->regmap,
902 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
905 "Error in configuring SLEEP register\n");
910 * For regulator that has separate operational and sleep register make
911 * sure that operational is used and clear sleep register to turn
912 * regulator off when external control is inactive
914 if ((id == TPS65910_REG_VDD1) ||
915 (id == TPS65910_REG_VDD2) ||
916 ((id == TPS65911_REG_VDDCTRL) &&
917 (tps65910_chip_id(mfd) == TPS65911))) {
918 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
919 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
922 ret = regmap_read(mfd->regmap, op_reg_add, &opvsel);
925 ret = regmap_read(mfd->regmap, sr_reg_add, &srvsel);
929 if (opvsel & VDD1_OP_CMD_MASK) {
930 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
932 ret = regmap_write(mfd->regmap, op_reg_add, reg_val);
935 "Error in configuring op register\n");
939 ret = regmap_write(mfd->regmap, sr_reg_add, 0);
941 dev_err(mfd->dev, "Error in setting sr register\n");
946 ret = regmap_clear_bits(mfd->regmap,
947 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
949 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
950 ret = regmap_set_bits(mfd->regmap,
951 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
953 ret = regmap_clear_bits(mfd->regmap,
954 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
958 "Error in configuring SLEEP register\n");
965 static struct of_regulator_match tps65910_matches[] = {
966 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
967 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
968 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
969 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
970 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
971 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
972 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
973 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
974 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
975 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
976 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
977 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
978 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
979 { .name = "vbb", .driver_data = (void *) &tps65910_regs[13] },
982 static struct of_regulator_match tps65911_matches[] = {
983 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
984 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
985 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
986 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
987 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
988 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
989 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
990 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
991 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
992 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
993 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
994 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
995 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
998 static struct tps65910_board *tps65910_parse_dt_reg_data(
999 struct platform_device *pdev,
1000 struct of_regulator_match **tps65910_reg_matches)
1002 struct tps65910_board *pmic_plat_data;
1003 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1004 struct device_node *np, *regulators;
1005 struct of_regulator_match *matches;
1007 int idx = 0, ret, count;
1009 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
1011 if (!pmic_plat_data)
1014 np = pdev->dev.parent->of_node;
1015 regulators = of_get_child_by_name(np, "regulators");
1017 dev_err(&pdev->dev, "regulator node not found\n");
1021 switch (tps65910_chip_id(tps65910)) {
1023 count = ARRAY_SIZE(tps65910_matches);
1024 matches = tps65910_matches;
1027 count = ARRAY_SIZE(tps65911_matches);
1028 matches = tps65911_matches;
1031 of_node_put(regulators);
1032 dev_err(&pdev->dev, "Invalid tps chip version\n");
1036 ret = of_regulator_match(&pdev->dev, regulators, matches, count);
1037 of_node_put(regulators);
1039 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1044 *tps65910_reg_matches = matches;
1046 for (idx = 0; idx < count; idx++) {
1047 if (!matches[idx].of_node)
1050 pmic_plat_data->tps65910_pmic_init_data[idx] =
1051 matches[idx].init_data;
1053 ret = of_property_read_u32(matches[idx].of_node,
1054 "ti,regulator-ext-sleep-control", &prop);
1056 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1060 return pmic_plat_data;
1063 static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1064 struct platform_device *pdev,
1065 struct of_regulator_match **tps65910_reg_matches)
1067 *tps65910_reg_matches = NULL;
1072 static int tps65910_probe(struct platform_device *pdev)
1074 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1075 struct regulator_config config = { };
1076 struct tps_info *info;
1077 struct regulator_dev *rdev;
1078 struct tps65910_reg *pmic;
1079 struct tps65910_board *pmic_plat_data;
1080 struct of_regulator_match *tps65910_reg_matches = NULL;
1083 pmic_plat_data = dev_get_platdata(tps65910->dev);
1084 if (!pmic_plat_data && tps65910->dev->of_node)
1085 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1086 &tps65910_reg_matches);
1088 if (!pmic_plat_data) {
1089 dev_err(&pdev->dev, "Platform data not found\n");
1093 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1097 pmic->mfd = tps65910;
1098 platform_set_drvdata(pdev, pmic);
1100 /* Give control of all register to control port */
1101 err = regmap_set_bits(pmic->mfd->regmap, TPS65910_DEVCTRL,
1102 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1106 switch (tps65910_chip_id(tps65910)) {
1108 BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
1109 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1110 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1111 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1112 info = tps65910_regs;
1113 /* Work around silicon erratum SWCZ010: output programmed
1114 * voltage level can go higher than expected or crash
1115 * Workaround: use no synchronization of DCDC clocks
1117 regmap_clear_bits(pmic->mfd->regmap, TPS65910_DCDCCTRL,
1118 DCDCCTRL_DCDCCKSYNC_MASK);
1121 BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
1122 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1123 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1124 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1125 info = tps65911_regs;
1128 dev_err(&pdev->dev, "Invalid tps chip version\n");
1132 pmic->desc = devm_kcalloc(&pdev->dev,
1133 pmic->num_regulators,
1134 sizeof(struct regulator_desc),
1139 pmic->info = devm_kcalloc(&pdev->dev,
1140 pmic->num_regulators,
1141 sizeof(struct tps_info *),
1146 pmic->rdev = devm_kcalloc(&pdev->dev,
1147 pmic->num_regulators,
1148 sizeof(struct regulator_dev *),
1153 for (i = 0; i < pmic->num_regulators; i++, info++) {
1154 /* Register the regulators */
1155 pmic->info[i] = info;
1157 pmic->desc[i].name = info->name;
1158 pmic->desc[i].supply_name = info->vin_name;
1159 pmic->desc[i].id = i;
1160 pmic->desc[i].n_voltages = info->n_voltages;
1161 pmic->desc[i].enable_time = info->enable_time_us;
1163 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1164 pmic->desc[i].ops = &tps65910_ops_dcdc;
1165 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1166 VDD1_2_NUM_VOLT_COARSE;
1167 pmic->desc[i].ramp_delay = 12500;
1168 } else if (i == TPS65910_REG_VDD3) {
1169 if (tps65910_chip_id(tps65910) == TPS65910) {
1170 pmic->desc[i].ops = &tps65910_ops_vdd3;
1171 pmic->desc[i].volt_table = info->voltage_table;
1173 pmic->desc[i].ops = &tps65910_ops_dcdc;
1174 pmic->desc[i].ramp_delay = 5000;
1176 } else if (i == TPS65910_REG_VBB &&
1177 tps65910_chip_id(tps65910) == TPS65910) {
1178 pmic->desc[i].ops = &tps65910_ops_vbb;
1179 pmic->desc[i].volt_table = info->voltage_table;
1181 if (tps65910_chip_id(tps65910) == TPS65910) {
1182 pmic->desc[i].ops = &tps65910_ops;
1183 pmic->desc[i].volt_table = info->voltage_table;
1185 pmic->desc[i].ops = &tps65911_ops;
1189 err = tps65910_set_ext_sleep_config(pmic, i,
1190 pmic_plat_data->regulator_ext_sleep_control[i]);
1192 * Failing on regulator for configuring externally control
1193 * is not a serious issue, just throw warning.
1196 dev_warn(tps65910->dev,
1197 "Failed to initialise ext control config\n");
1199 pmic->desc[i].type = REGULATOR_VOLTAGE;
1200 pmic->desc[i].owner = THIS_MODULE;
1201 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1202 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1204 config.dev = tps65910->dev;
1205 config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
1206 config.driver_data = pmic;
1207 config.regmap = tps65910->regmap;
1209 if (tps65910_reg_matches)
1210 config.of_node = tps65910_reg_matches[i].of_node;
1212 rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
1215 return dev_err_probe(tps65910->dev, PTR_ERR(rdev),
1216 "failed to register %s regulator\n",
1219 /* Save regulator for cleanup */
1220 pmic->rdev[i] = rdev;
1225 static void tps65910_shutdown(struct platform_device *pdev)
1227 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1231 * Before bootloader jumps to kernel, it makes sure that required
1232 * external control signals are in desired state so that given rails
1233 * can be configure accordingly.
1234 * If rails are configured to be controlled from external control
1235 * then before shutting down/rebooting the system, the external
1236 * control configuration need to be remove from the rails so that
1237 * its output will be available as per register programming even
1238 * if external controls are removed. This is require when the POR
1239 * value of the control signals are not in active state and before
1240 * bootloader initializes it, the system requires the rail output
1241 * to be active for booting.
1243 for (i = 0; i < pmic->num_regulators; i++) {
1248 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1251 "Error in clearing external control\n");
1255 static struct platform_driver tps65910_driver = {
1257 .name = "tps65910-pmic",
1259 .probe = tps65910_probe,
1260 .shutdown = tps65910_shutdown,
1263 static int __init tps65910_init(void)
1265 return platform_driver_register(&tps65910_driver);
1267 subsys_initcall(tps65910_init);
1269 static void __exit tps65910_cleanup(void)
1271 platform_driver_unregister(&tps65910_driver);
1273 module_exit(tps65910_cleanup);
1275 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1276 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1277 MODULE_LICENSE("GPL v2");
1278 MODULE_ALIAS("platform:tps65910-pmic");