Skip to content

Commit e450a2b

Browse files
linuswbroonie
authored andcommitted
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: Linus Walleij <[email protected]> Link: https://msgid.link/r/[email protected] Acked-by: Lee Jones <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 4d52f57 commit e450a2b

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

drivers/regulator/da9055-regulator.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <linux/module.h>
1010
#include <linux/init.h>
1111
#include <linux/err.h>
12-
#include <linux/gpio.h>
1312
#include <linux/gpio/consumer.h>
1413
#include <linux/platform_device.h>
1514
#include <linux/regulator/driver.h>
@@ -413,31 +412,35 @@ static struct da9055_regulator_info da9055_regulator_info[] = {
413412
* GPIO can control regulator state and/or select the regulator register
414413
* set A/B for voltage ramping.
415414
*/
416-
static int da9055_gpio_init(struct da9055_regulator *regulator,
415+
static int da9055_gpio_init(struct device *dev,
416+
struct da9055_regulator *regulator,
417417
struct regulator_config *config,
418418
struct da9055_pdata *pdata, int id)
419419
{
420420
struct da9055_regulator_info *info = regulator->info;
421+
struct gpio_desc *ren;
422+
struct gpio_desc *ena;
423+
struct gpio_desc *rsel;
421424
int ret = 0;
422425

423-
if (!pdata)
424-
return 0;
426+
/* Look for "regulator-enable-gpios" GPIOs in the regulator node */
427+
ren = devm_gpiod_get_optional(dev, "regulator-enable", GPIOD_IN);
428+
if (IS_ERR(ren))
429+
return PTR_ERR(ren);
425430

426-
if (pdata->gpio_ren && pdata->gpio_ren[id]) {
427-
char name[18];
428-
int gpio_mux = pdata->gpio_ren[id];
431+
if (ren) {
432+
/* This GPIO is not optional at this point */
433+
ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
434+
if (IS_ERR(ena))
435+
return PTR_ERR(ena);
429436

430-
config->ena_gpiod = pdata->ena_gpiods[id];
437+
config->ena_gpiod = ena;
431438

432439
/*
433440
* GPI pin is muxed with regulator to control the
434441
* regulator state.
435442
*/
436-
sprintf(name, "DA9055 GPI %d", gpio_mux);
437-
ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
438-
name);
439-
if (ret < 0)
440-
goto err;
443+
gpiod_set_consumer_name(ren, "DA9055 ren GPI");
441444

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

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

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

460465
/*
461466
* GPI pin is muxed with regulator to select the
462467
* regulator register set A/B for voltage ramping.
463468
*/
464-
sprintf(name, "DA9055 GPI %d", gpio_mux);
465-
ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
466-
name);
467-
if (ret < 0)
468-
goto err;
469+
gpiod_set_consumer_name(rsel, "DA9055 rsel GPI");
469470

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

480-
err:
481481
return ret;
482482
}
483483

@@ -532,7 +532,7 @@ static int da9055_regulator_probe(struct platform_device *pdev)
532532
if (pdata)
533533
config.init_data = pdata->regulators[pdev->id];
534534

535-
ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);
535+
ret = da9055_gpio_init(&pdev->dev, regulator, &config, pdata, pdev->id);
536536
if (ret < 0)
537537
return ret;
538538

include/linux/mfd/da9055/pdata.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define DA9055_MAX_REGULATORS 8
88

99
struct da9055;
10-
struct gpio_desc;
1110

1211
enum gpio_select {
1312
NO_GPIO = 0,
@@ -23,16 +22,6 @@ struct da9055_pdata {
2322
struct regulator_init_data *regulators[DA9055_MAX_REGULATORS];
2423
/* Enable RTC in RESET Mode */
2524
bool reset_enable;
26-
/*
27-
* GPI muxed pin to control
28-
* regulator state A/B, 0 if not available.
29-
*/
30-
int *gpio_ren;
31-
/*
32-
* GPI muxed pin to control
33-
* regulator set, 0 if not available.
34-
*/
35-
int *gpio_rsel;
3625
/*
3726
* Regulator mode control bits value (GPI offset) that
3827
* controls the regulator state, 0 if not available.
@@ -43,7 +32,5 @@ struct da9055_pdata {
4332
* controls the regulator set A/B, 0 if not available.
4433
*/
4534
enum gpio_select *reg_rsel;
46-
/* GPIO descriptors to enable regulator, NULL if not available */
47-
struct gpio_desc **ena_gpiods;
4835
};
4936
#endif /* __DA9055_PDATA_H */

0 commit comments

Comments
 (0)