From patchwork Mon Feb 22 16:36:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= X-Patchwork-Id: 8379931 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A915C9F2F0 for ; Mon, 22 Feb 2016 16:40:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B82CF204EB for ; Mon, 22 Feb 2016 16:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8F972051A for ; Mon, 22 Feb 2016 16:40:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754263AbcBVQkf (ORCPT ); Mon, 22 Feb 2016 11:40:35 -0500 Received: from mail-qk0-f174.google.com ([209.85.220.174]:34005 "EHLO mail-qk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752741AbcBVQhF (ORCPT ); Mon, 22 Feb 2016 11:37:05 -0500 Received: by mail-qk0-f174.google.com with SMTP id x1so57654179qkc.1; Mon, 22 Feb 2016 08:37:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=n+nMccdyvrR2F4jwbLYOcclpxXbnWFwmERoWWxzGs8E=; b=K60a1DvgbPHiZGUiiSFCCsZBr8rXyD8+qBAo8ReLF01iinga2e6zXFEWC+JEdD+gVM VwUk0NLgyfOAtmsQW15+sA6ejhdzMTqMmqeKdxKunJYtjCebJ/QXUQL/s4mx1UnpB03w yVMPTWb/05HSiKd0uz31FwZNVowby5vU9wAW6NWl2OHwP5Y2BmVYS4mTrlTDjLGzMYHZ A5oQOKhUq9i9+/vIL4lpz/tkV4Fc4dLAwQ7iHe2ta04Tf1mZ+AiSRRIxRUQZnNB5lswP hXfbrsB68LTk3pD0ObKzJ5TNCm31pW1O/vezQRvz/a7jfWHuElMa6RlhyYsRC+D9JVX1 6n4Q== 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:mime-version:content-type:content-transfer-encoding; bh=n+nMccdyvrR2F4jwbLYOcclpxXbnWFwmERoWWxzGs8E=; b=lP+yaMzfLfVTj8qiOk0k2PFX4Zs6Xo8+cVYp1pGOFEYSIEOWytautKW0Z/0PSdUoS+ blGfEJcyqwLoKTRwvYjaj0f1pQqk0We8uJBp41+bBmtnQ3enHLW+JAbJNQmaQ2+8M5Un kTbmLzPXsu7XRr5sQU/ebpGp8lmZeChGsLhA27my3ARIhtK0RVxX4d3umlCDkDX96HqP HwPIGoOR34XXjQ9rCPtMYfmeExnrOnrFzrqXLG0LjAVEQ+i5QbPjhqHD4qb8sr/1KM9m P14m8ODVmwDblI90B2aFCt64kcg750KCtre3MBgcbVoG3Rw3h7dWt0KNz+yZwXfKn1o/ WCjg== X-Gm-Message-State: AG10YOQ1Q4BJ4BkfxYMuMY9tmLCU38EtF2VM4Pm+pP5RYhdkSuIIyQInLRQplHhK1i0xJQ== X-Received: by 10.55.76.213 with SMTP id z204mr35082845qka.58.1456159024079; Mon, 22 Feb 2016 08:37:04 -0800 (PST) Received: from kiddo.endlessm-sf.com (c-98-239-150-235.hsd1.wv.comcast.net. [98.239.150.235]) by smtp.gmail.com with ESMTPSA id j67sm6874669qgj.35.2016.02.22.08.37.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 08:37:03 -0800 (PST) From: "=?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?=" X-Google-Original-From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= To: Johannes Berg Cc: "David S. Miller" , Darren Hart , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessm.com, =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Subject: [PATCHv2 07/10] rfkill: Create "rfkill-airplane-mode" LED trigger Date: Mon, 22 Feb 2016 11:36:38 -0500 Message-Id: <1456159001-20307-8-git-send-email-jprvita@endlessm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456159001-20307-1-git-send-email-jprvita@endlessm.com> References: <1456159001-20307-1-git-send-email-jprvita@endlessm.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 creates a new LED trigger to be used by platform drivers as a default trigger for airplane-mode indicator LEDs. By default this trigger will fire when RFKILL_OP_CHANGE_ALL is called for all types (RFKILL_TYPE_ALL), setting the LED brightness to LED_FULL when the changing the state to blocked, and to LED_OFF when the changing the state to unblocked. In the future there will be a mechanism for userspace to override the default policy, so it can implement its own. This trigger will be used by the asus-wireless x86 platform driver. Signed-off-by: João Paulo Rechi Vita --- Documentation/rfkill.txt | 2 ++ net/rfkill/core.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Documentation/rfkill.txt b/Documentation/rfkill.txt index 1f0c270..b13025a 100644 --- a/Documentation/rfkill.txt +++ b/Documentation/rfkill.txt @@ -85,6 +85,8 @@ device). Don't do this unless you cannot get the event in any other way. RFKill provides per-switch LED triggers, which can be used to drive LEDs according to the switch state (LED_FULL when blocked, LED_OFF otherwise). +An airplane-mode indicator LED trigger is also available, which triggers +LED_FULL when all radios known by RFKill are blocked, and LED_OFF otherwise. 5. Userspace support diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 8b96869..50b538b 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -126,6 +126,30 @@ static bool rfkill_epo_lock_active; #ifdef CONFIG_RFKILL_LEDS +static struct led_trigger rfkill_apm_led_trigger; + +static void rfkill_apm_led_trigger_event(bool state) +{ + led_trigger_event(&rfkill_apm_led_trigger, state ? LED_FULL : LED_OFF); +} + +static void rfkill_apm_led_trigger_activate(struct led_classdev *led) +{ + rfkill_apm_led_trigger_event(!rfkill_default_state); +} + +static int rfkill_apm_led_trigger_register(void) +{ + rfkill_apm_led_trigger.name = "rfkill-airplane-mode"; + rfkill_apm_led_trigger.activate = rfkill_apm_led_trigger_activate; + return led_trigger_register(&rfkill_apm_led_trigger); +} + +static void rfkill_apm_led_trigger_unregister(void) +{ + led_trigger_unregister(&rfkill_apm_led_trigger); +} + static void rfkill_led_trigger_event(struct rfkill *rfkill) { struct led_trigger *trigger; @@ -177,6 +201,19 @@ static void rfkill_led_trigger_unregister(struct rfkill *rfkill) led_trigger_unregister(&rfkill->led_trigger); } #else +static void rfkill_apm_led_trigger_event(bool state) +{ +} + +static int rfkill_apm_led_trigger_register(void) +{ + return 0; +} + +static void rfkill_apm_led_trigger_unregister(void) +{ +} + static void rfkill_led_trigger_event(struct rfkill *rfkill) { } @@ -313,6 +350,7 @@ static void rfkill_update_global_state(enum rfkill_type type, bool blocked) for (i = 0; i < NUM_RFKILL_TYPES; i++) rfkill_global_states[i].cur = blocked; + rfkill_apm_led_trigger_event(blocked); } #ifdef CONFIG_RFKILL_INPUT @@ -1260,15 +1298,22 @@ static int __init rfkill_init(void) { int error; + error = rfkill_apm_led_trigger_register(); + if (error) + goto out; + rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state); error = class_register(&rfkill_class); - if (error) + if (error) { + rfkill_apm_led_trigger_unregister(); goto out; + } error = misc_register(&rfkill_miscdev); if (error) { class_unregister(&rfkill_class); + rfkill_apm_led_trigger_unregister(); goto out; } @@ -1277,6 +1322,7 @@ static int __init rfkill_init(void) if (error) { misc_deregister(&rfkill_miscdev); class_unregister(&rfkill_class); + rfkill_apm_led_trigger_unregister(); goto out; } #endif @@ -1293,5 +1339,6 @@ static void __exit rfkill_exit(void) #endif misc_deregister(&rfkill_miscdev); class_unregister(&rfkill_class); + rfkill_apm_led_trigger_unregister(); } module_exit(rfkill_exit);