Commit | Line | Data |
---|---|---|
02d7f589 KE |
1 | /* |
2 | * Fujitsu B-series Lifebook PS/2 TouchScreen driver | |
3 | * | |
4 | * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz> | |
5 | * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de> | |
6 | * | |
7 | * TouchScreen detection, absolute mode setting and packet layout is taken from | |
8 | * Harald Hoyer's description of the device. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify it | |
11 | * under the terms of the GNU General Public License version 2 as published by | |
12 | * the Free Software Foundation. | |
13 | */ | |
14 | ||
15 | #include <linux/input.h> | |
16 | #include <linux/serio.h> | |
17 | #include <linux/libps2.h> | |
18 | #include <linux/dmi.h> | |
19 | ||
20 | #include "psmouse.h" | |
21 | #include "lifebook.h" | |
22 | ||
2ebdcc61 DT |
23 | struct lifebook_data { |
24 | struct input_dev *dev2; /* Relative device */ | |
25 | char phys[32]; | |
26 | }; | |
27 | ||
7705d548 DT |
28 | static bool lifebook_present; |
29 | ||
e7afcd1b DT |
30 | static const char *desired_serio_phys; |
31 | ||
7705d548 | 32 | static int lifebook_limit_serio3(const struct dmi_system_id *d) |
e7afcd1b | 33 | { |
7705d548 | 34 | desired_serio_phys = "isa0060/serio3"; |
e7afcd1b DT |
35 | return 0; |
36 | } | |
37 | ||
b7802c5c | 38 | static bool lifebook_use_6byte_proto; |
1b118799 | 39 | |
1855256c | 40 | static int lifebook_set_6byte_proto(const struct dmi_system_id *d) |
1b118799 | 41 | { |
b7802c5c | 42 | lifebook_use_6byte_proto = true; |
1b118799 DT |
43 | return 0; |
44 | } | |
45 | ||
7705d548 DT |
46 | static const struct dmi_system_id __initconst lifebook_dmi_table[] = { |
47 | #if defined(CONFIG_DMI) && defined(CONFIG_X86) | |
b1b29650 AM |
48 | { |
49 | .ident = "FLORA-ie 55mi", | |
50 | .matches = { | |
51 | DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"), | |
52 | }, | |
53 | }, | |
54 | { | |
55 | .ident = "LifeBook B", | |
56 | .matches = { | |
57 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"), | |
58 | }, | |
59 | }, | |
60 | { | |
61 | .ident = "Lifebook B", | |
62 | .matches = { | |
63 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"), | |
64 | }, | |
65 | }, | |
6b9ff696 DT |
66 | { |
67 | .ident = "Lifebook B-2130", | |
68 | .matches = { | |
69 | DMI_MATCH(DMI_BOARD_NAME, "ZEPHYR"), | |
70 | }, | |
71 | }, | |
b1b29650 AM |
72 | { |
73 | .ident = "Lifebook B213x/B2150", | |
74 | .matches = { | |
75 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"), | |
76 | }, | |
77 | }, | |
78 | { | |
79 | .ident = "Zephyr", | |
80 | .matches = { | |
81 | DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"), | |
82 | }, | |
83 | }, | |
84 | { | |
85 | .ident = "CF-18", | |
86 | .matches = { | |
87 | DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"), | |
88 | }, | |
7705d548 | 89 | .callback = lifebook_limit_serio3, |
b1b29650 | 90 | }, |
1b118799 DT |
91 | { |
92 | .ident = "Panasonic CF-28", | |
93 | .matches = { | |
94 | DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"), | |
95 | DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"), | |
96 | }, | |
97 | .callback = lifebook_set_6byte_proto, | |
98 | }, | |
43887ba1 DT |
99 | { |
100 | .ident = "Panasonic CF-29", | |
101 | .matches = { | |
102 | DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"), | |
103 | DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"), | |
104 | }, | |
105 | .callback = lifebook_set_6byte_proto, | |
106 | }, | |
f76f672e DT |
107 | { |
108 | .ident = "CF-72", | |
109 | .matches = { | |
110 | DMI_MATCH(DMI_PRODUCT_NAME, "CF-72"), | |
111 | }, | |
b1e69aae | 112 | .callback = lifebook_set_6byte_proto, |
f76f672e | 113 | }, |
b1b29650 AM |
114 | { |
115 | .ident = "Lifebook B142", | |
116 | .matches = { | |
117 | DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"), | |
118 | }, | |
119 | }, | |
120 | { } | |
7705d548 | 121 | #endif |
02d7f589 KE |
122 | }; |
123 | ||
7705d548 DT |
124 | void __init lifebook_module_init(void) |
125 | { | |
126 | lifebook_present = dmi_check_system(lifebook_dmi_table); | |
127 | } | |
128 | ||
7d12e780 | 129 | static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse) |
02d7f589 | 130 | { |
2ebdcc61 DT |
131 | struct lifebook_data *priv = psmouse->private; |
132 | struct input_dev *dev1 = psmouse->dev; | |
e6b20d8d | 133 | struct input_dev *dev2 = priv ? priv->dev2 : NULL; |
1b118799 | 134 | unsigned char *packet = psmouse->packet; |
b7802c5c | 135 | bool relative_packet = packet[0] & 0x08; |
02d7f589 | 136 | |
1b118799 DT |
137 | if (relative_packet || !lifebook_use_6byte_proto) { |
138 | if (psmouse->pktcnt != 3) | |
139 | return PSMOUSE_GOOD_DATA; | |
02d7f589 | 140 | } else { |
1b118799 DT |
141 | switch (psmouse->pktcnt) { |
142 | case 1: | |
143 | return (packet[0] & 0xf8) == 0x00 ? | |
144 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; | |
145 | case 2: | |
146 | return PSMOUSE_GOOD_DATA; | |
147 | case 3: | |
148 | return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ? | |
149 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; | |
150 | case 4: | |
151 | return (packet[3] & 0xf8) == 0xc0 ? | |
152 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; | |
153 | case 5: | |
154 | return (packet[4] & 0xc0) == (packet[2] & 0xc0) ? | |
155 | PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA; | |
156 | case 6: | |
157 | if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0)) | |
158 | return PSMOUSE_BAD_DATA; | |
159 | if ((packet[5] & 0xc0) != (packet[1] & 0xc0)) | |
160 | return PSMOUSE_BAD_DATA; | |
161 | break; /* report data */ | |
162 | } | |
163 | } | |
164 | ||
165 | if (relative_packet) { | |
2ebdcc61 DT |
166 | if (!dev2) |
167 | printk(KERN_WARNING "lifebook.c: got relative packet " | |
168 | "but no relative device set up\n"); | |
1b118799 | 169 | } else { |
9b771ac4 DT |
170 | if (lifebook_use_6byte_proto) { |
171 | input_report_abs(dev1, ABS_X, | |
172 | ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f)); | |
173 | input_report_abs(dev1, ABS_Y, | |
174 | 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f))); | |
175 | } else { | |
176 | input_report_abs(dev1, ABS_X, | |
177 | (packet[1] | ((packet[0] & 0x30) << 4))); | |
178 | input_report_abs(dev1, ABS_Y, | |
179 | 1024 - (packet[2] | ((packet[0] & 0xC0) << 2))); | |
180 | } | |
181 | input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04); | |
182 | input_sync(dev1); | |
02d7f589 KE |
183 | } |
184 | ||
2ebdcc61 DT |
185 | if (dev2) { |
186 | if (relative_packet) { | |
187 | input_report_rel(dev2, REL_X, | |
188 | ((packet[0] & 0x10) ? packet[1] - 256 : packet[1])); | |
189 | input_report_rel(dev2, REL_Y, | |
190 | -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2])); | |
191 | } | |
192 | input_report_key(dev2, BTN_LEFT, packet[0] & 0x01); | |
193 | input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02); | |
194 | input_sync(dev2); | |
195 | } | |
02d7f589 KE |
196 | |
197 | return PSMOUSE_FULL_PACKET; | |
198 | } | |
199 | ||
a15d60f8 | 200 | static int lifebook_absolute_mode(struct psmouse *psmouse) |
02d7f589 KE |
201 | { |
202 | struct ps2dev *ps2dev = &psmouse->ps2dev; | |
203 | unsigned char param; | |
204 | ||
14e94143 | 205 | if (psmouse_reset(psmouse)) |
02d7f589 KE |
206 | return -1; |
207 | ||
14e94143 | 208 | /* |
0cc1770b DT |
209 | * Enable absolute output -- ps2_command fails always but if |
210 | * you leave this call out the touchsreen will never send | |
211 | * absolute coordinates | |
212 | */ | |
1b118799 | 213 | param = lifebook_use_6byte_proto ? 0x08 : 0x07; |
02d7f589 KE |
214 | ps2_command(ps2dev, ¶m, PSMOUSE_CMD_SETRES); |
215 | ||
02d7f589 KE |
216 | return 0; |
217 | } | |
218 | ||
2ebdcc61 DT |
219 | static void lifebook_relative_mode(struct psmouse *psmouse) |
220 | { | |
221 | struct ps2dev *ps2dev = &psmouse->ps2dev; | |
222 | unsigned char param = 0x06; | |
223 | ||
224 | ps2_command(ps2dev, ¶m, PSMOUSE_CMD_SETRES); | |
225 | } | |
226 | ||
a913829e DT |
227 | static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution) |
228 | { | |
e38de678 HD |
229 | static const unsigned char params[] = { 0, 1, 2, 2, 3 }; |
230 | unsigned char p; | |
a913829e DT |
231 | |
232 | if (resolution == 0 || resolution > 400) | |
233 | resolution = 400; | |
234 | ||
e38de678 HD |
235 | p = params[resolution / 100]; |
236 | ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES); | |
237 | psmouse->resolution = 50 << p; | |
a913829e DT |
238 | } |
239 | ||
02d7f589 KE |
240 | static void lifebook_disconnect(struct psmouse *psmouse) |
241 | { | |
653e91d0 AS |
242 | struct lifebook_data *priv = psmouse->private; |
243 | ||
02d7f589 | 244 | psmouse_reset(psmouse); |
653e91d0 AS |
245 | if (priv) { |
246 | input_unregister_device(priv->dev2); | |
247 | kfree(priv); | |
248 | } | |
2ebdcc61 | 249 | psmouse->private = NULL; |
02d7f589 KE |
250 | } |
251 | ||
b7802c5c | 252 | int lifebook_detect(struct psmouse *psmouse, bool set_properties) |
02d7f589 | 253 | { |
7705d548 | 254 | if (!lifebook_present) |
02d7f589 KE |
255 | return -1; |
256 | ||
e7afcd1b DT |
257 | if (desired_serio_phys && |
258 | strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys)) | |
259 | return -1; | |
260 | ||
02d7f589 | 261 | if (set_properties) { |
a15d60f8 DT |
262 | psmouse->vendor = "Fujitsu"; |
263 | psmouse->name = "Lifebook TouchScreen"; | |
02d7f589 KE |
264 | } |
265 | ||
a15d60f8 | 266 | return 0; |
02d7f589 | 267 | } |
a15d60f8 | 268 | |
2ebdcc61 DT |
269 | static int lifebook_create_relative_device(struct psmouse *psmouse) |
270 | { | |
271 | struct input_dev *dev2; | |
272 | struct lifebook_data *priv; | |
273 | int error = -ENOMEM; | |
274 | ||
275 | priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL); | |
276 | dev2 = input_allocate_device(); | |
277 | if (!priv || !dev2) | |
278 | goto err_out; | |
279 | ||
280 | priv->dev2 = dev2; | |
281 | snprintf(priv->phys, sizeof(priv->phys), | |
282 | "%s/input1", psmouse->ps2dev.serio->phys); | |
283 | ||
284 | dev2->phys = priv->phys; | |
285 | dev2->name = "PS/2 Touchpad"; | |
286 | dev2->id.bustype = BUS_I8042; | |
287 | dev2->id.vendor = 0x0002; | |
288 | dev2->id.product = PSMOUSE_LIFEBOOK; | |
289 | dev2->id.version = 0x0000; | |
290 | dev2->dev.parent = &psmouse->ps2dev.serio->dev; | |
291 | ||
7b19ada2 JS |
292 | dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
293 | dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); | |
0cc1770b DT |
294 | dev2->keybit[BIT_WORD(BTN_LEFT)] = |
295 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); | |
2ebdcc61 DT |
296 | |
297 | error = input_register_device(priv->dev2); | |
298 | if (error) | |
299 | goto err_out; | |
300 | ||
301 | psmouse->private = priv; | |
302 | return 0; | |
303 | ||
304 | err_out: | |
305 | input_free_device(dev2); | |
306 | kfree(priv); | |
307 | return error; | |
308 | } | |
309 | ||
a15d60f8 DT |
310 | int lifebook_init(struct psmouse *psmouse) |
311 | { | |
2ebdcc61 | 312 | struct input_dev *dev1 = psmouse->dev; |
62e729b6 | 313 | int max_coord = lifebook_use_6byte_proto ? 4096 : 1024; |
2e5b636b | 314 | |
a15d60f8 DT |
315 | if (lifebook_absolute_mode(psmouse)) |
316 | return -1; | |
317 | ||
7b19ada2 | 318 | dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY); |
2ebdcc61 | 319 | dev1->relbit[0] = 0; |
0cc1770b | 320 | dev1->keybit[BIT_WORD(BTN_MOUSE)] = 0; |
7b19ada2 | 321 | dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
2ebdcc61 DT |
322 | input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0); |
323 | input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0); | |
324 | ||
325 | if (!desired_serio_phys) { | |
326 | if (lifebook_create_relative_device(psmouse)) { | |
327 | lifebook_relative_mode(psmouse); | |
328 | return -1; | |
329 | } | |
330 | } | |
a15d60f8 DT |
331 | |
332 | psmouse->protocol_handler = lifebook_process_byte; | |
a913829e | 333 | psmouse->set_resolution = lifebook_set_resolution; |
a15d60f8 DT |
334 | psmouse->disconnect = lifebook_disconnect; |
335 | psmouse->reconnect = lifebook_absolute_mode; | |
1b118799 | 336 | |
2ebdcc61 DT |
337 | psmouse->model = lifebook_use_6byte_proto ? 6 : 3; |
338 | ||
1b118799 DT |
339 | /* |
340 | * Use packet size = 3 even when using 6-byte protocol because | |
341 | * that's what POLL will return on Lifebooks (according to spec). | |
342 | */ | |
a15d60f8 DT |
343 | psmouse->pktsize = 3; |
344 | ||
345 | return 0; | |
346 | } | |
347 |