All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ritesh Raj Sarraf <rrs@debian.org>
To: platform-driver-x86@vger.kernel.org
Cc: Ritesh Raj Sarraf <rrs@debian.org>
Subject: [PATCH] Add sysfs interface for touchpad state
Date: Mon, 30 Jan 2017 16:27:49 +0530	[thread overview]
Message-ID: <20170130105749.17338-1-rrs@debian.org> (raw)

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.

There is no interface available to query the physical state of these
devices. Also, from the driver, it doesn't look to be having an EC
command to get that information from the acpi driver.

When in tablet mode, the hardware keyboard and touchpad get disabled.
This could be one sub-optimal way to assume that under such condition
(touchpad disabled) the machine is in Tablet-Mode. Other than this, I've
not come across another way to determine the physical state of the
hardware.

Currently, some of the hardware status is provided through debugfs,
which is useless for unprivileged processes. (This already has many
broken reports: radio and wifi, which are active/on as I write this)

root@learner:/sys/kernel/debug# cat ideapad/status
Backlight max:	16
Backlight now:	3
BL power value:	On
=====================
Radio status:	Off(0)
Wifi status:	Off(0)
BT status:	Off(0)
3G status:	Off(0)
=====================
Touchpad status:On(1)
SW_TABLET_MODE:	Off(0)
Camera status:	On(1)

This patch adds a sysfs interface for unprivileged process access under:
/sys/bus/platform/devices/VPC2004\:00/touchpad_state

rrs@learner:/sys/bus/platform/devices/VPC2004:00$ cat touchpad_state
1
2017-01-30 / 16:12:00 ♒♒♒  ☺
rrs@learner:/sys/bus/platform/devices/VPC2004:00$ cat touchpad_state
0
2017-01-30 / 16:12:06 ♒♒♒  ☺

Signed-off-by: Ritesh Raj Sarraf <rrs@debian.org>
---
 drivers/platform/x86/ideapad-laptop.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index a7614fc542b5..3a1622ef2f45 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -423,9 +423,33 @@ 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_state(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_state(struct device *dev,
+				 struct device_attribute *attr,
+				 const char *buf, size_t count)
+{
+        /* Don't enable writing here */
+        return -1;
+}
+
+static DEVICE_ATTR(touchpad_state, 0644, show_touchpad_state, store_touchpad_state);
+
 static struct attribute *ideapad_attributes[] = {
 	&dev_attr_camera_power.attr,
 	&dev_attr_fan_mode.attr,
+	&dev_attr_touchpad_state.attr,
 	NULL
 };
 
-- 
2.11.0

             reply	other threads:[~2017-01-30 11:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-30 10:57 Ritesh Raj Sarraf [this message]
2017-01-30 20:25 ` [PATCH] Add sysfs interface for touchpad state Andy Shevchenko
2017-01-31 11:47   ` Ritesh Raj Sarraf
2017-02-01 11:25     ` Andy Shevchenko
2017-02-01 14:26       ` Ritesh Raj Sarraf
2017-02-01 15:07         ` Andy Shevchenko
2017-02-01 16:17           ` Ritesh Raj Sarraf
2017-02-01 20:53             ` Andy Shevchenko
2017-02-02  8:16               ` Ritesh Raj Sarraf
2017-02-13 22:26                 ` Andy Shevchenko
2017-02-14 14:18                   ` Ritesh Raj Sarraf

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=20170130105749.17338-1-rrs@debian.org \
    --to=rrs@debian.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.