1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <linux/errno.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/slab.h>
33#include <linux/input.h>
34#include <linux/serio.h>
35
36#define DRIVER_DESC "Gunze AHL-51S touchscreen driver"
37
38MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
39MODULE_DESCRIPTION(DRIVER_DESC);
40MODULE_LICENSE("GPL");
41
42
43
44
45
46#define GUNZE_MAX_LENGTH 10
47
48
49
50
51
52struct gunze {
53 struct input_dev *dev;
54 struct serio *serio;
55 int idx;
56 unsigned char data[GUNZE_MAX_LENGTH];
57 char phys[32];
58};
59
60static void gunze_process_packet(struct gunze* gunze)
61{
62 struct input_dev *dev = gunze->dev;
63
64 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
65 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
66 printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);
67 return;
68 }
69
70 input_report_abs(dev, ABS_X, simple_strtoul(gunze->data + 1, NULL, 10));
71 input_report_abs(dev, ABS_Y, 1024 - simple_strtoul(gunze->data + 6, NULL, 10));
72 input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T');
73 input_sync(dev);
74}
75
76static irqreturn_t gunze_interrupt(struct serio *serio,
77 unsigned char data, unsigned int flags)
78{
79 struct gunze* gunze = serio_get_drvdata(serio);
80
81 if (data == '\r') {
82 gunze_process_packet(gunze);
83 gunze->idx = 0;
84 } else {
85 if (gunze->idx < GUNZE_MAX_LENGTH)
86 gunze->data[gunze->idx++] = data;
87 }
88 return IRQ_HANDLED;
89}
90
91
92
93
94
95static void gunze_disconnect(struct serio *serio)
96{
97 struct gunze *gunze = serio_get_drvdata(serio);
98
99 input_get_device(gunze->dev);
100 input_unregister_device(gunze->dev);
101 serio_close(serio);
102 serio_set_drvdata(serio, NULL);
103 input_put_device(gunze->dev);
104 kfree(gunze);
105}
106
107
108
109
110
111
112
113static int gunze_connect(struct serio *serio, struct serio_driver *drv)
114{
115 struct gunze *gunze;
116 struct input_dev *input_dev;
117 int err;
118
119 gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);
120 input_dev = input_allocate_device();
121 if (!gunze || !input_dev) {
122 err = -ENOMEM;
123 goto fail1;
124 }
125
126 gunze->serio = serio;
127 gunze->dev = input_dev;
128 snprintf(gunze->phys, sizeof(serio->phys), "%s/input0", serio->phys);
129
130 input_dev->name = "Gunze AHL-51S TouchScreen";
131 input_dev->phys = gunze->phys;
132 input_dev->id.bustype = BUS_RS232;
133 input_dev->id.vendor = SERIO_GUNZE;
134 input_dev->id.product = 0x0051;
135 input_dev->id.version = 0x0100;
136 input_dev->dev.parent = &serio->dev;
137 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
138 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
139 input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0);
140 input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0);
141
142 serio_set_drvdata(serio, gunze);
143
144 err = serio_open(serio, drv);
145 if (err)
146 goto fail2;
147
148 err = input_register_device(gunze->dev);
149 if (err)
150 goto fail3;
151
152 return 0;
153
154 fail3: serio_close(serio);
155 fail2: serio_set_drvdata(serio, NULL);
156 fail1: input_free_device(input_dev);
157 kfree(gunze);
158 return err;
159}
160
161
162
163
164
165static struct serio_device_id gunze_serio_ids[] = {
166 {
167 .type = SERIO_RS232,
168 .proto = SERIO_GUNZE,
169 .id = SERIO_ANY,
170 .extra = SERIO_ANY,
171 },
172 { 0 }
173};
174
175MODULE_DEVICE_TABLE(serio, gunze_serio_ids);
176
177static struct serio_driver gunze_drv = {
178 .driver = {
179 .name = "gunze",
180 },
181 .description = DRIVER_DESC,
182 .id_table = gunze_serio_ids,
183 .interrupt = gunze_interrupt,
184 .connect = gunze_connect,
185 .disconnect = gunze_disconnect,
186};
187
188module_serio_driver(gunze_drv);
189