regulator: tps65910: add support for input supply
[deliverable/linux.git] / drivers / regulator / tps65910-regulator.c
index 4a37c2b6367fa3c6b8d926205e7719f4e4b5c4c9..e319d963fee687bd953c6dfe50ffe7b2b619085a 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
-#include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/gpio.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/regulator/of_regulator.h>
 
 #define TPS65910_SUPPLY_STATE_ENABLED  0x1
 #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 |      \
                        TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 |          \
                        TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
 
-/* supported VIO voltages in milivolts */
-static const u16 VIO_VSEL_table[] = {
-       1500, 1800, 2500, 3300,
+/* supported VIO voltages in microvolts */
+static const unsigned int VIO_VSEL_table[] = {
+       1500000, 1800000, 2500000, 3300000,
 };
 
 /* VSEL tables for TPS65910 specific LDOs and dcdc's */
 
-/* supported VDD3 voltages in milivolts */
-static const u16 VDD3_VSEL_table[] = {
-       5000,
+/* supported VDD3 voltages in microvolts */
+static const unsigned int VDD3_VSEL_table[] = {
+       5000000,
 };
 
-/* supported VDIG1 voltages in milivolts */
-static const u16 VDIG1_VSEL_table[] = {
-       1200, 1500, 1800, 2700,
+/* supported VDIG1 voltages in microvolts */
+static const unsigned int VDIG1_VSEL_table[] = {
+       1200000, 1500000, 1800000, 2700000,
 };
 
-/* supported VDIG2 voltages in milivolts */
-static const u16 VDIG2_VSEL_table[] = {
-       1000, 1100, 1200, 1800,
+/* supported VDIG2 voltages in microvolts */
+static const unsigned int VDIG2_VSEL_table[] = {
+       1000000, 1100000, 1200000, 1800000,
 };
 
-/* supported VPLL voltages in milivolts */
-static const u16 VPLL_VSEL_table[] = {
-       1000, 1100, 1800, 2500,
+/* supported VPLL voltages in microvolts */
+static const unsigned int VPLL_VSEL_table[] = {
+       1000000, 1100000, 1800000, 2500000,
 };
 
-/* supported VDAC voltages in milivolts */
-static const u16 VDAC_VSEL_table[] = {
-       1800, 2600, 2800, 2850,
+/* supported VDAC voltages in microvolts */
+static const unsigned int VDAC_VSEL_table[] = {
+       1800000, 2600000, 2800000, 2850000,
 };
 
-/* supported VAUX1 voltages in milivolts */
-static const u16 VAUX1_VSEL_table[] = {
-       1800, 2500, 2800, 2850,
+/* supported VAUX1 voltages in microvolts */
+static const unsigned int VAUX1_VSEL_table[] = {
+       1800000, 2500000, 2800000, 2850000,
 };
 
-/* supported VAUX2 voltages in milivolts */
-static const u16 VAUX2_VSEL_table[] = {
-       1800, 2800, 2900, 3300,
+/* supported VAUX2 voltages in microvolts */
+static const unsigned int VAUX2_VSEL_table[] = {
+       1800000, 2800000, 2900000, 3300000,
 };
 
-/* supported VAUX33 voltages in milivolts */
-static const u16 VAUX33_VSEL_table[] = {
-       1800, 2000, 2800, 3300,
+/* supported VAUX33 voltages in microvolts */
+static const unsigned int VAUX33_VSEL_table[] = {
+       1800000, 2000000, 2800000, 3300000,
 };
 
-/* supported VMMC voltages in milivolts */
-static const u16 VMMC_VSEL_table[] = {
-       1800, 2800, 3000, 3300,
+/* supported VMMC voltages in microvolts */
+static const unsigned int VMMC_VSEL_table[] = {
+       1800000, 2800000, 3000000, 3300000,
 };
 
 struct tps_info {
        const char *name;
-       unsigned min_uV;
-       unsigned max_uV;
+       const char *vin_name;
        u8 n_voltages;
-       const u16 *voltage_table;
+       const unsigned int *voltage_table;
        int enable_time_us;
 };
 
 static struct tps_info tps65910_regs[] = {
        {
-               .name = "VRTC",
+               .name = "vrtc",
+               .vin_name = "vcc7",
                .enable_time_us = 2200,
        },
        {
-               .name = "VIO",
-               .min_uV = 1500000,
-               .max_uV = 3300000,
+               .name = "vio",
+               .vin_name = "vccio",
                .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
                .voltage_table = VIO_VSEL_table,
                .enable_time_us = 350,
        },
        {
-               .name = "VDD1",
-               .min_uV = 600000,
-               .max_uV = 4500000,
+               .name = "vdd1",
+               .vin_name = "vcc1",
                .enable_time_us = 350,
        },
        {
-               .name = "VDD2",
-               .min_uV = 600000,
-               .max_uV = 4500000,
+               .name = "vdd2",
+               .vin_name = "vcc2",
                .enable_time_us = 350,
        },
        {
-               .name = "VDD3",
-               .min_uV = 5000000,
-               .max_uV = 5000000,
+               .name = "vdd3",
                .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
                .voltage_table = VDD3_VSEL_table,
                .enable_time_us = 200,
        },
        {
-               .name = "VDIG1",
-               .min_uV = 1200000,
-               .max_uV = 2700000,
+               .name = "vdig1",
+               .vin_name = "vcc6",
                .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
                .voltage_table = VDIG1_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VDIG2",
-               .min_uV = 1000000,
-               .max_uV = 1800000,
+               .name = "vdig2",
+               .vin_name = "vcc6",
                .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
                .voltage_table = VDIG2_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VPLL",
-               .min_uV = 1000000,
-               .max_uV = 2500000,
+               .name = "vpll",
+               .vin_name = "vcc5",
                .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
                .voltage_table = VPLL_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VDAC",
-               .min_uV = 1800000,
-               .max_uV = 2850000,
+               .name = "vdac",
+               .vin_name = "vcc5",
                .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
                .voltage_table = VDAC_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VAUX1",
-               .min_uV = 1800000,
-               .max_uV = 2850000,
+               .name = "vaux1",
+               .vin_name = "vcc4",
                .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
                .voltage_table = VAUX1_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VAUX2",
-               .min_uV = 1800000,
-               .max_uV = 3300000,
+               .name = "vaux2",
+               .vin_name = "vcc4",
                .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
                .voltage_table = VAUX2_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VAUX33",
-               .min_uV = 1800000,
-               .max_uV = 3300000,
+               .name = "vaux33",
+               .vin_name = "vcc3",
                .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
                .voltage_table = VAUX33_VSEL_table,
                .enable_time_us = 100,
        },
        {
-               .name = "VMMC",
-               .min_uV = 1800000,
-               .max_uV = 3300000,
+               .name = "vmmc",
+               .vin_name = "vcc3",
                .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
                .voltage_table = VMMC_VSEL_table,
                .enable_time_us = 100,
@@ -193,91 +180,79 @@ static struct tps_info tps65910_regs[] = {
 
 static struct tps_info tps65911_regs[] = {
        {
-               .name = "VRTC",
+               .name = "vrtc",
+               .vin_name = "vcc7",
                .enable_time_us = 2200,
        },
        {
-               .name = "VIO",
-               .min_uV = 1500000,
-               .max_uV = 3300000,
+               .name = "vio",
+               .vin_name = "vccio",
                .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
                .voltage_table = VIO_VSEL_table,
                .enable_time_us = 350,
        },
        {
-               .name = "VDD1",
-               .min_uV = 600000,
-               .max_uV = 4500000,
+               .name = "vdd1",
+               .vin_name = "vcc1",
                .n_voltages = 73,
                .enable_time_us = 350,
        },
        {
-               .name = "VDD2",
-               .min_uV = 600000,
-               .max_uV = 4500000,
+               .name = "vdd2",
+               .vin_name = "vcc2",
                .n_voltages = 73,
                .enable_time_us = 350,
        },
        {
-               .name = "VDDCTRL",
-               .min_uV = 600000,
-               .max_uV = 1400000,
+               .name = "vddctrl",
                .n_voltages = 65,
                .enable_time_us = 900,
        },
        {
-               .name = "LDO1",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo1",
+               .vin_name = "vcc6",
                .n_voltages = 47,
                .enable_time_us = 420,
        },
        {
-               .name = "LDO2",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo2",
+               .vin_name = "vcc6",
                .n_voltages = 47,
                .enable_time_us = 420,
        },
        {
-               .name = "LDO3",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo3",
+               .vin_name = "vcc5",
                .n_voltages = 24,
                .enable_time_us = 230,
        },
        {
-               .name = "LDO4",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo4",
+               .vin_name = "vcc5",
                .n_voltages = 47,
                .enable_time_us = 230,
        },
        {
-               .name = "LDO5",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo5",
+               .vin_name = "vcc4",
                .n_voltages = 24,
                .enable_time_us = 230,
        },
        {
-               .name = "LDO6",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo6",
+               .vin_name = "vcc3",
                .n_voltages = 24,
                .enable_time_us = 230,
        },
        {
-               .name = "LDO7",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo7",
+               .vin_name = "vcc3",
                .n_voltages = 24,
                .enable_time_us = 230,
        },
        {
-               .name = "LDO8",
-               .min_uV = 1000000,
-               .max_uV = 3300000,
+               .name = "ldo8",
+               .vin_name = "vcc3",
                .n_voltages = 24,
                .enable_time_us = 230,
        },
@@ -331,21 +306,16 @@ struct tps65910_reg {
 
 static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg)
 {
-       u8 val;
+       unsigned int val;
        int err;
 
-       err = pmic->mfd->read(pmic->mfd, reg, 1, &val);
+       err = tps65910_reg_read(pmic->mfd, reg, &val);
        if (err)
                return err;
 
        return val;
 }
 
-static inline int tps65910_write(struct tps65910_reg *pmic, u8 reg, u8 val)
-{
-       return pmic->mfd->write(pmic->mfd, reg, 1, &val);
-}
-
 static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
                                        u8 set_mask, u8 clear_mask)
 {
@@ -362,7 +332,7 @@ static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg,
 
        data &= ~clear_mask;
        data |= set_mask;
-       err = tps65910_write(pmic, reg, data);
+       err = tps65910_reg_write(pmic->mfd, reg, data);
        if (err)
                dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
 
@@ -371,7 +341,7 @@ out:
        return err;
 }
 
-static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
+static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg)
 {
        int data;
 
@@ -385,13 +355,13 @@ static int tps65910_reg_read(struct tps65910_reg *pmic, u8 reg)
        return data;
 }
 
-static int tps65910_reg_write(struct tps65910_reg *pmic, u8 reg, u8 val)
+static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val)
 {
        int err;
 
        mutex_lock(&pmic->mutex);
 
-       err = tps65910_write(pmic, reg, val);
+       err = tps65910_reg_write(pmic->mfd, reg, val);
        if (err < 0)
                dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg);
 
@@ -467,55 +437,6 @@ static int tps65911_get_ctrl_register(int id)
        }
 }
 
-static int tps65910_is_enabled(struct regulator_dev *dev)
-{
-       struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       int reg, value, id = rdev_get_id(dev);
-
-       reg = pmic->get_ctrl_reg(id);
-       if (reg < 0)
-               return reg;
-
-       value = tps65910_reg_read(pmic, reg);
-       if (value < 0)
-               return value;
-
-       return value & TPS65910_SUPPLY_STATE_ENABLED;
-}
-
-static int tps65910_enable(struct regulator_dev *dev)
-{
-       struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       struct tps65910 *mfd = pmic->mfd;
-       int reg, id = rdev_get_id(dev);
-
-       reg = pmic->get_ctrl_reg(id);
-       if (reg < 0)
-               return reg;
-
-       return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
-}
-
-static int tps65910_disable(struct regulator_dev *dev)
-{
-       struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       struct tps65910 *mfd = pmic->mfd;
-       int reg, id = rdev_get_id(dev);
-
-       reg = pmic->get_ctrl_reg(id);
-       if (reg < 0)
-               return reg;
-
-       return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED);
-}
-
-static int tps65910_enable_time(struct regulator_dev *dev)
-{
-       struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       int id = rdev_get_id(dev);
-       return pmic->info[id]->enable_time_us;
-}
-
 static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
 {
        struct tps65910_reg *pmic = rdev_get_drvdata(dev);
@@ -532,9 +453,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
                                                        LDO_ST_MODE_BIT);
        case REGULATOR_MODE_IDLE:
                value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT;
-               return tps65910_set_bits(mfd, reg, value);
+               return tps65910_reg_set_bits(mfd, reg, value);
        case REGULATOR_MODE_STANDBY:
-               return tps65910_clear_bits(mfd, reg, LDO_ST_ON_BIT);
+               return tps65910_reg_clear_bits(mfd, reg, LDO_ST_ON_BIT);
        }
 
        return -EINVAL;
@@ -549,7 +470,7 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev)
        if (reg < 0)
                return reg;
 
-       value = tps65910_reg_read(pmic, reg);
+       value = tps65910_reg_read_locked(pmic, reg);
        if (value < 0)
                return value;
 
@@ -569,28 +490,28 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
 
        switch (id) {
        case TPS65910_REG_VDD1:
-               opvsel = tps65910_reg_read(pmic, TPS65910_VDD1_OP);
-               mult = tps65910_reg_read(pmic, TPS65910_VDD1);
+               opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP);
+               mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1);
                mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
-               srvsel = tps65910_reg_read(pmic, TPS65910_VDD1_SR);
+               srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR);
                sr = opvsel & VDD1_OP_CMD_MASK;
                opvsel &= VDD1_OP_SEL_MASK;
                srvsel &= VDD1_SR_SEL_MASK;
                vselmax = 75;
                break;
        case TPS65910_REG_VDD2:
-               opvsel = tps65910_reg_read(pmic, TPS65910_VDD2_OP);
-               mult = tps65910_reg_read(pmic, TPS65910_VDD2);
+               opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP);
+               mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2);
                mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
-               srvsel = tps65910_reg_read(pmic, TPS65910_VDD2_SR);
+               srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR);
                sr = opvsel & VDD2_OP_CMD_MASK;
                opvsel &= VDD2_OP_SEL_MASK;
                srvsel &= VDD2_SR_SEL_MASK;
                vselmax = 75;
                break;
        case TPS65911_REG_VDDCTRL:
-               opvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_OP);
-               srvsel = tps65910_reg_read(pmic, TPS65911_VDDCTRL_SR);
+               opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP);
+               srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR);
                sr = opvsel & VDDCTRL_OP_CMD_MASK;
                opvsel &= VDDCTRL_OP_SEL_MASK;
                srvsel &= VDDCTRL_SR_SEL_MASK;
