From patchwork Wed Jan 6 02:29:07 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: 7964011 Return-Path: X-Original-To: patchwork-platform-driver-x86@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 979909F32E for ; Wed, 6 Jan 2016 02:29:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FD302022A for ; Wed, 6 Jan 2016 02:29:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 617D020221 for ; Wed, 6 Jan 2016 02:29:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751761AbcAFC3N (ORCPT ); Tue, 5 Jan 2016 21:29:13 -0500 Received: from mail-qk0-f175.google.com ([209.85.220.175]:36769 "EHLO mail-qk0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750846AbcAFC3N (ORCPT ); Tue, 5 Jan 2016 21:29:13 -0500 Received: by mail-qk0-f175.google.com with SMTP id q19so92765754qke.3; Tue, 05 Jan 2016 18:29:12 -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=B86RQsVCgBcItDGGJqO4UG/mh86BF6UIaCJEdnYIYHI=; b=q28qS1FfclcPznu7cI+FXfJb7QB7a6nVkMiiznnc65rNyhwZmItQYklF4EoAS2ppzk C/qYjKBEcJcGW8sN8sUCDbtjNS7/6IlWisaiu2kwMkyU1obzJpOC9y+TSywoS6wXUYdb oSDqxkv3alMMi8XJOMoOxknlTfDW7MYH+rinL5gpt545a/Lq4TzKo6VegX3n0RI//XtF YPjXCNuAfBzoso+PSYQt4+MFMLraXIij47jMrAzdYiYQSTFxwqUJtLyiNAA1wT2C2eid DedTtjfHCrl5GhCH5EIQNW4ZzfHbbKLaYUdcQTAwFmQX4pCGCBsyERN3xXv4YVNBelGU I4gA== X-Received: by 10.55.26.204 with SMTP id l73mr126852859qkh.78.1452047351918; Tue, 05 Jan 2016 18:29:11 -0800 (PST) Received: from localhost.localdomain (c-98-239-150-235.hsd1.wv.comcast.net. [98.239.150.235]) by smtp.gmail.com with ESMTPSA id a129sm14311494qkb.45.2016.01.05.18.29.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Jan 2016 18:29:11 -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: Darren Hart Cc: Corentin Chary , andy.shevchenko@gmail.com, platform-driver-x86@vger.kernel.org, acpi4asus-user@lists.sourceforge.net, linux-kernel@vger.kernel.org, =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Subject: [PATCH 1/2] asus-wireless: Toggle airplane mode LED Date: Tue, 5 Jan 2016 21:29:07 -0500 Message-Id: <1452047347-7101-1-git-send-email-jprvita@endlessm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452046768-6291-2-git-send-email-jprvita@endlessm.com> References: <1452046768-6291-2-git-send-email-jprvita@endlessm.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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=ham 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 In the ASHS device we have the HSWC method, which basically calls either OWGD or OWGS, depending on its parameter: Device (ASHS) { Name (_HID, "ATK4002") // _HID: Hardware ID Method (HSWC, 1, Serialized) { If ((Arg0 < 0x02)) { OWGD (Arg0) Return (One) } If ((Arg0 == 0x02)) { Local0 = OWGS () If (Local0) { Return (0x05) } Else { Return (0x04) } } If ((Arg0 == 0x03)) { Return (0xFF) } If ((Arg0 == 0x04)) { OWGD (Zero) Return (One) } If ((Arg0 == 0x05)) { OWGD (One) Return (One) } If ((Arg0 == 0x80)) { Return (One) } } Method (_STA, 0, NotSerialized) // _STA: Status { If ((MSOS () >= OSW8)) { Return (0x0F) } Else { Return (Zero) } } } On the Asus E202SA laptop, which does not have an airplane mode LED, OWGD has an empty implementation and OWGS simply returns 0. On the Asus X555UB these methods have the following implementation: Method (OWGD, 1, Serialized) { SGPL (0x0203000F, Arg0) SGPL (0x0203000F, Arg0) } Method (OWGS, 0, Serialized) { Store (RGPL (0x0203000F), Local0) Return (Local0) } Where OWGD(1) sets the airplane mode LED ON, OWGD(0) set it off, and OWGS() returns its state. This commit makes use of a newly implemented RFKill LED trigger to trigger the LED when the system enters or exits "Airplane Mode", there is, when all radios are blocked. Signed-off-by: João Paulo Rechi Vita --- drivers/platform/x86/Kconfig | 2 + drivers/platform/x86/asus-wireless.c | 92 +++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index f37821f..5798cc4 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -591,6 +591,8 @@ config ASUS_WIRELESS tristate "Asus Wireless Radio Control Driver" depends on ACPI depends on INPUT + select NEW_LEDS + select LEDS_CLASS ---help--- The Asus Wireless Radio Control handles the airplane mode hotkey present on some Asus laptops. diff --git a/drivers/platform/x86/asus-wireless.c b/drivers/platform/x86/asus-wireless.c index 9ec721e..052a527 100644 --- a/drivers/platform/x86/asus-wireless.c +++ b/drivers/platform/x86/asus-wireless.c @@ -15,11 +15,78 @@ #include #include #include +#include + +#define ASUS_WIRELESS_LED_STATUS 0x2 +#define ASUS_WIRELESS_LED_OFF 0x4 +#define ASUS_WIRELESS_LED_ON 0x5 struct asus_wireless_data { struct input_dev *idev; + struct acpi_device *adev; + struct workqueue_struct *wq; + struct work_struct led_work; + struct led_classdev led; + int led_state; }; +static u64 asus_wireless_method(acpi_handle handle, const char *method, + int param) +{ + union acpi_object obj; + struct acpi_object_list p; + acpi_status s; + u64 ret; + + acpi_handle_debug(handle, "Evaluating method %s, parameter %#x\n", + method, param); + obj.type = ACPI_TYPE_INTEGER; + obj.integer.value = param; + p.count = 1; + p.pointer = &obj; + + s = acpi_evaluate_integer(handle, (acpi_string) method, &p, &ret); + if (ACPI_FAILURE(s)) + acpi_handle_err(handle, + "Failed to eval method %s, param %#x (%d)\n", + method, param, s); + acpi_handle_debug(handle, "%s returned %#x\n", method, (uint) ret); + return ret; +} + +static enum led_brightness asus_wireless_led_get(struct led_classdev *led) +{ + struct asus_wireless_data *data; + int s; + + data = container_of(led, struct asus_wireless_data, led); + s = asus_wireless_method(acpi_device_handle(data->adev), "HSWC", + ASUS_WIRELESS_LED_STATUS); + if (s == ASUS_WIRELESS_LED_ON) + return LED_FULL; + return LED_OFF; +} + +static void asus_wireless_led_update(struct work_struct *work) +{ + struct asus_wireless_data *data; + + data = container_of(work, struct asus_wireless_data, led_work); + asus_wireless_method(acpi_device_handle(data->adev), "HSWC", + data->led_state); +} + +static void asus_wireless_led_set(struct led_classdev *led, + enum led_brightness value) +{ + struct asus_wireless_data *data; + + data = container_of(led, struct asus_wireless_data, led); + data->led_state = value == LED_OFF ? ASUS_WIRELESS_LED_OFF : + ASUS_WIRELESS_LED_ON; + queue_work(data->wq, &data->led_work); +} + static void asus_wireless_notify(struct acpi_device *adev, u32 event) { struct asus_wireless_data *data = acpi_driver_data(adev); @@ -37,6 +104,7 @@ static void asus_wireless_notify(struct acpi_device *adev, u32 event) static int asus_wireless_add(struct acpi_device *adev) { struct asus_wireless_data *data; + int err; data = devm_kzalloc(&adev->dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -52,11 +120,33 @@ static int asus_wireless_add(struct acpi_device *adev) data->idev->id.vendor = PCI_VENDOR_ID_ASUSTEK; set_bit(EV_KEY, data->idev->evbit); set_bit(KEY_RFKILL, data->idev->keybit); - return input_register_device(data->idev); + err = input_register_device(data->idev); + if (err) + return err; + + data->adev = adev; + data->wq = create_singlethread_workqueue("asus_wireless_workqueue"); + if (!data->wq) + return -ENOMEM; + INIT_WORK(&data->led_work, asus_wireless_led_update); + data->led.name = "asus-wireless::airplane_mode"; + data->led.brightness_set = asus_wireless_led_set; + data->led.brightness_get = asus_wireless_led_get; + data->led.flags = LED_CORE_SUSPENDRESUME; + data->led.max_brightness = 1; + data->led.default_trigger = "rfkill-airplane-mode"; + err = devm_led_classdev_register(&adev->dev, &data->led); + if (err) + destroy_workqueue(data->wq); + return err; } static int asus_wireless_remove(struct acpi_device *adev) { + struct asus_wireless_data *data = acpi_driver_data(adev); + + if (data->wq) + destroy_workqueue(data->wq); return 0; }