Skip to contentSkip to conversation

Add sysfs interface for touchpad state

PATCH Superseded Ritesh Raj Sarraf 2 participants 3 messages Feb 17, 2017 x86 platform drivers

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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:
https://bugs.launchpad.net/onboard/+bug/1366421/comments/43

This patch adds a sysfs interface for read/write access under:
/sys/bus/platform/devices/VPC2004\:00/touchpad_mode

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

v2:
Include Andy Shevchenko's comments

---
 .../ABI/testing/sysfs-platform-ideapad-laptop      |  8 +++++
 drivers/platform/x86/ideapad-laptop.c              | 36 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)
Documentation/ABI/testing/sysfs-platform-ideapad-laptop +8 -0
index b31e782bd985..5d24f1e8e6ef 100644
@@ -17,3 +17,11 @@ Description:
 			* 2 -> Dust Cleaning
 			* 4 -> Efficient Thermal Dissipation Mode
 
+What:		/sys/devices/platform/ideapad/touchpad
+Date:		Feb 2017
+KernelVersion:	4.11
+Contact:	"Ritesh Raj Sarraf <[email protected]>"
+Description:
+		Control touchpad mode.
+			* 1 -> Switched On
+			* 0 -> Switched Off
drivers/platform/x86/ideapad-laptop.c +36 -0
index f46ece2ce3c4..aff1a561c9ec 100644
@@ -423,9 +423,45 @@ 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, state;
+
+	ret = kstrtoint(buf, 0, &state);
+	if (ret)
+		return ret;
+
+	if (state != 0 && 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_RW(touchpad);
+
 static struct attribute *ideapad_attributes[] = {
 	&dev_attr_camera_power.attr,
 	&dev_attr_fan_mode.attr,
+	&dev_attr_touchpad.attr,
 	NULL
 };
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 18 lines · Ritesh Raj Sarraf

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:
https://bugs.launchpad.net/onboard/+bug/1366421/comments/43

This patch adds a sysfs interface for read/write access under:
/sys/bus/platform/devices/VPC2004\:00/touchpad_mode

drivers/platform/x86/ideapad-laptop.c static ssize_t store_ideapad_fan(struct device *dev, · line 448

Quoted 10 lines
drivers/platform/x86/ideapad-laptop.c +10 -0
+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, state;
+
+       ret = kstrtoint(buf, 0, &state);
+       if (ret)
+               return ret;

If it's intended to be boolean, better to use kstrtobool()

Quoted 22 lines
drivers/platform/x86/ideapad-laptop.c +13 -1
+
+       if (state != 0 && 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_RW(touchpad);
+
 static struct attribute *ideapad_attributes[] = {
        &dev_attr_camera_power.attr,
        &dev_attr_fan_mode.attr,
+       &dev_attr_touchpad.attr,
        NULL
 };
 
--

2.11.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Quoted 4 lines · Andy Shevchenko
Quoted 4 lines
drivers/platform/x86/ideapad-laptop.c +4 -0
+static ssize_t touchpad_store(struct device *dev,
+                                struct device_attribute *attr,
+                                const char *buf, size_t count)
+{
Quoted 8 lines
Quoted 6 lines

+       struct ideapad_private *priv = dev_get_drvdata(dev); +       int ret, state;
+
+       ret = kstrtoint(buf, 0, &state);
+       if (ret)
+               return ret;

If it's intended to be boolean, better to use kstrtobool()

Thanks. Revised patch built, tested locally, and sent (git send-email).

- --
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEQCVDstmIVAB/Yn02pjpYo/LhdWkFAlinRdoACgkQpjpYo/Lh dWljCRAAqAqvbXABNFnoObBrQ4e4nULupH/R2FuAOU+tgKJUv6Fks85TuPvoNLwb OYMP7HoXXKf1ME4lIILEhrl6UCvlOzN4lUbxdFaUhg/NvvduHc9n5v+hFDask/BC dA+Vt4r8KI8FH6O5O/JqxkFm0UZSVA41K15fTsX/5JunH7f+SOKPQIjMAk3/3MBm puVtxDUTHjx0yOTpzIv0xzIrVtwAeFtfINDG/M+e5wKuurCyZ+ARvRb0melRHGXH N4PlAAZ2BvgLqHjZqU+EqkER1wiAPkpZw0VSavT9Efw+FMy/yKoogdRLImRNR8Sh MwAuj+U4xL572n53x09w9UBbAGAbP4O4O/1DUl2zL6MXFtHboCs+AkPP9UYaUXYG rhi3GSPHCDk0iQuXrwMmjyDw3Ta1RFJs4aBAuRdJOiifH0nOTsA5SmX4i4Mep+9k QuMSEIHTNQpflAuGe0/4ku+QEQDm0L7IXxzqK7Ra+P9XdqOxa5iYyrbmPxqgL0xA +DjT/92ZvHI5IFBBk/c5ZSCaRmSchaHiHWPG3z7qcP770jKqKAeMVeyxMAo8q/h7 J0E7w5p+kFn/71+3E4TvM1pC13mHwspAqheoIfYObPS1nU3XVIUpJ9A/rLLcvXY5 920LxV0Yz+Gs1GcgVlItOSSUhPeh11atzV3Y4UAnMuvh7RWWzDc= =6Bli
-----END PGP SIGNATURE-----