@@ -621,16 +542,16 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
        return -EINVAL;
 }
 
-static int tps65910_get_voltage(struct regulator_dev *dev)
+static int tps65910_get_voltage_sel(struct regulator_dev *dev)
 {
        struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       int reg, value, id = rdev_get_id(dev), voltage = 0;
+       int reg, value, id = rdev_get_id(dev);
 
        reg = pmic->get_ctrl_reg(id);
        if (reg < 0)
                return reg;
 
-       value = tps65910_reg_read(pmic, reg);
+       value = tps65910_reg_read_locked(pmic, reg);
        if (value < 0)
                return value;
 
@@ -651,25 +572,23 @@ static int tps65910_get_voltage(struct regulator_dev *dev)
                return -EINVAL;
        }
 
-       voltage = pmic->info[id]->voltage_table[value] * 1000;
-
-       return voltage;
+       return value;
 }
 
 static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
 {
-       return 5 * 1000 * 1000;
+       return dev->desc->volt_table[0];
 }
 
-static int tps65911_get_voltage(struct regulator_dev *dev)
+static int tps65911_get_voltage_sel(struct regulator_dev *dev)
 {
        struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       int step_mv, id = rdev_get_id(dev);
+       int id = rdev_get_id(dev);
        u8 value, reg;
 
        reg = pmic->get_ctrl_reg(id);
 
-       value = tps65910_reg_read(pmic, reg);
+       value = tps65910_reg_read_locked(pmic, reg);
 
        switch (id) {
        case TPS65911_REG_LDO1:
@@ -677,13 +596,6 @@ static int tps65911_get_voltage(struct regulator_dev *dev)
        case TPS65911_REG_LDO4:
                value &= LDO1_SEL_MASK;
                value >>= LDO_SEL_SHIFT;
-               /* The first 5 values of the selector correspond to 1V */
-               if (value < 5)
-                       value = 0;
-               else
-                       value -= 4;
-
-               step_mv = 50;
                break;
        case TPS65911_REG_LDO3:
        case TPS65911_REG_LDO5:
@@ -692,23 +604,16 @@ static int tps65911_get_voltage(struct regulator_dev *dev)
        case TPS65911_REG_LDO8:
                value &= LDO3_SEL_MASK;
                value >>= LDO_SEL_SHIFT;
-               /* The first 3 values of the selector correspond to 1V */
-               if (value < 3)
-                       value = 0;
-               else
-                       value -= 2;
-
-               step_mv = 100;
                break;
        case TPS65910_REG_VIO:
                value &= LDO_SEL_MASK;
                value >>= LDO_SEL_SHIFT;
-               return pmic->info[id]->voltage_table[value] * 1000;
+               break;
        default:
                return -EINVAL;
        }
 
-       return (LDO_MIN_VOLT + value * step_mv) * 1000;
+       return value;
 }
 
 static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
