All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function
@ 2015-12-01  1:13 Jason Gerecke
  2015-12-01  1:13 ` [PATCH 2/7] HID: wacom: Slim down wacom_intuos_pad processing Jason Gerecke
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

Begin slimming down the body of 'wacom_intuos_irq' by moving out its
largest block of code to a dedicated 'wacom_intuos_pad' function.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 482 +++++++++++++++++++++++++-----------------------
 1 file changed, 247 insertions(+), 235 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 8b29949..c611ea5 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -446,6 +446,249 @@ static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
 	}
 }
 
+static int wacom_intuos_pad(struct wacom_wac *wacom)
+{
+	struct wacom_features *features = &wacom->features;
+	unsigned char *data = wacom->data;
+	struct input_dev *input = wacom->pad_input;
+
+	/* pad packets. Works as a second tool and is always in prox */
+	if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
+	      data[0] == WACOM_REPORT_CINTIQPAD))
+		return 0;
+
+	if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
+		input_report_key(input, BTN_0, (data[2] & 0x01));
+		input_report_key(input, BTN_1, (data[3] & 0x01));
+		input_report_key(input, BTN_2, (data[3] & 0x02));
+		input_report_key(input, BTN_3, (data[3] & 0x04));
+		input_report_key(input, BTN_4, (data[3] & 0x08));
+		input_report_key(input, BTN_5, (data[3] & 0x10));
+		input_report_key(input, BTN_6, (data[3] & 0x20));
+		if (data[1] & 0x80) {
+			input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
+		} else {
+			/* Out of proximity, clear wheel value. */
+			input_report_abs(input, ABS_WHEEL, 0);
+		}
+		if (features->type != INTUOS4S) {
+			input_report_key(input, BTN_7, (data[3] & 0x40));
+			input_report_key(input, BTN_8, (data[3] & 0x80));
+		}
+		if (data[1] | (data[2] & 0x01) | data[3]) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	} else if (features->type == DTK) {
+		input_report_key(input, BTN_0, (data[6] & 0x01));
+		input_report_key(input, BTN_1, (data[6] & 0x02));
+		input_report_key(input, BTN_2, (data[6] & 0x04));
+		input_report_key(input, BTN_3, (data[6] & 0x08));
+		input_report_key(input, BTN_4, (data[6] & 0x10));
+		input_report_key(input, BTN_5, (data[6] & 0x20));
+		if (data[6] & 0x3f) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	} else if (features->type == WACOM_13HD) {
+		input_report_key(input, BTN_0, (data[3] & 0x01));
+		input_report_key(input, BTN_1, (data[4] & 0x01));
+		input_report_key(input, BTN_2, (data[4] & 0x02));
+		input_report_key(input, BTN_3, (data[4] & 0x04));
+		input_report_key(input, BTN_4, (data[4] & 0x08));
+		input_report_key(input, BTN_5, (data[4] & 0x10));
+		input_report_key(input, BTN_6, (data[4] & 0x20));
+		input_report_key(input, BTN_7, (data[4] & 0x40));
+		input_report_key(input, BTN_8, (data[4] & 0x80));
+		if ((data[3] & 0x01) | data[4]) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	} else if (features->type == WACOM_24HD) {
+		input_report_key(input, BTN_0, (data[6] & 0x01));
+		input_report_key(input, BTN_1, (data[6] & 0x02));
+		input_report_key(input, BTN_2, (data[6] & 0x04));
+		input_report_key(input, BTN_3, (data[6] & 0x08));
+		input_report_key(input, BTN_4, (data[6] & 0x10));
+		input_report_key(input, BTN_5, (data[6] & 0x20));
+		input_report_key(input, BTN_6, (data[6] & 0x40));
+		input_report_key(input, BTN_7, (data[6] & 0x80));
+		input_report_key(input, BTN_8, (data[8] & 0x01));
+		input_report_key(input, BTN_9, (data[8] & 0x02));
+		input_report_key(input, BTN_A, (data[8] & 0x04));
+		input_report_key(input, BTN_B, (data[8] & 0x08));
+		input_report_key(input, BTN_C, (data[8] & 0x10));
+		input_report_key(input, BTN_X, (data[8] & 0x20));
+		input_report_key(input, BTN_Y, (data[8] & 0x40));
+		input_report_key(input, BTN_Z, (data[8] & 0x80));
+
+		/*
+		 * Three "buttons" are available on the 24HD which are
+		 * physically implemented as a touchstrip. Each button
+		 * is approximately 3 bits wide with a 2 bit spacing.
+		 * The raw touchstrip bits are stored at:
+		 *    ((data[3] & 0x1f) << 8) | data[4])
+		 */
+		input_report_key(input, KEY_PROG1, data[4] & 0x07);
+		input_report_key(input, KEY_PROG2, data[4] & 0xE0);
+		input_report_key(input, KEY_PROG3, data[3] & 0x1C);
+
+		if (data[1] & 0x80) {
+			input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
+		} else {
+			/* Out of proximity, clear wheel value. */
+			input_report_abs(input, ABS_WHEEL, 0);
+		}
+
+		if (data[2] & 0x80) {
+			input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
+		} else {
+			/* Out of proximity, clear second wheel value. */
+			input_report_abs(input, ABS_THROTTLE, 0);
+		}
+
+		if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	} else if (features->type == WACOM_27QHD) {
+		input_report_key(input, KEY_PROG1, data[2] & 0x01);
+		input_report_key(input, KEY_PROG2, data[2] & 0x02);
+		input_report_key(input, KEY_PROG3, data[2] & 0x04);
+
+		input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
+		input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
+		input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
+		if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	} else if (features->type == CINTIQ_HYBRID) {
+		/*
+		 * Do not send hardware buttons under Android. They
+		 * are already sent to the system through GPIO (and
+		 * have different meaning).
+		 */
+		input_report_key(input, BTN_1, (data[4] & 0x01));
+		input_report_key(input, BTN_2, (data[4] & 0x02));
+		input_report_key(input, BTN_3, (data[4] & 0x04));
+		input_report_key(input, BTN_4, (data[4] & 0x08));
+
+		input_report_key(input, BTN_5, (data[4] & 0x10));  /* Right  */
+		input_report_key(input, BTN_6, (data[4] & 0x20));  /* Up     */
+		input_report_key(input, BTN_7, (data[4] & 0x40));  /* Left   */
+		input_report_key(input, BTN_8, (data[4] & 0x80));  /* Down   */
+		input_report_key(input, BTN_0, (data[3] & 0x01));  /* Center */
+
+		if (data[4] | (data[3] & 0x01)) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+
+	} else if (features->type == CINTIQ_COMPANION_2) {
+		input_report_key(input, BTN_1, (data[1] & 0x02));
+		input_report_key(input, BTN_2, (data[2] & 0x01));
+		input_report_key(input, BTN_3, (data[2] & 0x02));
+		input_report_key(input, BTN_4, (data[2] & 0x04));
+		input_report_key(input, BTN_5, (data[2] & 0x08));
+		input_report_key(input, BTN_6, (data[1] & 0x04));
+
+		input_report_key(input, BTN_7, (data[2] & 0x10));  /* Right  */
+		input_report_key(input, BTN_8, (data[2] & 0x20));  /* Up	 */
+		input_report_key(input, BTN_9, (data[2] & 0x40));  /* Left   */
+		input_report_key(input, BTN_A, (data[2] & 0x80));  /* Down   */
+		input_report_key(input, BTN_0, (data[1] & 0x01));  /* Center */
+
+		if (data[2] | (data[1] & 0x07)) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+
+	} else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
+		int i;
+
+		/* Touch ring mode switch has no capacitive sensor */
+		input_report_key(input, BTN_0, (data[3] & 0x01));
+
+		/*
+		 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
+		 * addition to the mechanical switch. Switch data is
+		 * stored in data[4], capacitive data in data[5].
+		 */
+		for (i = 0; i < 8; i++)
+			input_report_key(input, BTN_1 + i, data[4] & (1 << i));
+
+		if (data[2] & 0x80) {
+			input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
+		} else {
+			/* Out of proximity, clear wheel value. */
+			input_report_abs(input, ABS_WHEEL, 0);
+		}
+
+		if (data[2] | (data[3] & 0x01) | data[4] | data[5]) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	} else {
+		if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
+			input_report_key(input, BTN_0, (data[5] & 0x01));
+			input_report_key(input, BTN_1, (data[6] & 0x01));
+			input_report_key(input, BTN_2, (data[6] & 0x02));
+			input_report_key(input, BTN_3, (data[6] & 0x04));
+			input_report_key(input, BTN_4, (data[6] & 0x08));
+			input_report_key(input, BTN_5, (data[6] & 0x10));
+			input_report_key(input, BTN_6, (data[6] & 0x20));
+			input_report_key(input, BTN_7, (data[6] & 0x40));
+			input_report_key(input, BTN_8, (data[6] & 0x80));
+			input_report_key(input, BTN_9, (data[7] & 0x01));
+			input_report_key(input, BTN_A, (data[8] & 0x01));
+			input_report_key(input, BTN_B, (data[8] & 0x02));
+			input_report_key(input, BTN_C, (data[8] & 0x04));
+			input_report_key(input, BTN_X, (data[8] & 0x08));
+			input_report_key(input, BTN_Y, (data[8] & 0x10));
+			input_report_key(input, BTN_Z, (data[8] & 0x20));
+			input_report_key(input, BTN_BASE, (data[8] & 0x40));
+			input_report_key(input, BTN_BASE2, (data[8] & 0x80));
+
+			if (features->type == WACOM_22HD) {
+				input_report_key(input, KEY_PROG1, data[9] & 0x01);
+				input_report_key(input, KEY_PROG2, data[9] & 0x02);
+				input_report_key(input, KEY_PROG3, data[9] & 0x04);
+			}
+		} else {
+			input_report_key(input, BTN_0, (data[5] & 0x01));
+			input_report_key(input, BTN_1, (data[5] & 0x02));
+			input_report_key(input, BTN_2, (data[5] & 0x04));
+			input_report_key(input, BTN_3, (data[5] & 0x08));
+			input_report_key(input, BTN_4, (data[6] & 0x01));
+			input_report_key(input, BTN_5, (data[6] & 0x02));
+			input_report_key(input, BTN_6, (data[6] & 0x04));
+			input_report_key(input, BTN_7, (data[6] & 0x08));
+			input_report_key(input, BTN_8, (data[5] & 0x10));
+			input_report_key(input, BTN_9, (data[6] & 0x10));
+		}
+		input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
+		input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
+
+		if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
+			data[2] | (data[3] & 0x1f) | data[4] | data[8] |
+			(data[7] & 0x01)) {
+			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
+		} else {
+			input_report_abs(input, ABS_MISC, 0);
+		}
+	}
+	return 1;
+}
+
 static int wacom_intuos_inout(struct wacom_wac *wacom)
 {
 	struct wacom_features *features = &wacom->features;
@@ -814,241 +1057,10 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
 	if (features->type == INTUOS)
 		idx = data[1] & 0x01;
 
-	/* pad packets. Works as a second tool and is always in prox */
-	if (data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
-	    data[0] == WACOM_REPORT_CINTIQPAD) {
-		input = wacom->pad_input;
-		if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
-			input_report_key(input, BTN_0, (data[2] & 0x01));
-			input_report_key(input, BTN_1, (data[3] & 0x01));
-			input_report_key(input, BTN_2, (data[3] & 0x02));
-			input_report_key(input, BTN_3, (data[3] & 0x04));
-			input_report_key(input, BTN_4, (data[3] & 0x08));
-			input_report_key(input, BTN_5, (data[3] & 0x10));
-			input_report_key(input, BTN_6, (data[3] & 0x20));
-			if (data[1] & 0x80) {
-				input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
-			} else {
-				/* Out of proximity, clear wheel value. */
-				input_report_abs(input, ABS_WHEEL, 0);
-			}
-			if (features->type != INTUOS4S) {
-				input_report_key(input, BTN_7, (data[3] & 0x40));
-				input_report_key(input, BTN_8, (data[3] & 0x80));
-			}
-			if (data[1] | (data[2] & 0x01) | data[3]) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		} else if (features->type == DTK) {
-			input_report_key(input, BTN_0, (data[6] & 0x01));
-			input_report_key(input, BTN_1, (data[6] & 0x02));
-			input_report_key(input, BTN_2, (data[6] & 0x04));
-			input_report_key(input, BTN_3, (data[6] & 0x08));
-			input_report_key(input, BTN_4, (data[6] & 0x10));
-			input_report_key(input, BTN_5, (data[6] & 0x20));
-			if (data[6] & 0x3f) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		} else if (features->type == WACOM_13HD) {
-			input_report_key(input, BTN_0, (data[3] & 0x01));
-			input_report_key(input, BTN_1, (data[4] & 0x01));
-			input_report_key(input, BTN_2, (data[4] & 0x02));
-			input_report_key(input, BTN_3, (data[4] & 0x04));
-			input_report_key(input, BTN_4, (data[4] & 0x08));
-			input_report_key(input, BTN_5, (data[4] & 0x10));
-			input_report_key(input, BTN_6, (data[4] & 0x20));
-			input_report_key(input, BTN_7, (data[4] & 0x40));
-			input_report_key(input, BTN_8, (data[4] & 0x80));
-			if ((data[3] & 0x01) | data[4]) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		} else if (features->type == WACOM_24HD) {
-			input_report_key(input, BTN_0, (data[6] & 0x01));
-			input_report_key(input, BTN_1, (data[6] & 0x02));
-			input_report_key(input, BTN_2, (data[6] & 0x04));
-			input_report_key(input, BTN_3, (data[6] & 0x08));
-			input_report_key(input, BTN_4, (data[6] & 0x10));
-			input_report_key(input, BTN_5, (data[6] & 0x20));
-			input_report_key(input, BTN_6, (data[6] & 0x40));
-			input_report_key(input, BTN_7, (data[6] & 0x80));
-			input_report_key(input, BTN_8, (data[8] & 0x01));
-			input_report_key(input, BTN_9, (data[8] & 0x02));
-			input_report_key(input, BTN_A, (data[8] & 0x04));
-			input_report_key(input, BTN_B, (data[8] & 0x08));
-			input_report_key(input, BTN_C, (data[8] & 0x10));
-			input_report_key(input, BTN_X, (data[8] & 0x20));
-			input_report_key(input, BTN_Y, (data[8] & 0x40));
-			input_report_key(input, BTN_Z, (data[8] & 0x80));
-
-			/*
-			 * Three "buttons" are available on the 24HD which are
-			 * physically implemented as a touchstrip. Each button
-			 * is approximately 3 bits wide with a 2 bit spacing.
-			 * The raw touchstrip bits are stored at:
-			 *    ((data[3] & 0x1f) << 8) | data[4])
-			 */
-			input_report_key(input, KEY_PROG1, data[4] & 0x07);
-			input_report_key(input, KEY_PROG2, data[4] & 0xE0);
-			input_report_key(input, KEY_PROG3, data[3] & 0x1C);
-
-			if (data[1] & 0x80) {
-				input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
-			} else {
-				/* Out of proximity, clear wheel value. */
-				input_report_abs(input, ABS_WHEEL, 0);
-			}
-
-			if (data[2] & 0x80) {
-				input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
-			} else {
-				/* Out of proximity, clear second wheel value. */
-				input_report_abs(input, ABS_THROTTLE, 0);
-			}
-
-			if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		} else if (features->type == WACOM_27QHD) {
-			input_report_key(input, KEY_PROG1, data[2] & 0x01);
-			input_report_key(input, KEY_PROG2, data[2] & 0x02);
-			input_report_key(input, KEY_PROG3, data[2] & 0x04);
-
-			input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
-			input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
-			input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
-			if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		} else if (features->type == CINTIQ_HYBRID) {
-			/*
-			 * Do not send hardware buttons under Android. They
-			 * are already sent to the system through GPIO (and
-			 * have different meaning).
-			 */
-			input_report_key(input, BTN_1, (data[4] & 0x01));
-			input_report_key(input, BTN_2, (data[4] & 0x02));
-			input_report_key(input, BTN_3, (data[4] & 0x04));
-			input_report_key(input, BTN_4, (data[4] & 0x08));
-
-			input_report_key(input, BTN_5, (data[4] & 0x10));  /* Right  */
-			input_report_key(input, BTN_6, (data[4] & 0x20));  /* Up     */
-			input_report_key(input, BTN_7, (data[4] & 0x40));  /* Left   */
-			input_report_key(input, BTN_8, (data[4] & 0x80));  /* Down   */
-			input_report_key(input, BTN_0, (data[3] & 0x01));  /* Center */
-
-			if (data[4] | (data[3] & 0x01)) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-
-		} else if (features->type == CINTIQ_COMPANION_2) {
-			input_report_key(input, BTN_1, (data[1] & 0x02));
-			input_report_key(input, BTN_2, (data[2] & 0x01));
-			input_report_key(input, BTN_3, (data[2] & 0x02));
-			input_report_key(input, BTN_4, (data[2] & 0x04));
-			input_report_key(input, BTN_5, (data[2] & 0x08));
-			input_report_key(input, BTN_6, (data[1] & 0x04));
-
-			input_report_key(input, BTN_7, (data[2] & 0x10));  /* Right  */
-			input_report_key(input, BTN_8, (data[2] & 0x20));  /* Up	 */
-			input_report_key(input, BTN_9, (data[2] & 0x40));  /* Left   */
-			input_report_key(input, BTN_A, (data[2] & 0x80));  /* Down   */
-			input_report_key(input, BTN_0, (data[1] & 0x01));  /* Center */
-
-			if (data[2] | (data[1] & 0x07)) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-
-		} else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
-			int i;
-
-			/* Touch ring mode switch has no capacitive sensor */
-			input_report_key(input, BTN_0, (data[3] & 0x01));
-
-			/*
-			 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
-			 * addition to the mechanical switch. Switch data is
-			 * stored in data[4], capacitive data in data[5].
-			 */
-			for (i = 0; i < 8; i++)
-				input_report_key(input, BTN_1 + i, data[4] & (1 << i));
-
-			if (data[2] & 0x80) {
-				input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
-			} else {
-				/* Out of proximity, clear wheel value. */
-				input_report_abs(input, ABS_WHEEL, 0);
-			}
-
-			if (data[2] | (data[3] & 0x01) | data[4] | data[5]) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		} else {
-			if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
-				input_report_key(input, BTN_0, (data[5] & 0x01));
-				input_report_key(input, BTN_1, (data[6] & 0x01));
-				input_report_key(input, BTN_2, (data[6] & 0x02));
-				input_report_key(input, BTN_3, (data[6] & 0x04));
-				input_report_key(input, BTN_4, (data[6] & 0x08));
-				input_report_key(input, BTN_5, (data[6] & 0x10));
-				input_report_key(input, BTN_6, (data[6] & 0x20));
-				input_report_key(input, BTN_7, (data[6] & 0x40));
-				input_report_key(input, BTN_8, (data[6] & 0x80));
-				input_report_key(input, BTN_9, (data[7] & 0x01));
-				input_report_key(input, BTN_A, (data[8] & 0x01));
-				input_report_key(input, BTN_B, (data[8] & 0x02));
-				input_report_key(input, BTN_C, (data[8] & 0x04));
-				input_report_key(input, BTN_X, (data[8] & 0x08));
-				input_report_key(input, BTN_Y, (data[8] & 0x10));
-				input_report_key(input, BTN_Z, (data[8] & 0x20));
-				input_report_key(input, BTN_BASE, (data[8] & 0x40));
-				input_report_key(input, BTN_BASE2, (data[8] & 0x80));
-
-				if (features->type == WACOM_22HD) {
-					input_report_key(input, KEY_PROG1, data[9] & 0x01);
-					input_report_key(input, KEY_PROG2, data[9] & 0x02);
-					input_report_key(input, KEY_PROG3, data[9] & 0x04);
-				}
-			} else {
-				input_report_key(input, BTN_0, (data[5] & 0x01));
-				input_report_key(input, BTN_1, (data[5] & 0x02));
-				input_report_key(input, BTN_2, (data[5] & 0x04));
-				input_report_key(input, BTN_3, (data[5] & 0x08));
-				input_report_key(input, BTN_4, (data[6] & 0x01));
-				input_report_key(input, BTN_5, (data[6] & 0x02));
-				input_report_key(input, BTN_6, (data[6] & 0x04));
-				input_report_key(input, BTN_7, (data[6] & 0x08));
-				input_report_key(input, BTN_8, (data[5] & 0x10));
-				input_report_key(input, BTN_9, (data[6] & 0x10));
-			}
-			input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
-			input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
-
-			if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
-				data[2] | (data[3] & 0x1f) | data[4] | data[8] |
-				(data[7] & 0x01)) {
-				input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-			} else {
-				input_report_abs(input, ABS_MISC, 0);
-			}
-		}
-                return 1;
-	}
+	/* process pad events */
+	result = wacom_intuos_pad(wacom);
+	if (result)
+		return result;
 
 	/* process in/out prox events */
 	result = wacom_intuos_inout(wacom);
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/7] HID: wacom: Slim down wacom_intuos_pad processing
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
@ 2015-12-01  1:13 ` Jason Gerecke
  2015-12-01  1:13 ` [PATCH 3/7] HID: wacom: Centralize Intuos pen packet decoding Jason Gerecke
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

Seperate the function into two halves: first gather data from the packet,
next report all gathered data. The input subsystem should automatically
mute any events that aren't actually declared for the tablet at hand.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 277 +++++++++++++++---------------------------------
 1 file changed, 86 insertions(+), 191 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index c611ea5..ec1e13e 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -34,6 +34,9 @@
  */
 #define WACOM_CONTACT_AREA_SCALE 2607
 
+static void wacom_report_numbered_buttons(struct input_dev *input_dev,
+				int button_count, int mask);
+
 /*
  * Percent of battery capacity for Graphire.
  * 8th value means AC online and show 100% capacity.
@@ -451,6 +454,12 @@ static int wacom_intuos_pad(struct wacom_wac *wacom)
 	struct wacom_features *features = &wacom->features;
 	unsigned char *data = wacom->data;
 	struct input_dev *input = wacom->pad_input;
+	int i;
+	int buttons = 0, nbuttons = features->numbered_buttons;
+	int keys = 0, nkeys = 0;
+	int ring1 = 0, ring2 = 0;
+	int strip1 = 0, strip2 = 0;
+	bool prox = false;
 
 	/* pad packets. Works as a second tool and is always in prox */
 	if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
@@ -458,72 +467,16 @@ static int wacom_intuos_pad(struct wacom_wac *wacom)
 		return 0;
 
 	if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
-		input_report_key(input, BTN_0, (data[2] & 0x01));
-		input_report_key(input, BTN_1, (data[3] & 0x01));
-		input_report_key(input, BTN_2, (data[3] & 0x02));
-		input_report_key(input, BTN_3, (data[3] & 0x04));
-		input_report_key(input, BTN_4, (data[3] & 0x08));
-		input_report_key(input, BTN_5, (data[3] & 0x10));
-		input_report_key(input, BTN_6, (data[3] & 0x20));
-		if (data[1] & 0x80) {
-			input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
-		} else {
-			/* Out of proximity, clear wheel value. */
-			input_report_abs(input, ABS_WHEEL, 0);
-		}
-		if (features->type != INTUOS4S) {
-			input_report_key(input, BTN_7, (data[3] & 0x40));
-			input_report_key(input, BTN_8, (data[3] & 0x80));
-		}
-		if (data[1] | (data[2] & 0x01) | data[3]) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
+		buttons = (data[3] << 1) | (data[2] & 0x01);
+		ring1 = data[1];
 	} else if (features->type == DTK) {
-		input_report_key(input, BTN_0, (data[6] & 0x01));
-		input_report_key(input, BTN_1, (data[6] & 0x02));
-		input_report_key(input, BTN_2, (data[6] & 0x04));
-		input_report_key(input, BTN_3, (data[6] & 0x08));
-		input_report_key(input, BTN_4, (data[6] & 0x10));
-		input_report_key(input, BTN_5, (data[6] & 0x20));
-		if (data[6] & 0x3f) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
+		buttons = data[6];
 	} else if (features->type == WACOM_13HD) {
-		input_report_key(input, BTN_0, (data[3] & 0x01));
-		input_report_key(input, BTN_1, (data[4] & 0x01));
-		input_report_key(input, BTN_2, (data[4] & 0x02));
-		input_report_key(input, BTN_3, (data[4] & 0x04));
-		input_report_key(input, BTN_4, (data[4] & 0x08));
-		input_report_key(input, BTN_5, (data[4] & 0x10));
-		input_report_key(input, BTN_6, (data[4] & 0x20));
-		input_report_key(input, BTN_7, (data[4] & 0x40));
-		input_report_key(input, BTN_8, (data[4] & 0x80));
-		if ((data[3] & 0x01) | data[4]) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
+		buttons = (data[4] << 1) | (data[3] & 0x01);
 	} else if (features->type == WACOM_24HD) {
-		input_report_key(input, BTN_0, (data[6] & 0x01));
-		input_report_key(input, BTN_1, (data[6] & 0x02));
-		input_report_key(input, BTN_2, (data[6] & 0x04));
-		input_report_key(input, BTN_3, (data[6] & 0x08));
-		input_report_key(input, BTN_4, (data[6] & 0x10));
-		input_report_key(input, BTN_5, (data[6] & 0x20));
-		input_report_key(input, BTN_6, (data[6] & 0x40));
-		input_report_key(input, BTN_7, (data[6] & 0x80));
-		input_report_key(input, BTN_8, (data[8] & 0x01));
-		input_report_key(input, BTN_9, (data[8] & 0x02));
-		input_report_key(input, BTN_A, (data[8] & 0x04));
-		input_report_key(input, BTN_B, (data[8] & 0x08));
-		input_report_key(input, BTN_C, (data[8] & 0x10));
-		input_report_key(input, BTN_X, (data[8] & 0x20));
-		input_report_key(input, BTN_Y, (data[8] & 0x40));
-		input_report_key(input, BTN_Z, (data[8] & 0x80));
+		buttons = (data[8] << 8) | data[6];
+		ring1 = data[1];
+		ring2 = data[2];
 
 		/*
 		 * Three "buttons" are available on the 24HD which are
@@ -532,160 +485,89 @@ static int wacom_intuos_pad(struct wacom_wac *wacom)
 		 * The raw touchstrip bits are stored at:
 		 *    ((data[3] & 0x1f) << 8) | data[4])
 		 */
-		input_report_key(input, KEY_PROG1, data[4] & 0x07);
-		input_report_key(input, KEY_PROG2, data[4] & 0xE0);
-		input_report_key(input, KEY_PROG3, data[3] & 0x1C);
-
-		if (data[1] & 0x80) {
-			input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
-		} else {
-			/* Out of proximity, clear wheel value. */
-			input_report_abs(input, ABS_WHEEL, 0);
-		}
-
-		if (data[2] & 0x80) {
-			input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f));
-		} else {
-			/* Out of proximity, clear second wheel value. */
-			input_report_abs(input, ABS_THROTTLE, 0);
-		}
-
-		if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
+		nkeys = 3;
+		keys = ((data[3] & 0x1C) ? 1<<2 : 0) |
+		       ((data[4] & 0xE0) ? 1<<1 : 0) |
+		       ((data[4] & 0x07) ? 1<<0 : 0);
 	} else if (features->type == WACOM_27QHD) {
-		input_report_key(input, KEY_PROG1, data[2] & 0x01);
-		input_report_key(input, KEY_PROG2, data[2] & 0x02);
-		input_report_key(input, KEY_PROG3, data[2] & 0x04);
+		nkeys = 3;
+		keys = data[2] & 0x07;
 
 		input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4]));
 		input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6]));
 		input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8]));
-		if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
 	} else if (features->type == CINTIQ_HYBRID) {
 		/*
 		 * Do not send hardware buttons under Android. They
 		 * are already sent to the system through GPIO (and
 		 * have different meaning).
+		 *
+		 * d-pad right  -> data[4] & 0x10
+		 * d-pad up     -> data[4] & 0x20
+		 * d-pad left   -> data[4] & 0x40
+		 * d-pad down   -> data[4] & 0x80
+		 * d-pad center -> data[3] & 0x01
 		 */
-		input_report_key(input, BTN_1, (data[4] & 0x01));
-		input_report_key(input, BTN_2, (data[4] & 0x02));
-		input_report_key(input, BTN_3, (data[4] & 0x04));
-		input_report_key(input, BTN_4, (data[4] & 0x08));
-
-		input_report_key(input, BTN_5, (data[4] & 0x10));  /* Right  */
-		input_report_key(input, BTN_6, (data[4] & 0x20));  /* Up     */
-		input_report_key(input, BTN_7, (data[4] & 0x40));  /* Left   */
-		input_report_key(input, BTN_8, (data[4] & 0x80));  /* Down   */
-		input_report_key(input, BTN_0, (data[3] & 0x01));  /* Center */
-
-		if (data[4] | (data[3] & 0x01)) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
-
+		buttons = (data[4] << 1) | (data[3] & 0x01);
 	} else if (features->type == CINTIQ_COMPANION_2) {
-		input_report_key(input, BTN_1, (data[1] & 0x02));
-		input_report_key(input, BTN_2, (data[2] & 0x01));
-		input_report_key(input, BTN_3, (data[2] & 0x02));
-		input_report_key(input, BTN_4, (data[2] & 0x04));
-		input_report_key(input, BTN_5, (data[2] & 0x08));
-		input_report_key(input, BTN_6, (data[1] & 0x04));
-
-		input_report_key(input, BTN_7, (data[2] & 0x10));  /* Right  */
-		input_report_key(input, BTN_8, (data[2] & 0x20));  /* Up	 */
-		input_report_key(input, BTN_9, (data[2] & 0x40));  /* Left   */
-		input_report_key(input, BTN_A, (data[2] & 0x80));  /* Down   */
-		input_report_key(input, BTN_0, (data[1] & 0x01));  /* Center */
-
-		if (data[2] | (data[1] & 0x07)) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
-
+		/* d-pad right  -> data[4] & 0x10
+		 * d-pad up     -> data[4] & 0x20
+		 * d-pad left   -> data[4] & 0x40
+		 * d-pad down   -> data[4] & 0x80
+		 * d-pad center -> data[3] & 0x01
+		 */
+		buttons = ((data[2] & 0xF0) << 7) |
+		          ((data[1] & 0x04) << 6) |
+		          ((data[2] & 0x0F) << 2) |
+		          (data[1] & 0x03);
 	} else if (features->type >= INTUOS5S && features->type <= INTUOSPL) {
-		int i;
-
-		/* Touch ring mode switch has no capacitive sensor */
-		input_report_key(input, BTN_0, (data[3] & 0x01));
-
 		/*
 		 * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in
 		 * addition to the mechanical switch. Switch data is
 		 * stored in data[4], capacitive data in data[5].
+		 *
+		 * Touch ring mode switch (data[3]) has no capacitive sensor
 		 */
-		for (i = 0; i < 8; i++)
-			input_report_key(input, BTN_1 + i, data[4] & (1 << i));
-
-		if (data[2] & 0x80) {
-			input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f));
-		} else {
-			/* Out of proximity, clear wheel value. */
-			input_report_abs(input, ABS_WHEEL, 0);
-		}
-
-		if (data[2] | (data[3] & 0x01) | data[4] | data[5]) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
-		}
+		buttons = (data[4] << 1) | (data[3] & 0x01);
+		ring1 = data[2];
 	} else {
 		if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) {
-			input_report_key(input, BTN_0, (data[5] & 0x01));
-			input_report_key(input, BTN_1, (data[6] & 0x01));
-			input_report_key(input, BTN_2, (data[6] & 0x02));
-			input_report_key(input, BTN_3, (data[6] & 0x04));
-			input_report_key(input, BTN_4, (data[6] & 0x08));
-			input_report_key(input, BTN_5, (data[6] & 0x10));
-			input_report_key(input, BTN_6, (data[6] & 0x20));
-			input_report_key(input, BTN_7, (data[6] & 0x40));
-			input_report_key(input, BTN_8, (data[6] & 0x80));
-			input_report_key(input, BTN_9, (data[7] & 0x01));
-			input_report_key(input, BTN_A, (data[8] & 0x01));
-			input_report_key(input, BTN_B, (data[8] & 0x02));
-			input_report_key(input, BTN_C, (data[8] & 0x04));
-			input_report_key(input, BTN_X, (data[8] & 0x08));
-			input_report_key(input, BTN_Y, (data[8] & 0x10));
-			input_report_key(input, BTN_Z, (data[8] & 0x20));
-			input_report_key(input, BTN_BASE, (data[8] & 0x40));
-			input_report_key(input, BTN_BASE2, (data[8] & 0x80));
+			buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) |
+			          (data[6] << 1) | (data[5] & 0x01);
 
 			if (features->type == WACOM_22HD) {
-				input_report_key(input, KEY_PROG1, data[9] & 0x01);
-				input_report_key(input, KEY_PROG2, data[9] & 0x02);
-				input_report_key(input, KEY_PROG3, data[9] & 0x04);
+				nkeys = 3;
+				keys = data[9] & 0x07;
 			}
 		} else {
-			input_report_key(input, BTN_0, (data[5] & 0x01));
-			input_report_key(input, BTN_1, (data[5] & 0x02));
-			input_report_key(input, BTN_2, (data[5] & 0x04));
-			input_report_key(input, BTN_3, (data[5] & 0x08));
-			input_report_key(input, BTN_4, (data[6] & 0x01));
-			input_report_key(input, BTN_5, (data[6] & 0x02));
-			input_report_key(input, BTN_6, (data[6] & 0x04));
-			input_report_key(input, BTN_7, (data[6] & 0x08));
-			input_report_key(input, BTN_8, (data[5] & 0x10));
-			input_report_key(input, BTN_9, (data[6] & 0x10));
-		}
-		input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
-		input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
-
-		if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) |
-			data[2] | (data[3] & 0x1f) | data[4] | data[8] |
-			(data[7] & 0x01)) {
-			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
-		} else {
-			input_report_abs(input, ABS_MISC, 0);
+			buttons = ((data[6] & 0x10) << 10) |
+			          ((data[5] & 0x10) << 9)  |
+			          ((data[6] & 0x0F) << 4)  |
+			          (data[5] & 0x0F);
 		}
+		strip1 = (data[1] << 8) || data[2];
+		strip2 = (data[3] << 8) || data[4];
 	}
+
+	prox = (buttons & ~(~0 << nbuttons)) || (keys & ~(~0 << nkeys)) ||
+	       (ring1 & 0x80) || (ring2 & 0x80) || strip1 || strip2;
+
+	wacom_report_numbered_buttons(input, nbuttons, buttons);
+
+	for (i = 0; i < nkeys; i++)
+		input_report_key(input, KEY_PROG1 + i, keys & (1 << i));
+
+	input_report_abs(input, ABS_RX, strip1);
+	input_report_abs(input, ABS_RX, strip2);
+
+	input_report_abs(input, ABS_WHEEL,    ring1 & 0x7f ? ring1 : 0);
+	input_report_abs(input, ABS_THROTTLE, ring2 & 0x07 ? ring2 : 0);
+
+	input_report_key(input, wacom->tool[1], prox ? 1 : 0);
+	input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0);
+
+	input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
+
 	return 1;
 }
 
@@ -2818,6 +2700,19 @@ static void wacom_setup_numbered_buttons(struct input_dev *input_dev,
 		__set_bit(BTN_BASE + (i-16), input_dev->keybit);
 }
 
+static void wacom_report_numbered_buttons(struct input_dev *input_dev,
+				int button_count, int mask)
+{
+	int i;
+
+	for (i = 0; i < button_count && i < 10; i++)
+		input_report_key(input_dev, BTN_0 + i, mask & (1 << i));
+	for (i = 10; i < button_count && i < 16; i++)
+		input_report_key(input_dev, BTN_A + (i-10), mask & (1 << i));
+	for (i = 16; i < button_count && i < 18; i++)
+		input_report_key(input_dev, BTN_BASE + (i-16), mask & (1 << i));
+}
+
 int wacom_setup_pad_input_capabilities(struct input_dev *input_dev,
 				   struct wacom_wac *wacom_wac)
 {
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/7] HID: wacom: Centralize Intuos pen packet decoding
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
  2015-12-01  1:13 ` [PATCH 2/7] HID: wacom: Slim down wacom_intuos_pad processing Jason Gerecke
