2 * Copyright (c) 2000-2001 Vojtech Pavlik
6 * Gunze AHL-51S touchscreen driver for Linux
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
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 #include <linux/init.h>
37 #define DRIVER_DESC "Gunze AHL-51S touchscreen driver"
39 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
40 MODULE_DESCRIPTION(DRIVER_DESC
);
41 MODULE_LICENSE("GPL");
44 * Definitions & global arrays.
47 #define GUNZE_MAX_LENGTH 10
50 * Per-touchscreen data.
54 struct input_dev
*dev
;
57 unsigned char data
[GUNZE_MAX_LENGTH
];
61 static void gunze_process_packet(struct gunze
* gunze
)
63 struct input_dev
*dev
= gunze
->dev
;
65 if (gunze
->idx
!= GUNZE_MAX_LENGTH
|| gunze
->data
[5] != ',' ||
66 (gunze
->data
[0] != 'T' && gunze
->data
[0] != 'R')) {
67 printk(KERN_WARNING
"gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH
, gunze
->data
);
71 input_report_abs(dev
, ABS_X
, simple_strtoul(gunze
->data
+ 1, NULL
, 10));
72 input_report_abs(dev
, ABS_Y
, 1024 - simple_strtoul(gunze
->data
+ 6, NULL
, 10));
73 input_report_key(dev
, BTN_TOUCH
, gunze
->data
[0] == 'T');
77 static irqreturn_t
gunze_interrupt(struct serio
*serio
,
78 unsigned char data
, unsigned int flags
)
80 struct gunze
* gunze
= serio_get_drvdata(serio
);
83 gunze_process_packet(gunze
);
86 if (gunze
->idx
< GUNZE_MAX_LENGTH
)
87 gunze
->data
[gunze
->idx
++] = data
;
93 * gunze_disconnect() is the opposite of gunze_connect()
96 static void gunze_disconnect(struct serio
*serio
)
98 struct gunze
*gunze
= serio_get_drvdata(serio
);
100 input_get_device(gunze
->dev
);
101 input_unregister_device(gunze
->dev
);
103 serio_set_drvdata(serio
, NULL
);
104 input_put_device(gunze
->dev
);
109 * gunze_connect() is the routine that is called when someone adds a
110 * new serio device that supports Gunze protocol and registers it as
114 static int gunze_connect(struct serio
*serio
, struct serio_driver
*drv
)
117 struct input_dev
*input_dev
;
120 gunze
= kzalloc(sizeof(struct gunze
), GFP_KERNEL
);
121 input_dev
= input_allocate_device();
122 if (!gunze
|| !input_dev
) {
127 gunze
->serio
= serio
;
128 gunze
->dev
= input_dev
;
129 snprintf(gunze
->phys
, sizeof(serio
->phys
), "%s/input0", serio
->phys
);
131 input_dev
->name
= "Gunze AHL-51S TouchScreen";
132 input_dev
->phys
= gunze
->phys
;
133 input_dev
->id
.bustype
= BUS_RS232
;
134 input_dev
->id
.vendor
= SERIO_GUNZE
;
135 input_dev
->id
.product
= 0x0051;
136 input_dev
->id
.version
= 0x0100;
137 input_dev
->dev
.parent
= &serio
->dev
;
138 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
139 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
140 input_set_abs_params(input_dev
, ABS_X
, 24, 1000, 0, 0);
141 input_set_abs_params(input_dev
, ABS_Y
, 24, 1000, 0, 0);
143 serio_set_drvdata(serio
, gunze
);
145 err
= serio_open(serio
, drv
);
149 err
= input_register_device(gunze
->dev
);
155 fail3
: serio_close(serio
);
156 fail2
: serio_set_drvdata(serio
, NULL
);
157 fail1
: input_free_device(input_dev
);
163 * The serio driver structure.
166 static struct serio_device_id gunze_serio_ids
[] = {
169 .proto
= SERIO_GUNZE
,
176 MODULE_DEVICE_TABLE(serio
, gunze_serio_ids
);
178 static struct serio_driver gunze_drv
= {
182 .description
= DRIVER_DESC
,
183 .id_table
= gunze_serio_ids
,
184 .interrupt
= gunze_interrupt
,
185 .connect
= gunze_connect
,
186 .disconnect
= gunze_disconnect
,
190 * The functions for inserting/removing us as a module.
193 static int __init
gunze_init(void)
195 return serio_register_driver(&gunze_drv
);
198 static void __exit
gunze_exit(void)
200 serio_unregister_driver(&gunze_drv
);
203 module_init(gunze_init
);
204 module_exit(gunze_exit
);