regulator: max8973: Pass descriptor instead of GPIO number
Instead of passing a global GPIO number, pass a descriptor looked up with the standard devm_gpiod_get_optional() call. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
910adc0e1b
commit
e7d2be696f
|
@ -34,6 +34,7 @@
|
||||||
#include <linux/regulator/max8973-regulator.h>
|
#include <linux/regulator/max8973-regulator.h>
|
||||||
#include <linux/regulator/of_regulator.h>
|
#include <linux/regulator/of_regulator.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
|
#include <linux/gpio/consumer.h>
|
||||||
#include <linux/of_gpio.h>
|
#include <linux/of_gpio.h>
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
@ -114,7 +115,6 @@ struct max8973_chip {
|
||||||
struct regulator_desc desc;
|
struct regulator_desc desc;
|
||||||
struct regmap *regmap;
|
struct regmap *regmap;
|
||||||
bool enable_external_control;
|
bool enable_external_control;
|
||||||
int enable_gpio;
|
|
||||||
int dvs_gpio;
|
int dvs_gpio;
|
||||||
int lru_index[MAX8973_MAX_VOUT_REG];
|
int lru_index[MAX8973_MAX_VOUT_REG];
|
||||||
int curr_vout_val[MAX8973_MAX_VOUT_REG];
|
int curr_vout_val[MAX8973_MAX_VOUT_REG];
|
||||||
|
@ -567,7 +567,6 @@ static struct max8973_regulator_platform_data *max8973_parse_dt(
|
||||||
|
|
||||||
pdata->enable_ext_control = of_property_read_bool(np,
|
pdata->enable_ext_control = of_property_read_bool(np,
|
||||||
"maxim,externally-enable");
|
"maxim,externally-enable");
|
||||||
pdata->enable_gpio = of_get_named_gpio(np, "maxim,enable-gpio", 0);
|
|
||||||
pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
|
pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
|
||||||
|
|
||||||
ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
|
ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
|
||||||
|
@ -633,6 +632,8 @@ static int max8973_probe(struct i2c_client *client,
|
||||||
struct max8973_chip *max;
|
struct max8973_chip *max;
|
||||||
bool pdata_from_dt = false;
|
bool pdata_from_dt = false;
|
||||||
unsigned int chip_id;
|
unsigned int chip_id;
|
||||||
|
struct gpio_desc *gpiod;
|
||||||
|
enum gpiod_flags gflags;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pdata = dev_get_platdata(&client->dev);
|
pdata = dev_get_platdata(&client->dev);
|
||||||
|
@ -647,8 +648,7 @@ static int max8973_probe(struct i2c_client *client,
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pdata->dvs_gpio == -EPROBE_DEFER) ||
|
if (pdata->dvs_gpio == -EPROBE_DEFER)
|
||||||
(pdata->enable_gpio == -EPROBE_DEFER))
|
|
||||||
return -EPROBE_DEFER;
|
return -EPROBE_DEFER;
|
||||||
|
|
||||||
max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
|
max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
|
||||||
|
@ -696,15 +696,11 @@ static int max8973_probe(struct i2c_client *client,
|
||||||
max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE;
|
max->desc.n_voltages = MAX8973_BUCK_N_VOLTAGE;
|
||||||
|
|
||||||
max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
|
max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
|
||||||
max->enable_gpio = (pdata->enable_gpio) ? pdata->enable_gpio : -EINVAL;
|
|
||||||
max->enable_external_control = pdata->enable_ext_control;
|
max->enable_external_control = pdata->enable_ext_control;
|
||||||
max->curr_gpio_val = pdata->dvs_def_state;
|
max->curr_gpio_val = pdata->dvs_def_state;
|
||||||
max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
|
max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
|
||||||
max->junction_temp_warning = pdata->junction_temp_warning;
|
max->junction_temp_warning = pdata->junction_temp_warning;
|
||||||
|
|
||||||
if (gpio_is_valid(max->enable_gpio))
|
|
||||||
max->enable_external_control = true;
|
|
||||||
|
|
||||||
max->lru_index[0] = max->curr_vout_reg;
|
max->lru_index[0] = max->curr_vout_reg;
|
||||||
|
|
||||||
if (gpio_is_valid(max->dvs_gpio)) {
|
if (gpio_is_valid(max->dvs_gpio)) {
|
||||||
|
@ -757,27 +753,35 @@ static int max8973_probe(struct i2c_client *client,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_is_valid(max->enable_gpio)) {
|
if (ridata && (ridata->constraints.always_on ||
|
||||||
config.ena_gpio_flags = GPIOF_OUT_INIT_LOW;
|
ridata->constraints.boot_on))
|
||||||
if (ridata && (ridata->constraints.always_on ||
|
gflags = GPIOD_OUT_HIGH;
|
||||||
ridata->constraints.boot_on))
|
else
|
||||||
config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
|
gflags = GPIOD_OUT_LOW;
|
||||||
config.ena_gpio = max->enable_gpio;
|
gpiod = devm_gpiod_get_optional(&client->dev,
|
||||||
|
"maxim,enable",
|
||||||
|
gflags);
|
||||||
|
if (IS_ERR(gpiod))
|
||||||
|
return PTR_ERR(gpiod);
|
||||||
|
if (gpiod) {
|
||||||
|
config.ena_gpiod = gpiod;
|
||||||
|
max->enable_external_control = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MAX77621:
|
case MAX77621:
|
||||||
if (gpio_is_valid(max->enable_gpio)) {
|
/*
|
||||||
ret = devm_gpio_request_one(&client->dev,
|
* We do not let the core switch this regulator on/off,
|
||||||
max->enable_gpio, GPIOF_OUT_INIT_HIGH,
|
* we just leave it on.
|
||||||
"max8973-en-gpio");
|
*/
|
||||||
if (ret) {
|
gpiod = devm_gpiod_get_optional(&client->dev,
|
||||||
dev_err(&client->dev,
|
"maxim,enable",
|
||||||
"gpio_request for gpio %d failed: %d\n",
|
GPIOD_OUT_HIGH);
|
||||||
max->enable_gpio, ret);
|
if (IS_ERR(gpiod))
|
||||||
return ret;
|
return PTR_ERR(gpiod);
|
||||||
}
|
if (gpiod)
|
||||||
}
|
max->enable_external_control = true;
|
||||||
|
|
||||||
max->desc.enable_reg = MAX8973_VOUT;
|
max->desc.enable_reg = MAX8973_VOUT;
|
||||||
max->desc.enable_mask = MAX8973_VOUT_ENABLE;
|
max->desc.enable_mask = MAX8973_VOUT_ENABLE;
|
||||||
|
|
Loading…
Reference in New Issue