blob: 5e6308694408d695515264885ea906053191136c [file] [log] [blame]
Kenan Esau02d7f582005-05-29 02:30:22 -05001/*
2 * Fujitsu B-series Lifebook PS/2 TouchScreen driver
3 *
4 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
5 * Copyright (c) 2005 Kenan Esau <kenan.esau@conan.de>
6 *
7 * TouchScreen detection, absolute mode setting and packet layout is taken from
8 * Harald Hoyer's description of the device.
9 *
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.
13 */
14
15#include <linux/input.h>
16#include <linux/serio.h>
17#include <linux/libps2.h>
18#include <linux/dmi.h>
19
20#include "psmouse.h"
21#include "lifebook.h"
22
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -040023struct lifebook_data {
24 struct input_dev *dev2; /* Relative device */
25 char phys[32];
26};
27
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040028static const char *desired_serio_phys;
29
Jeff Garzik18552562007-10-03 15:15:40 -040030static int lifebook_set_serio_phys(const struct dmi_system_id *d)
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040031{
32 desired_serio_phys = d->driver_data;
33 return 0;
34}
35
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070036static bool lifebook_use_6byte_proto;
Dmitry Torokhov1b118792007-04-12 01:36:34 -040037
Jeff Garzik18552562007-10-03 15:15:40 -040038static int lifebook_set_6byte_proto(const struct dmi_system_id *d)
Dmitry Torokhov1b118792007-04-12 01:36:34 -040039{
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070040 lifebook_use_6byte_proto = true;
Dmitry Torokhov1b118792007-04-12 01:36:34 -040041 return 0;
42}
43
Jeff Garzik18552562007-10-03 15:15:40 -040044static const struct dmi_system_id lifebook_dmi_table[] = {
Andrew Mortonb1b29652006-11-02 23:27:44 -050045 {
46 .ident = "FLORA-ie 55mi",
47 .matches = {
48 DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
49 },
50 },
51 {
52 .ident = "LifeBook B",
53 .matches = {
54 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
55 },
56 },
57 {
58 .ident = "Lifebook B",
59 .matches = {
60 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
61 },
62 },
63 {
Dmitry Torokhov6b9ff692009-04-24 12:01:47 -070064 .ident = "Lifebook B-2130",
65 .matches = {
66 DMI_MATCH(DMI_BOARD_NAME, "ZEPHYR"),
67 },
68 },
69 {
Andrew Mortonb1b29652006-11-02 23:27:44 -050070 .ident = "Lifebook B213x/B2150",
71 .matches = {
72 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
73 },
74 },
75 {
76 .ident = "Zephyr",
77 .matches = {
78 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
79 },
80 },
81 {
82 .ident = "CF-18",
83 .matches = {
84 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
85 },
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040086 .callback = lifebook_set_serio_phys,
87 .driver_data = "isa0060/serio3",
Andrew Mortonb1b29652006-11-02 23:27:44 -050088 },
89 {
Dmitry Torokhov1b118792007-04-12 01:36:34 -040090 .ident = "Panasonic CF-28",
91 .matches = {
92 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
93 DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
94 },
95 .callback = lifebook_set_6byte_proto,
96 },
97 {
Dmitry Torokhov43887ba2007-04-25 00:39:31 -040098 .ident = "Panasonic CF-29",
99 .matches = {
100 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
101 DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
102 },
103 .callback = lifebook_set_6byte_proto,
104 },
105 {
Dmitry Torokhovf76f6722007-09-05 00:22:17 -0400106 .ident = "CF-72",
107 .matches = {
108 DMI_MATCH(DMI_PRODUCT_NAME, "CF-72"),
109 },
110 .callback = lifebook_set_serio_phys,
111 .driver_data = "isa0060/serio3",
112 },
113 {
Andrew Mortonb1b29652006-11-02 23:27:44 -0500114 .ident = "Lifebook B142",
115 .matches = {
116 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
117 },
118 },
119 { }
Kenan Esau02d7f582005-05-29 02:30:22 -0500120};
121
David Howells7d12e782006-10-05 14:55:46 +0100122static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500123{
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400124 struct lifebook_data *priv = psmouse->private;
125 struct input_dev *dev1 = psmouse->dev;
Dmitry Torokhove6b20d82007-07-20 00:29:14 -0400126 struct input_dev *dev2 = priv ? priv->dev2 : NULL;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400127 unsigned char *packet = psmouse->packet;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700128 bool relative_packet = packet[0] & 0x08;
Kenan Esau02d7f582005-05-29 02:30:22 -0500129
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400130 if (relative_packet || !lifebook_use_6byte_proto) {
131 if (psmouse->pktcnt != 3)
132 return PSMOUSE_GOOD_DATA;
Kenan Esau02d7f582005-05-29 02:30:22 -0500133 } else {
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400134 switch (psmouse->pktcnt) {
135 case 1:
136 return (packet[0] & 0xf8) == 0x00 ?
137 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
138 case 2:
139 return PSMOUSE_GOOD_DATA;
140 case 3:
141 return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
142 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
143 case 4:
144 return (packet[3] & 0xf8) == 0xc0 ?
145 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
146 case 5:
147 return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
148 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
149 case 6:
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 */
155 }
156 }
157
158 if (relative_packet) {
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400159 if (!dev2)
160 printk(KERN_WARNING "lifebook.c: got relative packet "
161 "but no relative device set up\n");
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400162 } else {
Dmitry Torokhov9b771ac2009-05-08 18:30:32 -0700163 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)));
168 } else {
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)));
173 }
174 input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
175 input_sync(dev1);
Kenan Esau02d7f582005-05-29 02:30:22 -0500176 }
177
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400178 if (dev2) {
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]));
184 }
185 input_report_key(dev2, BTN_LEFT, packet[0] & 0x01);
186 input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02);
187 input_sync(dev2);
188 }
Kenan Esau02d7f582005-05-29 02:30:22 -0500189
190 return PSMOUSE_FULL_PACKET;
191}
192
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500193static int lifebook_absolute_mode(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500194{
195 struct ps2dev *ps2dev = &psmouse->ps2dev;
196 unsigned char param;
197
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500198 if (psmouse_reset(psmouse))
Kenan Esau02d7f582005-05-29 02:30:22 -0500199 return -1;
200
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500201 /*
Kenan Esau02d7f582005-05-29 02:30:22 -0500202 Enable absolute output -- ps2_command fails always but if
203 you leave this call out the touchsreen will never send
204 absolute coordinates
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500205 */
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400206 param = lifebook_use_6byte_proto ? 0x08 : 0x07;
Kenan Esau02d7f582005-05-29 02:30:22 -0500207 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
208
Kenan Esau02d7f582005-05-29 02:30:22 -0500209 return 0;
210}
211
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400212static void lifebook_relative_mode(struct psmouse *psmouse)
213{
214 struct ps2dev *ps2dev = &psmouse->ps2dev;
215 unsigned char param = 0x06;
216
217 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
218}
219
Dmitry Torokhova9138292005-05-29 02:30:37 -0500220static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
221{
Helge Dellere38de672006-09-10 21:54:39 -0400222 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
223 unsigned char p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500224
225 if (resolution == 0 || resolution > 400)
226 resolution = 400;
227
Helge Dellere38de672006-09-10 21:54:39 -0400228 p = params[resolution / 100];
229 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
230 psmouse->resolution = 50 << p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500231}
232
Kenan Esau02d7f582005-05-29 02:30:22 -0500233static void lifebook_disconnect(struct psmouse *psmouse)
234{
Andres Salomon653e91d2008-01-17 12:01:51 -0500235 struct lifebook_data *priv = psmouse->private;
236
Kenan Esau02d7f582005-05-29 02:30:22 -0500237 psmouse_reset(psmouse);
Andres Salomon653e91d2008-01-17 12:01:51 -0500238 if (priv) {
239 input_unregister_device(priv->dev2);
240 kfree(priv);
241 }
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400242 psmouse->private = NULL;
Kenan Esau02d7f582005-05-29 02:30:22 -0500243}
244
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700245int lifebook_detect(struct psmouse *psmouse, bool set_properties)
Kenan Esau02d7f582005-05-29 02:30:22 -0500246{
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500247 if (!dmi_check_system(lifebook_dmi_table))
Kenan Esau02d7f582005-05-29 02:30:22 -0500248 return -1;
249
Dmitry Torokhove7afcd12007-04-12 01:36:25 -0400250 if (desired_serio_phys &&
251 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
252 return -1;
253
Kenan Esau02d7f582005-05-29 02:30:22 -0500254 if (set_properties) {
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500255 psmouse->vendor = "Fujitsu";
256 psmouse->name = "Lifebook TouchScreen";
Kenan Esau02d7f582005-05-29 02:30:22 -0500257 }
258
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500259 return 0;
Kenan Esau02d7f582005-05-29 02:30:22 -0500260}
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500261
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400262static int lifebook_create_relative_device(struct psmouse *psmouse)
263{
264 struct input_dev *dev2;
265 struct lifebook_data *priv;
266 int error = -ENOMEM;
267
268 priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL);
269 dev2 = input_allocate_device();
270 if (!priv || !dev2)
271 goto err_out;
272
273 priv->dev2 = dev2;
274 snprintf(priv->phys, sizeof(priv->phys),
275 "%s/input1", psmouse->ps2dev.serio->phys);
276
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;
284
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700285 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) |
288 BIT_MASK(BTN_RIGHT);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400289
290 error = input_register_device(priv->dev2);
291 if (error)
292 goto err_out;
293
294 psmouse->private = priv;
295 return 0;
296
297 err_out:
298 input_free_device(dev2);
299 kfree(priv);
300 return error;
301}
302
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500303int lifebook_init(struct psmouse *psmouse)
304{
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400305 struct input_dev *dev1 = psmouse->dev;
Dmitry Torokhov62e729b2007-10-12 14:19:50 -0400306 int max_coord = lifebook_use_6byte_proto ? 4096 : 1024;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500307
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500308 if (lifebook_absolute_mode(psmouse))
309 return -1;
310
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700311 dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400312 dev1->relbit[0] = 0;
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700313 dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400314 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);
316
317 if (!desired_serio_phys) {
318 if (lifebook_create_relative_device(psmouse)) {
319 lifebook_relative_mode(psmouse);
320 return -1;
321 }
322 }
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500323
324 psmouse->protocol_handler = lifebook_process_byte;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500325 psmouse->set_resolution = lifebook_set_resolution;
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500326 psmouse->disconnect = lifebook_disconnect;
327 psmouse->reconnect = lifebook_absolute_mode;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400328
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400329 psmouse->model = lifebook_use_6byte_proto ? 6 : 3;
330
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400331 /*
332 * Use packet size = 3 even when using 6-byte protocol because
333 * that's what POLL will return on Lifebooks (according to spec).
334 */
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500335 psmouse->pktsize = 3;
336
337 return 0;
338}
339