Skip to content

Commit 802ec11

Browse files
committed
Convert some regulator drivers to GPIO descriptors
Merge series from Linus Walleij <linus.walleij@linaro.org>: Despite the work to convert the regulator core to GPIO descriptors, there are some outliers that use legacy GPIO numbers in various ways. Convert them all over.
2 parents 531a0c0 + f25828a commit 802ec11

File tree

10 files changed

+143
-275
lines changed

10 files changed

+143
-275
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

drivers/regulator/lp8788-buck.c

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <linux/platform_device.h>
1414
#include <linux/regulator/driver.h>
1515
#include <linux/mfd/lp8788.h>
16-
#include <linux/gpio.h>
16+
#include <linux/gpio/consumer.h>
1717

1818
/* register address */
1919
#define LP8788_EN_BUCK 0x0C
@@ -69,8 +69,8 @@
6969
#define BUCK_FPWM_SHIFT(x) (x)
7070

7171
enum lp8788_dvs_state {
72-
DVS_LOW = GPIOF_OUT_INIT_LOW,
73-
DVS_HIGH = GPIOF_OUT_INIT_HIGH,
72+
DVS_LOW = 0,
73+
DVS_HIGH = 1,
7474
};
7575

7676
enum lp8788_dvs_mode {
@@ -89,6 +89,8 @@ struct lp8788_buck {
8989
struct lp8788 *lp;
9090
struct regulator_dev *regulator;
9191
void *dvs;
92+
struct gpio_desc *gpio1;
93+
struct gpio_desc *gpio2; /* Only used on BUCK2 */
9294
};
9395

9496
/* BUCK 1 ~ 4 voltage ranges */
@@ -106,8 +108,7 @@ static void lp8788_buck1_set_dvs(struct lp8788_buck *buck)
106108
return;
107109

108110
pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH;
109-
if (gpio_is_valid(dvs->gpio))
110-
gpio_set_value(dvs->gpio, pinstate);
111+
gpiod_set_value(buck->gpio1, pinstate);
111112
}
112113

113114
static void lp8788_buck2_set_dvs(struct lp8788_buck *buck)
@@ -139,11 +140,8 @@ static void lp8788_buck2_set_dvs(struct lp8788_buck *buck)
139140
return;
140141
}
141142

142-
if (gpio_is_valid(dvs->gpio[0]))
143-
gpio_set_value(dvs->gpio[0], pin1);
144-
145-
if (gpio_is_valid(dvs->gpio[1]))
146-
gpio_set_value(dvs->gpio[1], pin2);
143+
gpiod_set_value(buck->gpio1, pin1);
144+
gpiod_set_value(buck->gpio2, pin2);
147145
}
148146

149147
static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id)
@@ -202,19 +200,13 @@ static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck,
202200
enum lp8788_buck_id id)
203201
{
204202
enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id);
205-
struct lp8788_buck1_dvs *b1_dvs;
206-
struct lp8788_buck2_dvs *b2_dvs;
207203
u8 val, idx, addr;
208204
int pin1, pin2;
209205