@ 2015-12-01  1:13 ` Jason Gerecke
  2015-12-01  1:13 ` [PATCH 4/7] HID: wacom: Replace magic masks and comparisons with switch cases Jason Gerecke
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

Continue to slim down 'wacom_intuos_irq' by moving all decoding and
reporting of pen packet data into the  'wacom_intuos_general' function.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 105 +++++++++++++++++++++++++-----------------------
 1 file changed, 54 insertions(+), 51 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index ec1e13e..e395688 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -880,13 +880,28 @@ static int wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len)
 	return 0;
 }
 
-static void wacom_intuos_general(struct wacom_wac *wacom)
+static int wacom_intuos_general(struct wacom_wac *wacom)
 {
 	struct wacom_features *features = &wacom->features;
 	unsigned char *data = wacom->data;
 	struct input_dev *input = wacom->pen_input;
+	int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
 	unsigned int t;
 
+	if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
+		data[0] != WACOM_REPORT_INTUOS_PEN)
+		return 0;
+
+	if (features->type >= INTUOS3S) {
+		input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
+		input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
+		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
+	} else {
+		input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
+		input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
+		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
+	}
+
 	/* general pen packet */
 	if ((data[1] & 0xb8) == 0xa0) {
 		t = (data[6] << 2) | ((data[7] >> 6) & 3);
@@ -912,55 +927,6 @@ static void wacom_intuos_general(struct wacom_wac *wacom)
 				 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
 		input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
 	}
