Skip to contentSkip to conversation

input - wacom_w8001: Support pen or touch only devices

PATCH Superseded Ping Cheng 3 participants 4 messages Dec 9, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ping Cheng

author
#0 lore raw

PATCH 1/2 input - wacom_w8001: Support pen or touch only devices

Not all penabled devices support touch. The same idea is true for touch devices. Setting up the devices according to the specific querying results.

---
 drivers/input/touchscreen/wacom_w8001.c |   39 ++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 8 deletions(-)
drivers/input/touchscreen/wacom_w8001.c +31 -8
index 361d00a..90b92e8 100644
@@ -37,6 +37,7 @@ MODULE_LICENSE("GPL");
 
 #define W8001_QUERY_PACKET	0x20
 
+#define W8001_CMD_STOP		'0'
 #define W8001_CMD_START		'1'
 #define W8001_CMD_QUERY		'*'
 #define W8001_CMD_TOUCHQUERY	'%'
@@ -279,24 +280,46 @@ static int w8001_setup(struct w8001 *w8001)
 	struct w8001_coord coord;
 	int error;
 
-	error = w8001_command(w8001, W8001_CMD_QUERY, true);
+	error = w8001_command(w8001, W8001_CMD_STOP, false);
 	if (error)
 		return error;
 
-	parse_data(w8001->response, &coord);
+	mdelay(250);	/* wait 250ms before querying the device */
 
-	input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
-	input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
-	input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
-	input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
-	input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+	/* penabled? */
+	error = w8001_command(w8001, W8001_CMD_QUERY, true);
+	if (!error) {
+		dev->keybit[BIT_WORD(BTN_TOOL_PEN)] |= BIT_MASK(BTN_TOOL_PEN);
+		dev->keybit[BIT_WORD(BTN_TOOL_RUBBER)] |= BIT_MASK(BTN_TOOL_RUBBER);
+		dev->keybit[BIT_WORD(BTN_STYLUS)] |= BIT_MASK(BTN_STYLUS);
+		dev->keybit[BIT_WORD(BTN_STYLUS2)] |= BIT_MASK(BTN_STYLUS2);
+		parse_data(w8001->response, &coord);
+
+		input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
+		input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
+		input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
+		if (coord.tilt_x && coord.tilt_y)
+		{
+			input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
+			input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+		}
+	}
 
+	/* touch enabled? */
 	error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
