Skip to content

Commit e9542df

Browse files
andusvandtor
authored andcommitted
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>
1 parent 7dce869 commit e9542df

1 file changed

Lines changed: 57 additions & 107 deletions

File tree

‎drivers/input/mouse/appletouch.c‎

Lines changed: 57 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -35,79 +35,59 @@
3535
#include <linux/module.h>
3636
#include <linux/usb/input.h>
3737

38-
/* Apple has powerbooks which have the keyboard with different Product IDs */
39-
#define APPLE_VENDOR_ID 0x05AC
40-
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
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+
};
7446

75-
#define ATP_DEVICE(prod) \
47+
#define ATP_DEVICE(prod, type) \
48+
{ \
7649
.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
7750
USB_DEVICE_ID_MATCH_INT_CLASS | \
7851
USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
79-
.idVendor = APPLE_VENDOR_ID, \
52+
.idVendor = 0x05ac, /* Apple */ \
8053
.idProduct = (prod), \
8154
.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+
*/
8364

84-
/* table of devices that work with this driver */
8565
static struct usb_device_id atp_table [] = {
8666
/* 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 */
9171

9272
/* 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 */
9676

9777
/* 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 */
10181

10282
/* 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 */
10686

10787
/* 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 */
11191

11292
/* Terminating entry */
11393
{ }
@@ -132,9 +112,13 @@ MODULE_DEVICE_TABLE(usb, atp_table);
132112
* We try to keep the touchpad aspect ratio while still doing only simple
133113
* arithmetics.
134114
* The factors below give coordinates like:
135-
* 0 <= x < 960 on 12" and 15" Powerbooks
136-
* 0 <= x < 1600 on 17" Powerbooks
137-
* 0 <= y < 646
115+
*
116+
* 0 <= x < 960 on 12" and 15" Powerbooks
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
138122
*/
139123
#define ATP_XFACT 64
140124
#define ATP_YFACT 43
@@ -159,6 +143,7 @@ struct atp {
159143
struct urb *urb; /* usb request block */
160144
signed char *data; /* transferred data */
161145
struct input_dev *input; /* input dev */
146+
enum atp_touchpad_type type; /* type of touchpad */
162147
bool open;
163148
bool valid; /* are the samples valid? */
164149
bool size_detect_done;
@@ -209,40 +194,6 @@ static int debug;
209194
module_param(debug, int, 0644);
210195
MODULE_PARM_DESC(debug, "Activate debugging output");
211196

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-
246197
/*
247198
* By default newer Geyser devices send standard USB HID mouse
248199
* packets (Report ID 2). This code changes device mode, so it
@@ -416,7 +367,7 @@ static void atp_complete(struct urb *urb)
416367
}
417368

418369
/* reorder the sensors values */
419-
if (atp_is_geyser_3(dev)) {
370+
if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) {
420371
memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
421372

422373
/*
@@ -435,7 +386,7 @@ static void atp_complete(struct urb *urb)
435386
dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
436387
dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
437388
}
438-
} else if (atp_is_geyser_2(dev)) {
389+
} else if (dev->type == ATP_GEYSER2) {
439390
memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
440391

441392
/*
@@ -479,17 +430,17 @@ static void atp_complete(struct urb *urb)
479430
memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
480431

481432
if (dev->size_detect_done ||
482-
atp_is_geyser_3(dev)) /* No 17" Macbooks (yet) */
433+
dev->type == ATP_GEYSER3) /* No 17" Macbooks (yet) */
483434
goto exit;
484435

485436
/* 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);
487438
i < ATP_XSENSORS; i++) {
488439
if (!dev->xy_cur[i])
489440
continue;
490441

491442
printk(KERN_INFO "appletouch: 17\" model detected.\n");
492-
if (atp_is_geyser_2(dev))
443+
if (dev->type == ATP_GEYSER2)
493444
input_set_abs_params(dev->input, ABS_X, 0,
494445
(20 - 1) *
495446
ATP_XFACT - 1,
@@ -569,7 +520,7 @@ static void atp_complete(struct urb *urb)
569520
* several hundred times a second. Re-initialization does not
570521
* work on Fountain touchpads.
571522
*/
572-
if (!atp_is_fountain(dev)) {
523+
if (dev->type != ATP_FOUNTAIN) {
573524
/*
574525
* Button must not be pressed when entering suspend,
575526
* otherwise we will never release the button.
@@ -650,15 +601,14 @@ static int atp_probe(struct usb_interface *iface,
650601

651602
dev->udev = udev;
652603
dev->input = input_dev;
604+
dev->type = id->driver_info;
653605
dev->overflow_warned = false;
654-
if (atp_is_geyser_3(dev))
655-
dev->datalen = 64;
656-
else if (atp_is_geyser_2(dev))
657-
dev->datalen = 64;
658-
else
606+
if (dev->type == ATP_FOUNTAIN || dev->type == ATP_GEYSER1)
659607
dev->datalen = 81;
608+
else
609+
dev->datalen = 64;
660610

661-
if (!atp_is_fountain(dev)) {
611+
if (dev->type != ATP_FOUNTAIN) {
662612
/* switch to raw sensor mode */
663613
if (atp_geyser_init(udev))
664614
goto err_free_devs;
@@ -694,15 +644,15 @@ static int atp_probe(struct usb_interface *iface,
694644

695645
set_bit(EV_ABS, input_dev->evbit);
696646

697-
if (atp_is_geyser_3(dev)) {
647+
if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) {
698648
/*
699649
* MacBook have 20 X sensors, 10 Y sensors
700650
*/
701651
input_set_abs_params(input_dev, ABS_X, 0,
702652
((20 - 1) * ATP_XFACT) - 1, ATP_FUZZ, 0);
703653
input_set_abs_params(input_dev, ABS_Y, 0,
704654
((10 - 1) * ATP_YFACT) - 1, ATP_FUZZ, 0);
705-
} else if (atp_is_geyser_2(dev)) {
655+
} else if (dev->type == ATP_GEYSER2) {
706656
/*
707657
* Oct 2005 15" PowerBooks have 15 X sensors, 17" are detected
708658
* later.

0 commit comments

Comments
 (0)