-}
-
-static int wacom_intuos_irq(struct wacom_wac *wacom)
-{
-	struct wacom_features *features = &wacom->features;
-	unsigned char *data = wacom->data;
-	struct input_dev *input = wacom->pen_input;
-	unsigned int t;
-	int idx = 0, result;
-
-	if (data[0] != WACOM_REPORT_PENABLED &&
-	    data[0] != WACOM_REPORT_INTUOSREAD &&
-	    data[0] != WACOM_REPORT_INTUOSWRITE &&
-	    data[0] != WACOM_REPORT_INTUOSPAD &&
-	    data[0] != WACOM_REPORT_INTUOS_PEN &&
-	    data[0] != WACOM_REPORT_CINTIQ &&
-	    data[0] != WACOM_REPORT_CINTIQPAD &&
-	    data[0] != WACOM_REPORT_INTUOS5PAD) {
-		dev_dbg(input->dev.parent,
-			"%s: received unknown report #%d\n", __func__, data[0]);
-                return 0;
-	}
-
-	/* tool number */
-	if (features->type == INTUOS)
-		idx = data[1] & 0x01;
-
-	/* process pad events */
-	result = wacom_intuos_pad(wacom);
-	if (result)
-		return result;
-
-	/* process in/out prox events */
-	result = wacom_intuos_inout(wacom);
-	if (result)
-                return result - 1;
-
-	if (features->type >= INTUOS3S) {
-		input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
-		input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
-		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
-	} else {
-		input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
-		input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
-		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
-	}
-
-	/* process general packets */
-	wacom_intuos_general(wacom);
 
 	/* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
 	if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
@@ -1036,7 +1002,44 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
 	input_report_key(input, wacom->tool[idx], 1);
 	input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
 	wacom->reporting_data = true;
-	return 1;
+	return 2;
+}
+
+static int wacom_intuos_irq(struct wacom_wac *wacom)
+{
+	unsigned char *data = wacom->data;
+	struct input_dev *input = wacom->pen_input;
+	int result;
+
+	if (data[0] != WACOM_REPORT_PENABLED &&
+	    data[0] != WACOM_REPORT_INTUOSREAD &&
+	    data[0] != WACOM_REPORT_INTUOSWRITE &&
+	    data[0] != WACOM_REPORT_INTUOSPAD &&
+	    data[0] != WACOM_REPORT_INTUOS_PEN &&
+	    data[0] != WACOM_REPORT_CINTIQ &&
+	    data[0] != WACOM_REPORT_CINTIQPAD &&
+	    data[0] != WACOM_REPORT_INTUOS5PAD) {
+		dev_dbg(input->dev.parent,
+			"%s: received unknown report #%d\n", __func__, data[0]);
+                return 0;
+	}
+
+	/* process pad events */
+	result = wacom_intuos_pad(wacom);
+	if (result)
+		return result;
+
+	/* process in/out prox events */
+	result = wacom_intuos_inout(wacom);
+	if (result)
+		return result - 1;
+
+	/* process general packets */
+	result = wacom_intuos_general(wacom);
+	if (result)
+		return result - 1;
+
+	return 0;
 }
 
 static int int_dist(int x1, int y1, int x2, int y2)
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/7] HID: wacom: Replace magic masks and comparisons with switch cases
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
  2015-12-01  1:13 ` [PATCH 2/7] HID: wacom: Slim down wacom_intuos_pad processing Jason Gerecke
  2015-12-01  1:13 ` [PATCH 3/7] HID: wacom: Centralize Intuos pen packet decoding Jason Gerecke
