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