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