Skip to content

Commit a13eaf0

Browse files
Uwe Kleine-Königbroonie
authored andcommitted
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 <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 604d499 commit a13eaf0

1 file changed

Lines changed: 12 additions & 20 deletions

File tree

drivers/regulator/rk808-regulator.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
9595
unsigned int val;
9696
int ret;
9797

98-
if (IS_ERR(gpio) || gpiod_get_value(gpio) == 0)
98+
if (!gpio || gpiod_get_value(gpio) == 0)
9999
return regulator_get_voltage_sel_regmap(rdev);
100100

101101
ret = regmap_read(rdev->regmap,
@@ -169,7 +169,7 @@ static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
169169
unsigned old_sel;
170170
int ret, gpio_level;
171171

172-
if (IS_ERR(gpio))
172+
if (!gpio)
173173
return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel);
174174

175175
gpio_level = gpiod_get_value(gpio);
@@ -206,7 +206,7 @@ static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
206206
struct gpio_desc *gpio = pdata->dvs_gpio[id];
207207

208208
/* if there is no dvs1/2 pin, we don't need wait extra time here. */
209-
if (IS_ERR(gpio))
209+
if (!gpio)
210210
return 0;
211211

212212
return regulator_set_voltage_time_sel(rdev, old_selector, new_selector);
@@ -541,14 +541,20 @@ static int rk808_regulator_dt_parse_pdata(struct device *dev,
541541
goto dt_parse_end;
542542

543543
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);
545547
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]) {
546554
dev_warn(dev, "there is no dvs%d gpio\n", i);
547555
continue;
548556
}
549557

550-
gpiod_direction_output(pdata->dvs_gpio[i], 0);
551-
552558
tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL;
553559
ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp,
554560
gpiod_is_active_low(pdata->dvs_gpio[i]) ?
@@ -560,19 +566,6 @@ static int rk808_regulator_dt_parse_pdata(struct device *dev,
560566
return ret;
561567
}
562568

563-
static int rk808_regulator_remove(struct platform_device *pdev)
564-
{
565-
struct rk808_regulator_data *pdata = platform_get_drvdata(pdev);
566-
int i;
567-
568-
for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
569-
if (!IS_ERR(pdata->dvs_gpio[i]))
570-
gpiod_put(pdata->dvs_gpio[i]);
571-
}
572-
573-
return 0;
574-
}
575-
576569
static int rk808_regulator_probe(struct platform_device *pdev)
577570
{
578571
struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -619,7 +612,6 @@ static int rk808_regulator_probe(struct platform_device *pdev)
619612

620613
static struct platform_driver rk808_regulator_driver = {
621614
.probe = rk808_regulator_probe,
622-
.remove = rk808_regulator_remove,
623615
.driver = {
624616
.name = "rk808-regulator",
625617
.owner = THIS_MODULE,

0 commit comments

Comments
 (0)