3ff7c26
From 33fc16fd8aa3684e19b1d1f0a712593e2e570ab1 Mon Sep 17 00:00:00 2001
3ff7c26
From: Hans de Goede <hdegoede@redhat.com>
3ff7c26
Date: Sun, 11 Jun 2017 21:24:50 +0200
3ff7c26
Subject: [PATCH 10/16] Input: silead: Add support for capactive home button
3ff7c26
 found on some x86 tablets
3ff7c26
3ff7c26
On some x86 tablets with a silead touchscreen the windows logo on the
3ff7c26
front is a capacitive home button. Touching this button results in a touch
3ff7c26
with bits 12-15 of the Y coordinates set, while normally only the lower 12
3ff7c26
are used.
3ff7c26
3ff7c26
Detect this and report a KEY_LEFTMETA press when this happens. Note for
3ff7c26
now we only respond to the Y coordinate bits 12-15 containing 0x01, on some
3ff7c26
tablets *without* a capacative button I've noticed these bits containing
3ff7c26
0x04 when crossing the edges of the screen.
3ff7c26
3ff7c26
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3ff7c26
---
3ff7c26
 drivers/input/touchscreen/silead.c | 45 ++++++++++++++++++++++++++++----------
3ff7c26
 1 file changed, 34 insertions(+), 11 deletions(-)
3ff7c26
3ff7c26
diff --git a/drivers/input/touchscreen/silead.c b/drivers/input/touchscreen/silead.c
3ff7c26
index 0dbcf105f7db..c0ba40c09699 100644
3ff7c26
--- a/drivers/input/touchscreen/silead.c
3ff7c26
+++ b/drivers/input/touchscreen/silead.c
3ff7c26
@@ -56,7 +56,7 @@
3ff7c26
 #define SILEAD_POINT_Y_MSB_OFF	0x01
3ff7c26
 #define SILEAD_POINT_X_OFF	0x02
3ff7c26
 #define SILEAD_POINT_X_MSB_OFF	0x03
3ff7c26
-#define SILEAD_TOUCH_ID_MASK	0xF0
3ff7c26
+#define SILEAD_EXTRA_DATA_MASK	0xF0
3ff7c26
 
3ff7c26
 #define SILEAD_CMD_SLEEP_MIN	10000
3ff7c26
 #define SILEAD_CMD_SLEEP_MAX	20000
3ff7c26
@@ -109,6 +109,8 @@ static int silead_ts_request_input_dev(struct silead_ts_data *data)
3ff7c26
 			    INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED |
3ff7c26
 			    INPUT_MT_TRACK);
3ff7c26
 
3ff7c26
+	input_set_capability(data->input, EV_KEY, KEY_LEFTMETA);
3ff7c26
+
3ff7c26
 	data->input->name = SILEAD_TS_NAME;
3ff7c26
 	data->input->phys = "input/ts";
3ff7c26
 	data->input->id.bustype = BUS_I2C;
3ff7c26
@@ -139,7 +141,8 @@ static void silead_ts_read_data(struct i2c_client *client)
3ff7c26
 	struct input_dev *input = data->input;
3ff7c26
 	struct device *dev = &client->dev;
3ff7c26
 	u8 *bufp, buf[SILEAD_TS_DATA_LEN];
3ff7c26
-	int touch_nr, error, i;
3ff7c26
+	int touch_nr, softbutton, error, i;
3ff7c26
+	bool softbutton_pressed = false;
3ff7c26
 
3ff7c26
 	error = i2c_smbus_read_i2c_block_data(client, SILEAD_REG_DATA,
3ff7c26
 					      SILEAD_TS_DATA_LEN, buf);
3ff7c26
@@ -148,21 +151,40 @@ static void silead_ts_read_data(struct i2c_client *client)
3ff7c26
 		return;
3ff7c26
 	}
3ff7c26
 
3ff7c26
-	touch_nr = buf[0];
3ff7c26
-	if (touch_nr > data->max_fingers) {
3ff7c26
+	if (buf[0] > data->max_fingers) {
3ff7c26
 		dev_warn(dev, "More touches reported then supported %d > %d\n",
3ff7c26
-			 touch_nr, data->max_fingers);
3ff7c26
-		touch_nr = data->max_fingers;
3ff7c26
+			 buf[0], data->max_fingers);
3ff7c26
+		buf[0] = data->max_fingers;
3ff7c26
 	}
3ff7c26
 
3ff7c26
+	touch_nr = 0;
3ff7c26
 	bufp = buf + SILEAD_POINT_DATA_LEN;
3ff7c26
-	for (i = 0; i < touch_nr; i++, bufp += SILEAD_POINT_DATA_LEN) {
3ff7c26
-		/* Bits 4-7 are the touch id */
3ff7c26
-		data->id[i] = (bufp[SILEAD_POINT_X_MSB_OFF] &
3ff7c26
-			       SILEAD_TOUCH_ID_MASK) >> 4;
3ff7c26
-		touchscreen_set_mt_pos(&data->pos[i], &data->prop,
3ff7c26
+	for (i = 0; i < buf[0]; i++, bufp += SILEAD_POINT_DATA_LEN) {
3ff7c26
+		softbutton = (bufp[SILEAD_POINT_Y_MSB_OFF] &
3ff7c26
+			      SILEAD_EXTRA_DATA_MASK) >> 4;
3ff7c26
+
3ff7c26
+		if (softbutton) {
3ff7c26
+			/*
3ff7c26
+			 * For now only respond to softbutton == 0x01, some
3ff7c26
+			 * tablets *without* a capacative button send 0x04
3ff7c26
+			 * when crossing the edges of the screen.
3ff7c26
+			 */
3ff7c26
+			if (softbutton == 0x01)
3ff7c26
+				softbutton_pressed = true;
3ff7c26
+
3ff7c26
+			continue;
3ff7c26
+		}
3ff7c26
+
3ff7c26
+		/*
3ff7c26
+		 * Bits 4-7 are the touch id, note not all models have
3ff7c26
+		 * hardware touch ids so atm we don't use these.
3ff7c26
+		 */
3ff7c26
+		data->id[touch_nr] = (bufp[SILEAD_POINT_X_MSB_OFF] &
3ff7c26
+				      SILEAD_EXTRA_DATA_MASK) >> 4;
3ff7c26
+		touchscreen_set_mt_pos(&data->pos[touch_nr], &data->prop,
3ff7c26
 			get_unaligned_le16(&bufp[SILEAD_POINT_X_OFF]) & 0xfff,
3ff7c26
 			get_unaligned_le16(&bufp[SILEAD_POINT_Y_OFF]) & 0xfff);
3ff7c26
+		touch_nr++;
3ff7c26
 	}
3ff7c26
 
3ff7c26
 	input_mt_assign_slots(input, data->slots, data->pos, touch_nr, 0);
3ff7c26
@@ -178,6 +200,7 @@ static void silead_ts_read_data(struct i2c_client *client)
3ff7c26
 	}
3ff7c26
 
3ff7c26
 	input_mt_sync_frame(input);
3ff7c26
+	input_report_key(input, KEY_LEFTMETA, softbutton_pressed);
3ff7c26
 	input_sync(input);
3ff7c26
 }
3ff7c26
 
3ff7c26
-- 
3ff7c26
2.13.0
3ff7c26