Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <linus.walleij@linaro.org>
Link: https://msgid.link/r/20240220-descriptors-regulators-v1-3-097f608694be@linaro.org
Acked-by: Lee Jones <lee@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Linus Walleij and committed by
Mark Brown
95daa868 e450a2b3

+28 -45
+26 -38
drivers/regulator/lp8788-buck.c
··· 13 13 #include <linux/platform_device.h> 14 14 #include <linux/regulator/driver.h> 15 15 #include <linux/mfd/lp8788.h> 16 - #include <linux/gpio.h> 16 + #include <linux/gpio/consumer.h> 17 17 18 18 /* register address */ 19 19 #define LP8788_EN_BUCK 0x0C ··· 69 69 #define BUCK_FPWM_SHIFT(x) (x) 70 70 71 71 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, 74 74 }; 75 75 76 76 enum lp8788_dvs_mode { ··· 89 89 struct lp8788 *lp; 90 90 struct regulator_dev *regulator; 91 91 void *dvs; 92 + struct gpio_desc *gpio1; 93 + struct gpio_desc *gpio2; /* Only used on BUCK2 */ 92 94 }; 93 95 94 96 /* BUCK 1 ~ 4 voltage ranges */ ··· 108 106 return; 109 107 110 108 pinstate = dvs->vsel == DVS_SEL_V0 ? DVS_LOW : DVS_HIGH; 111 - if (gpio_is_valid(dvs->gpio)) 112 - gpio_set_value(dvs->gpio, pinstate); 109 + gpiod_set_value(buck->gpio1, pinstate); 113 110 } 114 111 115 112 static void lp8788_buck2_set_dvs(struct lp8788_buck *buck) ··· 140 139 return; 141 140 } 142 141 143 - if (gpio_is_valid(dvs->gpio[0])) 144 - gpio_set_value(dvs->gpio[0], pin1); 145 - 146 - if (gpio_is_valid(dvs->gpio[1])) 147 - gpio_set_value(dvs->gpio[1], pin2); 142 + gpiod_set_value(buck->gpio1, pin1); 143 + gpiod_set_value(buck->gpio2, pin2); 148 144 } 149 145 150 146 static void lp8788_set_dvs(struct lp8788_buck *buck, enum lp8788_buck_id id) ··· 200 202 enum lp8788_buck_id id) 201 203 { 202 204 enum lp8788_dvs_mode mode = lp8788_get_buck_dvs_ctrl_mode(buck, id); 203 - struct lp8788_buck1_dvs *b1_dvs; 204 - struct lp8788_buck2_dvs *b2_dvs; 205 205 u8 val, idx, addr; 206 206 int pin1, pin2; 207 207 208 208 switch (id) { 209 209 case BUCK1: 210 210 if (mode == EXTPIN) { 211 - b1_dvs = (struct lp8788_buck1_dvs *)buck->dvs; 212 - if (!b1_dvs) 213 - goto err; 214 - 215 - idx = gpio_get_value(b1_dvs->gpio) ? 1 : 0; 211 + idx = gpiod_get_value(buck->gpio1); 216 212 } else { 217 213 lp8788_read_byte(buck->lp, LP8788_BUCK_DVS_SEL, &val); 218 214 idx = (val & LP8788_BUCK1_DVS_M) >> LP8788_BUCK1_DVS_S; ··· 215 223 break; 216 224 case BUCK2: 217 225 if (mode == EXTPIN) { 218 - b2_dvs = (struct lp8788_buck2_dvs *)buck->dvs; 219 - if (!b2_dvs) 220 - goto err; 221 - 222 - pin1 = gpio_get_value(b2_dvs->gpio[0]); 223 - pin2 = gpio_get_value(b2_dvs->gpio[1]); 226 + pin1 = gpiod_get_value(buck->gpio1); 227 + pin2 = gpiod_get_value(buck->gpio2); 224 228 225 229 if (pin1 == PIN_LOW && pin2 == PIN_LOW) 226 230 idx = 0; ··· 412 424 enum lp8788_buck_id id) 413 425 { 414 426 struct lp8788_platform_data *pdata = buck->lp->pdata; 415 - char *b1_name = "LP8788_B1_DVS"; 416 - char *b2_name[] = { "LP8788_B2_DVS1", "LP8788_B2_DVS2" }; 417 - int i, gpio, ret; 427 + struct device *dev = &pdev->dev; 418 428 419 429 switch (id) { 420 430 case BUCK1: 421 - gpio = pdata->buck1_dvs->gpio; 422 - ret = devm_gpio_request_one(&pdev->dev, gpio, DVS_LOW, 423 - b1_name); 424 - if (ret) 425 - return ret; 431 + buck->gpio1 = devm_gpiod_get(dev, "dvs", GPIOD_OUT_LOW); 432 + if (IS_ERR(buck->gpio1)) 433 + return PTR_ERR(buck->gpio1); 434 + gpiod_set_consumer_name(buck->gpio1, "LP8788_B1_DVS"); 426 435 427 436 buck->dvs = pdata->buck1_dvs; 428 437 break; 429 438 case BUCK2: 430 - for (i = 0; i < LP8788_NUM_BUCK2_DVS; i++) { 431 - gpio = pdata->buck2_dvs->gpio[i]; 432 - ret = devm_gpio_request_one(&pdev->dev, gpio, 433 - DVS_LOW, b2_name[i]); 434 - if (ret) 435 - return ret; 436 - } 439 + buck->gpio1 = devm_gpiod_get_index(dev, "dvs", 0, GPIOD_OUT_LOW); 440 + if (IS_ERR(buck->gpio1)) 441 + return PTR_ERR(buck->gpio1); 442 + gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS1"); 443 + 444 + buck->gpio2 = devm_gpiod_get_index(dev, "dvs", 1, GPIOD_OUT_LOW); 445 + if (IS_ERR(buck->gpio1)) 446 + return PTR_ERR(buck->gpio1); 447 + gpiod_set_consumer_name(buck->gpio1, "LP8788_B2_DVS2"); 448 + 437 449 buck->dvs = pdata->buck2_dvs; 438 450 break; 439 451 default:
+2 -7
include/linux/mfd/lp8788.h
··· 10 10 #ifndef __MFD_LP8788_H__ 11 11 #define __MFD_LP8788_H__ 12 12 13 - #include <linux/gpio.h> 14 13 #include <linux/irqdomain.h> 15 14 #include <linux/pwm.h> 16 15 #include <linux/regmap.h> ··· 158 159 159 160 /* 160 161 * lp8788_buck1_dvs 161 - * @gpio : gpio pin number for dvs control 162 162 * @vsel : dvs selector for buck v1 register 163 163 */ 164 164 struct lp8788_buck1_dvs { 165 - int gpio; 166 165 enum lp8788_dvs_sel vsel; 167 166 }; 168 167 169 168 /* 170 169 * lp8788_buck2_dvs 171 - * @gpio : two gpio pin numbers are used for dvs 172 170 * @vsel : dvs selector for buck v2 register 173 171 */ 174 172 struct lp8788_buck2_dvs { 175 - int gpio[LP8788_NUM_BUCK2_DVS]; 176 173 enum lp8788_dvs_sel vsel; 177 174 }; 178 175 ··· 263 268 * @buck_data : regulator initial data for buck 264 269 * @dldo_data : regulator initial data for digital ldo 265 270 * @aldo_data : regulator initial data for analog ldo 266 - * @buck1_dvs : gpio configurations for buck1 dvs 267 - * @buck2_dvs : gpio configurations for buck2 dvs 271 + * @buck1_dvs : configurations for buck1 dvs 272 + * @buck2_dvs : configurations for buck2 dvs 268 273 * @chg_pdata : platform data for charger driver 269 274 * @alarm_sel : rtc alarm selection (1 or 2) 270 275 * @bl_pdata : configurable data for backlight driver