210206
switch (id) {
211207
case BUCK1:
212208
if (mode == EXTPIN) {
213-
b1_dvs = (struct lp8788_buck1_dvs *)buck->dvs;
214-
if (!b1_dvs)
215-
goto err;
216-
217-
idx = gpio_get_value(b1_dvs->gpio) ? 1 : 0;
209+
idx = gpiod_get_value(buck->gpio1);
218210
} else {
219211
lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val);
220212
idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S;
@@ -223,12 +215,8 @@ static u8 lp8788_select_buck_vout_addr(struct lp8788_buck *buck,
223215
break;
224216
case BUCK2:
225217
if (mode == EXTPIN) {
226-
b2_dvs = (struct lp8788_buck2_dvs *)buck->dvs;
227-
if (!b2_dvs)
228-
goto err;
229-
230-
pin1 = gpio_get_value(b2_dvs->gpio[0]);
231-
pin2 = gpio_get_value(b2_dvs->gpio[1]);
218+
pin1 = gpiod_get_value(buck->gpio1);
219+
pin2 = gpiod_get_value(buck->gpio2);
232220

233221
if (pin1 == PIN_LOW && pin2 == PIN_LOW)
234222
idx = 0;
@@ -424,28 +412,28 @@ static int lp8788_dvs_gpio_request(struct platform_device *pdev,
424412
enum lp8788_buck_id id)
425413
{
426414
struct lp8788_platform_data *pdata = buck->lp->pdata;
427-
char *b1_name = "LP8788_B1_DVS";
428-
char *b2_name[] = { "LP8788_B2_DVS1", "LP8788_B2_DVS2" };
429-
int i, gpio, ret;
415+
struct device *dev = &pdev->dev;
430416

431417
switch (id) {
432418
case BUCK1:
433-
gpio = pdata->buck1_dvs->gpio;
434-
ret = devm_gpio_request_one(&pdev->dev, gpio, DVS_LOW,
435-
b1_name);
436-
if (ret)
437-
return ret;
419+
buck->gpio1 = devm_gpiod_get(dev, "dvs", GPIOD_OUT_LOW);
420+
if (IS_ERR(buck->gpio1))
421+
return PTR_ERR(buck->gpio1);
422+
gpiod_set_consumer_name(buck->gpio1, "LP8788_B1_DVS");
438423

439424
buck->dvs = pdata->buck1_dvs;
440425
break;
441426
case BUCK2:
442-
for (i = 0; i < LP8788_NUM_BUCK2_DVS; i++) {
443-
gpio = pdata->buck2_dvs->gpio[i];
444-
ret = devm_gpio_request_one(&pdev->dev, gpio,
445-
DVS_LOW, b2_name[i]);
446-
if (ret)
447-
return ret;
448-
}
427+
buck->gpio1 = devm_gpiod_get_index(dev, "dvs", 0, GPIOD_OUT_LOW);
428+
if (IS_ERR(buck->gpio1))
429+
return PTR_ERR(buck->gpio1);
430+
gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS1");
431+
432+
buck->gpio2 = devm_gpiod_get_index(dev, "dvs", 1, GPIOD_OUT_LOW);
433+
if (IS_ERR(buck->gpio1))
434+
return PTR_ERR(buck->gpio1);
435+
gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS2");
436+
449437
buck->dvs = pdata->buck2_dvs;
450438
break;
451439
default:

drivers/regulator/max8973-regulator.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
#include <linux/regulator/machine.h>
2121
#include <linux/regulator/max8973-regulator.h>
2222
#include <linux/regulator/of_regulator.h>
23-
#include <linux/gpio.h>
2423
#include <linux/gpio/consumer.h>
25-
#include <linux/of_gpio.h>
2624
#include <linux/i2c.h>
2725
#include <linux/slab.h>
2826
#include <linux/regmap.h>
@@ -102,7 +100,7 @@ struct max8973_chip {
102100
struct regulator_desc desc;
103101
struct regmap *regmap;
104102
bool enable_external_control;
105-
int dvs_gpio;
103+
struct gpio_desc *dvs_gpiod;
106104
int lru_index[MAX8973_MAX_VOUT_REG];
107105
int curr_vout_val[MAX8973_MAX_VOUT_REG];
108106
int curr_vout_reg;
@@ -184,7 +182,7 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
184182
* If gpios are available to select the VOUT register then least
185183
* recently used register for new configuration.
186184
*/
187-
if (gpio_is_valid(max->dvs_gpio))
185+
if (max->dvs_gpiod)
188186
found = find_voltage_set_register(max, vsel,
189187
&vout_reg, &gpio_val);
190188

@@ -201,8 +199,8 @@ static int max8973_dcdc_set_voltage_sel(struct regulator_dev *rdev,
201199
}
202200

203201
/* Select proper VOUT register vio gpios */
204-
if (gpio_is_valid(max->dvs_gpio)) {
205-
gpio_set_value_cansleep(max->dvs_gpio, gpio_val & 0x1);
202+
if (max->dvs_gpiod) {
203+
gpiod_set_value_cansleep(max->dvs_gpiod, gpio_val & 0x1);
206204
max->curr_gpio_val = gpio_val;
207205
}
208206
return 0;
@@ -531,7 +529,6 @@ static struct max8973_regulator_platform_data *max8973_parse_dt(
531529

532530
pdata->enable_ext_control = of_property_read_bool(np,
533531
"maxim,externally-enable");
534-
pdata->dvs_gpio = of_get_named_gpio(np, "maxim,dvs-gpio", 0);
535532

536533
ret = of_property_read_u32(np, "maxim,dvs-default-state", &pval);
537534
if (!ret)
@@ -612,13 +609,17 @@ static int max8973_probe(struct i2c_client *client)
612609
return -EIO;
613610
}
614611

615-
if (pdata->dvs_gpio == -EPROBE_DEFER)
616-
return -EPROBE_DEFER;
617-
618612
max = devm_kzalloc(&client->dev, sizeof(*max), GFP_KERNEL);
619613
if (!max)
620614
return -ENOMEM;
621615

616+
max->dvs_gpiod = devm_gpiod_get_optional(&client->dev, "maxim,dvs",
617+
(pdata->dvs_def_state) ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW);
618+
if (IS_ERR(max->dvs_gpiod))
619+
return dev_err_probe(&client->dev, PTR_ERR(max->dvs_gpiod),
620+
"failed to obtain dvs gpio\n");
621+
gpiod_set_consumer_name(max->dvs_gpiod, "max8973-dvs");
622+
622623
max->regmap = devm_regmap_init_i2c(client, &max8973_regmap_config);
623624
if (IS_ERR(max->regmap)) {
624625
ret = PTR_ERR(max->regmap);
@@ -663,29 +664,16 @@ static int max8973_probe(struct i2c_client *client)
663664
max->desc.ramp_delay_table = max8973_buck_ramp_table;
664665
max->desc.n_ramp_values = ARRAY_SIZE(max8973_buck_ramp_table);
665666

666-
max->dvs_gpio = (pdata->dvs_gpio) ? pdata->dvs_gpio : -EINVAL;
667667
max->enable_external_control = pdata->enable_ext_control;
668668
max->curr_gpio_val = pdata->dvs_def_state;
669669
max->curr_vout_reg = MAX8973_VOUT + pdata->dvs_def_state;
670670
max->junction_temp_warning = pdata->junction_temp_warning;
671671

672672
max->lru_index[0] = max->curr_vout_reg;
673673

674-
if (gpio_is_valid(max->dvs_gpio)) {
675-
int gpio_flags;
674+
if (max->dvs_gpiod) {
676675
int i;
677676

678-
gpio_flags = (pdata->dvs_def_state) ?
679-
GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
680-
ret = devm_gpio_request_one(&client->dev, max->dvs_gpio,
681-
gpio_flags, "max8973-dvs");
682-
if (ret) {
683-
dev_err(&client->dev,
684-
"gpio_request for gpio %d failed, err = %d\n",
685-
max->dvs_gpio, ret);
686-
return ret;
687-
}
688-
689677
/*
690678
* Initialize the lru index with vout_reg id
691679
* The index 0 will be most recently used and

0 commit comments

Comments
 (0)