aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-06-08 04:29:48 -0400
committerJacek Anaszewski <j.anaszewski@samsung.com>2016-06-08 05:47:06 -0400
commit5ab92a7cb82c66bf30685583a38a18538e3807db (patch)
treee4e31ecd7cce17d9716202acdb1da4b3c12b907e
parent7cfe749fad5158247282f2fee30773fd454029ab (diff)
leds: handle suspend/resume in heartbeat trigger
The following phenomena was observed: when suspending the system, sometimes the heartbeat LED was left on, glowing and wasting power while the rest of the system is asleep, also disturbing power dissapation measures on the odd suspend cycle when it's left on. Clearly this is not how we want the heartbeat trigger to work: it should turn off and leave the LED off during system suspend. This removes the heartbeat trigger when preparing suspend and restores it during resume. The trigger code will make sure all LEDs are left in OFF state after removing the trigger, and will re-enable the trigger on all LEDs after resuming. Cc: linux-pm@vger.kernel.org Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
-rw-r--r--drivers/leds/trigger/ledtrig-heartbeat.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c
index 410c39c62dc7..c9f386213e9e 100644
--- a/drivers/leds/trigger/ledtrig-heartbeat.c
+++ b/drivers/leds/trigger/ledtrig-heartbeat.c
@@ -19,6 +19,7 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/leds.h> 20#include <linux/leds.h>
21#include <linux/reboot.h> 21#include <linux/reboot.h>
22#include <linux/suspend.h>
22#include "../leds.h" 23#include "../leds.h"
23 24
24static int panic_heartbeats; 25static int panic_heartbeats;
@@ -154,6 +155,30 @@ static struct led_trigger heartbeat_led_trigger = {
154 .deactivate = heartbeat_trig_deactivate, 155 .deactivate = heartbeat_trig_deactivate,
155}; 156};
156 157
158static int heartbeat_pm_notifier(struct notifier_block *nb,
159 unsigned long pm_event, void *unused)
160{
161 int rc;
162
163 switch (pm_event) {
164 case PM_SUSPEND_PREPARE:
165 case PM_HIBERNATION_PREPARE:
166 case PM_RESTORE_PREPARE:
167 led_trigger_unregister(&heartbeat_led_trigger);
168 break;
169 case PM_POST_SUSPEND:
170 case PM_POST_HIBERNATION:
171 case PM_POST_RESTORE:
172 rc = led_trigger_register(&heartbeat_led_trigger);
173 if (rc)
174 pr_err("could not re-register heartbeat trigger\n");
175 break;
176 default:
177 break;
178 }
179 return NOTIFY_DONE;
180}
181
157static int heartbeat_reboot_notifier(struct notifier_block *nb, 182static int heartbeat_reboot_notifier(struct notifier_block *nb,
158 unsigned long code, void *unused) 183 unsigned long code, void *unused)
159{ 184{
@@ -168,6 +193,10 @@ static int heartbeat_panic_notifier(struct notifier_block *nb,
168 return NOTIFY_DONE; 193 return NOTIFY_DONE;
169} 194}
170 195
196static struct notifier_block heartbeat_pm_nb = {
197 .notifier_call = heartbeat_pm_notifier,
198};
199
171static struct notifier_block heartbeat_reboot_nb = { 200static struct notifier_block heartbeat_reboot_nb = {
172 .notifier_call = heartbeat_reboot_notifier, 201 .notifier_call = heartbeat_reboot_notifier,
173}; 202};
@@ -184,12 +213,14 @@ static int __init heartbeat_trig_init(void)
184 atomic_notifier_chain_register(&panic_notifier_list, 213 atomic_notifier_chain_register(&panic_notifier_list,
185 &heartbeat_panic_nb); 214 &heartbeat_panic_nb);
186 register_reboot_notifier(&heartbeat_reboot_nb); 215 register_reboot_notifier(&heartbeat_reboot_nb);
216 register_pm_notifier(&heartbeat_pm_nb);
187 } 217 }
188 return rc; 218 return rc;
189} 219}
190 220
191static void __exit heartbeat_trig_exit(void) 221static void __exit heartbeat_trig_exit(void)
192{ 222{
223 unregister_pm_notifier(&heartbeat_pm_nb);
193 unregister_reboot_notifier(&heartbeat_reboot_nb); 224 unregister_reboot_notifier(&heartbeat_reboot_nb);
194 atomic_notifier_chain_unregister(&panic_notifier_list, 225 atomic_notifier_chain_unregister(&panic_notifier_list,
195 &heartbeat_panic_nb); 226 &heartbeat_panic_nb);