@@ -728,7 +633,7 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
                tps65910_modify_bits(pmic, TPS65910_VDD1,
                                (dcdc_mult << VDD1_VGAIN_SEL_SHIFT),
                                                VDD1_VGAIN_SEL_MASK);
-               tps65910_reg_write(pmic, TPS65910_VDD1_OP, vsel);
+               tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel);
                break;
        case TPS65910_REG_VDD2:
                dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
@@ -739,11 +644,11 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
                tps65910_modify_bits(pmic, TPS65910_VDD2,
                                (dcdc_mult << VDD2_VGAIN_SEL_SHIFT),
                                                VDD1_VGAIN_SEL_MASK);
-               tps65910_reg_write(pmic, TPS65910_VDD2_OP, vsel);
+               tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel);
                break;
        case TPS65911_REG_VDDCTRL:
                vsel = selector + 3;
-               tps65910_reg_write(pmic, TPS65911_VDDCTRL_OP, vsel);
+               tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel);
        }
 
        return 0;
@@ -831,23 +736,6 @@ static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
        return  volt * 100 * mult;
 }
 
-static int tps65910_list_voltage(struct regulator_dev *dev,
-                                       unsigned selector)
-{
-       struct tps65910_reg *pmic = rdev_get_drvdata(dev);
-       int id = rdev_get_id(dev), voltage;
-
-       if (id < TPS65910_REG_VIO || id > TPS65910_REG_VMMC)
-               return -EINVAL;
-
-       if (selector >= pmic->info[id]->n_voltages)
-               return -EINVAL;
-       else
-               voltage = pmic->info[id]->voltage_table[selector] * 1000;
-
-       return voltage;
-}
-
 static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
 {
        struct tps65910_reg *pmic = rdev_get_drvdata(dev);
@@ -879,7 +767,7 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
                step_mv = 100;
                break;
        case TPS65910_REG_VIO:
-               return pmic->info[id]->voltage_table[selector] * 1000;
+               return pmic->info[id]->voltage_table[selector];
        default:
                return -EINVAL;
        }
