diff options
author | Frans Klaver <frans.klaver@xsens.com> | 2015-01-14 03:15:38 -0500 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2015-01-20 07:58:28 -0500 |
commit | a5f67be5200787aacc7143144bdab7efe7cd268a (patch) | |
tree | a0bc5b0d0b6a710442fca9b10188c61f9337a404 /drivers/power | |
parent | 62113b31174a9dba99eda8a4222417dd526c7c79 (diff) |
power: reset: ltc2952: reduce dependency on global variables
Documentation/CodingStyle ch.4 mentions in a side node that global
variables should only be used if you really need them. Reduce the use of
the global instance of ltc2952_poweroff so we may eventually remove it
entirely.
While at it, rename ltc2952_poweroff_data to ltc2952_poweroff, just to
save that little bit of typing.
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.c | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/drivers/power/reset/ltc2952-poweroff.c b/drivers/power/reset/ltc2952-poweroff.c index 4caa9d285026..83042691cd79 100644 --- a/drivers/power/reset/ltc2952-poweroff.c +++ b/drivers/power/reset/ltc2952-poweroff.c | |||
@@ -63,7 +63,7 @@ | |||
63 | #include <linux/gpio/consumer.h> | 63 | #include <linux/gpio/consumer.h> |
64 | #include <linux/reboot.h> | 64 | #include <linux/reboot.h> |
65 | 65 | ||
66 | struct ltc2952_poweroff_data { | 66 | struct ltc2952_poweroff { |
67 | struct hrtimer timer_trigger; | 67 | struct hrtimer timer_trigger; |
68 | struct hrtimer timer_wde; | 68 | struct hrtimer timer_wde; |
69 | 69 | ||
@@ -77,8 +77,14 @@ struct ltc2952_poweroff_data { | |||
77 | struct gpio_desc *gpio_kill; | 77 | struct gpio_desc *gpio_kill; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | #define to_ltc2952(p, m) container_of(p, struct ltc2952_poweroff, m) | ||
81 | |||
82 | /* | ||
83 | * This global variable is only needed for pm_power_off. We should | ||
84 | * remove it entirely once we don't need the global state anymore. | ||
85 | */ | ||
86 | static struct ltc2952_poweroff *ltc2952_data; | ||
80 | static int ltc2952_poweroff_panic; | 87 | static int ltc2952_poweroff_panic; |
81 | static struct ltc2952_poweroff_data *ltc2952_data; | ||
82 | 88 | ||
83 | /** | 89 | /** |
84 | * ltc2952_poweroff_timer_wde - Timer callback | 90 | * ltc2952_poweroff_timer_wde - Timer callback |
@@ -94,29 +100,29 @@ static enum hrtimer_restart ltc2952_poweroff_timer_wde(struct hrtimer *timer) | |||
94 | ktime_t now; | 100 | ktime_t now; |
95 | int state; | 101 | int state; |
96 | unsigned long overruns; | 102 | unsigned long overruns; |
103 | struct ltc2952_poweroff *data = to_ltc2952(timer, timer_wde); | ||
97 | 104 | ||
98 | if (ltc2952_poweroff_panic) | 105 | if (ltc2952_poweroff_panic) |
99 | return HRTIMER_NORESTART; | 106 | return HRTIMER_NORESTART; |
100 | 107 | ||
101 | state = gpiod_get_value(ltc2952_data->gpio_watchdog); | 108 | state = gpiod_get_value(data->gpio_watchdog); |
102 | gpiod_set_value(ltc2952_data->gpio_watchdog, !state); | 109 | gpiod_set_value(data->gpio_watchdog, !state); |
103 | 110 | ||
104 | now = hrtimer_cb_get_time(timer); | 111 | now = hrtimer_cb_get_time(timer); |
105 | overruns = hrtimer_forward(timer, now, ltc2952_data->wde_interval); | 112 | overruns = hrtimer_forward(timer, now, data->wde_interval); |
106 | 113 | ||
107 | return HRTIMER_RESTART; | 114 | return HRTIMER_RESTART; |
108 | } | 115 | } |
109 | 116 | ||
110 | static enum hrtimer_restart ltc2952_poweroff_timer_trigger( | 117 | static enum hrtimer_restart |
111 | struct hrtimer *timer) | 118 | ltc2952_poweroff_timer_trigger(struct hrtimer *timer) |
112 | { | 119 | { |
113 | int ret; | 120 | struct ltc2952_poweroff *data = to_ltc2952(timer, timer_trigger); |
114 | 121 | int ret = hrtimer_start(&data->timer_wde, | |
115 | ret = hrtimer_start(<c2952_data->timer_wde, | 122 | data->wde_interval, HRTIMER_MODE_REL); |
116 | ltc2952_data->wde_interval, HRTIMER_MODE_REL); | ||
117 | 123 | ||
118 | if (ret) { | 124 | if (ret) { |
119 | dev_err(ltc2952_data->dev, "unable to start the timer\n"); | 125 | dev_err(data->dev, "unable to start the timer\n"); |
120 | /* | 126 | /* |
121 | * The device will not toggle the watchdog reset, | 127 | * The device will not toggle the watchdog reset, |
122 | * thus shut down is only safe if the PowerPath controller | 128 | * thus shut down is only safe if the PowerPath controller |
@@ -127,7 +133,7 @@ static enum hrtimer_restart ltc2952_poweroff_timer_trigger( | |||
127 | */ | 133 | */ |
128 | } | 134 | } |
129 | 135 | ||
130 | dev_info(ltc2952_data->dev, "executing shutdown\n"); | 136 | dev_info(data->dev, "executing shutdown\n"); |
131 | 137 | ||
132 | orderly_poweroff(true); | 138 | orderly_poweroff(true); |
133 | 139 | ||
@@ -146,7 +152,7 @@ static enum hrtimer_restart ltc2952_poweroff_timer_trigger( | |||
146 | static irqreturn_t ltc2952_poweroff_handler(int irq, void *dev_id) | 152 | static irqreturn_t ltc2952_poweroff_handler(int irq, void *dev_id) |
147 | { | 153 | { |
148 | int ret; | 154 | int ret; |
149 | struct ltc2952_poweroff_data *data = dev_id; | 155 | struct ltc2952_poweroff *data = dev_id; |
150 | 156 | ||
151 | if (ltc2952_poweroff_panic) | 157 | if (ltc2952_poweroff_panic) |
152 | goto irq_ok; | 158 | goto irq_ok; |
@@ -187,7 +193,7 @@ static int ltc2952_poweroff_resume(struct platform_device *pdev) | |||
187 | return -ENOSYS; | 193 | return -ENOSYS; |
188 | } | 194 | } |
189 | 195 | ||
190 | static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data) | 196 | static void ltc2952_poweroff_default(struct ltc2952_poweroff *data) |
191 | { | 197 | { |
192 | data->wde_interval = ktime_set(0, 300L*1E6L); | 198 | data->wde_interval = ktime_set(0, 300L*1E6L); |
193 | data->trigger_delay = ktime_set(2, 500L*1E6L); | 199 | data->trigger_delay = ktime_set(2, 500L*1E6L); |
@@ -202,36 +208,34 @@ static void ltc2952_poweroff_default(struct ltc2952_poweroff_data *data) | |||
202 | static int ltc2952_poweroff_init(struct platform_device *pdev) | 208 | static int ltc2952_poweroff_init(struct platform_device *pdev) |
203 | { | 209 | { |
204 | int ret, virq; | 210 | int ret, virq; |
205 | struct ltc2952_poweroff_data *data; | 211 | struct ltc2952_poweroff *data = platform_get_drvdata(pdev); |
206 | 212 | ||
207 | data = ltc2952_data; | 213 | ltc2952_poweroff_default(data); |
208 | ltc2952_poweroff_default(ltc2952_data); | ||
209 | 214 | ||
210 | ltc2952_data->gpio_watchdog = devm_gpiod_get(&pdev->dev, "watchdog", | 215 | data->gpio_watchdog = devm_gpiod_get(&pdev->dev, "watchdog", |
211 | GPIOD_OUT_LOW); | 216 | GPIOD_OUT_LOW); |
212 | if (IS_ERR(ltc2952_data->gpio_watchdog)) { | 217 | if (IS_ERR(data->gpio_watchdog)) { |
213 | ret = PTR_ERR(ltc2952_data->gpio_watchdog); | 218 | ret = PTR_ERR(data->gpio_watchdog); |
214 | dev_err(&pdev->dev, "unable to claim gpio \"watchdog\"\n"); | 219 | dev_err(&pdev->dev, "unable to claim gpio \"watchdog\"\n"); |
215 | return ret; | 220 | return ret; |
216 | } | 221 | } |
217 | 222 | ||
218 | ltc2952_data->gpio_kill = devm_gpiod_get(&pdev->dev, "kill", | 223 | data->gpio_kill = devm_gpiod_get(&pdev->dev, "kill", GPIOD_OUT_LOW); |
219 | GPIOD_OUT_LOW); | 224 | if (IS_ERR(data->gpio_kill)) { |
220 | if (IS_ERR(ltc2952_data->gpio_kill)) { | 225 | ret = PTR_ERR(data->gpio_kill); |
221 | ret = PTR_ERR(ltc2952_data->gpio_kill); | ||
222 | dev_err(&pdev->dev, "unable to claim gpio \"kill\"\n"); | 226 | dev_err(&pdev->dev, "unable to claim gpio \"kill\"\n"); |
223 | return ret; | 227 | return ret; |
224 | } | 228 | } |
225 | 229 | ||
226 | ltc2952_data->gpio_trigger = devm_gpiod_get(&pdev->dev, "trigger", | 230 | data->gpio_trigger = devm_gpiod_get(&pdev->dev, "trigger", |
227 | GPIOD_IN); | 231 | GPIOD_IN); |
228 | if (IS_ERR(ltc2952_data->gpio_trigger)) { | 232 | if (IS_ERR(ltc2952_data->gpio_trigger)) { |
229 | ret = PTR_ERR(ltc2952_data->gpio_trigger); | 233 | ret = PTR_ERR(ltc2952_data->gpio_trigger); |
230 | dev_err(&pdev->dev, "unable to claim gpio \"trigger\"\n"); | 234 | dev_err(&pdev->dev, "unable to claim gpio \"trigger\"\n"); |
231 | return ret; | 235 | return ret; |
232 | } | 236 | } |
233 | 237 | ||
234 | virq = gpiod_to_irq(ltc2952_data->gpio_trigger); | 238 | virq = gpiod_to_irq(data->gpio_trigger); |
235 | if (virq < 0) { | 239 | if (virq < 0) { |
236 | dev_err(&pdev->dev, "cannot map GPIO as interrupt"); | 240 | dev_err(&pdev->dev, "cannot map GPIO as interrupt"); |
237 | return ret; | 241 | return ret; |
@@ -241,7 +245,7 @@ static int ltc2952_poweroff_init(struct platform_device *pdev) | |||
241 | ltc2952_poweroff_handler, | 245 | ltc2952_poweroff_handler, |
242 | (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING), | 246 | (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING), |
243 | "ltc2952-poweroff", | 247 | "ltc2952-poweroff", |
244 | ltc2952_data); | 248 | data); |
245 | 249 | ||
246 | if (ret) { | 250 | if (ret) { |
247 | dev_err(&pdev->dev, "cannot configure an interrupt handler\n"); | 251 | dev_err(&pdev->dev, "cannot configure an interrupt handler\n"); |
@@ -254,23 +258,26 @@ static int ltc2952_poweroff_init(struct platform_device *pdev) | |||
254 | static int ltc2952_poweroff_probe(struct platform_device *pdev) | 258 | static int ltc2952_poweroff_probe(struct platform_device *pdev) |
255 | { | 259 | { |
256 | int ret; | 260 | int ret; |
261 | struct ltc2952_poweroff *data; | ||
257 | 262 | ||
258 | if (pm_power_off) { | 263 | if (pm_power_off) { |
259 | dev_err(&pdev->dev, "pm_power_off already registered"); | 264 | dev_err(&pdev->dev, "pm_power_off already registered"); |
260 | return -EBUSY; | 265 | return -EBUSY; |
261 | } | 266 | } |
262 | 267 | ||
263 | ltc2952_data = devm_kzalloc(&pdev->dev, sizeof(*ltc2952_data), | 268 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
264 | GFP_KERNEL); | 269 | if (!data) |
265 | if (!ltc2952_data) | ||
266 | return -ENOMEM; | 270 | return -ENOMEM; |
267 | 271 | ||
268 | ltc2952_data->dev = &pdev->dev; | 272 | data->dev = &pdev->dev; |
273 | platform_set_drvdata(pdev, data); | ||
269 | 274 | ||
270 | ret = ltc2952_poweroff_init(pdev); | 275 | ret = ltc2952_poweroff_init(pdev); |
271 | if (ret) | 276 | if (ret) |
272 | return ret; | 277 | return ret; |
273 | 278 | ||
279 | /* TODO: remove ltc2952_data */ | ||
280 | ltc2952_data = data; | ||
274 | pm_power_off = <c2952_poweroff_kill; | 281 | pm_power_off = <c2952_poweroff_kill; |
275 | 282 | ||
276 | dev_info(&pdev->dev, "probe successful\n"); | 283 | dev_info(&pdev->dev, "probe successful\n"); |