From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: Linus Walleij <linus.walleij@linaro.org>,
Mark Brown <broonie@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Chris Zhong" <zyw@rock-chips.com>,
linux-next@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@pengutronix.de
Subject: [PATCH v2 2/2] regulator: rk808: make better use of the gpiod API
Date: Tue, 21 Jul 2015 16:46:25 +0200 [thread overview]
Message-ID: <1437489985-1362-2-git-send-email-uwe@kleine-koenig.org> (raw)
In-Reply-To: <1437489985-1362-1-git-send-email-uwe@kleine-koenig.org>
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
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>
---
note the above mentioned gpiod change is already in next, so the driver
fails to build there.
Changes since (implicit) v1, sent with
Message-Id: 1437461993-14860-1-git-send-email-u.kleine-koenig@pengutronix.de:
- Assert that of_node_put is called in error path to not leak a reference
and drop now empty remove callback.
Thanks to Krzysztof Kozlowski for catching.
Best regards
Uwe
drivers/regulator/rk808-regulator.c | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
index ac9436d2ea8d..d86a3dcd61e2 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -95,7 +95,7 @@ static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
unsigned int val;
int ret;
- if (IS_ERR(gpio) || gpiod_get_value(gpio) == 0)
+ if (!gpio || gpiod_get_value(gpio) == 0)
return regulator_get_voltage_sel_regmap(rdev);
ret = regmap_read(rdev->regmap,
@@ -169,7 +169,7 @@ static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
unsigned old_sel;
int ret, gpio_level;
- if (IS_ERR(gpio))
+ if (!gpio)
return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel);
gpio_level = gpiod_get_value(gpio);
@@ -206,7 +206,7 @@ static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
struct gpio_desc *gpio = pdata->dvs_gpio[id];
/* if there is no dvs1/2 pin, we don't need wait extra time here. */
- if (IS_ERR(gpio))
+ if (!gpio)
return 0;
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,
goto dt_parse_end;
for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
- pdata->dvs_gpio[i] = gpiod_get_index(client_dev, "dvs", i);
+ pdata->dvs_gpio[i] =
+ devm_gpiod_get_index_optional(client_dev, "dvs", i,
+ GPIOD_OUT_LOW);
if (IS_ERR(pdata->dvs_gpio[i])) {
+ ret = PTR_ERR(pdata->dvs_gpio[i]);
+ dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret);
+ goto dt_parse_end;
+ }
+
+ if (!pdata->dvs_gpio[i]) {
dev_warn(dev, "there is no dvs%d gpio\n", i);
continue;
}
- gpiod_direction_output(pdata->dvs_gpio[i], 0);
-
tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL;
ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp,
gpiod_is_active_low(pdata->dvs_gpio[i]) ?
@@ -560,19 +566,6 @@ dt_parse_end:
return ret;
}
-static int rk808_regulator_remove(struct platform_device *pdev)
-{
- struct rk808_regulator_data *pdata = platform_get_drvdata(pdev);
- int i;
-
- for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
- if (!IS_ERR(pdata->dvs_gpio[i]))
- gpiod_put(pdata->dvs_gpio[i]);
- }
-
- return 0;
-}
-
static int rk808_regulator_probe(struct platform_device *pdev)
{
struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
@@ -619,7 +612,6 @@ static int rk808_regulator_probe(struct platform_device *pdev)
static struct platform_driver rk808_regulator_driver = {
.probe = rk808_regulator_probe,
- .remove = rk808_regulator_remove,
.driver = {
.name = "rk808-regulator",
.owner = THIS_MODULE,
--
2.1.4
next prev parent reply other threads:[~2015-07-21 14:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-21 3:29 linux-next: build failure after merge of the gpio tree Stephen Rothwell
2015-07-21 6:59 ` [PATCH] regulator: rk808: make better use of the gpiod API Uwe Kleine-König
2015-07-21 9:56 ` Linus Walleij
2015-07-21 11:04 ` Mark Brown
2015-07-21 14:21 ` Uwe Kleine-König
2015-07-21 14:46 ` [PATCH 1/2] regulator: rk808: add #include for gpiod functions Uwe Kleine-König
2015-07-21 14:46 ` Uwe Kleine-König [this message]
2015-07-22 2:21 ` [PATCH v2 2/2] regulator: rk808: make better use of the gpiod API Krzysztof Kozlowski
2015-07-21 13:09 ` [PATCH] " Krzysztof Kozlowski
2015-07-21 14:35 ` Uwe Kleine-König
2015-07-21 14:41 ` Mark Brown
2015-07-21 15:08 ` [PATCH] base/platform: assert that dev_pm_domain callbacks are called unconditionally Uwe Kleine-König
2015-08-06 0:06 ` Greg Kroah-Hartman
2015-07-22 0:13 ` [PATCH] regulator: rk808: make better use of the gpiod API Krzysztof Kozlowski
2015-07-22 7:13 ` Uwe Kleine-König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1437489985-1362-2-git-send-email-uwe@kleine-koenig.org \
--to=uwe@kleine-koenig.org \
--cc=broonie@kernel.org \
--cc=kernel@pengutronix.de \
--cc=lgirdwood@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
--cc=zyw@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).