Commit e450a2b3 authored by Linus Walleij's avatar Linus Walleij Committed by Mark Brown

regulator: da9055: Fully convert to GPIO descriptors

The DA9055 regulator was touched before, requireing enable GPIOs
to be passed from pdata.

As we have a device for each regulator, obtain the three gpios
ren ("regulator enable"), rsel ("regulator select") and the
ena ("enable") GPIO associated with the regulator enable
directly from the device and cut down on the amount of
GPIO numbers passed as platform data.

The ren and rsel are just requested as inputs: these are
actually handled by hardware. The ena gpios are driven
actively by the regulator core.

There are no in-tree users, but the regulators are instantiated
from the (undocumed) device tree nodes with "dlg,da9055-regulator"
as compatible, and by simply adding regulator-enable-gpios,
regulator-select-gpios and enable-gpios to this DT node, all
will work as before.
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://msgid.link/r/20240220-descriptors-regulators-v1-2-097f608694be@linaro.orgAcked-by: default avatarLee Jones <lee@kernel.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4d52f575
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/regulator/driver.h> #include <linux/regulator/driver.h>
...@@ -413,31 +412,35 @@ static struct da9055_regulator_info da9055_regulator_info[] = { ...@@ -413,31 +412,35 @@ static struct da9055_regulator_info da9055_regulator_info[] = {
* GPIO can control regulator state and/or select the regulator register * GPIO can control regulator state and/or select the regulator register
* set A/B for voltage ramping. * set A/B for voltage ramping.
*/ */
static int da9055_gpio_init(struct da9055_regulator *regulator, static int da9055_gpio_init(struct device *dev,
struct da9055_regulator *regulator,
struct regulator_config *config, struct regulator_config *config,
struct da9055_pdata *pdata, int id) struct da9055_pdata *pdata, int id)
{ {
struct da9055_regulator_info *info = regulator->info; struct da9055_regulator_info *info = regulator->info;
struct gpio_desc *ren;
struct gpio_desc *ena;
struct gpio_desc *rsel;
int ret = 0; int ret = 0;
if (!pdata) /* Look for "regulator-enable-gpios" GPIOs in the regulator node */
return 0; ren = devm_gpiod_get_optional(dev, "regulator-enable", GPIOD_IN);
if (IS_ERR(ren))
return PTR_ERR(ren);
if (pdata->gpio_ren && pdata->gpio_ren[id]) { if (ren) {
char name[18]; /* This GPIO is not optional at this point */
int gpio_mux = pdata->gpio_ren[id]; ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
if (IS_ERR(ena))
return PTR_ERR(ena);
config->ena_gpiod = pdata->ena_gpiods[id]; config->ena_gpiod = ena;
/* /*
* GPI pin is muxed with regulator to control the * GPI pin is muxed with regulator to control the
* regulator state. * regulator state.
*/ */
sprintf(name, "DA9055 GPI %d", gpio_mux); gpiod_set_consumer_name(ren, "DA9055 ren GPI");
ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
name);
if (ret < 0)
goto err;
/* /*
* Let the regulator know that its state is controlled * Let the regulator know that its state is controlled
...@@ -448,24 +451,22 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, ...@@ -448,24 +451,22 @@ static int da9055_gpio_init(struct da9055_regulator *regulator,
pdata->reg_ren[id] pdata->reg_ren[id]
<< DA9055_E_GPI_SHIFT); << DA9055_E_GPI_SHIFT);
if (ret < 0) if (ret < 0)
goto err; return ret;
} }
if (pdata->gpio_rsel && pdata->gpio_rsel[id]) { /* Look for "regulator-select-gpios" GPIOs in the regulator node */
char name[18]; rsel = devm_gpiod_get_optional(dev, "regulator-select", GPIOD_IN);
int gpio_mux = pdata->gpio_rsel[id]; if (IS_ERR(rsel))
return PTR_ERR(rsel);
if (rsel) {
regulator->reg_rselect = pdata->reg_rsel[id]; regulator->reg_rselect = pdata->reg_rsel[id];
/* /*
* GPI pin is muxed with regulator to select the * GPI pin is muxed with regulator to select the
* regulator register set A/B for voltage ramping. * regulator register set A/B for voltage ramping.
*/ */
sprintf(name, "DA9055 GPI %d", gpio_mux); gpiod_set_consumer_name(rsel, "DA9055 rsel GPI");
ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
name);
if (ret < 0)
goto err;
/* /*
* Let the regulator know that its register set A/B * Let the regulator know that its register set A/B
...@@ -477,7 +478,6 @@ static int da9055_gpio_init(struct da9055_regulator *regulator, ...@@ -477,7 +478,6 @@ static int da9055_gpio_init(struct da9055_regulator *regulator,
<< DA9055_V_GPI_SHIFT); << DA9055_V_GPI_SHIFT);
} }
err:
return ret; return ret;
} }
...@@ -532,7 +532,7 @@ static int da9055_regulator_probe(struct platform_device *pdev) ...@@ -532,7 +532,7 @@ static int da9055_regulator_probe(struct platform_device *pdev)
if (pdata) if (pdata)
config.init_data = pdata->regulators[pdev->id]; config.init_data = pdata->regulators[pdev->id];
ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); ret = da9055_gpio_init(&pdev->dev, regulator, &config, pdata, pdev->id);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#define DA9055_MAX_REGULATORS 8 #define DA9055_MAX_REGULATORS 8
struct da9055; struct da9055;
struct gpio_desc;
enum gpio_select { enum gpio_select {
NO_GPIO = 0, NO_GPIO = 0,
...@@ -23,16 +22,6 @@ struct da9055_pdata { ...@@ -23,16 +22,6 @@ struct da9055_pdata {
struct regulator_init_data *regulators[DA9055_MAX_REGULATORS]; struct regulator_init_data *regulators[DA9055_MAX_REGULATORS];
/* Enable RTC in RESET Mode */ /* Enable RTC in RESET Mode */
bool reset_enable; bool reset_enable;
/*
* GPI muxed pin to control
* regulator state A/B, 0 if not available.
*/
int *gpio_ren;
/*
* GPI muxed pin to control
* regulator set, 0 if not available.
*/
int *gpio_rsel;
/* /*
* Regulator mode control bits value (GPI offset) that * Regulator mode control bits value (GPI offset) that
* controls the regulator state, 0 if not available. * controls the regulator state, 0 if not available.
...@@ -43,7 +32,5 @@ struct da9055_pdata { ...@@ -43,7 +32,5 @@ struct da9055_pdata {
* controls the regulator set A/B, 0 if not available. * controls the regulator set A/B, 0 if not available.
*/ */
enum gpio_select *reg_rsel; enum gpio_select *reg_rsel;
/* GPIO descriptors to enable regulator, NULL if not available */
struct gpio_desc **ena_gpiods;
}; };
#endif /* __DA9055_PDATA_H */ #endif /* __DA9055_PDATA_H */
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