@ 2015-12-01  1:13 ` Jason Gerecke
  2015-12-01  1:13 ` [PATCH 5/7] HID: wacom: Further clean up wacom_intuos_general packet decoder Jason Gerecke
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

Reasoning through the conditions under which a particular block of code
in 'wacom_intuos_general' will be reached is not at all easy due to the
sheer number of magic masks and comparisons. Remove these and replace
them with a switch statement over the various 'types' of packets that
will be encountered.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 79 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 49 insertions(+), 30 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index e395688..a426cb2 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -886,6 +886,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 	unsigned char *data = wacom->data;
 	struct input_dev *input = wacom->pen_input;
 	int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
+	unsigned char type = (data[1] >> 1) & 0x0F;
 	unsigned int t;
 
 	if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
@@ -902,8 +903,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
 	}
 
-	/* general pen packet */
-	if ((data[1] & 0xb8) == 0xa0) {
+	switch (type) {
+	case 0x00:
+	case 0x01:
+	case 0x02:
+	case 0x03:
+		/* general pen packet */
 		t = (data[6] << 2) | ((data[7] >> 6) & 3);
 		if (features->pressure_max == 2047) {
 			t = (t << 1) | (data[1] & 1);
@@ -917,36 +922,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 		input_report_key(input, BTN_STYLUS, data[1] & 2);
 		input_report_key(input, BTN_STYLUS2, data[1] & 4);
 		input_report_key(input, BTN_TOUCH, t > 10);
-	}
+		break;
 
-	/* airbrush second packet */
-	if ((data[1] & 0xbc) == 0xb4) {
+	case 0x0a:
+	case 0x0b:
+		/* airbrush second packet */
 		input_report_abs(input, ABS_WHEEL,
 				(data[6] << 2) | ((data[7] >> 6) & 3));
 		input_report_abs(input, ABS_TILT_X,
 				 (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
 		input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
-	}
+		break;
 
-	/* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
-	if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
-
-		if (data[1] & 0x02) {
-			/* Rotation packet */
-			if (features->type >= INTUOS3S) {
-				/* I3 marker pen rotation */
-				t = (data[6] << 3) | ((data[7] >> 5) & 7);
-				t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
-					((t-1) / 2 + 450)) : (450 - t / 2) ;
-				input_report_abs(input, ABS_Z, t);
-			} else {
-				/* 4D mouse rotation packet */
-				t = (data[6] << 3) | ((data[7] >> 5) & 7);
-				input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
-					((t - 1) / 2) : -t / 2);
-			}
+	case 0x05:
+	case 0x07:
+		/* Rotation packet */
+		if (features->type >= INTUOS3S) {
+			/* I3 marker pen rotation */
+			t = (data[6] << 3) | ((data[7] >> 5) & 7);
+			t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
+				((t-1) / 2 + 450)) : (450 - t / 2) ;
+			input_report_abs(input, ABS_Z, t);
+		} else {
+			/* 4D mouse rotation packet */
+			t = (data[6] << 3) | ((data[7] >> 5) & 7);
+			input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
+				((t - 1) / 2) : -t / 2);
+		}
+		break;
 
