Re: [PATCH v4] platform/x86: ideapad-laptop: Add sysfs interface for touchpad state

From: Ritesh Raj Sarraf
Date: Wed May 03 2017 - 10:36:53 EST

Resending again, as Google servers are behaving weird lately.

On Sun, 2017-04-30 at 15:54 +0300, Andy Shevchenko wrote:
> > > the main issue that driver doesn't
> > > send SW_TABLET_MODE event through input device.
> >
> > Well. Yes. That is one part. If SW_TABLET_MODE is done in the driver, much
> > better. My patch was simply in line with some of the other drivers (hp-wmi
> > and
> > thinkpad_acpi) to get it working for Lenovo Yoga series.
> sysfs ABI for drivers that provide input interface is quite strong for
> my opinion. It means I'm not totally objecting, but I would accept it
> if and only if there is nothing else could be done.

The need we have in the user application is for read-only access.Â

I have attached the same old patch with just the minor file attribute change,
which would make the sysfs interface to read-only. If in future, there are good
reasons to expose that interface as read/write, updating that attribute can be

Can this now be included in your tree ? This minor patch may be helpful to many
Ideapad users with a Hybrid machine.

PS: Given how minimal the change is, I just hand updated the patch. If you want
it in the proper git send-email flow, please let me know.

Ritesh Raj Sarraf |
Debian - The Universal Operating SystemFrom f18911c1ee0714943a023db8ae43bf84a3873d98 Mon Sep 17 00:00:00 2001
From: Ritesh Raj Sarraf <rrs@xxxxxxxxxx>
Date: Mon, 30 Jan 2017 15:05:48 +0530
Subject: [PATCH v4] platform/x86: ideapad-laptop: Add sysfs interface for touchpad state

Lenovo Yoga (many variants: Yoga, Yoga2 Pro, Yoga2 13, Yoga3 Pro, Yoga 3
14 etc) has multiple modles that are a hybrid laptop, working in laptop
mode as well as tablet mode.

Currently, there is no easy interface to determine the touchpad status,
which in case of the Yoga family of machines, can also be useful to
assume tablet mode status.
Note: The ideapad-laptop driver does not provide a SW_TABLET_MODE either

For a detailed discussion on why we want either of the interfaces,
please see:

This patch adds a sysfs interface for read access under:

Set file attribute to read-only

Use kstrtobool because supported values are boolean

Include Darren Hart's comments
Changed sysfs inteface from "touchpad_mode" to "touchpad"

Include Andy Shevchenko's comments

Signed-off-by: Ritesh Raj Sarraf <rrs@xxxxxxxxxx>
.../ABI/testing/sysfs-platform-ideapad-laptop | 8 +++++
drivers/platform/x86/ideapad-laptop.c | 34 ++++++++++++++++++++++
2 files changed, 42 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
index b31e782bd985..5d24f1e8e6ef 100644
--- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
+++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
@@ -17,3 +17,11 @@ Description:
* 2 -> Dust Cleaning
* 4 -> Efficient Thermal Dissipation Mode

+What: /sys/devices/platform/ideapad/touchpad
+Date: Feb 2017
+KernelVersion: 4.12
+Contact: "Ritesh Raj Sarraf <rrs@xxxxxxxxxx>"
+ Read touchpad status.
+ * 1 -> Switched On
+ * 0 -> Switched Off
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index f46ece2ce3c4..b35954707e11 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -423,9 +423,43 @@ static ssize_t store_ideapad_fan(struct device *dev,

static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan);

+static ssize_t touchpad_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+ struct ideapad_private *priv = dev_get_drvdata(dev);
+ unsigned long result;
+ if (read_ec_data(priv->adev->handle, VPCCMD_R_TOUCHPAD, &result))
+ return sprintf(buf, "-1\n");
+ return sprintf(buf, "%lu\n", result);
+static ssize_t touchpad_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+ struct ideapad_private *priv = dev_get_drvdata(dev);
+ int ret;
+ bool state;
+ ret = kstrtobool(buf, &state);
+ if (ret)
+ return ret;
+ ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state);
+ if (ret < 0)
+ return -EIO;
+ return count;
+static DEVICE_ATTR_RO(touchpad);
static struct attribute *ideapad_attributes[] = {
+ &dev_attr_touchpad.attr,


Attachment: signature.asc
Description: This is a digitally signed message part