Commit 8ded8d4e authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'regulator-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator

Pull regulator updates from Mark Brown:
 "The diffstat and changelog here is dominated by Lee Jones' heroic
  efforts to sync the ab8500 driver that's been maintained out of tree
  with mainline (plus Axel's cleanup work on the results) but there's a
  few other things here:

   - Axel Lin added regulator_map_voltage_ascend() optimising a common
     pattern for drivers using the core code.
   - Milo Kim tought the regulator core to handle regulators sharing an
     enable GPIO, avoiding the need to do hacks to support such systems.
   - Andrew Bresticker added code to handle missing supplies for
     regulators more sensibly for device tree systems, reducing the need
     for stubbing there.

  plus the usual batch of driver specific updates and fixes"

* tag 'regulator-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (152 commits)
  regulator: mc13892: Fix MC13892_SWITCHERS0_SWxHI bit in set_voltage_sel
  regulator: Remove NULL test before calling regulator_unregister()
  regulator: mc13783: Add device tree probe support
  regulator: mc13xxx: Add warning of incorrect names of regulators
  regulator: max77686: Don't update max77686->opmode if update register fails
  regulator: max8952: Add missing config.of_node setting for regulator register
  regulator: ab3100: Fix regulator register error handling
  regulator: tps6524x: Use regulator_map_voltage_ascend
  regulator: lp8788-buck: Use regulator_map_voltage_ascend
  regulator: lp872x: Use regulator_map_voltage_ascend
  regulator: mc13892: Use regulator_map_voltage_ascend for mc13892_sw_regulator_ops
  regulator: tps65023: Use regulator_map_voltage_ascend
  regulator: tps65023: Merge tps65020 ldo1 and ldo2 vsel table
  regulator: tps6507x: Use regulator_map_voltage_ascend
  regulator: mc13892: Fix MC13892_SWITCHERS0_SWxHI bit in set_voltage_sel
  regulator: ab3100: device tree support
  regulator: ab3100: refactor probe to use IDs
  regulator: max8973: Don't override control1 variable when set ramp delay bits
  regulator: tps80031: Convert tps80031_dcdc_ops to [get|set]_voltage_sel_regmap
  regulator: tps80031: Fix LDO2 track mode for TPS80031 or TPS80032-ES1.0
  ...
parents 7b053842 bee54658
......@@ -10,10 +10,40 @@ Optional properties:
- fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used
Sub-nodes:
- regulators : Contain the regulator nodes. The MC13892 regulators are
bound using their names as listed below with their registers and bits
for enabling.
- regulators : Contain the regulator nodes. The regulators are bound using
their names as listed below with their registers and bits for enabling.
MC13783 regulators:
sw1a : regulator SW1A (register 24, bit 0)
sw1b : regulator SW1B (register 25, bit 0)
sw2a : regulator SW2A (register 26, bit 0)
sw2b : regulator SW2B (register 27, bit 0)
sw3 : regulator SW3 (register 29, bit 20)
vaudio : regulator VAUDIO (register 32, bit 0)
viohi : regulator VIOHI (register 32, bit 3)
violo : regulator VIOLO (register 32, bit 6)
vdig : regulator VDIG (register 32, bit 9)
vgen : regulator VGEN (register 32, bit 12)
vrfdig : regulator VRFDIG (register 32, bit 15)
vrfref : regulator VRFREF (register 32, bit 18)
vrfcp : regulator VRFCP (register 32, bit 21)
vsim : regulator VSIM (register 33, bit 0)
vesim : regulator VESIM (register 33, bit 3)
vcam : regulator VCAM (register 33, bit 6)
vrfbg : regulator VRFBG (register 33, bit 9)
vvib : regulator VVIB (register 33, bit 11)
vrf1 : regulator VRF1 (register 33, bit 12)
vrf2 : regulator VRF2 (register 33, bit 15)
vmmc1 : regulator VMMC1 (register 33, bit 18)
vmmc2 : regulator VMMC2 (register 33, bit 21)
gpo1 : regulator GPO1 (register 34, bit 6)
gpo2 : regulator GPO2 (register 34, bit 8)
gpo3 : regulator GPO3 (register 34, bit 10)
gpo4 : regulator GPO4 (register 34, bit 12)
pwgt1spi : regulator PWGT1SPI (register 34, bit 15)
pwgt2spi : regulator PWGT2SPI (register 34, bit 16)
MC13892 regulators:
vcoincell : regulator VCOINCELL (register 13, bit 23)
sw1 : regulator SW1 (register 24, bit 0)
sw2 : regulator SW2 (register 25, bit 0)
......
Maxim MAX8952 voltage regulator
Required properties:
- compatible: must be equal to "maxim,max8952"
- reg: I2C slave address, usually 0x60
- max8952,dvs-mode-microvolt: array of 4 integer values defining DVS voltages
in microvolts. All values must be from range <770000, 1400000>
- any required generic properties defined in regulator.txt
Optional properties:
- max8952,vid-gpios: array of two GPIO pins used for DVS voltage selection
- max8952,en-gpio: GPIO used to control enable status of regulator
- max8952,default-mode: index of default DVS voltage, from <0, 3> range
- max8952,sync-freq: sync frequency, must be one of following values:
- 0: 26 MHz
- 1: 13 MHz
- 2: 19.2 MHz
Defaults to 26 MHz if not specified.
- max8952,ramp-speed: voltage ramp speed, must be one of following values:
- 0: 32mV/us
- 1: 16mV/us
- 2: 8mV/us
- 3: 4mV/us
- 4: 2mV/us
- 5: 1mV/us
- 6: 0.5mV/us
- 7: 0.25mV/us
Defaults to 32mV/us if not specified.
- any available generic properties defined in regulator.txt
Example:
vdd_arm_reg: pmic@60 {
compatible = "maxim,max8952";
reg = <0x60>;
/* max8952-specific properties */
max8952,vid-gpios = <&gpx0 3 0>, <&gpx0 4 0>;
max8952,en-gpio = <&gpx0 1 0>;
max8952,default-mode = <0>;
max8952,dvs-mode-microvolt = <1250000>, <1200000>,
<1050000>, <950000>;
max8952,sync-freq = <0>;
max8952,ramp-speed = <0>;
/* generic regulator properties */
regulator-name = "vdd_arm";
regulator-min-microvolt = <770000>;
regulator-max-microvolt = <1400000>;
regulator-always-on;
regulator-boot-on;
};
......@@ -8732,7 +8732,7 @@ F: drivers/scsi/vmw_pvscsi.c
F: drivers/scsi/vmw_pvscsi.h
VOLTAGE AND CURRENT REGULATOR FRAMEWORK
M: Liam Girdwood <lrg@ti.com>
M: Liam Girdwood <lgirdwood@gmail.com>
M: Mark Brown <broonie@kernel.org>
W: http://opensource.wolfsonmicro.com/node/15
W: http://www.slimlogic.co.uk/?p=48
......
......@@ -97,6 +97,19 @@ static struct s3c2410_uartcfg universal_uartcfgs[] __initdata = {
static struct regulator_consumer_supply max8952_consumer =
REGULATOR_SUPPLY("vdd_arm", NULL);
static struct regulator_init_data universal_max8952_reg_data = {
.constraints = {
.name = "VARM_1.2V",
.min_uV = 770000,
.max_uV = 1400000,
.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
.always_on = 1,
.boot_on = 1,
},
.num_consumer_supplies = 1,
.consumer_supplies = &max8952_consumer,
};
static struct max8952_platform_data universal_max8952_pdata __initdata = {
.gpio_vid0 = EXYNOS4_GPX0(3),
.gpio_vid1 = EXYNOS4_GPX0(4),
......@@ -105,19 +118,7 @@ static struct max8952_platform_data universal_max8952_pdata __initdata = {
.dvs_mode = { 48, 32, 28, 18 }, /* 1.25, 1.20, 1.05, 0.95V */
.sync_freq = 0, /* default: fastest */
.ramp_speed = 0, /* default: fastest */
.reg_data = {
.constraints = {
.name = "VARM_1.2V",
.min_uV = 770000,
.max_uV = 1400000,
.valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
.always_on = 1,
.boot_on = 1,
},
.num_consumer_supplies = 1,
.consumer_supplies = &max8952_consumer,
},
.reg_data = &universal_max8952_reg_data,
};
static struct regulator_consumer_supply lp3974_buck1_consumer =
......
......@@ -14,10 +14,11 @@
#include <linux/regulator/machine.h>
#include <linux/regulator/ab8500.h>
extern struct ab8500_regulator_reg_init
ab8500_regulator_reg_init[AB8500_NUM_REGULATOR_REGISTERS];
extern struct regulator_init_data ab8500_regulators[AB8500_NUM_REGULATORS];
extern struct ab8500_regulator_platform_data ab8500_regulator_plat_data;
extern struct ab8500_regulator_platform_data ab8505_regulator_plat_data;
extern struct regulator_init_data tps61052_regulator;
extern struct regulator_init_data gpio_en_3v3_regulator;
void mop500_regulator_init(void);
#endif
......@@ -199,10 +199,7 @@ static struct platform_device snowball_sbnet_dev = {
struct ab8500_platform_data ab8500_platdata = {
.irq_base = MOP500_AB8500_IRQ_BASE,
.regulator_reg_init = ab8500_regulator_reg_init,
.num_regulator_reg_init = ARRAY_SIZE(ab8500_regulator_reg_init),
.regulator = ab8500_regulators,
.num_regulator = ARRAY_SIZE(ab8500_regulators),
.regulator = &ab8500_regulator_plat_data,
.gpio = &ab8500_gpio_pdata,
.codec = &ab8500_codec_pdata,
};
......
......@@ -753,6 +753,7 @@ static struct mfd_cell ab3100_devs[] = {
},
{
.name = "ab3100-regulators",
.of_compatible = "stericsson,ab3100-regulators",
.id = -1,
},
{
......
......@@ -220,35 +220,6 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
return ret;
}
static int pm8606_preg_enable(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
return pm860x_set_bits(info->i2c, rdev->desc->enable_reg,
1 << rdev->desc->enable_mask, 0);
}
static int pm8606_preg_disable(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
return pm860x_set_bits(info->i2c, rdev->desc->enable_reg,
1 << rdev->desc->enable_mask,
1 << rdev->desc->enable_mask);
}
static int pm8606_preg_is_enabled(struct regulator_dev *rdev)
{
struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
int ret;
ret = pm860x_reg_read(info->i2c, rdev->desc->enable_reg);
if (ret < 0)
return ret;
return !((unsigned char)ret & (1 << rdev->desc->enable_mask));
}
static struct regulator_ops pm8607_regulator_ops = {
.list_voltage = pm8607_list_voltage,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
......@@ -259,9 +230,9 @@ static struct regulator_ops pm8607_regulator_ops = {
};
static struct regulator_ops pm8606_preg_ops = {
.enable = pm8606_preg_enable,
.disable = pm8606_preg_disable,
.is_enabled = pm8606_preg_is_enabled,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
};
#define PM8606_PREG(ereg, ebit) \
......@@ -274,6 +245,7 @@ static struct regulator_ops pm8606_preg_ops = {
.owner = THIS_MODULE, \
.enable_reg = PM8606_##ereg, \
.enable_mask = (ebit), \
.enable_is_inverted = true, \
}, \
}
......
......@@ -12,7 +12,7 @@ obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o
obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o
obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o
obj-$(CONFIG_REGULATOR_AB8500) += ab8500.o ab8500-ext.o
obj-$(CONFIG_REGULATOR_AD5398) += ad5398.o
obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o
obj-$(CONFIG_REGULATOR_ARIZONA) += arizona-micsupp.o arizona-ldo1.o
......
......@@ -17,6 +17,8 @@
#include <linux/regulator/driver.h>
#include <linux/mfd/ab3100.h>
#include <linux/mfd/abx500.h>
#include <linux/of.h>
#include <linux/regulator/of_regulator.h>
/* LDO registers and some handy masking definitions for AB3100 */
#define AB3100_LDO_A 0x40
......@@ -345,7 +347,11 @@ static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
{
struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
return abreg->plfdata->external_voltage;
if (abreg->plfdata)
return abreg->plfdata->external_voltage;
else
/* TODO: encode external voltage into device tree */
return 0;
}
static struct regulator_ops regulator_ops_fixed = {
......@@ -488,16 +494,174 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
},
};
static int ab3100_regulator_register(struct platform_device *pdev,
struct ab3100_platform_data *plfdata,
struct regulator_init_data *init_data,
struct device_node *np,
int id)
{
struct regulator_desc *desc;
struct ab3100_regulator *reg;
struct regulator_dev *rdev;
struct regulator_config config = { };
int err, i;
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
desc = &ab3100_regulator_desc[i];
if (desc->id == id)
break;
}
if (desc->id != id)
return -ENODEV;
/* Same index used for this array */
reg = &ab3100_regulators[i];
/*
* Initialize per-regulator struct.
* Inherit platform data, this comes down from the
* i2c boarddata, from the machine. So if you want to
* see what it looks like for a certain machine, go
* into the machine I2C setup.
*/
reg->dev = &pdev->dev;
if (plfdata) {
reg->plfdata = plfdata;
config.init_data = &plfdata->reg_constraints[i];
} else if (np) {
config.of_node = np;
config.init_data = init_data;
}
config.dev = &pdev->dev;
config.driver_data = reg;
rdev = regulator_register(desc, &config);
if (IS_ERR(rdev)) {
err = PTR_ERR(rdev);
dev_err(&pdev->dev,
"%s: failed to register regulator %s err %d\n",
__func__, desc->name,
err);
return err;
}
/* Then set a pointer back to the registered regulator */
reg->rdev = rdev;
return 0;
}
static struct of_regulator_match ab3100_regulator_matches[] = {
{ .name = "ab3100_ldo_a", .driver_data = (void *) AB3100_LDO_A, },
{ .name = "ab3100_ldo_c", .driver_data = (void *) AB3100_LDO_C, },
{ .name = "ab3100_ldo_d", .driver_data = (void *) AB3100_LDO_D, },
{ .name = "ab3100_ldo_e", .driver_data = (void *) AB3100_LDO_E, },
{ .name = "ab3100_ldo_f", .driver_data = (void *) AB3100_LDO_F },
{ .name = "ab3100_ldo_g", .driver_data = (void *) AB3100_LDO_G },
{ .name = "ab3100_ldo_h", .driver_data = (void *) AB3100_LDO_H },
{ .name = "ab3100_ldo_k", .driver_data = (void *) AB3100_LDO_K },
{ .name = "ab3100_ext", .driver_data = (void *) AB3100_LDO_EXT },
{ .name = "ab3100_buck", .driver_data = (void *) AB3100_BUCK },
};
/*
* NOTE: the following functions are regulators pluralis - it is the
* binding to the AB3100 core driver and the parent platform device
* for all the different regulators.
* Initial settings of ab3100 registers.
* Common for below LDO regulator settings are that
* bit 7-5 controls voltage. Bit 4 turns regulator ON(1) or OFF(0).
* Bit 3-2 controls sleep enable and bit 1-0 controls sleep mode.
*/
/* LDO_A 0x16: 2.75V, ON, SLEEP_A, SLEEP OFF GND */
#define LDO_A_SETTING 0x16
/* LDO_C 0x10: 2.65V, ON, SLEEP_A or B, SLEEP full power */
#define LDO_C_SETTING 0x10
/* LDO_D 0x10: 2.65V, ON, sleep mode not used */
#define LDO_D_SETTING 0x10
/* LDO_E 0x10: 1.8V, ON, SLEEP_A or B, SLEEP full power */
#define LDO_E_SETTING 0x10
/* LDO_E SLEEP 0x00: 1.8V, not used, SLEEP_A or B, not used */
#define LDO_E_SLEEP_SETTING 0x00
/* LDO_F 0xD0: 2.5V, ON, SLEEP_A or B, SLEEP full power */
#define LDO_F_SETTING 0xD0
/* LDO_G 0x00: 2.85V, OFF, SLEEP_A or B, SLEEP full power */
#define LDO_G_SETTING 0x00
/* LDO_H 0x18: 2.75V, ON, SLEEP_B, SLEEP full power */
#define LDO_H_SETTING 0x18
/* LDO_K 0x00: 2.75V, OFF, SLEEP_A or B, SLEEP full power */
#define LDO_K_SETTING 0x00
/* LDO_EXT 0x00: Voltage not set, OFF, not used, not used */
#define LDO_EXT_SETTING 0x00
/* BUCK 0x7D: 1.2V, ON, SLEEP_A and B, SLEEP low power */
#define BUCK_SETTING 0x7D
/* BUCK SLEEP 0xAC: 1.05V, Not used, SLEEP_A and B, Not used */
#define BUCK_SLEEP_SETTING 0xAC
static const u8 ab3100_reg_initvals[] = {
LDO_A_SETTING,
LDO_C_SETTING,
LDO_E_SETTING,
LDO_E_SLEEP_SETTING,
LDO_F_SETTING,
LDO_G_SETTING,
LDO_H_SETTING,
LDO_K_SETTING,
LDO_EXT_SETTING,
BUCK_SETTING,
BUCK_SLEEP_SETTING,
LDO_D_SETTING,
};
static int ab3100_regulators_remove(struct platform_device *pdev)
{
int i;
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
struct ab3100_regulator *reg = &ab3100_regulators[i];
regulator_unregister(reg->rdev);
reg->rdev = NULL;
}
return 0;
}
static int
ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
{
int err, i;
/*
* Set up the regulator registers, as was previously done with
* platform data.
*/
/* Set up regulators */
for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
err = abx500_set_register_interruptible(&pdev->dev, 0,
ab3100_reg_init_order[i],
ab3100_reg_initvals[i]);
if (err) {
dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
err);
return err;
}
}
for (i = 0; i < ARRAY_SIZE(ab3100_regulator_matches); i++) {
err = ab3100_regulator_register(
pdev, NULL, ab3100_regulator_matches[i].init_data,
ab3100_regulator_matches[i].of_node,
(int) ab3100_regulator_matches[i].driver_data);
if (err) {
ab3100_regulators_remove(pdev);
return err;
}
}
return 0;
}
static int ab3100_regulators_probe(struct platform_device *pdev)
{
struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
struct regulator_config config = { };
struct device_node *np = pdev->dev.of_node;
int err = 0;
u8 data;
int i;
......@@ -516,6 +680,18 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
dev_notice(&pdev->dev,
"chip is in inactive mode (Cold start)\n");
if (np) {
err = of_regulator_match(&pdev->dev, np,
ab3100_regulator_matches,
ARRAY_SIZE(ab3100_regulator_matches));
if (err < 0) {
dev_err(&pdev->dev,
"Error parsing regulator init data: %d\n", err);
return err;
}
return ab3100_regulator_of_probe(pdev, np);
}
/* Set up regulators */
for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
err = abx500_set_register_interruptible(&pdev->dev, 0,
......@@ -530,59 +706,19 @@ static int ab3100_regulators_probe(struct platform_device *pdev)
/* Register the regulators */
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
struct ab3100_regulator *reg = &ab3100_regulators[i];
struct regulator_dev *rdev;
/*
* Initialize per-regulator struct.
* Inherit platform data, this comes down from the
* i2c boarddata, from the machine. So if you want to
* see what it looks like for a certain machine, go
* into the machine I2C setup.
*/
reg->dev = &pdev->dev;
reg->plfdata = plfdata;
struct regulator_desc *desc = &ab3100_regulator_desc[i];
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], &config);
if (IS_ERR(rdev)) {
err = PTR_ERR(rdev);
dev_err(&pdev->dev,
"%s: failed to register regulator %s err %d\n",
__func__, ab3100_regulator_desc[i].name,
err);
/* remove the already registered regulators */
while (--i >= 0)
regulator_unregister(ab3100_regulators[i].rdev);
err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
desc->id);
if (err) {
ab3100_regulators_remove(pdev);
return err;
}
/* Then set a pointer back to the registered regulator */
reg->rdev = rdev;
}
return 0;
}
static int ab3100_regulators_remove(struct platform_device *pdev)
{
int i;
for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
struct ab3100_regulator *reg = &ab3100_regulators[i];
regulator_unregister(reg->rdev);
}
return 0;
}
static struct platform_driver ab3100_regulators_driver = {
.driver = {
.name = "ab3100-regulators",
......
This diff is collapsed.
This diff is collapsed.
......@@ -131,7 +131,7 @@ static const struct regulator_desc arizona_ldo1_hc = {
.min_uV = 900000,
.uV_step = 50000,
.n_voltages = 8,
.enable_time = 500,
.enable_time = 1500,
.owner = THIS_MODULE,
};
......
......@@ -13,9 +13,11 @@
#include <linux/init.h>
#include <linux/mfd/as3711.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/of_regulator.h>
#include <linux/slab.h>
struct as3711_regulator_info {
......@@ -276,6 +278,53 @@ static struct as3711_regulator_info as3711_reg_info[] = {
#define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_info)
static struct of_regulator_match
as3711_regulator_matches[AS3711_REGULATOR_NUM] = {
[AS3711_REGULATOR_SD_1] = { .name = "sd1" },
[AS3711_REGULATOR_SD_2] = { .name = "sd2" },
[AS3711_REGULATOR_SD_3] = { .name = "sd3" },
[AS3711_REGULATOR_SD_4] = { .name = "sd4" },
[AS3711_REGULATOR_LDO_1] = { .name = "ldo1" },
[AS3711_REGULATOR_LDO_2] = { .name = "ldo2" },
[AS3711_REGULATOR_LDO_3] = { .name = "ldo3" },
[AS3711_REGULATOR_LDO_4] = { .name = "ldo4" },
[AS3711_REGULATOR_LDO_5] = { .name = "ldo5" },
[AS3711_REGULATOR_LDO_6] = { .name = "ldo6" },
[AS3711_REGULATOR_LDO_7] = { .name = "ldo7" },
[AS3711_REGULATOR_LDO_8] = { .name = "ldo8" },
};
static int as3711_regulator_parse_dt(struct device *dev,
struct device_node **of_node, const int count)
{
struct as3711_regulator_pdata *pdata = dev_get_platdata(dev);
struct device_node *regulators =
of_find_node_by_name(dev->parent->of_node, "regulators");
struct of_regulator_match *match;
int ret, i;
if (!regulators) {
dev_err(dev, "regulator node not found\n");
return -ENODEV;
}
ret = of_regulator_match(dev->parent, regulators,
as3711_regulator_matches, count);
of_node_put(regulators);
if (ret < 0) {
dev_err(dev, "Error parsing regulator init data: %d\n", ret);
return ret;
}
for (i = 0, match = as3711_regulator_matches; i < count; i++, match++)
if (match->of_node) {
pdata->init_data[i] = match->init_data;
of_node[i] = match->of_node;
}
return 0;
}
static int as3711_regulator_probe(struct platform_device *pdev)
{
struct as3711_regulator_pdata *pdata = dev_get_platdata(&pdev->dev);
......@@ -284,13 +333,24 @@ static int as3711_regulator_probe(struct platform_device *pdev)
struct regulator_config config = {.dev = &pdev->dev,};
struct as3711_regulator *reg = NULL;
struct as3711_regulator *regs;
struct device_node *of_node[AS3711_REGULATOR_NUM] = {};
struct regulator_dev *rdev;
struct as3711_regulator_info *ri;
int ret;
int id;
if (!pdata)
dev_dbg(&pdev->dev, "No platform data...\n");
if (!pdata) {
dev_err(&pdev->dev, "No platform data...\n");
return -ENODEV;
}
if (pdev->dev.parent->of_node) {
ret = as3711_regulator_parse_dt(&pdev->dev, of_node, AS3711_REGULATOR_NUM);
if (ret < 0) {
dev_err(&pdev->dev, "DT parsing failed: %d\n", ret);
return ret;
}
}
regs = devm_kzalloc(&pdev->dev, AS3711_REGULATOR_NUM *
sizeof(struct as3711_regulator), GFP_KERNEL);
......@@ -300,7 +360,7 @@ static int as3711_regulator_probe(struct platform_device *pdev)
}
for (id = 0, ri = as3711_reg_info; id < AS3711_REGULATOR_NUM; ++id, ri++) {
reg_data = pdata ? pdata->init_data[id] : NULL;
reg_data = pdata->init_data[id];
/* No need to register if there is no regulator data */
if (!reg_data)
......@@ -312,6 +372,7 @@ static int as3711_regulator_probe(struct platform_device *pdev)
config.init_data = reg_data;
config.driver_data = reg;
config.regmap = as3711->regmap;
config.of_node = of_node[id];
rdev = regulator_register(&ri->desc, &config);
if (IS_ERR(rdev)) {
......
......@@ -51,6 +51,7 @@
static DEFINE_MUTEX(regulator_list_mutex);
static LIST_HEAD(regulator_list);
static LIST_HEAD(regulator_map_list);
static LIST_HEAD(regulator_ena_gpio_list);
static bool has_full_constraints;
static bool board_wants_dummy_regulator;
......@@ -68,6 +69,19 @@ struct regulator_map {
struct regulator_dev *regulator;
};
/*
* struct regulator_enable_gpio
*
* Management for shared enable GPIO pin
*/
struct regulator_enable_gpio {
struct list_head list;
int gpio;
u32 enable_count; /* a number of enabled shared GPIO */
u32 request_count; /* a number of requested shared GPIO */
unsigned int ena_gpio_invert:1;
};
/*
* struct regulator
*
......@@ -116,7 +130,7 @@ static const char *rdev_get_name(struct regulator_dev *rdev)
* @supply: regulator supply name
*
* Extract the regulator device node corresponding to the supply name.
* retruns the device node corresponding to the regulator if found, else
* returns the device node corresponding to the regulator if found, else
* returns NULL.
*/
static struct device_node *of_get_regulator(struct device *dev, const char *supply)
......@@ -1229,7 +1243,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
struct regulator_dev *rdev;
struct regulator *regulator = ERR_PTR(-EPROBE_DEFER);
const char *devname = NULL;
int ret;
int ret = 0;
if (id == NULL) {
pr_err("get() with no identifier\n");
......@@ -1245,6 +1259,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
if (rdev)
goto found;
/*
* If we have return value from dev_lookup fail, we do not expect to
* succeed, so, quit with appropriate error value
*/
if (ret) {
regulator = ERR_PTR(ret);
goto out;
}
if (board_wants_dummy_regulator) {
rdev = dummy_regulator_rdev;
goto found;
......@@ -1456,6 +1479,101 @@ void devm_regulator_put(struct regulator *regulator)
}
EXPORT_SYMBOL_GPL(devm_regulator_put);
/* Manage enable GPIO list. Same GPIO pin can be shared among regulators */
static int regulator_ena_gpio_request(struct regulator_dev *rdev,
const struct regulator_config *config)
{
struct regulator_enable_gpio *pin;
int ret;
list_for_each_entry(pin, &regulator_ena_gpio_list, list) {
if (pin->gpio == config->ena_gpio) {
rdev_dbg(rdev, "GPIO %d is already used\n",
config->ena_gpio);
goto update_ena_gpio_to_rdev;
}
}
ret = gpio_request_one(config->ena_gpio,
GPIOF_DIR_OUT | config->ena_gpio_flags,
rdev_get_name(rdev));
if (ret)
return ret;
pin = kzalloc(sizeof(struct regulator_enable_gpio), GFP_KERNEL);
if (pin == NULL) {
gpio_free(config->ena_gpio);
return -ENOMEM;
}
pin->gpio = config->ena_gpio;
pin->ena_gpio_invert = config->ena_gpio_invert;
list_add(&pin->list, &regulator_ena_gpio_list);
update_ena_gpio_to_rdev:
pin->request_count++;
rdev->ena_pin = pin;
return 0;
}
static void regulator_ena_gpio_free(struct regulator_dev *rdev)
{
struct regulator_enable_gpio *pin, *n;
if (!rdev->ena_pin)
return;
/* Free the GPIO only in case of no use */
list_for_each_entry_safe(pin, n, &regulator_ena_gpio_list, list) {
if (pin->gpio == rdev->ena_pin->gpio) {
if (pin->request_count <= 1) {
pin->request_count = 0;
gpio_free(pin->gpio);
list_del(&pin->list);
kfree(pin);
} else {
pin->request_count--;
}
}
}
}
/**
* Balance enable_count of each GPIO and actual GPIO pin control.
* GPIO is enabled in case of initial use. (enable_count is 0)
* GPIO is disabled when it is not shared any more. (enable_count <= 1)
*/
static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
{
struct regulator_enable_gpio *pin = rdev->ena_pin;
if (!pin)
return -EINVAL;
if (enable) {
/* Enable GPIO at initial use */
if (pin->enable_count == 0)
gpio_set_value_cansleep(pin->gpio,
!pin->ena_gpio_invert);
pin->enable_count++;
} else {
if (pin->enable_count > 1) {
pin->enable_count--;
return 0;
}
/* Disable GPIO if not used */
if (pin->enable_count <= 1) {
gpio_set_value_cansleep(pin->gpio,
pin->ena_gpio_invert);
pin->enable_count = 0;
}
}
return 0;
}
static int _regulator_do_enable(struct regulator_dev *rdev)
{
int ret, delay;
......@@ -1471,9 +1589,10 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
trace_regulator_enable(rdev_get_name(rdev));
if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
!rdev->ena_gpio_invert);
if (rdev->ena_pin) {
ret = regulator_ena_gpio_ctrl(rdev, true);
if (ret < 0)
return ret;
rdev->ena_gpio_state = 1;
} else if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
......@@ -1575,9 +1694,10 @@ static int _regulator_do_disable(struct regulator_dev *rdev)
trace_regulator_disable(rdev_get_name(rdev));
if (rdev->ena_gpio) {
gpio_set_value_cansleep(rdev->ena_gpio,
rdev->ena_gpio_invert);
if (rdev->ena_pin) {
ret = regulator_ena_gpio_ctrl(rdev, false);
if (ret < 0)
return ret;
rdev->ena_gpio_state = 0;
} else if (rdev->desc->ops->disable) {
......@@ -1794,7 +1914,10 @@ int regulator_is_enabled_regmap(struct regulator_dev *rdev)
if (ret != 0)
return ret;
return (val & rdev->desc->enable_mask) != 0;
if (rdev->desc->enable_is_inverted)
return (val & rdev->desc->enable_mask) == 0;
else
return (val & rdev->desc->enable_mask) != 0;
}
EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
......@@ -1809,9 +1932,15 @@ EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
*/
int regulator_enable_regmap(struct regulator_dev *rdev)
{
unsigned int val;
if (rdev->desc->enable_is_inverted)
val = 0;
else
val = rdev->desc->enable_mask;
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask,
rdev->desc->enable_mask);
rdev->desc->enable_mask, val);
}
EXPORT_SYMBOL_GPL(regulator_enable_regmap);
......@@ -1826,15 +1955,22 @@ EXPORT_SYMBOL_GPL(regulator_enable_regmap);
*/
int regulator_disable_regmap(struct regulator_dev *rdev)
{
unsigned int val;
if (rdev->desc->enable_is_inverted)
val = rdev->desc->enable_mask;
else
val = 0;
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, 0);
rdev->desc->enable_mask, val);
}
EXPORT_SYMBOL_GPL(regulator_disable_regmap);
static int _regulator_is_enabled(struct regulator_dev *rdev)
{
/* A GPIO control always takes precedence */
if (rdev->ena_gpio)
if (rdev->ena_pin)
return rdev->ena_gpio_state;
/* If we don't know then assume that the regulator is always on */
......@@ -2137,6 +2273,37 @@ int regulator_map_voltage_iterate(struct regulator_dev *rdev,
}
EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
/**
* regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
*
* @rdev: Regulator to operate on
* @min_uV: Lower bound for voltage
* @max_uV: Upper bound for voltage
*
* Drivers that have ascendant voltage list can use this as their
* map_voltage() operation.
*/
int regulator_map_voltage_ascend(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
int i, ret;
for (i = 0; i < rdev->desc->n_voltages; i++) {
ret = rdev->desc->ops->list_voltage(rdev, i);
if (ret < 0)
continue;
if (ret > max_uV)
break;
if (ret >= min_uV && ret <= max_uV)
return i;
}
return -EINVAL;
}
EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
/**
* regulator_map_voltage_linear - map_voltage() for simple linear mappings
*
......@@ -3237,7 +3404,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
if (status < 0)
return status;
}
if (rdev->ena_gpio || ops->is_enabled) {
if (rdev->ena_pin || ops->is_enabled) {
status = device_create_file(dev, &dev_attr_state);
if (status < 0)
return status;
......@@ -3439,22 +3606,17 @@ regulator_register(const struct regulator_desc *regulator_desc,
dev_set_drvdata(&rdev->dev, rdev);
if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) {
ret = gpio_request_one(config->ena_gpio,
GPIOF_DIR_OUT | config->ena_gpio_flags,
rdev_get_name(rdev));
ret = regulator_ena_gpio_request(rdev, config);
if (ret != 0) {
rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
config->ena_gpio, ret);
goto wash;
}
rdev->ena_gpio = config->ena_gpio;
rdev->ena_gpio_invert = config->ena_gpio_invert;
if (config->ena_gpio_flags & GPIOF_OUT_INIT_HIGH)
rdev->ena_gpio_state = 1;
if (rdev->ena_gpio_invert)
if (config->ena_gpio_invert)
rdev->ena_gpio_state = !rdev->ena_gpio_state;
}
......@@ -3481,7 +3643,14 @@ regulator_register(const struct regulator_desc *regulator_desc,
r = regulator_dev_lookup(dev, supply, &ret);
if (!r) {
if (ret == -ENODEV) {
/*
* No supply was specified for this regulator and
* there will never be one.
*/
ret = 0;
goto add_dev;
} else if (!r) {
dev_err(dev, "Failed to find supply %s\n", supply);
ret = -EPROBE_DEFER;
goto scrub;
......@@ -3499,6 +3668,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
}
}
add_dev:
/* add consumers devices */
if (init_data) {
for (i = 0; i < init_data->num_consumer_supplies; i++) {
......@@ -3526,8 +3696,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
scrub:
if (rdev->supply)
_regulator_put(rdev->supply);
if (rdev->ena_gpio)
gpio_free(rdev->ena_gpio);
regulator_ena_gpio_free(rdev);
kfree(rdev->constraints);
wash:
device_unregister(&rdev->dev);
......@@ -3562,8 +3731,7 @@ void regulator_unregister(struct regulator_dev *rdev)
unset_regulator_supplies(rdev);
list_del(&rdev->list);
kfree(rdev->constraints);
if (rdev->ena_gpio)
gpio_free(rdev->ena_gpio);
regulator_ena_gpio_free(rdev);
device_unregister(&rdev->dev);
mutex_unlock(&regulator_list_mutex);
}
......
......@@ -21,7 +21,6 @@
* @is_enabled: status of the regulator
* @epod_id: id for EPOD (power domain)
* @is_ramret: RAM retention switch for EPOD (power domain)
* @operating_point: operating point (only for vape, to be removed)
*
*/
struct dbx500_regulator_info {
......@@ -32,7 +31,6 @@ struct dbx500_regulator_info {
u16 epod_id;
bool is_ramret;
bool exclude_from_power_state;
unsigned int operating_point;
};
void power_state_active_enable(void);
......
......@@ -219,9 +219,7 @@ static int fan53555_regulator_register(struct fan53555_device_info *di,
rdesc->owner = THIS_MODULE;
di->rdev = regulator_register(&di->desc, config);
if (IS_ERR(di->rdev))
return PTR_ERR(di->rdev);
return 0;
return PTR_RET(di->rdev);
}
......
......@@ -163,6 +163,7 @@ static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev,
static struct regulator_ops lp3971_ldo_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.is_enabled = lp3971_ldo_is_enabled,
.enable = lp3971_ldo_enable,
.disable = lp3971_ldo_disable,
......@@ -236,6 +237,7 @@ static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev,
static struct regulator_ops lp3971_dcdc_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.is_enabled = lp3971_dcdc_is_enabled,
.enable = lp3971_dcdc_enable,
.disable = lp3971_dcdc_disable,
......
......@@ -309,6 +309,7 @@ static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev,
static struct regulator_ops lp3972_ldo_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.is_enabled = lp3972_ldo_is_enabled,
.enable = lp3972_ldo_enable,
.disable = lp3972_ldo_disable,
......@@ -389,6 +390,7 @@ static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev,
static struct regulator_ops lp3972_dcdc_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.is_enabled = lp3972_dcdc_is_enabled,
.enable = lp3972_dcdc_enable,
.disable = lp3972_dcdc_disable,
......
......@@ -478,6 +478,7 @@ static unsigned int lp872x_buck_get_mode(struct regulator_dev *rdev)
static struct regulator_ops lp872x_ldo_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.enable = regulator_enable_regmap,
......@@ -488,6 +489,7 @@ static struct regulator_ops lp872x_ldo_ops = {
static struct regulator_ops lp8720_buck_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_voltage_sel = lp872x_buck_set_voltage_sel,
.get_voltage_sel = lp872x_buck_get_voltage_sel,
.enable = regulator_enable_regmap,
......@@ -500,6 +502,7 @@ static struct regulator_ops lp8720_buck_ops = {
static struct regulator_ops lp8725_buck_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_voltage_sel = lp872x_buck_set_voltage_sel,
.get_voltage_sel = lp872x_buck_get_voltage_sel,
.enable = regulator_enable_regmap,
......
......@@ -346,6 +346,7 @@ static unsigned int lp8788_buck_get_mode(struct regulator_dev *rdev)
static struct regulator_ops lp8788_buck12_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_voltage_sel = lp8788_buck12_set_voltage_sel,
.get_voltage_sel = lp8788_buck12_get_voltage_sel,
.enable = regulator_enable_regmap,
......@@ -358,6 +359,7 @@ static struct regulator_ops lp8788_buck12_ops = {
static struct regulator_ops lp8788_buck34_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.enable = regulator_enable_regmap,
......
......@@ -156,68 +156,6 @@ static const int lp8788_aldo7_vtbl[] = {
1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1800000,
};
static enum lp8788_ldo_id lp8788_dldo_id[] = {
DLDO1,
DLDO2,
DLDO3,
DLDO4,
DLDO5,
DLDO6,
DLDO7,
DLDO8,
DLDO9,
DLDO10,
DLDO11,
DLDO12,
};
static enum lp8788_ldo_id lp8788_aldo_id[] = {
ALDO1,
ALDO2,
ALDO3,
ALDO4,
ALDO5,
ALDO6,
ALDO7,
ALDO8,
ALDO9,
ALDO10,
};
static int lp8788_ldo_enable(struct regulator_dev *rdev)
{
struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
if (ldo->en_pin) {
gpio_set_value(ldo->en_pin->gpio, ENABLE);
return 0;
} else {
return regulator_enable_regmap(rdev);
}
}
static int lp8788_ldo_disable(struct regulator_dev *rdev)
{
struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
if (ldo->en_pin) {
gpio_set_value(ldo->en_pin->gpio, DISABLE);
return 0;
} else {
return regulator_disable_regmap(rdev);
}
}
static int lp8788_ldo_is_enabled(struct regulator_dev *rdev)
{
struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
if (ldo->en_pin)
return gpio_get_value(ldo->en_pin->gpio) ? 1 : 0;
else
return regulator_is_enabled_regmap(rdev);
}
static int lp8788_ldo_enable_time(struct regulator_dev *rdev)
{
struct lp8788_ldo *ldo = rdev_get_drvdata(rdev);
......@@ -232,38 +170,21 @@ static int lp8788_ldo_enable_time(struct regulator_dev *rdev)
return ENABLE_TIME_USEC * val;
}
static int lp8788_ldo_fixed_get_voltage(struct regulator_dev *rdev)
{
enum lp8788_ldo_id id = rdev_get_id(rdev);
switch (id) {
case ALDO2 ... ALDO5:
return 2850000;
case DLDO12:
case ALDO8 ... ALDO9:
return 2500000;
case ALDO10:
return 1100000;
default:
return -EINVAL;
}
}
static struct regulator_ops lp8788_ldo_voltage_table_ops = {
.list_voltage = regulator_list_voltage_table,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.enable = lp8788_ldo_enable,
.disable = lp8788_ldo_disable,
.is_enabled = lp8788_ldo_is_enabled,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
.enable_time = lp8788_ldo_enable_time,
};
static struct regulator_ops lp8788_ldo_voltage_fixed_ops = {
.get_voltage = lp8788_ldo_fixed_get_voltage,
.enable = lp8788_ldo_enable,
.disable = lp8788_ldo_disable,
.is_enabled = lp8788_ldo_is_enabled,
.list_voltage = regulator_list_voltage_linear,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
.enable_time = lp8788_ldo_enable_time,
};
......@@ -420,6 +341,7 @@ static struct regulator_desc lp8788_dldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_B,
.enable_mask = LP8788_EN_DLDO12_M,
.min_uV = 2500000,
},
};
......@@ -446,6 +368,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_B,
.enable_mask = LP8788_EN_ALDO2_M,
.min_uV = 2850000,
},
{
.name = "aldo3",
......@@ -456,6 +379,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_B,
.enable_mask = LP8788_EN_ALDO3_M,
.min_uV = 2850000,
},
{
.name = "aldo4",
......@@ -466,6 +390,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_B,
.enable_mask = LP8788_EN_ALDO4_M,
.min_uV = 2850000,
},
{
.name = "aldo5",
......@@ -476,6 +401,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_C,
.enable_mask = LP8788_EN_ALDO5_M,
.min_uV = 2850000,
},
{
.name = "aldo6",
......@@ -512,6 +438,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_C,
.enable_mask = LP8788_EN_ALDO8_M,
.min_uV = 2500000,
},
{
.name = "aldo9",
......@@ -522,6 +449,7 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_C,
.enable_mask = LP8788_EN_ALDO9_M,
.min_uV = 2500000,
},
{
.name = "aldo10",
......@@ -532,46 +460,14 @@ static struct regulator_desc lp8788_aldo_desc[] = {
.owner = THIS_MODULE,
.enable_reg = LP8788_EN_LDO_C,
.enable_mask = LP8788_EN_ALDO10_M,
.min_uV = 1100000,
},
};
static int lp8788_gpio_request_ldo_en(struct platform_device *pdev,
struct lp8788_ldo *ldo,
enum lp8788_ext_ldo_en_id id)
{
struct device *dev = &pdev->dev;
struct lp8788_ldo_enable_pin *pin = ldo->en_pin;
int ret, gpio, pinstate;
char *name[] = {
[EN_ALDO1] = "LP8788_EN_ALDO1",
[EN_ALDO234] = "LP8788_EN_ALDO234",
[EN_ALDO5] = "LP8788_EN_ALDO5",
[EN_ALDO7] = "LP8788_EN_ALDO7",
[EN_DLDO7] = "LP8788_EN_DLDO7",
[EN_DLDO911] = "LP8788_EN_DLDO911",
};
gpio = pin->gpio;
if (!gpio_is_valid(gpio)) {
dev_err(dev, "invalid gpio: %d\n", gpio);
return -EINVAL;
}
pinstate = pin->init_state;
ret = devm_gpio_request_one(dev, gpio, pinstate, name[id]);
if (ret == -EBUSY) {
dev_warn(dev, "gpio%d already used\n", gpio);
return 0;
}
return ret;
}
static int lp8788_config_ldo_enable_mode(struct platform_device *pdev,
struct lp8788_ldo *ldo,
enum lp8788_ldo_id id)
{
int ret;
struct lp8788 *lp = ldo->lp;
struct lp8788_platform_data *pdata = lp->pdata;
enum lp8788_ext_ldo_en_id enable_id;
......@@ -613,14 +509,7 @@ static int lp8788_config_ldo_enable_mode(struct platform_device *pdev,
goto set_default_ldo_enable_mode;
ldo->en_pin = pdata->ldo_pin[enable_id];
ret = lp8788_gpio_request_ldo_en(pdev, ldo, enable_id);
if (ret) {
ldo->en_pin = NULL;
goto set_default_ldo_enable_mode;
}
return ret;
return 0;
set_default_ldo_enable_mode:
return lp8788_update_bits(lp, LP8788_EN_SEL, en_mask[enable_id], 0);
......@@ -640,10 +529,15 @@ static int lp8788_dldo_probe(struct platform_device *pdev)
return -ENOMEM;
ldo->lp = lp;
ret = lp8788_config_ldo_enable_mode(pdev, ldo, lp8788_dldo_id[id]);
ret = lp8788_config_ldo_enable_mode(pdev, ldo, id);
if (ret)
return ret;
if (ldo->en_pin) {
cfg.ena_gpio = ldo->en_pin->gpio;
cfg.ena_gpio_flags = ldo->en_pin->init_state;
}
cfg.dev = pdev->dev.parent;
cfg.init_data = lp->pdata ? lp->pdata->dldo_data[id] : NULL;
cfg.driver_data = ldo;
......@@ -696,10 +590,15 @@ static int lp8788_aldo_probe(struct platform_device *pdev)
return -ENOMEM;
ldo->lp = lp;
ret = lp8788_config_ldo_enable_mode(pdev, ldo, lp8788_aldo_id[id]);
ret = lp8788_config_ldo_enable_mode(pdev, ldo, id + ALDO1);
if (ret)
return ret;
if (ldo->en_pin) {
cfg.ena_gpio = ldo->en_pin->gpio;
cfg.ena_gpio_flags = ldo->en_pin->init_state;
}
cfg.dev = pdev->dev.parent;
cfg.init_data = lp->pdata ? lp->pdata->aldo_data[id] : NULL;
cfg.driver_data = ldo;
......
......@@ -56,7 +56,7 @@ struct max1586_data {
* set V6 to either 0V, 1.8V, 2.5V, 3V depending on (x & 0x3)
* As regulator framework doesn't accept voltages to be 0V, we use 1uV.
*/
static int v6_voltages_uv[] = { 1, 1800000, 2500000, 3000000 };
static const unsigned int v6_voltages_uv[] = { 1, 1800000, 2500000, 3000000 };
/*
* V3 voltage
......@@ -232,8 +232,7 @@ static int max1586_pmic_remove(struct i2c_client *client)
int i;
for (i = 0; i <= MAX1586_V6; i++)
if (max1586->rdev[i])
regulator_unregister(max1586->rdev[i]);
regulator_unregister(max1586->rdev[i]);
return 0;
}
......
......@@ -75,17 +75,20 @@ static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev)
{
unsigned int val;
struct max77686_data *max77686 = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
int ret, id = rdev_get_id(rdev);
if (id == MAX77686_BUCK1)
val = 0x1;
else
val = 0x1 << MAX77686_OPMODE_BUCK234_SHIFT;
ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val);
if (ret)
return ret;
max77686->opmode[id] = val;
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask,
val);
return 0;
}
/* Some LDOs supports [LPM/Normal]ON mode during suspend state */
......@@ -94,7 +97,7 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev,
{
struct max77686_data *max77686 = rdev_get_drvdata(rdev);
unsigned int val;
int id = rdev_get_id(rdev);
int ret, id = rdev_get_id(rdev);
/* BUCK[5-9] doesn't support this feature */
if (id >= MAX77686_BUCK5)
......@@ -113,10 +116,13 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev,
return -EINVAL;
}
ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val);
if (ret)
return ret;
max77686->opmode[id] = val;
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask,
val);
return 0;
}
/* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
......@@ -125,6 +131,7 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
{
unsigned int val;
struct max77686_data *max77686 = rdev_get_drvdata(rdev);
int ret;
switch (mode) {
case REGULATOR_MODE_STANDBY: /* switch off */
......@@ -142,10 +149,13 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
return -EINVAL;
}
ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val);
if (ret)
return ret;
max77686->opmode[rdev_get_id(rdev)] = val;
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask,
val);
return 0;
}
static int max77686_enable(struct regulator_dev *rdev)
......
......@@ -60,36 +60,6 @@ struct max8649_regulator_info {
unsigned ramp_down:1;
};
/* EN_PD means pulldown on EN input */
static int max8649_enable(struct regulator_dev *rdev)
{
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
return regmap_update_bits(info->regmap, MAX8649_CONTROL, MAX8649_EN_PD, 0);
}
/*
* Applied internal pulldown resistor on EN input pin.
* If pulldown EN pin outside, it would be better.
*/
static int max8649_disable(struct regulator_dev *rdev)
{
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
return regmap_update_bits(info->regmap, MAX8649_CONTROL, MAX8649_EN_PD,
MAX8649_EN_PD);
}
static int max8649_is_enabled(struct regulator_dev *rdev)
{
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
unsigned int val;
int ret;
ret = regmap_read(info->regmap, MAX8649_CONTROL, &val);
if (ret != 0)
return ret;
return !((unsigned char)val & MAX8649_EN_PD);
}
static int max8649_enable_time(struct regulator_dev *rdev)
{
struct max8649_regulator_info *info = rdev_get_drvdata(rdev);
......@@ -151,9 +121,9 @@ static struct regulator_ops max8649_dcdc_ops = {
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.list_voltage = regulator_list_voltage_linear,
.map_voltage = regulator_map_voltage_linear,
.enable = max8649_enable,
.disable = max8649_disable,
.is_enabled = max8649_is_enabled,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
.enable_time = max8649_enable_time,
.set_mode = max8649_set_mode,
.get_mode = max8649_get_mode,
......@@ -169,6 +139,9 @@ static struct regulator_desc dcdc_desc = {
.vsel_mask = MAX8649_VOL_MASK,
.min_uV = MAX8649_DCDC_VMIN,
.uV_step = MAX8649_DCDC_STEP,
.enable_reg = MAX8649_CONTROL,
.enable_mask = MAX8649_EN_PD,
.enable_is_inverted = true,
};
static struct regmap_config max8649_regmap_config = {
......@@ -275,10 +248,8 @@ static int max8649_regulator_remove(struct i2c_client *client)
{
struct max8649_regulator_info *info = i2c_get_clientdata(client);
if (info) {
if (info->regulator)
regulator_unregister(info->regulator);
}
if (info)
regulator_unregister(info->regulator);
return 0;
}
......
......@@ -426,8 +426,7 @@ static int max8660_remove(struct i2c_client *client)
int i;
for (i = 0; i < MAX8660_V_END; i++)
if (max8660->rdev[i])
regulator_unregister(max8660->rdev[i]);
regulator_unregister(max8660->rdev[i]);
return 0;
}
......
......@@ -246,7 +246,6 @@ static struct max8925_regulator_info max8925_regulator_info[] = {
#ifdef CONFIG_OF
static int max8925_regulator_dt_init(struct platform_device *pdev,
struct max8925_regulator_info *info,
struct regulator_config *config,
int ridx)
{
......@@ -272,7 +271,7 @@ static int max8925_regulator_dt_init(struct platform_device *pdev,
return 0;
}
#else
#define max8925_regulator_dt_init(w, x, y, z) (-1)
#define max8925_regulator_dt_init(x, y, z) (-1)
#endif
static int max8925_regulator_probe(struct platform_device *pdev)
......@@ -309,7 +308,7 @@ static int max8925_regulator_probe(struct platform_device *pdev)
config.dev = &pdev->dev;
config.driver_data = ri;
if (max8925_regulator_dt_init(pdev, ri, &config, regulator_idx))
if (max8925_regulator_dt_init(pdev, &config, regulator_idx))
if (pdata)
config.init_data = pdata;
......
......@@ -28,6 +28,9 @@
#include <linux/regulator/max8952.h>
#include <linux/gpio.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/regulator/of_regulator.h>
#include <linux/slab.h>
/* Registers */
......@@ -126,6 +129,69 @@ static const struct regulator_desc regulator = {
.owner = THIS_MODULE,
};
#ifdef CONFIG_OF
static struct of_device_id max8952_dt_match[] = {
{ .compatible = "maxim,max8952" },
{},
};
MODULE_DEVICE_TABLE(of, max8952_dt_match);
static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
{
struct max8952_platform_data *pd;
struct device_node *np = dev->of_node;
int ret;
int i;
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
if (!pd) {
dev_err(dev, "Failed to allocate platform data\n");
return NULL;
}
pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0);
pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1);
pd->gpio_en = of_get_named_gpio(np, "max8952,en-gpio", 0);
if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode))
dev_warn(dev, "Default mode not specified, assuming 0\n");
ret = of_property_read_u32_array(np, "max8952,dvs-mode-microvolt",
pd->dvs_mode, ARRAY_SIZE(pd->dvs_mode));
if (ret) {
dev_err(dev, "max8952,dvs-mode-microvolt property not specified");
return NULL;
}
for (i = 0; i < ARRAY_SIZE(pd->dvs_mode); ++i) {
if (pd->dvs_mode[i] < 770000 || pd->dvs_mode[i] > 1400000) {
dev_err(dev, "DVS voltage %d out of range\n", i);
return NULL;
}
pd->dvs_mode[i] = (pd->dvs_mode[i] - 770000) / 10000;
}
if (of_property_read_u32(np, "max8952,sync-freq", &pd->sync_freq))
dev_warn(dev, "max8952,sync-freq property not specified, defaulting to 26MHz\n");
if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed))
dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n");
pd->reg_data = of_get_regulator_init_data(dev, np);
if (!pd->reg_data) {
dev_err(dev, "Failed to parse regulator init data\n");
return NULL;
}
return pd;
}
#else
static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
{
return NULL;
}
#endif
static int max8952_pmic_probe(struct i2c_client *client,
const struct i2c_device_id *i2c_id)
{
......@@ -136,6 +202,9 @@ static int max8952_pmic_probe(struct i2c_client *client,
int ret = 0, err = 0;
if (client->dev.of_node)
pdata = max8952_parse_dt(&client->dev);
if (!pdata) {
dev_err(&client->dev, "Require the platform data\n");
return -EINVAL;
......@@ -154,11 +223,12 @@ static int max8952_pmic_probe(struct i2c_client *client,
max8952->pdata = pdata;
config.dev = max8952->dev;
config.init_data = &pdata->reg_data;
config.init_data = pdata->reg_data;
config.driver_data = max8952;
config.of_node = client->dev.of_node;
config.ena_gpio = pdata->gpio_en;
if (pdata->reg_data.constraints.boot_on)
if (pdata->reg_data->constraints.boot_on)
config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
max8952->rdev = regulator_register(&regulator, &config);
......@@ -271,6 +341,7 @@ static struct i2c_driver max8952_pmic_driver = {
.remove = max8952_pmic_remove,
.driver = {
.name = "max8952",
.of_match_table = of_match_ptr(max8952_dt_match),
},
.id_table = max8952_ids,
};
......
......@@ -274,15 +274,15 @@ static int max8973_init_dcdc(struct max8973_chip *max,
if (pdata->reg_init_data &&
pdata->reg_init_data->constraints.ramp_delay) {
if (pdata->reg_init_data->constraints.ramp_delay < 25000)
control1 = MAX8973_RAMP_12mV_PER_US;
control1 |= MAX8973_RAMP_12mV_PER_US;
else if (pdata->reg_init_data->constraints.ramp_delay < 50000)
control1 = MAX8973_RAMP_25mV_PER_US;
control1 |= MAX8973_RAMP_25mV_PER_US;
else if (pdata->reg_init_data->constraints.ramp_delay < 200000)
control1 = MAX8973_RAMP_50mV_PER_US;
control1 |= MAX8973_RAMP_50mV_PER_US;
else
control1 = MAX8973_RAMP_200mV_PER_US;
control1 |= MAX8973_RAMP_200mV_PER_US;
} else {
control1 = MAX8973_RAMP_12mV_PER_US;
control1 |= MAX8973_RAMP_12mV_PER_US;
max->desc.ramp_delay = 12500;
}
......
......@@ -1035,8 +1035,8 @@ static int max8997_pmic_probe(struct platform_device *pdev)
int i, ret, size, nr_dvs;
u8 max_buck1 = 0, max_buck2 = 0, max_buck5 = 0;
if (IS_ERR_OR_NULL(pdata)) {
dev_err(pdev->dev.parent, "No platform init data supplied.\n");
if (!pdata) {
dev_err(&pdev->dev, "No platform init data supplied.\n");
return -ENODEV;
}
......
......@@ -665,14 +665,16 @@ static int max8998_pmic_probe(struct platform_device *pdev)
gpio_is_valid(pdata->buck1_set2)) {
/* Check if SET1 is not equal to 0 */
if (!pdata->buck1_set1) {
printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n");
dev_err(&pdev->dev,
"MAX8998 SET1 GPIO defined as 0 !\n");
WARN_ON(!pdata->buck1_set1);
ret = -EIO;
goto err_out;
}
/* Check if SET2 is not equal to 0 */
if (!pdata->buck1_set2) {
printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n");
dev_err(&pdev->dev,
"MAX8998 SET2 GPIO defined as 0 !\n");
WARN_ON(!pdata->buck1_set2);
ret = -EIO;
goto err_out;
......@@ -738,7 +740,8 @@ static int max8998_pmic_probe(struct platform_device *pdev)
if (gpio_is_valid(pdata->buck2_set3)) {
/* Check if SET3 is not equal to 0 */
if (!pdata->buck2_set3) {
printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n");
dev_err(&pdev->dev,
"MAX8998 SET3 GPIO defined as 0 !\n");
WARN_ON(!pdata->buck2_set3);
ret = -EIO;
goto err_out;
......
......@@ -398,33 +398,51 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
struct mc13xxx_regulator_platform_data *pdata =
dev_get_platdata(&pdev->dev);
struct mc13xxx_regulator_init_data *init_data;
struct mc13xxx_regulator_init_data *mc13xxx_data;
struct regulator_config config = { };
int i, ret;
int i, ret, num_regulators;
dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id);
num_regulators = mc13xxx_get_num_regulators_dt(pdev);
if (!pdata)
if (num_regulators <= 0 && pdata)
num_regulators = pdata->num_regulators;
if (num_regulators <= 0)
return -EINVAL;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv) +
pdata->num_regulators * sizeof(priv->regulators[0]),
num_regulators * sizeof(priv->regulators[0]),
GFP_KERNEL);
if (!priv)
return -ENOMEM;
priv->num_regulators = num_regulators;
priv->mc13xxx_regulators = mc13783_regulators;
priv->mc13xxx = mc13783;
platform_set_drvdata(pdev, priv);
for (i = 0; i < pdata->num_regulators; i++) {
struct regulator_desc *desc;
mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13783_regulators,
ARRAY_SIZE(mc13783_regulators));
init_data = &pdata->regulators[i];
desc = &mc13783_regulators[init_data->id].desc;
for (i = 0; i < priv->num_regulators; i++) {
struct regulator_init_data *init_data;
struct regulator_desc *desc;
struct device_node *node = NULL;
int id;
if (mc13xxx_data) {
id = mc13xxx_data[i].id;
init_data = mc13xxx_data[i].init_data;
node = mc13xxx_data[i].node;
} else {
id = pdata->regulators[i].id;
init_data = pdata->regulators[i].init_data;
}
desc = &mc13783_regulators[id].desc;
config.dev = &pdev->dev;
config.init_data = init_data->init_data;
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])) {
......@@ -435,8 +453,6 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
}
}
platform_set_drvdata(pdev, priv);
return 0;
err:
while (--i >= 0)
......@@ -448,13 +464,11 @@ static int mc13783_regulator_probe(struct platform_device *pdev)
static int mc13783_regulator_remove(struct platform_device *pdev)
{
struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
struct mc13xxx_regulator_platform_data *pdata =
dev_get_platdata(&pdev->dev);
int i;
platform_set_drvdata(pdev, NULL);
for (i = 0; i < pdata->num_regulators; i++)
for (i = 0; i < priv->num_regulators; i++)
regulator_unregister(priv->regulators[i]);
return 0;
......
......@@ -465,13 +465,13 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
*/
if (mc13892_regulators[id].vsel_reg != MC13892_SWITCHERS0) {
mask |= MC13892_SWITCHERS0_SWxHI;
if (volt > 1375000) {
reg_value -= MC13892_SWxHI_SEL_OFFSET;
reg_value |= MC13892_SWITCHERS0_SWxHI;
mask |= MC13892_SWITCHERS0_SWxHI;
} else if (volt < 1100000) {
} else {
reg_value &= ~MC13892_SWITCHERS0_SWxHI;
mask |= MC13892_SWITCHERS0_SWxHI;
}
}
......@@ -485,6 +485,7 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
static struct regulator_ops mc13892_sw_regulator_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
.get_voltage_sel = mc13892_sw_regulator_get_voltage_sel,
};
......@@ -535,7 +536,7 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
struct mc13xxx_regulator_init_data *mc13xxx_data;
struct regulator_config config = { };
int i, ret;
int num_regulators = 0, num_parsed;
int num_regulators = 0;
u32 val;
num_regulators = mc13xxx_get_num_regulators_dt(pdev);
......@@ -545,8 +546,6 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
if (num_regulators <= 0)
return -EINVAL;
num_parsed = num_regulators;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv) +
num_regulators * sizeof(priv->regulators[0]),
GFP_KERNEL);
......@@ -589,40 +588,9 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
= mc13892_vcam_get_mode;
mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
ARRAY_SIZE(mc13892_regulators),
&num_parsed);
/*
* Perform a little sanity check on the regulator tree - if we found
* a number of regulators from mc13xxx_get_num_regulators_dt and
* then parsed a smaller number in mc13xxx_parse_regulators_dt then
* there is a regulator defined in the regulators node which has
* not matched any usable regulator in the driver. In this case,
* there is one missing and what will happen is the first regulator
* will get registered again.
*
* Fix this by basically making our number of registerable regulators
* equal to the number of regulators we parsed. We are allocating
* too much memory for priv, but this is unavoidable at this point.
*
* As an example of how this can happen, try making a typo in your
* regulators node (vviohi {} instead of viohi {}) so that the name
* does not match..
*
* The check will basically pass for platform data (non-DT) because
* mc13xxx_parse_regulators_dt for !CONFIG_OF will not touch num_parsed.
*
*/
if (num_parsed != num_regulators) {
dev_warn(&pdev->dev,
"parsed %d != regulators %d - check your device tree!\n",
num_parsed, num_regulators);
num_regulators = num_parsed;
priv->num_regulators = num_regulators;
}
ARRAY_SIZE(mc13892_regulators));
for (i = 0; i < num_regulators; i++) {
for (i = 0; i < priv->num_regulators; i++) {
struct regulator_init_data *init_data;
struct regulator_desc *desc;
struct device_node *node = NULL;
......
......@@ -180,15 +180,13 @@ EXPORT_SYMBOL_GPL(mc13xxx_get_num_regulators_dt);
struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
struct platform_device *pdev, struct mc13xxx_regulator *regulators,
int num_regulators, int *num_parsed)
int num_regulators)
{
struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
struct mc13xxx_regulator_init_data *data, *p;
struct device_node *parent, *child;
int i, parsed = 0;
*num_parsed = 0;
of_node_get(pdev->dev.parent->of_node);
parent = of_find_node_by_name(pdev->dev.parent->of_node, "regulators");
if (!parent)
......@@ -204,10 +202,13 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
p = data;
for_each_child_of_node(parent, child) {
int found = 0;
for (i = 0; i < num_regulators; i++) {
if (!regulators[i].desc.name)
continue;
if (!of_node_cmp(child->name,
regulators[i].desc.name)) {
p->id = i;
p->init_data = of_get_regulator_init_data(
&pdev->dev, child);
......@@ -215,13 +216,19 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
p++;
parsed++;
found = 1;
break;
}
}
if (!found)
dev_warn(&pdev->dev,
"Unknown regulator: %s\n", child->name);
}
of_node_put(parent);
*num_parsed = parsed;
priv->num_regulators = parsed;
return data;
}
EXPORT_SYMBOL_GPL(mc13xxx_parse_regulators_dt);
......
......@@ -39,7 +39,7 @@ extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
extern int mc13xxx_get_num_regulators_dt(struct platform_device *pdev);
extern struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
struct platform_device *pdev, struct mc13xxx_regulator *regulators,
int num_regulators, int *num_parsed);
int num_regulators);
#else
static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
{
......@@ -48,7 +48,7 @@ static inline int mc13xxx_get_num_regulators_dt(struct platform_device *pdev)
static inline struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
struct platform_device *pdev, struct mc13xxx_regulator *regulators,
int num_regulators, int *num_parsed)
int num_regulators)
{
return NULL;
}
......
This diff is collapsed.
......@@ -49,10 +49,6 @@ struct rc5t583_regulator_info {
struct rc5t583_regulator {
struct rc5t583_regulator_info *reg_info;
/* Devices */
struct device *dev;
struct rc5t583 *mfd;
struct regulator_dev *rdev;
};
......@@ -155,8 +151,6 @@ static int rc5t583_regulator_probe(struct platform_device *pdev)
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;
......
......@@ -549,7 +549,7 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
rmode = devm_kzalloc(&pdev->dev, sizeof(*rmode) *
pdata->num_regulators, GFP_KERNEL);
if (!rdata) {
if (!rmode) {
dev_err(iodev->dev,
"could not allocate memory for regulator mode\n");
return -ENOMEM;
......@@ -923,8 +923,7 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
return 0;
err:
for (i = 0; i < s5m8767->num_regulators; i++)
if (rdev[i])
regulator_unregister(rdev[i]);
regulator_unregister(rdev[i]);
return ret;
}
......@@ -936,8 +935,7 @@ static int s5m8767_pmic_remove(struct platform_device *pdev)
int i;
for (i = 0; i < s5m8767->num_regulators; i++)
if (rdev[i])
regulator_unregister(rdev[i]);
regulator_unregister(rdev[i]);
return 0;
}
......
......@@ -278,7 +278,7 @@ static int tps62360_init_dcdc(struct tps62360_chip *tps,
__func__, REG_RAMPCTRL, ret);
return ret;
}
ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
ramp_ctrl = (ramp_ctrl >> 5) & 0x7;
/* ramp mV/us = 32/(2^ramp_ctrl) */
tps->desc.ramp_delay = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
......
......@@ -107,12 +107,7 @@ static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = {
};
/* Supported voltage values for LDO regulators for tps65020 */
static const unsigned int TPS65020_LDO1_VSEL_table[] = {
1000000, 1050000, 1100000, 1300000,
1800000, 2500000, 3000000, 3300000,
};
static const unsigned int TPS65020_LDO2_VSEL_table[] = {
static const unsigned int TPS65020_LDO_VSEL_table[] = {
1000000, 1050000, 1100000, 1300000,
1800000, 2500000, 3000000, 3300000,
};
......@@ -154,20 +149,15 @@ struct tps_driver_data {
static int tps65023_dcdc_get_voltage_sel(struct regulator_dev *dev)
{
struct tps_pmic *tps = rdev_get_drvdata(dev);
int ret;
int data, dcdc = rdev_get_id(dev);
int dcdc = rdev_get_id(dev);
if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3)
return -EINVAL;
if (dcdc == tps->core_regulator) {
ret = regmap_read(tps->regmap, TPS65023_REG_DEF_CORE, &data);
if (ret != 0)
return ret;
data &= (tps->info[dcdc]->table_len - 1);
return data;
} else
if (dcdc != tps->core_regulator)
return 0;
return regulator_get_voltage_sel_regmap(dev);
}
static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
......@@ -175,23 +165,11 @@ static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
{
struct tps_pmic *tps = rdev_get_drvdata(dev);
int dcdc = rdev_get_id(dev);
int ret;
if (dcdc != tps->core_regulator)
return -EINVAL;
ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, selector);
if (ret)
goto out;
/* Tell the chip that we have changed the value in DEFCORE
* and its time to update the core voltage
*/
ret = regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2,
TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO);
out:
return ret;
return regulator_set_voltage_sel_regmap(dev, selector);
}
/* Operations permitted on VDCDCx */
......@@ -202,6 +180,7 @@ static struct regulator_ops tps65023_dcdc_ops = {
.get_voltage_sel = tps65023_dcdc_get_voltage_sel,
.set_voltage_sel = tps65023_dcdc_set_voltage_sel,
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
};
/* Operations permitted on LDOx */
......@@ -212,6 +191,7 @@ static struct regulator_ops tps65023_ldo_ops = {
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
};
static struct regmap_config tps65023_regmap_config = {
......@@ -285,6 +265,10 @@ static int tps_65023_probe(struct i2c_client *client,
default: /* DCDCx */
tps->desc[i].enable_mask =
1 << (TPS65023_NUM_REGULATOR - i);
tps->desc[i].vsel_reg = TPS65023_REG_DEF_CORE;
tps->desc[i].vsel_mask = info->table_len - 1;
tps->desc[i].apply_reg = TPS65023_REG_CON_CTRL2;
tps->desc[i].apply_bit = TPS65023_REG_CTRL2_GO;
}
config.dev = &client->dev;
......@@ -347,13 +331,13 @@ static const struct tps_info tps65020_regs[] = {
},
{
.name = "LDO1",
.table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table),
.table = TPS65020_LDO1_VSEL_table,
.table_len = ARRAY_SIZE(TPS65020_LDO_VSEL_table),
.table = TPS65020_LDO_VSEL_table,
},
{
.name = "LDO2",
.table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table),
.table = TPS65020_LDO2_VSEL_table,
.table_len = ARRAY_SIZE(TPS65020_LDO_VSEL_table),
.table = TPS65020_LDO_VSEL_table,
},
};
......
......@@ -356,6 +356,7 @@ static struct regulator_ops tps6507x_pmic_ops = {
.get_voltage_sel = tps6507x_pmic_get_voltage_sel,
.set_voltage_sel = tps6507x_pmic_set_voltage_sel,
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
};
#ifdef CONFIG_OF
......
......@@ -572,6 +572,7 @@ static struct regulator_ops regulator_ops = {
.get_voltage_sel = get_voltage_sel,
.set_voltage_sel = set_voltage_sel,
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.set_current_limit = set_current_limit,
.get_current_limit = get_current_limit,
};
......@@ -584,8 +585,7 @@ static int pmic_remove(struct spi_device *spi)
if (!hw)
return 0;
for (i = 0; i < N_REGULATORS; i++) {
if (hw->rdev[i])
regulator_unregister(hw->rdev[i]);
regulator_unregister(hw->rdev[i]);
hw->rdev[i] = NULL;
}
spi_set_drvdata(spi, NULL);
......
......@@ -70,6 +70,7 @@ static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev)
static struct regulator_ops tps6586x_regulator_ops = {
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
......@@ -245,7 +246,7 @@ static int tps6586x_regulator_set_slew_rate(struct platform_device *pdev,
reg = TPS6586X_SM1SL;
break;
default:
dev_warn(&pdev->dev, "Only SM0/SM1 can set slew rate\n");
dev_err(&pdev->dev, "Only SM0/SM1 can set slew rate\n");
return -EINVAL;
}
......@@ -304,14 +305,12 @@ static struct tps6586x_platform_data *tps6586x_parse_regulator_dt(
}
err = of_regulator_match(&pdev->dev, regs, tps6586x_matches, num);
of_node_put(regs);
if (err < 0) {
dev_err(&pdev->dev, "Regulator match failed, e %d\n", err);
of_node_put(regs);
return NULL;
}
of_node_put(regs);
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) {
dev_err(&pdev->dev, "Memory alloction failed\n");
......
......@@ -748,6 +748,7 @@ static struct regulator_ops tps65910_ops_dcdc = {
.set_voltage_sel = tps65910_set_voltage_dcdc_sel,
.set_voltage_time_sel = regulator_set_voltage_time_sel,
.list_voltage = tps65910_list_voltage_dcdc,
.map_voltage = regulator_map_voltage_ascend,
};
static struct regulator_ops tps65910_ops_vdd3 = {
......@@ -758,6 +759,7 @@ static struct regulator_ops tps65910_ops_vdd3 = {
.get_mode = tps65910_get_mode,
.get_voltage = tps65910_get_voltage_vdd3,
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
};
static struct regulator_ops tps65910_ops = {
......@@ -769,6 +771,7 @@ static struct regulator_ops tps65910_ops = {
.get_voltage_sel = tps65910_get_voltage_sel,
.set_voltage_sel = tps65910_set_voltage_sel,
.list_voltage = regulator_list_voltage_table,
.map_voltage = regulator_map_voltage_ascend,
};
static struct regulator_ops tps65911_ops = {
......@@ -780,6 +783,7 @@ static struct regulator_ops tps65911_ops = {
.get_voltage_sel = tps65911_get_voltage_sel,
.set_voltage_sel = tps65911_set_voltage_sel,
.list_voltage = tps65911_list_voltage,
.map_voltage = regulator_map_voltage_ascend,
};
static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
......
......@@ -238,12 +238,11 @@ static int tps80031_dcdc_get_voltage_sel(struct regulator_dev *rdev)
return vsel & SMPS_VSEL_MASK;
}
static int tps80031_ldo_set_voltage_sel(struct regulator_dev *rdev,
unsigned sel)
static int tps80031_ldo_list_voltage(struct regulator_dev *rdev,
unsigned int sel)
{
struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
struct device *parent = to_tps80031_dev(rdev);
int ret;
/* Check for valid setting for TPS80031 or TPS80032-ES1.0 */
if ((ri->rinfo->desc.id == TPS80031_REGULATOR_LDO2) &&
......@@ -260,28 +259,27 @@ static int tps80031_ldo_set_voltage_sel(struct regulator_dev *rdev,
}
}
ret = tps80031_write(parent, ri->rinfo->volt_id,
ri->rinfo->volt_reg, sel);
if (ret < 0)
dev_err(ri->dev, "Error in writing reg 0x%02x, e = %d\n",
ri->rinfo->volt_reg, ret);
return ret;
return regulator_list_voltage_linear(rdev, sel);
}
static int tps80031_ldo_get_voltage_sel(struct regulator_dev *rdev)
static int tps80031_ldo_map_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
struct tps80031_regulator *ri = rdev_get_drvdata(rdev);
struct device *parent = to_tps80031_dev(rdev);
uint8_t vsel;
int ret;
ret = tps80031_read(parent, ri->rinfo->volt_id,
ri->rinfo->volt_reg, &vsel);
if (ret < 0) {
dev_err(ri->dev, "Error in writing the Voltage register\n");
return ret;
/* Check for valid setting for TPS80031 or TPS80032-ES1.0 */
if ((ri->rinfo->desc.id == TPS80031_REGULATOR_LDO2) &&
(ri->device_flags & TRACK_MODE_ENABLE)) {
if (((tps80031_get_chip_info(parent) == TPS80031) ||
((tps80031_get_chip_info(parent) == TPS80032) &&
(tps80031_get_pmu_version(parent) == 0x0)))) {
return regulator_map_voltage_iterate(rdev, min_uV,
max_uV);
}
}
return vsel & rdev->desc->vsel_mask;
return regulator_map_voltage_linear(rdev, min_uV, max_uV);
}
static int tps80031_vbus_is_enabled(struct regulator_dev *rdev)
......@@ -390,9 +388,10 @@ static struct regulator_ops tps80031_dcdc_ops = {
};
static struct regulator_ops tps80031_ldo_ops = {
.list_voltage = regulator_list_voltage_linear,
.set_voltage_sel = tps80031_ldo_set_voltage_sel,
.get_voltage_sel = tps80031_ldo_get_voltage_sel,
.list_voltage = tps80031_ldo_list_voltage,
.map_voltage = tps80031_ldo_map_voltage,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.enable = tps80031_reg_enable,
.disable = tps80031_reg_disable,
.is_enabled = tps80031_reg_is_enabled,
......@@ -459,6 +458,7 @@ static struct regulator_ops tps80031_ext_reg_ops = {
.uV_step = 100000, \
.linear_min_sel = 1, \
.n_voltages = 25, \
.vsel_reg = TPS80031_##_id##_CFG_VOLTAGE, \
.vsel_mask = LDO_VSEL_MASK, \
.enable_time = 500, \
}, \
......@@ -680,6 +680,7 @@ static int tps80031_regulator_probe(struct platform_device *pdev)
struct tps80031_regulator *pmic;
struct regulator_dev *rdev;
struct regulator_config config = { };
struct tps80031 *tps80031_mfd = dev_get_drvdata(pdev->dev.parent);
int ret;
int num;
......@@ -707,6 +708,8 @@ static int tps80031_regulator_probe(struct platform_device *pdev)
config.dev = &pdev->dev;
config.init_data = NULL;
config.driver_data = ri;
config.regmap = tps80031_mfd->regmap[ri->rinfo->volt_id];
if (tps_pdata) {
config.init_data = tps_pdata->reg_init_data;
ri->config_flags = tps_pdata->config_flags;
......
......@@ -441,12 +441,6 @@ static const u16 VSIM_VSEL_table[] = {
static const u16 VDAC_VSEL_table[] = {
1200, 1300, 1800, 1800,
};
static const u16 VDD1_VSEL_table[] = {
800, 1450,
};
static const u16 VDD2_VSEL_table[] = {
800, 1450, 1500,
};
static const u16 VIO_VSEL_table[] = {
1800, 1850,
};
......@@ -615,18 +609,8 @@ static struct regulator_ops twl6030ldo_ops = {
/*----------------------------------------------------------------------*/
/*
* Fixed voltage LDOs don't have a VSEL field to update.
*/
static int twlfixed_list_voltage(struct regulator_dev *rdev, unsigned index)
{
struct twlreg_info *info = rdev_get_drvdata(rdev);
return info->min_mV * 1000;
}
static struct regulator_ops twl4030fixed_ops = {
.list_voltage = twlfixed_list_voltage,
.list_voltage = regulator_list_voltage_linear,
.enable = twl4030reg_enable,
.disable = twl4030reg_disable,
......@@ -638,7 +622,7 @@ static struct regulator_ops twl4030fixed_ops = {
};
static struct regulator_ops twl6030fixed_ops = {
.list_voltage = twlfixed_list_voltage,
.list_voltage = regulator_list_voltage_linear,
.enable = twl6030reg_enable,
.disable = twl6030reg_disable,
......@@ -944,19 +928,7 @@ static const struct twlreg_info TWLFIXED_INFO_##label = { \
.ops = &operations, \
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
.enable_time = turnon_delay, \
}, \
}
#define TWL6030_FIXED_RESOURCE(label, offset, turnon_delay) \
static struct twlreg_info TWLRES_INFO_##label = { \
.base = offset, \
.desc = { \
.name = #label, \
.id = TWL6030_REG_##label, \
.ops = &twl6030_fixed_resource, \
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
.min_uV = mVolts * 1000, \
.enable_time = turnon_delay, \
}, \
}
......
......@@ -18,6 +18,7 @@
#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/slab.h>
......@@ -28,6 +29,8 @@
struct wm8994_ldo {
struct regulator_dev *regulator;
struct wm8994 *wm8994;
struct regulator_consumer_supply supply;
struct regulator_init_data init_data;
};
#define WM8994_LDO1_MAX_SELECTOR 0x7
......@@ -99,6 +102,26 @@ static const struct regulator_desc wm8994_ldo_desc[] = {
},
};
static const struct regulator_consumer_supply wm8994_ldo_consumer[] = {
{ .supply = "AVDD1" },
{ .supply = "DCVDD" },
};
static const struct regulator_init_data wm8994_ldo_default[] = {
{
.constraints = {
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
},
.num_consumer_supplies = 1,
},
{
.constraints = {
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
},
.num_consumer_supplies = 1,
},
};
static int wm8994_ldo_probe(struct platform_device *pdev)
{
struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent);
......@@ -117,13 +140,29 @@ static int wm8994_ldo_probe(struct platform_device *pdev)
}
ldo->wm8994 = wm8994;
ldo->supply = wm8994_ldo_consumer[id];
ldo->supply.dev_name = dev_name(wm8994->dev);
config.dev = wm8994->dev;
config.driver_data = ldo;
config.regmap = wm8994->regmap;
if (pdata) {
config.init_data = pdata->ldo[id].init_data;
config.init_data = &ldo->init_data;
if (pdata)
config.ena_gpio = pdata->ldo[id].enable;
else if (wm8994->dev->of_node)
config.ena_gpio = wm8994->pdata.ldo[id].enable;
/* Use default constraints if none set up */
if (!pdata || !pdata->ldo[id].init_data || wm8994->dev->of_node) {
dev_dbg(wm8994->dev, "Using default init data, supply %s %s\n",
ldo->supply.dev_name, ldo->supply.supply);
ldo->init_data = wm8994_ldo_default[id];
ldo->init_data.consumer_supplies = &ldo->supply;
if (!config.ena_gpio)
ldo->init_data.constraints.valid_ops_mask = 0;
} else {
ldo->init_data = *pdata->ldo[id].init_data;
}
ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config);
......@@ -162,23 +201,7 @@ static struct platform_driver wm8994_ldo_driver = {
},
};
static int __init wm8994_ldo_init(void)
{
int ret;
ret = platform_driver_register(&wm8994_ldo_driver);
if (ret != 0)
pr_err("Failed to register Wm8994 GP LDO driver: %d\n", ret);
return ret;
}
subsys_initcall(wm8994_ldo_init);
static void __exit wm8994_ldo_exit(void)
{
platform_driver_unregister(&wm8994_ldo_driver);
}
module_exit(wm8994_ldo_exit);
module_platform_driver(wm8994_ldo_driver);
/* Module information */
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
......
......@@ -364,8 +364,7 @@ struct ab8500 {
const int *irq_reg_offset;
};
struct regulator_reg_init;
struct regulator_init_data;
struct ab8500_regulator_platform_data;
struct ab8500_gpio_platform_data;
struct ab8500_codec_platform_data;
struct ab8500_sysctrl_platform_data;
......@@ -375,19 +374,13 @@ struct ab8500_sysctrl_platform_data;
* @irq_base: start of AB8500 IRQs, AB8500_NR_IRQS will be used
* @pm_power_off: Should machine pm power off hook be registered or not
* @init: board-specific initialization after detection of ab8500
* @num_regulator_reg_init: number of regulator init registers
* @regulator_reg_init: regulator init registers
* @num_regulator: number of regulators
* @regulator: machine-specific constraints for regulators
*/
struct ab8500_platform_data {
int irq_base;
bool pm_power_off;
void (*init) (struct ab8500 *);
int num_regulator_reg_init;
struct ab8500_regulator_reg_init *regulator_reg_init;
int num_regulator;
struct regulator_init_data *regulator;
struct ab8500_regulator_platform_data *regulator;
struct abx500_gpio_platform_data *gpio;
struct ab8500_codec_platform_data *codec;
struct ab8500_sysctrl_platform_data *sysctrl;
......
......@@ -109,19 +109,6 @@ struct palmas_reg_init {
*/
int mode_sleep;
/* tstep is the timestep loaded to the TSTEP register
*
* For SMPS
*
* 0: Jump (no slope control)
* 1: 10mV/us
* 2: 5mV/us
* 3: 2.5mV/us
*
* For LDO unused
*/
int tstep;
/* voltage_sel is the bitfield loaded onto the SMPSX_VOLTAGE
* register. Set this is the default voltage set in OTP needs
* to be overridden.
......@@ -154,6 +141,12 @@ enum palmas_regulators {
PALMAS_REG_LDO9,
PALMAS_REG_LDOLN,
PALMAS_REG_LDOUSB,
/* External regulators */
PALMAS_REG_REGEN1,
PALMAS_REG_REGEN2,
PALMAS_REG_REGEN3,
PALMAS_REG_SYSEN1,
PALMAS_REG_SYSEN2,
/* Total number of regulators */
PALMAS_NUM_REGS,
};
......@@ -171,6 +164,9 @@ struct palmas_pmic_platform_data {
/* use LDO6 for vibrator control */
int ldo6_vibrator;
/* Enable tracking mode of LDO8 */
bool enable_ldo8_tracking;
};
struct palmas_usb_platform_data {
......@@ -331,6 +327,8 @@ struct palmas_pmic {
int smps457;
int range[PALMAS_REG_SMPS10];
unsigned int ramp_delay[PALMAS_REG_SMPS10];
unsigned int current_reg_mode[PALMAS_REG_SMPS10];
};
struct palmas_resource {
......
......@@ -5,11 +5,14 @@
*
* Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
* Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
* Daniel Willerud <daniel.willerud@stericsson.com> for ST-Ericsson
*/
#ifndef __LINUX_MFD_AB8500_REGULATOR_H
#define __LINUX_MFD_AB8500_REGULATOR_H
#include <linux/platform_device.h>
/* AB8500 regulators */
enum ab8500_regulator_id {
AB8500_LDO_AUX1,
......@@ -17,7 +20,6 @@ enum ab8500_regulator_id {
AB8500_LDO_AUX3,
AB8500_LDO_INTCORE,
AB8500_LDO_TVOUT,
AB8500_LDO_USB,
AB8500_LDO_AUDIO,
AB8500_LDO_ANAMIC1,
AB8500_LDO_ANAMIC2,
......@@ -26,7 +28,28 @@ enum ab8500_regulator_id {
AB8500_NUM_REGULATORS,
};
/* AB9450 regulators */
/* AB8505 regulators */
enum ab8505_regulator_id {
AB8505_LDO_AUX1,
AB8505_LDO_AUX2,
AB8505_LDO_AUX3,
AB8505_LDO_AUX4,
AB8505_LDO_AUX5,
AB8505_LDO_AUX6,
AB8505_LDO_INTCORE,
AB8505_LDO_ADC,
AB8505_LDO_USB,
AB8505_LDO_AUDIO,
AB8505_LDO_ANAMIC1,
AB8505_LDO_ANAMIC2,
AB8505_LDO_AUX8,
AB8505_LDO_ANA,
AB8505_SYSCLKREQ_2,
AB8505_SYSCLKREQ_4,
AB8505_NUM_REGULATORS,
};
/* AB9540 regulators */
enum ab9540_regulator_id {
AB9540_LDO_AUX1,
AB9540_LDO_AUX2,
......@@ -45,16 +68,39 @@ enum ab9540_regulator_id {
AB9540_NUM_REGULATORS,
};
/* AB8500 and AB9540 register initialization */
/* AB8540 regulators */
enum ab8540_regulator_id {
AB8540_LDO_AUX1,
AB8540_LDO_AUX2,
AB8540_LDO_AUX3,
AB8540_LDO_AUX4,
AB8540_LDO_AUX5,
AB8540_LDO_AUX6,
AB8540_LDO_INTCORE,
AB8540_LDO_TVOUT,
AB8540_LDO_AUDIO,
AB8540_LDO_ANAMIC1,
AB8540_LDO_ANAMIC2,
AB8540_LDO_DMIC,
AB8540_LDO_ANA,
AB8540_LDO_SDIO,
AB8540_SYSCLKREQ_2,
AB8540_SYSCLKREQ_4,
AB8540_NUM_REGULATORS,
};
/* AB8500, AB8505, and AB9540 register initialization */
struct ab8500_regulator_reg_init {
int id;
u8 mask;
u8 value;
};
#define INIT_REGULATOR_REGISTER(_id, _value) \
{ \
.id = _id, \
.value = _value, \
#define INIT_REGULATOR_REGISTER(_id, _mask, _value) \
{ \
.id = _id, \
.mask = _mask, \
.value = _value, \
}
/* AB8500 registers */
......@@ -86,10 +132,58 @@ enum ab8500_regulator_reg {
AB8500_REGUCTRL2SPARE,
AB8500_REGUCTRLDISCH,
AB8500_REGUCTRLDISCH2,
AB8500_VSMPS1SEL1,
AB8500_NUM_REGULATOR_REGISTERS,
};
/* AB8505 registers */
enum ab8505_regulator_reg {
AB8505_REGUREQUESTCTRL1,
AB8505_REGUREQUESTCTRL2,
AB8505_REGUREQUESTCTRL3,
AB8505_REGUREQUESTCTRL4,
AB8505_REGUSYSCLKREQ1HPVALID1,
AB8505_REGUSYSCLKREQ1HPVALID2,
AB8505_REGUHWHPREQ1VALID1,
AB8505_REGUHWHPREQ1VALID2,
AB8505_REGUHWHPREQ2VALID1,
AB8505_REGUHWHPREQ2VALID2,
AB8505_REGUSWHPREQVALID1,
AB8505_REGUSWHPREQVALID2,
AB8505_REGUSYSCLKREQVALID1,
AB8505_REGUSYSCLKREQVALID2,
AB8505_REGUVAUX4REQVALID,
AB8505_REGUMISC1,
AB8505_VAUDIOSUPPLY,
AB8505_REGUCTRL1VAMIC,
AB8505_VSMPSAREGU,
AB8505_VSMPSBREGU,
AB8505_VSAFEREGU, /* NOTE! PRCMU register */
AB8505_VPLLVANAREGU,
AB8505_EXTSUPPLYREGU,
AB8505_VAUX12REGU,
AB8505_VRF1VAUX3REGU,
AB8505_VSMPSASEL1,
AB8505_VSMPSASEL2,
AB8505_VSMPSASEL3,
AB8505_VSMPSBSEL1,
AB8505_VSMPSBSEL2,
AB8505_VSMPSBSEL3,
AB8505_VSAFESEL1, /* NOTE! PRCMU register */
AB8505_VSAFESEL2, /* NOTE! PRCMU register */
AB8505_VSAFESEL3, /* NOTE! PRCMU register */
AB8505_VAUX1SEL,
AB8505_VAUX2SEL,
AB8505_VRF1VAUX3SEL,
AB8505_VAUX4REQCTRL,
AB8505_VAUX4REGU,
AB8505_VAUX4SEL,
AB8505_REGUCTRLDISCH,
AB8505_REGUCTRLDISCH2,
AB8505_REGUCTRLDISCH3,
AB8505_CTRLVAUX5,
AB8505_CTRLVAUX6,
AB8505_NUM_REGULATOR_REGISTERS,
};
/* AB9540 registers */
enum ab9540_regulator_reg {
......@@ -139,4 +233,111 @@ enum ab9540_regulator_reg {
AB9540_NUM_REGULATOR_REGISTERS,
};
/* AB8540 registers */
enum ab8540_regulator_reg {
AB8540_REGUREQUESTCTRL1,
AB8540_REGUREQUESTCTRL2,
AB8540_REGUREQUESTCTRL3,
AB8540_REGUREQUESTCTRL4,
AB8540_REGUSYSCLKREQ1HPVALID1,
AB8540_REGUSYSCLKREQ1HPVALID2,
AB8540_REGUHWHPREQ1VALID1,
AB8540_REGUHWHPREQ1VALID2,
AB8540_REGUHWHPREQ2VALID1,
AB8540_REGUHWHPREQ2VALID2,
AB8540_REGUSWHPREQVALID1,
AB8540_REGUSWHPREQVALID2,
AB8540_REGUSYSCLKREQVALID1,
AB8540_REGUSYSCLKREQVALID2,
AB8540_REGUVAUX4REQVALID,
AB8540_REGUVAUX5REQVALID,
AB8540_REGUVAUX6REQVALID,
AB8540_REGUVCLKBREQVALID,
AB8540_REGUVRF1REQVALID,
AB8540_REGUMISC1,
AB8540_VAUDIOSUPPLY,
AB8540_REGUCTRL1VAMIC,
AB8540_VHSIC,
AB8540_VSDIO,
AB8540_VSMPS1REGU,
AB8540_VSMPS2REGU,
AB8540_VSMPS3REGU,
AB8540_VPLLVANAREGU,
AB8540_EXTSUPPLYREGU,
AB8540_VAUX12REGU,
AB8540_VRF1VAUX3REGU,
AB8540_VSMPS1SEL1,
AB8540_VSMPS1SEL2,
AB8540_VSMPS1SEL3,
AB8540_VSMPS2SEL1,
AB8540_VSMPS2SEL2,
AB8540_VSMPS2SEL3,
AB8540_VSMPS3SEL1,
AB8540_VSMPS3SEL2,
AB8540_VAUX1SEL,
AB8540_VAUX2SEL,
AB8540_VRF1VAUX3SEL,
AB8540_REGUCTRL2SPARE,
AB8540_VAUX4REQCTRL,
AB8540_VAUX4REGU,
AB8540_VAUX4SEL,
AB8540_VAUX5REQCTRL,
AB8540_VAUX5REGU,
AB8540_VAUX5SEL,
AB8540_VAUX6REQCTRL,
AB8540_VAUX6REGU,
AB8540_VAUX6SEL,
AB8540_VCLKBREQCTRL,
AB8540_VCLKBREGU,
AB8540_VCLKBSEL,
AB8540_VRF1REQCTRL,
AB8540_REGUCTRLDISCH,
AB8540_REGUCTRLDISCH2,
AB8540_REGUCTRLDISCH3,
AB8540_REGUCTRLDISCH4,
AB8540_VSIMSYSCLKCTRL,
AB8540_VANAVPLLSEL,
AB8540_NUM_REGULATOR_REGISTERS,
};
/* AB8500 external regulators */
struct ab8500_ext_regulator_cfg {
bool hwreq; /* requires hw mode or high power mode */
};
enum ab8500_ext_regulator_id {
AB8500_EXT_SUPPLY1,
AB8500_EXT_SUPPLY2,
AB8500_EXT_SUPPLY3,
AB8500_NUM_EXT_REGULATORS,
};
/* AB8500 regulator platform data */
struct ab8500_regulator_platform_data {
int num_reg_init;
struct ab8500_regulator_reg_init *reg_init;
int num_regulator;
struct regulator_init_data *regulator;
int num_ext_regulator;
struct regulator_init_data *ext_regulator;
};
#ifdef CONFIG_REGULATOR_AB8500_DEBUG
int ab8500_regulator_debug_init(struct platform_device *pdev);
int ab8500_regulator_debug_exit(struct platform_device *pdev);
#else
static inline int ab8500_regulator_debug_init(struct platform_device *pdev)
{
return 0;
}
static inline int ab8500_regulator_debug_exit(struct platform_device *pdev)
{
return 0;
}
#endif
/* AB8500 external regulator functions. */
int ab8500_ext_regulator_init(struct platform_device *pdev);
void ab8500_ext_regulator_exit(struct platform_device *pdev);
#endif
......@@ -141,18 +141,18 @@ void regulator_put(struct regulator *regulator);
void devm_regulator_put(struct regulator *regulator);
/* regulator output control and status */
int regulator_enable(struct regulator *regulator);
int __must_check regulator_enable(struct regulator *regulator);
int regulator_disable(struct regulator *regulator);
int regulator_force_disable(struct regulator *regulator);
int regulator_is_enabled(struct regulator *regulator);
int regulator_disable_deferred(struct regulator *regulator, int ms);
int regulator_bulk_get(struct device *dev, int num_consumers,
struct regulator_bulk_data *consumers);
int devm_regulator_bulk_get(struct device *dev, int num_consumers,
struct regulator_bulk_data *consumers);
int regulator_bulk_enable(int num_consumers,
struct regulator_bulk_data *consumers);
int __must_check regulator_bulk_get(struct device *dev, int num_consumers,
struct regulator_bulk_data *consumers);
int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers,
struct regulator_bulk_data *consumers);
int __must_check regulator_bulk_enable(int num_consumers,
struct regulator_bulk_data *consumers);
int regulator_bulk_disable(int num_consumers,
struct regulator_bulk_data *consumers);
int regulator_bulk_force_disable(int num_consumers,
......
......@@ -22,6 +22,7 @@
struct regmap;
struct regulator_dev;
struct regulator_init_data;
struct regulator_enable_gpio;
enum regulator_status {
REGULATOR_STATUS_OFF,
......@@ -199,6 +200,8 @@ enum regulator_type {
* output when using regulator_set_voltage_sel_regmap
* @enable_reg: Register for control when using regmap enable/disable ops
* @enable_mask: Mask for control when using regmap enable/disable ops
* @enable_is_inverted: A flag to indicate set enable_mask bits to disable
* when using regulator_enable_regmap and friends APIs.
* @bypass_reg: Register for control when using regmap set_bypass
* @bypass_mask: Mask for control when using regmap set_bypass
*
......@@ -228,6 +231,7 @@ struct regulator_desc {
unsigned int apply_bit;
unsigned int enable_reg;
unsigned int enable_mask;
bool enable_is_inverted;
unsigned int bypass_reg;
unsigned int bypass_mask;
......@@ -302,8 +306,7 @@ struct regulator_dev {
struct dentry *debugfs;
int ena_gpio;
unsigned int ena_gpio_invert:1;
struct regulator_enable_gpio *ena_pin;
unsigned int ena_gpio_state:1;
};
......@@ -329,6 +332,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
int min_uV, int max_uV);
int regulator_map_voltage_iterate(struct regulator_dev *rdev,
int min_uV, int max_uV);
int regulator_map_voltage_ascend(struct regulator_dev *rdev,
int min_uV, int max_uV);
int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
int regulator_is_enabled_regmap(struct regulator_dev *rdev);
......
......@@ -122,13 +122,13 @@ struct max8952_platform_data {
int gpio_vid1;
int gpio_en;
u8 default_mode;
u8 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */
u32 default_mode;
u32 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */
u8 sync_freq;
u8 ramp_speed;
u32 sync_freq;
u32 ramp_speed;
struct regulator_init_data reg_data;
struct regulator_init_data *reg_data;
};
......
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