Merge remote-tracking branches 'regulator/topic/anatop', 'regulator/topic/disable', 'regulator/topic/dummy' and 'regulator/topic/gpio' into regulator-next

This commit is contained in:
Mark Brown 2014-12-05 11:14:35 +00:00
13 changed files with 109 additions and 45 deletions

View File

@ -283,6 +283,19 @@ static int anatop_regulator_probe(struct platform_device *pdev)
sreg->sel = 0; sreg->sel = 0;
sreg->bypass = true; sreg->bypass = true;
} }
/*
* In case vddpu was disabled by the bootloader, we need to set
* a sane default until imx6-cpufreq was probed and changes the
* voltage to the correct value. In this case we set 1.25V.
*/
if (!sreg->sel && !strcmp(sreg->name, "vddpu"))
sreg->sel = 22;
if (!sreg->sel) {
dev_err(&pdev->dev, "Failed to read a valid default voltage selector.\n");
return -EINVAL;
}
} else { } else {
rdesc->ops = &anatop_rops; rdesc->ops = &anatop_rops;
} }

View File

@ -260,6 +260,8 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
ret = arizona_ldo1_of_get_pdata(arizona, &config); ret = arizona_ldo1_of_get_pdata(arizona, &config);
if (ret < 0) if (ret < 0)
return ret; return ret;
config.ena_gpio_initialized = true;
} }
} }

View File

