--- zzzz-none-000/linux-3.10.107/drivers/media/rc/ati_remote.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/media/rc/ati_remote.c 2021-02-04 17:41:59.000000000 +0000 @@ -279,46 +279,42 @@ /* "Kinds" of messages sent from the hardware to the driver. */ #define KIND_END 0 -#define KIND_LITERAL 1 /* Simply pass to input system */ +#define KIND_LITERAL 1 /* Simply pass to input system as EV_KEY */ #define KIND_FILTERED 2 /* Add artificial key-up events, drop keyrepeats */ -#define KIND_LU 3 /* Directional keypad diagonals - left up, */ -#define KIND_RU 4 /* right up, */ -#define KIND_LD 5 /* left down, */ -#define KIND_RD 6 /* right down */ -#define KIND_ACCEL 7 /* Directional keypad - left, right, up, down.*/ +#define KIND_ACCEL 3 /* Translate to EV_REL mouse-move events */ /* Translation table from hardware messages to input events. */ static const struct { - short kind; - unsigned char data; - int type; - unsigned int code; - int value; + unsigned char kind; + unsigned char data; /* Raw key code from remote */ + unsigned short code; /* Input layer translation */ } ati_remote_tbl[] = { - /* Directional control pad axes */ - {KIND_ACCEL, 0x70, EV_REL, REL_X, -1}, /* left */ - {KIND_ACCEL, 0x71, EV_REL, REL_X, 1}, /* right */ - {KIND_ACCEL, 0x72, EV_REL, REL_Y, -1}, /* up */ - {KIND_ACCEL, 0x73, EV_REL, REL_Y, 1}, /* down */ + /* Directional control pad axes. Code is xxyy */ + {KIND_ACCEL, 0x70, 0xff00}, /* left */ + {KIND_ACCEL, 0x71, 0x0100}, /* right */ + {KIND_ACCEL, 0x72, 0x00ff}, /* up */ + {KIND_ACCEL, 0x73, 0x0001}, /* down */ + /* Directional control pad diagonals */ - {KIND_LU, 0x74, EV_REL, 0, 0}, /* left up */ - {KIND_RU, 0x75, EV_REL, 0, 0}, /* right up */ - {KIND_LD, 0x77, EV_REL, 0, 0}, /* left down */ - {KIND_RD, 0x76, EV_REL, 0, 0}, /* right down */ - - /* "Mouse button" buttons */ - {KIND_LITERAL, 0x78, EV_KEY, BTN_LEFT, 1}, /* left btn down */ - {KIND_LITERAL, 0x79, EV_KEY, BTN_LEFT, 0}, /* left btn up */ - {KIND_LITERAL, 0x7c, EV_KEY, BTN_RIGHT, 1},/* right btn down */ - {KIND_LITERAL, 0x7d, EV_KEY, BTN_RIGHT, 0},/* right btn up */ + {KIND_ACCEL, 0x74, 0xffff}, /* left up */ + {KIND_ACCEL, 0x75, 0x01ff}, /* right up */ + {KIND_ACCEL, 0x77, 0xff01}, /* left down */ + {KIND_ACCEL, 0x76, 0x0101}, /* right down */ + + /* "Mouse button" buttons. The code below uses the fact that the + * lsbit of the raw code is a down/up indicator. */ + {KIND_LITERAL, 0x78, BTN_LEFT}, /* left btn down */ + {KIND_LITERAL, 0x79, BTN_LEFT}, /* left btn up */ + {KIND_LITERAL, 0x7c, BTN_RIGHT},/* right btn down */ + {KIND_LITERAL, 0x7d, BTN_RIGHT},/* right btn up */ /* Artificial "doubleclick" events are generated by the hardware. * They are mapped to the "side" and "extra" mouse buttons here. */ - {KIND_FILTERED, 0x7a, EV_KEY, BTN_SIDE, 1}, /* left dblclick */ - {KIND_FILTERED, 0x7e, EV_KEY, BTN_EXTRA, 1},/* right dblclick */ + {KIND_FILTERED, 0x7a, BTN_SIDE}, /* left dblclick */ + {KIND_FILTERED, 0x7e, BTN_EXTRA},/* right dblclick */ /* Non-mouse events are handled by rc-core */ - {KIND_END, 0x00, EV_MAX + 1, 0, 0} + {KIND_END, 0x00, 0} }; /* @@ -493,7 +489,6 @@ unsigned char *data= ati_remote->inbuf; struct input_dev *dev = ati_remote->idev; int index = -1; - int acc; int remote_num; unsigned char scancode; u32 wheel_keycode = KEY_RESERVED; @@ -507,8 +502,9 @@ */ /* Deal with strange looking inputs */ - if ( (urb->actual_length != 4) || (data[0] != 0x14) || - ((data[3] & 0x0f) != 0x00) ) { + if ( urb->actual_length != 4 || data[0] != 0x14 || + data[1] != (unsigned char)(data[2] + data[3] + 0xD5) || + (data[3] & 0x0f) != 0x00) { ati_remote_dump(&urb->dev->dev, data, urb->actual_length); return; } @@ -524,9 +520,9 @@ remote_num = (data[3] >> 4) & 0x0f; if (channel_mask & (1 << (remote_num + 1))) { dbginfo(&ati_remote->interface->dev, - "Masked input from channel 0x%02x: data %02x,%02x, " + "Masked input from channel 0x%02x: data %02x, " "mask= 0x%02lx\n", - remote_num, data[1], data[2], channel_mask); + remote_num, data[2], channel_mask); return; } @@ -566,16 +562,16 @@ } if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) { - input_event(dev, ati_remote_tbl[index].type, - ati_remote_tbl[index].code, - ati_remote_tbl[index].value); - input_sync(dev); + /* + * The lsbit of the raw key code is a down/up flag. + * Invert it to match the input layer's conventions. + */ + input_event(dev, EV_KEY, ati_remote_tbl[index].code, + !(data[2] & 1)); ati_remote->old_jiffies = jiffies; - return; - } - if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) { + } else if (index < 0 || ati_remote_tbl[index].kind == KIND_FILTERED) { unsigned long now = jiffies; /* Filter duplicate events which happen "too close" together. */ @@ -588,12 +584,11 @@ ati_remote->first_jiffies = now; } - ati_remote->old_data = data[2]; ati_remote->old_jiffies = now; - /* Ensure we skip at least the 4 first duplicate events (generated - * by a single keypress), and continue skipping until repeat_delay - * msecs have passed + /* Ensure we skip at least the 4 first duplicate events + * (generated by a single keypress), and continue skipping + * until repeat_delay msecs have passed. */ if (ati_remote->repeat_count > 0 && (ati_remote->repeat_count < 5 || @@ -601,7 +596,10 @@ msecs_to_jiffies(repeat_delay)))) return; - if (index < 0) { + if (index >= 0) { + input_event(dev, EV_KEY, ati_remote_tbl[index].code, 1); + input_event(dev, EV_KEY, ati_remote_tbl[index].code, 0); + } else { /* Not a mouse event, hand it to rc-core. */ int count = 1; @@ -622,61 +620,37 @@ * it would cause ghost repeats which would be a * regression for this driver. */ - rc_keydown_notimeout(ati_remote->rdev, scancode, - data[2]); + rc_keydown_notimeout(ati_remote->rdev, RC_TYPE_OTHER, + scancode, data[2]); rc_keyup(ati_remote->rdev); } - return; + goto nosync; } - input_event(dev, ati_remote_tbl[index].type, - ati_remote_tbl[index].code, 1); - input_sync(dev); - input_event(dev, ati_remote_tbl[index].type, - ati_remote_tbl[index].code, 0); - input_sync(dev); - - } else { + } else if (ati_remote_tbl[index].kind == KIND_ACCEL) { + signed char dx = ati_remote_tbl[index].code >> 8; + signed char dy = ati_remote_tbl[index].code & 255; /* * Other event kinds are from the directional control pad, and * have an acceleration factor applied to them. Without this * acceleration, the control pad is mostly unusable. */ - acc = ati_remote_compute_accel(ati_remote); - - switch (ati_remote_tbl[index].kind) { - case KIND_ACCEL: - input_event(dev, ati_remote_tbl[index].type, - ati_remote_tbl[index].code, - ati_remote_tbl[index].value * acc); - break; - case KIND_LU: - input_report_rel(dev, REL_X, -acc); - input_report_rel(dev, REL_Y, -acc); - break; - case KIND_RU: - input_report_rel(dev, REL_X, acc); - input_report_rel(dev, REL_Y, -acc); - break; - case KIND_LD: - input_report_rel(dev, REL_X, -acc); - input_report_rel(dev, REL_Y, acc); - break; - case KIND_RD: - input_report_rel(dev, REL_X, acc); - input_report_rel(dev, REL_Y, acc); - break; - default: - dev_dbg(&ati_remote->interface->dev, - "ati_remote kind=%d\n", - ati_remote_tbl[index].kind); - } - input_sync(dev); - + int acc = ati_remote_compute_accel(ati_remote); + if (dx) + input_report_rel(dev, REL_X, dx * acc); + if (dy) + input_report_rel(dev, REL_Y, dy * acc); ati_remote->old_jiffies = jiffies; - ati_remote->old_data = data[2]; + + } else { + dev_dbg(&ati_remote->interface->dev, "ati_remote kind=%d\n", + ati_remote_tbl[index].kind); + return; } + input_sync(dev); +nosync: + ati_remote->old_data = data[2]; } /* @@ -763,8 +737,9 @@ BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA); idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) - if (ati_remote_tbl[i].type == EV_KEY) - set_bit(ati_remote_tbl[i].code, idev->keybit); + if (ati_remote_tbl[i].kind == KIND_LITERAL || + ati_remote_tbl[i].kind == KIND_FILTERED) + __set_bit(ati_remote_tbl[i].code, idev->keybit); input_set_drvdata(idev, ati_remote); @@ -784,7 +759,7 @@ rdev->priv = ati_remote; rdev->driver_type = RC_DRIVER_SCANCODE; - rdev->allowed_protos = RC_BIT_OTHER; + rdev->allowed_protocols = RC_BIT_OTHER; rdev->driver_name = "ati_remote"; rdev->open = ati_remote_rc_open;