@@ -887,76 +775,47 @@ static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
        return (LDO_MIN_VOLT + selector * step_mv) * 1000;
 }
 
-static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev,
-               unsigned int old_selector, unsigned int new_selector)
-{
-       int id = rdev_get_id(dev);
-       int old_volt, new_volt;
-
-       old_volt = tps65910_list_voltage_dcdc(dev, old_selector);
-       if (old_volt < 0)
-               return old_volt;
-
-       new_volt = tps65910_list_voltage_dcdc(dev, new_selector);
-       if (new_volt < 0)
-               return new_volt;
-
-       /* VDD1 and VDD2 are 12.5mV/us, VDDCTRL is 100mV/20us */
-       switch (id) {
-       case TPS65910_REG_VDD1:
-       case TPS65910_REG_VDD2:
-               return DIV_ROUND_UP(abs(old_volt - new_volt), 12500);
-       case TPS65911_REG_VDDCTRL:
-               return DIV_ROUND_UP(abs(old_volt - new_volt), 5000);
-       }
-       return -EINVAL;
-}
-
 /* Regulator ops (except VRTC) */
 static struct regulator_ops tps65910_ops_dcdc = {
-       .is_enabled             = tps65910_is_enabled,
-       .enable                 = tps65910_enable,
-       .disable                = tps65910_disable,
-       .enable_time            = tps65910_enable_time,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = regulator_enable_regmap,
+       .disable                = regulator_disable_regmap,
        .set_mode               = tps65910_set_mode,
        .get_mode               = tps65910_get_mode,
        .get_voltage_sel        = tps65910_get_voltage_dcdc_sel,
        .set_voltage_sel        = tps65910_set_voltage_dcdc_sel,
-       .set_voltage_time_sel   = tps65910_set_voltage_dcdc_time_sel,
+       .set_voltage_time_sel   = regulator_set_voltage_time_sel,
        .list_voltage           = tps65910_list_voltage_dcdc,
 };
 
 static struct regulator_ops tps65910_ops_vdd3 = {
-       .is_enabled             = tps65910_is_enabled,
-       .enable                 = tps65910_enable,
-       .disable                = tps65910_disable,
-       .enable_time            = tps65910_enable_time,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = regulator_enable_regmap,
+       .disable                = regulator_disable_regmap,
        .set_mode               = tps65910_set_mode,
        .get_mode               = tps65910_get_mode,
        .get_voltage            = tps65910_get_voltage_vdd3,
-       .list_voltage           = tps65910_list_voltage,
+       .list_voltage           = regulator_list_voltage_table,
 };
 
 static struct regulator_ops tps65910_ops = {
-       .is_enabled             = tps65910_is_enabled,
-       .enable                 = tps65910_enable,
-       .disable                = tps65910_disable,
-       .enable_time            = tps65910_enable_time,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = regulator_enable_regmap,
+       .disable                = regulator_disable_regmap,
        .set_mode               = tps65910_set_mode,
        .get_mode               = tps65910_get_mode,
-       .get_voltage            = tps65910_get_voltage,
+       .get_voltage_sel        = tps65910_get_voltage_sel,
        .set_voltage_sel        = tps65910_set_voltage_sel,
-       .list_voltage           = tps65910_list_voltage,
+       .list_voltage           = regulator_list_voltage_table,
 };
 
 static struct regulator_ops tps65911_ops = {
-       .is_enabled             = tps65910_is_enabled,
-       .enable                 = tps65910_enable,
-       .disable                = tps65910_disable,
-       .enable_time            = tps65910_enable_time,
+       .is_enabled             = regulator_is_enabled_regmap,
+       .enable                 = regulator_enable_regmap,
+       .disable                = regulator_disable_regmap,
        .set_mode               = tps65910_set_mode,
        .get_mode               = tps65910_get_mode,
-       .get_voltage            = tps65911_get_voltage,
+       .get_voltage_sel        = tps65911_get_voltage_sel,
        .set_voltage_sel        = tps65911_set_voltage_sel,
        .list_voltage           = tps65911_list_voltage,
 };
