19 #include <linux/errno.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/input.h>
24 #include <linux/serio.h>
26 #include <linux/ctype.h>
28 #define DRIVER_DESC "Elo serial touchscreen driver"
38 #define ELO_MAX_LENGTH 10
40 #define ELO10_PACKET_LEN 8
41 #define ELO10_TOUCH 0x03
42 #define ELO10_PRESSURE 0x80
44 #define ELO10_LEAD_BYTE 'U'
46 #define ELO10_ID_CMD 'i'
48 #define ELO10_TOUCH_PACKET 'T'
49 #define ELO10_ACK_PACKET 'A'
50 #define ELI10_ID_PACKET 'I'
57 struct input_dev *
dev;
70 static void elo_process_data_10(
struct elo *
elo,
unsigned char data)
72 struct input_dev *
dev = elo->
dev;
81 "unsynchronized data: 0x%02x\n", data);
88 if (data != elo->
csum) {
90 "bad checksum: 0x%02x, expected 0x%02x\n",
97 "unexpected packet: 0x%02x\n",
102 input_report_abs(dev,
ABS_X, (elo->
data[4] << 8) | elo->
data[3]);
103 input_report_abs(dev,
ABS_Y, (elo->
data[6] << 8) | elo->
data[5]);
106 (elo->
data[8] << 8) | elo->
data[7]);
110 if (elo->
data[2] ==
'0')
122 static void elo_process_data_6(
struct elo *
elo,
unsigned char data)
124 struct input_dev *
dev = elo->
dev;
128 switch (elo->
idx++) {
131 if ((data & 0xc0) != 0xc0)
136 if ((data & 0xc0) != 0x80)
141 if ((data & 0xc0) != 0x40)
151 input_report_abs(dev,
ABS_X, ((elo->
data[0] & 0x3f) << 6) | (elo->
data[1] & 0x3f));
152 input_report_abs(dev,
ABS_Y, ((elo->
data[2] & 0x3f) << 6) | (elo->
data[3] & 0x3f));
170 if ((data & 0xf0) == 0) {
180 static void elo_process_data_3(
struct elo *elo,
unsigned char data)
182 struct input_dev *dev = elo->
dev;
186 switch (elo->
idx++) {
189 if ((data & 0x7f) != 0x01)
194 input_report_abs(dev,
ABS_X, elo->
data[1]);
195 input_report_abs(dev,
ABS_Y, elo->
data[2]);
203 unsigned char data,
unsigned int flags)
205 struct elo *elo = serio_get_drvdata(serio);
209 elo_process_data_10(elo, data);
214 elo_process_data_6(elo, data);
218 elo_process_data_3(elo, data);
225 static int elo_command_10(
struct elo *elo,
unsigned char *
packet)
233 serio_pause_rx(elo->
serio);
236 serio_continue_rx(elo->
serio);
243 if (serio_write(elo->
serio, packet[i]))
247 if (serio_write(elo->
serio, csum))
263 static int elo_setup_10(
struct elo *elo)
265 static const char *elo_types[] = {
"Accu",
"Dura",
"Intelli",
"Carroll" };
266 struct input_dev *dev = elo->
dev;
269 if (elo_command_10(elo, packet))
272 dev->id.version = (packet[5] << 8) | packet[4];
274 input_set_abs_params(dev,
ABS_X, 96, 4000, 0, 0);
275 input_set_abs_params(dev,
ABS_Y, 96, 4000, 0, 0);
280 "%sTouch touchscreen, fw: %02x.%02x, features: 0x%02x, controller: 0x%02x\n",
281 elo_types[(packet[1] -
'0') & 0x03],
282 packet[5], packet[4], packet[3], packet[7]);
291 static void elo_disconnect(
struct serio *serio)
293 struct elo *elo = serio_get_drvdata(serio);
295 input_get_device(elo->
dev);
296 input_unregister_device(elo->
dev);
298 serio_set_drvdata(serio,
NULL);
299 input_put_device(elo->
dev);
309 static int elo_connect(
struct serio *serio,
struct serio_driver *drv)
312 struct input_dev *input_dev;
315 elo = kzalloc(
sizeof(
struct elo),
GFP_KERNEL);
316 input_dev = input_allocate_device();
317 if (!elo || !input_dev) {
323 elo->
id = serio->
id.id;
324 elo->
dev = input_dev;
330 input_dev->name =
"Elo Serial TouchScreen";
331 input_dev->phys = elo->
phys;
334 input_dev->id.product = elo->
id;
335 input_dev->id.version = 0x0100;
336 input_dev->dev.parent = &serio->
dev;
341 serio_set_drvdata(serio, elo);
349 if (elo_setup_10(elo))
355 input_set_abs_params(input_dev,
ABS_PRESSURE, 0, 15, 0, 0);
358 input_set_abs_params(input_dev,
ABS_X, 96, 4000, 0, 0);
359 input_set_abs_params(input_dev,
ABS_Y, 96, 4000, 0, 0);
363 input_set_abs_params(input_dev,
ABS_X, 0, 255, 0, 0);
364 input_set_abs_params(input_dev,
ABS_Y, 0, 255, 0, 0);
368 err = input_register_device(elo->
dev);
375 fail2: serio_set_drvdata(serio,
NULL);
376 fail1: input_free_device(input_dev);
402 .id_table = elo_serio_ids,
403 .interrupt = elo_interrupt,
404 .connect = elo_connect,
405 .disconnect = elo_disconnect,