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

regulator: rk808: make better use of the gpiod API

The gpiod functions include variants for managed gpiod resources. Use it
to simplify the remove function.

As the driver handles a device node without a specification of dvs gpios
just fine, additionally use the variant of gpiod_get exactly for this
use case. This makes error checking more strict.

As a third benefit this patch makes the driver use the flags parameter
of gpiod_get* which will not be optional any more after 4.2 and so
prevents a build failure when the respective gpiod commit is merged.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Uwe Kleine-König and committed by
Mark Brown
a13eaf02 604d4994

+12 -20
+12 -20
drivers/regulator/rk808-regulator.c
··· 95 95 unsigned int val; 96 96 int ret; 97 97 98 - if (IS_ERR(gpio) || gpiod_get_value(gpio) == 0) 98 + if (!gpio || gpiod_get_value(gpio) == 0) 99 99 return regulator_get_voltage_sel_regmap(rdev); 100 100 101 101 ret = regmap_read(rdev->regmap, ··· 169 169 unsigned old_sel; 170 170 int ret, gpio_level; 171 171 172 - if (IS_ERR(gpio)) 172 + if (!gpio) 173 173 return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel); 174 174 175 175 gpio_level = gpiod_get_value(gpio); ··· 206 206 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 207 207 208 208 /* if there is no dvs1/2 pin, we don't need wait extra time here. */ 209 - if (IS_ERR(gpio)) 209 + if (!gpio) 210 210 return 0; 211 211 212 212 return regulator_set_voltage_time_sel(rdev, old_selector, new_selector); ··· 541 541 goto dt_parse_end; 542 542 543 543 for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) { 544 - pdata->dvs_gpio[i] = gpiod_get_index(client_dev, "dvs", i); 544 + pdata->dvs_gpio[i] = 545 + devm_gpiod_get_index_optional(client_dev, "dvs", i, 546 + GPIOD_OUT_LOW); 545 547 if (IS_ERR(pdata->dvs_gpio[i])) { 548 + ret = PTR_ERR(pdata->dvs_gpio[i]); 549 + dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret); 550 + goto dt_parse_end; 551 + } 552 + 553 + if (!pdata->dvs_gpio[i]) { 546 554 dev_warn(dev, "there is no dvs%d gpio\n", i); 547 555 continue; 548 556 } 549 - 550 - gpiod_direction_output(pdata->dvs_gpio[i], 0); 551 557 552 558 tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL; 553 559 ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp, ··· 564 558 dt_parse_end: 565 559 of_node_put(np); 566 560 return ret; 567 - } 568 - 569 - static int rk808_regulator_remove(struct platform_device *pdev) 570 - { 571 - struct rk808_regulator_data *pdata = platform_get_drvdata(pdev); 572 - int i; 573 - 574 - for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) { 575 - if (!IS_ERR(pdata->dvs_gpio[i])) 576 - gpiod_put(pdata->dvs_gpio[i]); 577 - } 578 - 579 - return 0; 580 561 } 581 562 582 563 static int rk808_regulator_probe(struct platform_device *pdev) ··· 612 619 613 620 static struct platform_driver rk808_regulator_driver = { 614 621 .probe = rk808_regulator_probe, 615 - .remove = rk808_regulator_remove, 616 622 .driver = { 617 623 .name = "rk808-regulator", 618 624 .owner = THIS_MODULE,