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

Input: appletouch - miscellaneous code cleanups

This patch does some code cleanups in appletouch:
* useless comment removal
* make almost checkpatch clean
* make sparse clean

Signed-off-by: Sven Anders <anders@anduras.de>
[jberg: most of the changes including removing much of the original patch]
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Johannes Berg and committed by
Dmitry Torokhov
7dce869f 5b7c407b

+100 -73
+100 -73
drivers/input/mouse/appletouch.c
··· 2 2 * Apple USB Touchpad (for post-February 2005 PowerBooks and MacBooks) driver 3 3 * 4 4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) 5 - * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net) 5 + * Copyright (C) 2005-2008 Johannes Berg (johannes@sipsolutions.net) 6 6 * Copyright (C) 2005 Stelian Pop (stelian@popies.net) 7 7 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de) 8 8 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com) 9 9 * Copyright (C) 2005 Michael Hanselmann (linux-kernel@hansmi.ch) 10 10 * Copyright (C) 2006 Nicolas Boichat (nicolas@boichat.ch) 11 + * Copyright (C) 2007-2008 Sven Anders (anders@anduras.de) 11 12 * 12 13 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs. 13 14 * ··· 39 38 #define APPLE_VENDOR_ID 0x05AC 40 39 41 40 /* These names come from Info.plist in AppleUSBTrackpad.kext */ 41 + 42 + /* PowerBooks Feb 2005 / iBooks */ 42 43 #define FOUNTAIN_ANSI_PRODUCT_ID 0x020E 43 44 #define FOUNTAIN_ISO_PRODUCT_ID 0x020F 44 45 ··· 48 45 49 46 #define GEYSER1_TP_ONLY_PRODUCT_ID 0x030B 50 47 51 - #define GEYSER_ANSI_PRODUCT_ID 0x0214 52 - #define GEYSER_ISO_PRODUCT_ID 0x0215 53 - #define GEYSER_JIS_PRODUCT_ID 0x0216 48 + /* PowerBooks Oct 2005 */ 49 + #define GEYSER2_ANSI_PRODUCT_ID 0x0214 50 + #define GEYSER2_ISO_PRODUCT_ID 0x0215 51 + #define GEYSER2_JIS_PRODUCT_ID 0x0216 54 52 55 53 /* MacBook devices */ 56 54 #define GEYSER3_ANSI_PRODUCT_ID 0x0217 ··· 59 55 #define GEYSER3_JIS_PRODUCT_ID 0x0219 60 56 61 57 /* 62 - * Geyser IV: same as Geyser III according to Info.plist in AppleUSBTrackpad.kext 58 + * Geyser IV: same as Geyser III according to Info.plist in OSX's 59 + * AppleUSBTrackpad.kext 63 60 * -> same IOClass (AppleUSBGrIIITrackpad), same acceleration tables 64 61 */ 65 - #define GEYSER4_ANSI_PRODUCT_ID 0x021A 66 - #define GEYSER4_ISO_PRODUCT_ID 0x021B 67 - #define GEYSER4_JIS_PRODUCT_ID 0x021C 62 + #define GEYSER4_ANSI_PRODUCT_ID 0x021A 63 + #define GEYSER4_ISO_PRODUCT_ID 0x021B 64 + #define GEYSER4_JIS_PRODUCT_ID 0x021C 68 65 66 + /* Macbook3,1 devices */ 69 67 #define GEYSER4_HF_ANSI_PRODUCT_ID 0x0229 70 68 #define GEYSER4_HF_ISO_PRODUCT_ID 0x022A 71 69 #define GEYSER4_HF_JIS_PRODUCT_ID 0x022B ··· 83 77 84 78 /* table of devices that work with this driver */ 85 79 static struct usb_device_id atp_table [] = { 80 + /* PowerBooks Feb 2005, iBooks G4 */ 86 81 { ATP_DEVICE(FOUNTAIN_ANSI_PRODUCT_ID) }, 87 82 { ATP_DEVICE(FOUNTAIN_ISO_PRODUCT_ID) }, 88 83 { ATP_DEVICE(FOUNTAIN_TP_ONLY_PRODUCT_ID) }, 89 84 { ATP_DEVICE(GEYSER1_TP_ONLY_PRODUCT_ID) }, 90 85 91 86 /* PowerBooks Oct 2005 */ 92 - { ATP_DEVICE(GEYSER_ANSI_PRODUCT_ID) }, 93 - { ATP_DEVICE(GEYSER_ISO_PRODUCT_ID) }, 94 - { ATP_DEVICE(GEYSER_JIS_PRODUCT_ID) }, 87 + { ATP_DEVICE(GEYSER2_ANSI_PRODUCT_ID) }, 88 + { ATP_DEVICE(GEYSER2_ISO_PRODUCT_ID) }, 89 + { ATP_DEVICE(GEYSER2_JIS_PRODUCT_ID) }, 95 90 96 91 /* Core Duo MacBook & MacBook Pro */ 97 92 { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) }, ··· 104 97 { ATP_DEVICE(GEYSER4_ISO_PRODUCT_ID) }, 105 98 { ATP_DEVICE(GEYSER4_JIS_PRODUCT_ID) }, 106 99 100 + /* Core2 Duo MacBook3,1 */ 107 101 { ATP_DEVICE(GEYSER4_HF_ANSI_PRODUCT_ID) }, 108 102 { ATP_DEVICE(GEYSER4_HF_ISO_PRODUCT_ID) }, 109 103 { ATP_DEVICE(GEYSER4_HF_JIS_PRODUCT_ID) }, ··· 112 104 /* Terminating entry */ 113 105 { } 114 106 }; 115 - MODULE_DEVICE_TABLE (usb, atp_table); 107 + MODULE_DEVICE_TABLE(usb, atp_table); 116 108 117 109 /* 118 110 * number of sensors. Note that only 16 instead of 26 X (horizontal) ··· 155 147 /* Structure to hold all of our device specific stuff */ 156 148 struct atp { 157 149 char phys[64]; 158 - struct usb_device * udev; /* usb device */ 159 - struct urb * urb; /* usb request block */ 160 - signed char * data; /* transferred data */ 161 - struct input_dev * input; /* input dev */ 162 - unsigned char open; /* non-zero if opened */ 163 - unsigned char valid; /* are the sensors valid ? */ 164 - unsigned char size_detect_done; 165 - unsigned char overflowwarn; /* overflow warning printed? */ 150 + struct usb_device *udev; /* usb device */ 151 + struct urb *urb; /* usb request block */ 152 + signed char *data; /* transferred data */ 153 + struct input_dev *input; /* input dev */ 154 + bool open; 155 + bool valid; /* are the samples valid? */ 156 + bool size_detect_done; 157 + bool overflow_warned; 166 158 int x_old; /* last reported x/y, */ 167 159 int y_old; /* used for smoothing */ 168 - /* current value of the sensors */ 169 160 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS]; 170 - /* last value of the sensors */ 171 161 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS]; 172 - /* accumulated sensors */ 173 162 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 174 - int datalen; /* size of an USB urb transfer */ 175 - int idlecount; /* number of empty packets */ 176 - struct work_struct work; 163 + int datalen; /* size of USB transfer */ 164 + int idlecount; /* number of empty packets */ 165 + struct work_struct work; 177 166 }; 178 167 179 168 #define dbg_dump(msg, tab) \ 180 169 if (debug > 1) { \ 181 - int i; \ 182 - printk("appletouch: %s %lld", msg, (long long)jiffies); \ 183 - for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \ 184 - printk(" %02x", tab[i]); \ 170 + int __i; \ 171 + printk(KERN_DEBUG "appletouch: %s", msg); \ 172 + for (__i = 0; __i < ATP_XSENSORS + ATP_YSENSORS; __i++) \ 173 + printk(" %02x", tab[__i]); \ 185 174 printk("\n"); \ 186 175 } 187 176 188 177 #define dprintk(format, a...) \ 189 178 do { \ 190 - if (debug) printk(KERN_DEBUG format, ##a); \ 179 + if (debug) \ 180 + printk(KERN_DEBUG format, ##a); \ 191 181 } while (0) 192 182 193 - MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Michael Hanselmann"); 194 - MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver"); 183 + MODULE_AUTHOR("Johannes Berg"); 184 + MODULE_AUTHOR("Stelian Pop"); 185 + MODULE_AUTHOR("Frank Arnold"); 186 + MODULE_AUTHOR("Michael Hanselmann"); 187 + MODULE_AUTHOR("Sven Anders"); 188 + MODULE_DESCRIPTION("Apple PowerBook and MacBook USB touchpad driver"); 195 189 MODULE_LICENSE("GPL"); 196 190 197 191 /* ··· 201 191 */ 202 192 static int threshold = ATP_THRESHOLD; 203 193 module_param(threshold, int, 0644); 204 - MODULE_PARM_DESC(threshold, "Discards any change in data from a sensor (trackpad has hundreds of these sensors) less than this value"); 194 + MODULE_PARM_DESC(threshold, "Discard any change in data from a sensor" 195 + " (the trackpad has many of these sensors)" 196 + " less than this value."); 205 197 206 - static int debug = 1; 198 + static int debug; 207 199 module_param(debug, int, 0644); 208 200 MODULE_PARM_DESC(debug, "Activate debugging output"); 209 201 ··· 223 211 { 224 212 u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct); 225 213 226 - return (productId == GEYSER_ANSI_PRODUCT_ID) || 227 - (productId == GEYSER_ISO_PRODUCT_ID) || 228 - (productId == GEYSER_JIS_PRODUCT_ID); 214 + return (productId == GEYSER2_ANSI_PRODUCT_ID) || 215 + (productId == GEYSER2_ISO_PRODUCT_ID) || 216 + (productId == GEYSER2_JIS_PRODUCT_ID); 229 217 } 230 218 231 219 static inline int atp_is_geyser_3(struct atp *dev) ··· 252 240 { 253 241 char data[8]; 254 242 int size; 243 + int i; 255 244 256 245 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 257 246 ATP_GEYSER_MODE_READ_REQUEST_ID, ··· 261 248 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); 262 249 263 250 if (size != 8) { 264 - err("Could not do mode read request from device" 265 - " (Geyser Raw mode)"); 251 + dprintk("atp_geyser_init: read error\n"); 252 + for (i = 0; i < 8; i++) 253 + dprintk("appletouch[%d]: %d\n", i, data[i]); 254 + 255 + err("Failed to read mode from device."); 266 256 return -EIO; 267 257 } 268 258 ··· 279 263 ATP_GEYSER_MODE_REQUEST_INDEX, &data, 8, 5000); 280 264 281 265 if (size != 8) { 282 - err("Could not do mode write request to device" 283 - " (Geyser Raw mode)"); 266 + dprintk("atp_geyser_init: write error\n"); 267 + for (i = 0; i < 8; i++) 268 + dprintk("appletouch[%d]: %d\n", i, data[i]); 269 + 270 + err("Failed to request geyser raw mode"); 284 271 return -EIO; 285 272 } 286 273 return 0; ··· 299 280 struct usb_device *udev = dev->udev; 300 281 int retval; 301 282 283 + dprintk("appletouch: putting appletouch to sleep (reinit)\n"); 302 284 dev->idlecount = 0; 303 285 304 286 atp_geyser_init(udev); 305 287 306 288 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 307 - if (retval) { 308 - err("%s - usb_submit_urb failed with result %d", 309 - __func__, retval); 310 - } 289 + if (retval) 290 + err("atp_reinit: usb_submit_urb failed with error %d", 291 + retval); 311 292 } 312 293 313 294 static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, ··· 342 323 * 343 324 * - Jason Parekh <jasonparekh@gmail.com> 344 325 */ 345 - if (i < 1 || (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { 326 + if (i < 1 || 327 + (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) { 346 328 (*fingers)++; 347 329 is_increasing = 1; 348 330 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) { ··· 351 331 } 352 332 353 333 /* 354 - * Subtracts threshold so a high sensor that just passes the threshold 355 - * won't skew the calculated absolute coordinate. Fixes an issue 356 - * where slowly moving the mouse would occassionaly jump a number of 357 - * pixels (let me restate--slowly moving the mouse makes this issue 358 - * most apparent). 334 + * Subtracts threshold so a high sensor that just passes the 335 + * threshold won't skew the calculated absolute coordinate. 336 + * Fixes an issue where slowly moving the mouse would 337 + * occasionally jump a number of pixels (slowly moving the 338 + * finger makes this issue most apparent.) 359 339 */ 360 340 pcum += (xy_sensors[i] - threshold) * i; 361 341 psum += (xy_sensors[i] - threshold); ··· 376 356 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); 377 357 } 378 358 379 - static void atp_complete(struct urb* urb) 359 + static void atp_complete(struct urb *urb) 380 360 { 381 361 int x, y, x_z, y_z, x_f, y_f; 382 362 int retval, i, j; ··· 388 368 /* success */ 389 369 break; 390 370 case -EOVERFLOW: 391 - if(!dev->overflowwarn) { 371 + if (!dev->overflow_warned) { 392 372 printk(KERN_WARNING "appletouch: OVERFLOW with data " 393 373 "length %d, actual length is %d\n", 394 374 dev->datalen, dev->urb->actual_length); 395 - dev->overflowwarn = 1; 375 + dev->overflow_warned = true; 396 376 } 397 377 case -ECONNRESET: 398 378 case -ENOENT: 399 379 case -ESHUTDOWN: 400 380 /* This urb is terminated, clean up */ 401 - dbg("%s - urb shutting down with status: %d", 402 - __func__, urb->status); 381 + dbg("atp_complete: urb shutting down with status: %d", 382 + urb->status); 403 383 return; 404 384 default: 405 - dbg("%s - nonzero urb status received: %d", 406 - __func__, urb->status); 385 + dbg("atp_complete: nonzero urb status received: %d", 386 + urb->status); 407 387 goto exit; 408 388 } 409 389 ··· 458 438 } else { 459 439 for (i = 0; i < 8; i++) { 460 440 /* X values */ 461 - dev->xy_cur[i ] = dev->data[5 * i + 2]; 441 + dev->xy_cur[i + 0] = dev->data[5 * i + 2]; 462 442 dev->xy_cur[i + 8] = dev->data[5 * i + 4]; 463 443 dev->xy_cur[i + 16] = dev->data[5 * i + 42]; 464 444 if (i < 2) ··· 474 454 475 455 if (!dev->valid) { 476 456 /* first sample */ 477 - dev->valid = 1; 457 + dev->valid = true; 478 458 dev->x_old = dev->y_old = -1; 479 459 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); 480 460 ··· 483 463 goto exit; 484 464 485 465 /* 17" Powerbooks have extra X sensors */ 486 - for (i = (atp_is_geyser_2(dev) ? 15 : 16); i < ATP_XSENSORS; i++) { 466 + for (i = (atp_is_geyser_2(dev) ? 15 : 16); 467 + i < ATP_XSENSORS; i++) { 487 468 if (!dev->xy_cur[i]) 488 469 continue; 489 470 ··· 570 549 * work on Fountain touchpads. 571 550 */ 572 551 if (!atp_is_fountain(dev)) { 552 + /* 553 + * Button must not be pressed when entering suspend, 554 + * otherwise we will never release the button. 555 + */ 573 556 if (!x && !y && !key) { 574 557 dev->idlecount++; 575 558 if (dev->idlecount == 10) { 576 - dev->valid = 0; 559 + dev->valid = false; 577 560 schedule_work(&dev->work); 578 561 /* Don't resubmit urb here, wait for reinit */ 579 562 return; ··· 586 561 dev->idlecount = 0; 587 562 } 588 563 589 - exit: 564 + exit: 590 565 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 591 - if (retval) { 592 - err("%s - usb_submit_urb failed with result %d", 593 - __func__, retval); 594 - } 566 + if (retval) 567 + err("atp_complete: usb_submit_urb failed with result %d", 568 + retval); 595 569 } 596 570 597 571 static int atp_open(struct input_dev *input) ··· 613 589 dev->open = 0; 614 590 } 615 591 616 - static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id) 592 + static int atp_probe(struct usb_interface *iface, 593 + const struct usb_device_id *id) 617 594 { 618 595 struct atp *dev; 619 596 struct input_dev *input_dev; ··· 650 625 651 626 dev->udev = udev; 652 627 dev->input = input_dev; 653 - dev->overflowwarn = 0; 628 + dev->overflow_warned = false; 654 629 if (atp_is_geyser_3(dev)) 655 630 dev->datalen = 64; 656 631 else if (atp_is_geyser_2(dev)) ··· 717 692 * 17" models are detected later. 718 693 */ 719 694 input_set_abs_params(input_dev, ABS_X, 0, 720 - (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0); 695 + (16 - 1) * ATP_XFACT - 1, 696 + ATP_FUZZ, 0); 721 697 input_set_abs_params(input_dev, ABS_Y, 0, 722 - (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0); 698 + (ATP_YSENSORS - 1) * ATP_YFACT - 1, 699 + ATP_FUZZ, 0); 723 700 } 724 701 input_set_abs_params(input_dev, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0); 725 702 ··· 776 749 struct atp *dev = usb_get_intfdata(iface); 777 750 778 751 usb_kill_urb(dev->urb); 779 - dev->valid = 0; 752 + dev->valid = false; 780 753 781 754 return 0; 782 755 }