aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorFrans Klaver <frans.klaver@xsens.com>2015-01-14 03:15:36 -0500
committerSebastian Reichel <sre@kernel.org>2015-01-20 07:58:28 -0500
commitf66472df697ed6341e2317d5c825f2d6916ae47f (patch)
tree7f275f583a2fde9ddfef359b91b16271f2d2fda4 /drivers/power
parent07d08237d3ff08c6a53c6e8496bd255176e1d68f (diff)
power: reset: ltc2952: unroll gpio_desc array
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> Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/reset/ltc2952-poweroff.c86
1 files changed, 38 insertions, 48 deletions
diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c
index 0b0792a9ad56..accadfc01270 100644
--- a/drivers/power/reset/ltc2952-poweroff.c
+++ b/drivers/power/reset/ltc2952-poweroff.c
@@ -72,21 +72,14 @@ struct ltc2952_poweroff_data {
72 72
73 struct device *dev; 73 struct device *dev;
74 74
75 /** 75 struct gpio_desc *gpio_trigger;
76 * 0: trigger 76 struct gpio_desc *gpio_watchdog;
77 * 1: watchdog 77 struct gpio_desc *gpio_kill;
78 * 2: kill
79 */
80 struct gpio_desc *gpio[3];
81}; 78};
82 79
83static int ltc2952_poweroff_panic; 80static int ltc2952_poweroff_panic;
84static struct ltc2952_poweroff_data *ltc2952_data; 81static struct ltc2952_poweroff_data *ltc2952_data;
85 82
86#define POWERPATH_IO_TRIGGER 0
87#define POWERPATH_IO_WATCHDOG 1
88#define POWERPATH_IO_KILL 2
89
90/** 83/**
91 * ltc2952_poweroff_timer_wde - Timer callback 84 * ltc2952_poweroff_timer_wde - Timer callback
92 * Toggles the watchdog reset signal each wde_interval 85 * Toggles the watchdog reset signal each wde_interval
@@ -105,8 +98,8 @@ static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer)
105 if (ltc2952_poweroff_panic) 98 if (ltc2952_poweroff_panic)
106 return HRTIMER_NORESTART; 99 return HRTIMER_NORESTART;
107 100
108 state = gpiod_get_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG]); 101 state = gpiod_get_value(ltc2952_data->gpio_watchdog);
109 gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], !state); 102 gpiod_set_value(ltc2952_data->gpio_watchdog, !state);
110 103
111 now = hrtimer_cb_get_time(timer); 104 now = hrtimer_cb_get_time(timer);
112 overruns = hrtimer_forward(timer, now, ltc2952_data->wde_interval); 105 overruns = hrtimer_forward(timer, now, ltc2952_data->wde_interval);
@@ -120,7 +113,7 @@ static enum hrtimer_restart ltc2952_poweroff_timer_trigger(
120 int ret; 113 int ret;
121 114
122 ret = hrtimer_start(&ltc2952_data->timer_wde, 115 ret = hrtimer_start(&ltc2952_data->timer_wde,
123 ltc2952_data->wde_interval, HRTIMER_MODE_REL); 116 ltc2952_data->wde_interval, HRTIMER_MODE_REL);
124 117
125 if (ret) { 118 if (ret) {
126 dev_err(ltc2952_data->dev, "unable to start the timer\n"); 119 dev_err(ltc2952_data->dev, "unable to start the timer\n");
@@ -180,7 +173,7 @@ irq_ok:
180 173
181static void ltc2952_poweroff_kill(void) 174static void ltc2952_poweroff_kill(void)
182{ 175{
183 gpiod_set_value(ltc2952_data->gpio[POWERPATH_IO_KILL], 1); 176 gpiod_set_value(ltc2952_data->gpio_kill, 1);
184} 177}
185 178
186static int ltc2952_poweroff_suspend(struct platform_device *pdev, 179static int ltc2952_poweroff_suspend(struct platform_device *pdev,
@@ -196,11 +189,6 @@ static int ltc2952_poweroff_resume(struct platform_device *pdev)
196 189
197static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data) 190static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data)
198{ 191{
199 unsigned int i;
200
201 for (i = 0; i < ARRAY_SIZE(data->gpio); i++)
202 data->gpio[i] = NULL;
203
204 data->wde_interval = ktime_set(0, 300L*1E6L); 192 data->wde_interval = ktime_set(0, 300L*1E6L);
205 data->trigger_delay = ktime_set(2, 500L*1E6L); 193 data->trigger_delay = ktime_set(2, 500L*1E6L);
206 194
@@ -214,45 +202,46 @@ static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data)
214static int ltc2952_poweroff_init(struct platform_device *pdev) 202static int ltc2952_poweroff_init(struct platform_device *pdev)
215{ 203{
216 int ret, virq; 204 int ret, virq;
217 unsigned int i;
218 struct ltc2952_poweroff_data *data; 205 struct ltc2952_poweroff_data *data;
219 206
220 static char *name[] = {
221 "trigger",
222 "watchdog",
223 "kill",
224 NULL
225 };
226
227 data = ltc2952_data; 207 data = ltc2952_data;
228 ltc2952_poweroff_default(ltc2952_data); 208 ltc2952_poweroff_default(ltc2952_data);
229 209
230 for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) { 210 ltc2952_data->gpio_watchdog = gpiod_get(&pdev->dev, "watchdog");
231 ltc2952_data->gpio[i] = gpiod_get(&pdev->dev, name[i]); 211 if (IS_ERR(ltc2952_data->gpio_watchdog)) {
212 ret = PTR_ERR(ltc2952_data->gpio_watchdog);
213 dev_err(&pdev->dev, "unable to claim gpio \"watchdog\"\n");
214 return ret;
215 }
232 216
233 if (IS_ERR(ltc2952_data->gpio[i])) { 217 ltc2952_data->gpio_kill = gpiod_get(&pdev->dev, "kill");
234 ret = PTR_ERR(ltc2952_data->gpio[i]); 218 if (IS_ERR(ltc2952_data->gpio_kill)) {
235 dev_err(&pdev->dev, 219 ret = PTR_ERR(ltc2952_data->gpio_kill);
236 "unable to claim the following gpio: %s\n", 220 dev_err(&pdev->dev, "unable to claim gpio \"kill\"\n");
237 name[i]); 221 goto err_kill;
238 goto err_io; 222 }
239 } 223
224 ltc2952_data->gpio_trigger = gpiod_get(&pdev->dev, "trigger");
225 if (IS_ERR(ltc2952_data->gpio_trigger)) {
226 ret = PTR_ERR(ltc2952_data->gpio_trigger);
227 dev_err(&pdev->dev, "unable to claim gpio \"trigger\"\n");
228 goto err_trigger;
240 } 229 }
241 230
242 ret = gpiod_direction_output( 231 ret = gpiod_direction_output(
243 ltc2952_data->gpio[POWERPATH_IO_WATCHDOG], 0); 232 ltc2952_data->gpio_watchdog, 0);
244 if (ret) { 233 if (ret) {
245 dev_err(&pdev->dev, "unable to use watchdog-gpio as output\n"); 234 dev_err(&pdev->dev, "unable to use watchdog-gpio as output\n");
246 goto err_io; 235 goto err_io;
247 } 236 }
248 237
249 ret = gpiod_direction_output(ltc2952_data->gpio[POWERPATH_IO_KILL], 0); 238 ret = gpiod_direction_output(ltc2952_data->gpio_kill, 0);
250 if (ret) { 239 if (ret) {
251 dev_err(&pdev->dev, "unable to use kill-gpio as output\n"); 240 dev_err(&pdev->dev, "unable to use kill-gpio as output\n");
252 goto err_io; 241 goto err_io;
253 } 242 }
254 243
255 virq = gpiod_to_irq(ltc2952_data->gpio[POWERPATH_IO_TRIGGER]); 244 virq = gpiod_to_irq(ltc2952_data->gpio_trigger);
256 if (virq < 0) { 245 if (virq < 0) {
257 dev_err(&pdev->dev, "cannot map GPIO as interrupt"); 246 dev_err(&pdev->dev, "cannot map GPIO as interrupt");
258 goto err_io; 247 goto err_io;
@@ -272,9 +261,11 @@ static int ltc2952_poweroff_init(struct platform_device *pdev)
272 return 0; 261 return 0;
273 262
274err_io: 263err_io:
275 for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) 264 gpiod_put(ltc2952_data->gpio_trigger);
276 if (ltc2952_data->gpio[i]) 265err_trigger:
277 gpiod_put(ltc2952_data->gpio[i]); 266 gpiod_put(ltc2952_data->gpio_kill);
267err_kill:
268 gpiod_put(ltc2952_data->gpio_watchdog);
278 269
279 return ret; 270 return ret;
280} 271}
@@ -308,14 +299,13 @@ static int ltc2952_poweroff_probe(struct platform_device *pdev)
308 299
309static int ltc2952_poweroff_remove(struct platform_device *pdev) 300static int ltc2952_poweroff_remove(struct platform_device *pdev)
310{ 301{
311 unsigned int i;
312
313 pm_power_off = NULL; 302 pm_power_off = NULL;
314 303
315 if (ltc2952_data) 304 if (ltc2952_data) {
316 for (i = 0; i < ARRAY_SIZE(ltc2952_data->gpio); i++) 305 gpiod_put(ltc2952_data->gpio_trigger);
317 gpiod_put(ltc2952_data->gpio[i]); 306 gpiod_put(ltc2952_data->gpio_watchdog);
318 307 gpiod_put(ltc2952_data->gpio_kill);
308 }
319 return 0; 309 return 0;
320} 310}
321 311