All of lore.kernel.org
 help / color / mirror / Atom feed
From: "João Paulo Rechi Vita" <jprvita@gmail.com>
To: Corentin Chary <corentin.chary@gmail.com>
Cc: platform-driver-x86@vger.kernel.org,
	acpi4asus-user@lists.sourceforge.net, jprvita@gmail.com,
	"João Paulo Rechi Vita" <jprvita@endlessm.com>
Subject: [PATCH 4/4] asus-wrc: Toggle airplane mode LED
Date: Tue, 15 Dec 2015 10:30:42 -0500	[thread overview]
Message-ID: <1450193442-7930-5-git-send-email-jprvita@endlessm.com> (raw)
In-Reply-To: <1450193442-7930-1-git-send-email-jprvita@endlessm.com>

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 <jprvita@endlessm.com>
---
 drivers/platform/x86/asus-wrc.c | 81 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/drivers/platform/x86/asus-wrc.c b/drivers/platform/x86/asus-wrc.c
index 941ad73..6acb36e 100644
--- a/drivers/platform/x86/asus-wrc.c
+++ b/drivers/platform/x86/asus-wrc.c
@@ -17,11 +17,21 @@
 #include <linux/acpi.h>
 #include <linux/input.h>
 #include <linux/input/sparse-keymap.h>
+#include <linux/leds.h>
 
 #define ASUS_WRC_MODULE_NAME "Asus Wireless Radio Control Driver"
 
+#define ASUS_WRC_LED_STATUS 0x2
+#define ASUS_WRC_LED_OFF 0x4
+#define ASUS_WRC_LED_ON 0x5
+
 struct asus_wrc_data {
 	struct input_dev *inputdev;
+	struct acpi_device *acpidev;
+	struct workqueue_struct *wq;
+	struct work_struct led_work;
+	struct led_classdev led;
+	int led_state;
 };
 
 static const struct key_entry asus_wrc_keymap[] = {
@@ -29,6 +39,57 @@ static const struct key_entry asus_wrc_keymap[] = {
 	{ KE_END, 0 }
 };
 
+static u64 asus_wrc_method(acpi_handle handle, const char *method, int param)
+{
+	union acpi_object obj;
+	struct acpi_object_list p;
+	acpi_status s;
+	u64 ret;
+
+	pr_debug("Evaluating method %s, parameter 0x%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_SUCCESS(s))
+		pr_err("Failed to evaluate method %s, parameter 0x%X (%d)\n",
+		       method, param, s);
+
+	pr_debug("%s returned 0x%X\n", method, (uint) ret);
+	return ret;
+}
+
+static enum led_brightness asus_wrc_led_get(struct led_classdev *led)
+{
+	struct asus_wrc_data *data = container_of(led, struct asus_wrc_data,
+						  led);
+	int s = asus_wrc_method(data->acpidev->handle, "HSWC",
+				ASUS_WRC_LED_STATUS);
+	if (s == ASUS_WRC_LED_ON)
+		return LED_FULL;
+	return LED_OFF;
+}
+
+static void asus_wrc_led_update(struct work_struct *work)
+{
+	struct asus_wrc_data *data = container_of(work, struct asus_wrc_data,
+						  led_work);
+	asus_wrc_method(data->acpidev->handle, "HSWC", data->led_state);
+}
+
+static void asus_wrc_led_set(struct led_classdev *led,
+			     enum led_brightness value)
+{
+	struct asus_wrc_data *data = container_of(led, struct asus_wrc_data,
+						  led);
+	data->led_state = value == LED_OFF ? ASUS_WRC_LED_OFF : ASUS_WRC_LED_ON;
+	queue_work(data->wq, &data->led_work);
+}
+
 static void asus_wrc_notify(struct acpi_device *device, u32 event)
 {
 	struct asus_wrc_data *data = acpi_driver_data(device);
@@ -50,6 +111,8 @@ static int asus_wrc_add(struct acpi_device *device)
 	if (!data)
 		return -ENOMEM;
 
+	data->acpidev = device;
+
 	data->inputdev = input_allocate_device();
 	if (!data->inputdev)
 		goto fail;
@@ -60,6 +123,10 @@ static int asus_wrc_add(struct acpi_device *device)
 	data->inputdev->dev.parent = &device->dev;
 	set_bit(EV_REP, data->inputdev->evbit);
 
+	data->wq = create_singlethread_workqueue("asus_wrc_workqueue");
+	if (!data->wq)
+		goto fail;
+
 	err = sparse_keymap_setup(data->inputdev, asus_wrc_keymap, NULL);
 	if (err)
 		goto fail;
@@ -68,6 +135,17 @@ static int asus_wrc_add(struct acpi_device *device)
 	if (err)
 		goto fail;
 
+	INIT_WORK(&data->led_work, asus_wrc_led_update);
+	data->led.name = "asus-wrc::airplane_mode";
+	data->led.brightness_set = asus_wrc_led_set;
+	data->led.brightness_get = asus_wrc_led_get;
+	data->led.flags = LED_CORE_SUSPENDRESUME;
+	data->led.max_brightness = 1;
+	data->led.default_trigger = "rfkill-airplane-mode";
+	err = led_classdev_register(&device->dev, &data->led);
+	if (err)
+		goto fail;
+
 	device->driver_data = data;
 	return 0;
 
@@ -89,6 +167,9 @@ static int asus_wrc_remove(struct acpi_device *device)
 			data->inputdev = NULL;
 		}
 
+		if (data->wq)
+			destroy_workqueue(data->wq);
+
 		kfree(data);
 		data = NULL;
 	}
-- 
2.5.0

  parent reply	other threads:[~2015-12-15 15:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-15 15:30 [RFC 0/4] Asus Wireless Radio Control driver João Paulo Rechi Vita
2015-12-15 15:30 ` [PATCH 1/4] platform/x86: Add " João Paulo Rechi Vita
2015-12-19  6:39   ` Darren Hart
     [not found]     ` <CA+A7VXWGTAsen2V29ifJ9nGCuHRnQnZi=Q_oEi1fkmeo=t1gxQ@mail.gmail.com>
2015-12-20 16:58       ` João Paulo Rechi Vita
2015-12-19  7:23   ` Darren Hart
     [not found]     ` <CA+A7VXU9MepWmWL6BS+XyjbLs2s_ONR5Yy3tqT--cbYS7p1P1Q@mail.gmail.com>
2015-12-20 17:00       ` João Paulo Rechi Vita
2015-12-15 15:30 ` [PATCH 2/4] asus-wrc: Add ACPI HID ATK4001 João Paulo Rechi Vita
2015-12-19  6:40   ` Darren Hart
2015-12-20 18:57     ` João Paulo Rechi Vita
2015-12-15 15:30 ` [PATCH 3/4] net/rfkill: Create "airplane mode" LED trigger João Paulo Rechi Vita
2015-12-19  0:22   ` Darren Hart
2015-12-19  0:36     ` João Paulo Rechi Vita
2015-12-19  2:25     ` David Miller
2015-12-15 15:30 ` João Paulo Rechi Vita [this message]
2015-12-19  8:00 ` [RFC 0/4] Asus Wireless Radio Control driver Darren Hart
2015-12-20 19:01   ` João Paulo Rechi Vita

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450193442-7930-5-git-send-email-jprvita@endlessm.com \
    --to=jprvita@gmail.com \
    --cc=acpi4asus-user@lists.sourceforge.net \
    --cc=corentin.chary@gmail.com \
    --cc=jprvita@endlessm.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.