RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / drivers / input / mouse / lifebook.c
blobf3b61af701f7da207fed5dadc8c78e8ec3eb1dfe
1 /*
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>
20 #include "psmouse.h"
21 #include "lifebook.h"
23 struct lifebook_data {
24 struct input_dev *dev2; /* Relative device */
25 char phys[32];
28 static const char *desired_serio_phys;
30 static int lifebook_set_serio_phys(struct dmi_system_id *d)
32 desired_serio_phys = d->driver_data;
33 return 0;
36 static unsigned char lifebook_use_6byte_proto;
38 static int lifebook_set_6byte_proto(struct dmi_system_id *d)
40 lifebook_use_6byte_proto = 1;
41 return 0;
44 static struct dmi_system_id lifebook_dmi_table[] = {
46 .ident = "FLORA-ie 55mi",
47 .matches = {
48 DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
52 .ident = "LifeBook B",
53 .matches = {
54 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
58 .ident = "Lifebook B",
59 .matches = {
60 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
64 .ident = "Lifebook B213x/B2150",
65 .matches = {
66 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
70 .ident = "Zephyr",
71 .matches = {
72 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
76 .ident = "CF-18",
77 .matches = {
78 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
80 .callback = lifebook_set_serio_phys,
81 .driver_data = "isa0060/serio3",
84 .ident = "Panasonic CF-28",
85 .matches = {
86 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
87 DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
89 .callback = lifebook_set_6byte_proto,
92 .ident = "Panasonic CF-29",
93 .matches = {
94 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
95 DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
97 .callback = lifebook_set_6byte_proto,
100 .ident = "Lifebook B142",
101 .matches = {
102 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
108 static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
110 struct lifebook_data *priv = psmouse->private;
111 struct input_dev *dev1 = psmouse->dev;
112 struct input_dev *dev2 = priv ? priv->dev2 : NULL;
113 unsigned char *packet = psmouse->packet;
114 int relative_packet = packet[0] & 0x08;
116 if (relative_packet || !lifebook_use_6byte_proto) {
117 if (psmouse->pktcnt != 3)
118 return PSMOUSE_GOOD_DATA;
119 } else {
120 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 */
144 if (relative_packet) {
145 if (!dev2)
146 printk(KERN_WARNING "lifebook.c: got relative packet "
147 "but no relative device set up\n");
148 } else if (lifebook_use_6byte_proto) {
149 input_report_abs(dev1, ABS_X,
150 ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
151 input_report_abs(dev1, ABS_Y,
152 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
153 } else {
154 input_report_abs(dev1, ABS_X,
155 (packet[1] | ((packet[0] & 0x30) << 4)));
156 input_report_abs(dev1, ABS_Y,
157 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
160 input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
161 input_sync(dev1);
163 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]));
170 input_report_key(dev2, BTN_LEFT, packet[0] & 0x01);
171 input_report_key(dev2, BTN_RIGHT, packet[0] & 0x02);
172 input_sync(dev2);
175 return PSMOUSE_FULL_PACKET;
178 static int lifebook_absolute_mode(struct psmouse *psmouse)
180 struct ps2dev *ps2dev = &psmouse->ps2dev;
181 unsigned char param;
183 if (psmouse_reset(psmouse))
184 return -1;
187 Enable absolute output -- ps2_command fails always but if
188 you leave this call out the touchsreen will never send
189 absolute coordinates
191 param = lifebook_use_6byte_proto ? 0x08 : 0x07;
192 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
194 return 0;
197 static void lifebook_relative_mode(struct psmouse *psmouse)
199 struct ps2dev *ps2dev = &psmouse->ps2dev;
200 unsigned char param = 0x06;
202 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
205 static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
207 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
208 unsigned char p;
210 if (resolution == 0 || resolution > 400)
211 resolution = 400;
213 p = params[resolution / 100];
214 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
215 psmouse->resolution = 50 << p;
218 static void lifebook_disconnect(struct psmouse *psmouse)
220 psmouse_reset(psmouse);
221 kfree(psmouse->private);
222 psmouse->private = NULL;
225 int lifebook_detect(struct psmouse *psmouse, int set_properties)
227 if (!dmi_check_system(lifebook_dmi_table))
228 return -1;
230 if (desired_serio_phys &&
231 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
232 return -1;
234 if (set_properties) {
235 psmouse->vendor = "Fujitsu";
236 psmouse->name = "Lifebook TouchScreen";
239 return 0;
242 static int lifebook_create_relative_device(struct psmouse *psmouse)
244 struct input_dev *dev2;
245 struct lifebook_data *priv;
246 int error = -ENOMEM;
248 priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL);
249 dev2 = input_allocate_device();
250 if (!priv || !dev2)
251 goto err_out;
253 priv->dev2 = dev2;
254 snprintf(priv->phys, sizeof(priv->phys),
255 "%s/input1", psmouse->ps2dev.serio->phys);
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;
265 dev2->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
266 dev2->relbit[BIT_WORD(REL_X)] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
267 dev2->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
268 BIT_MASK(BTN_RIGHT);
270 error = input_register_device(priv->dev2);
271 if (error)
272 goto err_out;
274 psmouse->private = priv;
275 return 0;
277 err_out:
278 input_free_device(dev2);
279 kfree(priv);
280 return error;
283 int lifebook_init(struct psmouse *psmouse)
285 struct input_dev *dev1 = psmouse->dev;
286 int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
288 if (lifebook_absolute_mode(psmouse))
289 return -1;
291 dev1->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
292 dev1->relbit[0] = 0;
293 dev1->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
294 input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0);
295 input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0);
297 if (!desired_serio_phys) {
298 if (lifebook_create_relative_device(psmouse)) {
299 lifebook_relative_mode(psmouse);
300 return -1;
304 psmouse->protocol_handler = lifebook_process_byte;
305 psmouse->set_resolution = lifebook_set_resolution;
306 psmouse->disconnect = lifebook_disconnect;
307 psmouse->reconnect = lifebook_absolute_mode;
309 psmouse->model = lifebook_use_6byte_proto ? 6 : 3;
312 * Use packet size = 3 even when using 6-byte protocol because
313 * that's what POLL will return on Lifebooks (according to spec).
315 psmouse->pktsize = 3;
317 return 0;