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 static const char *desired_serio_phys;
25 static int lifebook_set_serio_phys(struct dmi_system_id *d)
27 desired_serio_phys = d->driver_data;
31 static unsigned char lifebook_use_6byte_proto;
33 static int lifebook_set_6byte_proto(struct dmi_system_id *d)
35 lifebook_use_6byte_proto = 1;
39 static struct dmi_system_id lifebook_dmi_table[] = {
41 .ident = "FLORA-ie 55mi",
43 DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
47 .ident = "LifeBook B",
49 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
53 .ident = "Lifebook B",
55 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
59 .ident = "Lifebook B213x/B2150",
61 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
67 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
73 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
75 .callback = lifebook_set_serio_phys,
76 .driver_data = "isa0060/serio3",
79 .ident = "Panasonic CF-28",
81 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
82 DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
84 .callback = lifebook_set_6byte_proto,
87 .ident = "Panasonic CF-29",
89 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
90 DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
92 .callback = lifebook_set_6byte_proto,
95 .ident = "Lifebook B142",
97 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
103 static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
105 struct input_dev *dev = psmouse->dev;
106 unsigned char *packet = psmouse->packet;
107 int relative_packet = packet[0] & 0x08;
109 if (relative_packet || !lifebook_use_6byte_proto) {
110 if (psmouse->pktcnt != 3)
111 return PSMOUSE_GOOD_DATA;
113 switch (psmouse->pktcnt) {
115 return (packet[0] & 0xf8) == 0x00 ?
116 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
118 return PSMOUSE_GOOD_DATA;
120 return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
121 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
123 return (packet[3] & 0xf8) == 0xc0 ?
124 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
126 return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
127 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
129 if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
130 return PSMOUSE_BAD_DATA;
131 if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
132 return PSMOUSE_BAD_DATA;
133 break; /* report data */
137 if (relative_packet) {
138 input_report_rel(dev, REL_X,
139 ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
140 input_report_rel(dev, REL_Y,
141 -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
142 } else if (lifebook_use_6byte_proto) {
143 input_report_abs(dev, ABS_X,
144 ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
145 input_report_abs(dev, ABS_Y,
146 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
148 input_report_abs(dev, ABS_X,
149 (packet[1] | ((packet[0] & 0x30) << 4)));
150 input_report_abs(dev, ABS_Y,
151 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
154 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
155 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
156 input_report_key(dev, BTN_TOUCH, packet[0] & 0x04);
160 return PSMOUSE_FULL_PACKET;
163 static int lifebook_absolute_mode(struct psmouse *psmouse)
165 struct ps2dev *ps2dev = &psmouse->ps2dev;
168 if (psmouse_reset(psmouse))
172 Enable absolute output -- ps2_command fails always but if
173 you leave this call out the touchsreen will never send
176 param = lifebook_use_6byte_proto ? 0x08 : 0x07;
177 ps2_command(ps2dev, ¶m, PSMOUSE_CMD_SETRES);
182 static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
184 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
187 if (resolution == 0 || resolution > 400)
190 p = params[resolution / 100];
191 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
192 psmouse->resolution = 50 << p;
195 static void lifebook_disconnect(struct psmouse *psmouse)
197 psmouse_reset(psmouse);
200 int lifebook_detect(struct psmouse *psmouse, int set_properties)
202 if (!dmi_check_system(lifebook_dmi_table))
205 if (desired_serio_phys &&
206 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
209 if (set_properties) {
210 psmouse->vendor = "Fujitsu";
211 psmouse->name = "Lifebook TouchScreen";
217 int lifebook_init(struct psmouse *psmouse)
219 struct input_dev *input_dev = psmouse->dev;
220 int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
222 if (lifebook_absolute_mode(psmouse))
225 input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
226 input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
227 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
228 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
229 input_set_abs_params(input_dev, ABS_X, 0, max_coord, 0, 0);
230 input_set_abs_params(input_dev, ABS_Y, 0, max_coord, 0, 0);
232 psmouse->protocol_handler = lifebook_process_byte;
233 psmouse->set_resolution = lifebook_set_resolution;
234 psmouse->disconnect = lifebook_disconnect;
235 psmouse->reconnect = lifebook_absolute_mode;
238 * Use packet size = 3 even when using 6-byte protocol because
239 * that's what POLL will return on Lifebooks (according to spec).
241 psmouse->pktsize = 3;