@@ -994,10 +853,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 
        /* External EN1 control */
        if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
-               ret = tps65910_set_bits(mfd,
+               ret = tps65910_reg_set_bits(mfd,
                                TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
        else
-               ret = tps65910_clear_bits(mfd,
+               ret = tps65910_reg_clear_bits(mfd,
                                TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
        if (ret < 0) {
                dev_err(mfd->dev,
@@ -1007,10 +866,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
 
        /* External EN2 control */
        if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
-               ret = tps65910_set_bits(mfd,
+               ret = tps65910_reg_set_bits(mfd,
                                TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
        else
-               ret = tps65910_clear_bits(mfd,
+               ret = tps65910_reg_clear_bits(mfd,
                                TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
        if (ret < 0) {
                dev_err(mfd->dev,
@@ -1022,10 +881,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
        if ((tps65910_chip_id(mfd) == TPS65910) &&
                        (id >= TPS65910_REG_VDIG1)) {
                if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
-                       ret = tps65910_set_bits(mfd,
+                       ret = tps65910_reg_set_bits(mfd,
                                TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
                else
-                       ret = tps65910_clear_bits(mfd,
+                       ret = tps65910_reg_clear_bits(mfd,
                                TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
                if (ret < 0) {
                        dev_err(mfd->dev,
@@ -1037,10 +896,10 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
        /* Return if no external control is selected */
        if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
                /* Clear all sleep controls */
-               ret = tps65910_clear_bits(mfd,
+               ret = tps65910_reg_clear_bits(mfd,
                        TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
                if (!ret)
-                       ret = tps65910_clear_bits(mfd,
+                       ret = tps65910_reg_clear_bits(mfd,
                                TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
                if (ret < 0)
                        dev_err(mfd->dev,
@@ -1059,32 +918,33 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
                                (tps65910_chip_id(mfd) == TPS65911))) {
                int op_reg_add = pmic->get_ctrl_reg(id) + 1;
                int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
-               int opvsel = tps65910_reg_read(pmic, op_reg_add);
-               int srvsel = tps65910_reg_read(pmic, sr_reg_add);
+               int opvsel = tps65910_reg_read_locked(pmic, op_reg_add);
+               int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add);
                if (opvsel & VDD1_OP_CMD_MASK) {
                        u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
-                       ret = tps65910_reg_write(pmic, op_reg_add, reg_val);
+                       ret = tps65910_reg_write_locked(pmic, op_reg_add,
+                                                       reg_val);
                        if (ret < 0) {
                                dev_err(mfd->dev,
                                        "Error in configuring op register\n");
                                return ret;
                        }
                }
-               ret = tps65910_reg_write(pmic, sr_reg_add, 0);
+               ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0);
                if (ret < 0) {
                        dev_err(mfd->dev, "Error in settting sr register\n");
                        return ret;
                }
        }
 
-       ret = tps65910_clear_bits(mfd,
+       ret = tps65910_reg_clear_bits(mfd,
                        TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
        if (!ret) {
                if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
-                       ret = tps65910_set_bits(mfd,
+                       ret = tps65910_reg_set_bits(mfd,
                                TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
                else
-                       ret = tps65910_clear_bits(mfd,
+                       ret = tps65910_reg_clear_bits(mfd,
                                TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
        }
        if (ret < 0)
@@ -1094,30 +954,158 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
        return ret;
 }
 
+#ifdef CONFIG_OF
+
+static struct of_regulator_match tps65910_matches[] = {
+       { .name = "vrtc",       .driver_data = (void *) &tps65910_regs[0] },
+       { .name = "vio",        .driver_data = (void *) &tps65910_regs[1] },
+       { .name = "vdd1",       .driver_data = (void *) &tps65910_regs[2] },
+       { .name = "vdd2",       .driver_data = (void *) &tps65910_regs[3] },
+       { .name = "vdd3",       .driver_data = (void *) &tps65910_regs[4] },
+       { .name = "vdig1",      .driver_data = (void *) &tps65910_regs[5] },
+       { .name = "vdig2",      .driver_data = (void *) &tps65910_regs[6] },
+       { .name = "vpll",       .driver_data = (void *) &tps65910_regs[7] },
+       { .name = "vdac",       .driver_data = (void *) &tps65910_regs[8] },
+       { .name = "vaux1",      .driver_data = (void *) &tps65910_regs[9] },
+       { .name = "vaux2",      .driver_data = (void *) &tps65910_regs[10] },
+       { .name = "vaux33",     .driver_data = (void *) &tps65910_regs[11] },
+       { .name = "vmmc",       .driver_data = (void *) &tps65910_regs[12] },
+};
+
+static struct of_regulator_match tps65911_matches[] = {
+       { .name = "vrtc",       .driver_data = (void *) &tps65911_regs[0] },
+       { .name = "vio",        .driver_data = (void *) &tps65911_regs[1] },
+       { .name = "vdd1",       .driver_data = (void *) &tps65911_regs[2] },
+       { .name = "vdd2",       .driver_data = (void *) &tps65911_regs[3] },
+       { .name = "vddctrl",    .driver_data = (void *) &tps65911_regs[4] },
+       { .name = "ldo1",       .driver_data = (void *) &tps65911_regs[5] },
+       { .name = "ldo2",       .driver_data = (void *) &tps65911_regs[6] },
+       { .name = "ldo3",       .driver_data = (void *) &tps65911_regs[7] },
+       { .name = "ldo4",       .driver_data = (void *) &tps65911_regs[8] },
+       { .name = "ldo5",       .driver_data = (void *) &tps65911_regs[9] },
+       { .name = "ldo6",       .driver_data = (void *) &tps65911_regs[10] },
+       { .name = "ldo7",       .driver_data = (void *) &tps65911_regs[11] },
+       { .name = "ldo8",       .driver_data = (void *) &tps65911_regs[12] },
+};
+
+static struct tps65910_board *tps65910_parse_dt_reg_data(
+               struct platform_device *pdev,
+               struct of_regulator_match **tps65910_reg_matches)
+{
+       struct tps65910_board *pmic_plat_data;
+       struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
+       struct device_node *np = pdev->dev.parent->of_node;
+       struct device_node *regulators;
+       struct of_regulator_match *matches;
+       unsigned int prop;
+       int idx = 0, ret, count;
+
+       pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
+                                       GFP_KERNEL);
+
+       if (!pmic_plat_data) {
+               dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
+               return NULL;
+       }
+
+       regulators = of_find_node_by_name(np, "regulators");
+       if (!regulators) {
+               dev_err(&pdev->dev, "regulator node not found\n");
+               return NULL;
+       }
+
+       switch (tps65910_chip_id(tps65910)) {
+       case TPS65910:
+               count = ARRAY_SIZE(tps65910_matches);
+               matches = tps65910_matches;
+               break;
+       case TPS65911:
+               count = ARRAY_SIZE(tps65911_matches);
+               matches = tps65911_matches;
+               break;
+       default:
+               dev_err(&pdev->dev, "Invalid tps chip version\n");
+               return NULL;
+       }
+
+       ret = of_regulator_match(pdev->dev.parent, regulators, matches, count);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
+                       ret);
+               return NULL;
+       }
+
+       *tps65910_reg_matches = matches;
+
+       for (idx = 0; idx < count; idx++) {
+               struct tps_info *info = matches[idx].driver_data;
+               char in_supply[32]; /* 32 is max size of property name */
+
+               if (!matches[idx].init_data || !matches[idx].of_node)
+                       continue;
+
+               pmic_plat_data->tps65910_pmic_init_data[idx] =
+                                                       matches[idx].init_data;
+
+               ret = of_property_read_u32(matches[idx].of_node,
+                               "ti,regulator-ext-sleep-control", &prop);
+               if (!ret)
+                       pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
+
+               if (info->vin_name) {
+                       snprintf(in_supply, 32, "%s-supply", info->vin_name);
+                       if (of_find_property(np, in_supply, 0))
+                               pmic_plat_data->input_supply[idx] =
+                                                               info->vin_name;
+               }
+       }
+
+       return pmic_plat_data;
+}
+#else
+static inline struct tps65910_board *tps65910_parse_dt_reg_data(
+                       struct platform_device *pdev,
+                       struct of_regulator_match **tps65910_reg_matches)
+{
+       *tps65910_reg_matches = NULL;
+       return NULL;
+}
+#endif
+
 static __devinit int tps65910_probe(struct platform_device *pdev)
 {
        struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
+       struct regulator_config config = { };
        struct tps_info *info;
        struct regulator_init_data *reg_data;
        struct regulator_dev *rdev;
        struct tps65910_reg *pmic;
        struct tps65910_board *pmic_plat_data;
+       struct of_regulator_match *tps65910_reg_matches = NULL;
        int i, err;
 
        pmic_plat_data = dev_get_platdata(tps65910->dev);
-       if (!pmic_plat_data)
+       if (!pmic_plat_data && tps65910->dev->of_node)
+               pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
+                                               &tps65910_reg_matches);
+
+       if (!pmic_plat_data) {
+               dev_err(&pdev->dev, "Platform data not found\n");
                return -EINVAL;
+       }
 
-       pmic = kzalloc(sizeof(*pmic), GFP_KERNEL);
-       if (!pmic)
+       pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
+       if (!pmic) {
+               dev_err(&pdev->dev, "Memory allocation failed for pmic\n");
                return -ENOMEM;
+       }
 
        mutex_init(&pmic->mutex);
        pmic->mfd = tps65910;
        platform_set_drvdata(pdev, pmic);
 
        /* Give control of all register to control port */
-       tps65910_set_bits(pmic->mfd, TPS65910_DEVCTRL,
+       tps65910_reg_set_bits(pmic->mfd, TPS65910_DEVCTRL,
                                DEVCTRL_SR_CTL_I2C_SEL_MASK);
 
        switch(tps65910_chip_id(tps65910)) {
@@ -1134,30 +1122,29 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
                info = tps65911_regs;
                break;
        default:
-               pr_err("Invalid tps chip version\n");
-               kfree(pmic);
+               dev_err(&pdev->dev, "Invalid tps chip version\n");
                return -ENODEV;
        }
 
-       pmic->desc = kcalloc(pmic->num_regulators,
+       pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators *
                        sizeof(struct regulator_desc), GFP_KERNEL);
        if (!pmic->desc) {
-               err = -ENOMEM;
-               goto err_free_pmic;
+               dev_err(&pdev->dev, "Memory alloc fails for desc\n");
+               return -ENOMEM;
        }
 
-       pmic->info = kcalloc(pmic->num_regulators,
+       pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators *
                        sizeof(struct tps_info *), GFP_KERNEL);
        if (!pmic->info) {
-               err = -ENOMEM;
-               goto err_free_desc;
+               dev_err(&pdev->dev, "Memory alloc fails for info\n");
+               return -ENOMEM;
        }
 
-       pmic->rdev = kcalloc(pmic->num_regulators,
+       pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators *
                        sizeof(struct regulator_dev *), GFP_KERNEL);
        if (!pmic->rdev) {
-               err = -ENOMEM;
-               goto err_free_info;
+               dev_err(&pdev->dev, "Memory alloc fails for rdev\n");
+               return -ENOMEM;
        }
 
        for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS;
@@ -1174,23 +1161,31 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
                pmic->info[i] = info;
 
                pmic->desc[i].name = info->name;
+               pmic->desc[i].supply_name = pmic_plat_data->input_supply[i];
                pmic->desc[i].id = i;
                pmic->desc[i].n_voltages = info->n_voltages;
+               pmic->desc[i].enable_time = info->enable_time_us;
 
                if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
                        pmic->desc[i].ops = &tps65910_ops_dcdc;
                        pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
                                                        VDD1_2_NUM_VOLT_COARSE;
+                       pmic->desc[i].ramp_delay = 12500;
                } else if (i == TPS65910_REG_VDD3) {
-                       if (tps65910_chip_id(tps65910) == TPS65910)
+                       if (tps65910_chip_id(tps65910) == TPS65910) {
                                pmic->desc[i].ops = &tps65910_ops_vdd3;
-                       else
+                               pmic->desc[i].volt_table = info->voltage_table;
+                       } else {
                                pmic->desc[i].ops = &tps65910_ops_dcdc;
+                               pmic->desc[i].ramp_delay = 5000;
+                       }
                } else {
-                       if (tps65910_chip_id(tps65910) == TPS65910)
+                       if (tps65910_chip_id(tps65910) == TPS65910) {
                                pmic->desc[i].ops = &tps65910_ops;
-                       else
+                               pmic->desc[i].volt_table = info->voltage_table;
+                       } else {
                                pmic->desc[i].ops = &tps65911_ops;
+                       }
                }
 
                err = tps65910_set_ext_sleep_config(pmic, i,
@@ -1205,9 +1200,18 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 
                pmic->desc[i].type = REGULATOR_VOLTAGE;
                pmic->desc[i].owner = THIS_MODULE;
+               pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
+               pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
+
+               config.dev = tps65910->dev;
+               config.init_data = reg_data;
+               config.driver_data = pmic;
+               config.regmap = tps65910->regmap;
+
+               if (tps65910_reg_matches)
+                       config.of_node = tps65910_reg_matches[i].of_node;
 
-               rdev = regulator_register(&pmic->desc[i],
-                               tps65910->dev, reg_data, pmic, NULL);
+               rdev = regulator_register(&pmic->desc[i], &config);
                if (IS_ERR(rdev)) {
                        dev_err(tps65910->dev,
                                "failed to register %s regulator\n",
@@ -1224,13 +1228,6 @@ static __devinit int tps65910_probe(struct platform_device *pdev)
 err_unregister_regulator:
        while (--i >= 0)
                regulator_unregister(pmic->rdev[i]);
-       kfree(pmic->rdev);
-err_free_info:
-       kfree(pmic->info);
-err_free_desc:
-       kfree(pmic->desc);
-err_free_pmic:
-       kfree(pmic);
        return err;
 }
 
@@ -1242,10 +1239,6 @@ static int __devexit tps65910_remove(struct platform_device *pdev)
        for (i = 0; i < pmic->num_regulators; i++)
                regulator_unregister(pmic->rdev[i]);
 
-       kfree(pmic->rdev);
-       kfree(pmic->info);
-       kfree(pmic->desc);
-       kfree(pmic);
        return 0;
 }
 
This page took 0.038676 seconds and 5 git commands to generate.