From patchwork Mon Apr 4 20:22:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 8743931 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C50CDC0553 for ; Mon, 4 Apr 2016 20:24:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD3BD201EF for ; Mon, 4 Apr 2016 20:24:51 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 75FE92025A for ; Mon, 4 Apr 2016 20:24:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1anB1R-0006rX-15; Mon, 04 Apr 2016 20:22:53 +0000 Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1anB1H-0006mE-Mc for linux-arm-kernel@lists.infradead.org; Mon, 04 Apr 2016 20:22:45 +0000 Received: by mail-qk0-x235.google.com with SMTP id s5so67371397qkd.0 for ; Mon, 04 Apr 2016 13:22:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EF1K8YCQYHwaTPXv42uZXAbnj+6F0Tt1H9Pbw+CciOw=; b=tP+C7b+FdFyiVrxabZZ7ptCl3hY5nl0cWyFJ/4kibsAYKIYc9BIWgz4RAiZUlsSoOk aoP9DCu87Doaw2qn4j1BJEJEeJnEJQWtGQH1DwWSdb4/tLpqO1FNplSEZhGbIgFHumsm pGwEzKhRURE/WYnKGQfsttVtil+VvVe99YyADdcP5LikyzSQoC5m1dGWuk4ZWkPl4NeT dyP7Fgxap84BnHAERA5+dmdeDeASm3XhPco+M9kZwJArUrGt5/df+Q2EFGXKxTrNkKJb y4poLAbqQQiPAM2GgB2DxyxYwIwV6lodYD7kFm64l1KOPZ997qjRJAUwHM5ijfCjqj79 Nuag== 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:in-reply-to :references; bh=EF1K8YCQYHwaTPXv42uZXAbnj+6F0Tt1H9Pbw+CciOw=; b=XPYyLtZTWI6wPGix96MJX6IzPuq9cT7EyQspjCsmSSTyrfou0pmEv+ZKUepwYS4C93 VDRW216bgIRhsv/N4Zh3Eq8chdIM6vR9bII6KWiZ5+YFf7U7NDDXk8tJ4QipXksK0X6U vn93DTaWreU/Z/4imKWddLPeSjPSISd60WtjBP6l6OxeDsvQqJGLJb9KWkjToRxYDE6R HQHHUf931Kvy+go+7GSbmeFnQ0/ILoxfpMQpOCuOvzO045IWzLEGZSryUwXhfsudQSzp 7lpXZOKgDwELI5eh9P7XhBam85Tmu85wDaMGR2GxaJ8O9jwjyllrNsV/Hn1P/5cFy4N1 u4hw== X-Gm-Message-State: AD7BkJI9OMrx6HxtKyDHdVPTShiyW/AVERczRkA4kawDFJwNzsK6bT4I5tWiKi3FVxHuMA== X-Received: by 10.55.77.202 with SMTP id a193mr36067912qkb.48.1459801342619; Mon, 04 Apr 2016 13:22:22 -0700 (PDT) Received: from localhost.localdomain ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id w75sm13065124qka.49.2016.04.04.13.22.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Apr 2016 13:22:21 -0700 (PDT) From: Ezequiel Garcia To: , , Subject: [PATCH 1/5] leds: triggers: Allow to switch the trigger to "panic" on a kernel panic Date: Mon, 4 Apr 2016 17:22:02 -0300 Message-Id: <1459801326-5541-2-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1459801326-5541-1-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1459801326-5541-1-git-send-email-ezequiel@vanguardiasur.com.ar> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160404_132243_925393_3FCA8987 X-CRM114-Status: GOOD ( 14.98 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Purdie , Jacek Anaszewski , Ezequiel Garcia MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit adds a new led_cdev flag LED_BLINK_AT_PANIC, which allows to mark a specific LED to be switched to the "panic" trigger, on a kernel panic. This is useful to allow the user to assign a regular trigger to a given LED, and still blink that LED on a kernel panic. Signed-off-by: Ezequiel Garcia --- drivers/leds/led-triggers.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/leds.h | 1 + 2 files changed, 53 insertions(+) diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 2181581795d3..f5c9d7c4d181 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -148,6 +148,43 @@ void led_trigger_remove(struct led_classdev *led_cdev) } EXPORT_SYMBOL_GPL(led_trigger_remove); +/* + * This is a called in a special context by the atomic panic + * notifier. This means the trigger can be changed without + * worrying about locking. + */ +static void led_trigger_set_panic(struct led_classdev *led_cdev) +{ + struct led_trigger *trig; + + list_for_each_entry(trig, &trigger_list, next_trig) { + if (strcmp("panic", trig->name)) + continue; + if (led_cdev->trigger) + list_del(&led_cdev->trig_list); + list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); + led_cdev->trigger = trig; + if (trig->activate) + trig->activate(led_cdev); + break; + } +} + +static int led_trigger_panic_notifier(struct notifier_block *nb, + unsigned long code, void *unused) +{ + struct led_classdev *led_cdev; + + list_for_each_entry(led_cdev, &leds_list, node) + if (led_cdev->flags & LED_BLINK_AT_PANIC) + led_trigger_set_panic(led_cdev); + return NOTIFY_DONE; +} + +static struct notifier_block led_trigger_panic_nb = { + .notifier_call = led_trigger_panic_notifier, +}; + void led_trigger_set_default(struct led_classdev *led_cdev) { struct led_trigger *trig; @@ -356,6 +393,21 @@ void led_trigger_unregister_simple(struct led_trigger *trig) } EXPORT_SYMBOL_GPL(led_trigger_unregister_simple); +static int __init leds_trigger_init(void) +{ + atomic_notifier_chain_register(&panic_notifier_list, + &led_trigger_panic_nb); + return 0; +} + +static void __exit leds_trigger_exit(void) +{ + atomic_notifier_chain_unregister(&panic_notifier_list, + &led_trigger_panic_nb); +} +module_init(leds_trigger_init); +module_exit(leds_trigger_exit); + MODULE_AUTHOR("Richard Purdie"); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("LED Triggers Core"); diff --git a/include/linux/leds.h b/include/linux/leds.h index f203a8f89d30..7f1428bb1e69 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -50,6 +50,7 @@ struct led_classdev { #define LED_SYSFS_DISABLE (1 << 22) #define LED_DEV_CAP_FLASH (1 << 23) #define LED_HW_PLUGGABLE (1 << 24) +#define LED_BLINK_AT_PANIC (1 << 25) /* Set LED brightness level * Must not sleep. Use brightness_set_blocking for drivers