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>
20 #include <linux/types.h>
25 struct lifebook_data
{
26 struct input_dev
*dev2
; /* Relative device */
30 static bool lifebook_present
;
32 static const char *desired_serio_phys
;
34 static int lifebook_limit_serio3(const struct dmi_system_id
*d
)
36 desired_serio_phys
= "isa0060/serio3";
40 static bool lifebook_use_6byte_proto
;
42 static int lifebook_set_6byte_proto(const struct dmi_system_id
*d
)
44 lifebook_use_6byte_proto
= true;
48 static const struct dmi_system_id lifebook_dmi_table
[] __initconst
= {
52 DMI_MATCH(DMI_PRODUCT_NAME
, "FLORA-ie 55mi"),
58 DMI_MATCH(DMI_PRODUCT_NAME
, "Lifebook B Series"),
64 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B Series"),
70 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK B Series"),
76 DMI_MATCH(DMI_BOARD_NAME
, "ZEPHYR"),
80 /* Lifebook B213x/B2150 */
82 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B2131/B2133/B2150"),
88 DMI_MATCH(DMI_PRODUCT_NAME
, "ZEPHYR"),
94 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-18"),
96 .callback
= lifebook_limit_serio3
,
101 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
102 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-28"),
104 .callback
= lifebook_set_6byte_proto
,
107 /* Panasonic CF-29 */
109 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
110 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-29"),
112 .callback
= lifebook_set_6byte_proto
,
115 /* Panasonic CF-72 */
117 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-72"),
119 .callback
= lifebook_set_6byte_proto
,
124 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B142"),
130 void __init
lifebook_module_init(void)
132 lifebook_present
= dmi_check_system(lifebook_dmi_table
);
135 static psmouse_ret_t
lifebook_process_byte(struct psmouse
*psmouse
)
137 struct lifebook_data
*priv
= psmouse
->private;
138 struct input_dev
*dev1
= psmouse
->dev
;
139 struct input_dev
*dev2
= priv
? priv
->dev2
: NULL
;
140 u8
*packet
= psmouse
->packet
;
141 bool relative_packet
= packet
[0] & 0x08;
143 if (relative_packet
|| !lifebook_use_6byte_proto
) {
144 if (psmouse
->pktcnt
!= 3)
145 return PSMOUSE_GOOD_DATA
;
147 switch (psmouse
->pktcnt
) {
149 return (packet
[0] & 0xf8) == 0x00 ?
150 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
152 return PSMOUSE_GOOD_DATA
;
154 return ((packet
[2] & 0x30) << 2) == (packet
[2] & 0xc0) ?
155 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
157 return (packet
[3] & 0xf8) == 0xc0 ?
158 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
160 return (packet
[4] & 0xc0) == (packet
[2] & 0xc0) ?
161 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
163 if (((packet
[5] & 0x30) << 2) != (packet
[5] & 0xc0))
164 return PSMOUSE_BAD_DATA
;
165 if ((packet
[5] & 0xc0) != (packet
[1] & 0xc0))
166 return PSMOUSE_BAD_DATA
;
167 break; /* report data */
171 if (relative_packet
) {
173 psmouse_warn(psmouse
,
174 "got relative packet but no relative device set up\n");
176 if (lifebook_use_6byte_proto
) {
177 input_report_abs(dev1
, ABS_X
,
178 ((packet
[1] & 0x3f) << 6) | (packet
[2] & 0x3f));
179 input_report_abs(dev1
, ABS_Y
,
180 4096 - (((packet
[4] & 0x3f) << 6) | (packet
[5] & 0x3f)));
182 input_report_abs(dev1
, ABS_X
,
183 (packet
[1] | ((packet
[0] & 0x30) << 4)));
184 input_report_abs(dev1
, ABS_Y
,
185 1024 - (packet
[2] | ((packet
[0] & 0xC0) << 2)));
187 input_report_key(dev1
, BTN_TOUCH
, packet
[0] & 0x04);
193 psmouse_report_standard_motion(dev2
, packet
);
195 psmouse_report_standard_buttons(dev2
, packet
[0]);
199 return PSMOUSE_FULL_PACKET
;
202 static int lifebook_absolute_mode(struct psmouse
*psmouse
)
204 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
208 error
= psmouse_reset(psmouse
);
213 * Enable absolute output -- ps2_command fails always but if
214 * you leave this call out the touchscreen will never send
215 * absolute coordinates
217 param
= lifebook_use_6byte_proto
? 0x08 : 0x07;
218 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
223 static void lifebook_relative_mode(struct psmouse
*psmouse
)
225 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
228 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
231 static void lifebook_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
)
233 static const u8 params
[] = { 0, 1, 2, 2, 3 };
236 if (resolution
== 0 || resolution
> 400)
239 p
= params
[resolution
/ 100];
240 ps2_command(&psmouse
->ps2dev
, &p
, PSMOUSE_CMD_SETRES
);
241 psmouse
->resolution
= 50 << p
;
244 static void lifebook_disconnect(struct psmouse
*psmouse
)
246 struct lifebook_data
*priv
= psmouse
->private;
248 psmouse_reset(psmouse
);
250 input_unregister_device(priv
->dev2
);
253 psmouse
->private = NULL
;
256 int lifebook_detect(struct psmouse
*psmouse
, bool set_properties
)
258 if (!lifebook_present
)
261 if (desired_serio_phys
&&
262 strcmp(psmouse
->ps2dev
.serio
->phys
, desired_serio_phys
))
265 if (set_properties
) {
266 psmouse
->vendor
= "Fujitsu";
267 psmouse
->name
= "Lifebook TouchScreen";
273 static int lifebook_create_relative_device(struct psmouse
*psmouse
)
275 struct input_dev
*dev2
;
276 struct lifebook_data
*priv
;
279 priv
= kzalloc(sizeof(struct lifebook_data
), GFP_KERNEL
);
280 dev2
= input_allocate_device();
285 snprintf(priv
->phys
, sizeof(priv
->phys
),
286 "%s/input1", psmouse
->ps2dev
.serio
->phys
);
288 dev2
->phys
= priv
->phys
;
289 dev2
->name
= "LBPS/2 Fujitsu Lifebook Touchpad";
290 dev2
->id
.bustype
= BUS_I8042
;
291 dev2
->id
.vendor
= 0x0002;
292 dev2
->id
.product
= PSMOUSE_LIFEBOOK
;
293 dev2
->id
.version
= 0x0000;
294 dev2
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
296 input_set_capability(dev2
, EV_REL
, REL_X
);
297 input_set_capability(dev2
, EV_REL
, REL_Y
);
298 input_set_capability(dev2
, EV_KEY
, BTN_LEFT
);
299 input_set_capability(dev2
, EV_KEY
, BTN_RIGHT
);
301 error
= input_register_device(priv
->dev2
);
305 psmouse
->private = priv
;
309 input_free_device(dev2
);
314 int lifebook_init(struct psmouse
*psmouse
)
316 struct input_dev
*dev1
= psmouse
->dev
;
317 int max_coord
= lifebook_use_6byte_proto
? 4096 : 1024;
320 error
= lifebook_absolute_mode(psmouse
);
324 /* Clear default capabilities */
325 bitmap_zero(dev1
->evbit
, EV_CNT
);
326 bitmap_zero(dev1
->relbit
, REL_CNT
);
327 bitmap_zero(dev1
->keybit
, KEY_CNT
);
329 input_set_capability(dev1
, EV_KEY
, BTN_TOUCH
);
330 input_set_abs_params(dev1
, ABS_X
, 0, max_coord
, 0, 0);
331 input_set_abs_params(dev1
, ABS_Y
, 0, max_coord
, 0, 0);
333 if (!desired_serio_phys
) {
334 error
= lifebook_create_relative_device(psmouse
);
336 lifebook_relative_mode(psmouse
);
341 psmouse
->protocol_handler
= lifebook_process_byte
;
342 psmouse
->set_resolution
= lifebook_set_resolution
;
343 psmouse
->disconnect
= lifebook_disconnect
;
344 psmouse
->reconnect
= lifebook_absolute_mode
;
346 psmouse
->model
= lifebook_use_6byte_proto
? 6 : 3;
349 * Use packet size = 3 even when using 6-byte protocol because
350 * that's what POLL will return on Lifebooks (according to spec).
352 psmouse
->pktsize
= 3;