diff options
Diffstat (limited to 'drivers/regulator/lp872x.c')
| -rw-r--r-- | drivers/regulator/lp872x.c | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/drivers/regulator/lp872x.c b/drivers/regulator/lp872x.c index 303d7e2dc838..942f37082cb1 100644 --- a/drivers/regulator/lp872x.c +++ b/drivers/regulator/lp872x.c @@ -10,13 +10,12 @@ #include <linux/i2c.h> #include <linux/regmap.h> #include <linux/err.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/delay.h> #include <linux/regulator/lp872x.h> #include <linux/regulator/driver.h> #include <linux/platform_device.h> #include <linux/of.h> -#include <linux/of_gpio.h> #include <linux/regulator/of_regulator.h> /* Registers : LP8720/8725 shared */ @@ -104,7 +103,7 @@ struct lp872x { enum lp872x_id chipid; struct lp872x_platform_data *pdata; int num_regulators; - enum lp872x_dvs_state dvs_pin; + enum gpiod_flags dvs_pin; }; /* LP8720/LP8725 shared voltage table for LDOs */ @@ -250,12 +249,12 @@ static int lp872x_regulator_enable_time(struct regulator_dev *rdev) } static void lp872x_set_dvs(struct lp872x *lp, enum lp872x_dvs_sel dvs_sel, - int gpio) + struct gpio_desc *gpio) { - enum lp872x_dvs_state state; + enum gpiod_flags state; - state = dvs_sel == SEL_V1 ? DVS_HIGH : DVS_LOW; - gpio_set_value(gpio, state); + state = dvs_sel == SEL_V1 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + gpiod_set_value(gpio, state); lp->dvs_pin = state; } @@ -270,7 +269,7 @@ static u8 lp872x_select_buck_vout_addr(struct lp872x *lp, switch (buck) { case LP8720_ID_BUCK: if (val & LP8720_EXT_DVS_M) { - addr = (lp->dvs_pin == DVS_HIGH) ? + addr = (lp->dvs_pin == GPIOD_OUT_HIGH) ? LP8720_BUCK_VOUT1 : LP8720_BUCK_VOUT2; } else { if (lp872x_read_byte(lp, LP8720_ENABLE, &val)) @@ -284,7 +283,7 @@ static u8 lp872x_select_buck_vout_addr(struct lp872x *lp, if (val & LP8725_DVS1_M) addr = LP8725_BUCK1_VOUT1; else - addr = (lp->dvs_pin == DVS_HIGH) ? + addr = (lp->dvs_pin == GPIOD_OUT_HIGH) ? LP8725_BUCK1_VOUT1 : LP8725_BUCK1_VOUT2; break; case LP8725_ID_BUCK2: @@ -321,7 +320,7 @@ static int lp872x_buck_set_voltage_sel(struct regulator_dev *rdev, u8 addr, mask = LP872X_VOUT_M; struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL; - if (dvs && gpio_is_valid(dvs->gpio)) + if (dvs && dvs->gpio) lp872x_set_dvs(lp, dvs->vsel, dvs->gpio); addr = lp872x_select_buck_vout_addr(lp, buck); @@ -675,24 +674,23 @@ static const struct regulator_desc lp8725_regulator_desc[] = { static int lp872x_init_dvs(struct lp872x *lp) { - int ret, gpio; struct lp872x_dvs *dvs = lp->pdata ? lp->pdata->dvs : NULL; - enum lp872x_dvs_state pinstate; + enum gpiod_flags pinstate; u8 mask[] = { LP8720_EXT_DVS_M, LP8725_DVS1_M | LP8725_DVS2_M }; u8 default_dvs_mode[] = { LP8720_DEFAULT_DVS, LP8725_DEFAULT_DVS }; if (!dvs) goto set_default_dvs_mode; - gpio = dvs->gpio; - if (!gpio_is_valid(gpio)) + if (!dvs->gpio) goto set_default_dvs_mode; pinstate = dvs->init_state; - ret = devm_gpio_request_one(lp->dev, gpio, pinstate, "LP872X DVS"); - if (ret) { - dev_err(lp->dev, "gpio request err: %d\n", ret); - return ret; + dvs->gpio = devm_gpiod_get_optional(lp->dev, "ti,dvs", pinstate); + + if (IS_ERR(dvs->gpio)) { + dev_err(lp->dev, "gpio request err: %ld\n", PTR_ERR(dvs->gpio)); + return PTR_ERR(dvs->gpio); } lp->dvs_pin = pinstate; @@ -706,20 +704,17 @@ set_default_dvs_mode: static int lp872x_hw_enable(struct lp872x *lp) { - int ret, gpio; - if (!lp->pdata) return -EINVAL; - gpio = lp->pdata->enable_gpio; - if (!gpio_is_valid(gpio)) + if (!lp->pdata->enable_gpio) return 0; /* Always set enable GPIO high. */ - ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN"); - if (ret) { - dev_err(lp->dev, "gpio request err: %d\n", ret); - return ret; + lp->pdata->enable_gpio = devm_gpiod_get_optional(lp->dev, "enable", GPIOD_OUT_HIGH); + if (IS_ERR(lp->pdata->enable_gpio)) { + dev_err(lp->dev, "gpio request err: %ld\n", PTR_ERR(lp->pdata->enable_gpio)); + return PTR_ERR(lp->pdata->enable_gpio); } /* Each chip has a different enable delay. */ @@ -837,19 +832,15 @@ static struct lp872x_platform_data return ERR_PTR(-ENOMEM); of_property_read_u8(np, "ti,general-config", &pdata->general_config); - if (of_find_property(np, "ti,update-config", NULL)) - pdata->update_config = true; + pdata->update_config = of_property_read_bool(np, "ti,update-config"); pdata->dvs = devm_kzalloc(dev, sizeof(struct lp872x_dvs), GFP_KERNEL); if (!pdata->dvs) return ERR_PTR(-ENOMEM); - pdata->dvs->gpio = of_get_named_gpio(np, "ti,dvs-gpio", 0); of_property_read_u8(np, "ti,dvs-vsel", (u8 *)&pdata->dvs->vsel); of_property_read_u8(np, "ti,dvs-state", &dvs_state); - pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW; - - pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0); + pdata->dvs->init_state = dvs_state ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; if (of_get_child_count(np) == 0) goto out; @@ -873,7 +864,7 @@ static struct lp872x_platform_data for (i = 0; i < num_matches; i++) { pdata->regulator_data[i].id = - (enum lp872x_regulator_id)match[i].driver_data; + (uintptr_t)match[i].driver_data; pdata->regulator_data[i].init_data = match[i].init_data; } out: @@ -887,12 +878,13 @@ static struct lp872x_platform_data } #endif -static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) +static int lp872x_probe(struct i2c_client *cl) { + const struct i2c_device_id *id = i2c_client_get_device_id(cl); struct lp872x *lp; struct lp872x_platform_data *pdata; int ret; - const int lp872x_num_regulators[] = { + static const int lp872x_num_regulators[] = { [LP8720] = LP8720_NUM_REGULATORS, [LP8725] = LP8725_NUM_REGULATORS, }; @@ -935,7 +927,7 @@ static int lp872x_probe(struct i2c_client *cl, const struct i2c_device_id *id) return lp872x_regulator_register(lp); } -static const struct of_device_id lp872x_dt_ids[] = { +static const struct of_device_id lp872x_dt_ids[] __maybe_unused = { { .compatible = "ti,lp8720", }, { .compatible = "ti,lp8725", }, { } @@ -952,6 +944,7 @@ MODULE_DEVICE_TABLE(i2c, lp872x_ids); static struct i2c_driver lp872x_driver = { .driver = { .name = "lp872x", + .probe_type = PROBE_PREFER_ASYNCHRONOUS, .of_match_table = of_match_ptr(lp872x_dt_ids), }, .probe = lp872x_probe, |
