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_enable_time(struct regulator_dev *dev)
417 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
418 int id = rdev_get_id(dev);
419 return pmic->info[id]->enable_time_us;
422 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
424 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
425 struct tps65910 *mfd = pmic->mfd;
426 int reg, value, id = rdev_get_id(dev);
428 reg = pmic->get_ctrl_reg(id);
433 case REGULATOR_MODE_NORMAL:
434 return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT,
436 case REGULATOR_MODE_IDLE:
437 value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
438 return tps65910_reg_set_bits(mfd, reg, value);
439 case REGULATOR_MODE_STANDBY:
440 return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
446 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
448 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
449 int reg, value, id = rdev_get_id(dev);
451 reg = pmic->get_ctrl_reg(id);
455 value = tps65910_reg_read_locked(pmic, reg);
459 if (!(value & LDO_ST_ON_BIT))
460 return REGULATOR_MODE_STANDBY;
461 else if (value & LDO_ST_MODE_BIT)
462 return REGULATOR_MODE_IDLE;
464 return REGULATOR_MODE_NORMAL;
467 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
469 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
470 int id = rdev_get_id(dev);
471 int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
474 case TPS65910_REG_VDD1:
475 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
476 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
477 mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
478 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
479 sr = opvsel & VDD1_OP_CMD_MASK;
480 opvsel &= VDD1_OP_SEL_MASK;
481 srvsel &= VDD1_SR_SEL_MASK;
484 case TPS65910_REG_VDD2:
485 opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
486 mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
487 mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
488 srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
489 sr = opvsel & VDD2_OP_CMD_MASK;
490 opvsel &= VDD2_OP_SEL_MASK;
491 srvsel &= VDD2_SR_SEL_MASK;
494 case TPS65911_REG_VDDCTRL:
495 opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
496 srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
497 sr = opvsel & VDDCTRL_OP_CMD_MASK;
498 opvsel &= VDDCTRL_OP_SEL_MASK;
499 srvsel &= VDDCTRL_SR_SEL_MASK;
504 /* multiplier 0 == 1 but 2,3 normal */
509 /* normalise to valid range */
512 if (srvsel > vselmax)
517 /* normalise to valid range*/
520 if (opvsel > vselmax)
527 static int tps65910_get_voltage_sel(struct regulator_dev *dev)
529 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
530 int reg, value, id = rdev_get_id(dev);
532 reg = pmic->get_ctrl_reg(id);
536 value = tps65910_reg_read_locked(pmic, reg);
541 case TPS65910_REG_VIO:
542 case TPS65910_REG_VDIG1:
543 case TPS65910_REG_VDIG2:
544 case TPS65910_REG_VPLL:
545 case TPS65910_REG_VDAC:
546 case TPS65910_REG_VAUX1:
547 case TPS65910_REG_VAUX2:
548 case TPS65910_REG_VAUX33:
549 case TPS65910_REG_VMMC:
550 value &= LDO_SEL_MASK;
551 value >>= LDO_SEL_SHIFT;
560 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
562 return dev->desc->volt_table[0];
565 static int tps65911_get_voltage_sel(struct regulator_dev *dev)
567 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
568 int id = rdev_get_id(dev);
571 reg = pmic->get_ctrl_reg(id);
573 value = tps65910_reg_read_locked(pmic, reg);
576 case TPS65911_REG_LDO1:
577 case TPS65911_REG_LDO2:
578 case TPS65911_REG_LDO4:
579 value &= LDO1_SEL_MASK;
580 value >>= LDO_SEL_SHIFT;
582 case TPS65911_REG_LDO3:
583 case TPS65911_REG_LDO5:
584 case TPS65911_REG_LDO6:
585 case TPS65911_REG_LDO7:
586 case TPS65911_REG_LDO8:
587 value &= LDO3_SEL_MASK;
588 value >>= LDO_SEL_SHIFT;
590 case TPS65910_REG_VIO:
591 value &= LDO_SEL_MASK;
592 value >>= LDO_SEL_SHIFT;
601 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
604 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
605 int id = rdev_get_id(dev), vsel;
609 case TPS65910_REG_VDD1:
610 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
613 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
615 tps65910_modify_bits(pmic, TPS65910_VDD1,
616 (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
617 VDD1_VGAIN_SEL_MASK);
618 tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
620 case TPS65910_REG_VDD2:
621 dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
624 vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
626 tps65910_modify_bits(pmic, TPS65910_VDD2,
627 (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
628 VDD1_VGAIN_SEL_MASK);
629 tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
631 case TPS65911_REG_VDDCTRL:
633 tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
639 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
642 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
643 int reg, id = rdev_get_id(dev);
645 reg = pmic->get_ctrl_reg(id);
650 case TPS65910_REG_VIO:
651 case TPS65910_REG_VDIG1:
652 case TPS65910_REG_VDIG2:
653 case TPS65910_REG_VPLL:
654 case TPS65910_REG_VDAC:
655 case TPS65910_REG_VAUX1:
656 case TPS65910_REG_VAUX2:
657 case TPS65910_REG_VAUX33:
658 case TPS65910_REG_VMMC:
659 return tps65910_modify_bits(pmic, reg,
660 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
666 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
669 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
670 int reg, id = rdev_get_id(dev);
672 reg = pmic->get_ctrl_reg(id);
677 case TPS65911_REG_LDO1:
678 case TPS65911_REG_LDO2:
679 case TPS65911_REG_LDO4:
680 return tps65910_modify_bits(pmic, reg,
681 (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK);
682 case TPS65911_REG_LDO3:
683 case TPS65911_REG_LDO5:
684 case TPS65911_REG_LDO6:
685 case TPS65911_REG_LDO7:
686 case TPS65911_REG_LDO8:
687 return tps65910_modify_bits(pmic, reg,
688 (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK);
689 case TPS65910_REG_VIO:
690 return tps65910_modify_bits(pmic, reg,
691 (selector << LDO_SEL_SHIFT), LDO_SEL_MASK);
698 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
701 int volt, mult = 1, id = rdev_get_id(dev);
704 case TPS65910_REG_VDD1:
705 case TPS65910_REG_VDD2:
706 mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
707 volt = VDD1_2_MIN_VOLT +
708 (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
710 case TPS65911_REG_VDDCTRL:
711 volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
718 return volt * 100 * mult;
721 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
723 struct tps65910_reg *pmic = rdev_get_drvdata(dev);
724 int step_mv = 0, id = rdev_get_id(dev);
727 case TPS65911_REG_LDO1:
728 case TPS65911_REG_LDO2:
729 case TPS65911_REG_LDO4:
730 /* The first 5 values of the selector correspond to 1V */
738 case TPS65911_REG_LDO3:
739 case TPS65911_REG_LDO5:
740 case TPS65911_REG_LDO6:
741 case TPS65911_REG_LDO7:
742 case TPS65911_REG_LDO8:
743 /* The first 3 values of the selector correspond to 1V */
751 case TPS65910_REG_VIO:
752 return pmic->info[id]->voltage_table[selector];
757 return (LDO_MIN_VOLT + selector * step_mv) * 1000;
760 /* Regulator ops (except VRTC) */
761 static struct regulator_ops tps65910_ops_dcdc = {
762 .is_enabled = regulator_is_enabled_regmap,
763 .enable = regulator_enable_regmap,
764 .disable = regulator_disable_regmap,
765 .enable_time = tps65910_enable_time,
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,
774 static struct regulator_ops tps65910_ops_vdd3 = {
775 .is_enabled = regulator_is_enabled_regmap,
776 .enable = regulator_enable_regmap,
777 .disable = regulator_disable_regmap,
778 .enable_time = tps65910_enable_time,
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,
785 static struct regulator_ops tps65910_ops = {
786 .is_enabled = regulator_is_enabled_regmap,
787 .enable = regulator_enable_regmap,
788 .disable = regulator_disable_regmap,
789 .enable_time = tps65910_enable_time,
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,
797 static struct regulator_ops tps65911_ops = {
798 .is_enabled = regulator_is_enabled_regmap,
799 .enable = regulator_enable_regmap,
800 .disable = regulator_disable_regmap,
801 .enable_time = tps65910_enable_time,
802 .set_mode = tps65910_set_mode,
803 .get_mode = tps65910_get_mode,
804 .get_voltage_sel = tps65911_get_voltage_sel,
805 .set_voltage_sel = tps65911_set_voltage_sel,
806 .list_voltage = tps65911_list_voltage,
809 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
810 int id, int ext_sleep_config)
812 struct tps65910 *mfd = pmic->mfd;
813 u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
814 u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
818 * Regulator can not be control from multiple external input EN1, EN2
821 if (ext_sleep_config & EXT_SLEEP_CONTROL) {
823 en_count = ((ext_sleep_config &
824 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
825 en_count += ((ext_sleep_config &
826 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
827 en_count += ((ext_sleep_config &
828 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
829 en_count += ((ext_sleep_config &
830 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
833 "External sleep control flag is not proper\n");
838 pmic->board_ext_control[id] = ext_sleep_config;
840 /* External EN1 control */
841 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
842 ret = tps65910_reg_set_bits(mfd,
843 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
845 ret = tps65910_reg_clear_bits(mfd,
846 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
849 "Error in configuring external control EN1\n");
853 /* External EN2 control */
854 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
855 ret = tps65910_reg_set_bits(mfd,
856 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
858 ret = tps65910_reg_clear_bits(mfd,
859 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
862 "Error in configuring external control EN2\n");
866 /* External EN3 control for TPS65910 LDO only */
867 if ((tps65910_chip_id(mfd) == TPS65910) &&
868 (id >= TPS65910_REG_VDIG1)) {
869 if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
870 ret = tps65910_reg_set_bits(mfd,
871 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
873 ret = tps65910_reg_clear_bits(mfd,
874 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
877 "Error in configuring external control EN3\n");
882 /* Return if no external control is selected */
883 if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
884 /* Clear all sleep controls */
885 ret = tps65910_reg_clear_bits(mfd,
886 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
888 ret = tps65910_reg_clear_bits(mfd,
889 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
892 "Error in configuring SLEEP register\n");
897 * For regulator that has separate operational and sleep register make
898 * sure that operational is used and clear sleep register to turn
899 * regulator off when external control is inactive
901 if ((id == TPS65910_REG_VDD1) ||
902 (id == TPS65910_REG_VDD2) ||
903 ((id == TPS65911_REG_VDDCTRL) &&
904 (tps65910_chip_id(mfd) == TPS65911))) {
905 int op_reg_add = pmic->get_ctrl_reg(id) + 1;
906 int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
907 int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
908 int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
909 if (opvsel & VDD1_OP_CMD_MASK) {
910 u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
911 ret = tps65910_reg_write_locked(pmic, op_reg_add,
915 "Error in configuring op register\n");
919 ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
921 dev_err(mfd->dev, "Error in settting sr register\n");
926 ret = tps65910_reg_clear_bits(mfd,
927 TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
929 if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
930 ret = tps65910_reg_set_bits(mfd,
931 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
933 ret = tps65910_reg_clear_bits(mfd,
934 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
938 "Error in configuring SLEEP register\n");
945 static struct of_regulator_match tps65910_matches[] = {
946 { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
947 { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
948 { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
949 { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
950 { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
951 { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
952 { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
953 { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
954 { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
955 { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
956 { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
957 { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
958 { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
961 static struct of_regulator_match tps65911_matches[] = {
962 { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
963 { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
964 { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
965 { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
966 { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
967 { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
968 { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
969 { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
970 { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
971 { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
972 { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
973 { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
974 { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
977 static struct tps65910_board *tps65910_parse_dt_reg_data(
978 struct platform_device *pdev,
979 struct of_regulator_match **tps65910_reg_matches)
981 struct tps65910_board *pmic_plat_data;
982 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
983 struct device_node *np = pdev->dev.parent->of_node;
984 struct device_node *regulators;
985 struct of_regulator_match *matches;
987 int idx = 0, ret, count;
989 pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
992 if (!pmic_plat_data) {
993 dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
997 regulators = of_find_node_by_name(np, "regulators");
999 dev_err(&pdev->dev, "regulator node not found\n");
1003 switch (tps65910_chip_id(tps65910)) {
1005 count = ARRAY_SIZE(tps65910_matches);
1006 matches = tps65910_matches;
1009 count = ARRAY_SIZE(tps65911_matches);
1010 matches = tps65911_matches;
1013 dev_err(&pdev->dev, "Invalid tps chip version\n");
1017 ret = of_regulator_match(pdev->dev.parent, regulators, matches, count);
1019 dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1024 *tps65910_reg_matches = matches;
1026 for (idx = 0; idx < count; idx++) {
1027 if (!matches[idx].init_data || !matches[idx].of_node)
1030 pmic_plat_data->tps65910_pmic_init_data[idx] =
1031 matches[idx].init_data;
1033 ret = of_property_read_u32(matches[idx].of_node,
1034 "ti,regulator-ext-sleep-control", &prop);
1036 pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1039 return pmic_plat_data;
1042 static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1043 struct platform_device *pdev,
1044 struct of_regulator_match **tps65910_reg_matches)
1046 *tps65910_reg_matches = NULL;
1051 static __devinit int tps65910_probe(struct platform_device *pdev)
1053 struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
1054 struct regulator_config config = { };
1055 struct tps_info *info;
1056 struct regulator_init_data *reg_data;
1057 struct regulator_dev *rdev;
1058 struct tps65910_reg *pmic;
1059 struct tps65910_board *pmic_plat_data;
1060 struct of_regulator_match *tps65910_reg_matches = NULL;
1063 pmic_plat_data = dev_get_platdata(tps65910->dev);
1064 if (!pmic_plat_data && tps65910->dev->of_node)
1065 pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
1066 &tps65910_reg_matches);
1068 if (!pmic_plat_data) {
1069 dev_err(&pdev->dev, "Platform data not found\n");
1073 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1075 dev_err(&pdev->dev, "Memory allocation failed for pmic\n");
1079 mutex_init(&pmic->mutex);
1080 pmic->mfd = tps65910;
1081 platform_set_drvdata(pdev, pmic);
1083 /* Give control of all register to control port */
1084 tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
1085 DEVCTRL_SR_CTL_I2C_SEL_MASK);
1087 switch(tps65910_chip_id(tps65910)) {
1089 pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
1090 pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
1091 pmic->ext_sleep_control = tps65910_ext_sleep_control;
1092 info = tps65910_regs;
1095 pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
1096 pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
1097 pmic->ext_sleep_control = tps65911_ext_sleep_control;
1098 info = tps65911_regs;
1101 dev_err(&pdev->dev, "Invalid tps chip version\n");
1105 pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1106 sizeof(struct regulator_desc), GFP_KERNEL);
1108 dev_err(&pdev->dev, "Memory alloc fails for desc\n");
1112 pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1113 sizeof(struct tps_info *), GFP_KERNEL);
1115 dev_err(&pdev->dev, "Memory alloc fails for info\n");
1119 pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators *
1120 sizeof(struct regulator_dev *), GFP_KERNEL);
1122 dev_err(&pdev->dev, "Memory alloc fails for rdev\n");
1126 for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
1129 reg_data = pmic_plat_data->tps65910_pmic_init_data[i];
1131 /* Regulator API handles empty constraints but not NULL
1136 /* Register the regulators */
1137 pmic->info[i] = info;
1139 pmic->desc[i].name = info->name;
1140 pmic->desc[i].id = i;
1141 pmic->desc[i].n_voltages = info->n_voltages;
1143 if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
1144 pmic->desc[i].ops = &tps65910_ops_dcdc;
1145 pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
1146 VDD1_2_NUM_VOLT_COARSE;
1147 pmic->desc[i].ramp_delay = 12500;
1148 } else if (i == TPS65910_REG_VDD3) {
1149 if (tps65910_chip_id(tps65910) == TPS65910) {
1150 pmic->desc[i].ops = &tps65910_ops_vdd3;
1151 pmic->desc[i].volt_table = info->voltage_table;
1153 pmic->desc[i].ops = &tps65910_ops_dcdc;
1154 pmic->desc[i].ramp_delay = 5000;
1157 if (tps65910_chip_id(tps65910) == TPS65910) {
1158 pmic->desc[i].ops = &tps65910_ops;
1159 pmic->desc[i].volt_table = info->voltage_table;
1161 pmic->desc[i].ops = &tps65911_ops;
1165 err = tps65910_set_ext_sleep_config(pmic, i,
1166 pmic_plat_data->regulator_ext_sleep_control[i]);
1168 * Failing on regulator for configuring externally control
1169 * is not a serious issue, just throw warning.
1172 dev_warn(tps65910->dev,
1173 "Failed to initialise ext control config\n");
1175 pmic->desc[i].type = REGULATOR_VOLTAGE;
1176 pmic->desc[i].owner = THIS_MODULE;
1177 pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
1178 pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
1180 config.dev = tps65910->dev;
1181 config.init_data = reg_data;
1182 config.driver_data = pmic;
1183 config.regmap = tps65910->regmap;
1185 if (tps65910_reg_matches)
1186 config.of_node = tps65910_reg_matches[i].of_node;
1188 rdev = regulator_register(&pmic->desc[i], &config);
1190 dev_err(tps65910->dev,
1191 "failed to register %s regulator\n",
1193 err = PTR_ERR(rdev);
1194 goto err_unregister_regulator;
1197 /* Save regulator for cleanup */
1198 pmic->rdev[i] = rdev;
1202 err_unregister_regulator:
1204 regulator_unregister(pmic->rdev[i]);
1208 static int __devexit tps65910_remove(struct platform_device *pdev)
1210 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1213 for (i = 0; i < pmic->num_regulators; i++)
1214 regulator_unregister(pmic->rdev[i]);
1219 static void tps65910_shutdown(struct platform_device *pdev)
1221 struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1225 * Before bootloader jumps to kernel, it makes sure that required
1226 * external control signals are in desired state so that given rails
1227 * can be configure accordingly.
1228 * If rails are configured to be controlled from external control
1229 * then before shutting down/rebooting the system, the external
1230 * control configuration need to be remove from the rails so that
1231 * its output will be available as per register programming even
1232 * if external controls are removed. This is require when the POR
1233 * value of the control signals are not in active state and before
1234 * bootloader initializes it, the system requires the rail output
1235 * to be active for booting.
1237 for (i = 0; i < pmic->num_regulators; i++) {
1242 err = tps65910_set_ext_sleep_config(pmic, i, 0);
1245 "Error in clearing external control\n");
1249 static struct platform_driver tps65910_driver = {
1251 .name = "tps65910-pmic",
1252 .owner = THIS_MODULE,
1254 .probe = tps65910_probe,
1255 .remove = __devexit_p(tps65910_remove),
1256 .shutdown = tps65910_shutdown,
1259 static int __init tps65910_init(void)
1261 return platform_driver_register(&tps65910_driver);
1263 subsys_initcall(tps65910_init);
1265 static void __exit tps65910_cleanup(void)
1267 platform_driver_unregister(&tps65910_driver);
1269 module_exit(tps65910_cleanup);
1271 MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
1272 MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
1273 MODULE_LICENSE("GPL v2");
1274 MODULE_ALIAS("platform:tps65910-pmic");