From 8a3980bb15e31a5c17e7541bc60cbe4bc56bf604 Mon Sep 17 00:00:00 2001 From: Ritesh Raj Sarraf Date: Mon, 30 Jan 2017 15:05:48 +0530 Subject: [PATCH] Add sysfs interface for touchpad state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. This patch adds a sysfs interface for read/write access under: /sys/bus/platform/devices/VPC2004\:00/touchpad_mode rrs@learner:~$ cat /sys/bus/platform/devices/VPC2004\:00/touchpad_mode 1 2017-01-31 / 16:58:46 ♒♒♒ ☺ rrs@learner:~$ su Password: root@learner:/home/rrs# echo 0 > /sys/bus/platform/devices/VPC2004\:00/touchpad_mode root@learner:/home/rrs# cat /sys/bus/platform/devices/VPC2004\:00/touchpad_mode 0 root@learner:/home/rrs# echo 1 > /sys/bus/platform/devices/VPC2004\:00/touchpad_mode root@learner:/home/rrs# cat /sys/bus/platform/devices/VPC2004\:00/touchpad_mode 1 root@learner:/home/rrs# exit 2017-01-31 / 16:59:26 ♒♒♒ ☺ rrs@learner:~$ Enable write. Change name to _mode Update ABI documentation for ideapad-laptop Signed-off-by: Ritesh Raj Sarraf --- .../ABI/testing/sysfs-platform-ideapad-laptop | 9 ++++++ drivers/platform/x86/ideapad-laptop.c | 33 ++++++++++++++++++++++ 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..401e37e5acbd 100644 --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop @@ -17,3 +17,12 @@ Description: * 2 -> Dust Cleaning * 4 -> Efficient Thermal Dissipation Mode +What: /sys/devices/platform/ideapad/touchpad_mode +Date: Jan 2017 +KernelVersion: 4.11 +Contact: "Ritesh Raj Sarraf " +Description: + Control touchpad mode. + * 1 -> Switched On + * 0 -> Switched Off + diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index a7614fc542b5..e612e0764ba6 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -423,9 +423,42 @@ static ssize_t store_ideapad_fan(struct device *dev, static DEVICE_ATTR(fan_mode, 0644, show_ideapad_fan, store_ideapad_fan); + +static ssize_t show_touchpad_mode(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + unsigned long result; + struct ideapad_private *priv = dev_get_drvdata(dev); + + 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 store_touchpad_mode(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret, state; + struct ideapad_private *priv = dev_get_drvdata(dev); + + if (!count) + return 0; + if (sscanf(buf, "%i", &state) != 1) + return -EINVAL; + ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); + if (ret < 0) + return -EIO; + return count; +} + +static DEVICE_ATTR(touchpad_mode, 0644, show_touchpad_mode, store_touchpad_mode); + static struct attribute *ideapad_attributes[] = { &dev_attr_camera_power.attr, &dev_attr_fan_mode.attr, + &dev_attr_touchpad_mode.attr, NULL }; -- 2.11.0