Skip to content

Commit

Permalink
regulator: da9055: Fully convert to GPIO descriptors
Browse files Browse the repository at this point in the history
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: Linus Walleij <[email protected]>
Link: https://msgid.link/r/[email protected]
Acked-by: Lee Jones <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
linusw authored and broonie committed Feb 26, 2024
1 parent 4d52f57 commit e450a2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
48 changes: 24 additions & 24 deletions drivers/regulator/da9055-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
Expand Down Expand Up @@ -413,31 +412,35 @@ static struct da9055_regulator_info da9055_regulator_info[] = {
* GPIO can control regulator state and/or select the regulator register
* 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 da9055_pdata *pdata, int id)
{
struct da9055_regulator_info *info = regulator->info;
struct gpio_desc *ren;
struct gpio_desc *ena;
struct gpio_desc *rsel;
int ret = 0;

if (!pdata)
return 0;
/* Look for "regulator-enable-gpios" GPIOs in the regulator node */
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]) {
char name[18];
int gpio_mux = pdata->gpio_ren[id];
if (ren) {
/* This GPIO is not optional at this point */
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
* regulator state.
*/
sprintf(name, "DA9055 GPI %d", gpio_mux);
ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
name);
if (ret < 0)
goto err;
gpiod_set_consumer_name(ren, "DA9055 ren GPI");

/*
* Let the regulator know that its state is controlled
Expand All @@ -448,24 +451,22 @@ static int da9055_gpio_init(struct da9055_regulator *regulator,
pdata->reg_ren[id]
<< DA9055_E_GPI_SHIFT);
if (ret < 0)
goto err;
return ret;
}

if (pdata->gpio_rsel && pdata->gpio_rsel[id]) {
char name[18];
int gpio_mux = pdata->gpio_rsel[id];
/* Look for "regulator-select-gpios" GPIOs in the regulator node */
rsel = devm_gpiod_get_optional(dev, "regulator-select", GPIOD_IN);
if (IS_ERR(rsel))
return PTR_ERR(rsel);

if (rsel) {
regulator->reg_rselect = pdata->reg_rsel[id];

/*
* GPI pin is muxed with regulator to select the
* regulator register set A/B for voltage ramping.
*/
sprintf(name, "DA9055 GPI %d", gpio_mux);
ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
name);
if (ret < 0)
goto err;
gpiod_set_consumer_name(rsel, "DA9055 rsel GPI");

/*
* Let the regulator know that its register set A/B
Expand All @@ -477,7 +478,6 @@ static int da9055_gpio_init(struct da9055_regulator *regulator,
<< DA9055_V_GPI_SHIFT);
}

err:
return ret;
}

Expand Down Expand Up @@ -532,7 +532,7 @@ static int da9055_regulator_probe(struct platform_device *pdev)
if (pdata)
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)
return ret;

Expand Down
13 changes: 0 additions & 13 deletions include/linux/mfd/da9055/pdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define DA9055_MAX_REGULATORS 8

struct da9055;
struct gpio_desc;

enum gpio_select {
NO_GPIO = 0,
Expand All @@ -23,16 +22,6 @@ struct da9055_pdata {
struct regulator_init_data *regulators[DA9055_MAX_REGULATORS];
/* Enable RTC in RESET Mode */
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
* controls the regulator state, 0 if not available.
Expand All @@ -43,7 +32,5 @@ struct da9055_pdata {
* controls the regulator set A/B, 0 if not available.
*/
enum gpio_select *reg_rsel;
/* GPIO descriptors to enable regulator, NULL if not available */
struct gpio_desc **ena_gpiods;
};
#endif /* __DA9055_PDATA_H */

0 comments on commit e450a2b

Please sign in to comment.