@@ -189,7 +189,7 @@ struct ati_remote {
189189 dma_addr_t inbuf_dma ;
190190 dma_addr_t outbuf_dma ;
191191
192- unsigned char old_data [ 2 ]; /* Detect duplicate events */
192+ unsigned char old_data ; /* Detect duplicate events */
193193 unsigned long old_jiffies ;
194194 unsigned long acc_jiffies ; /* handle acceleration */
195195 unsigned long first_jiffies ;
@@ -221,35 +221,35 @@ struct ati_remote {
221221/* Translation table from hardware messages to input events. */
222222static const struct {
223223 short kind ;
224- unsigned char data1 , data2 ;
224+ unsigned char data ;
225225 int type ;
226226 unsigned int code ;
227227 int value ;
228228} ati_remote_tbl [] = {
229229 /* Directional control pad axes */
230- {KIND_ACCEL , 0x35 , 0x70 , EV_REL , REL_X , -1 }, /* left */
231- {KIND_ACCEL , 0x36 , 0x71 , EV_REL , REL_X , 1 }, /* right */
232- {KIND_ACCEL , 0x37 , 0x72 , EV_REL , REL_Y , -1 }, /* up */
233- {KIND_ACCEL , 0x38 , 0x73 , EV_REL , REL_Y , 1 }, /* down */
230+ {KIND_ACCEL , 0x70 , EV_REL , REL_X , -1 }, /* left */
231+ {KIND_ACCEL , 0x71 , EV_REL , REL_X , 1 }, /* right */
232+ {KIND_ACCEL , 0x72 , EV_REL , REL_Y , -1 }, /* up */
233+ {KIND_ACCEL , 0x73 , EV_REL , REL_Y , 1 }, /* down */
234234 /* Directional control pad diagonals */
235- {KIND_LU , 0x39 , 0x74 , EV_REL , 0 , 0 }, /* left up */
236- {KIND_RU , 0x3a , 0x75 , EV_REL , 0 , 0 }, /* right up */
237- {KIND_LD , 0x3c , 0x77 , EV_REL , 0 , 0 }, /* left down */
238- {KIND_RD , 0x3b , 0x76 , EV_REL , 0 , 0 }, /* right down */
235+ {KIND_LU , 0x74 , EV_REL , 0 , 0 }, /* left up */
236+ {KIND_RU , 0x75 , EV_REL , 0 , 0 }, /* right up */
237+ {KIND_LD , 0x77 , EV_REL , 0 , 0 }, /* left down */
238+ {KIND_RD , 0x76 , EV_REL , 0 , 0 }, /* right down */
239239
240240 /* "Mouse button" buttons */
241- {KIND_LITERAL , 0x3d , 0x78 , EV_KEY , BTN_LEFT , 1 }, /* left btn down */
242- {KIND_LITERAL , 0x3e , 0x79 , EV_KEY , BTN_LEFT , 0 }, /* left btn up */
243- {KIND_LITERAL , 0x41 , 0x7c , EV_KEY , BTN_RIGHT , 1 },/* right btn down */
244- {KIND_LITERAL , 0x42 , 0x7d , EV_KEY , BTN_RIGHT , 0 },/* right btn up */
241+ {KIND_LITERAL , 0x78 , EV_KEY , BTN_LEFT , 1 }, /* left btn down */
242+ {KIND_LITERAL , 0x79 , EV_KEY , BTN_LEFT , 0 }, /* left btn up */
243+ {KIND_LITERAL , 0x7c , EV_KEY , BTN_RIGHT , 1 },/* right btn down */
244+ {KIND_LITERAL , 0x7d , EV_KEY , BTN_RIGHT , 0 },/* right btn up */
245245
246246 /* Artificial "doubleclick" events are generated by the hardware.
247247 * They are mapped to the "side" and "extra" mouse buttons here. */
248- {KIND_FILTERED , 0x3f , 0x7a , EV_KEY , BTN_SIDE , 1 }, /* left dblclick */
249- {KIND_FILTERED , 0x43 , 0x7e , EV_KEY , BTN_EXTRA , 1 },/* right dblclick */
248+ {KIND_FILTERED , 0x7a , EV_KEY , BTN_SIDE , 1 }, /* left dblclick */
249+ {KIND_FILTERED , 0x7e , EV_KEY , BTN_EXTRA , 1 },/* right dblclick */
250250
251251 /* Non-mouse events are handled by rc-core */
252- {KIND_END , 0x00 , 0x00 , EV_MAX + 1 , 0 , 0 }
252+ {KIND_END , 0x00 , EV_MAX + 1 , 0 , 0 }
253253};
254254
255255/* Local function prototypes */
@@ -396,25 +396,6 @@ static int ati_remote_sendpacket(struct ati_remote *ati_remote, u16 cmd, unsigne
396396 return retval ;
397397}
398398
399- /*
400- * ati_remote_event_lookup
401- */
402- static int ati_remote_event_lookup (int rem , unsigned char d1 , unsigned char d2 )
403- {
404- int i ;
405-
406- for (i = 0 ; ati_remote_tbl [i ].kind != KIND_END ; i ++ ) {
407- /*
408- * Decide if the table entry matches the remote input.
409- */
410- if (ati_remote_tbl [i ].data1 == d1 &&
411- ati_remote_tbl [i ].data2 == d2 )
412- return i ;
413-
414- }
415- return -1 ;
416- }
417-
418399/*
419400 * ati_remote_compute_accel
420401 *
@@ -463,7 +444,15 @@ static void ati_remote_input_report(struct urb *urb)
463444 int index = -1 ;
464445 int acc ;
465446 int remote_num ;
466- unsigned char scancode [2 ];
447+ unsigned char scancode ;
448+ int i ;
449+
450+ /*
451+ * data[0] = 0x14
452+ * data[1] = data[2] + data[3] + 0xd5 (a checksum byte)
453+ * data[2] = the key code (with toggle bit in MSB with some models)
454+ * data[3] = channel << 4 (the low 4 bits must be zero)
455+ */
467456
468457 /* Deal with strange looking inputs */
469458 if ( (urb -> actual_length != 4 ) || (data [0 ] != 0x14 ) ||
@@ -472,6 +461,13 @@ static void ati_remote_input_report(struct urb *urb)
472461 return ;
473462 }
474463
464+ if (data [1 ] != ((data [2 ] + data [3 ] + 0xd5 ) & 0xff )) {
465+ dbginfo (& ati_remote -> interface -> dev ,
466+ "wrong checksum in input: %02x %02x %02x %02x\n" ,
467+ data [0 ], data [1 ], data [2 ], data [3 ]);
468+ return ;
469+ }
470+
475471 /* Mask unwanted remote channels. */
476472 /* note: remote_num is 0-based, channel 1 on remote == 0 here */
477473 remote_num = (data [3 ] >> 4 ) & 0x0f ;
@@ -482,31 +478,30 @@ static void ati_remote_input_report(struct urb *urb)
482478 return ;
483479 }
484480
485- scancode [0 ] = (((data [1 ] - ((remote_num + 1 ) << 4 )) & 0xf0 ) | (data [1 ] & 0x0f ));
486-
487481 /*
488- * Some devices (e.g. SnapStream Firefly) use 8080 as toggle code,
489- * so we have to clear them. The first bit is a bit tricky as the
490- * "non-toggled" state depends on remote_num, so we xor it with the
491- * second bit which is only used for toggle.
482+ * MSB is a toggle code, though only used by some devices
483+ * (e.g. SnapStream Firefly)
492484 */
493- scancode [0 ] ^= (data [2 ] & 0x80 );
494-
495- scancode [1 ] = data [2 ] & ~0x80 ;
485+ scancode = data [2 ] & 0x7f ;
496486
497- /* Look up event code index in mouse translation table. */
498- index = ati_remote_event_lookup (remote_num , scancode [0 ], scancode [1 ]);
487+ /* Look up event code index in the mouse translation table. */
488+ for (i = 0 ; ati_remote_tbl [i ].kind != KIND_END ; i ++ ) {
489+ if (scancode == ati_remote_tbl [i ].data ) {
490+ index = i ;
491+ break ;
492+ }
493+ }
499494
500495 if (index >= 0 ) {
501496 dbginfo (& ati_remote -> interface -> dev ,
502- "channel 0x%02x; mouse data %02x,%02x ; index %d; keycode %d\n" ,
503- remote_num , data [1 ], data [ 2 ], index , ati_remote_tbl [index ].code );
497+ "channel 0x%02x; mouse data %02x; index %d; keycode %d\n" ,
498+ remote_num , data [2 ], index , ati_remote_tbl [index ].code );
504499 if (!dev )
505500 return ; /* no mouse device */
506501 } else
507502 dbginfo (& ati_remote -> interface -> dev ,
508- "channel 0x%02x; key data %02x,%02x, scancode %02x, %02x\n" ,
509- remote_num , data [1 ], data [ 2 ], scancode [ 0 ], scancode [ 1 ] );
503+ "channel 0x%02x; key data %02x, scancode %02x\n" ,
504+ remote_num , data [2 ], scancode );
510505
511506
512507 if (index >= 0 && ati_remote_tbl [index ].kind == KIND_LITERAL ) {
@@ -523,8 +518,7 @@ static void ati_remote_input_report(struct urb *urb)
523518 unsigned long now = jiffies ;
524519
525520 /* Filter duplicate events which happen "too close" together. */
526- if (ati_remote -> old_data [0 ] == data [1 ] &&
527- ati_remote -> old_data [1 ] == data [2 ] &&
521+ if (ati_remote -> old_data == data [2 ] &&
528522 time_before (now , ati_remote -> old_jiffies +
529523 msecs_to_jiffies (repeat_filter ))) {
530524 ati_remote -> repeat_count ++ ;
@@ -533,8 +527,7 @@ static void ati_remote_input_report(struct urb *urb)
533527 ati_remote -> first_jiffies = now ;
534528 }
535529
536- ati_remote -> old_data [0 ] = data [1 ];
537- ati_remote -> old_data [1 ] = data [2 ];
530+ ati_remote -> old_data = data [2 ];
538531 ati_remote -> old_jiffies = now ;
539532
540533 /* Ensure we skip at least the 4 first duplicate events (generated
@@ -549,14 +542,13 @@ static void ati_remote_input_report(struct urb *urb)
549542
550543 if (index < 0 ) {
551544 /* Not a mouse event, hand it to rc-core. */
552- u32 rc_code = (scancode [0 ] << 8 ) | scancode [1 ];
553545
554546 /*
555547 * We don't use the rc-core repeat handling yet as
556548 * it would cause ghost repeats which would be a
557549 * regression for this driver.
558550 */
559- rc_keydown_notimeout (ati_remote -> rdev , rc_code ,
551+ rc_keydown_notimeout (ati_remote -> rdev , scancode ,
560552 data [2 ]);
561553 rc_keyup (ati_remote -> rdev );
562554 return ;
@@ -607,8 +599,7 @@ static void ati_remote_input_report(struct urb *urb)
607599 input_sync (dev );
608600
609601 ati_remote -> old_jiffies = jiffies ;
610- ati_remote -> old_data [0 ] = data [1 ];
611- ati_remote -> old_data [1 ] = data [2 ];
602+ ati_remote -> old_data = data [2 ];
612603 }
613604}
614605
0 commit comments