-		} else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
+	/* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
+	case 0x04:
+	case 0x06:
+	case 0x08:
+		if (features->type < INTUOS3S && type != 0x08) {
 			/* 4D mouse packet */
 			input_report_key(input, BTN_LEFT,   data[8] & 0x01);
 			input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -956,8 +965,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 			input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
 			t = (data[6] << 2) | ((data[7] >> 6) & 3);
 			input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
-
-		} else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
+		}
+		else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
 			/* I4 mouse */
 			if (features->type >= INTUOS4S && features->type <= INTUOSPL) {
 				input_report_key(input, BTN_LEFT,   data[6] & 0x01);
@@ -985,10 +994,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 					input_report_key(input, BTN_EXTRA,  data[8] & 0x20);
 				}
 			}
-		} else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
-				features->type == INTUOS4L || features->type == INTUOS5L ||
-				features->type == INTUOSPL) &&
-			   wacom->tool[idx] == BTN_TOOL_LENS) {
+		}
+		else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
+		          features->type == INTUOS4L || features->type == INTUOS5L ||
+		          features->type == INTUOSPL) &&
+		         wacom->tool[idx] == BTN_TOOL_LENS) {
 			/* Lens cursor packets */
 			input_report_key(input, BTN_LEFT,   data[8] & 0x01);
 			input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -996,6 +1006,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 			input_report_key(input, BTN_SIDE,   data[8] & 0x10);
 			input_report_key(input, BTN_EXTRA,  data[8] & 0x08);
 		}
