Input: lifebook - add signature of Panasonic CF-29
[linux-2.6] / drivers / input / mouse / lifebook.c
1 /*
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
23 static const char *desired_serio_phys;
24
25 static int lifebook_set_serio_phys(struct dmi_system_id *d)
26 {
27         desired_serio_phys = d->driver_data;
28         return 0;
29 }
30
31 static unsigned char lifebook_use_6byte_proto;
32
33 static int lifebook_set_6byte_proto(struct dmi_system_id *d)
34 {
35         lifebook_use_6byte_proto = 1;
36         return 0;
37 }
38
39 static struct dmi_system_id lifebook_dmi_table[] = {
40         {
41                 .ident = "FLORA-ie 55mi",
42                 .matches = {
43                         DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
44                 },
45         },
46         {
47                 .ident = "LifeBook B",
48                 .matches = {
49                         DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
50                 },
51         },
52         {
53                 .ident = "Lifebook B",
54                 .matches = {
55                         DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
56                 },
57         },
58         {
59                 .ident = "Lifebook B213x/B2150",
60                 .matches = {
61                         DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
62                 },
63         },
64         {
65                 .ident = "Zephyr",
66                 .matches = {
67                         DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
68                 },
69         },
70         {
71                 .ident = "CF-18",
72                 .matches = {
73                         DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
74                 },
75                 .callback = lifebook_set_serio_phys,
76                 .driver_data = "isa0060/serio3",
77         },
78         {
79                 .ident = "Panasonic CF-28",
80                 .matches = {
81                         DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
82                         DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
83                 },
84                 .callback = lifebook_set_6byte_proto,
85         },
86         {
87                 .ident = "Panasonic CF-29",
88                 .matches = {
89                         DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
90                         DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
91                 },
92                 .callback = lifebook_set_6byte_proto,
93         },
94         {
95                 .ident = "Lifebook B142",
96                 .matches = {
97                         DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
98                 },
99         },
100         { }
101 };
102
103 static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
104 {
105         struct input_dev *dev = psmouse->dev;
106         unsigned char *packet = psmouse->packet;
107         int relative_packet = packet[0] & 0x08;
108
109         if (relative_packet || !lifebook_use_6byte_proto) {
110                 if (psmouse->pktcnt != 3)
111                         return PSMOUSE_GOOD_DATA;
112         } else {
113                 switch (psmouse->pktcnt) {
114                 case 1:
115                         return (packet[0] & 0xf8) == 0x00 ?
116                                 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
117                 case 2:
118                         return PSMOUSE_GOOD_DATA;
119                 case 3:
120                         return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
121                                 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
122                 case 4:
123                         return (packet[3] & 0xf8) == 0xc0 ?
124                                 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
125                 case 5:
126                         return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
127                                 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
128                 case 6:
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 */
134                 }
135         }
136
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)));
147         } else {
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)));
152         }
153
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);
157
158         input_sync(dev);
159
160         return PSMOUSE_FULL_PACKET;
161 }
162
163 static int lifebook_absolute_mode(struct psmouse *psmouse)
164 {
165         struct ps2dev *ps2dev = &psmouse->ps2dev;
166         unsigned char param;
167
168         if (psmouse_reset(psmouse))
169                 return -1;
170
171         /*
172            Enable absolute output -- ps2_command fails always but if
173            you leave this call out the touchsreen will never send
174            absolute coordinates
175         */
176         param = lifebook_use_6byte_proto ? 0x08 : 0x07;
177         ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
178
179         return 0;
180 }
181
182 static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
183 {
184         static const unsigned char params[] = { 0, 1, 2, 2, 3 };
185         unsigned char p;
186
187         if (resolution == 0 || resolution > 400)
188                 resolution = 400;
189
190         p = params[resolution / 100];
191         ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
192         psmouse->resolution = 50 << p;
193 }
194
195 static void lifebook_disconnect(struct psmouse *psmouse)
196 {
197         psmouse_reset(psmouse);
198 }
199
200 int lifebook_detect(struct psmouse *psmouse, int set_properties)
201 {
202         if (!dmi_check_system(lifebook_dmi_table))
203                 return -1;
204
205         if (desired_serio_phys &&
206             strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
207                 return -1;
208
209         if (set_properties) {
210                 psmouse->vendor = "Fujitsu";
211                 psmouse->name = "Lifebook TouchScreen";
212         }
213
214         return 0;
215 }
216
217 int lifebook_init(struct psmouse *psmouse)
218 {
219         struct input_dev *input_dev = psmouse->dev;
220         int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
221
222         if (lifebook_absolute_mode(psmouse))
223                 return -1;
224
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);
231
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;
236
237         /*
238          * Use packet size = 3 even when using 6-byte protocol because
239          * that's what POLL will return on Lifebooks (according to spec).
240          */
241         psmouse->pktsize = 3;
242
243         return 0;
244 }
245