2 * Elo serial touchscreen driver
4 * Copyright (c) 2004 Vojtech Pavlik
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
14 * This driver can handle serial Elo touchscreens using either the Elo standard
15 * 'E271-2210' 10-byte protocol, Elo legacy 'E281A-4002' 6-byte protocol, Elo
16 * legacy 'E271-140' 4-byte protocol and Elo legacy 'E261-280' 3-byte protocol.
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>
25 #include <linux/init.h>
27 #define DRIVER_DESC "Elo serial touchscreen driver"
29 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
30 MODULE_DESCRIPTION(DRIVER_DESC
);
31 MODULE_LICENSE("GPL");
34 * Definitions & global arrays.
37 #define ELO_MAX_LENGTH 10
39 static char *elo_name
= "Elo Serial TouchScreen";
42 * Per-touchscreen data.
51 unsigned char data
[ELO_MAX_LENGTH
];
55 static void elo_process_data_10(struct elo
* elo
, unsigned char data
, struct pt_regs
*regs
)
57 struct input_dev
*dev
= &elo
->dev
;
59 elo
->csum
+= elo
->data
[elo
->idx
] = data
;
79 input_regs(dev
, regs
);
80 input_report_abs(dev
, ABS_X
, (elo
->data
[4] << 8) | elo
->data
[3]);
81 input_report_abs(dev
, ABS_Y
, (elo
->data
[6] << 8) | elo
->data
[5]);
82 input_report_abs(dev
, ABS_PRESSURE
, (elo
->data
[8] << 8) | elo
->data
[7]);
83 input_report_key(dev
, BTN_TOUCH
, elo
->data
[2] & 3);
92 static void elo_process_data_6(struct elo
* elo
, unsigned char data
, struct pt_regs
*regs
)
94 struct input_dev
*dev
= &elo
->dev
;
96 elo
->data
[elo
->idx
] = data
;
100 case 0: if ((data
& 0xc0) != 0xc0) elo
->idx
= 0; break;
101 case 1: if ((data
& 0xc0) != 0x80) elo
->idx
= 0; break;
102 case 2: if ((data
& 0xc0) != 0x40) elo
->idx
= 0; break;
110 input_regs(dev
, regs
);
111 input_report_abs(dev
, ABS_X
, ((elo
->data
[0] & 0x3f) << 6) | (elo
->data
[1] & 0x3f));
112 input_report_abs(dev
, ABS_Y
, ((elo
->data
[2] & 0x3f) << 6) | (elo
->data
[3] & 0x3f));
115 input_report_key(dev
, BTN_TOUCH
, 1);
130 if ((data
& 0xf0) == 0) {
131 input_report_abs(dev
, ABS_PRESSURE
, elo
->data
[5]);
132 input_report_key(dev
, BTN_TOUCH
, elo
->data
[5]);
140 static void elo_process_data_3(struct elo
* elo
, unsigned char data
, struct pt_regs
*regs
)
142 struct input_dev
*dev
= &elo
->dev
;
144 elo
->data
[elo
->idx
] = data
;
146 switch (elo
->idx
++) {
149 if ((data
& 0x7f) != 0x01)
153 input_regs(dev
, regs
);
154 input_report_key(dev
, BTN_TOUCH
, !(elo
->data
[1] & 0x80));
155 input_report_abs(dev
, ABS_X
, elo
->data
[1]);
156 input_report_abs(dev
, ABS_Y
, elo
->data
[2]);
163 static irqreturn_t
elo_interrupt(struct serio
*serio
,
164 unsigned char data
, unsigned int flags
, struct pt_regs
*regs
)
166 struct elo
* elo
= serio_get_drvdata(serio
);
170 elo_process_data_10(elo
, data
, regs
);
175 elo_process_data_6(elo
, data
, regs
);
179 elo_process_data_3(elo
, data
, regs
);
187 * elo_disconnect() is the opposite of elo_connect()
190 static void elo_disconnect(struct serio
*serio
)
192 struct elo
* elo
= serio_get_drvdata(serio
);
194 input_unregister_device(&elo
->dev
);
196 serio_set_drvdata(serio
, NULL
);
201 * elo_connect() is the routine that is called when someone adds a
202 * new serio device that supports Gunze protocol and registers it as
206 static int elo_connect(struct serio
*serio
, struct serio_driver
*drv
)
211 if (!(elo
= kmalloc(sizeof(struct elo
), GFP_KERNEL
)))
214 memset(elo
, 0, sizeof(struct elo
));
216 init_input_dev(&elo
->dev
);
217 elo
->dev
.evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
218 elo
->dev
.keybit
[LONG(BTN_TOUCH
)] = BIT(BTN_TOUCH
);
220 elo
->id
= serio
->id
.id
;
224 case 0: /* 10-byte protocol */
225 input_set_abs_params(&elo
->dev
, ABS_X
, 96, 4000, 0, 0);
226 input_set_abs_params(&elo
->dev
, ABS_Y
, 96, 4000, 0, 0);
227 input_set_abs_params(&elo
->dev
, ABS_PRESSURE
, 0, 255, 0, 0);
230 case 1: /* 6-byte protocol */
231 input_set_abs_params(&elo
->dev
, ABS_PRESSURE
, 0, 15, 0, 0);
233 case 2: /* 4-byte protocol */
234 input_set_abs_params(&elo
->dev
, ABS_X
, 96, 4000, 0, 0);
235 input_set_abs_params(&elo
->dev
, ABS_Y
, 96, 4000, 0, 0);
238 case 3: /* 3-byte protocol */
239 input_set_abs_params(&elo
->dev
, ABS_X
, 0, 255, 0, 0);
240 input_set_abs_params(&elo
->dev
, ABS_Y
, 0, 255, 0, 0);
246 sprintf(elo
->phys
, "%s/input0", serio
->phys
);
248 elo
->dev
.private = elo
;
249 elo
->dev
.name
= elo_name
;
250 elo
->dev
.phys
= elo
->phys
;
251 elo
->dev
.id
.bustype
= BUS_RS232
;
252 elo
->dev
.id
.vendor
= SERIO_ELO
;
253 elo
->dev
.id
.product
= elo
->id
;
254 elo
->dev
.id
.version
= 0x0100;
256 serio_set_drvdata(serio
, elo
);
258 err
= serio_open(serio
, drv
);
260 serio_set_drvdata(serio
, NULL
);
265 input_register_device(&elo
->dev
);
267 printk(KERN_INFO
"input: %s on %s\n", elo_name
, serio
->phys
);
273 * The serio driver structure.
276 static struct serio_device_id elo_serio_ids
[] = {
286 MODULE_DEVICE_TABLE(serio
, elo_serio_ids
);
288 static struct serio_driver elo_drv
= {
292 .description
= DRIVER_DESC
,
293 .id_table
= elo_serio_ids
,
294 .interrupt
= elo_interrupt
,
295 .connect
= elo_connect
,
296 .disconnect
= elo_disconnect
,
300 * The functions for inserting/removing us as a module.
303 static int __init
elo_init(void)
305 serio_register_driver(&elo_drv
);
309 static void __exit
elo_exit(void)
311 serio_unregister_driver(&elo_drv
);
314 module_init(elo_init
);
315 module_exit(elo_exit
);