blob: a5765f747c020b30cc6ecff500a94b6aa2c904ad [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Dmitry Torokhovc13b4182017-03-22 15:18:28 -070020#include <linux/types.h>
Kenan Esau02d7f582005-05-29 02:30:22 -050021
22#include "psmouse.h"
23#include "lifebook.h"
24
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -040025struct lifebook_data {
26 struct input_dev *dev2; /* Relative device */
27 char phys[32];
28};
29
Dmitry Torokhov7705d542009-12-03 23:21:14 -080030static bool lifebook_present;
31
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040032static const char *desired_serio_phys;
33
Dmitry Torokhov7705d542009-12-03 23:21:14 -080034static int lifebook_limit_serio3(const struct dmi_system_id *d)
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040035{
Dmitry Torokhov7705d542009-12-03 23:21:14 -080036 desired_serio_phys = "isa0060/serio3";
Axel Linfea20212011-07-13 00:02:21 -070037 return 1;
Dmitry Torokhove7afcd12007-04-12 01:36:25 -040038}
39
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070040static bool lifebook_use_6byte_proto;
Dmitry Torokhov1b118792007-04-12 01:36:34 -040041
Jeff Garzik18552562007-10-03 15:15:40 -040042static int lifebook_set_6byte_proto(const struct dmi_system_id *d)
Dmitry Torokhov1b118792007-04-12 01:36:34 -040043{
Dmitry Torokhovb7802c52009-09-09 19:13:20 -070044 lifebook_use_6byte_proto = true;
Axel Linfea20212011-07-13 00:02:21 -070045 return 1;
Dmitry Torokhov1b118792007-04-12 01:36:34 -040046}
47
Sachin Kamat3bd8a8b2013-08-12 11:05:43 -070048static const struct dmi_system_id lifebook_dmi_table[] __initconst = {
Andrew Mortonb1b29652006-11-02 23:27:44 -050049 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080050 /* FLORA-ie 55mi */
Andrew Mortonb1b29652006-11-02 23:27:44 -050051 .matches = {
52 DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
53 },
54 },
55 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080056 /* LifeBook B */
Andrew Mortonb1b29652006-11-02 23:27:44 -050057 .matches = {
Jon Dodgson57b5e2a2010-01-28 00:07:45 -080058 DMI_MATCH(DMI_PRODUCT_NAME, "Lifebook B Series"),
59 },
60 },
61 {
62 /* LifeBook B */
63 .matches = {
Andrew Mortonb1b29652006-11-02 23:27:44 -050064 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
65 },
66 },
67 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080068 /* Lifebook B */
Andrew Mortonb1b29652006-11-02 23:27:44 -050069 .matches = {
70 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
71 },
72 },
73 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080074 /* Lifebook B-2130 */
Dmitry Torokhov6b9ff692009-04-24 12:01:47 -070075 .matches = {
76 DMI_MATCH(DMI_BOARD_NAME, "ZEPHYR"),
77 },
78 },
79 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080080 /* Lifebook B213x/B2150 */
Andrew Mortonb1b29652006-11-02 23:27:44 -050081 .matches = {
82 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
83 },
84 },
85 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080086 /* Zephyr */
Andrew Mortonb1b29652006-11-02 23:27:44 -050087 .matches = {
88 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
89 },
90 },
91 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080092 /* Panasonic CF-18 */
Andrew Mortonb1b29652006-11-02 23:27:44 -050093 .matches = {
94 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
95 },
Dmitry Torokhov7705d542009-12-03 23:21:14 -080096 .callback = lifebook_limit_serio3,
Andrew Mortonb1b29652006-11-02 23:27:44 -050097 },
98 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -080099 /* Panasonic CF-28 */
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400100 .matches = {
101 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
102 DMI_MATCH(DMI_PRODUCT_NAME, "CF-28"),
103 },
104 .callback = lifebook_set_6byte_proto,
105 },
106 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800107 /* Panasonic CF-29 */
Dmitry Torokhov43887ba2007-04-25 00:39:31 -0400108 .matches = {
109 DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
110 DMI_MATCH(DMI_PRODUCT_NAME, "CF-29"),
111 },
112 .callback = lifebook_set_6byte_proto,
113 },
114 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800115 /* Panasonic CF-72 */
Dmitry Torokhovf76f6722007-09-05 00:22:17 -0400116 .matches = {
117 DMI_MATCH(DMI_PRODUCT_NAME, "CF-72"),
118 },
Abner Holsingerb1e69aa2009-11-16 22:12:14 -0800119 .callback = lifebook_set_6byte_proto,
Dmitry Torokhovf76f6722007-09-05 00:22:17 -0400120 },
121 {
Dmitry Torokhov9961e252009-12-04 10:24:20 -0800122 /* Lifebook B142 */
Andrew Mortonb1b29652006-11-02 23:27:44 -0500123 .matches = {
124 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
125 },
126 },
127 { }
Kenan Esau02d7f582005-05-29 02:30:22 -0500128};
129
Dmitry Torokhov7705d542009-12-03 23:21:14 -0800130void __init lifebook_module_init(void)
131{
132 lifebook_present = dmi_check_system(lifebook_dmi_table);
133}
134
David Howells7d12e782006-10-05 14:55:46 +0100135static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500136{
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400137 struct lifebook_data *priv = psmouse->private;
138 struct input_dev *dev1 = psmouse->dev;
Dmitry Torokhove6b20d82007-07-20 00:29:14 -0400139 struct input_dev *dev2 = priv ? priv->dev2 : NULL;
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700140 u8 *packet = psmouse->packet;
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700141 bool relative_packet = packet[0] & 0x08;
Kenan Esau02d7f582005-05-29 02:30:22 -0500142
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400143 if (relative_packet || !lifebook_use_6byte_proto) {
144 if (psmouse->pktcnt != 3)
145 return PSMOUSE_GOOD_DATA;
Kenan Esau02d7f582005-05-29 02:30:22 -0500146 } else {
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400147 switch (psmouse->pktcnt) {
148 case 1:
149 return (packet[0] & 0xf8) == 0x00 ?
150 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
151 case 2:
152 return PSMOUSE_GOOD_DATA;
153 case 3:
154 return ((packet[2] & 0x30) << 2) == (packet[2] & 0xc0) ?
155 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
156 case 4:
157 return (packet[3] & 0xf8) == 0xc0 ?
158 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
159 case 5:
160 return (packet[4] & 0xc0) == (packet[2] & 0xc0) ?
161 PSMOUSE_GOOD_DATA : PSMOUSE_BAD_DATA;
162 case 6:
163 if (((packet[5] & 0x30) << 2) != (packet[5] & 0xc0))
164 return PSMOUSE_BAD_DATA;
165 if ((packet[5] & 0xc0) != (packet[1] & 0xc0))
166 return PSMOUSE_BAD_DATA;
167 break; /* report data */
168 }
169 }
170
171 if (relative_packet) {
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400172 if (!dev2)
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700173 psmouse_warn(psmouse,
174 "got relative packet but no relative device set up\n");
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400175 } else {
Dmitry Torokhov9b771ac2009-05-08 18:30:32 -0700176 if (lifebook_use_6byte_proto) {
177 input_report_abs(dev1, ABS_X,
178 ((packet[1] & 0x3f) << 6) | (packet[2] & 0x3f));
179 input_report_abs(dev1, ABS_Y,
180 4096 - (((packet[4] & 0x3f) << 6) | (packet[5] & 0x3f)));
181 } else {
182 input_report_abs(dev1, ABS_X,
183 (packet[1] | ((packet[0] & 0x30) << 4)));
184 input_report_abs(dev1, ABS_Y,
185 1024 - (packet[2] | ((packet[0] & 0xC0) << 2)));
186 }
187 input_report_key(dev1, BTN_TOUCH, packet[0] & 0x04);
188 input_sync(dev1);
Kenan Esau02d7f582005-05-29 02:30:22 -0500189 }
190
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400191 if (dev2) {
Dmitry Torokhov1ef85802017-02-07 17:07:44 -0800192 if (relative_packet)
193 psmouse_report_standard_motion(dev2, packet);
194
195 psmouse_report_standard_buttons(dev2, packet[0]);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400196 input_sync(dev2);
197 }
Kenan Esau02d7f582005-05-29 02:30:22 -0500198
199 return PSMOUSE_FULL_PACKET;
200}
201
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500202static int lifebook_absolute_mode(struct psmouse *psmouse)
Kenan Esau02d7f582005-05-29 02:30:22 -0500203{
204 struct ps2dev *ps2dev = &psmouse->ps2dev;
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700205 u8 param;
206 int error;
Kenan Esau02d7f582005-05-29 02:30:22 -0500207
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700208 error = psmouse_reset(psmouse);
209 if (error)
210 return error;
Kenan Esau02d7f582005-05-29 02:30:22 -0500211
Dmitry Torokhov14e94142005-05-29 02:30:28 -0500212 /*
Dmitry Torokhov0cc17702009-11-16 22:12:21 -0800213 * Enable absolute output -- ps2_command fails always but if
Dmitry Torokhovb5d21702011-10-10 18:27:03 -0700214 * you leave this call out the touchscreen will never send
Dmitry Torokhov0cc17702009-11-16 22:12:21 -0800215 * absolute coordinates
216 */
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400217 param = lifebook_use_6byte_proto ? 0x08 : 0x07;
Kenan Esau02d7f582005-05-29 02:30:22 -0500218 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
219
Kenan Esau02d7f582005-05-29 02:30:22 -0500220 return 0;
221}
222
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400223static void lifebook_relative_mode(struct psmouse *psmouse)
224{
225 struct ps2dev *ps2dev = &psmouse->ps2dev;
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700226 u8 param = 0x06;
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400227
228 ps2_command(ps2dev, &param, PSMOUSE_CMD_SETRES);
229}
230
Dmitry Torokhova9138292005-05-29 02:30:37 -0500231static void lifebook_set_resolution(struct psmouse *psmouse, unsigned int resolution)
232{
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700233 static const u8 params[] = { 0, 1, 2, 2, 3 };
234 u8 p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500235
236 if (resolution == 0 || resolution > 400)
237 resolution = 400;
238
Helge Dellere38de672006-09-10 21:54:39 -0400239 p = params[resolution / 100];
240 ps2_command(&psmouse->ps2dev, &p, PSMOUSE_CMD_SETRES);
241 psmouse->resolution = 50 << p;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500242}
243
Kenan Esau02d7f582005-05-29 02:30:22 -0500244static void lifebook_disconnect(struct psmouse *psmouse)
245{
Andres Salomon653e91d2008-01-17 12:01:51 -0500246 struct lifebook_data *priv = psmouse->private;
247
Kenan Esau02d7f582005-05-29 02:30:22 -0500248 psmouse_reset(psmouse);
Andres Salomon653e91d2008-01-17 12:01:51 -0500249 if (priv) {
250 input_unregister_device(priv->dev2);
251 kfree(priv);
252 }
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400253 psmouse->private = NULL;
Kenan Esau02d7f582005-05-29 02:30:22 -0500254}
255
Dmitry Torokhovb7802c52009-09-09 19:13:20 -0700256int lifebook_detect(struct psmouse *psmouse, bool set_properties)
Kenan Esau02d7f582005-05-29 02:30:22 -0500257{
Brian K. Turner7e174702015-03-20 09:36:35 -0700258 if (!lifebook_present)
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700259 return -ENXIO;
Kenan Esau02d7f582005-05-29 02:30:22 -0500260
Dmitry Torokhove7afcd12007-04-12 01:36:25 -0400261 if (desired_serio_phys &&
262 strcmp(psmouse->ps2dev.serio->phys, desired_serio_phys))
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700263 return -ENXIO;
Dmitry Torokhove7afcd12007-04-12 01:36:25 -0400264
Kenan Esau02d7f582005-05-29 02:30:22 -0500265 if (set_properties) {
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500266 psmouse->vendor = "Fujitsu";
267 psmouse->name = "Lifebook TouchScreen";
Kenan Esau02d7f582005-05-29 02:30:22 -0500268 }
269
Brian K. Turner7e174702015-03-20 09:36:35 -0700270 return 0;
Kenan Esau02d7f582005-05-29 02:30:22 -0500271}
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500272
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400273static int lifebook_create_relative_device(struct psmouse *psmouse)
274{
275 struct input_dev *dev2;
276 struct lifebook_data *priv;
277 int error = -ENOMEM;
278
279 priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL);
280 dev2 = input_allocate_device();
281 if (!priv || !dev2)
282 goto err_out;
283
284 priv->dev2 = dev2;
285 snprintf(priv->phys, sizeof(priv->phys),
286 "%s/input1", psmouse->ps2dev.serio->phys);
287
288 dev2->phys = priv->phys;
Pali Rohár9096a452016-06-18 10:09:43 -0700289 dev2->name = "LBPS/2 Fujitsu Lifebook Touchpad";
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400290 dev2->id.bustype = BUS_I8042;
291 dev2->id.vendor = 0x0002;
292 dev2->id.product = PSMOUSE_LIFEBOOK;
293 dev2->id.version = 0x0000;
294 dev2->dev.parent = &psmouse->ps2dev.serio->dev;
295
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700296 input_set_capability(dev2, EV_REL, REL_X);
297 input_set_capability(dev2, EV_REL, REL_Y);
298 input_set_capability(dev2, EV_KEY, BTN_LEFT);
299 input_set_capability(dev2, EV_KEY, BTN_RIGHT);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400300
301 error = input_register_device(priv->dev2);
302 if (error)
303 goto err_out;
304
305 psmouse->private = priv;
306 return 0;
307
308 err_out:
309 input_free_device(dev2);
310 kfree(priv);
311 return error;
312}
313
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500314int lifebook_init(struct psmouse *psmouse)
315{
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400316 struct input_dev *dev1 = psmouse->dev;
Dmitry Torokhov62e729b2007-10-12 14:19:50 -0400317 int max_coord = lifebook_use_6byte_proto ? 4096 : 1024;
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700318 int error;
Dmitry Torokhov2e5b6362005-09-15 02:01:44 -0500319
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700320 error = lifebook_absolute_mode(psmouse);
321 if (error)
322 return error;
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500323
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700324 /* Clear default capabilities */
325 bitmap_zero(dev1->evbit, EV_CNT);
326 bitmap_zero(dev1->relbit, REL_CNT);
327 bitmap_zero(dev1->keybit, KEY_CNT);
328
329 input_set_capability(dev1, EV_KEY, BTN_TOUCH);
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400330 input_set_abs_params(dev1, ABS_X, 0, max_coord, 0, 0);
331 input_set_abs_params(dev1, ABS_Y, 0, max_coord, 0, 0);
332
333 if (!desired_serio_phys) {
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700334 error = lifebook_create_relative_device(psmouse);
335 if (error) {
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400336 lifebook_relative_mode(psmouse);
Dmitry Torokhovc13b4182017-03-22 15:18:28 -0700337 return error;
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400338 }
339 }
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500340
341 psmouse->protocol_handler = lifebook_process_byte;
Dmitry Torokhova9138292005-05-29 02:30:37 -0500342 psmouse->set_resolution = lifebook_set_resolution;
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500343 psmouse->disconnect = lifebook_disconnect;
344 psmouse->reconnect = lifebook_absolute_mode;
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400345
Dmitry Torokhov2ebdcc62007-04-25 00:39:53 -0400346 psmouse->model = lifebook_use_6byte_proto ? 6 : 3;
347
Dmitry Torokhov1b118792007-04-12 01:36:34 -0400348 /*
349 * Use packet size = 3 even when using 6-byte protocol because
350 * that's what POLL will return on Lifebooks (according to spec).
351 */
Dmitry Torokhova15d60f2005-05-29 02:30:32 -0500352 psmouse->pktsize = 3;
353
354 return 0;
355}
356