Skip to content

Commit 95daa86

Browse files
linuswbroonie
authored andcommitted
regulator: lp8788-buck: Fully convert to GPIO descriptors
This converts the LP8788 BUCK regulator driver to use GPIO descriptors. BUCK1 can use one DVS GPIO and BUCK2 can use two DVS GPIOS, and no more so just hardcode two GPIO descriptors into the per-DVS state containers. Obtain the descriptors from each regulators subdevice. As there are no in-tree users, board files need to populate descriptor tables for the buck regulator devices when they want to use this driver. BUCK1 need a GPIO descriptor at index 0 and BUCK2 needs two GPIO descriptors at indices 0 and 1. 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 e450a2b commit 95daa86

File tree

2 files changed

+28
-45
lines changed

2 files changed

+28
-45
lines changed

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:

include/linux/mfd/lp8788.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#ifndef __MFD_LP8788_H__
1111
#define __MFD_LP8788_H__
1212

13-
#include <linux/gpio.h>
1413
#include <linux/irqdomain.h>
1514
#include <linux/pwm.h>
1615
#include <linux/regmap.h>
@@ -159,21 +158,17 @@ struct lp8788;
159158

160159
/*
161160
* lp8788_buck1_dvs
162-
* @gpio : gpio pin number for dvs control
163161
* @vsel : dvs selector for buck v1 register
164162
*/
165163
struct lp8788_buck1_dvs {
166-
int gpio;
167164
enum lp8788_dvs_sel vsel;
168165
};
169166

170167
/*
171168
* lp8788_buck2_dvs
172-
* @gpio : two gpio pin numbers are used for dvs
173169
* @vsel : dvs selector for buck v2 register
174170
*/
175171
struct lp8788_buck2_dvs {
176-
int gpio[LP8788_NUM_BUCK2_DVS];
177172
enum lp8788_dvs_sel vsel;
178173
};
179174

@@ -268,8 +263,8 @@ struct lp8788_vib_platform_data {
268263
* @buck_data : regulator initial data for buck
269264
* @dldo_data : regulator initial data for digital ldo
270265
* @aldo_data : regulator initial data for analog ldo
271-
* @buck1_dvs : gpio configurations for buck1 dvs
272-
* @buck2_dvs : gpio configurations for buck2 dvs
266+
* @buck1_dvs : configurations for buck1 dvs
267+
* @buck2_dvs : configurations for buck2 dvs
273268
* @chg_pdata : platform data for charger driver
274269
* @alarm_sel : rtc alarm selection (1 or 2)
275270
* @bl_pdata : configurable data for backlight driver

0 commit comments

Comments
 (0)