aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/tablet/wacom_wac.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/tablet/wacom_wac.c')
-rw-r--r--drivers/input/tablet/wacom_wac.c1168
1 files changed, 630 insertions, 538 deletions
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 4a852d815c6..847fd0135bc 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -11,52 +11,58 @@
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 12 * (at your option) any later version.
13 */ 13 */
14#include "wacom.h" 14
15#include "wacom_wac.h" 15#include "wacom_wac.h"
16#include "wacom.h"
16 17
17static int wacom_penpartner_irq(struct wacom_wac *wacom, void *wcombo) 18static int wacom_penpartner_irq(struct wacom_wac *wacom)
18{ 19{
19 unsigned char *data = wacom->data; 20 unsigned char *data = wacom->data;
21 struct input_dev *input = wacom->input;
20 22
21 switch (data[0]) { 23 switch (data[0]) {
22 case 1: 24 case 1:
23 if (data[5] & 0x80) { 25 if (data[5] & 0x80) {
24 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 26 wacom->tool[0] = (data[5] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
25 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID; 27 wacom->id[0] = (data[5] & 0x20) ? ERASER_DEVICE_ID : STYLUS_DEVICE_ID;
26 wacom_report_key(wcombo, wacom->tool[0], 1); 28 input_report_key(input, wacom->tool[0], 1);
27 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */ 29 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
28 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1])); 30 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
29 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3])); 31 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
30 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127); 32 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
31 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -127)); 33 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -127));
32 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40)); 34 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
33 } else { 35 } else {
34 wacom_report_key(wcombo, wacom->tool[0], 0); 36 input_report_key(input, wacom->tool[0], 0);
35 wacom_report_abs(wcombo, ABS_MISC, 0); /* report tool id */ 37 input_report_abs(input, ABS_MISC, 0); /* report tool id */
36 wacom_report_abs(wcombo, ABS_PRESSURE, -1); 38 input_report_abs(input, ABS_PRESSURE, -1);
37 wacom_report_key(wcombo, BTN_TOUCH, 0); 39 input_report_key(input, BTN_TOUCH, 0);
38 } 40 }
39 break; 41 break;
40 case 2: 42
41 wacom_report_key(wcombo, BTN_TOOL_PEN, 1); 43 case 2:
42 wacom_report_abs(wcombo, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */ 44 input_report_key(input, BTN_TOOL_PEN, 1);
43 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1])); 45 input_report_abs(input, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
44 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3])); 46 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
45 wacom_report_abs(wcombo, ABS_PRESSURE, (signed char)data[6] + 127); 47 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
46 wacom_report_key(wcombo, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20)); 48 input_report_abs(input, ABS_PRESSURE, (signed char)data[6] + 127);
47 wacom_report_key(wcombo, BTN_STYLUS, (data[5] & 0x40)); 49 input_report_key(input, BTN_TOUCH, ((signed char)data[6] > -80) && !(data[5] & 0x20));
48 break; 50 input_report_key(input, BTN_STYLUS, (data[5] & 0x40));
49 default: 51 break;
50 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]); 52
51 return 0; 53 default:
54 printk(KERN_INFO "wacom_penpartner_irq: received unknown report #%d\n", data[0]);
55 return 0;
52 } 56 }
57
53 return 1; 58 return 1;
54} 59}
55 60
56static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo) 61static int wacom_pl_irq(struct wacom_wac *wacom)
57{ 62{
58 struct wacom_features *features = &wacom->features; 63 struct wacom_features *features = &wacom->features;
59 unsigned char *data = wacom->data; 64 unsigned char *data = wacom->data;
65 struct input_dev *input = wacom->input;
60 int prox, pressure; 66 int prox, pressure;
61 67
62 if (data[0] != WACOM_REPORT_PENABLED) { 68 if (data[0] != WACOM_REPORT_PENABLED) {
@@ -90,8 +96,8 @@ static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
90 /* was entered with stylus2 pressed */ 96 /* was entered with stylus2 pressed */
91 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) { 97 if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) {
92 /* report out proximity for previous tool */ 98 /* report out proximity for previous tool */
93 wacom_report_key(wcombo, wacom->tool[1], 0); 99 input_report_key(input, wacom->tool[1], 0);
94 wacom_input_sync(wcombo); 100 input_sync(input);
95 wacom->tool[1] = BTN_TOOL_PEN; 101 wacom->tool[1] = BTN_TOOL_PEN;
96 return 0; 102 return 0;
97 } 103 }
@@ -101,32 +107,33 @@ static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
101 wacom->tool[1] = BTN_TOOL_PEN; 107 wacom->tool[1] = BTN_TOOL_PEN;
102 wacom->id[0] = STYLUS_DEVICE_ID; 108 wacom->id[0] = STYLUS_DEVICE_ID;
103 } 109 }
104 wacom_report_key(wcombo, wacom->tool[1], prox); /* report in proximity for tool */ 110 input_report_key(input, wacom->tool[1], prox); /* report in proximity for tool */
105 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */ 111 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
106 wacom_report_abs(wcombo, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); 112 input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
107 wacom_report_abs(wcombo, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); 113 input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
108 wacom_report_abs(wcombo, ABS_PRESSURE, pressure); 114 input_report_abs(input, ABS_PRESSURE, pressure);
109 115
110 wacom_report_key(wcombo, BTN_TOUCH, data[4] & 0x08); 116 input_report_key(input, BTN_TOUCH, data[4] & 0x08);
111 wacom_report_key(wcombo, BTN_STYLUS, data[4] & 0x10); 117 input_report_key(input, BTN_STYLUS, data[4] & 0x10);
112 /* Only allow the stylus2 button to be reported for the pen tool. */ 118 /* Only allow the stylus2 button to be reported for the pen tool. */
113 wacom_report_key(wcombo, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20)); 119 input_report_key(input, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20));
114 } else { 120 } else {
115 /* report proximity-out of a (valid) tool */ 121 /* report proximity-out of a (valid) tool */
116 if (wacom->tool[1] != BTN_TOOL_RUBBER) { 122 if (wacom->tool[1] != BTN_TOOL_RUBBER) {
117 /* Unknown tool selected default to pen tool */ 123 /* Unknown tool selected default to pen tool */
118 wacom->tool[1] = BTN_TOOL_PEN; 124 wacom->tool[1] = BTN_TOOL_PEN;
119 } 125 }
120 wacom_report_key(wcombo, wacom->tool[1], prox); 126 input_report_key(input, wacom->tool[1], prox);
121 } 127 }
122 128
123 wacom->tool[0] = prox; /* Save proximity state */ 129 wacom->tool[0] = prox; /* Save proximity state */
124 return 1; 130 return 1;
125} 131}
126 132
127static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo) 133static int wacom_ptu_irq(struct wacom_wac *wacom)
128{ 134{
129 unsigned char *data = wacom->data; 135 unsigned char *data = wacom->data;
136 struct input_dev *input = wacom->input;
130 137
131 if (data[0] != WACOM_REPORT_PENABLED) { 138 if (data[0] != WACOM_REPORT_PENABLED) {
132 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]); 139 printk(KERN_INFO "wacom_ptu_irq: received unknown report #%d\n", data[0]);
@@ -134,40 +141,41 @@ static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
134 } 141 }
135 142
136 if (data[1] & 0x04) { 143 if (data[1] & 0x04) {
137 wacom_report_key(wcombo, BTN_TOOL_RUBBER, data[1] & 0x20); 144 input_report_key(input, BTN_TOOL_RUBBER, data[1] & 0x20);
138 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x08); 145 input_report_key(input, BTN_TOUCH, data[1] & 0x08);
139 wacom->id[0] = ERASER_DEVICE_ID; 146 wacom->id[0] = ERASER_DEVICE_ID;
140 } else { 147 } else {
141 wacom_report_key(wcombo, BTN_TOOL_PEN, data[1] & 0x20); 148 input_report_key(input, BTN_TOOL_PEN, data[1] & 0x20);
142 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01); 149 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
143 wacom->id[0] = STYLUS_DEVICE_ID; 150 wacom->id[0] = STYLUS_DEVICE_ID;
144 } 151 }
145 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */ 152 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
146 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2])); 153 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
147 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4])); 154 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
148 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6])); 155 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
149 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 156 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
150 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10); 157 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
151 return 1; 158 return 1;
152} 159}
153 160
154static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) 161static int wacom_graphire_irq(struct wacom_wac *wacom)
155{ 162{
156 struct wacom_features *features = &wacom->features; 163 struct wacom_features *features = &wacom->features;
157 unsigned char *data = wacom->data; 164 unsigned char *data = wacom->data;
158 int x, y, rw; 165 struct input_dev *input = wacom->input;
159 static int penData = 0; 166 int prox;
167 int rw = 0;
168 int retval = 0;
160 169
161 if (data[0] != WACOM_REPORT_PENABLED) { 170 if (data[0] != WACOM_REPORT_PENABLED) {
162 dbg("wacom_graphire_irq: received unknown report #%d", data[0]); 171 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
163 return 0; 172 goto exit;
164 } 173 }
165 174
166 if (data[1] & 0x80) { 175 prox = data[1] & 0x80;
167 /* in prox and not a pad data */ 176 if (prox || wacom->id[0]) {
168 penData = 1; 177 if (prox) {
169 178 switch ((data[1] >> 5) & 3) {
170 switch ((data[1] >> 5) & 3) {
171 179
172 case 0: /* Pen */ 180 case 0: /* Pen */
173 wacom->tool[0] = BTN_TOOL_PEN; 181 wacom->tool[0] = BTN_TOOL_PEN;
@@ -180,128 +188,89 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
180 break; 188 break;
181 189
182 case 2: /* Mouse with wheel */ 190 case 2: /* Mouse with wheel */
183 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04); 191 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
184 if (features->type == WACOM_G4 || features->type == WACOM_MO) {
185 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
186 wacom_report_rel(wcombo, REL_WHEEL, -rw);
187 } else
188 wacom_report_rel(wcombo, REL_WHEEL, -(signed char) data[6]);
189 /* fall through */ 192 /* fall through */
190 193
191 case 3: /* Mouse without wheel */ 194 case 3: /* Mouse without wheel */
192 wacom->tool[0] = BTN_TOOL_MOUSE; 195 wacom->tool[0] = BTN_TOOL_MOUSE;
193 wacom->id[0] = CURSOR_DEVICE_ID; 196 wacom->id[0] = CURSOR_DEVICE_ID;
194 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
195 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
196 if (features->type == WACOM_G4 || features->type == WACOM_MO)
197 wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f);
198 else
199 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
200 break; 197 break;
198 }
201 } 199 }
202 x = wacom_le16_to_cpu(&data[2]); 200 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
203 y = wacom_le16_to_cpu(&data[4]); 201 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
204 wacom_report_abs(wcombo, ABS_X, x);
205 wacom_report_abs(wcombo, ABS_Y, y);
206 if (wacom->tool[0] != BTN_TOOL_MOUSE) { 202 if (wacom->tool[0] != BTN_TOOL_MOUSE) {
207 wacom_report_abs(wcombo, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8)); 203 input_report_abs(input, ABS_PRESSURE, data[6] | ((data[7] & 0x01) << 8));
208 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01); 204 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
209 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 205 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 206 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
211 }
212 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
213 wacom_report_key(wcombo, wacom->tool[0], 1);
214 } else if (wacom->id[0]) {
215 wacom_report_abs(wcombo, ABS_X, 0);
216 wacom_report_abs(wcombo, ABS_Y, 0);
217 if (wacom->tool[0] == BTN_TOOL_MOUSE) {
218 wacom_report_key(wcombo, BTN_LEFT, 0);
219 wacom_report_key(wcombo, BTN_RIGHT, 0);
220 wacom_report_abs(wcombo, ABS_DISTANCE, 0);
221 } else { 207 } else {
222 wacom_report_abs(wcombo, ABS_PRESSURE, 0); 208 input_report_key(input, BTN_LEFT, data[1] & 0x01);
223 wacom_report_key(wcombo, BTN_TOUCH, 0); 209 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
224 wacom_report_key(wcombo, BTN_STYLUS, 0); 210 if (features->type == WACOM_G4 ||
225 wacom_report_key(wcombo, BTN_STYLUS2, 0); 211 features->type == WACOM_MO) {
212 input_report_abs(input, ABS_DISTANCE, data[6] & 0x3f);
213 rw = (signed)(data[7] & 0x04) - (data[7] & 0x03);
214 } else {
215 input_report_abs(input, ABS_DISTANCE, data[7] & 0x3f);
216 rw = -(signed)data[6];
217 }
218 input_report_rel(input, REL_WHEEL, rw);
226 } 219 }
227 wacom->id[0] = 0; 220
228 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 221 if (!prox)
229 wacom_report_key(wcombo, wacom->tool[0], 0); 222 wacom->id[0] = 0;
223 input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */
224 input_report_key(input, wacom->tool[0], prox);
225 input_sync(input); /* sync last event */
230 } 226 }
231 227
232 /* send pad data */ 228 /* send pad data */
233 switch (features->type) { 229 switch (features->type) {
234 case WACOM_G4: 230 case WACOM_G4:
235 if (data[7] & 0xf8) { 231 prox = data[7] & 0xf8;
236 if (penData) { 232 if (prox || wacom->id[1]) {
237 wacom_input_sync(wcombo); /* sync last event */
238 if (!wacom->id[0])
239 penData = 0;
240 }
241 wacom->id[1] = PAD_DEVICE_ID; 233 wacom->id[1] = PAD_DEVICE_ID;
242 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); 234 input_report_key(input, BTN_0, (data[7] & 0x40));
243 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80)); 235 input_report_key(input, BTN_4, (data[7] & 0x80));
244 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3); 236 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
245 wacom_report_rel(wcombo, REL_WHEEL, rw); 237 input_report_rel(input, REL_WHEEL, rw);
246 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 238 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
247 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]); 239 if (!prox)
248 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 240 wacom->id[1] = 0;
249 } else if (wacom->id[1]) { 241 input_report_abs(input, ABS_MISC, wacom->id[1]);
250 if (penData) { 242 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
251 wacom_input_sync(wcombo); /* sync last event */ 243 retval = 1;
252 if (!wacom->id[0])
253 penData = 0;
254 }
255 wacom->id[1] = 0;
256 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
257 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
258 wacom_report_rel(wcombo, REL_WHEEL, 0);
259 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
260 wacom_report_abs(wcombo, ABS_MISC, 0);
261 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
262 } 244 }
263 break; 245 break;
264 case WACOM_MO: 246
265 if ((data[7] & 0xf8) || (data[8] & 0xff)) { 247 case WACOM_MO:
266 if (penData) { 248 prox = (data[7] & 0xf8) || data[8];
267 wacom_input_sync(wcombo); /* sync last event */ 249 if (prox || wacom->id[1]) {
268 if (!wacom->id[0])
269 penData = 0;
270 }
271 wacom->id[1] = PAD_DEVICE_ID; 250 wacom->id[1] = PAD_DEVICE_ID;
272 wacom_report_key(wcombo, BTN_0, (data[7] & 0x08)); 251 input_report_key(input, BTN_0, (data[7] & 0x08));
273 wacom_report_key(wcombo, BTN_1, (data[7] & 0x20)); 252 input_report_key(input, BTN_1, (data[7] & 0x20));
274 wacom_report_key(wcombo, BTN_4, (data[7] & 0x10)); 253 input_report_key(input, BTN_4, (data[7] & 0x10));
275 wacom_report_key(wcombo, BTN_5, (data[7] & 0x40)); 254 input_report_key(input, BTN_5, (data[7] & 0x40));
276 wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f)); 255 input_report_abs(input, ABS_WHEEL, (data[8] & 0x7f));
277 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 256 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
278 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]); 257 if (!prox)
279 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 258 wacom->id[1] = 0;
280 } else if (wacom->id[1]) { 259 input_report_abs(input, ABS_MISC, wacom->id[1]);
281 if (penData) { 260 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
282 wacom_input_sync(wcombo); /* sync last event */
283 if (!wacom->id[0])
284 penData = 0;
285 }
286 wacom->id[1] = 0;
287 wacom_report_key(wcombo, BTN_0, (data[7] & 0x08));
288 wacom_report_key(wcombo, BTN_1, (data[7] & 0x20));
289 wacom_report_key(wcombo, BTN_4, (data[7] & 0x10));
290 wacom_report_key(wcombo, BTN_5, (data[7] & 0x40));
291 wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f));
292 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0);
293 wacom_report_abs(wcombo, ABS_MISC, 0);
294 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
295 } 261 }
262 retval = 1;
296 break; 263 break;
297 } 264 }
298 return 1; 265exit:
266 return retval;
299} 267}
300 268
301static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo) 269static int wacom_intuos_inout(struct wacom_wac *wacom)
302{ 270{
303 struct wacom_features *features = &wacom->features; 271 struct wacom_features *features = &wacom->features;
304 unsigned char *data = wacom->data; 272 unsigned char *data = wacom->data;
273 struct input_dev *input = wacom->input;
305 int idx = 0; 274 int idx = 0;
306 275
307 /* tool number */ 276 /* tool number */
@@ -316,64 +285,73 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
316 (data[6] << 4) + (data[7] >> 4); 285 (data[6] << 4) + (data[7] >> 4);
317 286
318 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4); 287 wacom->id[idx] = (data[2] << 4) | (data[3] >> 4);
288
319 switch (wacom->id[idx]) { 289 switch (wacom->id[idx]) {
320 case 0x812: /* Inking pen */ 290 case 0x812: /* Inking pen */
321 case 0x801: /* Intuos3 Inking pen */ 291 case 0x801: /* Intuos3 Inking pen */
322 case 0x20802: /* Intuos4 Classic Pen */ 292 case 0x20802: /* Intuos4 Classic Pen */
323 case 0x012: 293 case 0x012:
324 wacom->tool[idx] = BTN_TOOL_PENCIL; 294 wacom->tool[idx] = BTN_TOOL_PENCIL;
325 break; 295 break;
326 case 0x822: /* Pen */ 296
327 case 0x842: 297 case 0x822: /* Pen */
328 case 0x852: 298 case 0x842:
329 case 0x823: /* Intuos3 Grip Pen */ 299 case 0x852:
330 case 0x813: /* Intuos3 Classic Pen */ 300 case 0x823: /* Intuos3 Grip Pen */
331 case 0x885: /* Intuos3 Marker Pen */ 301 case 0x813: /* Intuos3 Classic Pen */
332 case 0x802: /* Intuos4 Grip Pen Eraser */ 302 case 0x885: /* Intuos3 Marker Pen */
333 case 0x804: /* Intuos4 Marker Pen */ 303 case 0x802: /* Intuos4 Grip Pen Eraser */
334 case 0x40802: /* Intuos4 Classic Pen */ 304 case 0x804: /* Intuos4 Marker Pen */
335 case 0x022: 305 case 0x40802: /* Intuos4 Classic Pen */
336 wacom->tool[idx] = BTN_TOOL_PEN; 306 case 0x022:
337 break; 307 wacom->tool[idx] = BTN_TOOL_PEN;
338 case 0x832: /* Stroke pen */ 308 break;
339 case 0x032: 309
340 wacom->tool[idx] = BTN_TOOL_BRUSH; 310 case 0x832: /* Stroke pen */
341 break; 311 case 0x032:
342 case 0x007: /* Mouse 4D and 2D */ 312 wacom->tool[idx] = BTN_TOOL_BRUSH;
343 case 0x09c: 313 break;
344 case 0x094: 314
345 case 0x017: /* Intuos3 2D Mouse */ 315 case 0x007: /* Mouse 4D and 2D */
346 case 0x806: /* Intuos4 Mouse */ 316 case 0x09c:
347 wacom->tool[idx] = BTN_TOOL_MOUSE; 317 case 0x094:
348 break; 318 case 0x017: /* Intuos3 2D Mouse */
349 case 0x096: /* Lens cursor */ 319 case 0x806: /* Intuos4 Mouse */
350 case 0x097: /* Intuos3 Lens cursor */ 320 wacom->tool[idx] = BTN_TOOL_MOUSE;
351 case 0x006: /* Intuos4 Lens cursor */ 321 break;
352 wacom->tool[idx] = BTN_TOOL_LENS; 322
353 break; 323 case 0x096: /* Lens cursor */
354 case 0x82a: /* Eraser */ 324 case 0x097: /* Intuos3 Lens cursor */
355 case 0x85a: 325 case 0x006: /* Intuos4 Lens cursor */
356 case 0x91a: 326 wacom->tool[idx] = BTN_TOOL_LENS;
357 case 0xd1a: 327 break;
358 case 0x0fa: 328
359 case 0x82b: /* Intuos3 Grip Pen Eraser */ 329 case 0x82a: /* Eraser */
360 case 0x81b: /* Intuos3 Classic Pen Eraser */ 330 case 0x85a:
361 case 0x91b: /* Intuos3 Airbrush Eraser */ 331 case 0x91a:
362 case 0x80c: /* Intuos4 Marker Pen Eraser */ 332 case 0xd1a:
363 case 0x80a: /* Intuos4 Grip Pen Eraser */ 333 case 0x0fa:
364 case 0x4080a: /* Intuos4 Classic Pen Eraser */ 334 case 0x82b: /* Intuos3 Grip Pen Eraser */
365 case 0x90a: /* Intuos4 Airbrush Eraser */ 335 case 0x81b: /* Intuos3 Classic Pen Eraser */
366 wacom->tool[idx] = BTN_TOOL_RUBBER; 336 case 0x91b: /* Intuos3 Airbrush Eraser */
367 break; 337 case 0x80c: /* Intuos4 Marker Pen Eraser */
368 case 0xd12: 338 case 0x80a: /* Intuos4 Grip Pen Eraser */
369 case 0x912: 339 case 0x4080a: /* Intuos4 Classic Pen Eraser */
370 case 0x112: 340 case 0x90a: /* Intuos4 Airbrush Eraser */
371 case 0x913: /* Intuos3 Airbrush */ 341 wacom->tool[idx] = BTN_TOOL_RUBBER;
372 case 0x902: /* Intuos4 Airbrush */ 342 break;
373 wacom->tool[idx] = BTN_TOOL_AIRBRUSH; 343
374 break; 344 case 0xd12:
375 default: /* Unknown tool */ 345 case 0x912:
376 wacom->tool[idx] = BTN_TOOL_PEN; 346 case 0x112:
347 case 0x913: /* Intuos3 Airbrush */
348 case 0x902: /* Intuos4 Airbrush */
349 wacom->tool[idx] = BTN_TOOL_AIRBRUSH;
350 break;
351
352 default: /* Unknown tool */
353 wacom->tool[idx] = BTN_TOOL_PEN;
354 break;
377 } 355 }
378 return 1; 356 return 1;
379 } 357 }
@@ -384,41 +362,42 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
384 * Reset all states otherwise we lose the initial states 362 * Reset all states otherwise we lose the initial states
385 * when in-prox next time 363 * when in-prox next time
386 */ 364 */
387 wacom_report_abs(wcombo, ABS_X, 0); 365 input_report_abs(input, ABS_X, 0);
388 wacom_report_abs(wcombo, ABS_Y, 0); 366 input_report_abs(input, ABS_Y, 0);
389 wacom_report_abs(wcombo, ABS_DISTANCE, 0); 367 input_report_abs(input, ABS_DISTANCE, 0);
390 wacom_report_abs(wcombo, ABS_TILT_X, 0); 368 input_report_abs(input, ABS_TILT_X, 0);
391 wacom_report_abs(wcombo, ABS_TILT_Y, 0); 369 input_report_abs(input, ABS_TILT_Y, 0);
392 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) { 370 if (wacom->tool[idx] >= BTN_TOOL_MOUSE) {
393 wacom_report_key(wcombo, BTN_LEFT, 0); 371 input_report_key(input, BTN_LEFT, 0);
394 wacom_report_key(wcombo, BTN_MIDDLE, 0); 372 input_report_key(input, BTN_MIDDLE, 0);
395 wacom_report_key(wcombo, BTN_RIGHT, 0); 373 input_report_key(input, BTN_RIGHT, 0);
396 wacom_report_key(wcombo, BTN_SIDE, 0); 374 input_report_key(input, BTN_SIDE, 0);
397 wacom_report_key(wcombo, BTN_EXTRA, 0); 375 input_report_key(input, BTN_EXTRA, 0);
398 wacom_report_abs(wcombo, ABS_THROTTLE, 0); 376 input_report_abs(input, ABS_THROTTLE, 0);
399 wacom_report_abs(wcombo, ABS_RZ, 0); 377 input_report_abs(input, ABS_RZ, 0);
400 } else { 378 } else {
401 wacom_report_abs(wcombo, ABS_PRESSURE, 0); 379 input_report_abs(input, ABS_PRESSURE, 0);
402 wacom_report_key(wcombo, BTN_STYLUS, 0); 380 input_report_key(input, BTN_STYLUS, 0);
403 wacom_report_key(wcombo, BTN_STYLUS2, 0); 381 input_report_key(input, BTN_STYLUS2, 0);
404 wacom_report_key(wcombo, BTN_TOUCH, 0); 382 input_report_key(input, BTN_TOUCH, 0);
405 wacom_report_abs(wcombo, ABS_WHEEL, 0); 383 input_report_abs(input, ABS_WHEEL, 0);
406 if (features->type >= INTUOS3S) 384 if (features->type >= INTUOS3S)
407 wacom_report_abs(wcombo, ABS_Z, 0); 385 input_report_abs(input, ABS_Z, 0);
408 } 386 }
409 wacom_report_key(wcombo, wacom->tool[idx], 0); 387 input_report_key(input, wacom->tool[idx], 0);
410 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 388 input_report_abs(input, ABS_MISC, 0); /* reset tool id */
411 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 389 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
412 wacom->id[idx] = 0; 390 wacom->id[idx] = 0;
413 return 2; 391 return 2;
414 } 392 }
415 return 0; 393 return 0;
416} 394}
417 395
418static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo) 396static void wacom_intuos_general(struct wacom_wac *wacom)
419{ 397{
420 struct wacom_features *features = &wacom->features; 398 struct wacom_features *features = &wacom->features;
421 unsigned char *data = wacom->data; 399 unsigned char *data = wacom->data;
400 struct input_dev *input = wacom->input;
422 unsigned int t; 401 unsigned int t;
423 402
424 /* general pen packet */ 403 /* general pen packet */
@@ -426,30 +405,30 @@ static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
426 t = (data[6] << 2) | ((data[7] >> 6) & 3); 405 t = (data[6] << 2) | ((data[7] >> 6) & 3);
427 if (features->type >= INTUOS4S && features->type <= INTUOS4L) 406 if (features->type >= INTUOS4S && features->type <= INTUOS4L)
428 t = (t << 1) | (data[1] & 1); 407 t = (t << 1) | (data[1] & 1);
429 wacom_report_abs(wcombo, ABS_PRESSURE, t); 408 input_report_abs(input, ABS_PRESSURE, t);
430 wacom_report_abs(wcombo, ABS_TILT_X, 409 input_report_abs(input, ABS_TILT_X,
431 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 410 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
432 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f); 411 input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
433 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 2); 412 input_report_key(input, BTN_STYLUS, data[1] & 2);
434 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 4); 413 input_report_key(input, BTN_STYLUS2, data[1] & 4);
435 wacom_report_key(wcombo, BTN_TOUCH, t > 10); 414 input_report_key(input, BTN_TOUCH, t > 10);
436 } 415 }
437 416
438 /* airbrush second packet */ 417 /* airbrush second packet */
439 if ((data[1] & 0xbc) == 0xb4) { 418 if ((data[1] & 0xbc) == 0xb4) {
440 wacom_report_abs(wcombo, ABS_WHEEL, 419 input_report_abs(input, ABS_WHEEL,
441 (data[6] << 2) | ((data[7] >> 6) & 3)); 420 (data[6] << 2) | ((data[7] >> 6) & 3));
442 wacom_report_abs(wcombo, ABS_TILT_X, 421 input_report_abs(input, ABS_TILT_X,
443 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 422 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
444 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f); 423 input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
445 } 424 }
446 return;
447} 425}
448 426
449static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo) 427static int wacom_intuos_irq(struct wacom_wac *wacom)
450{ 428{
451 struct wacom_features *features = &wacom->features; 429 struct wacom_features *features = &wacom->features;
452 unsigned char *data = wacom->data; 430 unsigned char *data = wacom->data;
431 struct input_dev *input = wacom->input;
453 unsigned int t; 432 unsigned int t;
454 int idx = 0, result; 433 int idx = 0, result;
455 434
@@ -470,61 +449,61 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
470 wacom->tool[1] = BTN_TOOL_FINGER; 449 wacom->tool[1] = BTN_TOOL_FINGER;
471 450
472 if (features->type >= INTUOS4S && features->type <= INTUOS4L) { 451 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
473 wacom_report_key(wcombo, BTN_0, (data[2] & 0x01)); 452 input_report_key(input, BTN_0, (data[2] & 0x01));
474 wacom_report_key(wcombo, BTN_1, (data[3] & 0x01)); 453 input_report_key(input, BTN_1, (data[3] & 0x01));
475 wacom_report_key(wcombo, BTN_2, (data[3] & 0x02)); 454 input_report_key(input, BTN_2, (data[3] & 0x02));
476 wacom_report_key(wcombo, BTN_3, (data[3] & 0x04)); 455 input_report_key(input, BTN_3, (data[3] & 0x04));
477 wacom_report_key(wcombo, BTN_4, (data[3] & 0x08)); 456 input_report_key(input, BTN_4, (data[3] & 0x08));
478 wacom_report_key(wcombo, BTN_5, (data[3] & 0x10)); 457 input_report_key(input, BTN_5, (data[3] & 0x10));
479 wacom_report_key(wcombo, BTN_6, (data[3] & 0x20)); 458 input_report_key(input, BTN_6, (data[3] & 0x20));
480 if (data[1] & 0x80) { 459 if (data[1] & 0x80) {
481 wacom_report_abs(wcombo, ABS_WHEEL, (data[1] & 0x7f)); 460 input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f));
482 } else { 461 } else {
483 /* Out of proximity, clear wheel value. */ 462 /* Out of proximity, clear wheel value. */
484 wacom_report_abs(wcombo, ABS_WHEEL, 0); 463 input_report_abs(input, ABS_WHEEL, 0);
485 } 464 }
486 if (features->type != INTUOS4S) { 465 if (features->type != INTUOS4S) {
487 wacom_report_key(wcombo, BTN_7, (data[3] & 0x40)); 466 input_report_key(input, BTN_7, (data[3] & 0x40));
488 wacom_report_key(wcombo, BTN_8, (data[3] & 0x80)); 467 input_report_key(input, BTN_8, (data[3] & 0x80));
489 } 468 }
490 if (data[1] | (data[2] & 0x01) | data[3]) { 469 if (data[1] | (data[2] & 0x01) | data[3]) {
491 wacom_report_key(wcombo, wacom->tool[1], 1); 470 input_report_key(input, wacom->tool[1], 1);
492 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID); 471 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
493 } else { 472 } else {
494 wacom_report_key(wcombo, wacom->tool[1], 0); 473 input_report_key(input, wacom->tool[1], 0);
495 wacom_report_abs(wcombo, ABS_MISC, 0); 474 input_report_abs(input, ABS_MISC, 0);
496 } 475 }
497 } else { 476 } else {
498 wacom_report_key(wcombo, BTN_0, (data[5] & 0x01)); 477 input_report_key(input, BTN_0, (data[5] & 0x01));
499 wacom_report_key(wcombo, BTN_1, (data[5] & 0x02)); 478 input_report_key(input, BTN_1, (data[5] & 0x02));
500 wacom_report_key(wcombo, BTN_2, (data[5] & 0x04)); 479 input_report_key(input, BTN_2, (data[5] & 0x04));
501 wacom_report_key(wcombo, BTN_3, (data[5] & 0x08)); 480 input_report_key(input, BTN_3, (data[5] & 0x08));
502 wacom_report_key(wcombo, BTN_4, (data[6] & 0x01)); 481 input_report_key(input, BTN_4, (data[6] & 0x01));
503 wacom_report_key(wcombo, BTN_5, (data[6] & 0x02)); 482 input_report_key(input, BTN_5, (data[6] & 0x02));
504 wacom_report_key(wcombo, BTN_6, (data[6] & 0x04)); 483 input_report_key(input, BTN_6, (data[6] & 0x04));
505 wacom_report_key(wcombo, BTN_7, (data[6] & 0x08)); 484 input_report_key(input, BTN_7, (data[6] & 0x08));
506 wacom_report_key(wcombo, BTN_8, (data[5] & 0x10)); 485 input_report_key(input, BTN_8, (data[5] & 0x10));
507 wacom_report_key(wcombo, BTN_9, (data[6] & 0x10)); 486 input_report_key(input, BTN_9, (data[6] & 0x10));
508 wacom_report_abs(wcombo, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); 487 input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
509 wacom_report_abs(wcombo, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); 488 input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
510 489
511 if ((data[5] & 0x1f) | (data[6] & 0x1f) | (data[1] & 0x1f) | 490 if ((data[5] & 0x1f) | (data[6] & 0x1f) | (data[1] & 0x1f) |
512 data[2] | (data[3] & 0x1f) | data[4]) { 491 data[2] | (data[3] & 0x1f) | data[4]) {
513 wacom_report_key(wcombo, wacom->tool[1], 1); 492 input_report_key(input, wacom->tool[1], 1);
514 wacom_report_abs(wcombo, ABS_MISC, PAD_DEVICE_ID); 493 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
515 } else { 494 } else {
516 wacom_report_key(wcombo, wacom->tool[1], 0); 495 input_report_key(input, wacom->tool[1], 0);
517 wacom_report_abs(wcombo, ABS_MISC, 0); 496 input_report_abs(input, ABS_MISC, 0);
518 } 497 }
519 } 498 }
520 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xffffffff); 499 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
521 return 1; 500 return 1;
522 } 501 }
523 502
524 /* process in/out prox events */ 503 /* process in/out prox events */
525 result = wacom_intuos_inout(wacom, wcombo); 504 result = wacom_intuos_inout(wacom);
526 if (result) 505 if (result)
527 return result-1; 506 return result - 1;
528 507
529 /* don't proceed if we don't know the ID */ 508 /* don't proceed if we don't know the ID */
530 if (!wacom->id[idx]) 509 if (!wacom->id[idx])
@@ -545,17 +524,17 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
545 return 0; 524 return 0;
546 525
547 if (features->type >= INTUOS3S) { 526 if (features->type >= INTUOS3S) {
548 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); 527 input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
549 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); 528 input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
550 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); 529 input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
551 } else { 530 } else {
552 wacom_report_abs(wcombo, ABS_X, wacom_be16_to_cpu(&data[2])); 531 input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2]));
553 wacom_report_abs(wcombo, ABS_Y, wacom_be16_to_cpu(&data[4])); 532 input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4]));
554 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); 533 input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f));
555 } 534 }
556 535
557 /* process general packets */ 536 /* process general packets */
558 wacom_intuos_general(wacom, wcombo); 537 wacom_intuos_general(wacom);
559 538
560 /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ 539 /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */
561 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) { 540 if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) {
@@ -567,174 +546,191 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
567 t = (data[6] << 3) | ((data[7] >> 5) & 7); 546 t = (data[6] << 3) | ((data[7] >> 5) & 7);
568 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : 547 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
569 ((t-1) / 2 + 450)) : (450 - t / 2) ; 548 ((t-1) / 2 + 450)) : (450 - t / 2) ;
570 wacom_report_abs(wcombo, ABS_Z, t); 549 input_report_abs(input, ABS_Z, t);
571 } else { 550 } else {
572 /* 4D mouse rotation packet */ 551 /* 4D mouse rotation packet */
573 t = (data[6] << 3) | ((data[7] >> 5) & 7); 552 t = (data[6] << 3) | ((data[7] >> 5) & 7);
574 wacom_report_abs(wcombo, ABS_RZ, (data[7] & 0x20) ? 553 input_report_abs(input, ABS_RZ, (data[7] & 0x20) ?
575 ((t - 1) / 2) : -t / 2); 554 ((t - 1) / 2) : -t / 2);
576 } 555 }
577 556
578 } else if (!(data[1] & 0x10) && features->type < INTUOS3S) { 557 } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
579 /* 4D mouse packet */ 558 /* 4D mouse packet */
580 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01); 559 input_report_key(input, BTN_LEFT, data[8] & 0x01);
581 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02); 560 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
582 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x04); 561 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
583 562
584 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x20); 563 input_report_key(input, BTN_SIDE, data[8] & 0x20);
585 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x10); 564 input_report_key(input, BTN_EXTRA, data[8] & 0x10);
586 t = (data[6] << 2) | ((data[7] >> 6) & 3); 565 t = (data[6] << 2) | ((data[7] >> 6) & 3);
587 wacom_report_abs(wcombo, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); 566 input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t);
588 567
589 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { 568 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
590 /* I4 mouse */ 569 /* I4 mouse */
591 if (features->type >= INTUOS4S && features->type <= INTUOS4L) { 570 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
592 wacom_report_key(wcombo, BTN_LEFT, data[6] & 0x01); 571 input_report_key(input, BTN_LEFT, data[6] & 0x01);
593 wacom_report_key(wcombo, BTN_MIDDLE, data[6] & 0x02); 572 input_report_key(input, BTN_MIDDLE, data[6] & 0x02);
594 wacom_report_key(wcombo, BTN_RIGHT, data[6] & 0x04); 573 input_report_key(input, BTN_RIGHT, data[6] & 0x04);
595 wacom_report_rel(wcombo, REL_WHEEL, ((data[7] & 0x80) >> 7) 574 input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7)
596 - ((data[7] & 0x40) >> 6)); 575 - ((data[7] & 0x40) >> 6));
597 wacom_report_key(wcombo, BTN_SIDE, data[6] & 0x08); 576 input_report_key(input, BTN_SIDE, data[6] & 0x08);
598 wacom_report_key(wcombo, BTN_EXTRA, data[6] & 0x10); 577 input_report_key(input, BTN_EXTRA, data[6] & 0x10);
599 578
600 wacom_report_abs(wcombo, ABS_TILT_X, 579 input_report_abs(input, ABS_TILT_X,
601 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 580 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
602 wacom_report_abs(wcombo, ABS_TILT_Y, data[8] & 0x7f); 581 input_report_abs(input, ABS_TILT_Y, data[8] & 0x7f);
603 } else { 582 } else {
604 /* 2D mouse packet */ 583 /* 2D mouse packet */
605 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x04); 584 input_report_key(input, BTN_LEFT, data[8] & 0x04);
606 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x08); 585 input_report_key(input, BTN_MIDDLE, data[8] & 0x08);
607 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x10); 586 input_report_key(input, BTN_RIGHT, data[8] & 0x10);
608 wacom_report_rel(wcombo, REL_WHEEL, (data[8] & 0x01) 587 input_report_rel(input, REL_WHEEL, (data[8] & 0x01)
609 - ((data[8] & 0x02) >> 1)); 588 - ((data[8] & 0x02) >> 1));
610 589
611 /* I3 2D mouse side buttons */ 590 /* I3 2D mouse side buttons */
612 if (features->type >= INTUOS3S && features->type <= INTUOS3L) { 591 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
613 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x40); 592 input_report_key(input, BTN_SIDE, data[8] & 0x40);
614 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x20); 593 input_report_key(input, BTN_EXTRA, data[8] & 0x20);
615 } 594 }
616 } 595 }
617 } else if ((features->type < INTUOS3S || features->type == INTUOS3L || 596 } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
618 features->type == INTUOS4L) && 597 features->type == INTUOS4L) &&
619 wacom->tool[idx] == BTN_TOOL_LENS) { 598 wacom->tool[idx] == BTN_TOOL_LENS) {
620 /* Lens cursor packets */ 599 /* Lens cursor packets */
621 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01); 600 input_report_key(input, BTN_LEFT, data[8] & 0x01);
622 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02); 601 input_report_key(input, BTN_MIDDLE, data[8] & 0x02);
623 wacom_report_key(wcombo, BTN_RIGHT, data[8] & 0x04); 602 input_report_key(input, BTN_RIGHT, data[8] & 0x04);
624 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x10); 603 input_report_key(input, BTN_SIDE, data[8] & 0x10);
625 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x08); 604 input_report_key(input, BTN_EXTRA, data[8] & 0x08);
626 } 605 }
627 } 606 }
628 607
629 wacom_report_abs(wcombo, ABS_MISC, wacom->id[idx]); /* report tool id */ 608 input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */
630 wacom_report_key(wcombo, wacom->tool[idx], 1); 609 input_report_key(input, wacom->tool[idx], 1);
631 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 610 input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
632 return 1; 611 return 1;
633} 612}
634 613
635 614
636static void wacom_tpc_finger_in(struct wacom_wac *wacom, void *wcombo, char *data, int idx) 615static void wacom_tpc_finger_in(struct wacom_wac *wacom, char *data, int idx)
637{ 616{
638 wacom_report_abs(wcombo, ABS_X, 617 struct input_dev *input = wacom->input;
639 (data[2 + idx * 2] & 0xff) | ((data[3 + idx * 2] & 0x7f) << 8)); 618 int finger = idx + 1;
640 wacom_report_abs(wcombo, ABS_Y, 619 int x = le16_to_cpup((__le16 *)&data[finger * 2]) & 0x7fff;
641 (data[6 + idx * 2] & 0xff) | ((data[7 + idx * 2] & 0x7f) << 8)); 620 int y = le16_to_cpup((__le16 *)&data[4 + finger * 2]) & 0x7fff;
642 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); 621
643 wacom_report_key(wcombo, wacom->tool[idx], 1); 622 /*
644 if (idx) 623 * Work around input core suppressing "duplicate" events since
645 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 624 * we are abusing ABS_X/ABS_Y to transmit multi-finger data.
646 else 625 * This should go away once we switch to true multitouch
647 wacom_report_key(wcombo, BTN_TOUCH, 1); 626 * protocol.
627 */
628 if (wacom->last_finger != finger) {
629 if (x == input->abs[ABS_X])
630 x++;
631
632 if (y == input->abs[ABS_Y])
633 y++;
634 }
635
636 input_report_abs(input, ABS_X, x);
637 input_report_abs(input, ABS_Y, y);
638 input_report_abs(input, ABS_MISC, wacom->id[0]);
639 input_report_key(input, wacom->tool[finger], 1);
640 if (!idx)
641 input_report_key(input, BTN_TOUCH, 1);
642 input_event(input, EV_MSC, MSC_SERIAL, finger);
643 input_sync(wacom->input);
644
645 wacom->last_finger = finger;
648} 646}
649 647
650static void wacom_tpc_touch_out(struct wacom_wac *wacom, void *wcombo, int idx) 648static void wacom_tpc_touch_out(struct wacom_wac *wacom, int idx)
651{ 649{
652 wacom_report_abs(wcombo, ABS_X, 0); 650 struct input_dev *input = wacom->input;
653 wacom_report_abs(wcombo, ABS_Y, 0); 651 int finger = idx + 1;
654 wacom_report_abs(wcombo, ABS_MISC, 0); 652
655 wacom_report_key(wcombo, wacom->tool[idx], 0); 653 input_report_abs(input, ABS_X, 0);
656 if (idx) 654 input_report_abs(input, ABS_Y, 0);
657 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 655 input_report_abs(input, ABS_MISC, 0);
658 else 656 input_report_key(input, wacom->tool[finger], 0);
659 wacom_report_key(wcombo, BTN_TOUCH, 0); 657 if (!idx)
660 return; 658 input_report_key(input, BTN_TOUCH, 0);
659 input_event(input, EV_MSC, MSC_SERIAL, finger);
660 input_sync(input);
661} 661}
662 662
663static void wacom_tpc_touch_in(struct wacom_wac *wacom, void *wcombo) 663static void wacom_tpc_touch_in(struct wacom_wac *wacom, size_t len)
664{ 664{
665 char *data = wacom->data; 665 char *data = wacom->data;
666 struct urb *urb = ((struct wacom_combo *)wcombo)->urb; 666 struct input_dev *input = wacom->input;
667 static int firstFinger = 0;
668 static int secondFinger = 0;
669 667
670 wacom->tool[0] = BTN_TOOL_DOUBLETAP; 668 wacom->tool[1] = BTN_TOOL_DOUBLETAP;
671 wacom->id[0] = TOUCH_DEVICE_ID; 669 wacom->id[0] = TOUCH_DEVICE_ID;
672 wacom->tool[1] = BTN_TOOL_TRIPLETAP; 670 wacom->tool[2] = BTN_TOOL_TRIPLETAP;
671
672 if (len != WACOM_PKGLEN_TPC1FG) {
673 673
674 if (urb->actual_length != WACOM_PKGLEN_TPC1FG) {
675 switch (data[0]) { 674 switch (data[0]) {
676 case WACOM_REPORT_TPC1FG:
677 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
678 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
679 wacom_report_abs(wcombo, ABS_PRESSURE, wacom_le16_to_cpu(&data[6]));
680 wacom_report_key(wcombo, BTN_TOUCH, wacom_le16_to_cpu(&data[6]));
681 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]);
682 wacom_report_key(wcombo, wacom->tool[0], 1);
683 break;
684 case WACOM_REPORT_TPC2FG:
685 /* keep this byte to send proper out-prox event */
686 wacom->id[1] = data[1] & 0x03;
687
688 if (data[1] & 0x01) {
689 wacom_tpc_finger_in(wacom, wcombo, data, 0);
690 firstFinger = 1;
691 } else if (firstFinger) {
692 wacom_tpc_touch_out(wacom, wcombo, 0);
693 }
694 675
695 if (data[1] & 0x02) { 676 case WACOM_REPORT_TPC1FG:
696 /* sync first finger data */ 677 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
697 if (firstFinger) 678 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
698 wacom_input_sync(wcombo); 679 input_report_abs(input, ABS_PRESSURE, le16_to_cpup((__le16 *)&data[6]));
680 input_report_key(input, BTN_TOUCH, le16_to_cpup((__le16 *)&data[6]));
681 input_report_abs(input, ABS_MISC, wacom->id[0]);
682 input_report_key(input, wacom->tool[1], 1);
683 input_sync(input);
684 break;
699 685
700 wacom_tpc_finger_in(wacom, wcombo, data, 1); 686 case WACOM_REPORT_TPC2FG:
701 secondFinger = 1; 687 if (data[1] & 0x01)
702 } else if (secondFinger) { 688 wacom_tpc_finger_in(wacom, data, 0);
703 /* sync first finger data */ 689 else if (wacom->id[1] & 0x01)
704 if (firstFinger) 690 wacom_tpc_touch_out(wacom, 0);
705 wacom_input_sync(wcombo);
706 691
707 wacom_tpc_touch_out(wacom, wcombo, 1); 692 if (data[1] & 0x02)
708 secondFinger = 0; 693 wacom_tpc_finger_in(wacom, data, 1);
709 } 694 else if (wacom->id[1] & 0x02)
710 if (!(data[1] & 0x01)) 695 wacom_tpc_touch_out(wacom, 1);
711 firstFinger = 0; 696 break;
712 break;
713 } 697 }
714 } else { 698 } else {
715 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[1])); 699 input_report_abs(input, ABS_X, get_unaligned_le16(&data[1]));
716 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[3])); 700 input_report_abs(input, ABS_Y, get_unaligned_le16(&data[3]));
717 wacom_report_key(wcombo, BTN_TOUCH, 1); 701 input_report_key(input, BTN_TOUCH, 1);
718 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); 702 input_report_abs(input, ABS_MISC, wacom->id[1]);
719 wacom_report_key(wcombo, wacom->tool[0], 1); 703 input_report_key(input, wacom->tool[1], 1);
704 input_sync(input);
720 } 705 }
721 return;
722} 706}
723 707
724static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo) 708static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len)
725{ 709{
726 struct wacom_features *features = &wacom->features; 710 struct wacom_features *features = &wacom->features;
727 char *data = wacom->data; 711 char *data = wacom->data;
728 int prox = 0, pressure, idx = -1; 712 struct input_dev *input = wacom->input;
729 static int stylusInProx, touchInProx = 1, touchOut; 713 int prox = 0, pressure;
730 struct urb *urb = ((struct wacom_combo *)wcombo)->urb; 714 int retval = 0;
731 715
732 dbg("wacom_tpc_irq: received report #%d", data[0]); 716 dbg("wacom_tpc_irq: received report #%d", data[0]);
733 717
734 if (urb->actual_length == WACOM_PKGLEN_TPC1FG || /* single touch */ 718 if (len == WACOM_PKGLEN_TPC1FG || /* single touch */
735 data[0] == WACOM_REPORT_TPC1FG || /* single touch */ 719 data[0] == WACOM_REPORT_TPC1FG || /* single touch */
736 data[0] == WACOM_REPORT_TPC2FG) { /* 2FG touch */ 720 data[0] == WACOM_REPORT_TPC2FG) { /* 2FG touch */
737 if (urb->actual_length == WACOM_PKGLEN_TPC1FG) { /* with touch */ 721
722 if (wacom->shared->stylus_in_proximity) {
723 if (wacom->id[1] & 0x01)
724 wacom_tpc_touch_out(wacom, 0);
725
726 if (wacom->id[1] & 0x02)
727 wacom_tpc_touch_out(wacom, 1);
728
729 wacom->id[1] = 0;
730 return 0;
731 }
732
733 if (len == WACOM_PKGLEN_TPC1FG) { /* with touch */
738 prox = data[0] & 0x01; 734 prox = data[0] & 0x01;
739 } else { /* with capacity */ 735 } else { /* with capacity */
740 if (data[0] == WACOM_REPORT_TPC1FG) 736 if (data[0] == WACOM_REPORT_TPC1FG)
@@ -745,168 +741,264 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo)
745 prox = data[1] & 0x03; 741 prox = data[1] & 0x03;
746 } 742 }
747 743
748 if (!stylusInProx) { /* stylus not in prox */ 744 if (prox) {
749 if (prox) { 745 if (!wacom->id[1])
750 if (touchInProx) { 746 wacom->last_finger = 1;
751 wacom_tpc_touch_in(wacom, wcombo); 747 wacom_tpc_touch_in(wacom, len);
752 touchOut = 1; 748 } else {
753 return 1; 749 if (data[0] == WACOM_REPORT_TPC2FG) {
754 }
755 } else {
756 /* 2FGT out-prox */ 750 /* 2FGT out-prox */
757 if (data[0] == WACOM_REPORT_TPC2FG) { 751 if (wacom->id[1] & 0x01)
758 idx = (wacom->id[1] & 0x01) - 1; 752 wacom_tpc_touch_out(wacom, 0);
759 if (idx == 0) { 753
760 wacom_tpc_touch_out(wacom, wcombo, idx); 754 if (wacom->id[1] & 0x02)
761 /* sync first finger event */ 755 wacom_tpc_touch_out(wacom, 1);
762 if (wacom->id[1] & 0x02) 756 } else
763 wacom_input_sync(wcombo); 757 /* one finger touch */
764 } 758 wacom_tpc_touch_out(wacom, 0);
765 idx = (wacom->id[1] & 0x02) - 1; 759
766 if (idx == 1) 760 wacom->id[0] = 0;
767 wacom_tpc_touch_out(wacom, wcombo, idx);
768 } else /* one finger touch */
769 wacom_tpc_touch_out(wacom, wcombo, 0);
770 touchOut = 0;
771 touchInProx = 1;
772 return 1;
773 }
774 } else if (touchOut || !prox) { /* force touch out-prox */
775 wacom_tpc_touch_out(wacom, wcombo, 0);
776 touchOut = 0;
777 touchInProx = 1;
778 return 1;
779 } 761 }
762 /* keep prox bit to send proper out-prox event */
763 wacom->id[1] = prox;
780 } else if (data[0] == WACOM_REPORT_PENABLED) { /* Penabled */ 764 } else if (data[0] == WACOM_REPORT_PENABLED) { /* Penabled */
781 prox = data[1] & 0x20; 765 prox = data[1] & 0x20;
782 766
783 touchInProx = 0; 767 if (!wacom->shared->stylus_in_proximity) { /* first in prox */
768 /* Going into proximity select tool */
769 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
770 if (wacom->tool[0] == BTN_TOOL_PEN)
771 wacom->id[0] = STYLUS_DEVICE_ID;
772 else
773 wacom->id[0] = ERASER_DEVICE_ID;
784 774
785 if (prox) { /* in prox */ 775 wacom->shared->stylus_in_proximity = true;
786 if (!wacom->id[0]) { 776 }
787 /* Going into proximity select tool */ 777 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
788 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 778 input_report_key(input, BTN_STYLUS2, data[1] & 0x10);
789 if (wacom->tool[0] == BTN_TOOL_PEN) 779 input_report_abs(input, ABS_X, le16_to_cpup((__le16 *)&data[2]));
790 wacom->id[0] = STYLUS_DEVICE_ID; 780 input_report_abs(input, ABS_Y, le16_to_cpup((__le16 *)&data[4]));
791 else 781 pressure = ((data[7] & 0x01) << 8) | data[6];
792 wacom->id[0] = ERASER_DEVICE_ID; 782 if (pressure < 0)
793 } 783 pressure = features->pressure_max + pressure + 1;
794 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 784 input_report_abs(input, ABS_PRESSURE, pressure);
795 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10); 785 input_report_key(input, BTN_TOUCH, data[1] & 0x05);
796 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2])); 786 if (!prox) { /* out-prox */
797 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
798 pressure = ((data[7] & 0x01) << 8) | data[6];
799 if (pressure < 0)
800 pressure = features->pressure_max + pressure + 1;
801 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
802 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x05);
803 } else {
804 wacom_report_abs(wcombo, ABS_X, 0);
805 wacom_report_abs(wcombo, ABS_Y, 0);
806 wacom_report_abs(wcombo, ABS_PRESSURE, 0);
807 wacom_report_key(wcombo, BTN_STYLUS, 0);
808 wacom_report_key(wcombo, BTN_STYLUS2, 0);
809 wacom_report_key(wcombo, BTN_TOUCH, 0);
810 wacom->id[0] = 0; 787 wacom->id[0] = 0;
811 /* pen is out so touch can be enabled now */ 788 wacom->shared->stylus_in_proximity = false;
812 touchInProx = 1;
813 } 789 }
814 wacom_report_key(wcombo, wacom->tool[0], prox); 790 input_report_key(input, wacom->tool[0], prox);
815 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); 791 input_report_abs(input, ABS_MISC, wacom->id[0]);
816 stylusInProx = prox; 792 retval = 1;
817 return 1;
818 } 793 }
819 return 0; 794 return retval;
820} 795}
821 796
822int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo) 797void wacom_wac_irq(struct wacom_wac *wacom_wac, size_t len)
823{ 798{
799 bool sync;
800
824 switch (wacom_wac->features.type) { 801 switch (wacom_wac->features.type) {
825 case PENPARTNER: 802 case PENPARTNER:
826 return wacom_penpartner_irq(wacom_wac, wcombo); 803 sync = wacom_penpartner_irq(wacom_wac);
827 804 break;
828 case PL: 805
829 return wacom_pl_irq(wacom_wac, wcombo); 806 case PL:
830 807 sync = wacom_pl_irq(wacom_wac);
831 case WACOM_G4: 808 break;
832 case GRAPHIRE: 809
833 case WACOM_MO: 810 case WACOM_G4:
834 return wacom_graphire_irq(wacom_wac, wcombo); 811 case GRAPHIRE:
835 812 case WACOM_MO:
836 case PTU: 813 sync = wacom_graphire_irq(wacom_wac);
837 return wacom_ptu_irq(wacom_wac, wcombo); 814 break;
838 815
839 case INTUOS: 816 case PTU:
840 case INTUOS3S: 817 sync = wacom_ptu_irq(wacom_wac);
841 case INTUOS3: 818 break;
842 case INTUOS3L: 819
843 case INTUOS4S: 820 case INTUOS:
844 case INTUOS4: 821 case INTUOS3S:
845 case INTUOS4L: 822 case INTUOS3:
846 case CINTIQ: 823 case INTUOS3L:
847 case WACOM_BEE: 824 case INTUOS4S:
848 return wacom_intuos_irq(wacom_wac, wcombo); 825 case INTUOS4:
849 826 case INTUOS4L:
850 case TABLETPC: 827 case CINTIQ:
851 case TABLETPC2FG: 828 case WACOM_BEE:
852 return wacom_tpc_irq(wacom_wac, wcombo); 829 sync = wacom_intuos_irq(wacom_wac);
853 830 break;
854 default: 831
855 return 0; 832 case TABLETPC:
833 case TABLETPC2FG:
834 sync = wacom_tpc_irq(wacom_wac, len);
835 break;
836
837 default:
838 sync = false;
839 break;
856 } 840 }
857 return 0; 841
842 if (sync)
843 input_sync(wacom_wac->input);
844}
845
846static void wacom_setup_intuos(struct wacom_wac *wacom_wac)
847{
848 struct input_dev *input_dev = wacom_wac->input;
849
850 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
851 input_set_capability(input_dev, EV_REL, REL_WHEEL);
852
853 __set_bit(BTN_LEFT, input_dev->keybit);
854 __set_bit(BTN_RIGHT, input_dev->keybit);
855 __set_bit(BTN_MIDDLE, input_dev->keybit);
856 __set_bit(BTN_SIDE, input_dev->keybit);
857 __set_bit(BTN_EXTRA, input_dev->keybit);
858
859 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
860 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
861 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
862 __set_bit(BTN_TOOL_BRUSH, input_dev->keybit);
863 __set_bit(BTN_TOOL_PENCIL, input_dev->keybit);
864 __set_bit(BTN_TOOL_AIRBRUSH, input_dev->keybit);
865 __set_bit(BTN_TOOL_LENS, input_dev->keybit);
866 __set_bit(BTN_STYLUS, input_dev->keybit);
867 __set_bit(BTN_STYLUS2, input_dev->keybit);
868
869 input_set_abs_params(input_dev, ABS_DISTANCE,
870 0, wacom_wac->features.distance_max, 0, 0);
871 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
872 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
873 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
874 input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
875 input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
858} 876}
859 877
860void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 878void wacom_setup_input_capabilities(struct input_dev *input_dev,
879 struct wacom_wac *wacom_wac)
861{ 880{
881 struct wacom_features *features = &wacom_wac->features;
882 int i;
883
884 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
885
886 __set_bit(BTN_TOUCH, input_dev->keybit);
887
888 input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0);
889 input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0);
890 input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0);
891
892 __set_bit(ABS_MISC, input_dev->absbit);
893
862 switch (wacom_wac->features.type) { 894 switch (wacom_wac->features.type) {
863 case WACOM_MO: 895 case WACOM_MO:
864 input_dev_mo(input_dev, wacom_wac); 896 __set_bit(BTN_1, input_dev->keybit);
865 case WACOM_G4: 897 __set_bit(BTN_5, input_dev->keybit);
866 input_dev_g4(input_dev, wacom_wac); 898
867 /* fall through */ 899 input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
868 case GRAPHIRE: 900 /* fall through */
869 input_dev_g(input_dev, wacom_wac); 901
870 break; 902 case WACOM_G4:
871 case WACOM_BEE: 903 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
872 input_dev_bee(input_dev, wacom_wac); 904
873 case INTUOS3: 905 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
874 case INTUOS3L: 906 __set_bit(BTN_0, input_dev->keybit);
875 case CINTIQ: 907 __set_bit(BTN_4, input_dev->keybit);
876 input_dev_i3(input_dev, wacom_wac); 908 /* fall through */
877 /* fall through */ 909
878 case INTUOS3S: 910 case GRAPHIRE:
879 input_dev_i3s(input_dev, wacom_wac); 911 input_set_capability(input_dev, EV_REL, REL_WHEEL);
880 /* fall through */ 912
881 case INTUOS: 913 __set_bit(BTN_LEFT, input_dev->keybit);
882 input_dev_i(input_dev, wacom_wac); 914 __set_bit(BTN_RIGHT, input_dev->keybit);
883 break; 915 __set_bit(BTN_MIDDLE, input_dev->keybit);
884 case INTUOS4: 916
885 case INTUOS4L: 917 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
886 input_dev_i4(input_dev, wacom_wac); 918 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
887 /* fall through */ 919 __set_bit(BTN_TOOL_MOUSE, input_dev->keybit);
888 case INTUOS4S: 920 __set_bit(BTN_STYLUS, input_dev->keybit);
889 input_dev_i4s(input_dev, wacom_wac); 921 __set_bit(BTN_STYLUS2, input_dev->keybit);
890 input_dev_i(input_dev, wacom_wac); 922 break;
891 break; 923
892 case TABLETPC2FG: 924 case WACOM_BEE:
893 input_dev_tpc2fg(input_dev, wacom_wac); 925 __set_bit(BTN_8, input_dev->keybit);
894 /* fall through */ 926 __set_bit(BTN_9, input_dev->keybit);
895 case TABLETPC: 927 /* fall through */
896 input_dev_tpc(input_dev, wacom_wac); 928
897 if (wacom_wac->features.device_type != BTN_TOOL_PEN) 929 case INTUOS3:
898 break; /* no need to process stylus stuff */ 930 case INTUOS3L:
899 931 case CINTIQ:
900 /* fall through */ 932 __set_bit(BTN_4, input_dev->keybit);
901 case PL: 933 __set_bit(BTN_5, input_dev->keybit);
902 case PTU: 934 __set_bit(BTN_6, input_dev->keybit);
903 input_dev_pl(input_dev, wacom_wac); 935 __set_bit(BTN_7, input_dev->keybit);
904 /* fall through */ 936
905 case PENPARTNER: 937 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
906 input_dev_pt(input_dev, wacom_wac); 938 /* fall through */
907 break; 939
940 case INTUOS3S:
941 __set_bit(BTN_0, input_dev->keybit);
942 __set_bit(BTN_1, input_dev->keybit);
943 __set_bit(BTN_2, input_dev->keybit);
944 __set_bit(BTN_3, input_dev->keybit);
945
946 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
947
948 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
949 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
950 /* fall through */
951
952 case INTUOS:
953 wacom_setup_intuos(wacom_wac);
954 break;
955
956 case INTUOS4:
957 case INTUOS4L:
958 __set_bit(BTN_7, input_dev->keybit);
959 __set_bit(BTN_8, input_dev->keybit);
960 /* fall through */
961
962 case INTUOS4S:
963 for (i = 0; i < 7; i++)
964 __set_bit(BTN_0 + i, input_dev->keybit);
965 __set_bit(BTN_TOOL_FINGER, input_dev->keybit);
966
967 input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
968 wacom_setup_intuos(wacom_wac);
969 break;
970
971 case TABLETPC2FG:
972 if (features->device_type == BTN_TOOL_TRIPLETAP) {
973 __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit);
974 input_set_capability(input_dev, EV_MSC, MSC_SERIAL);
975 }
976 /* fall through */
977
978 case TABLETPC:
979 if (features->device_type == BTN_TOOL_DOUBLETAP ||
980 features->device_type == BTN_TOOL_TRIPLETAP) {
981 input_set_abs_params(input_dev, ABS_RX, 0, features->x_phy, 0, 0);
982 input_set_abs_params(input_dev, ABS_RY, 0, features->y_phy, 0, 0);
983 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
984 }
985
986 if (features->device_type != BTN_TOOL_PEN)
987 break; /* no need to process stylus stuff */
988
989 /* fall through */
990
991 case PL:
992 case PTU:
993 __set_bit(BTN_TOOL_PEN, input_dev->keybit);
994 __set_bit(BTN_STYLUS, input_dev->keybit);
995 __set_bit(BTN_STYLUS2, input_dev->keybit);
996 /* fall through */
997
998 case PENPARTNER:
999 __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
1000 break;
908 } 1001 }
909 return;
910} 1002}
911 1003
912static const struct wacom_features wacom_features_0x00 = 1004static const struct wacom_features wacom_features_0x00 =