-	if (!error) {
+
+	/* Some non-touch devices may reply to the touch query. But their
+	 * second byte is empty, which indicates touch is not supported.
+	 */
+	if (!error && w8001->response[1]) {
 		struct w8001_touch_query touch;
 
 		parse_touchquery(w8001->response, &touch);
 
+		input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
+		input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
+		dev->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
+
 		switch (touch.sensor_id) {
 		case 0:
 		case 2:
Signature · 1 line
1.7.2.3
maintainer
#1 lore raw

Hi Ping,

Quoted 22 lines · Ping Cheng

Not all penabled devices support touch. The same idea is true for touch devices. Setting up the devices according to the specific querying results.

---
 drivers/input/touchscreen/wacom_w8001.c |   39 ++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 8 deletions(-)
drivers/input/touchscreen/wacom_w8001.c +1 -0
index 361d00a..90b92e8 100644
@@ -37,6 +37,7 @@ MODULE_LICENSE("GPL");
 
 #define W8001_QUERY_PACKET	0x20
 
+#define W8001_CMD_STOP		'0'
 #define W8001_CMD_START		'1'
 #define W8001_CMD_QUERY		'*'
 #define W8001_CMD_TOUCHQUERY	'%'

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 283

Quoted 5 lines
drivers/input/touchscreen/wacom_w8001.c +1 -1
@@ -279,24 +280,46 @@ static int w8001_setup(struct w8001 *w8001)
 	struct w8001_coord coord;
 	int error;
 
-	error = w8001_command(w8001, W8001_CMD_QUERY, true);
+	error = w8001_command(w8001, W8001_CMD_STOP, false);

Isn't there any response from the device to W8001_CMD_STOP?

Quoted 8 lines
drivers/input/touchscreen/wacom_w8001.c +1 -3
 	if (error)
 		return error;
 
-	parse_data(w8001->response, &coord);
+	mdelay(250);	/* wait 250ms before querying the device */
 
-	input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
-	input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 295

Quoted 10 lines
drivers/input/touchscreen/wacom_w8001.c +7 -3
-	input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
-	input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
-	input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+	/* penabled? */
+	error = w8001_command(w8001, W8001_CMD_QUERY, true);
+	if (!error) {
+		dev->keybit[BIT_WORD(BTN_TOOL_PEN)] |= BIT_MASK(BTN_TOOL_PEN);
+		dev->keybit[BIT_WORD(BTN_TOOL_RUBBER)] |= BIT_MASK(BTN_TOOL_RUBBER);
+		dev->keybit[BIT_WORD(BTN_STYLUS)] |= BIT_MASK(BTN_STYLUS);
+		dev->keybit[BIT_WORD(BTN_STYLUS2)] |= BIT_MASK(BTN_STYLUS2);

Could we start switching to __set_bit(BTN_TOOL_PEN, dev->keybit) style? The original way was somewhat OK when setting several buttons at once but I feel __set_bit() form is much safer.

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 302

Quoted 7 lines
drivers/input/touchscreen/wacom_w8001.c +7 -0
+		parse_data(w8001->response, &coord);
+
+		input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
+		input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
+		input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
+		if (coord.tilt_x && coord.tilt_y)
+		{

Formatting: opening brace goes on the same as the statement.

Quoted 27 lines
drivers/input/touchscreen/wacom_w8001.c +14 -1
+			input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
+			input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+		}
+	}
 
+	/* touch enabled? */
 	error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
-	if (!error) {
+
+	/* Some non-touch devices may reply to the touch query. But their
+	 * second byte is empty, which indicates touch is not supported.
+	 */
+	if (!error && w8001->response[1]) {
 		struct w8001_touch_query touch;
 
 		parse_touchquery(w8001->response, &touch);
 
+		input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
+		input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
+		dev->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
+
 		switch (touch.sensor_id) {
 		case 0:
 		case 2:
Signature · 1 line
1.7.2.3

Thanks.

Signature · 1 line
Dmitry
author
#2 lore raw
Quoted 28 lines · Dmitry Torokhov

Hi Ping,

Quoted 25 lines · Ping Cheng

Not all penabled devices support touch. The same idea is true for touch devices. Setting up the devices according to the specific querying results.

---
 drivers/input/touchscreen/wacom_w8001.c |   39 ++++++++++++++++++++++++------

 1 files changed, 31 insertions(+), 8 deletions(-)
drivers/input/touchscreen/wacom_w8001.c +1 -0
index 361d00a..90b92e8 100644
@@ -37,6 +37,7 @@ MODULE_LICENSE("GPL");
 
  #define W8001_QUERY_PACKET   0x20
 
+#define W8001_CMD_STOP               '0'
  #define W8001_CMD_START              '1'
  #define W8001_CMD_QUERY              '*'
  #define W8001_CMD_TOUCHQUERY '%'
@@ -279,24 +280,46 @@ static int w8001_setup(struct w8001 *w8001)
       struct w8001_coord coord;
       int error;
 
Quoted 4 lines

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 283

Quoted 2 lines
drivers/input/touchscreen/wacom_w8001.c +1 -1
-     error = w8001_command(w8001, W8001_CMD_QUERY, true);
+     error = w8001_command(w8001, W8001_CMD_STOP, false);

Isn't there any response from the device to W8001_CMD_STOP?

No, there is no response. We just tell the device to set ready for QUERY command.

Quoted 19 lines
Quoted 8 lines
drivers/input/touchscreen/wacom_w8001.c +1 -3
       if (error)
               return error;
 
-     parse_data(w8001->response, &coord);
+     mdelay(250);    /* wait 250ms before querying the device */
 
-     input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
-     input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 295

Quoted 10 lines
drivers/input/touchscreen/wacom_w8001.c +7 -3
-     input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
-     input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
-     input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+     /* penabled? */
+     error = w8001_command(w8001, W8001_CMD_QUERY, true);
+     if (!error) {
+             dev->keybit[BIT_WORD(BTN_TOOL_PEN)] |= BIT_MASK(BTN_TOOL_PEN);
+             dev->keybit[BIT_WORD(BTN_TOOL_RUBBER)] |= BIT_MASK(BTN_TOOL_RUBBER);
+             dev->keybit[BIT_WORD(BTN_STYLUS)] |= BIT_MASK(BTN_STYLUS);
+             dev->keybit[BIT_WORD(BTN_STYLUS2)] |= BIT_MASK(BTN_STYLUS2);
Quoted 1 line

Could we start switching to __set_bit(BTN_TOOL_PEN, dev->keybit) style?

Sure, I'll make a new patch. I was following the existing code style for consistency ......

Quoted 11 lines

The original way was somewhat OK when setting several buttons at once but I feel __set_bit() form is much safer.

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 302

Quoted 7 lines
drivers/input/touchscreen/wacom_w8001.c +7 -0
+             parse_data(w8001->response, &coord);
+
+             input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
+             input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
+             input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
+             if (coord.tilt_x && coord.tilt_y)
+             {
Quoted 1 line

Formatting: opening brace goes on the same as the statement.

Oops. I thought I've taken care of this already.

Thanks.

Ping

Quoted 30 lines
Quoted 22 lines
drivers/input/touchscreen/wacom_w8001.c +14 -1
+                     input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
+                     input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+             }
+     }
 
+     /* touch enabled? */
       error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
-     if (!error) {
+
+     /* Some non-touch devices may reply to the touch query. But their
+      * second byte is empty, which indicates touch is not supported.
+      */
+     if (!error && w8001->response[1]) {
               struct w8001_touch_query touch;
 
               parse_touchquery(w8001->response, &touch);
 
+             input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
+             input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
+             dev->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);
+
               switch (touch.sensor_id) {
Quoted 5 lines

              case 0:
              case 2:
--
1.7.2.3

Thanks.

Quoted 3 lines

--
Dmitry

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Ping Cheng

Hi Ping,

Quoted 62 lines · Ping Cheng

Not all penabled devices support touch. The same idea is true for touch devices. Setting up the devices according to the specific querying results.

---
 drivers/input/touchscreen/wacom_w8001.c |   39 ++++++++++++++++++++++++------

 1 files changed, 31 insertions(+), 8 deletions(-)
drivers/input/touchscreen/wacom_w8001.c +24 -8
index 361d00a..90b92e8 100644
@@ -37,6 +37,7 @@ MODULE_LICENSE("GPL");
 
  #define W8001_QUERY_PACKET     0x20
 
+#define W8001_CMD_STOP         '0'
  #define W8001_CMD_START                '1'
  #define W8001_CMD_QUERY                '*'
  #define W8001_CMD_TOUCHQUERY   '%'
@@ -279,24 +280,46 @@ static int w8001_setup(struct w8001 *w8001)
        struct w8001_coord coord;
        int error;
 
-       error = w8001_command(w8001, W8001_CMD_QUERY, true);
+       error = w8001_command(w8001, W8001_CMD_STOP, false);
        if (error)
                return error;
 
-       parse_data(w8001->response, &coord);
+       mdelay(250);    /* wait 250ms before querying the device */
 
-       input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
-       input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
-       input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
-       input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
-       input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+       /* penabled? */
+       error = w8001_command(w8001, W8001_CMD_QUERY, true);
+       if (!error) {
+               dev->keybit[BIT_WORD(BTN_TOOL_PEN)] |= BIT_MASK(BTN_TOOL_PEN);
+               dev->keybit[BIT_WORD(BTN_TOOL_RUBBER)] |= BIT_MASK(BTN_TOOL_RUBBER);
+               dev->keybit[BIT_WORD(BTN_STYLUS)] |= BIT_MASK(BTN_STYLUS);
+               dev->keybit[BIT_WORD(BTN_STYLUS2)] |= BIT_MASK(BTN_STYLUS2);
+               parse_data(w8001->response, &coord);
+
+               input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0);
+               input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0);
+               input_set_abs_params(dev, ABS_PRESSURE, 0, coord.pen_pressure, 0, 0);
+               if (coord.tilt_x && coord.tilt_y)
+               {
+                       input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0);
+                       input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0);
+               }
+       }
 
+       /* touch enabled? */
        error = w8001_command(w8001, W8001_CMD_TOUCHQUERY, true);
-       if (!error) {
+
+       /* Some non-touch devices may reply to the touch query. But their

drivers/input/touchscreen/wacom_w8001.c static int w8001_setup(struct w8001 *w8001) · line 321

Quoted 10 lines
drivers/input/touchscreen/wacom_w8001.c +6 -0
+        * second byte is empty, which indicates touch is not supported.
+        */
+       if (!error && w8001->response[1]) {
                struct w8001_touch_query touch;
 
                parse_touchquery(w8001->response, &touch);
 
+               input_set_abs_params(dev, ABS_X, 0, touch.x, 0, 0);
+               input_set_abs_params(dev, ABS_Y, 0, touch.y, 0, 0);
+               dev->keybit[BIT_WORD(BTN_TOOL_FINGER)] |= BIT_MASK(BTN_TOOL_FINGER);

Sorry for such basic questions: Is this an either/or thing? Is it either pen or touch device? Is the answer different for single vs. 2 touch devices? Doesn't this create a single input device?

If it can be combo on single input then it looks like it overrides its shared events. Probably the easiest solution is to normalize to single range... and I'd think that pen is higher resolution then touch so I'd put this logic before pen logic so pens resolution wins in combo case.

Shouldn't this also be disabling the MT events as well when touch isn't supported?

Chris

Quoted 7 lines
drivers/input/touchscreen/wacom_w8001.c +1 -0
+
                switch (touch.sensor_id) {

               case 0:
               case 2:
--
1.7.2.3

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html