@ -1978,9 +1978,18 @@ static int _regulator_disable(struct regulator_dev *rdev)
/* we are last user */ /* we are last user */
if (_regulator_can_change_status(rdev)) { if (_regulator_can_change_status(rdev)) {
ret = _notifier_call_chain(rdev,
REGULATOR_EVENT_PRE_DISABLE,
NULL);
if (ret & NOTIFY_STOP_MASK)
return -EINVAL;
ret = _regulator_do_disable(rdev); ret = _regulator_do_disable(rdev);
if (ret < 0) { if (ret < 0) {
rdev_err(rdev, "failed to disable\n"); rdev_err(rdev, "failed to disable\n");
_notifier_call_chain(rdev,
REGULATOR_EVENT_ABORT_DISABLE,
NULL);
return ret; return ret;
} }
_notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
@ -2037,9 +2046,16 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
{ {
int ret = 0; int ret = 0;
ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
REGULATOR_EVENT_PRE_DISABLE, NULL);
if (ret & NOTIFY_STOP_MASK)
return -EINVAL;
ret = _regulator_do_disable(rdev); ret = _regulator_do_disable(rdev);
if (ret < 0) { if (ret < 0) {
rdev_err(rdev, "failed to force disable\n"); rdev_err(rdev, "failed to force disable\n");
_notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
REGULATOR_EVENT_ABORT_DISABLE, NULL);
return ret; return ret;
} }
@ -3652,7 +3668,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
dev_set_drvdata(&rdev->dev, rdev); dev_set_drvdata(&rdev->dev, rdev);
if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) { if ((config->ena_gpio || config->ena_gpio_initialized) &&
gpio_is_valid(config->ena_gpio)) {
ret = regulator_ena_gpio_request(rdev, config); ret = regulator_ena_gpio_request(rdev, config);
if (ret != 0) { if (ret != 0) {
rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",

View File

@ -33,7 +33,7 @@ static struct regulator_init_data dummy_initdata = {
static struct regulator_ops dummy_ops; static struct regulator_ops dummy_ops;
static struct regulator_desc dummy_desc = { static const struct regulator_desc dummy_desc = {
.name = "regulator-dummy", .name = "regulator-dummy",
.id = -1, .id = -1,
.type = REGULATOR_VOLTAGE, .type = REGULATOR_VOLTAGE,

View File

@ -157,8 +157,11 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
drvdata->desc.fixed_uV = config->microvolts; drvdata->desc.fixed_uV = config->microvolts;
if (config->gpio >= 0) if (gpio_is_valid(config->gpio)) {
cfg.ena_gpio = config->gpio; cfg.ena_gpio = config->gpio;
if (pdev->dev.of_node)
cfg.ena_gpio_initialized = true;
}
cfg.ena_gpio_invert = !config->enable_high; cfg.ena_gpio_invert = !config->enable_high;
if (config->enabled_at_boot) { if (config->enabled_at_boot) {
if (config->enable_high) if (config->enable_high)

View File

@ -162,34 +162,41 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
/* Fetch GPIOs. */ /* Fetch GPIOs. - optional property*/
config->nr_gpios = of_gpio_count(np); ret = of_gpio_count(np);
if ((ret < 0) && (ret != -ENOENT))
return ERR_PTR(ret);
config->gpios = devm_kzalloc(dev, if (ret > 0) {
sizeof(struct gpio) * config->nr_gpios, config->nr_gpios = ret;
GFP_KERNEL); config->gpios = devm_kzalloc(dev,
if (!config->gpios) sizeof(struct gpio) * config->nr_gpios,
return ERR_PTR(-ENOMEM); GFP_KERNEL);
if (!config->gpios)
return ERR_PTR(-ENOMEM);
proplen = of_property_count_u32_elems(np, "gpios-states"); proplen = of_property_count_u32_elems(np, "gpios-states");
/* optional property */ /* optional property */
if (proplen < 0) if (proplen < 0)
proplen = 0; proplen = 0;
if (proplen > 0 && proplen != config->nr_gpios) { if (proplen > 0 && proplen != config->nr_gpios) {
dev_warn(dev, "gpios <-> gpios-states mismatch\n"); dev_warn(dev, "gpios <-> gpios-states mismatch\n");
proplen = 0; proplen = 0;
} }
for (i = 0; i < config->nr_gpios; i++) { for (i = 0; i < config->nr_gpios; i++) {
gpio = of_get_named_gpio(np, "gpios", i); gpio = of_get_named_gpio(np, "gpios", i);
if (gpio < 0) if (gpio < 0)
break; break;
config->gpios[i].gpio = gpio; config->gpios[i].gpio = gpio;
if (proplen > 0) { if (proplen > 0) {
of_property_read_u32_index(np, "gpios-states", i, &ret); of_property_read_u32_index(np, "gpios-states",
if (ret) i, &ret);
config->gpios[i].flags = GPIOF_OUT_INIT_HIGH; if (ret)
config->gpios[i].flags =
GPIOF_OUT_INIT_HIGH;
}
} }
} }
@ -261,13 +268,23 @@ static int gpio_regulator_probe(struct platform_device *pdev)
goto err; goto err;
} }
drvdata->gpios = kmemdup(config->gpios, if (config->nr_gpios != 0) {
config->nr_gpios * sizeof(struct gpio), drvdata->gpios = kmemdup(config->gpios,
GFP_KERNEL); config->nr_gpios * sizeof(struct gpio),
if (drvdata->gpios == NULL) { GFP_KERNEL);
dev_err(&pdev->dev, "Failed to allocate gpio data\n"); if (drvdata->gpios == NULL) {
ret = -ENOMEM; dev_err(&pdev->dev, "Failed to allocate gpio data\n");
goto err_name; ret = -ENOMEM;
goto err_name;
}
drvdata->nr_gpios = config->nr_gpios;
ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
if (ret) {
dev_err(&pdev->dev,
"Could not obtain regulator setting GPIOs: %d\n", ret);
goto err_memstate;
}
} }
drvdata->states = kmemdup(config->states, drvdata->states = kmemdup(config->states,
@ -301,14 +318,6 @@ static int gpio_regulator_probe(struct platform_device *pdev)
goto err_memgpio; goto err_memgpio;
} }
drvdata->nr_gpios = config->nr_gpios;
ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
if (ret) {
dev_err(&pdev->dev,
"Could not obtain regulator setting GPIOs: %d\n", ret);
goto err_memstate;
}
/* build initial state from gpio init data. */ /* build initial state from gpio init data. */
state = 0; state = 0;
for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) { for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) {
@ -322,8 +331,10 @@ static int gpio_regulator_probe(struct platform_device *pdev)
cfg.driver_data = drvdata; cfg.driver_data = drvdata;
cfg.of_node = np; cfg.of_node = np;
if (config->enable_gpio >= 0) if (gpio_is_valid(config->enable_gpio)) {
cfg.ena_gpio = config->enable_gpio; cfg.ena_gpio = config->enable_gpio;
cfg.ena_gpio_initialized = true;
}
cfg.ena_gpio_invert = !config->enable_high; cfg.ena_gpio_invert = !config->enable_high;
if (config->enabled_at_boot) { if (config->enabled_at_boot) {
if (config->enable_high) if (config->enable_high)

View File

@ -225,6 +225,8 @@ static int max8952_pmic_probe(struct i2c_client *client,
config.of_node = client->dev.of_node; config.of_node = client->dev.of_node;
config.ena_gpio = pdata->gpio_en; config.ena_gpio = pdata->gpio_en;
if (client->dev.of_node)
config.ena_gpio_initialized = true;
if (pdata->reg_data->constraints.boot_on) if (pdata->reg_data->constraints.boot_on)
config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;

View File

@ -886,6 +886,7 @@ common_reg:
config.regmap = iodev->regmap_pmic; config.regmap = iodev->regmap_pmic;
config.driver_data = s2mps11; config.driver_data = s2mps11;
config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
config.ena_gpio_initialized = true;
for (i = 0; i < s2mps11->rdev_num; i++) { for (i = 0; i < s2mps11->rdev_num; i++) {
struct regulator_dev *regulator; struct regulator_dev *regulator;

View File

@ -950,6 +950,7 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
config.of_node = pdata->regulators[i].reg_node; config.of_node = pdata->regulators[i].reg_node;
config.ena_gpio = -EINVAL; config.ena_gpio = -EINVAL;
config.ena_gpio_flags = 0; config.ena_gpio_flags = 0;
config.ena_gpio_initialized = true;
if (gpio_is_valid(pdata->regulators[i].ext_control_gpio)) if (gpio_is_valid(pdata->regulators[i].ext_control_gpio))
s5m8767_regulator_config_ext_control(s5m8767, s5m8767_regulator_config_ext_control(s5m8767,
&pdata->regulators[i], &config); &pdata->regulators[i], &config);

View File

@ -312,7 +312,11 @@ static void tps65090_configure_regulator_config(
gpio_flag = GPIOF_OUT_INIT_HIGH; gpio_flag = GPIOF_OUT_INIT_HIGH;
config->ena_gpio = tps_pdata->gpio; config->ena_gpio = tps_pdata->gpio;
config->ena_gpio_initialized = true;
config->ena_gpio_flags = gpio_flag; config->ena_gpio_flags = gpio_flag;
} else {
config->ena_gpio = -EINVAL;
config->ena_gpio_initialized = false;
} }
} }

View File

@ -145,10 +145,12 @@ static int wm8994_ldo_probe(struct platform_device *pdev)
config.driver_data = ldo; config.driver_data = ldo;
config.regmap = wm8994->regmap; config.regmap = wm8994->regmap;
config.init_data = &ldo->init_data; config.init_data = &ldo->init_data;
if (pdata) if (pdata) {
config.ena_gpio = pdata->ldo[id].enable; config.ena_gpio = pdata->ldo[id].enable;
else if (wm8994->dev->of_node) } else if (wm8994->dev->of_node) {
config.ena_gpio = wm8994->pdata.ldo[id].enable; config.ena_gpio = wm8994->pdata.ldo[id].enable;
config.ena_gpio_initialized = true;
}
/* Use default constraints if none set up */ /* Use default constraints if none set up */
if (!pdata || !pdata->ldo[id].init_data || wm8994->dev->of_node) { if (!pdata || !pdata->ldo[id].init_data || wm8994->dev->of_node) {

View File

@ -101,6 +101,8 @@ struct regmap;
* Data passed is "struct pre_voltage_change_data" * Data passed is "struct pre_voltage_change_data"
* ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason. * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason.
* Data passed is old voltage cast to (void *). * Data passed is old voltage cast to (void *).
* PRE_DISABLE Regulator is about to be disabled
* ABORT_DISABLE Regulator disable failed for some reason
* *
* NOTE: These events can be OR'ed together when passed into handler. * NOTE: These events can be OR'ed together when passed into handler.
*/ */
@ -115,6 +117,8 @@ struct regmap;
#define REGULATOR_EVENT_DISABLE 0x80 #define REGULATOR_EVENT_DISABLE 0x80
#define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100 #define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
#define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200 #define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
#define REGULATOR_EVENT_PRE_DISABLE 0x400
#define REGULATOR_EVENT_ABORT_DISABLE 0x800
/** /**
* struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event

View File

@ -301,6 +301,9 @@ struct regulator_desc {
* NULL). * NULL).
* @regmap: regmap to use for core regmap helpers if dev_get_regulator() is * @regmap: regmap to use for core regmap helpers if dev_get_regulator() is
* insufficient. * insufficient.
* @ena_gpio_initialized: GPIO controlling regulator enable was properly
* initialized, meaning that >= 0 is a valid gpio
* identifier and < 0 is a non existent gpio.
* @ena_gpio: GPIO controlling regulator enable. * @ena_gpio: GPIO controlling regulator enable.
* @ena_gpio_invert: Sense for GPIO enable control. * @ena_gpio_invert: Sense for GPIO enable control.
* @ena_gpio_flags: Flags to use when calling gpio_request_one() * @ena_gpio_flags: Flags to use when calling gpio_request_one()
@ -312,6 +315,7 @@ struct regulator_config {
struct device_node *of_node; struct device_node *of_node;
struct regmap *regmap; struct regmap *regmap;
bool ena_gpio_initialized;
int ena_gpio; int ena_gpio;
unsigned int ena_gpio_invert:1; unsigned int ena_gpio_invert:1;
unsigned int ena_gpio_flags; unsigned int ena_gpio_flags;