From patchwork Thu Jun 2 13:41:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 69164 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp124805qgf; Thu, 2 Jun 2016 06:41:56 -0700 (PDT) X-Received: by 10.98.35.93 with SMTP id j90mr4834859pfj.10.1464874916208; Thu, 02 Jun 2016 06:41:56 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si620375pfa.80.2016.06.02.06.41.56 for ; Thu, 02 Jun 2016 06:41:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-leds-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-leds-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751935AbcFBNlz (ORCPT ); Thu, 2 Jun 2016 09:41:55 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:33694 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751338AbcFBNly (ORCPT ); Thu, 2 Jun 2016 09:41:54 -0400 Received: by mail-lf0-f45.google.com with SMTP id s64so34309143lfe.0 for ; Thu, 02 Jun 2016 06:41:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=eRC1APxn2hIz/L9QrdZetlM7GqR0URcKaO9A7nIrhZI=; b=K6piQGNVyqoBmnIqhyAFRZtkEJIbDp52xgGfsVBHmURFUey6Lkq3BFz+oMZ6oHalkI 77DPzV3oOK+KzCeVCKEx8F2s8047MESk1XNT0H/B2lDaZEFwUuh3ReSEBr7eyig4gi+R +dmE+0pU08K3thpY4q+H1wx/uivqz5AzWkP1s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eRC1APxn2hIz/L9QrdZetlM7GqR0URcKaO9A7nIrhZI=; b=mdVqXLC95jWTIjOTZEC4a2gxyvhKmdr2OXfhl3Pex5Ff2DiYnSWRDZkkNv/U3CdzRB wYN07AX1klC6Y/k5A2RQvdkw+n7mjPQ6FeBqJpNQqyf4bSXYkKHH3j6ePl1rR0tloxho pE0Rjkex2c1tHZL2pCwzInq3mdthO5pHfolMTSGyG7goEZRO5Ktdr0EAXm+sHPEGViwe sewRveSL7FcKIz2oiN3FyvWWi+UG+b/6ERsDzNcW4w/V7IKwHN21u1j4uL1buF/DDzBF YlbQ4fswFei8RxHG+kysqHKfMAyttLXdc496dkfBRUD5+IgReGxgN7+LTdlDaewtWOe8 4E5Q== X-Gm-Message-State: ALyK8tJPl9S0G1ljpNs9x5rSEMMhM90xeO+sY3AEr0NDdG/ehjAKA11cNFUQCPXE+c7tAa1z X-Received: by 10.25.155.202 with SMTP id d193mr4041072lfe.120.1464874912671; Thu, 02 Jun 2016 06:41:52 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k13sm60774lfb.3.2016.06.02.06.41.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Jun 2016 06:41:51 -0700 (PDT) From: Linus Walleij To: Jacek Anaszewski , Richard Purdie Cc: linux-leds@vger.kernel.org, Linus Walleij , linux-pm@vger.kernel.org, Ulf Hansson Subject: [PATCH] leds: handle suspend/resume in heartbeat trigger Date: Thu, 2 Jun 2016 15:41:46 +0200 Message-Id: <1464874906-13120-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.4.11 Sender: linux-leds-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 Cc: Ulf Hansson Signed-off-by: Linus Walleij --- drivers/leds/trigger/ledtrig-heartbeat.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.4.11 -- To unsubscribe from this list: send the line "unsubscribe linux-leds" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/leds/trigger/ledtrig-heartbeat.c b/drivers/leds/trigger/ledtrig-heartbeat.c index 410c39c62dc7..c80e91152b6b 100644 --- a/drivers/leds/trigger/ledtrig-heartbeat.c +++ b/drivers/leds/trigger/ledtrig-heartbeat.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "../leds.h" static int panic_heartbeats; @@ -154,6 +155,26 @@ static struct led_trigger heartbeat_led_trigger = { .deactivate = heartbeat_trig_deactivate, }; +static int heartbeat_pm_notifier(struct notifier_block *nb, + unsigned long pm_event, void *unused) +{ + int rc; + + switch (pm_event) { + case PM_SUSPEND_PREPARE: + led_trigger_unregister(&heartbeat_led_trigger); + break; + case PM_POST_SUSPEND: + rc = led_trigger_register(&heartbeat_led_trigger); + if (rc) + pr_err("could not re-register heartbeat trigger\n"); + break; + default: + break; + } + return NOTIFY_DONE; +} + static int heartbeat_reboot_notifier(struct notifier_block *nb, unsigned long code, void *unused) { @@ -168,6 +189,10 @@ static int heartbeat_panic_notifier(struct notifier_block *nb, return NOTIFY_DONE; } +static struct notifier_block heartbeat_pm_nb = { + .notifier_call = heartbeat_pm_notifier, +}; + static struct notifier_block heartbeat_reboot_nb = { .notifier_call = heartbeat_reboot_notifier, }; @@ -184,12 +209,14 @@ static int __init heartbeat_trig_init(void) atomic_notifier_chain_register(&panic_notifier_list, &heartbeat_panic_nb); register_reboot_notifier(&heartbeat_reboot_nb); + register_pm_notifier(&heartbeat_pm_nb); } return rc; } static void __exit heartbeat_trig_exit(void) { + unregister_pm_notifier(&heartbeat_pm_nb); unregister_reboot_notifier(&heartbeat_reboot_nb); atomic_notifier_chain_unregister(&panic_notifier_list, &heartbeat_panic_nb);