+		break;
+
+	case 0x09:
+	case 0x0c:
+	case 0x0d:
+	case 0x0e:
+	case 0x0f:
+		/* unhandled */
+		break;
 	}
 
 	input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/7] HID: wacom: Further clean up wacom_intuos_general packet decoder
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
                   ` (2 preceding siblings ...)
  2015-12-01  1:13 ` [PATCH 4/7] HID: wacom: Replace magic masks and comparisons with switch cases Jason Gerecke
@ 2015-12-01  1:13 ` Jason Gerecke
  2015-12-01  1:13 ` [PATCH 6/7] HID: wacom: Clean up value reading Jason Gerecke
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

Continue re-organizing and trimming cases to make it easier to wrap
the brain around. A number of changes were made after consulting the
protocol spec and so don't necessarily follow from the code itself.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 87 +++++++++++++++++++++++--------------------------
 1 file changed, 41 insertions(+), 46 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index a426cb2..ce3afab 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -925,7 +925,6 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 		break;
 
 	case 0x0a:
-	case 0x0b:
 		/* airbrush second packet */
 		input_report_abs(input, ABS_WHEEL,
 				(data[6] << 2) | ((data[7] >> 6) & 3));
@@ -935,7 +934,6 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 		break;
 
 	case 0x05:
-	case 0x07:
 		/* Rotation packet */
 		if (features->type >= INTUOS3S) {
 			/* I3 marker pen rotation */
@@ -944,61 +942,56 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 				((t-1) / 2 + 450)) : (450 - t / 2) ;
 			input_report_abs(input, ABS_Z, t);
 		} else {
-			/* 4D mouse rotation packet */
+			/* 4D mouse 2nd packet */
 			t = (data[6] << 3) | ((data[7] >> 5) & 7);
 			input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
 				((t - 1) / 2) : -t / 2);
 		}
 		break;
 
-	/* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
 	case 0x04:
+		/* 4D mouse 1st packet */
+		input_report_key(input, BTN_LEFT,   data[8] & 0x01);
+		input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
+		input_report_key(input, BTN_RIGHT,  data[8] & 0x04);
+
+		input_report_key(input, BTN_SIDE,   data[8] & 0x20);
+		input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
+		t = (data[6] << 2) | ((data[7] >> 6) & 3);
+		input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
+		break;
+
 	case 0x06:
