blob: 608674d0be8b25e95e5e9b165f0516bed34ff319 [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 Torokhov1b118792007-04-12 01:36:34 -040036static unsigned char lifebook_use_6byte_proto;
37
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{
40 lifebook_use_6byte_proto = 1;
41 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 {
64 .ident = "Lifebook B213x/B2150",
65 .matches = {
66 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
67 },
68 },
69 {
70 .ident = "Zephyr",
71 .matches = {
72 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
73 },
74 },
75 {
76 .ident = "CF-18",
77 .matches = {
78 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
79 },
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040080 .callback = lifebook_set_serio_phys,
81 .driver_data = "isa0060/serio3",
Andrew Mortonb1b29652006-11-02 23:27:44 -050082 },
83 {
Dmitry Torokhov1b118792007-04-12 01:36:34 -040084 .ident = "Panasonic CF-28",
85 .matches = {
86 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
87 DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
88 },
89 .callback = lifebook_set_6byte_proto,
90 },
91 {
Dmitry Torokhov43887ba2007-04-25 00:39:31 -040092 .ident = "Panasonic CF-29",
93 .matches = {
94 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
95 DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
96 },
97 .callback = lifebook_set_6byte_proto,
98 },
99 {
Andrew Mortonb1b29652006-11-02 23:27:44 -0500100 .ident = "Lifebook B142",
101 .matches = {
102 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
103 },
104 },
105 { }
Kenan Esau02d7f582005-05-29 02:30:22 -0500106};
107
David Howells7d12e782006-10-05 14:55:46 +0100108static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500109{
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400110 struct lifebook_data *priv = psmouse->private;
111 struct input_dev *dev1 = psmouse->dev;
Dmitry Torokhove6b20d82007-07-20 00:29:14 -0400112 struct input_dev *dev2 = priv ? priv->dev2 : NULL;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400113 unsigned char *packet = psmouse->packet;
114 int relative_packet = packet[0] & 0x08;
Kenan Esau02d7f582005-05-29 02:30:22 -0500115
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400116 if (relative_packet || !lifebook_use_6byte_proto) {
117 if (psmouse->pktcnt != 3)
118 return PSMOUSE_GOOD_DATA;
Kenan Esau02d7f582005-05-29 02:30:22 -0500119 } else {
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400120 switch (psmouse->pktcnt) {
121 case 1:
122 return (packet[0] & 0xf8) == 0x00 ?
123 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
124 case 2:
125 return PSMOUSE_GOOD_DATA;
126 case 3:
127 return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
128 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
129 case 4:
130 return (packet[3] & 0xf8) == 0xc0 ?
131 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
132 case 5:
133 return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
134 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
135 case 6:
136 if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
137 return PSMOUSE_BAD_DATA;
138 if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
139 return PSMOUSE_BAD_DATA;
140 break; /* report data */
141 }
142 }
143
144 if (relative_packet) {
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400145 if (!dev2)
146 printk(KERN_WARNING "lifebook.c: got relative packet "
147 "but no relative device set up\n");
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400148 } else if (lifebook_use_6byte_proto) {
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400149 input_report_abs(dev1, ABS_X,
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400150 ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400151 input_report_abs(dev1, ABS_Y,
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400152 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
153 } else {
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400154 input_report_abs(dev1, ABS_X,
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400155 (packet[1] | ((packet[0] & 0x30) << 4)));
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400156 input_report_abs(dev1, ABS_Y,
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400157 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
Kenan Esau02d7f582005-05-29 02:30:22 -0500158 }
159
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400160 input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
161 input_sync(dev1);
Kenan Esau02d7f582005-05-29 02:30:22 -0500162
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400163 if (dev2) {
164 if (relative_packet) {
165 input_report_rel(dev2, REL_X,
166 ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
167 input_report_rel(dev2, REL_Y,
168 -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
169 }
170 input_report_key(dev2, BTN_LEFT, packet[0] & 0x01);
171 input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02);
172 input_sync(dev2);
173 }
Kenan Esau02d7f582005-05-29 02:30:22 -0500174
175 return PSMOUSE_FULL_PACKET;
176}
177
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500178static int lifebook_absolute_mode(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500179{
180 struct ps2dev *ps2dev = &psmouse->ps2dev;
181 unsigned char param;
182
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500183 if (psmouse_reset(psmouse))
Kenan Esau02d7f582005-05-29 02:30:22 -0500184 return -1;
185
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500186 /*
Kenan Esau02d7f582005-05-29 02:30:22 -0500187 Enable absolute output -- ps2_command fails always but if
188 you leave this call out the touchsreen will never send
189 absolute coordinates
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500190 */
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400191 param = lifebook_use_6byte_proto ? 0x08 : 0x07;
Kenan Esau02d7f582005-05-29 02:30:22 -0500192 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
193
Kenan Esau02d7f582005-05-29 02:30:22 -0500194 return 0;
195}
196
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400197static void lifebook_relative_mode(struct psmouse *psmouse)
198{
199 struct ps2dev *ps2dev = &psmouse->ps2dev;
200 unsigned char param = 0x06;
201
202 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
203}
204
Dmitry Torokhova9138292005-05-29 02:30:37 -0500205static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
206{
Helge Dellere38de672006-09-10 21:54:39 -0400207 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
208 unsigned char p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500209
210 if (resolution == 0 || resolution > 400)
211 resolution = 400;
212
Helge Dellere38de672006-09-10 21:54:39 -0400213 p = params[resolution / 100];
214 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
215 psmouse->resolution = 50 << p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500216}
217
Kenan Esau02d7f582005-05-29 02:30:22 -0500218static void lifebook_disconnect(struct psmouse *psmouse)
219{
220 psmouse_reset(psmouse);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400221 kfree(psmouse->private);
222 psmouse->private = NULL;
Kenan Esau02d7f582005-05-29 02:30:22 -0500223}
224
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500225int lifebook_detect(struct psmouse *psmouse, int set_properties)
Kenan Esau02d7f582005-05-29 02:30:22 -0500226{
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500227 if (!dmi_check_system(lifebook_dmi_table))
Kenan Esau02d7f582005-05-29 02:30:22 -0500228 return -1;
229
Dmitry Torokhove7afcd12007-04-12 01:36:25 -0400230 if (desired_serio_phys &&
231 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
232 return -1;
233
Kenan Esau02d7f582005-05-29 02:30:22 -0500234 if (set_properties) {
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500235 psmouse->vendor = "Fujitsu";
236 psmouse->name = "Lifebook TouchScreen";
Kenan Esau02d7f582005-05-29 02:30:22 -0500237 }
238
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500239 return 0;
Kenan Esau02d7f582005-05-29 02:30:22 -0500240}
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500241
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400242static int lifebook_create_relative_device(struct psmouse *psmouse)
243{
244 struct input_dev *dev2;
245 struct lifebook_data *priv;
246 int error = -ENOMEM;
247
248 priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL);
249 dev2 = input_allocate_device();
250 if (!priv || !dev2)
251 goto err_out;
252
253 priv->dev2 = dev2;
254 snprintf(priv->phys, sizeof(priv->phys),
255 "%s/input1", psmouse->ps2dev.serio->phys);
256
257 dev2->phys = priv->phys;
258 dev2->name = "PS/2 Touchpad";
259 dev2->id.bustype = BUS_I8042;
260 dev2->id.vendor = 0x0002;
261 dev2->id.product = PSMOUSE_LIFEBOOK;
262 dev2->id.version = 0x0000;
263 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
264
265 dev2->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
266 dev2->relbit[LONG(REL_X)] = BIT(REL_X) | BIT(REL_Y);
267 dev2->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT);
268
269 error = input_register_device(priv->dev2);
270 if (error)
271 goto err_out;
272
273 psmouse->private = priv;
274 return 0;
275
276 err_out:
277 input_free_device(dev2);
278 kfree(priv);
279 return error;
280}
281
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500282int lifebook_init(struct psmouse *psmouse)
283{
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400284 struct input_dev *dev1 = psmouse->dev;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400285 int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500286
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500287 if (lifebook_absolute_mode(psmouse))
288 return -1;
289
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400290 dev1->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
291 dev1->relbit[0] = 0;
292 dev1->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
293 input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0);
294 input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0);
295
296 if (!desired_serio_phys) {
297 if (lifebook_create_relative_device(psmouse)) {
298 lifebook_relative_mode(psmouse);
299 return -1;
300 }
301 }
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500302
303 psmouse->protocol_handler = lifebook_process_byte;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500304 psmouse->set_resolution = lifebook_set_resolution;
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500305 psmouse->disconnect = lifebook_disconnect;
306 psmouse->reconnect = lifebook_absolute_mode;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400307
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400308 psmouse->model = lifebook_use_6byte_proto ? 6 : 3;
309
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400310 /*
311 * Use packet size = 3 even when using 6-byte protocol because
312 * that's what POLL will return on Lifebooks (according to spec).
313 */
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500314 psmouse->pktsize = 3;
315
316 return 0;
317}
318