From patchwork Wed Apr 13 18:08:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 8824741 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 17C09C0553 for ; Wed, 13 Apr 2016 18:10:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C58220357 for ; Wed, 13 Apr 2016 18:10:57 +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 4C79F2014A for ; Wed, 13 Apr 2016 18:10:56 +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 1aqPDz-0006Mn-St; Wed, 13 Apr 2016 18:09:11 +0000 Received: from mail-qg0-x22e.google.com ([2607:f8b0:400d:c04::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aqPDs-0006Jp-Nl for linux-arm-kernel@lists.infradead.org; Wed, 13 Apr 2016 18:09:06 +0000 Received: by mail-qg0-x22e.google.com with SMTP id j35so49430769qge.0 for ; Wed, 13 Apr 2016 11:08:42 -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=xEPgIAkKRKEJ+8RtkKsIBn84xxbAWSV7Y9DZBsZpknY=; b=jXS5BaY5Xdwjnpw5CAzDeeN8wlKMYlfU9lMOHhMf7R+JoEwb2BdpL90grZqUAFc3RN +scdRR/1klQVfISZLAXjTCl+GR+6hlBKD735Unf5pbWPCy9OMAPreVHR/g81Tg4FX1xn /gs3wvzE4xCDWgTXPoHwAH7cw/VlWhKFHjNypejlXuOOmmPCurX2NgD2cRyZdJ4RrBx2 bH0UoFm9p58tt1ULaWu7eINkbNPsSTZsv3iPkj3XKdycuaCBbn/PK2U/LduwluseRI0y 8nD9/CkCJcomn5U6GWjIxTTFiEMjZqqu1kfWJiGJaP2O0zoBu1fUTucVhKNAJ8WP5F5b QDUg== 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=xEPgIAkKRKEJ+8RtkKsIBn84xxbAWSV7Y9DZBsZpknY=; b=Hs/2U0fuBsmTIJmaA37MQ1rpsSZGnqYhv38WQBLULZZk+81jFzdakYT/B3JC/vhTKu IwLKgj9KMHefOyj0ZxplbBs5x+wKtk20cszVOPH28tfrzfUQrnaa6WzRXg6/9qw1AzaN AiyOnxOhhcYp0paY9t5smLQhS9d7WHA19c/YPflzkljABGeHMKn8U7JRTTDG3qWnHzIx htB6lXeBUhGd7imdj+JDuBTYZcOJU+IqzhbiR7RsfFPvrt66+wKzUZ7DI4/7nZLyKEZK PvXWKTIilN+Qkql692yYk0egVEc8awDFKBDNO0zGeeEHpgD1+xjG/OzGIbDGjWMaB2f2 5bAw== X-Gm-Message-State: AOPr4FV8Ovo9lN8y/imnNQlUQxVDBcyEL2QPLCdvXELGuoVgjWt+HL71VRvHmTbcAGA2Rw== X-Received: by 10.140.228.68 with SMTP id y65mr6843238qhb.47.1460570921932; Wed, 13 Apr 2016 11:08:41 -0700 (PDT) Received: from localhost.localdomain ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id x189sm16248410qhb.43.2016.04.13.11.08.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 11:08:41 -0700 (PDT) From: Ezequiel Garcia To: , , , Subject: [PATCH v2 1/3] leds: triggers: Allow to switch the trigger to "panic" on a kernel panic Date: Wed, 13 Apr 2016 15:08:17 -0300 Message-Id: <1460570899-24642-2-git-send-email-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1460570899-24642-1-git-send-email-ezequiel@vanguardiasur.com.ar> References: <1460570899-24642-1-git-send-email-ezequiel@vanguardiasur.com.ar> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160413_110905_105063_62DAE670 X-CRM114-Status: GOOD ( 15.88 ) 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: Mark Rutland , Pawel Moll , Ian Campbell , Rob Herring , Richard Purdie , Ezequiel Garcia , Kumar Gala , Jacek Anaszewski 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_PANIC_INDICATOR, 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/leds.h | 1 + 2 files changed, 58 insertions(+) diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 2181581795d3..d27020daf711 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -148,6 +148,48 @@ 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); + + /* Avoid the delayed blink path */ + led_cdev->blink_delay_on = 0; + led_cdev->blink_delay_off = 0; + + 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_PANIC_INDICATOR) + 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 +398,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..49adf9c6e326 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_PANIC_INDICATOR (1 << 25) /* Set LED brightness level * Must not sleep. Use brightness_set_blocking for drivers