aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2017-03-22 19:28:48 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2018-02-02 19:48:58 -0500
commitba667650c568d55f6b80be54951b098f86939f2d (patch)
tree31d33a3f7640d8d531d91a62904c4cb0b8774b5b /drivers/input
parent1ef8580539d0b9282b726a2c9b7aa25057040cfe (diff)
Input: psmouse - clean up code
- switch to using BIT() macros - use u8 instead of unsigned char for byte data - use input_set_capability() instead of manipulating capabilities bits directly - use sign_extend32() when extracting wheel data. - do not abuse -1 as error code, propagate errors from various calls. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/mouse/psmouse-base.c140
1 files changed, 77 insertions, 63 deletions
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 58a2cc7d592c..074bc647509d 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -14,6 +14,7 @@
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15#define psmouse_fmt(fmt) fmt 15#define psmouse_fmt(fmt) fmt
16 16
17#include <linux/bitops.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
@@ -23,6 +24,7 @@
23#include <linux/init.h> 24#include <linux/init.h>
24#include <linux/libps2.h> 25#include <linux/libps2.h>
25#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/types.h>
26 28
27#include "psmouse.h" 29#include "psmouse.h"
28#include "synaptics.h" 30#include "synaptics.h"
@@ -147,7 +149,7 @@ void psmouse_report_standard_packet(struct input_dev *dev, u8 *packet)
147psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse) 149psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
148{ 150{
149 struct input_dev *dev = psmouse->dev; 151 struct input_dev *dev = psmouse->dev;
150 unsigned char *packet = psmouse->packet; 152 u8 *packet = psmouse->packet;
151 153
152 if (psmouse->pktcnt < psmouse->pktsize) 154 if (psmouse->pktcnt < psmouse->pktsize)
153 return PSMOUSE_GOOD_DATA; 155 return PSMOUSE_GOOD_DATA;
@@ -157,39 +159,42 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
157 switch (psmouse->protocol->type) { 159 switch (psmouse->protocol->type) {
158 case PSMOUSE_IMPS: 160 case PSMOUSE_IMPS:
159 /* IntelliMouse has scroll wheel */ 161 /* IntelliMouse has scroll wheel */
160 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 162 input_report_rel(dev, REL_WHEEL, -(s8) packet[3]);
161 break; 163 break;
162 164
163 case PSMOUSE_IMEX: 165 case PSMOUSE_IMEX:
164 /* Scroll wheel and buttons on IntelliMouse Explorer */ 166 /* Scroll wheel and buttons on IntelliMouse Explorer */
165 switch (packet[3] & 0xC0) { 167 switch (packet[3] & 0xC0) {
166 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */ 168 case 0x80: /* vertical scroll on IntelliMouse Explorer 4.0 */
167 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); 169 input_report_rel(dev, REL_WHEEL,
170 -sign_extend32(packet[3], 5));
168 break; 171 break;
169 case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */ 172 case 0x40: /* horizontal scroll on IntelliMouse Explorer 4.0 */
170 input_report_rel(dev, REL_HWHEEL, (int) (packet[3] & 32) - (int) (packet[3] & 31)); 173 input_report_rel(dev, REL_HWHEEL,
174 -sign_extend32(packet[3], 5));
171 break; 175 break;
172 case 0x00: 176 case 0x00:
173 case 0xC0: 177 case 0xC0:
174 input_report_rel(dev, REL_WHEEL, (int) (packet[3] & 8) - (int) (packet[3] & 7)); 178 input_report_rel(dev, REL_WHEEL,
175 input_report_key(dev, BTN_SIDE, (packet[3] >> 4) & 1); 179 -sign_extend32(packet[3], 3));
176 input_report_key(dev, BTN_EXTRA, (packet[3] >> 5) & 1); 180 input_report_key(dev, BTN_SIDE, BIT(4));
181 input_report_key(dev, BTN_EXTRA, BIT(5));
177 break; 182 break;
178 } 183 }
179 break; 184 break;
180 185
181 case PSMOUSE_GENPS: 186 case PSMOUSE_GENPS:
182 /* Report scroll buttons on NetMice */ 187 /* Report scroll buttons on NetMice */
183 input_report_rel(dev, REL_WHEEL, -(signed char) packet[3]); 188 input_report_rel(dev, REL_WHEEL, -(s8) packet[3]);
184 189
185 /* Extra buttons on Genius NewNet 3D */ 190 /* Extra buttons on Genius NewNet 3D */
186 input_report_key(dev, BTN_SIDE, (packet[0] >> 6) & 1); 191 input_report_key(dev, BTN_SIDE, BIT(6));
187 input_report_key(dev, BTN_EXTRA, (packet[0] >> 7) & 1); 192 input_report_key(dev, BTN_EXTRA, BIT(7));
188 break; 193 break;
189 194
190 case PSMOUSE_THINKPS: 195 case PSMOUSE_THINKPS:
191 /* Extra button on ThinkingMouse */ 196 /* Extra button on ThinkingMouse */
192 input_report_key(dev, BTN_EXTRA, (packet[0] >> 3) & 1); 197 input_report_key(dev, BTN_EXTRA, BIT(3));
193 198
194 /* 199 /*
195 * Without this bit of weirdness moving up gives wildly 200 * Without this bit of weirdness moving up gives wildly
@@ -203,8 +208,8 @@ psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
203 * Cortron PS2 Trackball reports SIDE button in the 208 * Cortron PS2 Trackball reports SIDE button in the
204 * 4th bit of the first byte. 209 * 4th bit of the first byte.
205 */ 210 */
206 input_report_key(dev, BTN_SIDE, (packet[0] >> 3) & 1); 211 input_report_key(dev, BTN_SIDE, BIT(3));
207 packet[0] |= 0x08; 212 packet[0] |= BIT(3);
208 break; 213 break;
209 214
210 default: 215 default:
@@ -269,7 +274,7 @@ static int psmouse_handle_byte(struct psmouse *psmouse)
269 psmouse_notice(psmouse, 274 psmouse_notice(psmouse,
270 "issuing reconnect request\n"); 275 "issuing reconnect request\n");
271 serio_reconnect(psmouse->ps2dev.serio); 276 serio_reconnect(psmouse->ps2dev.serio);
272 return -1; 277 return -EIO;
273 } 278 }
274 } 279 }
275 psmouse->pktcnt = 0; 280 psmouse->pktcnt = 0;
@@ -320,7 +325,7 @@ static void psmouse_handle_oob_data(struct psmouse *psmouse, u8 data)
320 * for normal processing or gathering them as command response. 325 * for normal processing or gathering them as command response.
321 */ 326 */
322static irqreturn_t psmouse_interrupt(struct serio *serio, 327static irqreturn_t psmouse_interrupt(struct serio *serio,
323 unsigned char data, unsigned int flags) 328 u8 data, unsigned int flags)
324{ 329{
325 struct psmouse *psmouse = serio_get_drvdata(serio); 330 struct psmouse *psmouse = serio_get_drvdata(serio);
326 331
@@ -418,17 +423,20 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
418 * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu 423 * 0xE6 0xE8 rr 0xE8 ss 0xE8 tt 0xE8 uu where (rr*64)+(ss*16)+(tt*4)+uu
419 * is the command. 424 * is the command.
420 */ 425 */
421int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command) 426int psmouse_sliced_command(struct psmouse *psmouse, u8 command)
422{ 427{
423 int i; 428 int i;
429 int error;
424 430
425 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11)) 431 error = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_SETSCALE11);
426 return -1; 432 if (error)
433 return error;
427 434
428 for (i = 6; i >= 0; i -= 2) { 435 for (i = 6; i >= 0; i -= 2) {
429 unsigned char d = (command >> i) & 3; 436 u8 d = (command >> i) & 3;
430 if (ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES)) 437 error = ps2_command(&psmouse->ps2dev, &d, PSMOUSE_CMD_SETRES);
431 return -1; 438 if (error)
439 return error;
432 } 440 }
433 441
434 return 0; 442 return 0;
@@ -439,13 +447,15 @@ int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command)
439 */ 447 */
440int psmouse_reset(struct psmouse *psmouse) 448int psmouse_reset(struct psmouse *psmouse)
441{ 449{
442 unsigned char param[2]; 450 u8 param[2];
451 int error;
443 452
444 if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT)) 453 error = ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_RESET_BAT);
445 return -1; 454 if (error)
455 return error;
446 456
447 if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID) 457 if (param[0] != PSMOUSE_RET_BAT && param[1] != PSMOUSE_RET_ID)
448 return -1; 458 return -EIO;
449 459
450 return 0; 460 return 0;
451} 461}
@@ -455,8 +465,8 @@ int psmouse_reset(struct psmouse *psmouse)
455 */ 465 */
456void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution) 466void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
457{ 467{
458 static const unsigned char params[] = { 0, 1, 2, 2, 3 }; 468 static const u8 params[] = { 0, 1, 2, 2, 3 };
459 unsigned char p; 469 u8 p;
460 470
461 if (resolution == 0 || resolution > 200) 471 if (resolution == 0 || resolution > 200)
462 resolution = 200; 472 resolution = 200;
@@ -471,11 +481,12 @@ void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution)
471 */ 481 */
472static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate) 482static void psmouse_set_rate(struct psmouse *psmouse, unsigned int rate)
473{ 483{
474 static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 }; 484 static const u8 rates[] = { 200, 100, 80, 60, 40, 20, 10, 0 };
475 unsigned char r; 485 u8 r;
476 int i = 0; 486 int i = 0;
477 487
478 while (rates[i] > rate) i++; 488 while (rates[i] > rate)
489 i++;
479 r = rates[i]; 490 r = rates[i];
480 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE); 491 ps2_command(&psmouse->ps2dev, &r, PSMOUSE_CMD_SETRATE);
481 psmouse->rate = r; 492 psmouse->rate = r;
@@ -547,7 +558,7 @@ bool psmouse_matches_pnp_id(struct psmouse *psmouse, const char * const ids[])
547static int genius_detect(struct psmouse *psmouse, bool set_properties) 558static int genius_detect(struct psmouse *psmouse, bool set_properties)
548{ 559{
549 struct ps2dev *ps2dev = &psmouse->ps2dev; 560 struct ps2dev *ps2dev = &psmouse->ps2dev;
550 unsigned char param[4]; 561 u8 param[4];
551 562
552 param[0] = 3; 563 param[0] = 3;
553 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 564 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
@@ -557,7 +568,7 @@ static int genius_detect(struct psmouse *psmouse, bool set_properties)
557 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO); 568 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO);
558 569
559 if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55) 570 if (param[0] != 0x00 || param[1] != 0x33 || param[2] != 0x55)
560 return -1; 571 return -ENODEV;
561 572
562 if (set_properties) { 573 if (set_properties) {
563 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 574 __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
@@ -579,7 +590,7 @@ static int genius_detect(struct psmouse *psmouse, bool set_properties)
579static int intellimouse_detect(struct psmouse *psmouse, bool set_properties) 590static int intellimouse_detect(struct psmouse *psmouse, bool set_properties)
580{ 591{
581 struct ps2dev *ps2dev = &psmouse->ps2dev; 592 struct ps2dev *ps2dev = &psmouse->ps2dev;
582 unsigned char param[2]; 593 u8 param[2];
583 594
584 param[0] = 200; 595 param[0] = 200;
585 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE); 596 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRATE);
@@ -590,7 +601,7 @@ static int intellimouse_detect(struct psmouse *psmouse, bool set_properties)
590 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 601 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
591 602
592 if (param[0] != 3) 603 if (param[0] != 3)
593 return -1; 604 return -ENODEV;
594 605
595 if (set_properties) { 606 if (set_properties) {
596 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 607 __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
@@ -612,7 +623,7 @@ static int intellimouse_detect(struct psmouse *psmouse, bool set_properties)
612static int im_explorer_detect(struct psmouse *psmouse, bool set_properties) 623static int im_explorer_detect(struct psmouse *psmouse, bool set_properties)
613{ 624{
614 struct ps2dev *ps2dev = &psmouse->ps2dev; 625 struct ps2dev *ps2dev = &psmouse->ps2dev;
615 unsigned char param[2]; 626 u8 param[2];
616 627
617 intellimouse_detect(psmouse, 0); 628 intellimouse_detect(psmouse, 0);
618 629
@@ -625,7 +636,7 @@ static int im_explorer_detect(struct psmouse *psmouse, bool set_properties)
625 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 636 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
626 637
627 if (param[0] != 4) 638 if (param[0] != 4)
628 return -1; 639 return -ENODEV;
629 640
630 /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */ 641 /* Magic to enable horizontal scrolling on IntelliMouse 4.0 */
631 param[0] = 200; 642 param[0] = 200;
@@ -658,8 +669,8 @@ static int im_explorer_detect(struct psmouse *psmouse, bool set_properties)
658static int thinking_detect(struct psmouse *psmouse, bool set_properties) 669static int thinking_detect(struct psmouse *psmouse, bool set_properties)
659{ 670{
660 struct ps2dev *ps2dev = &psmouse->ps2dev; 671 struct ps2dev *ps2dev = &psmouse->ps2dev;
661 unsigned char param[2]; 672 u8 param[2];
662 static const unsigned char seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 }; 673 static const u8 seq[] = { 20, 60, 40, 20, 20, 60, 40, 20, 20 };
663 int i; 674 int i;
664 675
665 param[0] = 10; 676 param[0] = 10;
@@ -673,7 +684,7 @@ static int thinking_detect(struct psmouse *psmouse, bool set_properties)
673 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID); 684 ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
674 685
675 if (param[0] != 2) 686 if (param[0] != 2)
676 return -1; 687 return -ENODEV;
677 688
678 if (set_properties) { 689 if (set_properties) {
679 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 690 __set_bit(BTN_MIDDLE, psmouse->dev->keybit);
@@ -701,7 +712,7 @@ static int ps2bare_detect(struct psmouse *psmouse, bool set_properties)
701 * We have no way of figuring true number of buttons so let's 712 * We have no way of figuring true number of buttons so let's
702 * assume that the device has 3. 713 * assume that the device has 3.
703 */ 714 */
704 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); 715 input_set_capability(psmouse->dev, EV_KEY, BTN_MIDDLE);
705 } 716 }
706 717
707 return 0; 718 return 0;
@@ -956,20 +967,17 @@ static void psmouse_apply_defaults(struct psmouse *psmouse)
956{ 967{
957 struct input_dev *input_dev = psmouse->dev; 968 struct input_dev *input_dev = psmouse->dev;
958 969
959 memset(input_dev->evbit, 0, sizeof(input_dev->evbit)); 970 bitmap_zero(input_dev->evbit, EV_CNT);
960 memset(input_dev->keybit, 0, sizeof(input_dev->keybit)); 971 bitmap_zero(input_dev->keybit, KEY_CNT);
961 memset(input_dev->relbit, 0, sizeof(input_dev->relbit)); 972 bitmap_zero(input_dev->relbit, REL_CNT);
962 memset(input_dev->absbit, 0, sizeof(input_dev->absbit)); 973 bitmap_zero(input_dev->absbit, ABS_CNT);
963 memset(input_dev->mscbit, 0, sizeof(input_dev->mscbit)); 974 bitmap_zero(input_dev->mscbit, MSC_CNT);
964
965 __set_bit(EV_KEY, input_dev->evbit);
966 __set_bit(EV_REL, input_dev->evbit);
967 975
968 __set_bit(BTN_LEFT, input_dev->keybit); 976 input_set_capability(input_dev, EV_KEY, BTN_LEFT);
969 __set_bit(BTN_RIGHT, input_dev->keybit); 977 input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
970 978
971 __set_bit(REL_X, input_dev->relbit); 979 input_set_capability(input_dev, EV_REL, REL_X);
972 __set_bit(REL_Y, input_dev->relbit); 980 input_set_capability(input_dev, EV_REL, REL_Y);
973 981
974 __set_bit(INPUT_PROP_POINTER, input_dev->propbit); 982 __set_bit(INPUT_PROP_POINTER, input_dev->propbit);
975 983
@@ -1231,7 +1239,8 @@ static int psmouse_extensions(struct psmouse *psmouse,
1231static int psmouse_probe(struct psmouse *psmouse) 1239static int psmouse_probe(struct psmouse *psmouse)
1232{ 1240{
1233 struct ps2dev *ps2dev = &psmouse->ps2dev; 1241 struct ps2dev *ps2dev = &psmouse->ps2dev;
1234 unsigned char param[2]; 1242 u8 param[2];
1243 int error;
1235 1244
1236 /* 1245 /*
1237 * First, we check if it's a mouse. It should send 0x00 or 0x03 in 1246 * First, we check if it's a mouse. It should send 0x00 or 0x03 in
@@ -1240,20 +1249,22 @@ static int psmouse_probe(struct psmouse *psmouse)
1240 * subsequent ID queries, probably due to a firmware bug. 1249 * subsequent ID queries, probably due to a firmware bug.
1241 */ 1250 */
1242 param[0] = 0xa5; 1251 param[0] = 0xa5;
1243 if (ps2_command(ps2dev, param, PSMOUSE_CMD_GETID)) 1252 error = ps2_command(ps2dev, param, PSMOUSE_CMD_GETID);
1244 return -1; 1253 if (error)
1254 return error;
1245 1255
1246 if (param[0] != 0x00 && param[0] != 0x03 && 1256 if (param[0] != 0x00 && param[0] != 0x03 &&
1247 param[0] != 0x04 && param[0] != 0xff) 1257 param[0] != 0x04 && param[0] != 0xff)
1248 return -1; 1258 return -ENODEV;
1249 1259
1250 /* 1260 /*
1251 * Then we reset and disable the mouse so that it doesn't generate 1261 * Then we reset and disable the mouse so that it doesn't generate
1252 * events. 1262 * events.
1253 */ 1263 */
1254 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS)) 1264 error = ps2_command(ps2dev, NULL, PSMOUSE_CMD_RESET_DIS);
1255 psmouse_warn(psmouse, "Failed to reset mouse on %s\n", 1265 if (error)
1256 ps2dev->serio->phys); 1266 psmouse_warn(psmouse, "Failed to reset mouse on %s: %d\n",
1267 ps2dev->serio->phys, error);
1257 1268
1258 return 0; 1269 return 0;
1259} 1270}
@@ -1294,10 +1305,13 @@ int psmouse_activate(struct psmouse *psmouse)
1294 */ 1305 */
1295int psmouse_deactivate(struct psmouse *psmouse) 1306int psmouse_deactivate(struct psmouse *psmouse)
1296{ 1307{
1297 if (ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE)) { 1308 int error;
1298 psmouse_warn(psmouse, "Failed to deactivate mouse on %s\n", 1309
1299 psmouse->ps2dev.serio->phys); 1310 error = ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_DISABLE);
1300 return -1; 1311 if (error) {
1312 psmouse_warn(psmouse, "Failed to deactivate mouse on %s: %d\n",
1313 psmouse->ps2dev.serio->phys, error);
1314 return error;
1301 } 1315 }
1302 1316
1303 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1317 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);