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>
23 struct lifebook_data
{
24 struct input_dev
*dev2
; /* Relative device */
28 static const char *desired_serio_phys
;
30 static int lifebook_set_serio_phys(const struct dmi_system_id
*d
)
32 desired_serio_phys
= d
->driver_data
;
36 static bool lifebook_use_6byte_proto
;
38 static int lifebook_set_6byte_proto(const struct dmi_system_id
*d
)
40 lifebook_use_6byte_proto
= true;
44 static const struct dmi_system_id lifebook_dmi_table
[] = {
46 .ident
= "FLORA-ie 55mi",
48 DMI_MATCH(DMI_PRODUCT_NAME
, "FLORA-ie 55mi"),
52 .ident
= "LifeBook B",
54 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B Series"),
58 .ident
= "Lifebook B",
60 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK B Series"),
64 .ident
= "Lifebook B-2130",
66 DMI_MATCH(DMI_BOARD_NAME
, "ZEPHYR"),
70 .ident
= "Lifebook B213x/B2150",
72 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B2131/B2133/B2150"),
78 DMI_MATCH(DMI_PRODUCT_NAME
, "ZEPHYR"),
84 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-18"),
86 .callback
= lifebook_set_serio_phys
,
87 .driver_data
= "isa0060/serio3",
90 .ident
= "Panasonic CF-28",
92 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
93 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-28"),
95 .callback
= lifebook_set_6byte_proto
,
98 .ident
= "Panasonic CF-29",
100 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
101 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-29"),
103 .callback
= lifebook_set_6byte_proto
,
108 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-72"),
110 .callback
= lifebook_set_serio_phys
,
111 .driver_data
= "isa0060/serio3",
114 .ident
= "Lifebook B142",
116 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B142"),
122 static psmouse_ret_t
lifebook_process_byte(struct psmouse
*psmouse
)
124 struct lifebook_data
*priv
= psmouse
->private;
125 struct input_dev
*dev1
= psmouse
->dev
;
126 struct input_dev
*dev2
= priv
? priv
->dev2
: NULL
;
127 unsigned char *packet
= psmouse
->packet
;
128 bool relative_packet
= packet
[0] & 0x08;
130 if (relative_packet
|| !lifebook_use_6byte_proto
) {
131 if (psmouse
->pktcnt
!= 3)
132 return PSMOUSE_GOOD_DATA
;
134 switch (psmouse
->pktcnt
) {
136 return (packet
[0] & 0xf8) == 0x00 ?
137 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
139 return PSMOUSE_GOOD_DATA
;
141 return ((packet
[2] & 0x30) << 2) == (packet
[2] & 0xc0) ?
142 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
144 return (packet
[3] & 0xf8) == 0xc0 ?
145 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
147 return (packet
[4] & 0xc0) == (packet
[2] & 0xc0) ?
148 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
150 if (((packet
[5] & 0x30) << 2) != (packet
[5] & 0xc0))
151 return PSMOUSE_BAD_DATA
;
152 if ((packet
[5] & 0xc0) != (packet
[1] & 0xc0))
153 return PSMOUSE_BAD_DATA
;
154 break; /* report data */
158 if (relative_packet
) {
160 printk(KERN_WARNING
"lifebook.c: got relative packet "
161 "but no relative device set up\n");
163 if (lifebook_use_6byte_proto
) {
164 input_report_abs(dev1
, ABS_X
,
165 ((packet
[1] & 0x3f) << 6) | (packet
[2] & 0x3f));
166 input_report_abs(dev1
, ABS_Y
,
167 4096 - (((packet
[4] & 0x3f) << 6) | (packet
[5] & 0x3f)));
169 input_report_abs(dev1
, ABS_X
,
170 (packet
[1] | ((packet
[0] & 0x30) << 4)));
171 input_report_abs(dev1
, ABS_Y
,
172 1024 - (packet
[2] | ((packet
[0] & 0xC0) << 2)));
174 input_report_key(dev1
, BTN_TOUCH
, packet
[0] & 0x04);
179 if (relative_packet
) {
180 input_report_rel(dev2
, REL_X
,
181 ((packet
[0] & 0x10) ? packet
[1] - 256 : packet
[1]));
182 input_report_rel(dev2
, REL_Y
,
183 -(int)((packet
[0] & 0x20) ? packet
[2] - 256 : packet
[2]));
185 input_report_key(dev2
, BTN_LEFT
, packet
[0] & 0x01);
186 input_report_key(dev2
, BTN_RIGHT
, packet
[0] & 0x02);
190 return PSMOUSE_FULL_PACKET
;
193 static int lifebook_absolute_mode(struct psmouse
*psmouse
)
195 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
198 if (psmouse_reset(psmouse
))
202 Enable absolute output -- ps2_command fails always but if
203 you leave this call out the touchsreen will never send
206 param
= lifebook_use_6byte_proto
? 0x08 : 0x07;
207 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
212 static void lifebook_relative_mode(struct psmouse
*psmouse
)
214 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
215 unsigned char param
= 0x06;
217 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
220 static void lifebook_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
)
222 static const unsigned char params
[] = { 0, 1, 2, 2, 3 };
225 if (resolution
== 0 || resolution
> 400)
228 p
= params
[resolution
/ 100];
229 ps2_command(&psmouse
->ps2dev
, &p
, PSMOUSE_CMD_SETRES
);
230 psmouse
->resolution
= 50 << p
;
233 static void lifebook_disconnect(struct psmouse
*psmouse
)
235 struct lifebook_data
*priv
= psmouse
->private;
237 psmouse_reset(psmouse
);
239 input_unregister_device(priv
->dev2
);
242 psmouse
->private = NULL
;
245 int lifebook_detect(struct psmouse
*psmouse
, bool set_properties
)
247 if (!dmi_check_system(lifebook_dmi_table
))
250 if (desired_serio_phys
&&
251 strcmp(psmouse
->ps2dev
.serio
->phys
, desired_serio_phys
))
254 if (set_properties
) {
255 psmouse
->vendor
= "Fujitsu";
256 psmouse
->name
= "Lifebook TouchScreen";
262 static int lifebook_create_relative_device(struct psmouse
*psmouse
)
264 struct input_dev
*dev2
;
265 struct lifebook_data
*priv
;
268 priv
= kzalloc(sizeof(struct lifebook_data
), GFP_KERNEL
);
269 dev2
= input_allocate_device();
274 snprintf(priv
->phys
, sizeof(priv
->phys
),
275 "%s/input1", psmouse
->ps2dev
.serio
->phys
);
277 dev2
->phys
= priv
->phys
;
278 dev2
->name
= "PS/2 Touchpad";
279 dev2
->id
.bustype
= BUS_I8042
;
280 dev2
->id
.vendor
= 0x0002;
281 dev2
->id
.product
= PSMOUSE_LIFEBOOK
;
282 dev2
->id
.version
= 0x0000;
283 dev2
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
285 dev2
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REL
);
286 dev2
->relbit
[BIT_WORD(REL_X
)] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
287 dev2
->keybit
[BIT_WORD(BTN_LEFT
)] = BIT_MASK(BTN_LEFT
) |
290 error
= input_register_device(priv
->dev2
);
294 psmouse
->private = priv
;
298 input_free_device(dev2
);
303 int lifebook_init(struct psmouse
*psmouse
)
305 struct input_dev
*dev1
= psmouse
->dev
;
306 int max_coord
= lifebook_use_6byte_proto
? 4096 : 1024;
308 if (lifebook_absolute_mode(psmouse
))
311 dev1
->evbit
[0] = BIT_MASK(EV_ABS
) | BIT_MASK(EV_KEY
);
313 dev1
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
314 input_set_abs_params(dev1
, ABS_X
, 0, max_coord
, 0, 0);
315 input_set_abs_params(dev1
, ABS_Y
, 0, max_coord
, 0, 0);
317 if (!desired_serio_phys
) {
318 if (lifebook_create_relative_device(psmouse
)) {
319 lifebook_relative_mode(psmouse
);
324 psmouse
->protocol_handler
= lifebook_process_byte
;
325 psmouse
->set_resolution
= lifebook_set_resolution
;
326 psmouse
->disconnect
= lifebook_disconnect
;
327 psmouse
->reconnect
= lifebook_absolute_mode
;
329 psmouse
->model
= lifebook_use_6byte_proto
? 6 : 3;
332 * Use packet size = 3 even when using 6-byte protocol because
333 * that's what POLL will return on Lifebooks (according to spec).
335 psmouse
->pktsize
= 3;