Commit 178e43ae authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branches 'regulator/topic/core',...

Merge remote-tracking branches 'regulator/topic/core', 'regulator/topic/regmap' and 'regulator/topic/register' into regulator-next
......@@ -11,8 +11,7 @@ Registration
Drivers can register a regulator by calling :-
struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
struct device *dev, struct regulator_init_data *init_data,
void *driver_data, struct device_node *of_node);
const struct regulator_config *config);
This will register the regulators capabilities and operations to the regulator
core.
......
......@@ -78,17 +78,6 @@ static struct mfd_cell tps65090s[] = {
},
};
struct tps65090 {
struct mutex lock;
struct device *dev;
struct i2c_client *client;
struct regmap *rmap;
struct irq_chip irq_chip;
struct mutex irq_lock;
int irq_base;
unsigned int id;
};
int tps65090_write(struct device *dev, int reg, uint8_t val)
{
struct tps65090 *tps = dev_get_drvdata(dev);
......
......@@ -27,13 +27,8 @@ struct pm8607_regulator_info {
unsigned int *vol_table;
unsigned int *vol_suspend;
int vol_reg;
int vol_shift;
int vol_nbits;
int update_reg;
int update_bit;
int enable_reg;
int enable_bit;
int slope_double;
};
......@@ -216,7 +211,7 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
int ret = -EINVAL;
if (info->vol_table && (index < (1 << info->vol_nbits))) {
if (info->vol_table && (index < rdev->desc->n_voltages)) {
ret = info->vol_table[index];
if (info->slope_double)
ret <<= 1;
......@@ -224,51 +219,16 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
return ret;
}
static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
static int pm8607_set_voltage_sel(struct regulator_dev *rdev, unsigned selector)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
int i, ret = -ENOENT;
if (info->slope_double) {
min_uV = min_uV >> 1;
max_uV = max_uV >> 1;
}
if (info->vol_table) {
for (i = 0; i < (1 << info->vol_nbits); i++) {
if (!info->vol_table[i])
break;
if ((min_uV <= info->vol_table[i])
&& (max_uV >= info->vol_table[i])) {
ret = i;
break;
}
}
}
if (ret < 0)
pr_err("invalid voltage range (%d %d) uV\n", min_uV, max_uV);
return ret;
}
static int pm8607_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV, unsigned *selector)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
uint8_t val, mask;
uint8_t val;
int ret;
if (min_uV > max_uV) {
pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
return -EINVAL;
}
ret = choose_voltage(rdev, min_uV, max_uV);
if (ret < 0)
return -EINVAL;
*selector = ret;
val = (uint8_t)(ret << info->vol_shift);
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
val = (uint8_t)(selector << (ffs(rdev->desc->vsel_mask) - 1));
ret = pm860x_set_bits(info->i2c, info->vol_reg, mask, val);
ret = pm860x_set_bits(info->i2c, rdev->desc->vsel_reg,
rdev->desc->vsel_mask, val);
if (ret)
return ret;
switch (info->desc.id) {
......@@ -282,60 +242,16 @@ static int pm8607_set_voltage(struct regulator_dev *rdev,
return ret;
}
static int pm8607_get_voltage(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
uint8_t val, mask;
int ret;
ret = pm860x_reg_read(info->i2c, info->vol_reg);
if (ret < 0)
return ret;
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
val = ((unsigned char)ret & mask) >> info->vol_shift;
return pm8607_list_voltage(rdev, val);
}
static int pm8607_enable(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
return pm860x_set_bits(info->i2c, info->enable_reg,
1 << info->enable_bit,
1 << info->enable_bit);
}
static int pm8607_disable(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
return pm860x_set_bits(info->i2c, info->enable_reg,
1 << info->enable_bit, 0);
}
static int pm8607_is_enabled(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
int ret;
ret = pm860x_reg_read(info->i2c, info->enable_reg);
if (ret < 0)
return ret;
return !!((unsigned char)ret & (1 << info->enable_bit));
}
static struct regulator_ops pm8607_regulator_ops = {
.set_voltage = pm8607_set_voltage,
.get_voltage = pm8607_get_voltage,
.enable = pm8607_enable,
.disable = pm8607_disable,
.is_enabled = pm8607_is_enabled,
.list_voltage = pm8607_list_voltage,
.set_voltage_sel = pm8607_set_voltage_sel,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
};
#define PM8607_DVC(vreg, nbits, ureg, ubit, ereg, ebit) \
#define PM8607_DVC(vreg, ureg, ubit, ereg, ebit) \
{ \
.desc = { \
.name = #vreg, \
......@@ -343,20 +259,20 @@ static struct regulator_ops pm8607_regulator_ops = {
.type = REGULATOR_VOLTAGE, \
.id = PM8607_ID_##vreg, \
.owner = THIS_MODULE, \
.n_voltages = ARRAY_SIZE(vreg##_table), \
.vsel_reg = PM8607_##vreg, \
.vsel_mask = ARRAY_SIZE(vreg##_table) - 1, \
.enable_reg = PM8607_##ereg, \
.enable_mask = 1 << (ebit), \
}, \
.vol_reg = PM8607_##vreg, \
.vol_shift = (0), \
.vol_nbits = (nbits), \
.update_reg = PM8607_##ureg, \
.update_bit = (ubit), \
.enable_reg = PM8607_##ereg, \
.enable_bit = (ebit), \
.slope_double = (0), \
.vol_table = (unsigned int *)&vreg##_table, \
.vol_suspend = (unsigned int *)&vreg##_suspend_table, \
}
#define PM8607_LDO(_id, vreg, shift, nbits, ereg, ebit) \
#define PM8607_LDO(_id, vreg, shift, ereg, ebit) \
{ \
.desc = { \
.name = "LDO" #_id, \
......@@ -364,35 +280,35 @@ static struct regulator_ops pm8607_regulator_ops = {
.type = REGULATOR_VOLTAGE, \
.id = PM8607_ID_LDO##_id, \
.owner = THIS_MODULE, \
}, \
.vol_reg = PM8607_##vreg, \
.vol_shift = (shift), \
.vol_nbits = (nbits), \
.n_voltages = ARRAY_SIZE(LDO##_id##_table), \
.vsel_reg = PM8607_##vreg, \
.vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \
.enable_reg = PM8607_##ereg, \
.enable_bit = (ebit), \
.enable_mask = 1 << (ebit), \
}, \
.slope_double = (0), \
.vol_table = (unsigned int *)&LDO##_id##_table, \
.vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \
}
static struct pm8607_regulator_info pm8607_regulator_info[] = {
PM8607_DVC(BUCK1, 6, GO, 0, SUPPLIES_EN11, 0),
PM8607_DVC(BUCK2, 6, GO, 1, SUPPLIES_EN11, 1),
PM8607_DVC(BUCK3, 6, GO, 2, SUPPLIES_EN11, 2),
PM8607_LDO( 1, LDO1, 0, 2, SUPPLIES_EN11, 3),
PM8607_LDO( 2, LDO2, 0, 3, SUPPLIES_EN11, 4),
PM8607_LDO( 3, LDO3, 0, 3, SUPPLIES_EN11, 5),
PM8607_LDO( 4, LDO4, 0, 3, SUPPLIES_EN11, 6),
PM8607_LDO( 5, LDO5, 0, 2, SUPPLIES_EN11, 7),
PM8607_LDO( 6, LDO6, 0, 3, SUPPLIES_EN12, 0),
PM8607_LDO( 7, LDO7, 0, 3, SUPPLIES_EN12, 1),
PM8607_LDO( 8, LDO8, 0, 3, SUPPLIES_EN12, 2),
PM8607_LDO( 9, LDO9, 0, 3, SUPPLIES_EN12, 3),
PM8607_LDO(10, LDO10, 0, 4, SUPPLIES_EN12, 4),
PM8607_LDO(12, LDO12, 0, 4, SUPPLIES_EN12, 5),
PM8607_LDO(13, VIBRATOR_SET, 1, 3, VIBRATOR_SET, 0),
PM8607_LDO(14, LDO14, 0, 3, SUPPLIES_EN12, 6),
PM8607_DVC(BUCK1, GO, 0, SUPPLIES_EN11, 0),
PM8607_DVC(BUCK2, GO, 1, SUPPLIES_EN11, 1),
PM8607_DVC(BUCK3, GO, 2, SUPPLIES_EN11, 2),
PM8607_LDO(1, LDO1, 0, SUPPLIES_EN11, 3),
PM8607_LDO(2, LDO2, 0, SUPPLIES_EN11, 4),
PM8607_LDO(3, LDO3, 0, SUPPLIES_EN11, 5),
PM8607_LDO(4, LDO4, 0, SUPPLIES_EN11, 6),
PM8607_LDO(5, LDO5, 0, SUPPLIES_EN11, 7),
PM8607_LDO(6, LDO6, 0, SUPPLIES_EN12, 0),
PM8607_LDO(7, LDO7, 0, SUPPLIES_EN12, 1),
PM8607_LDO(8, LDO8, 0, SUPPLIES_EN12, 2),
PM8607_LDO(9, LDO9, 0, SUPPLIES_EN12, 3),
PM8607_LDO(10, LDO10, 0, SUPPLIES_EN12, 4),
PM8607_LDO(12, LDO12, 0, SUPPLIES_EN12, 5),
PM8607_LDO(13, VIBRATOR_SET, 1, VIBRATOR_SET, 0),
PM8607_LDO(14, LDO14, 0, SUPPLIES_EN12, 6),
};
static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
......@@ -400,6 +316,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct pm8607_regulator_info *info = NULL;
struct regulator_init_data *pdata = pdev->dev.platform_data;
struct regulator_config config = { };
struct resource *res;
int i;
......@@ -425,9 +342,17 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
if ((i == PM8607_ID_BUCK3) && info->chip->buck3_double)
info->slope_double = 1;
config.dev = &pdev->dev;
config.init_data = pdata;
config.driver_data = info;
if (chip->id == CHIP_PM8607)
config.regmap = chip->regmap;
else
config.regmap = chip->regmap_companion;
/* replace driver_data with info */
info->regulator = regulator_register(&info->desc, &pdev->dev,
pdata, info, NULL);
info->regulator = regulator_register(&info->desc, &config);
if (IS_ERR(info->regulator)) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
info->desc.name);
......
......@@ -223,6 +223,16 @@ config REGULATOR_PCF50633
Say Y here to support the voltage regulators and convertors
on PCF50633
config REGULATOR_RC5T583
tristate "RICOH RC5T583 Power regulators"
depends on MFD_RC5T583
help
Select this option to enable the power regulator of RICOH
PMIC RC5T583.
This driver supports the control of different power rails of device
through regulator interface. The device supports multiple DCDC/LDO
outputs which can be controlled by i2c communication.
config REGULATOR_S5M8767
tristate "Samsung S5M8767A voltage regulator"
depends on MFD_S5M_CORE
......@@ -268,11 +278,11 @@ config REGULATOR_TPS6105X
audio amplifiers.
config REGULATOR_TPS62360
tristate "TI TPS62360 Power Regulator"
tristate "TI TPS6236x Power Regulator"
depends on I2C
select REGMAP_I2C
help
This driver supports TPS62360 voltage regulator chip. This
This driver supports TPS6236x voltage regulator chip. This
regulator is meant for processor core supply. This chip is
high-frequency synchronous step down dc-dc converter optimized
for battery-powered portable applications.
......@@ -294,6 +304,13 @@ config REGULATOR_TPS6507X
three step-down converters and two general-purpose LDO voltage regulators.
It supports TI's software based Class-2 SmartReflex implementation.
config REGULATOR_TPS65090
tristate "TI TPS65090 Power regulator"
depends on MFD_TPS65090
help
This driver provides support for the voltage regulators on the
TI TPS65090 PMIC.
config REGULATOR_TPS65217
tristate "TI TPS65217 Power regulators"
depends on MFD_TPS65217
......
......@@ -9,7 +9,6 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o
obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
......@@ -20,6 +19,7 @@ obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o
obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o
obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o
obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o
......@@ -35,11 +35,13 @@ obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o
obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o
obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o
obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o
obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o
obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
obj-$(CONFIG_REGULATOR_TPS65090) += tps65090-regulator.o
obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o
obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o
......
......@@ -178,6 +178,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
static int aat2870_regulator_probe(struct platform_device *pdev)
{
struct aat2870_regulator *ri;
struct regulator_config config = { 0 };
struct regulator_dev *rdev;
ri = aat2870_get_regulator(pdev->id);
......@@ -187,8 +188,11 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
}
ri->aat2870 = dev_get_drvdata(pdev->dev.parent);
rdev = regulator_register(&ri->desc, &pdev->dev,
pdev->dev.platform_data, ri, NULL);
config.dev = &pdev->dev;
config.driver_data = ri;
config.init_data = pdev->dev.platform_data;
rdev = regulator_register(&ri->desc, &config);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "Failed to register regulator %s\n",
ri->desc.name);
......@@ -231,3 +235,4 @@ module_exit(aat2870_regulator_exit);
MODULE_DESCRIPTION("AnalogicTech AAT2870 Regulator");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jin Park <jinyoungp@nvidia.com>");
MODULE_ALIAS("platform:aat2870-regulator");
......@@ -338,20 +338,12 @@ static int ab3100_get_best_voltage_index(struct regulator_dev *reg,
return bestindex;
}
static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
int min_uV, int max_uV,
unsigned *selector)
static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg,
unsigned selector)
{
struct ab3100_regulator *abreg = reg->reg_data;
u8 regval;
int err;
int bestindex;
bestindex = ab3100_get_best_voltage_index(reg, min_uV, max_uV);
if (bestindex < 0)
return bestindex;
*selector = bestindex;
err = abx500_get_register_interruptible(abreg->dev, 0,
abreg->regreg, &regval);
......@@ -364,7 +356,7 @@ static int ab3100_set_voltage_regulator(struct regulator_dev *reg,
/* The highest three bits control the variable regulators */
regval &= ~0xE0;
regval |= (bestindex << 5);
regval |= (selector << 5);
err = abx500_set_register_interruptible(abreg->dev, 0,
abreg->regreg, regval);
......@@ -464,7 +456,7 @@ static struct regulator_ops regulator_ops_variable = {
.disable = ab3100_disable_regulator,
.is_enabled = ab3100_is_enabled_regulator,
.get_voltage = ab3100_get_voltage_regulator,
.set_voltage = ab3100_set_voltage_regulator,
.set_voltage_sel = ab3100_set_voltage_regulator_sel,
.list_voltage = ab3100_list_voltage_regulator,
.enable_time = ab3100_enable_time_regulator,
};
......@@ -474,7 +466,7 @@ static struct regulator_ops regulator_ops_variable_sleepable = {
.disable = ab3100_disable_regulator,
.is_enabled = ab3100_is_enabled_regulator,
.get_voltage = ab3100_get_voltage_regulator,
.set_voltage = ab3100_set_voltage_regulator,
.set_voltage_sel = ab3100_set_voltage_regulator_sel,
.set_suspend_voltage = ab3100_set_suspend_voltage_regulator,
.list_voltage = ab3100_list_voltage_regulator,
.enable_time = ab3100_enable_time_regulator,
......@@ -582,6 +574,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
{
struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
struct regulator_config config = { };
int err = 0;
u8 data;
int i;
......@@ -627,15 +620,15 @@ static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
reg->dev = &pdev->dev;
reg->plfdata = plfdata;
config.dev = &pdev->dev;
config.driver_data = reg;
config.init_data = &plfdata->reg_constraints[i];
/*
* Register the regulator, pass around
* the ab3100_regulator struct
*/
rdev = regulator_register(&ab3100_regulator_desc[i],
&pdev->dev,
&plfdata->reg_constraints[i],
reg, NULL);
rdev = regulator_register(&ab3100_regulator_desc[i], &config);
if (IS_ERR(rdev)) {
err = PTR_ERR(rdev);
dev_err(&pdev->dev,
......
......@@ -234,25 +234,8 @@ static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
return val;
}
static int ab8500_get_best_voltage_index(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
int i;
/* check the supported voltage */
for (i = 0; i < info->voltages_len; i++) {
if ((info->voltages[i] >= min_uV) &&
(info->voltages[i] <= max_uV))
return i;
}
return -EINVAL;
}
static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV,
unsigned *selector)
static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned selector)
{
int ret;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
......@@ -263,18 +246,8 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
return -EINVAL;
}
/* get the appropriate voltages within the range */
ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
if (ret < 0) {
dev_err(rdev_get_dev(rdev),
"couldn't get best voltage for regulator\n");
return ret;
}
*selector = ret;
/* set the registers for the request */
regval = (u8)ret;
regval = (u8)selector;
ret = abx500_mask_and_set_register_interruptible(info->dev,
info->voltage_bank, info->voltage_reg,
info->voltage_mask, regval);
......@@ -319,7 +292,7 @@ static struct regulator_ops ab8500_regulator_ops = {
.disable = ab8500_regulator_disable,
.is_enabled = ab8500_regulator_is_enabled,
.get_voltage_sel = ab8500_regulator_get_voltage_sel,
.set_voltage = ab8500_regulator_set_voltage,
.set_voltage_sel = ab8500_regulator_set_voltage_sel,
.list_voltage = ab8500_list_voltage,
.enable_time = ab8500_regulator_enable_time,
.set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
......@@ -739,6 +712,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
{
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
struct ab8500_platform_data *pdata;
struct regulator_config config = { };
int i, err;
if (!ab8500) {
......@@ -806,6 +780,10 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
info = &ab8500_regulator_info[i];
info->dev = &pdev->dev;
config.dev = &pdev->dev;
config.init_data = &pdata->regulator[i];
config.driver_data = info;
/* fix for hardware before ab8500v2.0 */
if (abx500_get_chip_id(info->dev) < 0x20) {
if (info->desc.id == AB8500_LDO_AUX3) {
......@@ -819,8 +797,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
}
/* register regulator with framework */
info->regulator = regulator_register(&info->desc, &pdev->dev,
&pdata->regulator[i], info, NULL);
info->regulator = regulator_register(&info->desc, &config);
if (IS_ERR(info->regulator)) {
err = PTR_ERR(info->regulator);
dev_err(&pdev->dev, "failed to register regulator %s\n",
......
......@@ -99,8 +99,8 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
if (ad5398_calc_current(chip, selector) > max_uA)
return -EINVAL;
dev_dbg(&client->dev, "changing current %dmA\n",
ad5398_calc_current(chip, selector) / 1000);
dev_dbg(&client->dev, "changing current %duA\n",
ad5398_calc_current(chip, selector));
/* read chip enable bit */
ret = ad5398_read_reg(client, &data);
......@@ -184,7 +184,7 @@ static struct regulator_ops ad5398_ops = {
.is_enabled = ad5398_is_enabled,
};
static struct regulator_desc ad5398_reg = {
static const struct regulator_desc ad5398_reg = {
.name = "isink",
.id = 0,
.ops = &ad5398_ops,
......@@ -212,6 +212,7 @@ static int __devinit ad5398_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct regulator_init_data *init_data = client->dev.platform_data;
struct regulator_config config = { };
struct ad5398_chip_info *chip;
const struct ad5398_current_data_format *df =
(struct ad5398_current_data_format *)id->driver_data;
......@@ -220,10 +221,14 @@ static int __devinit ad5398_probe(struct i2c_client *client,
if (!init_data)
return -EINVAL;
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
return -ENOMEM;
config.dev = &client->dev;
config.init_data = init_data;
config.driver_data = chip;
chip->client = client;
chip->min_uA = df->min_uA;
......@@ -232,8 +237,7 @@ static int __devinit ad5398_probe(struct i2c_client *client,
chip->current_offset = df->current_offset;
chip->current_mask = (chip->current_level - 1) << chip->current_offset;
chip->rdev = regulator_register(&ad5398_reg, &client->dev,
init_data, chip, NULL);
chip->rdev = regulator_register(&ad5398_reg, &config);
if (IS_ERR(chip->rdev)) {
ret = PTR_ERR(chip->rdev);
dev_err(&client->dev, "failed to register %s %s\n",
......@@ -246,7 +250,6 @@ static int __devinit ad5398_probe(struct i2c_client *client,
return 0;
err:
kfree(chip);
return ret;
}
......@@ -255,8 +258,6 @@ static int __devexit ad5398_remove(struct i2c_client *client)
struct ad5398_chip_info *chip = i2c_get_clientdata(client);
regulator_unregister(chip->rdev);
kfree(chip);
return 0;
}
......
......@@ -122,6 +122,7 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev)
struct anatop_regulator *sreg;
struct regulator_init_data *initdata;
struct anatop *anatopmfd = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
int ret = 0;
initdata = of_get_regulator_init_data(dev, np);
......@@ -178,9 +179,13 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev)
rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage)
/ 25000 + 1;
config.dev = &pdev->dev;
config.init_data = initdata;
config.driver_data = sreg;
config.of_node = pdev->dev.of_node;
/* register regulator */
rdev = regulator_register(rdesc, dev,
initdata, sreg, pdev->dev.of_node);
rdev = regulator_register(rdesc, &config);
if (IS_ERR(rdev)) {
dev_err(dev, "failed to register %s\n",
rdesc->name);
......
This diff is collapsed.
......@@ -517,6 +517,7 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev)
{
struct da903x_regulator_info *ri = NULL;
struct regulator_dev *rdev;
struct regulator_config config = { };
ri = find_regulator_info(pdev->id);
if (ri == NULL) {
......@@ -536,8 +537,11 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev)
if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
ri->desc.ops = &da9030_regulator_ldo1_15_ops;
rdev = regulator_register(&ri->desc, &pdev->dev,
pdev->dev.platform_data, ri, NULL);
config.dev = &pdev->dev;
config.init_data = pdev->dev.platform_data;
config.driver_data = ri;
rdev = regulator_register(&ri->desc, &config);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
ri->desc.name);
......
This diff is collapsed.
......@@ -414,6 +414,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)
{
struct regulator_init_data *db8500_init_data =
dev_get_platdata(&pdev->dev);
struct regulator_config config = { };
int i, err;
/* register all regulators */
......@@ -425,9 +426,12 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)
info = &dbx500_regulator_info[i];
info->dev = &pdev->dev;
config.dev = &pdev->dev;
config.init_data = init_data;
config.driver_data = info;
/* register with the regulator framework */
info->rdev = regulator_register(&info->desc, &pdev->dev,
init_data, info, NULL);
info->rdev = regulator_register(&info->desc, &config);
if (IS_ERR(info->rdev)) {
err = PTR_ERR(info->rdev);
dev_err(&pdev->dev, "failed to register %s: err %i\n",
......
......@@ -39,10 +39,13 @@ static struct regulator_desc dummy_desc = {
static int __devinit dummy_regulator_probe(struct platform_device *pdev)
{
struct regulator_config config = { };
int ret;
dummy_regulator_rdev = regulator_register(&dummy_desc, NULL,
&dummy_initdata, NULL, NULL);
config.dev = &pdev->dev;
config.init_data = &dummy_initdata;
dummy_regulator_rdev = regulator_register(&dummy_desc, &config);
if (IS_ERR(dummy_regulator_rdev)) {
ret = PTR_ERR(dummy_regulator_rdev);
pr_err("Failed to register regulator: %d\n", ret);
......
......@@ -105,10 +105,8 @@ static int fixed_voltage_enable(struct regulator_dev *dev)
{
struct fixed_voltage_data *data = rdev_get_drvdata(dev);
if (gpio_is_valid(data->gpio)) {
gpio_set_value_cansleep(data->gpio, data->enable_high);
data->is_enabled = true;
}
return 0;
}
......@@ -117,10 +115,8 @@ static int fixed_voltage_disable(struct regulator_dev *dev)
{
struct fixed_voltage_data *data = rdev_get_drvdata(dev);
if (gpio_is_valid(data->gpio)) {
gpio_set_value_cansleep(data->gpio, !data->enable_high);
data->is_enabled = false;
}
return 0;
}
......@@ -153,7 +149,7 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev,
return data->microvolts;
}
static struct regulator_ops fixed_voltage_ops = {
static struct regulator_ops fixed_voltage_gpio_ops = {
.is_enabled = fixed_voltage_is_enabled,
.enable = fixed_voltage_enable,
.disable = fixed_voltage_disable,
......@@ -162,10 +158,16 @@ static struct regulator_ops fixed_voltage_ops = {
.list_voltage = fixed_voltage_list_voltage,
};
static struct regulator_ops fixed_voltage_ops = {
.get_voltage = fixed_voltage_get_voltage,
.list_voltage = fixed_voltage_list_voltage,
};
static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
{
struct fixed_voltage_config *config;
struct fixed_voltage_data *drvdata;
struct regulator_config cfg = { };
int ret;
if (pdev->dev.of_node)
......@@ -176,7 +178,8 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
if (!config)
return -ENOMEM;
drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL);
drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data),
GFP_KERNEL);
if (drvdata == NULL) {
dev_err(&pdev->dev, "Failed to allocate device data\n");
ret = -ENOMEM;
......@@ -191,7 +194,6 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
}
drvdata->desc.type = REGULATOR_VOLTAGE;
drvdata->desc.owner = THIS_MODULE;
drvdata->desc.ops = &fixed_voltage_ops;
if (config->microvolts)
drvdata->desc.n_voltages = 1;
......@@ -201,6 +203,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
drvdata->startup_delay = config->startup_delay;
if (gpio_is_valid(config->gpio)) {
int gpio_flag;
drvdata->enable_high = config->enable_high;
/* FIXME: Remove below print warning
......@@ -218,39 +221,39 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
dev_warn(&pdev->dev,
"using GPIO 0 for regulator enable control\n");
ret = gpio_request(config->gpio, config->supply_name);
if (ret) {
dev_err(&pdev->dev,
"Could not obtain regulator enable GPIO %d: %d\n",
config->gpio, ret);
goto err_name;
}
/* set output direction without changing state
/*
* set output direction without changing state
* to prevent glitch
*/
drvdata->is_enabled = config->enabled_at_boot;
ret = drvdata->is_enabled ?
config->enable_high : !config->enable_high;
gpio_flag = ret ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
if (config->gpio_is_open_drain)
gpio_flag |= GPIOF_OPEN_DRAIN;
ret = gpio_direction_output(config->gpio, ret);
ret = gpio_request_one(config->gpio, gpio_flag,
config->supply_name);
if (ret) {
dev_err(&pdev->dev,
"Could not configure regulator enable GPIO %d direction: %d\n",
"Could not obtain regulator enable GPIO %d: %d\n",
config->gpio, ret);
goto err_gpio;
goto err_name;
}
drvdata->desc.ops = &fixed_voltage_gpio_ops;
} else {
/* Regulator without GPIO control is considered
* always enabled
*/
drvdata->is_enabled = true;
drvdata->desc.ops = &fixed_voltage_ops;
}
drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
config->init_data, drvdata,
pdev->dev.of_node);
cfg.dev = &pdev->dev;
cfg.init_data = config->init_data;
cfg.driver_data = drvdata;
cfg.of_node = pdev->dev.of_node;
drvdata->dev = regulator_register(&drvdata->desc, &cfg);
if (IS_ERR(drvdata->dev)) {
ret = PTR_ERR(drvdata->dev);
dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
......@@ -270,7 +273,6 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
err_name:
kfree(drvdata->desc.name);
err:
kfree(drvdata);
return ret;
}
......@@ -282,7 +284,6 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
if (gpio_is_valid(drvdata->gpio))
gpio_free(drvdata->gpio);
kfree(drvdata->desc.name);
kfree(drvdata);
return 0;
}
......
......@@ -105,15 +105,15 @@ static int gpio_regulator_set_value(struct regulator_dev *dev,
int min, int max)
{
struct gpio_regulator_data *data = rdev_get_drvdata(dev);
int ptr, target, state;
int ptr, target, state, best_val = INT_MAX;
target = -1;
for (ptr = 0; ptr < data->nr_states; ptr++)
if (data->states[ptr].value >= min &&
if (data->states[ptr].value < best_val &&
data->states[ptr].value >= min &&
data->states[ptr].value <= max)
target = data->states[ptr].gpios;
if (target < 0)
if (best_val == INT_MAX)
return -EINVAL;
for (ptr = 0; ptr < data->nr_gpios; ptr++) {
......@@ -172,9 +172,11 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
{
struct gpio_regulator_config *config = pdev->dev.platform_data;
struct gpio_regulator_data *drvdata;
struct regulator_config cfg = { };
int ptr, ret, state;
drvdata = kzalloc(sizeof(struct gpio_regulator_data), GFP_KERNEL);
drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data),
GFP_KERNEL);
if (drvdata == NULL) {
dev_err(&pdev->dev, "Failed to allocate device data\n");
return -ENOMEM;
......@@ -283,8 +285,11 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
}
drvdata->state = state;
drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev,
config->init_data, drvdata, NULL);
cfg.dev = &pdev->dev;
cfg.init_data = config->init_data;
cfg.driver_data = &drvdata;
drvdata->dev = regulator_register(&drvdata->desc, &cfg);
if (IS_ERR(drvdata->dev)) {
ret = PTR_ERR(drvdata->dev);
dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
......@@ -307,7 +312,6 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev)
err_name:
kfree(drvdata->desc.name);
err:
kfree(drvdata);
return ret;
}
......@@ -326,7 +330,6 @@ static int __devexit gpio_regulator_remove(struct platform_device *pdev)
gpio_free(drvdata->enable_gpio);
kfree(drvdata->desc.name);
kfree(drvdata);
return 0;
}
......
......@@ -112,7 +112,7 @@ static struct regulator_ops isl_fixed_ops = {
.list_voltage = isl6271a_list_fixed_voltage,
};
static struct regulator_desc isl_rd[] = {
static const struct regulator_desc isl_rd[] = {
{
.name = "Core Buck",
.id = 0,
......@@ -140,6 +140,7 @@ static struct regulator_desc isl_rd[] = {
static int __devinit isl6271a_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
{
struct regulator_config config = { };
struct regulator_init_data *init_data = i2c->dev.platform_data;
struct isl_pmic *pmic;
int err, i;
......@@ -147,12 +148,7 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c,
if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -EIO;
if (!init_data) {
dev_err(&i2c->dev, "no platform data supplied\n");
return -EIO;
}
pmic = kzalloc(sizeof(struct isl_pmic), GFP_KERNEL);
pmic = devm_kzalloc(&i2c->dev, sizeof(struct isl_pmic), GFP_KERNEL);
if (!pmic)
return -ENOMEM;
......@@ -161,8 +157,14 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c,
mutex_init(&pmic->mtx);
for (i = 0; i < 3; i++) {
pmic->rdev[i] = regulator_register(&isl_rd[i], &i2c->dev,
init_data, pmic, NULL);
config.dev = &i2c->dev;
if (i == 0)
config.init_data = init_data;
else
config.init_data = 0;
config.driver_data = pmic;
pmic->rdev[i] = regulator_register(&isl_rd[i], &config);
if (IS_ERR(pmic->rdev[i])) {
dev_err(&i2c->dev, "failed to register %s\n", id->name);
err = PTR_ERR(pmic->rdev[i]);
......@@ -177,8 +179,6 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c,
error:
while (--i >= 0)
regulator_unregister(pmic->rdev[i]);
kfree(pmic);
return err;
}
......@@ -189,9 +189,6 @@ static int __devexit isl6271a_remove(struct i2c_client *i2c)
for (i = 0; i < 3; i++)
regulator_unregister(pmic->rdev[i]);
kfree(pmic);
return 0;
}
......
......@@ -124,6 +124,10 @@ static const int *ldo_voltage_map[] = {
static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
{
int ldo = rdev_get_id(dev) - LP3971_LDO1;
if (index > LDO_VOL_MAX_IDX)
return -EINVAL;
return 1000 * LDO_VOL_VALUE_MAP(ldo)[index];
}
......@@ -168,32 +172,15 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev)
return 1000 * LDO_VOL_VALUE_MAP(ldo)[val];
}
static int lp3971_ldo_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV,
unsigned int *selector)
static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev,
unsigned int selector)
{
struct lp3971 *lp3971 = rdev_get_drvdata(dev);
int ldo = rdev_get_id(dev) - LP3971_LDO1;
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const int *vol_map = LDO_VOL_VALUE_MAP(ldo);
u16 val;
if (min_vol < vol_map[LDO_VOL_MIN_IDX] ||
min_vol > vol_map[LDO_VOL_MAX_IDX])
return -EINVAL;
for (val = LDO_VOL_MIN_IDX; val <= LDO_VOL_MAX_IDX; val++)
if (vol_map[val] >= min_vol)
break;
if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol)
return -EINVAL;
*selector = val;
return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo),
LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo),
val << LDO_VOL_CONTR_SHIFT(ldo));
selector << LDO_VOL_CONTR_SHIFT(ldo));
}
static struct regulator_ops lp3971_ldo_ops = {
......@@ -202,11 +189,14 @@ static struct regulator_ops lp3971_ldo_ops = {
.enable = lp3971_ldo_enable,
.disable = lp3971_ldo_disable,
.get_voltage = lp3971_ldo_get_voltage,
.set_voltage = lp3971_ldo_set_voltage,
.set_voltage_sel = lp3971_ldo_set_voltage_sel,
};
static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
{
if (index < BUCK_TARGET_VOL_MIN_IDX || index > BUCK_TARGET_VOL_MAX_IDX)
return -EINVAL;
return 1000 * buck_voltage_map[index];
}
......@@ -259,33 +249,15 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev)
return val;
}
static int lp3971_dcdc_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV,
unsigned int *selector)
static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev,
unsigned int selector)
{
struct lp3971 *lp3971 = rdev_get_drvdata(dev);
int buck = rdev_get_id(dev) - LP3971_DCDC1;
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const int *vol_map = buck_voltage_map;
u16 val;
int ret;
if (min_vol < vol_map[BUCK_TARGET_VOL_MIN_IDX] ||
min_vol > vol_map[BUCK_TARGET_VOL_MAX_IDX])
return -EINVAL;
for (val = BUCK_TARGET_VOL_MIN_IDX; val <= BUCK_TARGET_VOL_MAX_IDX;
val++)
if (vol_map[val] >= min_vol)
break;
if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol)
return -EINVAL;
*selector = val;
ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck),
BUCK_TARGET_VOL_MASK, val);
BUCK_TARGET_VOL_MASK, selector);
if (ret)
return ret;
......@@ -306,10 +278,10 @@ static struct regulator_ops lp3971_dcdc_ops = {
.enable = lp3971_dcdc_enable,
.disable = lp3971_dcdc_disable,
.get_voltage = lp3971_dcdc_get_voltage,
.set_voltage = lp3971_dcdc_set_voltage,
.set_voltage_sel = lp3971_dcdc_set_voltage_sel,
};
static struct regulator_desc regulators[] = {
static const struct regulator_desc regulators[] = {
{
.name = "LDO1",
.id = LP3971_LDO1,
......@@ -449,10 +421,15 @@ static int __devinit setup_regulators(struct lp3971 *lp3971,
/* Instantiate the regulators */
for (i = 0; i < pdata->num_regulators; i++) {
struct regulator_config config = { };
struct lp3971_regulator_subdev *reg = &pdata->regulators[i];
lp3971->rdev[i] = regulator_register(&regulators[reg->id],
lp3971->dev, reg->initdata, lp3971, NULL);
config.dev = lp3971->dev;
config.init_data = reg->initdata;
config.driver_data = lp3971;
lp3971->rdev[i] = regulator_register(&regulators[reg->id],
&config);
if (IS_ERR(lp3971->rdev[i])) {
err = PTR_ERR(lp3971->rdev[i]);
dev_err(lp3971->dev, "regulator init failed: %d\n",
......@@ -545,23 +522,7 @@ static struct i2c_driver lp3971_i2c_driver = {
.id_table = lp3971_i2c_id,
};
static int __init lp3971_module_init(void)
{
int ret;
ret = i2c_add_driver(&lp3971_i2c_driver);
if (ret != 0)
pr_err("Failed to register I2C driver: %d\n", ret);
return ret;
}
module_init(lp3971_module_init);
static void __exit lp3971_module_exit(void)
{
i2c_del_driver(&lp3971_i2c_driver);
}
module_exit(lp3971_module_exit);
module_i2c_driver(lp3971_i2c_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Marek Szyprowski <m.szyprowski@samsung.com>");
......
......@@ -245,6 +245,11 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val)
static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index)
{
int ldo = rdev_get_id(dev) - LP3972_LDO1;
if (index < LP3972_LDO_VOL_MIN_IDX(ldo) ||
index > LP3972_LDO_VOL_MAX_IDX(ldo))
return -EINVAL;
return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index];
}
......@@ -292,34 +297,16 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev)
return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val];
}
static int lp3972_ldo_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV,
unsigned int *selector)
static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev,
unsigned int selector)
{
struct lp3972 *lp3972 = rdev_get_drvdata(dev);
int ldo = rdev_get_id(dev) - LP3972_LDO1;
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const int *vol_map = LP3972_LDO_VOL_VALUE_MAP(ldo);
u16 val;
int shift, ret;
if (min_vol < vol_map[LP3972_LDO_VOL_MIN_IDX(ldo)] ||
min_vol > vol_map[LP3972_LDO_VOL_MAX_IDX(ldo)])
return -EINVAL;
for (val = LP3972_LDO_VOL_MIN_IDX(ldo);
val <= LP3972_LDO_VOL_MAX_IDX(ldo); val++)
if (vol_map[val] >= min_vol)
break;
if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol)
return -EINVAL;
*selector = val;
shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo);
ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo),
LP3972_LDO_VOL_MASK(ldo) << shift, val << shift);
LP3972_LDO_VOL_MASK(ldo) << shift, selector << shift);
if (ret)
return ret;
......@@ -355,12 +342,17 @@ static struct regulator_ops lp3972_ldo_ops = {
.enable = lp3972_ldo_enable,
.disable = lp3972_ldo_disable,
.get_voltage = lp3972_ldo_get_voltage,
.set_voltage = lp3972_ldo_set_voltage,
.set_voltage_sel = lp3972_ldo_set_voltage_sel,
};
static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index)
{
int buck = rdev_get_id(dev) - LP3972_DCDC1;
if (index < LP3972_BUCK_VOL_MIN_IDX(buck) ||
index > LP3972_BUCK_VOL_MAX_IDX(buck))
return -EINVAL;
return 1000 * buck_voltage_map[buck][index];
}
......@@ -419,34 +411,15 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev)
return val;
}
static int lp3972_dcdc_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV,
unsigned int *selector)
static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev,
unsigned int selector)
{
struct lp3972 *lp3972 = rdev_get_drvdata(dev);
int buck = rdev_get_id(dev) - LP3972_DCDC1;
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const int *vol_map = buck_voltage_map[buck];
u16 val;
int ret;
if (min_vol < vol_map[LP3972_BUCK_VOL_MIN_IDX(buck)] ||
min_vol > vol_map[LP3972_BUCK_VOL_MAX_IDX(buck)])
return -EINVAL;
for (val = LP3972_BUCK_VOL_MIN_IDX(buck);
val <= LP3972_BUCK_VOL_MAX_IDX(buck); val++)
if (vol_map[val] >= min_vol)
break;
if (val > LP3972_BUCK_VOL_MAX_IDX(buck) ||
vol_map[val] > max_vol)
return -EINVAL;
*selector = val;
ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck),
LP3972_BUCK_VOL_MASK, val);
LP3972_BUCK_VOL_MASK, selector);
if (ret)
return ret;
......@@ -468,10 +441,10 @@ static struct regulator_ops lp3972_dcdc_ops = {
.enable = lp3972_dcdc_enable,
.disable = lp3972_dcdc_disable,
.get_voltage = lp3972_dcdc_get_voltage,
.set_voltage = lp3972_dcdc_set_voltage,
.set_voltage_sel = lp3972_dcdc_set_voltage_sel,
};
static struct regulator_desc regulators[] = {
static const struct regulator_desc regulators[] = {
{
.name = "LDO1",
.id = LP3972_LDO1,
......@@ -554,9 +527,14 @@ static int __devinit setup_regulators(struct lp3972 *lp3972,
/* Instantiate the regulators */
for (i = 0; i < pdata->num_regulators; i++) {
struct lp3972_regulator_subdev *reg = &pdata->regulators[i];
lp3972->rdev[i] = regulator_register(&regulators[reg->id],
lp3972->dev, reg->initdata, lp3972, NULL);
struct regulator_config config = { };
config.dev = lp3972->dev;
config.init_data = reg->initdata;
config.driver_data = lp3972;
lp3972->rdev[i] = regulator_register(&regulators[reg->id],
&config);
if (IS_ERR(lp3972->rdev[i])) {
err = PTR_ERR(lp3972->rdev[i]);
dev_err(lp3972->dev, "regulator init failed: %d\n",
......
......@@ -161,7 +161,7 @@ static struct regulator_ops max1586_v6_ops = {
.list_voltage = max1586_v6_list,
};
static struct regulator_desc max1586_reg[] = {
static const struct regulator_desc max1586_reg[] = {
{
.name = "Output_V3",
.id = MAX1586_V3,
......@@ -185,21 +185,21 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
{
struct regulator_dev **rdev;
struct max1586_platform_data *pdata = client->dev.platform_data;
struct regulator_config config = { };
struct max1586_data *max1586;
int i, id, ret = -ENOMEM;
max1586 = kzalloc(sizeof(struct max1586_data) +
max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) +
sizeof(struct regulator_dev *) * (MAX1586_V6 + 1),
GFP_KERNEL);
if (!max1586)
goto out;
return -ENOMEM;
max1586->client = client;
if (!pdata->v3_gain) {
ret = -EINVAL;
goto out_unmap;
}
if (!pdata->v3_gain)
return -EINVAL;
max1586->min_uV = MAX1586_V3_MIN_UV / 1000 * pdata->v3_gain / 1000;
max1586->max_uV = MAX1586_V3_MAX_UV / 1000 * pdata->v3_gain / 1000;
......@@ -212,9 +212,12 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
dev_err(&client->dev, "invalid regulator id %d\n", id);
goto err;
}
rdev[i] = regulator_register(&max1586_reg[id], &client->dev,
pdata->subdevs[i].platform_data,
max1586, NULL);
config.dev = &client->dev;
config.init_data = pdata->subdevs[i].platform_data;
config.driver_data = max1586;
rdev[i] = regulator_register(&max1586_reg[id], &config);
if (IS_ERR(rdev[i])) {
ret = PTR_ERR(rdev[i]);
dev_err(&client->dev, "failed to register %s\n",
......@@ -230,9 +233,6 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
err:
while (--i >= 0)
regulator_unregister(rdev[i]);
out_unmap:
kfree(max1586);
out:
return ret;
}
......@@ -244,8 +244,6 @@ static int __devexit max1586_pmic_remove(struct i2c_client *client)
for (i = 0; i <= MAX1586_V6; i++)
if (max1586->rdev[i])
regulator_unregister(max1586->rdev[i]);
kfree(max1586);
return 0;
}
......
......@@ -207,7 +207,7 @@ static struct regulator_ops max8649_dcdc_ops = {
};
static struct regulator_desc dcdc_desc = {
static const struct regulator_desc dcdc_desc = {
.name = "max8649",
.ops = &max8649_dcdc_ops,
.type = REGULATOR_VOLTAGE,
......@@ -225,21 +225,23 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client,
{
struct max8649_platform_data *pdata = client->dev.platform_data;
struct max8649_regulator_info *info = NULL;
struct regulator_config config = { };
unsigned int val;
unsigned char data;
int ret;
info = kzalloc(sizeof(struct max8649_regulator_info), GFP_KERNEL);
info = devm_kzalloc(&client->dev, sizeof(struct max8649_regulator_info),
GFP_KERNEL);
if (!info) {
dev_err(&client->dev, "No enough memory\n");
return -ENOMEM;
}
info->regmap = regmap_init_i2c(client, &max8649_regmap_config);
info->regmap = devm_regmap_init_i2c(client, &max8649_regmap_config);
if (IS_ERR(info->regmap)) {
ret = PTR_ERR(info->regmap);
dev_err(&client->dev, "Failed to allocate register map: %d\n", ret);
goto fail;
return ret;
}
info->dev = &client->dev;
......@@ -267,7 +269,7 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client,
if (ret != 0) {
dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n",
ret);
goto out;
return ret;
}
dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", val);
......@@ -297,22 +299,18 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client,
MAX8649_RAMP_DOWN);
}
info->regulator = regulator_register(&dcdc_desc, &client->dev,
pdata->regulator, info, NULL);
config.dev = &client->dev;
config.init_data = pdata->regulator;
config.driver_data = info;
info->regulator = regulator_register(&dcdc_desc, &config);
if (IS_ERR(info->regulator)) {
dev_err(info->dev, "failed to register regulator %s\n",
dcdc_desc.name);
ret = PTR_ERR(info->regulator);
goto out;
return PTR_ERR(info->regulator);
}
dev_info(info->dev, "Max8649 regulator device is detected.\n");
return 0;
out:
regmap_exit(info->regmap);
fail:
kfree(info);
return ret;
}
static int __devexit max8649_regulator_remove(struct i2c_client *client)
......@@ -322,8 +320,6 @@ static int __devexit max8649_regulator_remove(struct i2c_client *client)
if (info) {
if (info->regulator)
regulator_unregister(info->regulator);
regmap_exit(info->regmap);
kfree(info);
}
return 0;
......
......@@ -313,7 +313,7 @@ static struct regulator_ops max8660_ldo67_ops = {
.set_voltage = max8660_ldo67_set,
};
static struct regulator_desc max8660_reg[] = {
static const struct regulator_desc max8660_reg[] = {
{
.name = "V3(DCDC)",
.id = MAX8660_V3,
......@@ -361,21 +361,20 @@ static int __devinit max8660_probe(struct i2c_client *client,
{
struct regulator_dev **rdev;
struct max8660_platform_data *pdata = client->dev.platform_data;
struct regulator_config config = { };
struct max8660 *max8660;
int boot_on, i, id, ret = -EINVAL;
if (pdata->num_subdevs > MAX8660_V_END) {
dev_err(&client->dev, "Too many regulators found!\n");
goto out;
return -EINVAL;
}
max8660 = kzalloc(sizeof(struct max8660) +
sizeof(struct regulator_dev *) * MAX8660_V_END,
GFP_KERNEL);
if (!max8660) {
ret = -ENOMEM;
goto out;
}
if (!max8660)
return -ENOMEM;
max8660->client = client;
rdev = max8660->rdev;
......@@ -404,7 +403,7 @@ static int __devinit max8660_probe(struct i2c_client *client,
for (i = 0; i < pdata->num_subdevs; i++) {
if (!pdata->subdevs[i].platform_data)
goto err_free;
goto err_out;
boot_on = pdata->subdevs[i].platform_data->constraints.boot_on;
......@@ -430,7 +429,7 @@ static int __devinit max8660_probe(struct i2c_client *client,
case MAX8660_V7:
if (!strcmp(i2c_id->name, "max8661")) {
dev_err(&client->dev, "Regulator not on this chip!\n");
goto err_free;
goto err_out;
}
if (boot_on)
......@@ -440,7 +439,7 @@ static int __devinit max8660_probe(struct i2c_client *client,
default:
dev_err(&client->dev, "invalid regulator %s\n",
pdata->subdevs[i].name);
goto err_free;
goto err_out;
}
}
......@@ -449,9 +448,11 @@ static int __devinit max8660_probe(struct i2c_client *client,
id = pdata->subdevs[i].id;
rdev[i] = regulator_register(&max8660_reg[id], &client->dev,
pdata->subdevs[i].platform_data,
max8660, NULL);
config.dev = &client->dev;
config.init_data = pdata->subdevs[i].platform_data;
config.driver_data = max8660;
rdev[i] = regulator_register(&max8660_reg[id], &config);
if (IS_ERR(rdev[i])) {
ret = PTR_ERR(rdev[i]);
dev_err(&client->dev, "failed to register %s\n",
......@@ -461,15 +462,12 @@ static int __devinit max8660_probe(struct i2c_client *client,
}
i2c_set_clientdata(client, max8660);
dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n");
return 0;
err_unregister:
while (--i >= 0)
regulator_unregister(rdev[i]);
err_free:
kfree(max8660);
out:
err_out:
return ret;
}
......@@ -481,8 +479,6 @@ static int __devexit max8660_remove(struct i2c_client *client)
for (i = 0; i < MAX8660_V_END; i++)
if (max8660->rdev[i])
regulator_unregister(max8660->rdev[i]);
kfree(max8660);
return 0;
}
......
......@@ -42,8 +42,6 @@ struct max8925_regulator_info {
int max_uV;
int step_uV;
int vol_reg;
int vol_shift;
int vol_nbits;
int enable_reg;
};
......@@ -75,8 +73,7 @@ static int max8925_set_voltage(struct regulator_dev *rdev,
}
data = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
*selector = data;
data <<= info->vol_shift;
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
mask = rdev->desc->n_voltages - 1;
return max8925_set_bits(info->i2c, info->vol_reg, mask, data);
}
......@@ -90,8 +87,8 @@ static int max8925_get_voltage(struct regulator_dev *rdev)
ret = max8925_reg_read(info->i2c, info->vol_reg);
if (ret < 0)
return ret;
mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
data = (ret & mask) >> info->vol_shift;
mask = rdev->desc->n_voltages - 1;
data = ret & mask;
return max8925_list_voltage(rdev, data);
}
......@@ -163,6 +160,7 @@ static int max8925_set_dvm_disable(struct regulator_dev *rdev)
}
static struct regulator_ops max8925_regulator_sdv_ops = {
.list_voltage = max8925_list_voltage,
.set_voltage = max8925_set_voltage,
.get_voltage = max8925_get_voltage,
.enable = max8925_enable,
......@@ -174,6 +172,7 @@ static struct regulator_ops max8925_regulator_sdv_ops = {
};
static struct regulator_ops max8925_regulator_ldo_ops = {
.list_voltage = max8925_list_voltage,
.set_voltage = max8925_set_voltage,
.get_voltage = max8925_get_voltage,
.enable = max8925_enable,
......@@ -189,13 +188,12 @@ static struct regulator_ops max8925_regulator_ldo_ops = {
.type = REGULATOR_VOLTAGE, \
.id = MAX8925_ID_SD##_id, \
.owner = THIS_MODULE, \
.n_voltages = 64, \
}, \
.min_uV = min * 1000, \
.max_uV = max * 1000, \
.step_uV = step * 1000, \
.vol_reg = MAX8925_SDV##_id, \
.vol_shift = 0, \
.vol_nbits = 6, \
.enable_reg = MAX8925_SDCTL##_id, \
}
......@@ -207,13 +205,12 @@ static struct regulator_ops max8925_regulator_ldo_ops = {
.type = REGULATOR_VOLTAGE, \
.id = MAX8925_ID_LDO##_id, \
.owner = THIS_MODULE, \
.n_voltages = 64, \
}, \
.min_uV = min * 1000, \
.max_uV = max * 1000, \
.step_uV = step * 1000, \
.vol_reg = MAX8925_LDOVOUT##_id, \
.vol_shift = 0, \
.vol_nbits = 6, \
.enable_reg = MAX8925_LDOCTL##_id, \
}
......@@ -261,6 +258,7 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
{
struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent);
struct max8925_platform_data *pdata = chip->dev->platform_data;
struct regulator_config config = { };
struct max8925_regulator_info *ri;
struct regulator_dev *rdev;
......@@ -272,8 +270,11 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev)
ri->i2c = chip->i2c;
ri->chip = chip;
rdev = regulator_register(&ri->desc, &pdev->dev,
pdata->regulator[pdev->id], ri, NULL);
config.dev = &pdev->dev;
config.init_data = pdata->regulator[pdev->id];
config.driver_data = ri;
rdev = regulator_register(&ri->desc, &config);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
ri->desc.name);
......
......@@ -130,11 +130,10 @@ static int max8952_get_voltage(struct regulator_dev *rdev)
return max8952_voltage(max8952, vid);
}
static int max8952_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV, unsigned *selector)
static int max8952_set_voltage_sel(struct regulator_dev *rdev,
unsigned selector)
{
struct max8952_data *max8952 = rdev_get_drvdata(rdev);
s8 vid = -1, i;
if (!gpio_is_valid(max8952->pdata->gpio_vid0) ||
!gpio_is_valid(max8952->pdata->gpio_vid1)) {
......@@ -142,23 +141,10 @@ static int max8952_set_voltage(struct regulator_dev *rdev,
return -EPERM;
}
for (i = 0; i < MAX8952_NUM_DVS_MODE; i++) {
int volt = max8952_voltage(max8952, i);
/* Set the voltage as low as possible within the range */
if (volt <= max_uV && volt >= min_uV)
if (vid == -1 || max8952_voltage(max8952, vid) > volt)
vid = i;
}
if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) {
max8952->vid0 = (vid % 2 == 1);
max8952->vid1 = (((vid >> 1) % 2) == 1);
*selector = vid;
max8952->vid0 = selector & 0x1;
max8952->vid1 = (selector >> 1) & 0x1;
gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0);
gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1);
} else
return -EINVAL;
return 0;
}
......@@ -169,11 +155,11 @@ static struct regulator_ops max8952_ops = {
.enable = max8952_enable,
.disable = max8952_disable,
.get_voltage = max8952_get_voltage,
.set_voltage = max8952_set_voltage,
.set_voltage_sel = max8952_set_voltage_sel,
.set_suspend_disable = max8952_disable,
};
static struct regulator_desc regulator = {
static const struct regulator_desc regulator = {
.name = "MAX8952_VOUT",
.id = 0,
.n_voltages = MAX8952_NUM_DVS_MODE,
......@@ -187,6 +173,7 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
{
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct max8952_platform_data *pdata = client->dev.platform_data;
struct regulator_config config = { };
struct max8952_data *max8952;
int ret = 0, err = 0;
......@@ -207,8 +194,11 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
max8952->dev = &client->dev;
max8952->pdata = pdata;
max8952->rdev = regulator_register(&regulator, max8952->dev,
&pdata->reg_data, max8952, NULL);
config.dev = max8952->dev;
config.init_data = &pdata->reg_data;
config.driver_data = max8952;
max8952->rdev = regulator_register(&regulator, &config);
if (IS_ERR(max8952->rdev)) {
ret = PTR_ERR(max8952->rdev);
......@@ -217,8 +207,8 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
}
max8952->en = !!(pdata->reg_data.constraints.boot_on);
max8952->vid0 = (pdata->default_mode % 2) == 1;
max8952->vid1 = ((pdata->default_mode >> 1) % 2) == 1;
max8952->vid0 = pdata->default_mode & 0x1;
max8952->vid1 = (pdata->default_mode >> 1) & 0x1;
if (gpio_is_valid(pdata->gpio_en)) {
if (!gpio_request(pdata->gpio_en, "MAX8952 EN"))
......@@ -241,13 +231,13 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client,
gpio_is_valid(pdata->gpio_vid1)) {
if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0"))
gpio_direction_output(pdata->gpio_vid0,
(pdata->default_mode) % 2);
(pdata->default_mode) & 0x1);
else
err = 1;
if (!gpio_request(pdata->gpio_vid1, "MAX8952 VID1"))
gpio_direction_output(pdata->gpio_vid1,
(pdata->default_mode >> 1) % 2);
(pdata->default_mode >> 1) & 0x1);
else {
if (!err)
gpio_free(pdata->gpio_vid0);
......
......@@ -68,29 +68,28 @@ struct voltage_map_desc {
int min;
int max;
int step;
unsigned int n_bits;
};
/* Voltage maps in mV */
static const struct voltage_map_desc ldo_voltage_map_desc = {
.min = 800, .max = 3950, .step = 50, .n_bits = 6,
.min = 800, .max = 3950, .step = 50,
}; /* LDO1 ~ 18, 21 all */
static const struct voltage_map_desc buck1245_voltage_map_desc = {
.min = 650, .max = 2225, .step = 25, .n_bits = 6,
.min = 650, .max = 2225, .step = 25,
}; /* Buck1, 2, 4, 5 */
static const struct voltage_map_desc buck37_voltage_map_desc = {
.min = 750, .max = 3900, .step = 50, .n_bits = 6,
.min = 750, .max = 3900, .step = 50,
}; /* Buck3, 7 */
/* current map in mA */
static const struct voltage_map_desc charger_current_map_desc = {
.min = 200, .max = 950, .step = 50, .n_bits = 4,
.min = 200, .max = 950, .step = 50,
};
static const struct voltage_map_desc topoff_current_map_desc = {
.min = 50, .max = 200, .step = 10, .n_bits = 4,
.min = 50, .max = 200, .step = 10,
};
static const struct voltage_map_desc *reg_voltage_map[] = {
......@@ -320,6 +319,7 @@ static int max8997_reg_disable(struct regulator_dev *rdev)
static int max8997_get_voltage_register(struct regulator_dev *rdev,
int *_reg, int *_shift, int *_mask)
{
struct max8997_data *max8997 = rdev_get_drvdata(rdev);
int rid = rdev_get_id(rdev);
int reg, shift = 0, mask = 0x3f;
......@@ -329,9 +329,13 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev,
break;
case MAX8997_BUCK1:
reg = MAX8997_REG_BUCK1DVS1;
if (max8997->buck1_gpiodvs)
reg += max8997->buck125_gpioindex;
break;
case MAX8997_BUCK2:
reg = MAX8997_REG_BUCK2DVS1;
if (max8997->buck2_gpiodvs)
reg += max8997->buck125_gpioindex;
break;
case MAX8997_BUCK3:
reg = MAX8997_REG_BUCK3DVS;
......@@ -341,6 +345,8 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev,
break;
case MAX8997_BUCK5:
reg = MAX8997_REG_BUCK5DVS1;
if (max8997->buck5_gpiodvs)
reg += max8997->buck125_gpioindex;
break;
case MAX8997_BUCK7:
reg = MAX8997_REG_BUCK7DVS;
......@@ -381,18 +387,12 @@ static int max8997_get_voltage(struct regulator_dev *rdev)
struct max8997_data *max8997 = rdev_get_drvdata(rdev);
struct i2c_client *i2c = max8997->iodev->i2c;
int reg, shift, mask, ret;
int rid = rdev_get_id(rdev);
u8 val;
ret = max8997_get_voltage_register(rdev, &reg, &shift, &mask);
if (ret)
return ret;
if ((rid == MAX8997_BUCK1 && max8997->buck1_gpiodvs) ||
(rid == MAX8997_BUCK2 && max8997->buck2_gpiodvs) ||
(rid == MAX8997_BUCK5 && max8997->buck5_gpiodvs))
reg += max8997->buck125_gpioindex;
ret = max8997_read_reg(i2c, reg, &val);
if (ret)
return ret;
......@@ -415,7 +415,7 @@ static inline int max8997_get_voltage_proper_val(
const struct voltage_map_desc *desc,
int min_vol, int max_vol)
{
int i = 0;
int i;
if (desc == NULL)
return -EINVAL;
......@@ -423,14 +423,12 @@ static inline int max8997_get_voltage_proper_val(
if (max_vol < desc->min || min_vol > desc->max)
return -EINVAL;
while (desc->min + desc->step * i < min_vol &&
desc->min + desc->step * i < desc->max)
i++;
if (min_vol < desc->min)
min_vol = desc->min;
if (desc->min + desc->step * i > max_vol)
return -EINVAL;
i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
if (i >= (1 << desc->n_bits))
if (desc->min + desc->step * i > max_vol)
return -EINVAL;
return i;
......@@ -854,109 +852,65 @@ static struct regulator_ops max8997_charger_fixedstate_ops = {
.set_current_limit = max8997_set_voltage_ldobuck_wrap,
};
#define regulator_desc_ldo(num) { \
.name = "LDO"#num, \
.id = MAX8997_LDO##num, \
.ops = &max8997_ldo_ops, \
#define MAX8997_VOLTAGE_REGULATOR(_name, _ops) {\
.name = #_name, \
.id = MAX8997_##_name, \
.ops = &_ops, \
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
}
#define regulator_desc_buck(num) { \
.name = "BUCK"#num, \
.id = MAX8997_BUCK##num, \
.ops = &max8997_buck_ops, \
.type = REGULATOR_VOLTAGE, \
#define MAX8997_CURRENT_REGULATOR(_name, _ops) {\
.name = #_name, \
.id = MAX8997_##_name, \
.ops = &_ops, \
.type = REGULATOR_CURRENT, \
.owner = THIS_MODULE, \
}
static struct regulator_desc regulators[] = {
regulator_desc_ldo(1),
regulator_desc_ldo(2),
regulator_desc_ldo(3),
regulator_desc_ldo(4),
regulator_desc_ldo(5),
regulator_desc_ldo(6),
regulator_desc_ldo(7),
regulator_desc_ldo(8),
regulator_desc_ldo(9),
regulator_desc_ldo(10),
regulator_desc_ldo(11),
regulator_desc_ldo(12),
regulator_desc_ldo(13),
regulator_desc_ldo(14),
regulator_desc_ldo(15),
regulator_desc_ldo(16),
regulator_desc_ldo(17),
regulator_desc_ldo(18),
regulator_desc_ldo(21),
regulator_desc_buck(1),
regulator_desc_buck(2),
regulator_desc_buck(3),
regulator_desc_buck(4),
regulator_desc_buck(5),
{
.name = "BUCK6",
.id = MAX8997_BUCK6,
.ops = &max8997_fixedvolt_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
},
regulator_desc_buck(7),
{
.name = "EN32KHz_AP",
.id = MAX8997_EN32KHZ_AP,
.ops = &max8997_fixedvolt_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
}, {
.name = "EN32KHz_CP",
.id = MAX8997_EN32KHZ_CP,
.ops = &max8997_fixedvolt_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
}, {
.name = "ENVICHG",
.id = MAX8997_ENVICHG,
.ops = &max8997_fixedvolt_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
}, {
.name = "ESAFEOUT1",
.id = MAX8997_ESAFEOUT1,
.ops = &max8997_safeout_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
}, {
.name = "ESAFEOUT2",
.id = MAX8997_ESAFEOUT2,
.ops = &max8997_safeout_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
}, {
.name = "CHARGER_CV",
.id = MAX8997_CHARGER_CV,
.ops = &max8997_fixedstate_ops,
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
}, {
.name = "CHARGER",
.id = MAX8997_CHARGER,
.ops = &max8997_charger_ops,
.type = REGULATOR_CURRENT,
.owner = THIS_MODULE,
}, {
.name = "CHARGER_TOPOFF",
.id = MAX8997_CHARGER_TOPOFF,
.ops = &max8997_charger_fixedstate_ops,
.type = REGULATOR_CURRENT,
.owner = THIS_MODULE,
},
MAX8997_VOLTAGE_REGULATOR(LDO1, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO2, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO3, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO4, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO5, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO6, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO7, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO8, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO9, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO10, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO11, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO12, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO13, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO14, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO15, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO16, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO17, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO18, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(LDO21, max8997_ldo_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK1, max8997_buck_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK2, max8997_buck_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK3, max8997_buck_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK4, max8997_buck_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK5, max8997_buck_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK6, max8997_fixedvolt_ops),
MAX8997_VOLTAGE_REGULATOR(BUCK7, max8997_buck_ops),
MAX8997_VOLTAGE_REGULATOR(EN32KHZ_AP, max8997_fixedvolt_ops),
MAX8997_VOLTAGE_REGULATOR(EN32KHZ_CP, max8997_fixedvolt_ops),
MAX8997_VOLTAGE_REGULATOR(ENVICHG, max8997_fixedvolt_ops),
MAX8997_VOLTAGE_REGULATOR(ESAFEOUT1, max8997_safeout_ops),
MAX8997_VOLTAGE_REGULATOR(ESAFEOUT2, max8997_safeout_ops),
MAX8997_VOLTAGE_REGULATOR(CHARGER_CV, max8997_fixedstate_ops),
MAX8997_CURRENT_REGULATOR(CHARGER, max8997_charger_ops),
MAX8997_CURRENT_REGULATOR(CHARGER_TOPOFF,
max8997_charger_fixedstate_ops),
};
static __devinit int max8997_pmic_probe(struct platform_device *pdev)
{
struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev);
struct regulator_config config = { };
struct regulator_dev **rdev;
struct max8997_data *max8997;
struct i2c_client *i2c;
......@@ -1140,8 +1094,11 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
else if (id == MAX8997_CHARGER_CV)
regulators[id].n_voltages = 16;
rdev[i] = regulator_register(&regulators[id], max8997->dev,
pdata->regulators[i].initdata, max8997, NULL);
config.dev = max8997->dev;
config.init_data = pdata->regulators[i].initdata;
config.driver_data = max8997;
rdev[i] = regulator_register(&regulators[id], &config);
if (IS_ERR(rdev[i])) {
ret = PTR_ERR(rdev[i]);
dev_err(max8997->dev, "regulator init failed for %d\n",
......
......@@ -277,7 +277,7 @@ static int max8998_get_voltage_register(struct regulator_dev *rdev,
return 0;
}
static int max8998_get_voltage(struct regulator_dev *rdev)
static int max8998_get_voltage_sel(struct regulator_dev *rdev)
{
struct max8998_data *max8998 = rdev_get_drvdata(rdev);
struct i2c_client *i2c = max8998->iodev->i2c;
......@@ -295,7 +295,7 @@ static int max8998_get_voltage(struct regulator_dev *rdev)
val >>= shift;
val &= mask;
return max8998_list_voltage(rdev, val);
return val;
}
static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
......@@ -306,8 +306,7 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
const struct voltage_map_desc *desc;
int ldo = rdev_get_id(rdev);
int reg, shift = 0, mask, ret;
int i = 0;
int reg, shift = 0, mask, ret, i;
if (ldo >= ARRAY_SIZE(ldo_voltage_map))
return -EINVAL;
......@@ -319,9 +318,10 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev,
if (max_vol < desc->min || min_vol > desc->max)
return -EINVAL;
while (desc->min + desc->step*i < min_vol &&
desc->min + desc->step*i < desc->max)
i++;
if (min_vol < desc->min)
min_vol = desc->min;
i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
if (desc->min + desc->step*i > max_vol)
return -EINVAL;
......@@ -359,8 +359,7 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
const struct voltage_map_desc *desc;
int buck = rdev_get_id(rdev);
int reg, shift = 0, mask, ret;
int difference = 0, i = 0, j = 0, previous_vol = 0;
u8 val = 0;
int i, j, previous_sel;
static u8 buck1_last_val;
if (buck >= ARRAY_SIZE(ldo_voltage_map))
......@@ -374,9 +373,10 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
if (max_vol < desc->min || min_vol > desc->max)
return -EINVAL;
while (desc->min + desc->step*i < min_vol &&
desc->min + desc->step*i < desc->max)
i++;
if (min_vol < desc->min)
min_vol = desc->min;
i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
if (desc->min + desc->step*i > max_vol)
return -EINVAL;
......@@ -387,13 +387,14 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
if (ret)
return ret;
previous_vol = max8998_get_voltage(rdev);
previous_sel = max8998_get_voltage_sel(rdev);
/* Check if voltage needs to be changed */
/* if previous_voltage equal new voltage, return */
if (previous_vol == max8998_list_voltage(rdev, i)) {
if (previous_sel == i) {
dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n",
previous_vol, max8998_list_voltage(rdev, i));
max8998_list_voltage(rdev, previous_sel),
max8998_list_voltage(rdev, i));
return ret;
}
......@@ -482,19 +483,40 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
break;
}
return ret;
}
static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
unsigned int old_selector,
unsigned int new_selector)
{
struct max8998_data *max8998 = rdev_get_drvdata(rdev);
struct i2c_client *i2c = max8998->iodev->i2c;
const struct voltage_map_desc *desc;
int buck = rdev_get_id(rdev);
u8 val = 0;
int difference, ret;
if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4)
return -EINVAL;
desc = ldo_voltage_map[buck];
/* Voltage stabilization */
max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
if (ret)
return ret;
/* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */
/* MAX8998 has ENRAMP bit implemented, so test it*/
if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP))
return ret;
return 0;
difference = desc->min + desc->step*i - previous_vol/1000;
difference = (new_selector - old_selector) * desc->step;
if (difference > 0)
udelay(difference / ((val & 0x0f) + 1));
return difference / ((val & 0x0f) + 1);
return ret;
return 0;
}
static struct regulator_ops max8998_ldo_ops = {
......@@ -502,7 +524,7 @@ static struct regulator_ops max8998_ldo_ops = {
.is_enabled = max8998_ldo_is_enabled,
.enable = max8998_ldo_enable,
.disable = max8998_ldo_disable,
.get_voltage = max8998_get_voltage,
.get_voltage_sel = max8998_get_voltage_sel,
.set_voltage = max8998_set_voltage_ldo,
.set_suspend_enable = max8998_ldo_enable,
.set_suspend_disable = max8998_ldo_disable,
......@@ -513,8 +535,9 @@ static struct regulator_ops max8998_buck_ops = {
.is_enabled = max8998_ldo_is_enabled,
.enable = max8998_ldo_enable,
.disable = max8998_ldo_disable,
.get_voltage = max8998_get_voltage,
.get_voltage_sel = max8998_get_voltage_sel,
.set_voltage = max8998_set_voltage_buck,
.set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
.set_suspend_enable = max8998_ldo_enable,
.set_suspend_disable = max8998_ldo_disable,
};
......@@ -685,6 +708,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
{
struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
struct regulator_config config = { };
struct regulator_dev **rdev;
struct max8998_data *max8998;
struct i2c_client *i2c;
......@@ -840,8 +864,12 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
int count = (desc->max - desc->min) / desc->step + 1;
regulators[index].n_voltages = count;
}
rdev[i] = regulator_register(&regulators[index], max8998->dev,
pdata->regulators[i].initdata, max8998, NULL);
config.dev = max8998->dev;
config.init_data = pdata->regulators[i].initdata;
config.driver_data = max8998;
rdev[i] = regulator_register(&regulators[index], &config);
if (IS_ERR(rdev[i])) {
ret = PTR_ERR(rdev[i]);
dev_err(max8998->dev, "regulator init failed\n");
......
......@@ -340,6 +340,7 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
struct mc13xxx_regulator_platform_data *pdata =
dev_get_platdata(&pdev->dev);
struct mc13xxx_regulator_init_data *init_data;
struct regulator_config config = { };
int i, ret;
dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id);
......@@ -357,11 +358,16 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
priv->mc13xxx = mc13783;
for (i = 0; i < pdata->num_regulators; i++) {
struct regulator_desc *desc;
init_data = &pdata->regulators[i];
priv->regulators[i] = regulator_register(
&mc13783_regulators[init_data->id].desc,
&pdev->dev, init_data->init_data, priv, NULL);
desc = &mc13783_regulators[init_data->id].desc;
config.dev = &pdev->dev;
config.init_data = init_data->init_data;
config.driver_data = priv;
priv->regulators[i] = regulator_register(desc, &config);
if (IS_ERR(priv->regulators[i])) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
mc13783_regulators[i].desc.name);
......
......@@ -428,24 +428,15 @@ static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
return val;
}
static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV, unsigned *selector)
static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned selector)
{
struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
int hi, value, mask, id = rdev_get_id(rdev);
u32 valread;
int ret;
dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
__func__, id, min_uV, max_uV);
/* Find the best index */
value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
if (value < 0)
return value;
value = mc13892_regulators[id].voltages[value];
value = mc13892_regulators[id].voltages[selector];
mc13xxx_lock(priv->mc13xxx);
ret = mc13xxx_reg_read(priv->mc13xxx,
......@@ -480,7 +471,7 @@ static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev,
static struct regulator_ops mc13892_sw_regulator_ops = {
.is_enabled = mc13xxx_sw_regulator_is_enabled,
.list_voltage = mc13xxx_regulator_list_voltage,
.set_voltage = mc13892_sw_regulator_set_voltage,
.set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
.get_voltage = mc13892_sw_regulator_get_voltage,
};
......@@ -528,6 +519,7 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
struct mc13xxx_regulator_platform_data *pdata =
dev_get_platdata(&pdev->dev);
struct mc13xxx_regulator_init_data *mc13xxx_data;
struct regulator_config config = { };
int i, ret;
int num_regulators = 0;
u32 val;
......@@ -597,9 +589,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
}
desc = &mc13892_regulators[id].desc;
priv->regulators[i] = regulator_register(
desc, &pdev->dev, init_data, priv, node);
config.dev = &pdev->dev;
config.init_data = init_data;
config.driver_data = priv;
config.of_node = node;
priv->regulators[i] = regulator_register(desc, &config);
if (IS_ERR(priv->regulators[i])) {
dev_err(&pdev->dev, "failed to register regulator %s\n",
mc13892_regulators[i].desc.name);
......
......@@ -94,62 +94,18 @@ int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
}
EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage);
int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
int reg_id = rdev_get_id(rdev);
int i;
int bestmatch;
int bestindex;
/*
* Locate the minimum voltage fitting the criteria on
* this regulator. The switchable voltages are not
* in strict falling order so we need to check them
* all for the best match.
*/
bestmatch = INT_MAX;
bestindex = -1;
for (i = 0; i < mc13xxx_regulators[reg_id].desc.n_voltages; i++) {
if (mc13xxx_regulators[reg_id].voltages[i] >= min_uV &&
mc13xxx_regulators[reg_id].voltages[i] < bestmatch) {
bestmatch = mc13xxx_regulators[reg_id].voltages[i];
bestindex = i;
}
}
if (bestindex < 0 || bestmatch > max_uV) {
dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
min_uV, max_uV);
return -EINVAL;
}
return bestindex;
}
EXPORT_SYMBOL_GPL(mc13xxx_get_best_voltage_index);
static int mc13xxx_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
int max_uV, unsigned *selector)
static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned selector)
{
struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
int value, id = rdev_get_id(rdev);
int id = rdev_get_id(rdev);
int ret;
dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
__func__, id, min_uV, max_uV);
/* Find the best index */
value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
if (value < 0)
return value;
mc13xxx_lock(priv->mc13xxx);
ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg,
mc13xxx_regulators[id].vsel_mask,
value << mc13xxx_regulators[id].vsel_shift);
selector << mc13xxx_regulators[id].vsel_shift);
mc13xxx_unlock(priv->mc13xxx);
return ret;
......@@ -187,7 +143,7 @@ struct regulator_ops mc13xxx_regulator_ops = {
.disable = mc13xxx_regulator_disable,
.is_enabled = mc13xxx_regulator_is_enabled,
.list_voltage = mc13xxx_regulator_list_voltage,
.set_voltage = mc13xxx_regulator_set_voltage,
.set_voltage_sel = mc13xxx_regulator_set_voltage_sel,
.get_voltage = mc13xxx_regulator_get_voltage,
};
EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops);
......
......@@ -35,8 +35,6 @@ struct mc13xxx_regulator_priv {
extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev);
extern int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
int min_uV, int max_uV);
extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
unsigned selector);
extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
......
......@@ -150,57 +150,33 @@ static struct pcap_regulator vreg_table[] = {
VREG_INFO(SW2S, PCAP_REG_LOWPWR, NA, 20, NA, NA), */
};
static int pcap_regulator_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV,
unsigned *selector)
static int pcap_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned selector)
{
struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)];
void *pcap = rdev_get_drvdata(rdev);
int uV;
u8 i;
/* the regulator doesn't support voltage switching */
if (vreg->n_voltages == 1)
return -EINVAL;
for (i = 0; i < vreg->n_voltages; i++) {
/* For V1 the first is not the best match */
if (i == 0 && rdev_get_id(rdev) == V1)
i = 1;
else if (i + 1 == vreg->n_voltages && rdev_get_id(rdev) == V1)
i = 0;
uV = vreg->voltage_table[i] * 1000;
if (min_uV <= uV && uV <= max_uV) {
*selector = i;
return ezx_pcap_set_bits(pcap, vreg->reg,
(vreg->n_voltages - 1) << vreg->index,
i << vreg->index);
}
if (i == 0 && rdev_get_id(rdev) == V1)
i = vreg->n_voltages - 1;
}
/* the requested voltage range is not supported by this regulator */
return -EINVAL;
selector << vreg->index);
}
static int pcap_regulator_get_voltage(struct regulator_dev *rdev)
static int pcap_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)];
void *pcap = rdev_get_drvdata(rdev);
u32 tmp;
int mV;
if (vreg->n_voltages == 1)
return vreg->voltage_table[0] * 1000;
return 0;
ezx_pcap_read(pcap, vreg->reg, &tmp);
tmp = ((tmp >> vreg->index) & (vreg->n_voltages - 1));
mV = vreg->voltage_table[tmp];
return mV * 1000;
return tmp;
}
static int pcap_regulator_enable(struct regulator_dev *rdev)
......@@ -248,8 +224,8 @@ static int pcap_regulator_list_voltage(struct regulator_dev *rdev,
static struct regulator_ops pcap_regulator_ops = {
.list_voltage = pcap_regulator_list_voltage,
.set_voltage = pcap_regulator_set_voltage,
.get_voltage = pcap_regulator_get_voltage,
.set_voltage_sel = pcap_regulator_set_voltage_sel,
.get_voltage_sel = pcap_regulator_get_voltage_sel,
.enable = pcap_regulator_enable,
.disable = pcap_regulator_disable,
.is_enabled = pcap_regulator_is_enabled,
......@@ -265,7 +241,7 @@ static struct regulator_ops pcap_regulator_ops = {
.owner = THIS_MODULE, \
}
static struct regulator_desc pcap_regulators[] = {
static const struct regulator_desc pcap_regulators[] = {
VREG(V1), VREG(V2), VREG(V3), VREG(V4), VREG(V5), VREG(V6), VREG(V7),
VREG(V8), VREG(V9), VREG(V10), VREG(VAUX1), VREG(VAUX2), VREG(VAUX3),
VREG(VAUX4), VREG(VSIM), VREG(VSIM2), VREG(VVIB), VREG(SW1), VREG(SW2),
......@@ -275,9 +251,13 @@ static int __devinit pcap_regulator_probe(struct platform_device *pdev)
{
struct regulator_dev *rdev;
void *pcap = dev_get_drvdata(pdev->dev.parent);
struct regulator_config config = { };
config.dev = &pdev->dev;
config.init_data = pdev->dev.platform_data;
config.driver_data = pcap;
rdev = regulator_register(&pcap_regulators[pdev->id], &pdev->dev,
pdev->dev.platform_data, pcap, NULL);
rdev = regulator_register(&pcap_regulators[pdev->id], &config);
if (IS_ERR(rdev))
return PTR_ERR(rdev);
......
......@@ -27,32 +27,22 @@
#define PCF50633_REGULATOR(_name, _id, _n) \
{ \
.name = _name, \
.id = _id, \
.id = PCF50633_REGULATOR_##_id, \
.ops = &pcf50633_regulator_ops, \
.n_voltages = _n, \
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
.vsel_reg = PCF50633_REG_##_id##OUT, \
.vsel_mask = 0xff, \
.enable_reg = PCF50633_REG_##_id##OUT + 1, \
.enable_mask = PCF50633_REGULATOR_ON, \
}
static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
[PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
[PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
[PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
[PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
[PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
[PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
[PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
[PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
[PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
[PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
[PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
};
/* Bits from voltage value */
static u8 auto_voltage_bits(unsigned int millivolts)
{
if (millivolts < 1800)
return 0;
return 0x2f;
if (millivolts > 3800)
return 0xff;
......@@ -87,6 +77,9 @@ static u8 ldo_voltage_bits(unsigned int millivolts)
/* Obtain voltage value from bits */
static unsigned int auto_voltage_value(u8 bits)
{
/* AUTOOUT: 00000000 to 00101110 are reserved.
* Return 0 for bits in reserved range, which means this selector code
* can't be used on this system */
if (bits < 0x2f)
return 0;
......@@ -123,7 +116,7 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
millivolts = min_uV / 1000;
regnr = pcf50633_regulator_registers[regulator_id];
regnr = rdev->desc->vsel_reg;
switch (regulator_id) {
case PCF50633_REGULATOR_AUTO:
......@@ -154,20 +147,22 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
return pcf50633_reg_write(pcf, regnr, volt_bits);
}
static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id,
u8 bits)
static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev,
unsigned int index)
{
int regulator_id = rdev_get_id(rdev);
int millivolts;
switch (id) {
switch (regulator_id) {
case PCF50633_REGULATOR_AUTO:
millivolts = auto_voltage_value(bits);
millivolts = auto_voltage_value(index);
break;
case PCF50633_REGULATOR_DOWN1:
millivolts = down_voltage_value(bits);
millivolts = down_voltage_value(index);
break;
case PCF50633_REGULATOR_DOWN2:
millivolts = down_voltage_value(bits);
millivolts = down_voltage_value(index);
break;
case PCF50633_REGULATOR_LDO1:
case PCF50633_REGULATOR_LDO2:
......@@ -177,7 +172,7 @@ static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id,
case PCF50633_REGULATOR_LDO6:
case PCF50633_REGULATOR_HCLDO:
case PCF50633_REGULATOR_MEMLDO:
millivolts = ldo_voltage_value(bits);
millivolts = ldo_voltage_value(index);
break;
default:
return -EINVAL;
......@@ -186,140 +181,44 @@ static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id,
return millivolts * 1000;
}
static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev)
{
struct pcf50633 *pcf;
int regulator_id;
u8 volt_bits, regnr;
pcf = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
regnr = pcf50633_regulator_registers[regulator_id];
volt_bits = pcf50633_reg_read(pcf, regnr);
return pcf50633_regulator_voltage_value(regulator_id, volt_bits);
}
static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev,
unsigned int index)
{
struct pcf50633 *pcf;
int regulator_id;
pcf = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev);
switch (regulator_id) {
case PCF50633_REGULATOR_AUTO:
index += 0x2f;
break;
default:
break;
}
return pcf50633_regulator_voltage_value(regulator_id, index);
}
static int pcf50633_regulator_enable(struct regulator_dev *rdev)
{
struct pcf50633 *pcf = rdev_get_drvdata(rdev);
int regulator_id;
u8 regnr;
regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* The *ENA register is always one after the *OUT register */
regnr = pcf50633_regulator_registers[regulator_id] + 1;
return pcf50633_reg_set_bit_mask(pcf, regnr, PCF50633_REGULATOR_ON,
PCF50633_REGULATOR_ON);
}
static int pcf50633_regulator_disable(struct regulator_dev *rdev)
{
struct pcf50633 *pcf = rdev_get_drvdata(rdev);
int regulator_id;
u8 regnr;
regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
regnr = pcf50633_regulator_registers[regulator_id] + 1;
return pcf50633_reg_set_bit_mask(pcf, regnr,
PCF50633_REGULATOR_ON, 0);
}
static int pcf50633_regulator_is_enabled(struct regulator_dev *rdev)
{
struct pcf50633 *pcf = rdev_get_drvdata(rdev);
int regulator_id = rdev_get_id(rdev);
u8 regnr;
regulator_id = rdev_get_id(rdev);
if (regulator_id >= PCF50633_NUM_REGULATORS)
return -EINVAL;
/* the *ENA register is always one after the *OUT register */
regnr = pcf50633_regulator_registers[regulator_id] + 1;
return pcf50633_reg_read(pcf, regnr) & PCF50633_REGULATOR_ON;
}
static struct regulator_ops pcf50633_regulator_ops = {
.set_voltage = pcf50633_regulator_set_voltage,
.get_voltage = pcf50633_regulator_get_voltage,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.list_voltage = pcf50633_regulator_list_voltage,
.enable = pcf50633_regulator_enable,
.disable = pcf50633_regulator_disable,
.is_enabled = pcf50633_regulator_is_enabled,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
};
static struct regulator_desc regulators[] = {
[PCF50633_REGULATOR_AUTO] =
PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 81),
[PCF50633_REGULATOR_DOWN1] =
PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 96),
[PCF50633_REGULATOR_DOWN2] =
PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 96),
[PCF50633_REGULATOR_LDO1] =
PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 28),
[PCF50633_REGULATOR_LDO2] =
PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 28),
[PCF50633_REGULATOR_LDO3] =
PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 28),
[PCF50633_REGULATOR_LDO4] =
PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 28),
[PCF50633_REGULATOR_LDO5] =
PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 28),
[PCF50633_REGULATOR_LDO6] =
PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 28),
[PCF50633_REGULATOR_HCLDO] =
PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 28),
[PCF50633_REGULATOR_MEMLDO] =
PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 28),
static const struct regulator_desc regulators[] = {
[PCF50633_REGULATOR_AUTO] = PCF50633_REGULATOR("auto", AUTO, 128),
[PCF50633_REGULATOR_DOWN1] = PCF50633_REGULATOR("down1", DOWN1, 96),
[PCF50633_REGULATOR_DOWN2] = PCF50633_REGULATOR("down2", DOWN2, 96),
[PCF50633_REGULATOR_LDO1] = PCF50633_REGULATOR("ldo1", LDO1, 28),
[PCF50633_REGULATOR_LDO2] = PCF50633_REGULATOR("ldo2", LDO2, 28),
[PCF50633_REGULATOR_LDO3] = PCF50633_REGULATOR("ldo3", LDO3, 28),
[PCF50633_REGULATOR_LDO4] = PCF50633_REGULATOR("ldo4", LDO4, 28),
[PCF50633_REGULATOR_LDO5] = PCF50633_REGULATOR("ldo5", LDO5, 28),
[PCF50633_REGULATOR_LDO6] = PCF50633_REGULATOR("ldo6", LDO6, 28),
[PCF50633_REGULATOR_HCLDO] = PCF50633_REGULATOR("hcldo", HCLDO, 28),
[PCF50633_REGULATOR_MEMLDO] = PCF50633_REGULATOR("memldo", MEMLDO, 28),
};
static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
{
struct regulator_dev *rdev;
struct pcf50633 *pcf;
struct regulator_config config = { };
/* Already set by core driver */
pcf = dev_to_pcf50633(pdev->dev.parent);
rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
pdev->dev.platform_data, pcf, NULL);
config.dev = &pdev->dev;
config.init_data = pdev->dev.platform_data;
config.driver_data = pcf;
config.regmap = pcf->regmap;
rdev = regulator_register(&regulators[pdev->id], &config);
if (IS_ERR(rdev))
return PTR_ERR(rdev);
......
/*
* Regulator driver for RICOH RC5T583 power management chip.
*
* Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
* Author: Laxman dewangan <ldewangan@nvidia.com>
*
* based on code
* Copyright (C) 2011 RICOH COMPANY,LTD
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/gpio.h>
#include <linux/mfd/rc5t583.h>
struct rc5t583_regulator_info {
int deepsleep_id;
/* Regulator register address.*/
uint8_t reg_disc_reg;
uint8_t disc_bit;
uint8_t deepsleep_reg;
/* Chip constraints on regulator behavior */
int min_uV;
int max_uV;
int step_uV;
/* Regulator specific turn-on delay and voltage settling time*/
int enable_uv_per_us;
int change_uv_per_us;
/* Used by regulator core */
struct regulator_desc desc;
};
struct rc5t583_regulator {
struct rc5t583_regulator_info *reg_info;
/* Devices */
struct device *dev;
struct rc5t583 *mfd;
struct regulator_dev *rdev;
};
static int rc5t583_list_voltage(struct regulator_dev *rdev, unsigned selector)
{
struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);
struct rc5t583_regulator_info *ri = reg->reg_info;
return ri->min_uV + (ri->step_uV * selector);
}
static int rc5t583_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV, unsigned *selector)
{
struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);
struct rc5t583_regulator_info *ri = reg->reg_info;
int sel, ret;
if (min_uV < ri->min_uV)
min_uV = ri->min_uV;
sel = DIV_ROUND_UP(min_uV - ri->min_uV, ri->step_uV);
if (sel >= rdev->desc->n_voltages) {
dev_err(&rdev->dev, "Invalid selector 0x%02x\n", sel);
return -EINVAL;
}
*selector = sel;
ret = rc5t583_update(reg->mfd->dev, rdev->desc->vsel_reg, sel,
rdev->desc->vsel_mask);
if (ret < 0)
dev_err(&rdev->dev, "Error in update voltage register 0x%02x\n",
rdev->desc->vsel_reg);
return ret;
}
static int rc5t583_regulator_enable_time(struct regulator_dev *rdev)
{
struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);
int vsel = regulator_get_voltage_sel_regmap(rdev);
int curr_uV = rc5t583_list_voltage(rdev, vsel);
return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us);
}
static int rc5t583_set_voltage_time_sel(struct regulator_dev *rdev,
unsigned int old_selector, unsigned int new_selector)
{
struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);
int old_uV, new_uV;
old_uV = rc5t583_list_voltage(rdev, old_selector);
if (old_uV < 0)
return old_uV;
new_uV = rc5t583_list_voltage(rdev, new_selector);
if (new_uV < 0)
return new_uV;
return DIV_ROUND_UP(abs(old_uV - new_uV),
reg->reg_info->change_uv_per_us);
}
static struct regulator_ops rc5t583_ops = {
.is_enabled = regulator_is_enabled_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.enable_time = rc5t583_regulator_enable_time,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage = rc5t583_set_voltage,
.list_voltage = rc5t583_list_voltage,
.set_voltage_time_sel = rc5t583_set_voltage_time_sel,
};
#define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \
_vout_mask, _min_mv, _max_mv, _step_uV, _enable_mv) \
{ \
.reg_disc_reg = RC5T583_REG_##_disc_reg, \
.disc_bit = _disc_bit, \
.deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \
.min_uV = _min_mv * 1000, \
.max_uV = _max_mv * 1000, \
.step_uV = _step_uV, \
.enable_uv_per_us = _enable_mv * 1000, \
.change_uv_per_us = 40 * 1000, \
.deepsleep_id = RC5T583_DS_##_id, \
.desc = { \
.name = "rc5t583-regulator-"#_id, \
.id = RC5T583_REGULATOR_##_id, \
.n_voltages = (_max_mv - _min_mv) * 1000 / _step_uV + 1, \
.ops = &rc5t583_ops, \
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
.vsel_reg = RC5T583_REG_##_id##DAC, \
.vsel_mask = _vout_mask, \
.enable_reg = RC5T583_REG_##_en_reg, \
.enable_mask = BIT(_en_bit), \
}, \
}
static struct rc5t583_regulator_info rc5t583_reg_info[RC5T583_REGULATOR_MAX] = {
RC5T583_REG(DC0, DC0CTL, 0, DC0CTL, 1, 0x7F, 700, 1500, 12500, 4),
RC5T583_REG(DC1, DC1CTL, 0, DC1CTL, 1, 0x7F, 700, 1500, 12500, 14),
RC5T583_REG(DC2, DC2CTL, 0, DC2CTL, 1, 0x7F, 900, 2400, 12500, 14),
RC5T583_REG(DC3, DC3CTL, 0, DC3CTL, 1, 0x7F, 900, 2400, 12500, 14),
RC5T583_REG(LDO0, LDOEN2, 0, LDODIS2, 0, 0x7F, 900, 3400, 25000, 160),
RC5T583_REG(LDO1, LDOEN2, 1, LDODIS2, 1, 0x7F, 900, 3400, 25000, 160),
RC5T583_REG(LDO2, LDOEN2, 2, LDODIS2, 2, 0x7F, 900, 3400, 25000, 160),
RC5T583_REG(LDO3, LDOEN2, 3, LDODIS2, 3, 0x7F, 900, 3400, 25000, 160),
RC5T583_REG(LDO4, LDOEN2, 4, LDODIS2, 4, 0x3F, 750, 1500, 12500, 133),
RC5T583_REG(LDO5, LDOEN2, 5, LDODIS2, 5, 0x7F, 900, 3400, 25000, 267),
RC5T583_REG(LDO6, LDOEN2, 6, LDODIS2, 6, 0x7F, 900, 3400, 25000, 133),
RC5T583_REG(LDO7, LDOEN2, 7, LDODIS2, 7, 0x7F, 900, 3400, 25000, 233),
RC5T583_REG(LDO8, LDOEN1, 0, LDODIS1, 0, 0x7F, 900, 3400, 25000, 233),
RC5T583_REG(LDO9, LDOEN1, 1, LDODIS1, 1, 0x7F, 900, 3400, 25000, 133),
};
static int __devinit rc5t583_regulator_probe(struct platform_device *pdev)
{
struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent);
struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev);
struct regulator_init_data *reg_data;
struct regulator_config config = { };
struct rc5t583_regulator *reg = NULL;
struct rc5t583_regulator *regs;
struct regulator_dev *rdev;
struct rc5t583_regulator_info *ri;
int ret;
int id;
if (!pdata) {
dev_err(&pdev->dev, "No platform data, exiting...\n");
return -ENODEV;
}
regs = devm_kzalloc(&pdev->dev, RC5T583_REGULATOR_MAX *
sizeof(struct rc5t583_regulator), GFP_KERNEL);
if (!regs) {
dev_err(&pdev->dev, "Memory allocation failed exiting..\n");
return -ENOMEM;
}
for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) {
reg_data = pdata->reg_init_data[id];
/* No need to register if there is no regulator data */
if (!reg_data)
continue;
reg = &regs[id];
ri = &rc5t583_reg_info[id];
reg->reg_info = ri;
reg->mfd = rc5t583;
reg->dev = &pdev->dev;
if (ri->deepsleep_id == RC5T583_DS_NONE)
goto skip_ext_pwr_config;
ret = rc5t583_ext_power_req_config(rc5t583->dev,
ri->deepsleep_id,
pdata->regulator_ext_pwr_control[id],
pdata->regulator_deepsleep_slot[id]);
/*
* Configuring external control is not a major issue,
* just give warning.
*/
if (ret < 0)
dev_warn(&pdev->dev,
"Failed to configure ext control %d\n", id);
skip_ext_pwr_config:
config.dev = &pdev->dev;
config.init_data = reg_data;
config.driver_data = reg;
config.regmap = rc5t583->regmap;
rdev = regulator_register(&ri->desc, &config);
if (IS_ERR(rdev)) {
dev_err(&pdev->dev, "Failed to register regulator %s\n",
ri->desc.name);
ret = PTR_ERR(rdev);
goto clean_exit;
}
reg->rdev = rdev;
}
platform_set_drvdata(pdev, regs);
return 0;
clean_exit:
while (--id >= 0)
regulator_unregister(regs[id].rdev);
return ret;
}
static int __devexit rc5t583_regulator_remove(struct platform_device *pdev)
{
struct rc5t583_regulator *regs = platform_get_drvdata(pdev);
int id;
for (id = 0; id < RC5T583_REGULATOR_MAX; ++id)
regulator_unregister(regs[id].rdev);
return 0;
}
static struct platform_driver rc5t583_regulator_driver = {
.driver = {
.name = "rc5t583-regulator",
.owner = THIS_MODULE,
},
.probe = rc5t583_regulator_probe,
.remove = __devexit_p(rc5t583_regulator_remove),
};
static int __init rc5t583_regulator_init(void)
{
return platform_driver_register(&rc5t583_regulator_driver);
}
subsys_initcall(rc5t583_regulator_init);
static void __exit rc5t583_regulator_exit(void)
{
platform_driver_unregister(&rc5t583_regulator_driver);
}
module_exit(rc5t583_regulator_exit);
MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
MODULE_DESCRIPTION("RC5T583 regulator driver");
MODULE_ALIAS("platform:rc5t583-regulator");
MODULE_LICENSE("GPL v2");
This diff is collapsed.
......@@ -123,7 +123,7 @@ static struct regulator_ops tps6105x_regulator_ops = {
.list_voltage = tps6105x_regulator_list_voltage,
};
static struct regulator_desc tps6105x_regulator_desc = {
static const struct regulator_desc tps6105x_regulator_desc = {
.name = "tps6105x-boost",
.ops = &tps6105x_regulator_ops,
.type = REGULATOR_VOLTAGE,
......@@ -139,6 +139,7 @@ static int __devinit tps6105x_regulator_probe(struct platform_device *pdev)
{
struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev);
struct tps6105x_platform_data *pdata = tps6105x->pdata;
struct regulator_config config = { };
int ret;
/* This instance is not set for regulator mode so bail out */
......@@ -148,11 +149,13 @@ static int __devinit tps6105x_regulator_probe(struct platform_device *pdev)
return 0;
}
config.dev = &tps6105x->client->dev;
config.init_data = pdata->regulator_data;
config.driver_data = tps6105x;
/* Register regulator with framework */
tps6105x->regulator = regulator_register(&tps6105x_regulator_desc,
&tps6105x->client->dev,
pdata->regulator_data, tps6105x,
NULL);
&config);
if (IS_ERR(tps6105x->regulator)) {
ret = PTR_ERR(tps6105x->regulator);
dev_err(&tps6105x->client->dev,
......
/*
* tps62360.c -- TI tps62360
*
* Driver for processor core supply tps62360 and tps62361B
* Driver for processor core supply tps62360, tps62361B, tps62362 and tps62363.
*
* Copyright (c) 2012, NVIDIA Corporation.
*
......@@ -46,7 +46,7 @@
#define REG_RAMPCTRL 6
#define REG_CHIPID 8
enum chips {TPS62360, TPS62361};
enum chips {TPS62360, TPS62361, TPS62362, TPS62363};
#define TPS62360_BASE_VOLTAGE 770
#define TPS62360_N_VOLTAGES 64
......@@ -56,10 +56,8 @@ enum chips {TPS62360, TPS62361};
/* tps 62360 chip information */
struct tps62360_chip {
const char *name;
struct device *dev;
struct regulator_desc desc;
struct i2c_client *client;
struct regulator_dev *rdev;
struct regmap *regmap;
int chip_id;
......@@ -272,6 +270,7 @@ static const struct regmap_config tps62360_regmap_config = {
static int __devinit tps62360_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct regulator_config config = { };
struct tps62360_regulator_platform_data *pdata;
struct regulator_dev *rdev;
struct tps62360_chip *tps;
......@@ -297,21 +296,31 @@ static int __devinit tps62360_probe(struct i2c_client *client,
tps->en_internal_pulldn = pdata->en_internal_pulldn;
tps->vsel0_gpio = pdata->vsel0_gpio;
tps->vsel1_gpio = pdata->vsel1_gpio;
tps->client = client;
tps->dev = &client->dev;
tps->name = id->name;
tps->voltage_base = (id->driver_data == TPS62360) ?
TPS62360_BASE_VOLTAGE : TPS62361_BASE_VOLTAGE;
tps->voltage_reg_mask = (id->driver_data == TPS62360) ? 0x3F : 0x7F;
switch (id->driver_data) {
case TPS62360:
case TPS62362:
tps->voltage_base = TPS62360_BASE_VOLTAGE;
tps->voltage_reg_mask = 0x3F;
tps->desc.n_voltages = TPS62360_N_VOLTAGES;
break;
case TPS62361:
case TPS62363:
tps->voltage_base = TPS62361_BASE_VOLTAGE;
tps->voltage_reg_mask = 0x7F;
tps->desc.n_voltages = TPS62361_N_VOLTAGES;
break;
default:
return -ENODEV;
}
tps->desc.name = id->name;
tps->desc.id = 0;
tps->desc.n_voltages = (id->driver_data == TPS62360) ?
TPS62360_N_VOLTAGES : TPS62361_N_VOLTAGES;
tps->desc.ops = &tps62360_dcdc_ops;
tps->desc.type = REGULATOR_VOLTAGE;
tps->desc.owner = THIS_MODULE;
tps->regmap = regmap_init_i2c(client, &tps62360_regmap_config);
tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
if (IS_ERR(tps->regmap)) {
ret = PTR_ERR(tps->regmap);
dev_err(&client->dev, "%s() Err: Failed to allocate register"
......@@ -376,9 +385,12 @@ static int __devinit tps62360_probe(struct i2c_client *client,
goto err_init;
}
config.dev = &client->dev;
config.init_data = &pdata->reg_init_data;
config.driver_data = tps;
/* Register the regulators */
rdev = regulator_register(&tps->desc, &client->dev,
&pdata->reg_init_data, tps, NULL);
rdev = regulator_register(&tps->desc, &config);
if (IS_ERR(rdev)) {
dev_err(tps->dev, "%s() Err: Failed to register %s\n",
__func__, id->name);
......@@ -396,7 +408,6 @@ static int __devinit tps62360_probe(struct i2c_client *client,
if (gpio_is_valid(tps->vsel0_gpio))
gpio_free(tps->vsel0_gpio);
err_gpio0:
regmap_exit(tps->regmap);
return ret;
}
......@@ -417,7 +428,6 @@ static int __devexit tps62360_remove(struct i2c_client *client)
gpio_free(tps->vsel0_gpio);
regulator_unregister(tps->rdev);
regmap_exit(tps->regmap);
return 0;
}
......@@ -439,6 +449,8 @@ static void tps62360_shutdown(struct i2c_client *client)
static const struct i2c_device_id tps62360_id[] = {
{.name = "tps62360", .driver_data = TPS62360},
{.name = "tps62361", .driver_data = TPS62361},
{.name = "tps62362", .driver_data = TPS62362},
{.name = "tps62363", .driver_data = TPS62363},
{},
};
......@@ -468,5 +480,5 @@ static void __exit tps62360_cleanup(void)
module_exit(tps62360_cleanup);
MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
MODULE_DESCRIPTION("TPS62360 voltage regulator driver");
MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
MODULE_LICENSE("GPL v2");
This diff is collapsed.
......@@ -404,6 +404,7 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev)
{
struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent);
struct tps_info *info = &tps6507x_pmic_regs[0];
struct regulator_config config = { };
struct regulator_init_data *init_data;
struct regulator_dev *rdev;
struct tps6507x_pmic *tps;
......@@ -428,7 +429,7 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev)
if (!init_data)
return -EINVAL;
tps = kzalloc(sizeof(*tps), GFP_KERNEL);
tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL);
if (!tps)
return -ENOMEM;
......@@ -453,8 +454,11 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev)
tps->desc[i].type = REGULATOR_VOLTAGE;
tps->desc[i].owner = THIS_MODULE;
rdev = regulator_register(&tps->desc[i],
tps6507x_dev->dev, init_data, tps, NULL);
config.dev = tps6507x_dev->dev;
config.init_data = init_data;
config.driver_data = tps;
rdev = regulator_register(&tps->desc[i], &config);
if (IS_ERR(rdev)) {
dev_err(tps6507x_dev->dev,
"failed to register %s regulator\n",
......@@ -475,8 +479,6 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev)
fail:
while (--i >= 0)
regulator_unregister(tps->rdev[i]);
kfree(tps);
return error;
}
......@@ -488,9 +490,6 @@ static int __devexit tps6507x_pmic_remove(struct platform_device *pdev)
for (i = 0; i < TPS6507X_NUM_REGULATOR; i++)
regulator_unregister(tps->rdev[i]);
kfree(tps);
return 0;
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -323,11 +323,14 @@ static struct regulator_desc regulators[] = {
static int __devinit wm8400_regulator_probe(struct platform_device *pdev)
{
struct wm8400 *wm8400 = container_of(pdev, struct wm8400, regulators[pdev->id]);
struct regulator_config config = { };
struct regulator_dev *rdev;
rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
pdev->dev.platform_data, wm8400, NULL);
config.dev = &pdev->dev;
config.init_data = pdev->dev.platform_data;
config.driver_data = wm8400;
rdev = regulator_register(&regulators[pdev->id], &config);
if (IS_ERR(rdev))
return PTR_ERR(rdev);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment