blob: 6ac7177e21cb00a12e9c07d68941d3fd2e33c6df [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 Torokhove7afcd12007-04-12 01:36:25 -040023static const char *desired_serio_phys;
24
25static int lifebook_set_serio_phys(struct dmi_system_id *d)
26{
27 desired_serio_phys = d->driver_data;
28 return 0;
29}
30
Dmitry Torokhov1b118792007-04-12 01:36:34 -040031static unsigned char lifebook_use_6byte_proto;
32
33static int lifebook_set_6byte_proto(struct dmi_system_id *d)
34{
35 lifebook_use_6byte_proto = 1;
36 return 0;
37}
38
Kenan Esau02d7f582005-05-29 02:30:22 -050039static struct dmi_system_id lifebook_dmi_table[] = {
Andrew Mortonb1b29652006-11-02 23:27:44 -050040 {
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 },
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040075 .callback = lifebook_set_serio_phys,
76 .driver_data = "isa0060/serio3",
Andrew Mortonb1b29652006-11-02 23:27:44 -050077 },
78 {
Dmitry Torokhov1b118792007-04-12 01:36:34 -040079 .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 {
Andrew Mortonb1b29652006-11-02 23:27:44 -050087 .ident = "Lifebook B142",
88 .matches = {
89 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
90 },
91 },
92 { }
Kenan Esau02d7f582005-05-29 02:30:22 -050093};
94
David Howells7d12e782006-10-05 14:55:46 +010095static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -050096{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -050097 struct input_dev *dev = psmouse->dev;
Dmitry Torokhov1b118792007-04-12 01:36:34 -040098 unsigned char *packet = psmouse->packet;
99 int relative_packet = packet[0] & 0x08;
Kenan Esau02d7f582005-05-29 02:30:22 -0500100
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400101 if (relative_packet || !lifebook_use_6byte_proto) {
102 if (psmouse->pktcnt != 3)
103 return PSMOUSE_GOOD_DATA;
Kenan Esau02d7f582005-05-29 02:30:22 -0500104 } else {
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400105 switch (psmouse->pktcnt) {
106 case 1:
107 return (packet[0] & 0xf8) == 0x00 ?
108 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
109 case 2:
110 return PSMOUSE_GOOD_DATA;
111 case 3:
112 return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
113 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
114 case 4:
115 return (packet[3] & 0xf8) == 0xc0 ?
116 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
117 case 5:
118 return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
119 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
120 case 6:
121 if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
122 return PSMOUSE_BAD_DATA;
123 if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
124 return PSMOUSE_BAD_DATA;
125 break; /* report data */
126 }
127 }
128
129 if (relative_packet) {
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500130 input_report_rel(dev, REL_X,
131 ((packet[0] & 0x10) ? packet[1] - 256 : packet[1]));
132 input_report_rel(dev, REL_Y,
133 -(int)((packet[0] & 0x20) ? packet[2] - 256 : packet[2]));
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400134 } else if (lifebook_use_6byte_proto) {
135 input_report_abs(dev, ABS_X,
136 ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
137 input_report_abs(dev, ABS_Y,
138 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
139 } else {
140 input_report_abs(dev, ABS_X,
141 (packet[1] | ((packet[0] & 0x30) << 4)));
142 input_report_abs(dev, ABS_Y,
143 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
Kenan Esau02d7f582005-05-29 02:30:22 -0500144 }
145
146 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
147 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
148 input_report_key(dev, BTN_TOUCH, packet[0] & 0x04);
149
150 input_sync(dev);
151
152 return PSMOUSE_FULL_PACKET;
153}
154
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500155static int lifebook_absolute_mode(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500156{
157 struct ps2dev *ps2dev = &psmouse->ps2dev;
158 unsigned char param;
159
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500160 if (psmouse_reset(psmouse))
Kenan Esau02d7f582005-05-29 02:30:22 -0500161 return -1;
162
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500163 /*
Kenan Esau02d7f582005-05-29 02:30:22 -0500164 Enable absolute output -- ps2_command fails always but if
165 you leave this call out the touchsreen will never send
166 absolute coordinates
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500167 */
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400168 param = lifebook_use_6byte_proto ? 0x08 : 0x07;
Kenan Esau02d7f582005-05-29 02:30:22 -0500169 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
170
Kenan Esau02d7f582005-05-29 02:30:22 -0500171 return 0;
172}
173
Dmitry Torokhova9138292005-05-29 02:30:37 -0500174static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
175{
Helge Dellere38de672006-09-10 21:54:39 -0400176 static const unsigned char params[] = { 0, 1, 2, 2, 3 };
177 unsigned char p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500178
179 if (resolution == 0 || resolution > 400)
180 resolution = 400;
181
Helge Dellere38de672006-09-10 21:54:39 -0400182 p = params[resolution / 100];
183 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
184 psmouse->resolution = 50 << p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500185}
186
Kenan Esau02d7f582005-05-29 02:30:22 -0500187static void lifebook_disconnect(struct psmouse *psmouse)
188{
189 psmouse_reset(psmouse);
190}
191
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500192int lifebook_detect(struct psmouse *psmouse, int set_properties)
Kenan Esau02d7f582005-05-29 02:30:22 -0500193{
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500194 if (!dmi_check_system(lifebook_dmi_table))
Kenan Esau02d7f582005-05-29 02:30:22 -0500195 return -1;
196
Dmitry Torokhove7afcd12007-04-12 01:36:25 -0400197 if (desired_serio_phys &&
198 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
199 return -1;
200
Kenan Esau02d7f582005-05-29 02:30:22 -0500201 if (set_properties) {
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500202 psmouse->vendor = "Fujitsu";
203 psmouse->name = "Lifebook TouchScreen";
Kenan Esau02d7f582005-05-29 02:30:22 -0500204 }
205
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500206 return 0;
Kenan Esau02d7f582005-05-29 02:30:22 -0500207}
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500208
209int lifebook_init(struct psmouse *psmouse)
210{
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500211 struct input_dev *input_dev = psmouse->dev;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400212 int max_coord = lifebook_use_6byte_proto ? 1024 : 4096;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500213
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500214 if (lifebook_absolute_mode(psmouse))
215 return -1;
216
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500217 input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY) | BIT(EV_REL);
218 input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
219 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
220 input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400221 input_set_abs_params(input_dev, ABS_X, 0, max_coord, 0, 0);
222 input_set_abs_params(input_dev, ABS_Y, 0, max_coord, 0, 0);
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500223
224 psmouse->protocol_handler = lifebook_process_byte;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500225 psmouse->set_resolution = lifebook_set_resolution;
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500226 psmouse->disconnect = lifebook_disconnect;
227 psmouse->reconnect = lifebook_absolute_mode;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400228
229 /*
230 * Use packet size = 3 even when using 6-byte protocol because
231 * that's what POLL will return on Lifebooks (according to spec).
232 */
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500233 psmouse->pktsize = 3;
234
235 return 0;
236}
237