From: Ayman Bagabas <ayman.bagabas@gmail.com>
To: Darren Hart <dvhart@infradead.org>,
Andy Shevchenko <andy@infradead.org>,
Ayman Bagabas <ayman.bagabas@gmail.com>,
Takashi Iwai <tiwai@suse.de>, Mattias Jacobsson <2pi@mok.nu>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/6] platform/x86: huawei-wmi: Add fn-lock support
Date: Wed, 18 Sep 2019 20:54:57 -0400 [thread overview]
Message-ID: <20190919005505.23822-6-ayman.bagabas@gmail.com> (raw)
In-Reply-To: <20190919005505.23822-1-ayman.bagabas@gmail.com>
Huawei Matebook laptops uses Fn key and toggle to access F1-F12 keys.
Along with that, there is this feature called fn-lock that inverts the
behavior of this Fn key and the F1-F12 row.
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
---
drivers/platform/x86/huawei-wmi.c | 85 +++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 231b5cce00db..48be55c6027e 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -59,6 +59,7 @@ struct huawei_wmi_debug {
struct huawei_wmi {
bool battery_available;
+ bool fn_lock_available;
struct huawei_wmi_debug debug;
struct input_dev *idev[2];
@@ -515,6 +516,88 @@ static void huawei_wmi_battery_exit(struct device *dev)
}
}
+/* Fn lock */
+
+static int huawei_wmi_fn_lock_get(int *on)
+{
+ u8 ret[0x100] = { 0 };
+ int err, i;
+
+ err = huawei_wmi_cmd(FN_LOCK_GET, ret, 0x100);
+ if (err)
+ return err;
+
+ /* Find the first non-zero value. Return status is ignored. */
+ i = 1;
+ do {
+ if (on)
+ *on = ret[i] - 1; // -1 undefined, 0 off, 1 on.
+ } while (i < 0x100 && !ret[i++]);
+
+ return 0;
+}
+
+static int huawei_wmi_fn_lock_set(int on)
+{
+ union hwmi_arg arg;
+
+ arg.cmd = FN_LOCK_SET;
+ arg.args[2] = on + 1; // 0 undefined, 1 off, 2 on.
+
+ return huawei_wmi_cmd(arg.cmd, NULL, NULL);
+}
+
+static ssize_t fn_lock_state_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int err, on;
+
+ err = huawei_wmi_fn_lock_get(&on);
+ if (err)
+ return err;
+
+ return sprintf(buf, "%d\n", on);
+}
+
+static ssize_t fn_lock_state_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ int on, err;
+
+ if (kstrtoint(buf, 10, &on) ||
+ on < 0 || on > 1)
+ return -EINVAL;
+
+ err = huawei_wmi_fn_lock_set(on);
+ if (err)
+ return err;
+
+ return size;
+}
+
+static DEVICE_ATTR_RW(fn_lock_state);
+
+static void huawei_wmi_fn_lock_setup(struct device *dev)
+{
+ struct huawei_wmi *huawei = dev_get_drvdata(dev);
+
+ huawei->fn_lock_available = true;
+ if (huawei_wmi_fn_lock_get(NULL)) {
+ huawei->fn_lock_available = false;
+ return;
+ }
+
+ device_create_file(dev, &dev_attr_fn_lock_state);
+}
+
+static void huawei_wmi_fn_lock_exit(struct device *dev)
+{
+ if (huawei_wmi->fn_lock_available)
+ device_remove_file(dev, &dev_attr_fn_lock_state);
+}
+
/* Input */
static void huawei_wmi_process_key(struct input_dev *idev, int code)
@@ -638,6 +721,7 @@ static int huawei_wmi_probe(struct platform_device *pdev)
mutex_init(&huawei_wmi->battery_lock);
huawei_wmi_leds_setup(&pdev->dev);
+ huawei_wmi_fn_lock_setup(&pdev->dev);
huawei_wmi_battery_setup(&pdev->dev);
}
@@ -657,6 +741,7 @@ static int huawei_wmi_remove(struct platform_device *pdev)
if (wmi_has_guid(HWMI_METHOD_GUID)) {
huawei_wmi_battery_exit(&pdev->dev);
+ huawei_wmi_fn_lock_exit(&pdev->dev);
}
return 0;
--
2.21.0
next prev parent reply other threads:[~2019-09-19 0:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-19 0:54 [PATCH v2 0/6] platform/x86: Huawei WMI laptop extras driver Ayman Bagabas
2019-09-19 0:54 ` [PATCH v2 1/6] platform/x86: huawei-wmi: Move to platform driver Ayman Bagabas
2019-09-19 0:54 ` [PATCH v2 2/6] platform/x86: huawei-wmi: Add quirks and module parameters Ayman Bagabas
2019-09-19 0:54 ` [PATCH v2 3/6] platform/x86: huawei-wmi: Implement huawei wmi management Ayman Bagabas
2019-09-19 3:22 ` kbuild test robot
2019-09-19 0:54 ` [PATCH v2 4/6] platform/x86: huawei-wmi: Add battery charging thresholds Ayman Bagabas
2019-09-19 3:08 ` kbuild test robot
2019-09-19 0:54 ` Ayman Bagabas [this message]
2019-09-19 0:54 ` [PATCH v2 6/6] platform/x86: huawei-wmi: Add debugfs support Ayman Bagabas
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=20190919005505.23822-6-ayman.bagabas@gmail.com \
--to=ayman.bagabas@gmail.com \
--cc=2pi@mok.nu \
--cc=andy@infradead.org \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=tiwai@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®