Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: psmouse - create helper for reporting standard buttons/motion

Many protocol driver re-implement code to parse buttons or motion data from
the standard PS/2 protocol. Let's split the parsing into separate
functions and reuse them in protocol drivers.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+50 -71
+7 -23
drivers/input/mouse/alps.c
··· 827 827 unsigned char *packet = psmouse->packet; 828 828 struct input_dev *dev = psmouse->dev; 829 829 struct input_dev *dev2 = priv->dev2; 830 - int x, y, z, left, right, middle; 830 + int x, y, z; 831 831 832 832 /* 833 833 * We can use Byte5 to distinguish if the packet is from Touchpad ··· 847 847 x = packet[1] | ((packet[3] & 0x20) << 2); 848 848 y = packet[2] | ((packet[3] & 0x40) << 1); 849 849 z = packet[4]; 850 - left = packet[3] & 0x01; 851 - right = packet[3] & 0x02; 852 - middle = packet[3] & 0x04; 853 850 854 851 /* To prevent the cursor jump when finger lifted */ 855 852 if (x == 0x7F && y == 0x7F && z == 0x7F) ··· 856 859 input_report_rel(dev2, REL_X, (char)x / 4); 857 860 input_report_rel(dev2, REL_Y, -((char)y / 4)); 858 861 859 - input_report_key(dev2, BTN_LEFT, left); 860 - input_report_key(dev2, BTN_RIGHT, right); 861 - input_report_key(dev2, BTN_MIDDLE, middle); 862 + psmouse_report_standard_buttons(dev2, packet[3]); 862 863 863 864 input_sync(dev2); 864 865 return; ··· 866 871 x = packet[1] | ((packet[3] & 0x78) << 4); 867 872 y = packet[2] | ((packet[4] & 0x78) << 4); 868 873 z = packet[5]; 869 - left = packet[3] & 0x01; 870 - right = packet[3] & 0x02; 871 874 872 875 if (z > 30) 873 876 input_report_key(dev, BTN_TOUCH, 1); ··· 881 888 input_report_key(dev, BTN_TOOL_FINGER, z > 0); 882 889 883 890 /* v6 touchpad does not have middle button */ 884 - input_report_key(dev, BTN_LEFT, left); 885 - input_report_key(dev, BTN_RIGHT, right); 891 + packet[3] &= ~BIT(2); 892 + psmouse_report_standard_buttons(dev2, packet[3]); 886 893 887 894 input_sync(dev); 888 895 } ··· 1091 1098 struct alps_data *priv = psmouse->private; 1092 1099 unsigned char *packet = psmouse->packet; 1093 1100 struct input_dev *dev2 = priv->dev2; 1094 - int x, y, z, left, right, middle; 1101 + int x, y, z; 1095 1102 1096 1103 /* It should be a DualPoint when received trackstick packet */ 1097 1104 if (!(priv->flags & ALPS_DUALPOINT)) { ··· 1105 1112 ((packet[3] & 0x20) << 1); 1106 1113 z = (packet[5] & 0x3f) | ((packet[3] & 0x80) >> 1); 1107 1114 1108 - left = (packet[1] & 0x01); 1109 - right = (packet[1] & 0x02) >> 1; 1110 - middle = (packet[1] & 0x04) >> 2; 1111 - 1112 1115 input_report_rel(dev2, REL_X, (char)x); 1113 1116 input_report_rel(dev2, REL_Y, -((char)y)); 1114 1117 1115 - input_report_key(dev2, BTN_LEFT, left); 1116 - input_report_key(dev2, BTN_RIGHT, right); 1117 - input_report_key(dev2, BTN_MIDDLE, middle); 1118 + psmouse_report_standard_buttons(dev2, packet[1]); 1118 1119 1119 1120 input_sync(dev2); 1120 1121 } ··· 1490 1503 alps_report_buttons(dev, dev2, 1491 1504 packet[0] & 1, packet[0] & 2, packet[0] & 4); 1492 1505 1493 - input_report_rel(dev, REL_X, 1494 - packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0); 1495 - input_report_rel(dev, REL_Y, 1496 - packet[2] ? ((packet[0] << 3) & 0x100) - packet[2] : 0); 1506 + psmouse_report_standard_motion(dev, packet); 1497 1507 1498 1508 input_sync(dev); 1499 1509 }
+10 -18
drivers/input/mouse/elantech.c
··· 279 279 input_report_key(dev, BTN_TOOL_FINGER, fingers == 1); 280 280 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); 281 281 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 282 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 283 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 282 + 283 + psmouse_report_standard_buttons(dev, packet[0]); 284 284 285 285 if (etd->fw_version < 0x020000 && 286 286 (etd->capabilities[0] & ETP_CAP_HAS_ROCKER)) { ··· 390 390 input_report_key(dev, BTN_TOOL_DOUBLETAP, fingers == 2); 391 391 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 392 392 input_report_key(dev, BTN_TOOL_QUADTAP, fingers == 4); 393 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 394 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 393 + psmouse_report_standard_buttons(dev, packet[0]); 395 394 if (etd->reports_pressure) { 396 395 input_report_abs(dev, ABS_PRESSURE, pres); 397 396 input_report_abs(dev, ABS_TOOL_WIDTH, width); ··· 433 434 x = packet[4] - (int)((packet[1]^0x80) << 1); 434 435 y = (int)((packet[2]^0x80) << 1) - packet[5]; 435 436 436 - input_report_key(tp_dev, BTN_LEFT, packet[0] & 0x01); 437 - input_report_key(tp_dev, BTN_RIGHT, packet[0] & 0x02); 438 - input_report_key(tp_dev, BTN_MIDDLE, packet[0] & 0x04); 437 + psmouse_report_standard_buttons(tp_dev, packet[0]); 439 438 440 439 input_report_rel(tp_dev, REL_X, x); 441 440 input_report_rel(tp_dev, REL_Y, y); ··· 523 526 input_report_key(dev, BTN_TOOL_TRIPLETAP, fingers == 3); 524 527 525 528 /* For clickpads map both buttons to BTN_LEFT */ 526 - if (etd->fw_version & 0x001000) { 529 + if (etd->fw_version & 0x001000) 527 530 input_report_key(dev, BTN_LEFT, packet[0] & 0x03); 528 - } else { 529 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 530 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 531 - } 531 + else 532 + psmouse_report_standard_buttons(dev, packet[0]); 532 533 533 534 input_report_abs(dev, ABS_PRESSURE, pres); 534 535 input_report_abs(dev, ABS_TOOL_WIDTH, width); ··· 541 546 unsigned char *packet = psmouse->packet; 542 547 543 548 /* For clickpads map both buttons to BTN_LEFT */ 544 - if (etd->fw_version & 0x001000) { 549 + if (etd->fw_version & 0x001000) 545 550 input_report_key(dev, BTN_LEFT, packet[0] & 0x03); 546 - } else { 547 - input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 548 - input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 549 - input_report_key(dev, BTN_MIDDLE, packet[0] & 0x04); 550 - } 551 + else 552 + psmouse_report_standard_buttons(dev, packet[0]); 551 553 552 554 input_mt_report_pointer_emulation(dev, true); 553 555 input_sync(dev);
+4 -8
drivers/input/mouse/lifebook.c
··· 188 188 } 189 189 190 190 if (dev2) { 191 - if (relative_packet) { 192 - input_report_rel(dev2, REL_X, 193 - ((packet[0] & 0x10) ? packet[1] - 256 : packet[1])); 194 - input_report_rel(dev2, REL_Y, 195 - -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2])); 196 - } 197 - input_report_key(dev2, BTN_LEFT, packet[0] & 0x01); 198 - input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02); 191 + if (relative_packet) 192 + psmouse_report_standard_motion(dev2, packet); 193 + 194 + psmouse_report_standard_buttons(dev2, packet[0]); 199 195 input_sync(dev2); 200 196 } 201 197
+4 -6
drivers/input/mouse/logips2pp.c
··· 88 88 (packet[1] >> 4) | (packet[0] & 0x30)); 89 89 break; 90 90 } 91 + 92 + psmouse_report_standard_buttons(dev, packet[0]); 93 + 91 94 } else { 92 95 /* Standard PS/2 motion data */ 93 - input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); 94 - input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); 96 + psmouse_report_standard_packet(dev, packet); 95 97 } 96 - 97 - input_report_key(dev, BTN_LEFT, packet[0] & 1); 98 - input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); 99 - input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); 100 98 101 99 input_sync(dev); 102 100
+20 -6
drivers/input/mouse/psmouse-base.c
··· 116 116 117 117 static struct workqueue_struct *kpsmoused_wq; 118 118 119 - static void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons) 119 + void psmouse_report_standard_buttons(struct input_dev *dev, u8 buttons) 120 120 { 121 121 input_report_key(dev, BTN_LEFT, buttons & BIT(0)); 122 122 input_report_key(dev, BTN_MIDDLE, buttons & BIT(2)); 123 123 input_report_key(dev, BTN_RIGHT, buttons & BIT(1)); 124 + } 125 + 126 + void psmouse_report_standard_motion(struct input_dev *dev, u8 *packet) 127 + { 128 + int x, y; 129 + 130 + x = packet[1] ? packet[1] - ((packet[0] << 4) & 0x100) : 0; 131 + y = packet[2] ? packet[2] - ((packet[0] << 3) & 0x100) : 0; 132 + 133 + input_report_rel(dev, REL_X, x); 134 + input_report_rel(dev, REL_Y, -y); 135 + } 136 + 137 + void psmouse_report_standard_packet(struct input_dev *dev, u8 *packet) 138 + { 139 + psmouse_report_standard_buttons(dev, packet[0]); 140 + psmouse_report_standard_motion(dev, packet); 124 141 } 125 142 126 143 /* ··· 212 195 } 213 196 214 197 /* Generic PS/2 Mouse */ 215 - psmouse_report_standard_buttons(dev, 216 - packet[0] | psmouse->extra_buttons); 217 - 218 - input_report_rel(dev, REL_X, packet[1] ? (int) packet[1] - (int) ((packet[0] << 4) & 0x100) : 0); 219 - input_report_rel(dev, REL_Y, packet[2] ? (int) ((packet[0] << 3) & 0x100) - (int) packet[2] : 0); 198 + packet[0] |= psmouse->extra_buttons; 199 + psmouse_report_standard_packet(dev, packet); 220 200 221 201 input_sync(dev); 222 202
+4
drivers/input/mouse/psmouse.h
··· 140 140 int psmouse_deactivate(struct psmouse *psmouse); 141 141 bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[]); 142 142 143 + void psmouse_report_standard_buttons(struct input_dev *, u8 buttons); 144 + void psmouse_report_standard_motion(struct input_dev *, u8 *packet); 145 + void psmouse_report_standard_packet(struct input_dev *, u8 *packet); 146 + 143 147 struct psmouse_attribute { 144 148 struct device_attribute dattr; 145 149 void *data;
+1 -10
drivers/input/mouse/sentelic.c
··· 710 710 unsigned char *packet = psmouse->packet; 711 711 unsigned char button_status = 0, lscroll = 0, rscroll = 0; 712 712 unsigned short abs_x, abs_y, fgrs = 0; 713 - int rel_x, rel_y; 714 713 715 714 if (psmouse->pktcnt < 4) 716 715 return PSMOUSE_GOOD_DATA; ··· 839 840 /* 840 841 * Standard PS/2 Mouse 841 842 */ 842 - input_report_key(dev, BTN_LEFT, packet[0] & 1); 843 - input_report_key(dev, BTN_MIDDLE, (packet[0] >> 2) & 1); 844 - input_report_key(dev, BTN_RIGHT, (packet[0] >> 1) & 1); 845 - 846 - rel_x = packet[1] ? (int)packet[1] - (int)((packet[0] << 4) & 0x100) : 0; 847 - rel_y = packet[2] ? (int)((packet[0] << 3) & 0x100) - (int)packet[2] : 0; 848 - 849 - input_report_rel(dev, REL_X, rel_x); 850 - input_report_rel(dev, REL_Y, rel_y); 843 + psmouse_report_standard_packet(dev, packet); 851 844 break; 852 845 } 853 846