-	case 0x08:
-		if (features->type < INTUOS3S && type != 0x08) {
-			/* 4D mouse packet */
-			input_report_key(input, BTN_LEFT,   data[8] & 0x01);
-			input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
-			input_report_key(input, BTN_RIGHT,  data[8] & 0x04);
+		/* I4 mouse */
+		input_report_key(input, BTN_LEFT,   data[6] & 0x01);
+		input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
+		input_report_key(input, BTN_RIGHT,  data[6] & 0x04);
+		input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
+				 - ((data[7] & 0x40) >> 6));
+		input_report_key(input, BTN_SIDE,   data[6] & 0x08);
+		input_report_key(input, BTN_EXTRA,  data[6] & 0x10);
 
-			input_report_key(input, BTN_SIDE,   data[8] & 0x20);
-			input_report_key(input, BTN_EXTRA,  data[8] & 0x10);
-			t = (data[6] << 2) | ((data[7] >> 6) & 3);
-			input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
-		}
-		else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
-			/* I4 mouse */
-			if (features->type >= INTUOS4S && features->type <= INTUOSPL) {
-				input_report_key(input, BTN_LEFT,   data[6] & 0x01);
-				input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
-				input_report_key(input, BTN_RIGHT,  data[6] & 0x04);
-				input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
-						 - ((data[7] & 0x40) >> 6));
-				input_report_key(input, BTN_SIDE,   data[6] & 0x08);
-				input_report_key(input, BTN_EXTRA,  data[6] & 0x10);
-
-				input_report_abs(input, ABS_TILT_X,
-					(((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
-				input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
-			} else {
-				/* 2D mouse packet */
-				input_report_key(input, BTN_LEFT,   data[8] & 0x04);
-				input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
-				input_report_key(input, BTN_RIGHT,  data[8] & 0x10);
-				input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
-						 - ((data[8] & 0x02) >> 1));
-
-				/* I3 2D mouse side buttons */
-				if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
-					input_report_key(input, BTN_SIDE,   data[8] & 0x40);
-					input_report_key(input, BTN_EXTRA,  data[8] & 0x20);
-				}
+		input_report_abs(input, ABS_TILT_X,
+			(((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64);
+		input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64);
+		break;
+
+	case 0x08:
+		if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
+			/* 2D mouse packet */
+			input_report_key(input, BTN_LEFT,   data[8] & 0x04);
+			input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
+			input_report_key(input, BTN_RIGHT,  data[8] & 0x10);
+			input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
+					 - ((data[8] & 0x02) >> 1));
+
+			/* I3 2D mouse side buttons */
+			if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
+				input_report_key(input, BTN_SIDE,   data[8] & 0x40);
+				input_report_key(input, BTN_EXTRA,  data[8] & 0x20);
 			}
 		}
-		else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
-		          features->type == INTUOS4L || features->type == INTUOS5L ||
-		          features->type == INTUOSPL) &&
-		         wacom->tool[idx] == BTN_TOOL_LENS) {
+		else if (wacom->tool[idx] == BTN_TOOL_LENS) {
 			/* Lens cursor packets */
 			input_report_key(input, BTN_LEFT,   data[8] & 0x01);
 			input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
@@ -1008,7 +1001,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 		}
 		break;
 
+	case 0x07:
 	case 0x09:
+	case 0x0b:
 	case 0x0c:
 	case 0x0d:
 	case 0x0e:
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/7] HID: wacom: Clean up value reading
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
                   ` (3 preceding siblings ...)
  2015-12-01  1:13 ` [PATCH 5/7] HID: wacom: Further clean up wacom_intuos_general packet decoder Jason Gerecke
@ 2015-12-01  1:13 ` Jason Gerecke
  2015-12-01  1:13 ` [PATCH 7/7] HID: wacom: Rename wacom ID report ID macros Jason Gerecke
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

Make the logic for reading X, Y, distance, and pressure a bit more
clear. An additional bit was stuffed into the packet format many
models back, and /most/ devices in use will use it. If we happen
to be dealing with a particularly old tablet, just shift it off
the end to pretend we never read it.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index ce3afab..0008650 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -887,21 +887,23 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 	struct input_dev *input = wacom->pen_input;
 	int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0;
 	unsigned char type = (data[1] >> 1) & 0x0F;
-	unsigned int t;
+	unsigned int x, y, distance, t;
 
 	if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ &&
 		data[0] != WACOM_REPORT_INTUOS_PEN)
 		return 0;
 
-	if (features->type >= INTUOS3S) {
-		input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
-		input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
-		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
-	} else {
-		input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
-		input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
-		input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
+	x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1);
+	y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1);
+	distance = data[9] >> 2;
+	if (features->type < INTUOS3S) {
+		x >>= 1;
+		y >>= 1;
+		distance >>= 1;
 	}
+	input_report_abs(input, ABS_X, x);
+	input_report_abs(input, ABS_Y, y);
+	input_report_abs(input, ABS_DISTANCE, distance);
 
 	switch (type) {
 	case 0x00:
@@ -909,10 +911,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom)
 	case 0x02:
 	case 0x03:
 		/* general pen packet */
