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: 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 <linus.walleij@linaro.org>
Link: https://msgid.link/r/20240220-descriptors-regulators-v1-2-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
e450a2b3 4d52f575

+24 -37
+24 -24
drivers/regulator/da9055-regulator.c
··· 9 9 #include <linux/module.h> 10 10 #include <linux/init.h> 11 11 #include <linux/err.h> 12 - #include <linux/gpio.h> 13 12 #include <linux/gpio/consumer.h> 14 13 #include <linux/platform_device.h> 15 14 #include <linux/regulator/driver.h> ··· 412 413 * GPIO can control regulator state and/or select the regulator register 413 414 * set A/B for voltage ramping. 414 415 */ 415 - static int da9055_gpio_init(struct da9055_regulator *regulator, 416 + static int da9055_gpio_init(struct device *dev, 417 + struct da9055_regulator *regulator, 416 418 struct regulator_config *config, 417 419 struct da9055_pdata *pdata, int id) 418 420 { 419 421 struct da9055_regulator_info *info = regulator->info; 422 + struct gpio_desc *ren; 423 + struct gpio_desc *ena; 424 + struct gpio_desc *rsel; 420 425 int ret = 0; 421 426 422 - if (!pdata) 423 - return 0; 427 + /* Look for "regulator-enable-gpios" GPIOs in the regulator node */ 428 + ren = devm_gpiod_get_optional(dev, "regulator-enable", GPIOD_IN); 429 + if (IS_ERR(ren)) 430 + return PTR_ERR(ren); 424 431 425 - if (pdata->gpio_ren && pdata->gpio_ren[id]) { 426 - char name[18]; 427 - int gpio_mux = pdata->gpio_ren[id]; 432 + if (ren) { 433 + /* This GPIO is not optional at this point */ 434 + ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH); 435 + if (IS_ERR(ena)) 436 + return PTR_ERR(ena); 428 437 429 - config->ena_gpiod = pdata->ena_gpiods[id]; 438 + config->ena_gpiod = ena; 430 439 431 440 /* 432 441 * GPI pin is muxed with regulator to control the 433 442 * regulator state. 434 443 */ 435 - sprintf(name, "DA9055 GPI %d", gpio_mux); 436 - ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, 437 - name); 438 - if (ret < 0) 439 - goto err; 444 + gpiod_set_consumer_name(ren, "DA9055 ren GPI"); 440 445 441 446 /* 442 447 * Let the regulator know that its state is controlled ··· 451 448 pdata->reg_ren[id] 452 449 << DA9055_E_GPI_SHIFT); 453 450 if (ret < 0) 454 - goto err; 451 + return ret; 455 452 } 456 453 457 - if (pdata->gpio_rsel && pdata->gpio_rsel[id]) { 458 - char name[18]; 459 - int gpio_mux = pdata->gpio_rsel[id]; 454 + /* Look for "regulator-select-gpios" GPIOs in the regulator node */ 455 + rsel = devm_gpiod_get_optional(dev, "regulator-select", GPIOD_IN); 456 + if (IS_ERR(rsel)) 457 + return PTR_ERR(rsel); 460 458 459 + if (rsel) { 461 460 regulator->reg_rselect = pdata->reg_rsel[id]; 462 461 463 462 /* 464 463 * GPI pin is muxed with regulator to select the 465 464 * regulator register set A/B for voltage ramping. 466 465 */ 467 - sprintf(name, "DA9055 GPI %d", gpio_mux); 468 - ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN, 469 - name); 470 - if (ret < 0) 471 - goto err; 466 + gpiod_set_consumer_name(rsel, "DA9055 rsel GPI"); 472 467 473 468 /* 474 469 * Let the regulator know that its register set A/B ··· 478 477 << DA9055_V_GPI_SHIFT); 479 478 } 480 479 481 - err: 482 480 return ret; 483 481 } 484 482 ··· 532 532 if (pdata) 533 533 config.init_data = pdata->regulators[pdev->id]; 534 534 535 - ret = da9055_gpio_init(regulator, &config, pdata, pdev->id); 535 + ret = da9055_gpio_init(&pdev->dev, regulator, &config, pdata, pdev->id); 536 536 if (ret < 0) 537 537 return ret; 538 538
-13
include/linux/mfd/da9055/pdata.h
··· 7 7 #define DA9055_MAX_REGULATORS 8 8 8 9 9 struct da9055; 10 - struct gpio_desc; 11 10 12 11 enum gpio_select { 13 12 NO_GPIO = 0, ··· 23 24 /* Enable RTC in RESET Mode */ 24 25 bool reset_enable; 25 26 /* 26 - * GPI muxed pin to control 27 - * regulator state A/B, 0 if not available. 28 - */ 29 - int *gpio_ren; 30 - /* 31 - * GPI muxed pin to control 32 - * regulator set, 0 if not available. 33 - */ 34 - int *gpio_rsel; 35 - /* 36 27 * Regulator mode control bits value (GPI offset) that 37 28 * controls the regulator state, 0 if not available. 38 29 */ ··· 32 43 * controls the regulator set A/B, 0 if not available. 33 44 */ 34 45 enum gpio_select *reg_rsel; 35 - /* GPIO descriptors to enable regulator, NULL if not available */ 36 - struct gpio_desc **ena_gpiods; 37 46 }; 38 47 #endif /* __DA9055_PDATA_H */