aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/tablet/wacom_wac.c
diff options
context:
space:
mode:
authorPing Cheng <pingc@wacom.com>2010-03-05 00:50:59 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-03-05 03:36:10 -0500
commit776943fd6f104a6e8457dc95a17282e69e963666 (patch)
tree66a5f06a4878c234a35a00034316d10d141c0bb7 /drivers/input/tablet/wacom_wac.c
parent5bc923c505926af927d4f3011da92c243787d6a7 (diff)
Input: wacom - merge out and in prox events
Process out and in prox events for Graphire and Tablet PC devices in the same loop to simplify the data parsing logic. Signed-off-by: Ping Cheng <pingc@wacom.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/tablet/wacom_wac.c')
-rw-r--r--drivers/input/tablet/wacom_wac.c163
1 files changed, 59 insertions, 104 deletions
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 4a852d815c68..b3ba3437a2eb 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -155,19 +155,19 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
155{ 155{
156 struct wacom_features *features = &wacom->features; 156 struct wacom_features *features = &wacom->features;
157 unsigned char *data = wacom->data; 157 unsigned char *data = wacom->data;
158 int x, y, rw; 158 int x, y, prox;
159 static int penData = 0; 159 int rw = 0;
160 int retval = 0;
160 161
161 if (data[0] != WACOM_REPORT_PENABLED) { 162 if (data[0] != WACOM_REPORT_PENABLED) {
162 dbg("wacom_graphire_irq: received unknown report #%d", data[0]); 163 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
163 return 0; 164 goto exit;
164 } 165 }
165 166
166 if (data[1] & 0x80) { 167 prox = data[1] & 0x80;
167 /* in prox and not a pad data */ 168 if (prox || wacom->id[0]) {
168 penData = 1; 169 if (prox) {
169 170 switch ((data[1] >> 5) & 3) {
170 switch ((data[1] >> 5) & 3) {
171 171
172 case 0: /* Pen */ 172 case 0: /* Pen */
173 wacom->tool[0] = BTN_TOOL_PEN; 173 wacom->tool[0] = BTN_TOOL_PEN;
@@ -181,23 +181,13 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
181 181
182 case 2: /* Mouse with wheel */ 182 case 2: /* Mouse with wheel */
183 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04); 183 wacom_report_key(wcombo, 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 */ 184 /* fall through */
190 185
191 case 3: /* Mouse without wheel */ 186 case 3: /* Mouse without wheel */
192 wacom->tool[0] = BTN_TOOL_MOUSE; 187 wacom->tool[0] = BTN_TOOL_MOUSE;
193 wacom->id[0] = CURSOR_DEVICE_ID; 188 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; 189 break;
190 }
201 } 191 }
202 x = wacom_le16_to_cpu(&data[2]); 192 x = wacom_le16_to_cpu(&data[2]);
203 y = wacom_le16_to_cpu(&data[4]); 193 y = wacom_le16_to_cpu(&data[4]);
@@ -208,36 +198,32 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
208 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01); 198 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x01);
209 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 199 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 200 wacom_report_key(wcombo, 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 { 201 } else {
222 wacom_report_abs(wcombo, ABS_PRESSURE, 0); 202 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
223 wacom_report_key(wcombo, BTN_TOUCH, 0); 203 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
224 wacom_report_key(wcombo, BTN_STYLUS, 0); 204 if (features->type == WACOM_G4 ||
225 wacom_report_key(wcombo, BTN_STYLUS2, 0); 205 features->type == WACOM_MO) {
206 wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f);
207 rw = (signed)(data[7] & 0x04) - (data[7] & 0x03);
208 } else {
209 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
210 rw = -(signed)data[6];
211 }
212 wacom_report_rel(wcombo, REL_WHEEL, rw);
226 } 213 }
227 wacom->id[0] = 0; 214
228 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 215 if (!prox)
229 wacom_report_key(wcombo, wacom->tool[0], 0); 216 wacom->id[0] = 0;
217 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); /* report tool id */
218 wacom_report_key(wcombo, wacom->tool[0], prox);
219 wacom_input_sync(wcombo); /* sync last event */
230 } 220 }
231 221
232 /* send pad data */ 222 /* send pad data */
233 switch (features->type) { 223 switch (features->type) {
234 case WACOM_G4: 224 case WACOM_G4:
235 if (data[7] & 0xf8) { 225 prox = data[7] & 0xf8;
236 if (penData) { 226 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; 227 wacom->id[1] = PAD_DEVICE_ID;
242 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40)); 228 wacom_report_key(wcombo, BTN_0, (data[7] & 0x40));
243 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80)); 229 wacom_report_key(wcombo, BTN_4, (data[7] & 0x80));
@@ -245,29 +231,16 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
245 wacom_report_rel(wcombo, REL_WHEEL, rw); 231 wacom_report_rel(wcombo, REL_WHEEL, rw);
246 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 232 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
247 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]); 233 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
248 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 234 if (!prox)
249 } else if (wacom->id[1]) { 235 wacom->id[1] = 0;
250 if (penData) { 236 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
251 wacom_input_sync(wcombo); /* sync last event */
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); 237 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
262 } 238 }
239 retval = 1;
263 break; 240 break;
264 case WACOM_MO: 241 case WACOM_MO:
265 if ((data[7] & 0xf8) || (data[8] & 0xff)) { 242 prox = (data[7] & 0xf8) || data[8];
266 if (penData) { 243 if (prox || wacom->id[1]) {
267 wacom_input_sync(wcombo); /* sync last event */
268 if (!wacom->id[0])
269 penData = 0;
270 }
271 wacom->id[1] = PAD_DEVICE_ID; 244 wacom->id[1] = PAD_DEVICE_ID;
272 wacom_report_key(wcombo, BTN_0, (data[7] & 0x08)); 245 wacom_report_key(wcombo, BTN_0, (data[7] & 0x08));
273 wacom_report_key(wcombo, BTN_1, (data[7] & 0x20)); 246 wacom_report_key(wcombo, BTN_1, (data[7] & 0x20));
@@ -275,27 +248,16 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
275 wacom_report_key(wcombo, BTN_5, (data[7] & 0x40)); 248 wacom_report_key(wcombo, BTN_5, (data[7] & 0x40));
276 wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f)); 249 wacom_report_abs(wcombo, ABS_WHEEL, (data[8] & 0x7f));
277 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0); 250 wacom_report_key(wcombo, BTN_TOOL_FINGER, 0xf0);
251 if (!prox)
252 wacom->id[1] = 0;
278 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]); 253 wacom_report_abs(wcombo, ABS_MISC, wacom->id[1]);
279 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0); 254 wacom_input_event(wcombo, EV_MSC, MSC_SERIAL, 0xf0);
280 } else if (wacom->id[1]) {
281 if (penData) {
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 } 255 }
256 retval = 1;
296 break; 257 break;
297 } 258 }
298 return 1; 259exit:
260 return retval;
299} 261}
300 262
301static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo) 263static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
@@ -636,9 +598,9 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
636static void wacom_tpc_finger_in(struct wacom_wac *wacom, void *wcombo, char *data, int idx) 598static void wacom_tpc_finger_in(struct wacom_wac *wacom, void *wcombo, char *data, int idx)
637{ 599{
638 wacom_report_abs(wcombo, ABS_X, 600 wacom_report_abs(wcombo, ABS_X,
639 (data[2 + idx * 2] & 0xff) | ((data[3 + idx * 2] & 0x7f) << 8)); 601 data[2 + idx * 2] | ((data[3 + idx * 2] & 0x7f) << 8));
640 wacom_report_abs(wcombo, ABS_Y, 602 wacom_report_abs(wcombo, ABS_Y,
641 (data[6 + idx * 2] & 0xff) | ((data[7 + idx * 2] & 0x7f) << 8)); 603 data[6 + idx * 2] | ((data[7 + idx * 2] & 0x7f) << 8));
642 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]); 604 wacom_report_abs(wcombo, ABS_MISC, wacom->id[0]);
643 wacom_report_key(wcombo, wacom->tool[idx], 1); 605 wacom_report_key(wcombo, wacom->tool[idx], 1);
644 if (idx) 606 if (idx)
@@ -782,31 +744,24 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo)
782 744
783 touchInProx = 0; 745 touchInProx = 0;
784 746
785 if (prox) { /* in prox */ 747 if (!wacom->id[0]) { /* first in prox */
786 if (!wacom->id[0]) { 748 /* Going into proximity select tool */
787 /* Going into proximity select tool */ 749 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN;
788 wacom->tool[0] = (data[1] & 0x0c) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; 750 if (wacom->tool[0] == BTN_TOOL_PEN)
789 if (wacom->tool[0] == BTN_TOOL_PEN) 751 wacom->id[0] = STYLUS_DEVICE_ID;
790 wacom->id[0] = STYLUS_DEVICE_ID; 752 else
791 else 753 wacom->id[0] = ERASER_DEVICE_ID;
792 wacom->id[0] = ERASER_DEVICE_ID; 754 }
793 } 755 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
794 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 756 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10);
795 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x10); 757 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2]));
796 wacom_report_abs(wcombo, ABS_X, wacom_le16_to_cpu(&data[2])); 758 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
797 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4])); 759 pressure = ((data[7] & 0x01) << 8) | data[6];
798 pressure = ((data[7] & 0x01) << 8) | data[6]; 760 if (pressure < 0)
799 if (pressure < 0) 761 pressure = features->pressure_max + pressure + 1;
800 pressure = features->pressure_max + pressure + 1; 762 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
801 wacom_report_abs(wcombo, ABS_PRESSURE, pressure); 763 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x05);
802 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x05); 764 if (!prox) { /* out-prox */
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; 765 wacom->id[0] = 0;
811 /* pen is out so touch can be enabled now */ 766 /* pen is out so touch can be enabled now */
812 touchInProx = 1; 767 touchInProx = 1;