-		t = (data[6] << 2) | ((data[7] >> 6) & 3);
-		if (features->pressure_max == 2047) {
-			t = (t << 1) | (data[1] & 1);
-		}
+		t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
+		if (features->pressure_max < 2047)
+			t >>= 1;
 		input_report_abs(input, ABS_PRESSURE, t);
 		if (features->type != INTUOSHT2) {
 		    input_report_abs(input, ABS_TILT_X,
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/7] HID: wacom: Rename wacom ID report ID macros
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
                   ` (4 preceding siblings ...)
  2015-12-01  1:13 ` [PATCH 6/7] HID: wacom: Clean up value reading Jason Gerecke
@ 2015-12-01  1:13 ` Jason Gerecke
  2015-12-02 15:21 ` [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jiri Kosina
  2015-12-02 20:46 ` Jiri Kosina
  7 siblings, 0 replies; 10+ messages in thread
From: Jason Gerecke @ 2015-12-01  1:13 UTC (permalink / raw)
  To: linux-input
  Cc: Jiri Kosina, Ping Cheng, Aaron Skomra, Jason Gerecke, Jason Gerecke

"INTUOSREAD" and "INTUOSWRITE" are poorly named. These are report IDs
for pen ID (proximity) packets. It should be noted that the latter is
only used on Intuos/Intuos2 for a second stylus when DualTrack is in use.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
---
 drivers/hid/wacom_wac.c | 6 +++---
 drivers/hid/wacom_wac.h | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 0008650..3953416 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -443,7 +443,7 @@ static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
 	struct hid_report_enum *re;
 
 	re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]);
-	r = re->report_id_hash[WACOM_REPORT_INTUOSREAD];
+	r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1];
 	if (r) {
 		hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT);
 	}
@@ -1027,8 +1027,8 @@ static int wacom_intuos_irq(struct wacom_wac *wacom)
 	int result;
 
 	if (data[0] != WACOM_REPORT_PENABLED &&
-	    data[0] != WACOM_REPORT_INTUOSREAD &&
-	    data[0] != WACOM_REPORT_INTUOSWRITE &&
+	    data[0] != WACOM_REPORT_INTUOS_ID1 &&
+	    data[0] != WACOM_REPORT_INTUOS_ID2 &&
 	    data[0] != WACOM_REPORT_INTUOSPAD &&
 	    data[0] != WACOM_REPORT_INTUOS_PEN &&
 	    data[0] != WACOM_REPORT_CINTIQ &&
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index 877c24a..3f60192 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -47,8 +47,8 @@
 /* wacom data packet report IDs */
 #define WACOM_REPORT_PENABLED		2
 #define WACOM_REPORT_PENABLED_BT	3
-#define WACOM_REPORT_INTUOSREAD		5
-#define WACOM_REPORT_INTUOSWRITE	6
+#define WACOM_REPORT_INTUOS_ID1		5
+#define WACOM_REPORT_INTUOS_ID2		6
 #define WACOM_REPORT_INTUOSPAD		12
 #define WACOM_REPORT_INTUOS5PAD		3
 #define WACOM_REPORT_DTUSPAD		21
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
                   ` (5 preceding siblings ...)
  2015-12-01  1:13 ` [PATCH 7/7] HID: wacom: Rename wacom ID report ID macros Jason Gerecke
@ 2015-12-02 15:21 ` Jiri Kosina
  2015-12-02 15:22   ` Jiri Kosina
  2015-12-02 20:46 ` Jiri Kosina
  7 siblings, 1 reply; 10+ messages in thread
From: Jiri Kosina @ 2015-12-02 15:21 UTC (permalink / raw)
  To: Jason Gerecke; +Cc: linux-input, Ping Cheng, Aaron Skomra, Jason Gerecke

On Mon, 30 Nov 2015, Jason Gerecke wrote:

> Begin slimming down the body of 'wacom_intuos_irq' by moving out its
> largest block of code to a dedicated 'wacom_intuos_pad' function.
> 
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> ---
>  drivers/hid/wacom_wac.c | 482 +++++++++++++++++++++++++-----------------------
>  1 file changed, 247 insertions(+), 235 deletions(-)
> 
> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 8b29949..c611ea5 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -446,6 +446,249 @@ static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac)
>  	}
>  }
>  
> +static int wacom_intuos_pad(struct wacom_wac *wacom)
> +{
> +	struct wacom_features *features = &wacom->features;
> +	unsigned char *data = wacom->data;
> +	struct input_dev *input = wacom->pad_input;
> +
> +	/* pad packets. Works as a second tool and is always in prox */
> +	if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD ||
> +	      data[0] == WACOM_REPORT_CINTIQPAD))
> +		return 0;
> +
> +	if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
> +		input_report_key(input, BTN_0, (data[2] & 0x01));
> +		input_report_key(input, BTN_1, (data[3] & 0x01));
> +		input_report_key(input, BTN_2, (data[3] & 0x02));
> +		input_report_key(input, BTN_3, (data[3] & 0x04));
> +		input_report_key(input, BTN_4, (data[3] & 0x08));
> +		input_report_key(input, BTN_5, (data[3] & 0x10));
> +		input_report_key(input, BTN_6, (data[3] & 0x20));
> +		if (data[1] & 0x80) {
> +			input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
> +		} else {
> +			/* Out of proximity, clear wheel value. */
> +			input_report_abs(input, ABS_WHEEL, 0);
> +		}
> +		if (features->type != INTUOS4S) {
> +			input_report_key(input, BTN_7, (data[3] & 0x40));
> +			input_report_key(input, BTN_8, (data[3] & 0x80));
> +		}
> +		if (data[1] | (data[2] & 0x01) | data[3]) {
> +			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
> +		} else {
> +			input_report_abs(input, ABS_MISC, 0);
> +		}
> +	} else if (features->type == DTK) {
> +		input_report_key(input, BTN_0, (data[6] & 0x01));
> +		input_report_key(input, BTN_1, (data[6] & 0x02));
> +		input_report_key(input, BTN_2, (data[6] & 0x04));
> +		input_report_key(input, BTN_3, (data[6] & 0x08));
> +		input_report_key(input, BTN_4, (data[6] & 0x10));
> +		input_report_key(input, BTN_5, (data[6] & 0x20));
> +		if (data[6] & 0x3f) {
> +			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
> +		} else {
> +			input_report_abs(input, ABS_MISC, 0);
> +		}
> +	} else if (features->type == WACOM_13HD) {
> +		input_report_key(input, BTN_0, (data[3] & 0x01));
> +		input_report_key(input, BTN_1, (data[4] & 0x01));
> +		input_report_key(input, BTN_2, (data[4] & 0x02));
> +		input_report_key(input, BTN_3, (data[4] & 0x04));
> +		input_report_key(input, BTN_4, (data[4] & 0x08));
> +		input_report_key(input, BTN_5, (data[4] & 0x10));
> +		input_report_key(input, BTN_6, (data[4] & 0x20));
> +		input_report_key(input, BTN_7, (data[4] & 0x40));
> +		input_report_key(input, BTN_8, (data[4] & 0x80));
> +		if ((data[3] & 0x01) | data[4]) {
> +			input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
> +		} else {
> +			input_report_abs(input, ABS_MISC, 0);
> +		}
> +	} else if (features->type == WACOM_24HD) {
> +		input_report_key(input, BTN_0, (data[6] & 0x01));
> +		input_report_key(input, BTN_1, (data[6] & 0x02));
> +		input_report_key(input, BTN_2, (data[6] & 0x04));
> +		input_report_key(input, BTN_3, (data[6] & 0x08));
> +		input_report_key(input, BTN_4, (data[6] & 0x10));
> +		input_report_key(input, BTN_5, (data[6] & 0x20));
> +		input_report_key(input, BTN_6, (data[6] & 0x40));
> +		input_report_key(input, BTN_7, (data[6] & 0x80));
> +		input_report_key(input, BTN_8, (data[8] & 0x01));
> +		input_report_key(input, BTN_9, (data[8] & 0x02));
> +		input_report_key(input, BTN_A, (data[8] & 0x04));
> +		input_report_key(input, BTN_B, (data[8] & 0x08));
> +		input_report_key(input, BTN_C, (data[8] & 0x10));
> +		input_report_key(input, BTN_X, (data[8] & 0x20));
> +		input_report_key(input, BTN_Y, (data[8] & 0x40));
> +		input_report_key(input, BTN_Z, (data[8] & 0x80));

I know that this code (and other instances of similar spaghetti) has been 
there before already and you are just moving it around, but isn't this the 
proper time to clean it up a bit?

Like change it to a for-loop that'd use BTN_ as an array index to compute 
the position in the data bitstream and call input_report_key()?

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function
  2015-12-02 15:21 ` [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jiri Kosina
@ 2015-12-02 15:22   ` Jiri Kosina
  0 siblings, 0 replies; 10+ messages in thread
From: Jiri Kosina @ 2015-12-02 15:22 UTC (permalink / raw)
  To: Jason Gerecke; +Cc: linux-input, Ping Cheng, Aaron Skomra, Jason Gerecke

On Wed, 2 Dec 2015, Jiri Kosina wrote:

> I know that this code (and other instances of similar spaghetti) has been 
> there before already and you are just moving it around, but isn't this the 
> proper time to clean it up a bit?
> 
> Like change it to a for-loop that'd use BTN_ as an array index to compute 
> the position in the data bitstream and call input_report_key()?

Okay, scratch that, I see now that this ugliness is being dealt with later 
in the series. Sorry for the noise.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function
  2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
                   ` (6 preceding siblings ...)
  2015-12-02 15:21 ` [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jiri Kosina
@ 2015-12-02 20:46 ` Jiri Kosina
  7 siblings, 0 replies; 10+ messages in thread
From: Jiri Kosina @ 2015-12-02 20:46 UTC (permalink / raw)
  To: Jason Gerecke; +Cc: linux-input, Ping Cheng, Aaron Skomra, Jason Gerecke

On Mon, 30 Nov 2015, Jason Gerecke wrote:

> Begin slimming down the body of 'wacom_intuos_irq' by moving out its
> largest block of code to a dedicated 'wacom_intuos_pad' function.
> 
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>

I really like the cleanups done by this patchset, thanks. I have applied 
it to for-4.5/wacom branch.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-12-02 20:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-01  1:13 [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jason Gerecke
2015-12-01  1:13 ` [PATCH 2/7] HID: wacom: Slim down wacom_intuos_pad processing Jason Gerecke
2015-12-01  1:13 ` [PATCH 3/7] HID: wacom: Centralize Intuos pen packet decoding Jason Gerecke
2015-12-01  1:13 ` [PATCH 4/7] HID: wacom: Replace magic masks and comparisons with switch cases Jason Gerecke
2015-12-01  1:13 ` [PATCH 5/7] HID: wacom: Further clean up wacom_intuos_general packet decoder Jason Gerecke
2015-12-01  1:13 ` [PATCH 6/7] HID: wacom: Clean up value reading Jason Gerecke
2015-12-01  1:13 ` [PATCH 7/7] HID: wacom: Rename wacom ID report ID macros Jason Gerecke
2015-12-02 15:21 ` [PATCH 1/7] HID: wacom: Move Intuos pad handling code into dedicated function Jiri Kosina
2015-12-02 15:22   ` Jiri Kosina
2015-12-02 20:46 ` Jiri Kosina

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.