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

Input: appletouch - simplify touchpad type detection

This patch simplifies type detection and removes unnecessary code.

Signed-off-by: Sven Anders <anders@anduras.de>
[jberg: don't typedef, checkpatch clean, remove useless comments, ...]
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Sven Anders and committed by
Dmitry Torokhov
e9542dff 7dce869f

+57 -107
+57 -107
drivers/input/mouse/appletouch.c
··· 35 35 #include <linux/module.h> 36 36 #include <linux/usb/input.h> 37 37 38 - /* Apple has powerbooks which have the keyboard with different Product IDs */ 39 - #define APPLE_VENDOR_ID 0x05AC 38 + /* Type of touchpad */ 39 + enum atp_touchpad_type { 40 + ATP_FOUNTAIN, 41 + ATP_GEYSER1, 42 + ATP_GEYSER2, 43 + ATP_GEYSER3, 44 + ATP_GEYSER4 45 + }; 40 46 41 - /* These names come from Info.plist in AppleUSBTrackpad.kext */ 42 - 43 - /* PowerBooks Feb 2005 / iBooks */ 44 - #define FOUNTAIN_ANSI_PRODUCT_ID 0x020E 45 - #define FOUNTAIN_ISO_PRODUCT_ID 0x020F 46 - 47 - #define FOUNTAIN_TP_ONLY_PRODUCT_ID 0x030A 48 - 49 - #define GEYSER1_TP_ONLY_PRODUCT_ID 0x030B 50 - 51 - /* PowerBooks Oct 2005 */ 52 - #define GEYSER2_ANSI_PRODUCT_ID 0x0214 53 - #define GEYSER2_ISO_PRODUCT_ID 0x0215 54 - #define GEYSER2_JIS_PRODUCT_ID 0x0216 55 - 56 - /* MacBook devices */ 57 - #define GEYSER3_ANSI_PRODUCT_ID 0x0217 58 - #define GEYSER3_ISO_PRODUCT_ID 0x0218 59 - #define GEYSER3_JIS_PRODUCT_ID 0x0219 60 - 61 - /* 62 - * Geyser IV: same as Geyser III according to Info.plist in OSX's 63 - * AppleUSBTrackpad.kext 64 - * -> same IOClass (AppleUSBGrIIITrackpad), same acceleration tables 65 - */ 66 - #define GEYSER4_ANSI_PRODUCT_ID 0x021A 67 - #define GEYSER4_ISO_PRODUCT_ID 0x021B 68 - #define GEYSER4_JIS_PRODUCT_ID 0x021C 69 - 70 - /* Macbook3,1 devices */ 71 - #define GEYSER4_HF_ANSI_PRODUCT_ID 0x0229 72 - #define GEYSER4_HF_ISO_PRODUCT_ID 0x022A 73 - #define GEYSER4_HF_JIS_PRODUCT_ID 0x022B 74 - 75 - #define ATP_DEVICE(prod) \ 47 + #define ATP_DEVICE(prod, type) \ 48 + { \ 76 49 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 77 50 USB_DEVICE_ID_MATCH_INT_CLASS | \ 78 51 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ 79 - .idVendor = APPLE_VENDOR_ID, \ 52 + .idVendor = 0x05ac, /* Apple */ \ 80 53 .idProduct = (prod), \ 81 54 .bInterfaceClass = 0x03, \ 82 - .bInterfaceProtocol = 0x02 55 + .bInterfaceProtocol = 0x02, \ 56 + .driver_info = ATP_ ## type, \ 57 + } 83 58 84 - /* table of devices that work with this driver */ 59 + /* 60 + * Table of devices (Product IDs) that work with this driver. 61 + * (The names come from Info.plist in AppleUSBTrackpad.kext, 62 + * According to Info.plist Geyser IV is the same as Geyser III.) 63 + */ 64 + 85 65 static struct usb_device_id atp_table [] = { 86 66 /* PowerBooks Feb 2005, iBooks G4 */ 87 - { ATP_DEVICE(FOUNTAIN_ANSI_PRODUCT_ID) }, 88 - { ATP_DEVICE(FOUNTAIN_ISO_PRODUCT_ID) }, 89 - { ATP_DEVICE(FOUNTAIN_TP_ONLY_PRODUCT_ID) }, 90 - { ATP_DEVICE(GEYSER1_TP_ONLY_PRODUCT_ID) }, 67 + ATP_DEVICE(0x020e, FOUNTAIN), /* FOUNTAIN ANSI */ 68 + ATP_DEVICE(0x020f, FOUNTAIN), /* FOUNTAIN ISO */ 69 + ATP_DEVICE(0x030a, FOUNTAIN), /* FOUNTAIN TP ONLY */ 70 + ATP_DEVICE(0x030b, GEYSER1), /* GEYSER 1 TP ONLY */ 91 71 92 72 /* PowerBooks Oct 2005 */ 93 - { ATP_DEVICE(GEYSER2_ANSI_PRODUCT_ID) }, 94 - { ATP_DEVICE(GEYSER2_ISO_PRODUCT_ID) }, 95 - { ATP_DEVICE(GEYSER2_JIS_PRODUCT_ID) }, 73 + ATP_DEVICE(0x0214, GEYSER2), /* GEYSER 2 ANSI */ 74 + ATP_DEVICE(0x0215, GEYSER2), /* GEYSER 2 ISO */ 75 + ATP_DEVICE(0x0216, GEYSER2), /* GEYSER 2 JIS */ 96 76 97 77 /* Core Duo MacBook & MacBook Pro */ 98 - { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) }, 99 - { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) }, 100 - { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) }, 78 + ATP_DEVICE(0x0217, GEYSER3), /* GEYSER 3 ANSI */ 79 + ATP_DEVICE(0x0218, GEYSER3), /* GEYSER 3 ISO */ 80 + ATP_DEVICE(0x0219, GEYSER3), /* GEYSER 3 JIS */ 101 81 102 82 /* Core2 Duo MacBook & MacBook Pro */ 103 - { ATP_DEVICE(GEYSER4_ANSI_PRODUCT_ID) }, 104 - { ATP_DEVICE(GEYSER4_ISO_PRODUCT_ID) }, 105 - { ATP_DEVICE(GEYSER4_JIS_PRODUCT_ID) }, 83 + ATP_DEVICE(0x021a, GEYSER4), /* GEYSER 4 ANSI */ 84 + ATP_DEVICE(0x021b, GEYSER4), /* GEYSER 4 ISO */ 85 + ATP_DEVICE(0x021c, GEYSER4), /* GEYSER 4 JIS */ 106 86 107 87 /* Core2 Duo MacBook3,1 */ 108 - { ATP_DEVICE(GEYSER4_HF_ANSI_PRODUCT_ID) }, 109 - { ATP_DEVICE(GEYSER4_HF_ISO_PRODUCT_ID) }, 110 - { ATP_DEVICE(GEYSER4_HF_JIS_PRODUCT_ID) }, 88 + ATP_DEVICE(0x0229, GEYSER4), /* GEYSER 4 HF ANSI */ 89 + ATP_DEVICE(0x022a, GEYSER4), /* GEYSER 4 HF ISO */ 90 + ATP_DEVICE(0x022b, GEYSER4), /* GEYSER 4 HF JIS */ 111 91 112 92 /* Terminating entry */ 113 93 { } ··· 112 132 * We try to keep the touchpad aspect ratio while still doing only simple 113 133 * arithmetics. 114 134 * The factors below give coordinates like: 115 - * 0 <= x < 960 on 12" and 15" Powerbooks 116 - * 0 <= x < 1600 on 17" Powerbooks 117 - * 0 <= y < 646 135 + * 136 + * 0 <= x < 960 on 12" and 15" Powerbooks 137 + * 0 <= x < 1600 on 17" Powerbooks and 17" MacBook Pro 138 + * 0 <= x < 1216 on MacBooks and 15" MacBook Pro 139 + * 140 + * 0 <= y < 646 on all Powerbooks 141 + * 0 <= y < 774 on all MacBooks 118 142 */ 119 143 #define ATP_XFACT 64 120 144 #define ATP_YFACT 43 ··· 143 159 struct urb *urb; /* usb request block */ 144 160 signed char *data; /* transferred data */ 145 161 struct input_dev *input; /* input dev */ 162 + enum atp_touchpad_type type; /* type of touchpad */ 146 163 bool open; 147 164 bool valid; /* are the samples valid? */ 148 165 bool size_detect_done; ··· 193 208 static int debug; 194 209 module_param(debug, int, 0644); 195 210 MODULE_PARM_DESC(debug, "Activate debugging output"); 196 - 197 - static inline int atp_is_fountain(struct atp *dev) 198 - { 199 - u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct); 200 - 201 - return productId == FOUNTAIN_ANSI_PRODUCT_ID || 202 - productId == FOUNTAIN_ISO_PRODUCT_ID || 203 - productId == FOUNTAIN_TP_ONLY_PRODUCT_ID; 204 - } 205 - 206 - /* Checks if the device a Geyser 2 (ANSI, ISO, JIS) */ 207 - static inline int atp_is_geyser_2(struct atp *dev) 208 - { 209 - u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct); 210 - 211 - return (productId == GEYSER2_ANSI_PRODUCT_ID) || 212 - (productId == GEYSER2_ISO_PRODUCT_ID) || 213 - (productId == GEYSER2_JIS_PRODUCT_ID); 214 - } 215 - 216 - static inline int atp_is_geyser_3(struct atp *dev) 217 - { 218 - u16 productId = le16_to_cpu(dev->udev->descriptor.idProduct); 219 - 220 - return (productId == GEYSER3_ANSI_PRODUCT_ID) || 221 - (productId == GEYSER3_ISO_PRODUCT_ID) || 222 - (productId == GEYSER3_JIS_PRODUCT_ID) || 223 - (productId == GEYSER4_ANSI_PRODUCT_ID) || 224 - (productId == GEYSER4_ISO_PRODUCT_ID) || 225 - (productId == GEYSER4_JIS_PRODUCT_ID) || 226 - (productId == GEYSER4_HF_ANSI_PRODUCT_ID) || 227 - (productId == GEYSER4_HF_ISO_PRODUCT_ID) || 228 - (productId == GEYSER4_HF_JIS_PRODUCT_ID); 229 - } 230 211 231 212 /* 232 213 * By default newer Geyser devices send standard USB HID mouse ··· 367 416 } 368 417 369 418 /* reorder the sensors values */ 370 - if (atp_is_geyser_3(dev)) { 419 + if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) { 371 420 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 372 421 373 422 /* ··· 386 435 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; 387 436 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; 388 437 } 389 - } else if (atp_is_geyser_2(dev)) { 438 + } else if (dev->type == ATP_GEYSER2) { 390 439 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 391 440 392 441 /* ··· 430 479 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); 431 480 432 481 if (dev->size_detect_done || 433 - atp_is_geyser_3(dev)) /* No 17" Macbooks (yet) */ 482 + dev->type == ATP_GEYSER3) /* No 17" Macbooks (yet) */ 434 483 goto exit; 435 484 436 485 /* 17" Powerbooks have extra X sensors */ 437 - for (i = (atp_is_geyser_2(dev) ? 15 : 16); 486 + for (i = (dev->type == ATP_GEYSER2 ? 15 : 16); 438 487 i < ATP_XSENSORS; i++) { 439 488 if (!dev->xy_cur[i]) 440 489 continue; 441 490 442 491 printk(KERN_INFO "appletouch: 17\" model detected.\n"); 443 - if (atp_is_geyser_2(dev)) 492 + if (dev->type == ATP_GEYSER2) 444 493 input_set_abs_params(dev->input, ABS_X, 0, 445 494 (20 - 1) * 446 495 ATP_XFACT - 1, ··· 520 569 * several hundred times a second. Re-initialization does not 521 570 * work on Fountain touchpads. 522 571 */ 523 - if (!atp_is_fountain(dev)) { 572 + if (dev->type != ATP_FOUNTAIN) { 524 573 /* 525 574 * Button must not be pressed when entering suspend, 526 575 * otherwise we will never release the button. ··· 601 650 602 651 dev->udev = udev; 603 652 dev->input = input_dev; 653 + dev->type = id->driver_info; 604 654 dev->overflow_warned = false; 605 - if (atp_is_geyser_3(dev)) 606 - dev->datalen = 64; 607 - else if (atp_is_geyser_2(dev)) 608 - dev->datalen = 64; 609 - else 655 + if (dev->type == ATP_FOUNTAIN || dev->type == ATP_GEYSER1) 610 656 dev->datalen = 81; 657 + else 658 + dev->datalen = 64; 611 659 612 - if (!atp_is_fountain(dev)) { 660 + if (dev->type != ATP_FOUNTAIN) { 613 661 /* switch to raw sensor mode */ 614 662 if (atp_geyser_init(udev)) 615 663 goto err_free_devs; ··· 644 694 645 695 set_bit(EV_ABS, input_dev->evbit); 646 696 647 - if (atp_is_geyser_3(dev)) { 697 + if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) { 648 698 /* 649 699 * MacBook have 20 X sensors, 10 Y sensors 650 700 */ ··· 652 702 ((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0); 653 703 input_set_abs_params(input_dev, ABS_Y, 0, 654 704 ((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0); 655 - } else if (atp_is_geyser_2(dev)) { 705 + } else if (dev->type == ATP_GEYSER2) { 656 706 /* 657 707 * Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected 658 708 * later.