2 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
4 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de>
7 * TouchScreen detection, absolute mode setting and packet layout is taken from
8 * Harald Hoyer's description of the device.
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.
15 #include <linux/input.h>
16 #include <linux/serio.h>
17 #include <linux/libps2.h>
18 #include <linux/dmi.h>
19 #include <linux/slab.h>
24 struct lifebook_data
{
25 struct input_dev
*dev2
; /* Relative device */
29 static bool lifebook_present
;
31 static const char *desired_serio_phys
;
33 static int lifebook_limit_serio3(const struct dmi_system_id
*d
)
35 desired_serio_phys
= "isa0060/serio3";
39 static bool lifebook_use_6byte_proto
;
41 static int lifebook_set_6byte_proto(const struct dmi_system_id
*d
)
43 lifebook_use_6byte_proto
= true;
47 static const struct dmi_system_id __initconst lifebook_dmi_table
[] = {
51 DMI_MATCH(DMI_PRODUCT_NAME
, "FLORA-ie 55mi"),
57 DMI_MATCH(DMI_PRODUCT_NAME
, "Lifebook B Series"),
63 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B Series"),
69 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK B Series"),
75 DMI_MATCH(DMI_BOARD_NAME
, "ZEPHYR"),
79 /* Lifebook B213x/B2150 */
81 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B2131/B2133/B2150"),
87 DMI_MATCH(DMI_PRODUCT_NAME
, "ZEPHYR"),
93 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-18"),
95 .callback
= lifebook_limit_serio3
,
100 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
101 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-28"),
103 .callback
= lifebook_set_6byte_proto
,
106 /* Panasonic CF-29 */
108 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
109 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-29"),
111 .callback
= lifebook_set_6byte_proto
,
114 /* Panasonic CF-72 */
116 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-72"),
118 .callback
= lifebook_set_6byte_proto
,
123 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B142"),
129 void __init
lifebook_module_init(void)
131 lifebook_present
= dmi_check_system(lifebook_dmi_table
);
134 static psmouse_ret_t
lifebook_process_byte(struct psmouse
*psmouse
)
136 struct lifebook_data
*priv
= psmouse
->private;
137 struct input_dev
*dev1
= psmouse
->dev
;
138 struct input_dev
*dev2
= priv
? priv
->dev2
: NULL
;
139 unsigned char *packet
= psmouse
->packet
;
140 bool relative_packet
= packet
[0] & 0x08;
142 if (relative_packet
|| !lifebook_use_6byte_proto
) {
143 if (psmouse
->pktcnt
!= 3)
144 return PSMOUSE_GOOD_DATA
;
146 switch (psmouse
->pktcnt
) {
148 return (packet
[0] & 0xf8) == 0x00 ?
149 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
151 return PSMOUSE_GOOD_DATA
;
153 return ((packet
[2] & 0x30) << 2) == (packet
[2] & 0xc0) ?
154 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
156 return (packet
[3] & 0xf8) == 0xc0 ?
157 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
159 return (packet
[4] & 0xc0) == (packet
[2] & 0xc0) ?
160 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
162 if (((packet
[5] & 0x30) << 2) != (packet
[5] & 0xc0))
163 return PSMOUSE_BAD_DATA
;
164 if ((packet
[5] & 0xc0) != (packet
[1] & 0xc0))
165 return PSMOUSE_BAD_DATA
;
166 break; /* report data */
170 if (relative_packet
) {
172 printk(KERN_WARNING
"lifebook.c: got relative packet "
173 "but no relative device set up\n");
175 if (lifebook_use_6byte_proto
) {
176 input_report_abs(dev1
, ABS_X
,
177 ((packet
[1] & 0x3f) << 6) | (packet
[2] & 0x3f));
178 input_report_abs(dev1
, ABS_Y
,
179 4096 - (((packet
[4] & 0x3f) << 6) | (packet
[5] & 0x3f)));
181 input_report_abs(dev1
, ABS_X
,
182 (packet
[1] | ((packet
[0] & 0x30) << 4)));
183 input_report_abs(dev1
, ABS_Y
,
184 1024 - (packet
[2] | ((packet
[0] & 0xC0) << 2)));
186 input_report_key(dev1
, BTN_TOUCH
, packet
[0] & 0x04);
191 if (relative_packet
) {
192 input_report_rel(dev2
, REL_X
,
193 ((packet
[0] & 0x10) ? packet
[1] - 256 : packet
[1]));
194 input_report_rel(dev2
, REL_Y
,
195 -(int)((packet
[0] & 0x20) ? packet
[2] - 256 : packet
[2]));
197 input_report_key(dev2
, BTN_LEFT
, packet
[0] & 0x01);
198 input_report_key(dev2
, BTN_RIGHT
, packet
[0] & 0x02);
202 return PSMOUSE_FULL_PACKET
;
205 static int lifebook_absolute_mode(struct psmouse
*psmouse
)
207 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
210 if (psmouse_reset(psmouse
))
214 * Enable absolute output -- ps2_command fails always but if
215 * you leave this call out the touchsreen will never send
216 * absolute coordinates
218 param
= lifebook_use_6byte_proto
? 0x08 : 0x07;
219 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
224 static void lifebook_relative_mode(struct psmouse
*psmouse
)
226 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
227 unsigned char param
= 0x06;
229 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
232 static void lifebook_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
)
234 static const unsigned char params
[] = { 0, 1, 2, 2, 3 };
237 if (resolution
== 0 || resolution
> 400)
240 p
= params
[resolution
/ 100];
241 ps2_command(&psmouse
->ps2dev
, &p
, PSMOUSE_CMD_SETRES
);
242 psmouse
->resolution
= 50 << p
;
245 static void lifebook_disconnect(struct psmouse
*psmouse
)
247 struct lifebook_data
*priv
= psmouse
->private;
249 psmouse_reset(psmouse
);
251 input_unregister_device(priv
->dev2
);
254 psmouse
->private = NULL
;
257 int lifebook_detect(struct psmouse
*psmouse
, bool set_properties
)
259 if (!lifebook_present
)
262 if (desired_serio_phys
&&
263 strcmp(psmouse
->ps2dev
.serio
->phys
, desired_serio_phys
))
266 if (set_properties
) {
267 psmouse
->vendor
= "Fujitsu";
268 psmouse
->name
= "Lifebook TouchScreen";
274 static int lifebook_create_relative_device(struct psmouse
*psmouse
)
276 struct input_dev
*dev2
;
277 struct lifebook_data
*priv
;
280 priv
= kzalloc(sizeof(struct lifebook_data
), GFP_KERNEL
);
281 dev2
= input_allocate_device();
286 snprintf(priv
->phys
, sizeof(priv
->phys
),
287 "%s/input1", psmouse
->ps2dev
.serio
->phys
);
289 dev2
->phys
= priv
->phys
;
290 dev2
->name
= "PS/2 Touchpad";
291 dev2
->id
.bustype
= BUS_I8042
;
292 dev2
->id
.vendor
= 0x0002;
293 dev2
->id
.product
= PSMOUSE_LIFEBOOK
;
294 dev2
->id
.version
= 0x0000;
295 dev2
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
297 dev2
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REL
);
298 dev2
->relbit
[BIT_WORD(REL_X
)] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
299 dev2
->keybit
[BIT_WORD(BTN_LEFT
)] =
300 BIT_MASK(BTN_LEFT
) | BIT_MASK(BTN_RIGHT
);
302 error
= input_register_device(priv
->dev2
);
306 psmouse
->private = priv
;
310 input_free_device(dev2
);
315 int lifebook_init(struct psmouse
*psmouse
)
317 struct input_dev
*dev1
= psmouse
->dev
;
318 int max_coord
= lifebook_use_6byte_proto
? 4096 : 1024;
320 if (lifebook_absolute_mode(psmouse
))
323 dev1
->evbit
[0] = BIT_MASK(EV_ABS
) | BIT_MASK(EV_KEY
);
325 dev1
->keybit
[BIT_WORD(BTN_MOUSE
)] = 0;
326 dev1
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
327 input_set_abs_params(dev1
, ABS_X
, 0, max_coord
, 0, 0);
328 input_set_abs_params(dev1
, ABS_Y
, 0, max_coord
, 0, 0);
330 if (!desired_serio_phys
) {
331 if (lifebook_create_relative_device(psmouse
)) {
332 lifebook_relative_mode(psmouse
);
337 psmouse
->protocol_handler
= lifebook_process_byte
;
338 psmouse
->set_resolution
= lifebook_set_resolution
;
339 psmouse
->disconnect
= lifebook_disconnect
;
340 psmouse
->reconnect
= lifebook_absolute_mode
;
342 psmouse
->model
= lifebook_use_6byte_proto
? 6 : 3;
345 * Use packet size = 3 even when using 6-byte protocol because
346 * that's what POLL will return on Lifebooks (according to spec).
348 psmouse
->pktsize
= 3;