From: Frans Klaver <frans.klaver@xsens.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: "Frans Klaver" <frans.klaver@xsens.com>,
"Dmitry Eremin-Solenikov" <dbaryshkov@gmail.com>,
"David Woodhouse" <dwmw2@infradead.org>,
"Grant Likely" <grant.likely@linaro.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"René Moll" <linux@r-moll.nl>,
"Guenter Roeck" <linux@roeck-us.net>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
devicetree@vger.kernel.org
Subject: [PATCH 03/13] power: reset: ltc2952: unroll gpio_desc array
Date: Wed, 22 Oct 2014 16:31:00 +0200 [thread overview]
Message-ID: <1413988270-28092-4-git-send-email-frans.klaver@xsens.com> (raw)
In-Reply-To: <1413988270-28092-1-git-send-email-frans.klaver@xsens.com>
The three gpio's used by this driver are stored in an array of pointers.
This doesn't add much besides cleanups in a loop. In fact, it makes most
of the usage sites harder to read. Unroll the loop, and live with the
fact that cleanups become slightly larger.
Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
---
drivers/power/reset/ltc2952-poweroff.c | 86 +++++++++++++++-------------------
1 file changed, 38 insertions(+), 48 deletions(-)
diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c
index 2c11316..fc583e0 100644
--- a/drivers/power/reset/ltc2952-poweroff.c
+++ b/drivers/power/reset/ltc2952-poweroff.c
@@ -72,21 +72,14 @@ struct ltc2952_poweroff_data {
struct device *dev;
- /**
- * 0: trigger
- * 1: watchdog
- * 2: kill
- */
- struct gpio_desc *gpio[3];
+ struct gpio_desc *gpio_trigger;
+ struct gpio_desc *gpio_watchdog;
+ struct gpio_desc *gpio_kill;
};
static int ltc2952_poweroff_panic;
static struct ltc2952_poweroff_data *ltc2952_data;
-#define POWERPATH_IO_TRIGGER 0
-#define POWERPATH_IO_WATCHDOG 1
-#define POWERPATH_IO_KILL 2
-
/**
* ltc2952_poweroff_timer_wde - Timer callback
* Toggles the watchdog reset signal each wde_interval
@@ -105,8 +98,8 @@ static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer)
if (ltc2952_poweroff_panic)
return HRTIMER_NORESTART;
- state = gpiod_get_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG]);
- gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], !state);
+ state = gpiod_get_value(ltc2952_data->gpio_watchdog);
+ gpiod_set_value(ltc2952_data->gpio_watchdog, !state);
now = hrtimer_cb_get_time(timer);
overruns = hrtimer_forward(timer, now, ltc2952_data->wde_interval);
@@ -120,7 +113,7 @@ static enum hrtimer_restart ltc2952_poweroff_timer_trigger(
int ret;
ret = hrtimer_start(<c2952_data->timer_wde,
- ltc2952_data->wde_interval, HRTIMER_MODE_REL);
+ ltc2952_data->wde_interval, HRTIMER_MODE_REL);
if (ret) {
dev_err(ltc2952_data->dev, "unable to start the timer\n");
@@ -180,7 +173,7 @@ irq_ok:
static void ltc2952_poweroff_kill(void)
{
- gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_KILL], 1);
+ gpiod_set_value(ltc2952_data->gpio_kill, 1);
}
static int ltc2952_poweroff_suspend(struct platform_device *pdev,
@@ -196,11 +189,6 @@ static int ltc2952_poweroff_resume(struct platform_device *pdev)
static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data)
{
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE(data->gpio); i++)
- data->gpio[i] = NULL;
-
data->wde_interval = ktime_set(0, 300L*1E6L);
data->trigger_delay = ktime_set(2, 500L*1E6L);
@@ -214,45 +202,46 @@ static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data)
static int ltc2952_poweroff_init(struct platform_device *pdev)
{
int ret, virq;
- unsigned int i;
struct ltc2952_poweroff_data *data;
- static char *name[] = {
- "trigger",
- "watchdog",
- "kill",
- NULL
- };
-
data = ltc2952_data;
ltc2952_poweroff_default(ltc2952_data);
- for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) {
- ltc2952_data->gpio[i] = gpiod_get(&pdev->dev, name[i]);
+ ltc2952_data->gpio_watchdog = gpiod_get(&pdev->dev, "watchdog");
+ if (IS_ERR(ltc2952_data->gpio_watchdog)) {
+ ret = PTR_ERR(ltc2952_data->gpio_watchdog);
+ dev_err(&pdev->dev, "unable to claim gpio \"watchdog\"\n");
+ return ret;
+ }
- if (IS_ERR(ltc2952_data->gpio[i])) {
- ret = PTR_ERR(ltc2952_data->gpio[i]);
- dev_err(&pdev->dev,
- "unable to claim the following gpio: %s\n",
- name[i]);
- goto err_io;
- }
+ ltc2952_data->gpio_kill = gpiod_get(&pdev->dev, "kill");
+ if (IS_ERR(ltc2952_data->gpio_kill)) {
+ ret = PTR_ERR(ltc2952_data->gpio_kill);
+ dev_err(&pdev->dev, "unable to claim gpio \"kill\"\n");
+ goto err_kill;
+ }
+
+ ltc2952_data->gpio_trigger = gpiod_get(&pdev->dev, "trigger");
+ if (IS_ERR(ltc2952_data->gpio_trigger)) {
+ ret = PTR_ERR(ltc2952_data->gpio_trigger);
+ dev_err(&pdev->dev, "unable to claim gpio \"trigger\"\n");
+ goto err_trigger;
}
ret = gpiod_direction_output(
- ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], 0);
+ ltc2952_data->gpio_watchdog, 0);
if (ret) {
dev_err(&pdev->dev, "unable to use watchdog-gpio as output\n");
goto err_io;
}
- ret = gpiod_direction_output(ltc2952_data->gpio[POWERPATH_IO_KILL], 0);
+ ret = gpiod_direction_output(ltc2952_data->gpio_kill, 0);
if (ret) {
dev_err(&pdev->dev, "unable to use kill-gpio as output\n");
goto err_io;
}
- virq = gpiod_to_irq(ltc2952_data->gpio[POWERPATH_IO_TRIGGER]);
+ virq = gpiod_to_irq(ltc2952_data->gpio_trigger);
if (virq < 0) {
dev_err(&pdev->dev, "cannot map GPIO as interrupt");
goto err_io;
@@ -272,9 +261,11 @@ static int ltc2952_poweroff_init(struct platform_device *pdev)
return 0;
err_io:
- for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++)
- if (ltc2952_data->gpio[i])
- gpiod_put(ltc2952_data->gpio[i]);
+ gpiod_put(ltc2952_data->gpio_trigger);
+err_trigger:
+ gpiod_put(ltc2952_data->gpio_kill);
+err_kill:
+ gpiod_put(ltc2952_data->gpio_watchdog);
return ret;
}
@@ -308,14 +299,13 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev)
static int ltc2952_poweroff_remove(struct platform_device *pdev)
{
- unsigned int i;
-
pm_power_off = NULL;
- if (ltc2952_data)
- for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++)
- gpiod_put(ltc2952_data->gpio[i]);
-
+ if (ltc2952_data) {
+ gpiod_put(ltc2952_data->gpio_trigger);
+ gpiod_put(ltc2952_data->gpio_watchdog);
+ gpiod_put(ltc2952_data->gpio_kill);
+ }
return 0;
}
--
2.1.0
next prev parent reply other threads:[~2014-10-22 14:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-22 14:30 [PATCH 00/13] ltc2952 modernization and new functionality Frans Klaver
2014-10-22 14:30 ` [PATCH 01/13] power: reset: ltc2952: prefer devm_kzalloc over kzalloc Frans Klaver
2014-10-22 14:30 ` [PATCH 02/13] power: reset: ltc2952: prefer devm_request_irq over request_irq Frans Klaver
2014-10-22 14:31 ` Frans Klaver [this message]
2014-10-22 14:31 ` [PATCH 04/13] power: reset: ltc2952: prefer devm_gpiod_get over gpiod_get Frans Klaver
2014-10-22 14:31 ` [PATCH 05/13] power: reset: ltc2952: reduce dependency on global variables Frans Klaver
2014-10-22 14:31 ` [PATCH 06/13] power: reset: ltc2952: remove global variable poweroff_panic Frans Klaver
2014-10-22 14:31 ` [PATCH 07/13] power: reset: ltc2952: drop empty suspend/resume functions Frans Klaver
2014-10-22 14:31 ` [PATCH 08/13] power: reset: ltc2952: cleanup control flow in poweroff_handler Frans Klaver
2014-10-22 14:31 ` [PATCH 09/13] power: reset: ltc2952: fix C++ style function pointers Frans Klaver
2014-10-22 14:31 ` [PATCH 10/13] power: reset: ltc2952: disable timers in _remove Frans Klaver
2014-10-22 14:31 ` [PATCH 11/13] power: reset: ltc2952: check trigger value before starting timer Frans Klaver
2014-10-22 14:31 ` [PATCH 12/13] power: reset: ltc2952: make trigger input optional Frans Klaver
2014-10-23 8:44 ` Frans Klaver
2014-10-22 14:31 ` [PATCH 13/13] power: reset: ltc2952: document optional trigger behavior Frans Klaver
2014-12-22 9:04 ` [PATCH 00/13] ltc2952 modernization and new functionality Frans Klaver
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=1413988270-28092-4-git-send-email-frans.klaver@xsens.com \
--to=frans.klaver@xsens.com \
--cc=dbaryshkov@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dwmw2@infradead.org \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@r-moll.nl \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
/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