Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * tps65910.c  --  TI tps65910
0004  *
0005  * Copyright 2010 Texas Instruments Inc.
0006  *
0007  * Author: Graeme Gregory <gg@slimlogic.co.uk>
0008  * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
0009  */
0010 
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/init.h>
0014 #include <linux/err.h>
0015 #include <linux/of.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/regulator/driver.h>
0018 #include <linux/regulator/machine.h>
0019 #include <linux/slab.h>
0020 #include <linux/gpio.h>
0021 #include <linux/mfd/tps65910.h>
0022 #include <linux/regulator/of_regulator.h>
0023 
0024 #define TPS65910_SUPPLY_STATE_ENABLED   0x1
0025 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 |   \
0026             TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 |      \
0027             TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 |      \
0028             TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
0029 
0030 /* supported VIO voltages in microvolts */
0031 static const unsigned int VIO_VSEL_table[] = {
0032     1500000, 1800000, 2500000, 3300000,
0033 };
0034 
0035 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
0036 
0037 /* supported VRTC voltages in microvolts */
0038 static const unsigned int VRTC_VSEL_table[] = {
0039     1800000,
0040 };
0041 
0042 /* supported VDD3 voltages in microvolts */
0043 static const unsigned int VDD3_VSEL_table[] = {
0044     5000000,
0045 };
0046 
0047 /* supported VDIG1 voltages in microvolts */
0048 static const unsigned int VDIG1_VSEL_table[] = {
0049     1200000, 1500000, 1800000, 2700000,
0050 };
0051 
0052 /* supported VDIG2 voltages in microvolts */
0053 static const unsigned int VDIG2_VSEL_table[] = {
0054     1000000, 1100000, 1200000, 1800000,
0055 };
0056 
0057 /* supported VPLL voltages in microvolts */
0058 static const unsigned int VPLL_VSEL_table[] = {
0059     1000000, 1100000, 1800000, 2500000,
0060 };
0061 
0062 /* supported VDAC voltages in microvolts */
0063 static const unsigned int VDAC_VSEL_table[] = {
0064     1800000, 2600000, 2800000, 2850000,
0065 };
0066 
0067 /* supported VAUX1 voltages in microvolts */
0068 static const unsigned int VAUX1_VSEL_table[] = {
0069     1800000, 2500000, 2800000, 2850000,
0070 };
0071 
0072 /* supported VAUX2 voltages in microvolts */
0073 static const unsigned int VAUX2_VSEL_table[] = {
0074     1800000, 2800000, 2900000, 3300000,
0075 };
0076 
0077 /* supported VAUX33 voltages in microvolts */
0078 static const unsigned int VAUX33_VSEL_table[] = {
0079     1800000, 2000000, 2800000, 3300000,
0080 };
0081 
0082 /* supported VMMC voltages in microvolts */
0083 static const unsigned int VMMC_VSEL_table[] = {
0084     1800000, 2800000, 3000000, 3300000,
0085 };
0086 
0087 /* supported BBCH voltages in microvolts */
0088 static const unsigned int VBB_VSEL_table[] = {
0089     3000000, 2520000, 3150000, 5000000,
0090 };
0091 
0092 struct tps_info {
0093     const char *name;
0094     const char *vin_name;
0095     u8 n_voltages;
0096     const unsigned int *voltage_table;
0097     int enable_time_us;
0098 };
0099 
0100 static struct tps_info tps65910_regs[] = {
0101     {
0102         .name = "vrtc",
0103         .vin_name = "vcc7",
0104         .n_voltages = ARRAY_SIZE(VRTC_VSEL_table),
0105         .voltage_table = VRTC_VSEL_table,
0106         .enable_time_us = 2200,
0107     },
0108     {
0109         .name = "vio",
0110         .vin_name = "vccio",
0111         .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
0112         .voltage_table = VIO_VSEL_table,
0113         .enable_time_us = 350,
0114     },
0115     {
0116         .name = "vdd1",
0117         .vin_name = "vcc1",
0118         .enable_time_us = 350,
0119     },
0120     {
0121         .name = "vdd2",
0122         .vin_name = "vcc2",
0123         .enable_time_us = 350,
0124     },
0125     {
0126         .name = "vdd3",
0127         .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
0128         .voltage_table = VDD3_VSEL_table,
0129         .enable_time_us = 200,
0130     },
0131     {
0132         .name = "vdig1",
0133         .vin_name = "vcc6",
0134         .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
0135         .voltage_table = VDIG1_VSEL_table,
0136         .enable_time_us = 100,
0137     },
0138     {
0139         .name = "vdig2",
0140         .vin_name = "vcc6",
0141         .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
0142         .voltage_table = VDIG2_VSEL_table,
0143         .enable_time_us = 100,
0144     },
0145     {
0146         .name = "vpll",
0147         .vin_name = "vcc5",
0148         .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
0149         .voltage_table = VPLL_VSEL_table,
0150         .enable_time_us = 100,
0151     },
0152     {
0153         .name = "vdac",
0154         .vin_name = "vcc5",
0155         .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
0156         .voltage_table = VDAC_VSEL_table,
0157         .enable_time_us = 100,
0158     },
0159     {
0160         .name = "vaux1",
0161         .vin_name = "vcc4",
0162         .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
0163         .voltage_table = VAUX1_VSEL_table,
0164         .enable_time_us = 100,
0165     },
0166     {
0167         .name = "vaux2",
0168         .vin_name = "vcc4",
0169         .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
0170         .voltage_table = VAUX2_VSEL_table,
0171         .enable_time_us = 100,
0172     },
0173     {
0174         .name = "vaux33",
0175         .vin_name = "vcc3",
0176         .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
0177         .voltage_table = VAUX33_VSEL_table,
0178         .enable_time_us = 100,
0179     },
0180     {
0181         .name = "vmmc",
0182         .vin_name = "vcc3",
0183         .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
0184         .voltage_table = VMMC_VSEL_table,
0185         .enable_time_us = 100,
0186     },
0187     {
0188         .name = "vbb",
0189         .vin_name = "vcc7",
0190         .n_voltages = ARRAY_SIZE(VBB_VSEL_table),
0191         .voltage_table = VBB_VSEL_table,
0192     },
0193 };
0194 
0195 static struct tps_info tps65911_regs[] = {
0196     {
0197         .name = "vrtc",
0198         .vin_name = "vcc7",
0199         .enable_time_us = 2200,
0200     },
0201     {
0202         .name = "vio",
0203         .vin_name = "vccio",
0204         .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
0205         .voltage_table = VIO_VSEL_table,
0206         .enable_time_us = 350,
0207     },
0208     {
0209         .name = "vdd1",
0210         .vin_name = "vcc1",
0211         .n_voltages = 0x4C,
0212         .enable_time_us = 350,
0213     },
0214     {
0215         .name = "vdd2",
0216         .vin_name = "vcc2",
0217         .n_voltages = 0x4C,
0218         .enable_time_us = 350,
0219     },
0220     {
0221         .name = "vddctrl",
0222         .n_voltages = 0x44,
0223         .enable_time_us = 900,
0224     },
0225     {
0226         .name = "ldo1",
0227         .vin_name = "vcc6",
0228         .n_voltages = 0x33,
0229         .enable_time_us = 420,
0230     },
0231     {
0232         .name = "ldo2",
0233         .vin_name = "vcc6",
0234         .n_voltages = 0x33,
0235         .enable_time_us = 420,
0236     },
0237     {
0238         .name = "ldo3",
0239         .vin_name = "vcc5",
0240         .n_voltages = 0x1A,
0241         .enable_time_us = 230,
0242     },
0243     {
0244         .name = "ldo4",
0245         .vin_name = "vcc5",
0246         .n_voltages = 0x33,
0247         .enable_time_us = 230,
0248     },
0249     {
0250         .name = "ldo5",
0251         .vin_name = "vcc4",
0252         .n_voltages = 0x1A,
0253         .enable_time_us = 230,
0254     },
0255     {
0256         .name = "ldo6",
0257         .vin_name = "vcc3",
0258         .n_voltages = 0x1A,
0259         .enable_time_us = 230,
0260     },
0261     {
0262         .name = "ldo7",
0263         .vin_name = "vcc3",
0264         .n_voltages = 0x1A,
0265         .enable_time_us = 230,
0266     },
0267     {
0268         .name = "ldo8",
0269         .vin_name = "vcc3",
0270         .n_voltages = 0x1A,
0271         .enable_time_us = 230,
0272     },
0273 };
0274 
0275 #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
0276 static unsigned int tps65910_ext_sleep_control[] = {
0277     0,
0278     EXT_CONTROL_REG_BITS(VIO,    1, 0),
0279     EXT_CONTROL_REG_BITS(VDD1,   1, 1),
0280     EXT_CONTROL_REG_BITS(VDD2,   1, 2),
0281     EXT_CONTROL_REG_BITS(VDD3,   1, 3),
0282     EXT_CONTROL_REG_BITS(VDIG1,  0, 1),
0283     EXT_CONTROL_REG_BITS(VDIG2,  0, 2),
0284     EXT_CONTROL_REG_BITS(VPLL,   0, 6),
0285     EXT_CONTROL_REG_BITS(VDAC,   0, 7),
0286     EXT_CONTROL_REG_BITS(VAUX1,  0, 3),
0287     EXT_CONTROL_REG_BITS(VAUX2,  0, 4),
0288     EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
0289     EXT_CONTROL_REG_BITS(VMMC,   0, 0),
0290 };
0291 
0292 static unsigned int tps65911_ext_sleep_control[] = {
0293     0,
0294     EXT_CONTROL_REG_BITS(VIO,     1, 0),
0295     EXT_CONTROL_REG_BITS(VDD1,    1, 1),
0296     EXT_CONTROL_REG_BITS(VDD2,    1, 2),
0297     EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
0298     EXT_CONTROL_REG_BITS(LDO1,    0, 1),
0299     EXT_CONTROL_REG_BITS(LDO2,    0, 2),
0300     EXT_CONTROL_REG_BITS(LDO3,    0, 7),
0301     EXT_CONTROL_REG_BITS(LDO4,    0, 6),
0302     EXT_CONTROL_REG_BITS(LDO5,    0, 3),
0303     EXT_CONTROL_REG_BITS(LDO6,    0, 0),
0304     EXT_CONTROL_REG_BITS(LDO7,    0, 5),
0305     EXT_CONTROL_REG_BITS(LDO8,    0, 4),
0306 };
0307 
0308 struct tps65910_reg {
0309     struct regulator_desc *desc;
0310     struct tps65910 *mfd;
0311     struct regulator_dev **rdev;
0312     struct tps_info **info;
0313     int num_regulators;
0314     int mode;
0315     int  (*get_ctrl_reg)(int);
0316     unsigned int *ext_sleep_control;
0317     unsigned int board_ext_control[TPS65910_NUM_REGS];
0318 };
0319 
0320 static int tps65910_get_ctrl_register(int id)
0321 {
0322     switch (id) {
0323     case TPS65910_REG_VRTC:
0324         return TPS65910_VRTC;
0325     case TPS65910_REG_VIO:
0326         return TPS65910_VIO;
0327     case TPS65910_REG_VDD1:
0328         return TPS65910_VDD1;
0329     case TPS65910_REG_VDD2:
0330         return TPS65910_VDD2;
0331     case TPS65910_REG_VDD3:
0332         return TPS65910_VDD3;
0333     case TPS65910_REG_VDIG1:
0334         return TPS65910_VDIG1;
0335     case TPS65910_REG_VDIG2:
0336         return TPS65910_VDIG2;
0337     case TPS65910_REG_VPLL:
0338         return TPS65910_VPLL;
0339     case TPS65910_REG_VDAC:
0340         return TPS65910_VDAC;
0341     case TPS65910_REG_VAUX1:
0342         return TPS65910_VAUX1;
0343     case TPS65910_REG_VAUX2:
0344         return TPS65910_VAUX2;
0345     case TPS65910_REG_VAUX33:
0346         return TPS65910_VAUX33;
0347     case TPS65910_REG_VMMC:
0348         return TPS65910_VMMC;
0349     case TPS65910_REG_VBB:
0350         return TPS65910_BBCH;
0351     default:
0352         return -EINVAL;
0353     }
0354 }
0355 
0356 static int tps65911_get_ctrl_register(int id)
0357 {
0358     switch (id) {
0359     case TPS65910_REG_VRTC:
0360         return TPS65910_VRTC;
0361     case TPS65910_REG_VIO:
0362         return TPS65910_VIO;
0363     case TPS65910_REG_VDD1:
0364         return TPS65910_VDD1;
0365     case TPS65910_REG_VDD2:
0366         return TPS65910_VDD2;
0367     case TPS65911_REG_VDDCTRL:
0368         return TPS65911_VDDCTRL;
0369     case TPS65911_REG_LDO1:
0370         return TPS65911_LDO1;
0371     case TPS65911_REG_LDO2:
0372         return TPS65911_LDO2;
0373     case TPS65911_REG_LDO3:
0374         return TPS65911_LDO3;
0375     case TPS65911_REG_LDO4:
0376         return TPS65911_LDO4;
0377     case TPS65911_REG_LDO5:
0378         return TPS65911_LDO5;
0379     case TPS65911_REG_LDO6:
0380         return TPS65911_LDO6;
0381     case TPS65911_REG_LDO7:
0382         return TPS65911_LDO7;
0383     case TPS65911_REG_LDO8:
0384         return TPS65911_LDO8;
0385     default:
0386         return -EINVAL;
0387     }
0388 }
0389 
0390 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
0391 {
0392     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0393     struct regmap *regmap = rdev_get_regmap(dev);
0394     int reg, id = rdev_get_id(dev);
0395 
0396     reg = pmic->get_ctrl_reg(id);
0397     if (reg < 0)
0398         return reg;
0399 
0400     switch (mode) {
0401     case REGULATOR_MODE_NORMAL:
0402         return regmap_update_bits(regmap, reg,
0403                       LDO_ST_MODE_BIT | LDO_ST_ON_BIT,
0404                       LDO_ST_ON_BIT);
0405     case REGULATOR_MODE_IDLE:
0406         return regmap_set_bits(regmap, reg,
0407                        LDO_ST_ON_BIT | LDO_ST_MODE_BIT);
0408     case REGULATOR_MODE_STANDBY:
0409         return regmap_clear_bits(regmap, reg, LDO_ST_ON_BIT);
0410     }
0411 
0412     return -EINVAL;
0413 }
0414 
0415 static unsigned int tps65910_get_mode(struct regulator_dev *dev)
0416 {
0417     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0418     struct regmap *regmap = rdev_get_regmap(dev);
0419     int ret, reg, value, id = rdev_get_id(dev);
0420 
0421     reg = pmic->get_ctrl_reg(id);
0422     if (reg < 0)
0423         return reg;
0424 
0425     ret = regmap_read(regmap, reg, &value);
0426     if (ret < 0)
0427         return ret;
0428 
0429     if (!(value & LDO_ST_ON_BIT))
0430         return REGULATOR_MODE_STANDBY;
0431     else if (value & LDO_ST_MODE_BIT)
0432         return REGULATOR_MODE_IDLE;
0433     else
0434         return REGULATOR_MODE_NORMAL;
0435 }
0436 
0437 static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
0438 {
0439     struct regmap *regmap = rdev_get_regmap(dev);
0440     int ret, id = rdev_get_id(dev);
0441     int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
0442 
0443     switch (id) {
0444     case TPS65910_REG_VDD1:
0445         ret = regmap_read(regmap, TPS65910_VDD1_OP, &opvsel);
0446         if (ret < 0)
0447             return ret;
0448         ret = regmap_read(regmap, TPS65910_VDD1, &mult);
0449         if (ret < 0)
0450             return ret;
0451         mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
0452         ret = regmap_read(regmap, TPS65910_VDD1_SR, &srvsel);
0453         if (ret < 0)
0454             return ret;
0455         sr = opvsel & VDD1_OP_CMD_MASK;
0456         opvsel &= VDD1_OP_SEL_MASK;
0457         srvsel &= VDD1_SR_SEL_MASK;
0458         vselmax = 75;
0459         break;
0460     case TPS65910_REG_VDD2:
0461         ret = regmap_read(regmap, TPS65910_VDD2_OP, &opvsel);
0462         if (ret < 0)
0463             return ret;
0464         ret = regmap_read(regmap, TPS65910_VDD2, &mult);
0465         if (ret < 0)
0466             return ret;
0467         mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
0468         ret = regmap_read(regmap, TPS65910_VDD2_SR, &srvsel);
0469         if (ret < 0)
0470             return ret;
0471         sr = opvsel & VDD2_OP_CMD_MASK;
0472         opvsel &= VDD2_OP_SEL_MASK;
0473         srvsel &= VDD2_SR_SEL_MASK;
0474         vselmax = 75;
0475         break;
0476     case TPS65911_REG_VDDCTRL:
0477         ret = regmap_read(regmap, TPS65911_VDDCTRL_OP, &opvsel);
0478         if (ret < 0)
0479             return ret;
0480         ret = regmap_read(regmap, TPS65911_VDDCTRL_SR, &srvsel);
0481         if (ret < 0)
0482             return ret;
0483         sr = opvsel & VDDCTRL_OP_CMD_MASK;
0484         opvsel &= VDDCTRL_OP_SEL_MASK;
0485         srvsel &= VDDCTRL_SR_SEL_MASK;
0486         vselmax = 64;
0487         break;
0488     }
0489 
0490     /* multiplier 0 == 1 but 2,3 normal */
0491     if (!mult)
0492         mult = 1;
0493 
0494     if (sr) {
0495         /* normalise to valid range */
0496         if (srvsel < 3)
0497             srvsel = 3;
0498         if (srvsel > vselmax)
0499             srvsel = vselmax;
0500         return srvsel - 3;
0501     } else {
0502 
0503         /* normalise to valid range*/
0504         if (opvsel < 3)
0505             opvsel = 3;
0506         if (opvsel > vselmax)
0507             opvsel = vselmax;
0508         return opvsel - 3;
0509     }
0510     return -EINVAL;
0511 }
0512 
0513 static int tps65910_get_voltage_sel(struct regulator_dev *dev)
0514 {
0515     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0516     struct regmap *regmap = rdev_get_regmap(dev);
0517     int ret, reg, value, id = rdev_get_id(dev);
0518 
0519     reg = pmic->get_ctrl_reg(id);
0520     if (reg < 0)
0521         return reg;
0522 
0523     ret = regmap_read(regmap, reg, &value);
0524     if (ret < 0)
0525         return ret;
0526 
0527     switch (id) {
0528     case TPS65910_REG_VIO:
0529     case TPS65910_REG_VDIG1:
0530     case TPS65910_REG_VDIG2:
0531     case TPS65910_REG_VPLL:
0532     case TPS65910_REG_VDAC:
0533     case TPS65910_REG_VAUX1:
0534     case TPS65910_REG_VAUX2:
0535     case TPS65910_REG_VAUX33:
0536     case TPS65910_REG_VMMC:
0537         value &= LDO_SEL_MASK;
0538         value >>= LDO_SEL_SHIFT;
0539         break;
0540     case TPS65910_REG_VBB:
0541         value &= BBCH_BBSEL_MASK;
0542         value >>= BBCH_BBSEL_SHIFT;
0543         break;
0544     default:
0545         return -EINVAL;
0546     }
0547 
0548     return value;
0549 }
0550 
0551 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
0552 {
0553     return dev->desc->volt_table[0];
0554 }
0555 
0556 static int tps65911_get_voltage_sel(struct regulator_dev *dev)
0557 {
0558     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0559     struct regmap *regmap = rdev_get_regmap(dev);
0560     int ret, id = rdev_get_id(dev);
0561     unsigned int value, reg;
0562 
0563     reg = pmic->get_ctrl_reg(id);
0564 
0565     ret = regmap_read(regmap, reg, &value);
0566     if (ret < 0)
0567         return ret;
0568 
0569     switch (id) {
0570     case TPS65911_REG_LDO1:
0571     case TPS65911_REG_LDO2:
0572     case TPS65911_REG_LDO4:
0573         value &= LDO1_SEL_MASK;
0574         value >>= LDO_SEL_SHIFT;
0575         break;
0576     case TPS65911_REG_LDO3:
0577     case TPS65911_REG_LDO5:
0578     case TPS65911_REG_LDO6:
0579     case TPS65911_REG_LDO7:
0580     case TPS65911_REG_LDO8:
0581         value &= LDO3_SEL_MASK;
0582         value >>= LDO_SEL_SHIFT;
0583         break;
0584     case TPS65910_REG_VIO:
0585         value &= LDO_SEL_MASK;
0586         value >>= LDO_SEL_SHIFT;
0587         break;
0588     default:
0589         return -EINVAL;
0590     }
0591 
0592     return value;
0593 }
0594 
0595 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
0596                      unsigned selector)
0597 {
0598     struct regmap *regmap = rdev_get_regmap(dev);
0599     int id = rdev_get_id(dev), vsel;
0600     int dcdc_mult = 0;
0601 
0602     switch (id) {
0603     case TPS65910_REG_VDD1:
0604         dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
0605         if (dcdc_mult == 1)
0606             dcdc_mult--;
0607         vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
0608 
0609         regmap_update_bits(regmap, TPS65910_VDD1, VDD1_VGAIN_SEL_MASK,
0610                    dcdc_mult << VDD1_VGAIN_SEL_SHIFT);
0611         regmap_write(regmap, TPS65910_VDD1_OP, vsel);
0612         break;
0613     case TPS65910_REG_VDD2:
0614         dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
0615         if (dcdc_mult == 1)
0616             dcdc_mult--;
0617         vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
0618 
0619         regmap_update_bits(regmap, TPS65910_VDD2, VDD1_VGAIN_SEL_MASK,
0620                    dcdc_mult << VDD2_VGAIN_SEL_SHIFT);
0621         regmap_write(regmap, TPS65910_VDD2_OP, vsel);
0622         break;
0623     case TPS65911_REG_VDDCTRL:
0624         vsel = selector + 3;
0625         regmap_write(regmap, TPS65911_VDDCTRL_OP, vsel);
0626         break;
0627     }
0628 
0629     return 0;
0630 }
0631 
0632 static int tps65910_set_voltage_sel(struct regulator_dev *dev,
0633                     unsigned selector)
0634 {
0635     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0636     struct regmap *regmap = rdev_get_regmap(dev);
0637     int reg, id = rdev_get_id(dev);
0638 
0639     reg = pmic->get_ctrl_reg(id);
0640     if (reg < 0)
0641         return reg;
0642 
0643     switch (id) {
0644     case TPS65910_REG_VIO:
0645     case TPS65910_REG_VDIG1:
0646     case TPS65910_REG_VDIG2:
0647     case TPS65910_REG_VPLL:
0648     case TPS65910_REG_VDAC:
0649     case TPS65910_REG_VAUX1:
0650     case TPS65910_REG_VAUX2:
0651     case TPS65910_REG_VAUX33:
0652     case TPS65910_REG_VMMC:
0653         return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
0654                       selector << LDO_SEL_SHIFT);
0655     case TPS65910_REG_VBB:
0656         return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
0657                       selector << BBCH_BBSEL_SHIFT);
0658     }
0659 
0660     return -EINVAL;
0661 }
0662 
0663 static int tps65911_set_voltage_sel(struct regulator_dev *dev,
0664                     unsigned selector)
0665 {
0666     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0667     struct regmap *regmap = rdev_get_regmap(dev);
0668     int reg, id = rdev_get_id(dev);
0669 
0670     reg = pmic->get_ctrl_reg(id);
0671     if (reg < 0)
0672         return reg;
0673 
0674     switch (id) {
0675     case TPS65911_REG_LDO1:
0676     case TPS65911_REG_LDO2:
0677     case TPS65911_REG_LDO4:
0678         return regmap_update_bits(regmap, reg, LDO1_SEL_MASK,
0679                       selector << LDO_SEL_SHIFT);
0680     case TPS65911_REG_LDO3:
0681     case TPS65911_REG_LDO5:
0682     case TPS65911_REG_LDO6:
0683     case TPS65911_REG_LDO7:
0684     case TPS65911_REG_LDO8:
0685         return regmap_update_bits(regmap, reg, LDO3_SEL_MASK,
0686                       selector << LDO_SEL_SHIFT);
0687     case TPS65910_REG_VIO:
0688         return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
0689                       selector << LDO_SEL_SHIFT);
0690     case TPS65910_REG_VBB:
0691         return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
0692                       selector << BBCH_BBSEL_SHIFT);
0693     }
0694 
0695     return -EINVAL;
0696 }
0697 
0698 
0699 static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
0700                     unsigned selector)
0701 {
0702     int volt, mult = 1, id = rdev_get_id(dev);
0703 
0704     switch (id) {
0705     case TPS65910_REG_VDD1:
0706     case TPS65910_REG_VDD2:
0707         mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
0708         volt = VDD1_2_MIN_VOLT +
0709             (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
0710         break;
0711     case TPS65911_REG_VDDCTRL:
0712         volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
0713         break;
0714     default:
0715         BUG();
0716         return -EINVAL;
0717     }
0718 
0719     return  volt * 100 * mult;
0720 }
0721 
0722 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
0723 {
0724     struct tps65910_reg *pmic = rdev_get_drvdata(dev);
0725     int step_mv = 0, id = rdev_get_id(dev);
0726 
0727     switch (id) {
0728     case TPS65911_REG_LDO1:
0729     case TPS65911_REG_LDO2:
0730     case TPS65911_REG_LDO4:
0731         /* The first 5 values of the selector correspond to 1V */
0732         if (selector < 5)
0733             selector = 0;
0734         else
0735             selector -= 4;
0736 
0737         step_mv = 50;
0738         break;
0739     case TPS65911_REG_LDO3:
0740     case TPS65911_REG_LDO5:
0741     case TPS65911_REG_LDO6:
0742     case TPS65911_REG_LDO7:
0743     case TPS65911_REG_LDO8:
0744         /* The first 3 values of the selector correspond to 1V */
0745         if (selector < 3)
0746             selector = 0;
0747         else
0748             selector -= 2;
0749 
0750         step_mv = 100;
0751         break;
0752     case TPS65910_REG_VIO:
0753         return pmic->info[id]->voltage_table[selector];
0754     default:
0755         return -EINVAL;
0756     }
0757 
0758     return (LDO_MIN_VOLT + selector * step_mv) * 1000;
0759 }
0760 
0761 /* Regulator ops (except VRTC) */
0762 static const struct regulator_ops tps65910_ops_dcdc = {
0763     .is_enabled     = regulator_is_enabled_regmap,
0764     .enable         = regulator_enable_regmap,
0765     .disable        = regulator_disable_regmap,
0766     .set_mode       = tps65910_set_mode,
0767     .get_mode       = tps65910_get_mode,
0768     .get_voltage_sel    = tps65910_get_voltage_dcdc_sel,
0769     .set_voltage_sel    = tps65910_set_voltage_dcdc_sel,
0770     .set_voltage_time_sel   = regulator_set_voltage_time_sel,
0771     .list_voltage       = tps65910_list_voltage_dcdc,
0772     .map_voltage        = regulator_map_voltage_ascend,
0773 };
0774 
0775 static const struct regulator_ops tps65910_ops_vdd3 = {
0776     .is_enabled     = regulator_is_enabled_regmap,
0777     .enable         = regulator_enable_regmap,
0778     .disable        = regulator_disable_regmap,
0779     .set_mode       = tps65910_set_mode,
0780     .get_mode       = tps65910_get_mode,
0781     .get_voltage        = tps65910_get_voltage_vdd3,
0782     .list_voltage       = regulator_list_voltage_table,
0783     .map_voltage        = regulator_map_voltage_ascend,
0784 };
0785 
0786 static const struct regulator_ops tps65910_ops_vbb = {
0787     .is_enabled     = regulator_is_enabled_regmap,
0788     .enable         = regulator_enable_regmap,
0789     .disable        = regulator_disable_regmap,
0790     .set_mode       = tps65910_set_mode,
0791     .get_mode       = tps65910_get_mode,
0792     .get_voltage_sel    = tps65910_get_voltage_sel,
0793     .set_voltage_sel    = tps65910_set_voltage_sel,
0794     .list_voltage       = regulator_list_voltage_table,
0795     .map_voltage        = regulator_map_voltage_iterate,
0796 };
0797 
0798 static const struct regulator_ops tps65910_ops = {
0799     .is_enabled     = regulator_is_enabled_regmap,
0800     .enable         = regulator_enable_regmap,
0801     .disable        = regulator_disable_regmap,
0802     .set_mode       = tps65910_set_mode,
0803     .get_mode       = tps65910_get_mode,
0804     .get_voltage_sel    = tps65910_get_voltage_sel,
0805     .set_voltage_sel    = tps65910_set_voltage_sel,
0806     .list_voltage       = regulator_list_voltage_table,
0807     .map_voltage        = regulator_map_voltage_ascend,
0808 };
0809 
0810 static const struct regulator_ops tps65911_ops = {
0811     .is_enabled     = regulator_is_enabled_regmap,
0812     .enable         = regulator_enable_regmap,
0813     .disable        = regulator_disable_regmap,
0814     .set_mode       = tps65910_set_mode,
0815     .get_mode       = tps65910_get_mode,
0816     .get_voltage_sel    = tps65911_get_voltage_sel,
0817     .set_voltage_sel    = tps65911_set_voltage_sel,
0818     .list_voltage       = tps65911_list_voltage,
0819     .map_voltage        = regulator_map_voltage_ascend,
0820 };
0821 
0822 static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
0823         int id, int ext_sleep_config)
0824 {
0825     struct tps65910 *mfd = pmic->mfd;
0826     u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
0827     u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
0828     int ret;
0829 
0830     /*
0831      * Regulator can not be control from multiple external input EN1, EN2
0832      * and EN3 together.
0833      */
0834     if (ext_sleep_config & EXT_SLEEP_CONTROL) {
0835         int en_count;
0836         en_count = ((ext_sleep_config &
0837                 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
0838         en_count += ((ext_sleep_config &
0839                 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
0840         en_count += ((ext_sleep_config &
0841                 TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
0842         en_count += ((ext_sleep_config &
0843                 TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
0844         if (en_count > 1) {
0845             dev_err(mfd->dev,
0846                 "External sleep control flag is not proper\n");
0847             return -EINVAL;
0848         }
0849     }
0850 
0851     pmic->board_ext_control[id] = ext_sleep_config;
0852 
0853     /* External EN1 control */
0854     if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
0855         ret = regmap_set_bits(mfd->regmap,
0856                 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
0857     else
0858         ret = regmap_clear_bits(mfd->regmap,
0859                 TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
0860     if (ret < 0) {
0861         dev_err(mfd->dev,
0862             "Error in configuring external control EN1\n");
0863         return ret;
0864     }
0865 
0866     /* External EN2 control */
0867     if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
0868         ret = regmap_set_bits(mfd->regmap,
0869                 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
0870     else
0871         ret = regmap_clear_bits(mfd->regmap,
0872                 TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
0873     if (ret < 0) {
0874         dev_err(mfd->dev,
0875             "Error in configuring external control EN2\n");
0876         return ret;
0877     }
0878 
0879     /* External EN3 control for TPS65910 LDO only */
0880     if ((tps65910_chip_id(mfd) == TPS65910) &&
0881             (id >= TPS65910_REG_VDIG1)) {
0882         if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
0883             ret = regmap_set_bits(mfd->regmap,
0884                 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
0885         else
0886             ret = regmap_clear_bits(mfd->regmap,
0887                 TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
0888         if (ret < 0) {
0889             dev_err(mfd->dev,
0890                 "Error in configuring external control EN3\n");
0891             return ret;
0892         }
0893     }
0894 
0895     /* Return if no external control is selected */
0896     if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
0897         /* Clear all sleep controls */
0898         ret = regmap_clear_bits(mfd->regmap,
0899             TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
0900         if (!ret)
0901             ret = regmap_clear_bits(mfd->regmap,
0902                 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
0903         if (ret < 0)
0904             dev_err(mfd->dev,
0905                 "Error in configuring SLEEP register\n");
0906         return ret;
0907     }
0908 
0909     /*
0910      * For regulator that has separate operational and sleep register make
0911      * sure that operational is used and clear sleep register to turn
0912      * regulator off when external control is inactive
0913      */
0914     if ((id == TPS65910_REG_VDD1) ||
0915         (id == TPS65910_REG_VDD2) ||
0916             ((id == TPS65911_REG_VDDCTRL) &&
0917                 (tps65910_chip_id(mfd) == TPS65911))) {
0918         int op_reg_add = pmic->get_ctrl_reg(id) + 1;
0919         int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
0920         int opvsel, srvsel;
0921 
0922         ret = regmap_read(mfd->regmap, op_reg_add, &opvsel);
0923         if (ret < 0)
0924             return ret;
0925         ret = regmap_read(mfd->regmap, sr_reg_add, &srvsel);
0926         if (ret < 0)
0927             return ret;
0928 
0929         if (opvsel & VDD1_OP_CMD_MASK) {
0930             u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
0931 
0932             ret = regmap_write(mfd->regmap, op_reg_add, reg_val);
0933             if (ret < 0) {
0934                 dev_err(mfd->dev,
0935                     "Error in configuring op register\n");
0936                 return ret;
0937             }
0938         }
0939         ret = regmap_write(mfd->regmap, sr_reg_add, 0);
0940         if (ret < 0) {
0941             dev_err(mfd->dev, "Error in setting sr register\n");
0942             return ret;
0943         }
0944     }
0945 
0946     ret = regmap_clear_bits(mfd->regmap,
0947             TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
0948     if (!ret) {
0949         if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
0950             ret = regmap_set_bits(mfd->regmap,
0951                 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
0952         else
0953             ret = regmap_clear_bits(mfd->regmap,
0954                 TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
0955     }
0956     if (ret < 0)
0957         dev_err(mfd->dev,
0958             "Error in configuring SLEEP register\n");
0959 
0960     return ret;
0961 }
0962 
0963 #ifdef CONFIG_OF
0964 
0965 static struct of_regulator_match tps65910_matches[] = {
0966     { .name = "vrtc",   .driver_data = (void *) &tps65910_regs[0] },
0967     { .name = "vio",    .driver_data = (void *) &tps65910_regs[1] },
0968     { .name = "vdd1",   .driver_data = (void *) &tps65910_regs[2] },
0969     { .name = "vdd2",   .driver_data = (void *) &tps65910_regs[3] },
0970     { .name = "vdd3",   .driver_data = (void *) &tps65910_regs[4] },
0971     { .name = "vdig1",  .driver_data = (void *) &tps65910_regs[5] },
0972     { .name = "vdig2",  .driver_data = (void *) &tps65910_regs[6] },
0973     { .name = "vpll",   .driver_data = (void *) &tps65910_regs[7] },
0974     { .name = "vdac",   .driver_data = (void *) &tps65910_regs[8] },
0975     { .name = "vaux1",  .driver_data = (void *) &tps65910_regs[9] },
0976     { .name = "vaux2",  .driver_data = (void *) &tps65910_regs[10] },
0977     { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
0978     { .name = "vmmc",   .driver_data = (void *) &tps65910_regs[12] },
0979     { .name = "vbb",    .driver_data = (void *) &tps65910_regs[13] },
0980 };
0981 
0982 static struct of_regulator_match tps65911_matches[] = {
0983     { .name = "vrtc",   .driver_data = (void *) &tps65911_regs[0] },
0984     { .name = "vio",    .driver_data = (void *) &tps65911_regs[1] },
0985     { .name = "vdd1",   .driver_data = (void *) &tps65911_regs[2] },
0986     { .name = "vdd2",   .driver_data = (void *) &tps65911_regs[3] },
0987     { .name = "vddctrl",    .driver_data = (void *) &tps65911_regs[4] },
0988     { .name = "ldo1",   .driver_data = (void *) &tps65911_regs[5] },
0989     { .name = "ldo2",   .driver_data = (void *) &tps65911_regs[6] },
0990     { .name = "ldo3",   .driver_data = (void *) &tps65911_regs[7] },
0991     { .name = "ldo4",   .driver_data = (void *) &tps65911_regs[8] },
0992     { .name = "ldo5",   .driver_data = (void *) &tps65911_regs[9] },
0993     { .name = "ldo6",   .driver_data = (void *) &tps65911_regs[10] },
0994     { .name = "ldo7",   .driver_data = (void *) &tps65911_regs[11] },
0995     { .name = "ldo8",   .driver_data = (void *) &tps65911_regs[12] },
0996 };
0997 
0998 static struct tps65910_board *tps65910_parse_dt_reg_data(
0999         struct platform_device *pdev,
1000         struct of_regulator_match **tps65910_reg_matches)
1001 {
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;
1006     unsigned int prop;
1007     int idx = 0, ret, count;
1008 
1009     pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
1010                     GFP_KERNEL);
1011     if (!pmic_plat_data)
1012         return NULL;
1013 
1014     np = pdev->dev.parent->of_node;
1015     regulators = of_get_child_by_name(np, "regulators");
1016     if (!regulators) {
1017         dev_err(&pdev->dev, "regulator node not found\n");
1018         return NULL;
1019     }
1020 
1021     switch (tps65910_chip_id(tps65910)) {
1022     case TPS65910:
1023         count = ARRAY_SIZE(tps65910_matches);
1024         matches = tps65910_matches;
1025         break;
1026     case TPS65911:
1027         count = ARRAY_SIZE(tps65911_matches);
1028         matches = tps65911_matches;
1029         break;
1030     default:
1031         of_node_put(regulators);
1032         dev_err(&pdev->dev, "Invalid tps chip version\n");
1033         return NULL;
1034     }
1035 
1036     ret = of_regulator_match(&pdev->dev, regulators, matches, count);
1037     of_node_put(regulators);
1038     if (ret < 0) {
1039         dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
1040             ret);
1041         return NULL;
1042     }
1043 
1044     *tps65910_reg_matches = matches;
1045 
1046     for (idx = 0; idx < count; idx++) {
1047         if (!matches[idx].of_node)
1048             continue;
1049 
1050         pmic_plat_data->tps65910_pmic_init_data[idx] =
1051                             matches[idx].init_data;
1052 
1053         ret = of_property_read_u32(matches[idx].of_node,
1054                 "ti,regulator-ext-sleep-control", &prop);
1055         if (!ret)
1056             pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
1057 
1058     }
1059 
1060     return pmic_plat_data;
1061 }
1062 #else
1063 static inline struct tps65910_board *tps65910_parse_dt_reg_data(
1064             struct platform_device *pdev,
1065             struct of_regulator_match **tps65910_reg_matches)
1066 {
1067     *tps65910_reg_matches = NULL;
1068     return NULL;
1069 }
1070 #endif
1071 
1072 static int tps65910_probe(struct platform_device *pdev)
1073 {
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;
1081     int i, err;
1082 
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);
1087 
1088     if (!pmic_plat_data) {
1089         dev_err(&pdev->dev, "Platform data not found\n");
1090         return -EINVAL;
1091     }
1092 
1093     pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
1094     if (!pmic)
1095         return -ENOMEM;
1096 
1097     pmic->mfd = tps65910;
1098     platform_set_drvdata(pdev, pmic);
1099 
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);
1103     if (err < 0)
1104         return err;
1105 
1106     switch (tps65910_chip_id(tps65910)) {
1107     case 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
1116          */
1117         regmap_clear_bits(pmic->mfd->regmap, TPS65910_DCDCCTRL,
1118                     DCDCCTRL_DCDCCKSYNC_MASK);
1119         break;
1120     case TPS65911:
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;
1126         break;
1127     default:
1128         dev_err(&pdev->dev, "Invalid tps chip version\n");
1129         return -ENODEV;
1130     }
1131 
1132     pmic->desc = devm_kcalloc(&pdev->dev,
1133                   pmic->num_regulators,
1134                   sizeof(struct regulator_desc),
1135                   GFP_KERNEL);
1136     if (!pmic->desc)
1137         return -ENOMEM;
1138 
1139     pmic->info = devm_kcalloc(&pdev->dev,
1140                   pmic->num_regulators,
1141                   sizeof(struct tps_info *),
1142                   GFP_KERNEL);
1143     if (!pmic->info)
1144         return -ENOMEM;
1145 
1146     pmic->rdev = devm_kcalloc(&pdev->dev,
1147                   pmic->num_regulators,
1148                   sizeof(struct regulator_dev *),
1149                   GFP_KERNEL);
1150     if (!pmic->rdev)
1151         return -ENOMEM;
1152 
1153     for (i = 0; i < pmic->num_regulators; i++, info++) {
1154         /* Register the regulators */
1155         pmic->info[i] = info;
1156 
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;
1162 
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;
1172             } else {
1173                 pmic->desc[i].ops = &tps65910_ops_dcdc;
1174                 pmic->desc[i].ramp_delay = 5000;
1175             }
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;
1180         } else {
1181             if (tps65910_chip_id(tps65910) == TPS65910) {
1182                 pmic->desc[i].ops = &tps65910_ops;
1183                 pmic->desc[i].volt_table = info->voltage_table;
1184             } else {
1185                 pmic->desc[i].ops = &tps65911_ops;
1186             }
1187         }
1188 
1189         err = tps65910_set_ext_sleep_config(pmic, i,
1190                 pmic_plat_data->regulator_ext_sleep_control[i]);
1191         /*
1192          * Failing on regulator for configuring externally control
1193          * is not a serious issue, just throw warning.
1194          */
1195         if (err < 0)
1196             dev_warn(tps65910->dev,
1197                 "Failed to initialise ext control config\n");
1198 
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;
1203 
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;
1208 
1209         if (tps65910_reg_matches)
1210             config.of_node = tps65910_reg_matches[i].of_node;
1211 
1212         rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
1213                            &config);
1214         if (IS_ERR(rdev))
1215             return dev_err_probe(tps65910->dev, PTR_ERR(rdev),
1216                          "failed to register %s regulator\n",
1217                          pdev->name);
1218 
1219         /* Save regulator for cleanup */
1220         pmic->rdev[i] = rdev;
1221     }
1222     return 0;
1223 }
1224 
1225 static void tps65910_shutdown(struct platform_device *pdev)
1226 {
1227     struct tps65910_reg *pmic = platform_get_drvdata(pdev);
1228     int i;
1229 
1230     /*
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.
1242      */
1243     for (i = 0; i < pmic->num_regulators; i++) {
1244         int err;
1245         if (!pmic->rdev[i])
1246             continue;
1247 
1248         err = tps65910_set_ext_sleep_config(pmic, i, 0);
1249         if (err < 0)
1250             dev_err(&pdev->dev,
1251                 "Error in clearing external control\n");
1252     }
1253 }
1254 
1255 static struct platform_driver tps65910_driver = {
1256     .driver = {
1257         .name = "tps65910-pmic",
1258     },
1259     .probe = tps65910_probe,
1260     .shutdown = tps65910_shutdown,
1261 };
1262 
1263 static int __init tps65910_init(void)
1264 {
1265     return platform_driver_register(&tps65910_driver);
1266 }
1267 subsys_initcall(tps65910_init);
1268 
1269 static void __exit tps65910_cleanup(void)
1270 {
1271     platform_driver_unregister(&tps65910_driver);
1272 }
1273 module_exit(tps65910_cleanup);
1274 
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");