1 // SPDX-License-Identifier: GPL-2.0-only
3 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
5 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de>
8 * TouchScreen detection, absolute mode setting and packet layout is taken from
9 * Harald Hoyer's description of the device.
12 #include <linux/input.h>
13 #include <linux/serio.h>
14 #include <linux/libps2.h>
15 #include <linux/dmi.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
22 struct lifebook_data
{
23 struct input_dev
*dev2
; /* Relative device */
27 static bool lifebook_present
;
29 static const char *desired_serio_phys
;
31 static int lifebook_limit_serio3(const struct dmi_system_id
*d
)
33 desired_serio_phys
= "isa0060/serio3";
37 static bool lifebook_use_6byte_proto
;
39 static int lifebook_set_6byte_proto(const struct dmi_system_id
*d
)
41 lifebook_use_6byte_proto
= true;
45 static const struct dmi_system_id lifebook_dmi_table
[] __initconst
= {
49 DMI_MATCH(DMI_PRODUCT_NAME
, "FLORA-ie 55mi"),
55 DMI_MATCH(DMI_PRODUCT_NAME
, "Lifebook B Series"),
61 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B Series"),
67 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK B Series"),
73 DMI_MATCH(DMI_BOARD_NAME
, "ZEPHYR"),
77 /* Lifebook B213x/B2150 */
79 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B2131/B2133/B2150"),
85 DMI_MATCH(DMI_PRODUCT_NAME
, "ZEPHYR"),
91 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-18"),
93 .callback
= lifebook_limit_serio3
,
98 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
99 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-28"),
101 .callback
= lifebook_set_6byte_proto
,
104 /* Panasonic CF-29 */
106 DMI_MATCH(DMI_SYS_VENDOR
, "Matsushita"),
107 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-29"),
109 .callback
= lifebook_set_6byte_proto
,
112 /* Panasonic CF-72 */
114 DMI_MATCH(DMI_PRODUCT_NAME
, "CF-72"),
116 .callback
= lifebook_set_6byte_proto
,
121 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook B142"),
127 void __init
lifebook_module_init(void)
129 lifebook_present
= dmi_check_system(lifebook_dmi_table
);
132 static psmouse_ret_t
lifebook_process_byte(struct psmouse
*psmouse
)
134 struct lifebook_data
*priv
= psmouse
->private;
135 struct input_dev
*dev1
= psmouse
->dev
;
136 struct input_dev
*dev2
= priv
? priv
->dev2
: NULL
;
137 u8
*packet
= psmouse
->packet
;
138 bool relative_packet
= packet
[0] & 0x08;
140 if (relative_packet
|| !lifebook_use_6byte_proto
) {
141 if (psmouse
->pktcnt
!= 3)
142 return PSMOUSE_GOOD_DATA
;
144 switch (psmouse
->pktcnt
) {
146 return (packet
[0] & 0xf8) == 0x00 ?
147 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
149 return PSMOUSE_GOOD_DATA
;
151 return ((packet
[2] & 0x30) << 2) == (packet
[2] & 0xc0) ?
152 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
154 return (packet
[3] & 0xf8) == 0xc0 ?
155 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
157 return (packet
[4] & 0xc0) == (packet
[2] & 0xc0) ?
158 PSMOUSE_GOOD_DATA
: PSMOUSE_BAD_DATA
;
160 if (((packet
[5] & 0x30) << 2) != (packet
[5] & 0xc0))
161 return PSMOUSE_BAD_DATA
;
162 if ((packet
[5] & 0xc0) != (packet
[1] & 0xc0))
163 return PSMOUSE_BAD_DATA
;
164 break; /* report data */
168 if (relative_packet
) {
170 psmouse_warn(psmouse
,
171 "got relative packet but no relative device set up\n");
173 if (lifebook_use_6byte_proto
) {
174 input_report_abs(dev1
, ABS_X
,
175 ((packet
[1] & 0x3f) << 6) | (packet
[2] & 0x3f));
176 input_report_abs(dev1
, ABS_Y
,
177 4096 - (((packet
[4] & 0x3f) << 6) | (packet
[5] & 0x3f)));
179 input_report_abs(dev1
, ABS_X
,
180 (packet
[1] | ((packet
[0] & 0x30) << 4)));
181 input_report_abs(dev1
, ABS_Y
,
182 1024 - (packet
[2] | ((packet
[0] & 0xC0) << 2)));
184 input_report_key(dev1
, BTN_TOUCH
, packet
[0] & 0x04);
190 psmouse_report_standard_motion(dev2
, packet
);
192 psmouse_report_standard_buttons(dev2
, packet
[0]);
196 return PSMOUSE_FULL_PACKET
;
199 static int lifebook_absolute_mode(struct psmouse
*psmouse
)
201 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
205 error
= psmouse_reset(psmouse
);
210 * Enable absolute output -- ps2_command fails always but if
211 * you leave this call out the touchscreen will never send
212 * absolute coordinates
214 param
= lifebook_use_6byte_proto
? 0x08 : 0x07;
215 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
220 static void lifebook_relative_mode(struct psmouse
*psmouse
)
222 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
225 ps2_command(ps2dev
, ¶m
, PSMOUSE_CMD_SETRES
);
228 static void lifebook_set_resolution(struct psmouse
*psmouse
, unsigned int resolution
)
230 static const u8 params
[] = { 0, 1, 2, 2, 3 };
233 if (resolution
== 0 || resolution
> 400)
236 p
= params
[resolution
/ 100];
237 ps2_command(&psmouse
->ps2dev
, &p
, PSMOUSE_CMD_SETRES
);
238 psmouse
->resolution
= 50 << p
;
241 static void lifebook_disconnect(struct psmouse
*psmouse
)
243 struct lifebook_data
*priv
= psmouse
->private;
245 psmouse_reset(psmouse
);
247 input_unregister_device(priv
->dev2
);
250 psmouse
->private = NULL
;
253 int lifebook_detect(struct psmouse
*psmouse
, bool set_properties
)
255 if (!lifebook_present
)
258 if (desired_serio_phys
&&
259 strcmp(psmouse
->ps2dev
.serio
->phys
, desired_serio_phys
))
262 if (set_properties
) {
263 psmouse
->vendor
= "Fujitsu";
264 psmouse
->name
= "Lifebook TouchScreen";
270 static int lifebook_create_relative_device(struct psmouse
*psmouse
)
272 struct input_dev
*dev2
;
273 struct lifebook_data
*priv
;
276 priv
= kzalloc(sizeof(struct lifebook_data
), GFP_KERNEL
);
277 dev2
= input_allocate_device();
282 snprintf(priv
->phys
, sizeof(priv
->phys
),
283 "%s/input1", psmouse
->ps2dev
.serio
->phys
);
285 dev2
->phys
= priv
->phys
;
286 dev2
->name
= "LBPS/2 Fujitsu Lifebook Touchpad";
287 dev2
->id
.bustype
= BUS_I8042
;
288 dev2
->id
.vendor
= 0x0002;
289 dev2
->id
.product
= PSMOUSE_LIFEBOOK
;
290 dev2
->id
.version
= 0x0000;
291 dev2
->dev
.parent
= &psmouse
->ps2dev
.serio
->dev
;
293 input_set_capability(dev2
, EV_REL
, REL_X
);
294 input_set_capability(dev2
, EV_REL
, REL_Y
);
295 input_set_capability(dev2
, EV_KEY
, BTN_LEFT
);
296 input_set_capability(dev2
, EV_KEY
, BTN_RIGHT
);
298 error
= input_register_device(priv
->dev2
);
302 psmouse
->private = priv
;
306 input_free_device(dev2
);
311 int lifebook_init(struct psmouse
*psmouse
)
313 struct input_dev
*dev1
= psmouse
->dev
;
314 int max_coord
= lifebook_use_6byte_proto
? 4096 : 1024;
317 error
= lifebook_absolute_mode(psmouse
);
321 /* Clear default capabilities */
322 bitmap_zero(dev1
->evbit
, EV_CNT
);
323 bitmap_zero(dev1
->relbit
, REL_CNT
);
324 bitmap_zero(dev1
->keybit
, KEY_CNT
);
326 input_set_capability(dev1
, EV_KEY
, 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 error
= lifebook_create_relative_device(psmouse
);
333 lifebook_relative_mode(psmouse
);
338 psmouse
->protocol_handler
= lifebook_process_byte
;
339 psmouse
->set_resolution
= lifebook_set_resolution
;
340 psmouse
->disconnect
= lifebook_disconnect
;
341 psmouse
->reconnect
= lifebook_absolute_mode
;
343 psmouse
->model
= lifebook_use_6byte_proto
? 6 : 3;
346 * Use packet size = 3 even when using 6-byte protocol because
347 * that's what POLL will return on Lifebooks (according to spec).
349 psmouse
->pktsize
= 3;