From: Ayman Bagabas <ayman.bagabas@gmail.com>
To: Darren Hart <dvhart@infradead.org>,
Andy Shevchenko <andy@infradead.org>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Ayman Bagabas <ayman.bagabas@gmail.com>
Subject: [RFC 8/9] platform/x86: huawei-wmi: Add sysfs interface support
Date: Wed, 31 Jul 2019 13:52:54 -0400 [thread overview]
Message-ID: <20190731175255.25676-9-ayman.bagabas@gmail.com> (raw)
In-Reply-To: <20190731175255.25676-1-ayman.bagabas@gmail.com>
Add sysfs interface to enable the use of battery charging thresholds and
fn-lock support introduced in this series.
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
---
drivers/platform/x86/huawei-wmi.c | 82 +++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
index 4159e10bda26..f7041fb71026 100644
--- a/drivers/platform/x86/huawei-wmi.c
+++ b/drivers/platform/x86/huawei-wmi.c
@@ -14,6 +14,7 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
+#include <linux/sysfs.h>
#include <linux/wmi.h>
/*
@@ -381,6 +382,80 @@ static int huawei_wmi_fn_lock_set(struct device *dev, int on)
return huawei_wmi_cmd(dev, *(u64 *)arg, NULL, NULL);
}
+/* sysfs */
+
+static ssize_t charge_thresholds_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int err, low, high;
+
+ err = huawei_wmi_battery_get(dev, &low, &high);
+ if (err)
+ return err;
+
+ return sprintf(buf, "%d %d\n", low, high);
+}
+
+static ssize_t charge_thresholds_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ int low, high, err;
+
+ if (sscanf(buf, "%d %d", &low, &high) != 2 ||
+ low < 0 || high > 100 ||
+ low > high)
+ return -EINVAL;
+
+ err = huawei_wmi_battery_set(dev, low, high);
+ if (err)
+ return err;
+
+ return size;
+}
+
+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(dev, &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(dev, on);
+ if (err)
+ return err;
+
+ return size;
+}
+
+static DEVICE_ATTR_RW(charge_thresholds);
+static DEVICE_ATTR_RW(fn_lock_state);
+
+static struct attribute *huawei_wmi_attrs[] = {
+ &dev_attr_charge_thresholds.attr,
+ &dev_attr_fn_lock_state.attr,
+ NULL
+};
+
+ATTRIBUTE_GROUPS(huawei_wmi);
+
/* Input */
static void huawei_wmi_process_key(struct input_dev *idev, int code)
@@ -508,6 +583,12 @@ static int huawei_wmi_probe(struct platform_device *pdev)
dev_err(&pdev->dev, "Failed to setup leds\n");
return err;
}
+
+ err = sysfs_create_groups(&pdev->dev.kobj, huawei_wmi_groups);
+ if (err) {
+ dev_err(&pdev->dev, "Failed to create sysfs interface\n");
+ return err;
+ }
}
return 0;
@@ -522,6 +603,7 @@ static int huawei_wmi_remove(struct platform_device *pdev)
wmi_remove_notify_handler(HWMI_EVENT_GUID);
if (wmi_has_guid(HWMI_METHOD_GUID)) {
+ sysfs_remove_groups(&pdev->dev.kobj, huawei_wmi_groups);
}
return 0;
--
2.20.1
next prev parent reply other threads:[~2019-07-31 17:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-31 17:52 [RFC 0/9] platform/x86: Huawei WMI laptop extras driver Ayman Bagabas
2019-07-31 17:52 ` [RFC 2/9] platform/x86: huawei-wmi: Move to platform driver Ayman Bagabas
2019-07-31 17:52 ` [RFC 3/9] platform/x86: huawei-wmi: Implement huawei wmi management interface Ayman Bagabas
2019-07-31 17:52 ` [RFC 4/9] platform/x86: huawei-wmi: Add quirks and module parameters Ayman Bagabas
2019-07-31 17:52 ` [RFC 5/9] platform/x86: huawei-wmi: Control micmute led through wmi interface Ayman Bagabas
2019-07-31 17:52 ` [RFC 6/9] platform/x86: huawei-wmi: Add battery charging thresholds Ayman Bagabas
2019-07-31 17:52 ` [RFC 7/9] platform/x86: huawei-wmi: Add fn-lock support Ayman Bagabas
2019-07-31 17:52 ` Ayman Bagabas [this message]
2019-07-31 17:52 ` [RFC 9/9] platform/x86: huawei-wmi: Add debugfs support Ayman Bagabas
2019-08-01 0:21 ` [RFC 1/9] platform/x86: huawei-wmi: Rename guid and driver name Ayman Bagabas
2019-07-31 18:06 ` Ayman Bagabas
-- strict thread matches above, loose matches on Subject: below --
2019-06-30 5:40 [RFC 0/9] platform/x86: Huawei WMI laptop extras driver Ayman Bagabas
2019-06-30 5:41 ` [RFC 8/9] platform/x86: huawei-wmi: Add sysfs interface 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=20190731175255.25676-9-ayman.bagabas@gmail.com \
--to=ayman.bagabas@gmail.com \
--cc=andy@infradead.org \
--cc=dvhart@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).