From patchwork Wed Jun 8 08:29:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 69588 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2371408qgf; Wed, 8 Jun 2016 01:30:06 -0700 (PDT) X-Received: by 10.107.181.75 with SMTP id e72mr6587214iof.88.1465374605835; Wed, 08 Jun 2016 01:30:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2si131383pfi.223.2016.06.08.01.30.05 for ; Wed, 08 Jun 2016 01:30:05 -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 S1161776AbcFHIaC (ORCPT ); Wed, 8 Jun 2016 04:30:02 -0400 Received: from mail-lf0-f41.google.com ([209.85.215.41]:34491 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161337AbcFHI37 (ORCPT ); Wed, 8 Jun 2016 04:29:59 -0400 Received: by mail-lf0-f41.google.com with SMTP id s186so801134lfs.1 for ; Wed, 08 Jun 2016 01:29:58 -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=fFfHenHm6LgEI6GzO1rrZbj7ju1iDTZdwvkJqkhg2Ko=; b=VNZYfQOAh/7Le8qqtsZXBB+Apl37ebC3nZ2EcZ1R+Ah3vDZqdj5Y8aaI/tbE2Hqq8c uyjU3K49KTpt723wcXviX3Ve5MAt4Bjcvi/0ra/TF66ZEols1kWeGpwiAHzBpZH7pQ3e 5l6xAt2w4DHs76refE98SRmIKCnZmrU0eseyA= 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=fFfHenHm6LgEI6GzO1rrZbj7ju1iDTZdwvkJqkhg2Ko=; b=f27GtmpdsMAX1VBKzTKQosGVAOLHQZyQRi5Merzsya3cx1QmeL6NY5SANVQt7QIf9h HPDCMHfv/DeqW2SsgtmuTvoMYOAhO4gaSKjcPinDGsPc9lfJtsxxfqoPjLHkuwQJDC6W MnnHo3/hNg5ELBU5tNKS/UhbSK00dx/wm/GXMSw7s7GFPoU3CHPZid+FUFVNechD+mxE rprGebEwA2nQFbZ0S040XtzN7nqlry2Db+a/RBmAOAOhC3ROW+K8CGExIYeuFtA8gHLJ vKvAbzJXRg4M67d5FvqyMoynXu5fPP+jZaredV27+zy5/i/fxNSD6WutvMdjXIICOtNp R46w== X-Gm-Message-State: ALyK8tIPlL2S6ndoRJv8ez5nCMIgxM5SJUsEMBuJ+jmnZC8EmnVD7WAiKjSzdNwkSAiuUDc3 X-Received: by 10.25.76.5 with SMTP id z5mr3387247lfa.155.1465374597391; Wed, 08 Jun 2016 01:29:57 -0700 (PDT) Received: from localhost.localdomain ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id g101sm12806lji.26.2016.06.08.01.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Jun 2016 01:29:56 -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 v2] leds: handle suspend/resume in heartbeat trigger Date: Wed, 8 Jun 2016 10:29:48 +0200 Message-Id: <1465374588-8453-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 --- ChangeLog v1->v2: - Also register/unregister the trigger on PM_RESTORE and PM_HIBERNATION notifications. - Jacek if you already applied v1 please apply this instead, or tell me and I can make an incremental patch. --- drivers/leds/trigger/ledtrig-heartbeat.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 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 Reviewed-by: Ulf Hansson 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 @@ #include #include #include +#include #include "../leds.h" static int panic_heartbeats; @@ -154,6 +155,30 @@ 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: + case PM_HIBERNATION_PREPARE: + case PM_RESTORE_PREPARE: + led_trigger_unregister(&heartbeat_led_trigger); + break; + case PM_POST_SUSPEND: + case PM_POST_HIBERNATION: + case PM_POST_RESTORE: + 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 +193,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 +213,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);