blob: e2ee626152730795519f57e51e0ac99810112f21 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 2000-2001 Vojtech Pavlik
3 */
4
5/*
6 * Gunze AHL-51S touchscreen driver for Linux
7 */
8
9/*
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.
14 *
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.
19 *
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
23 *
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
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
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 * Definitions & global arrays.
44 */
45
46#define GUNZE_MAX_LENGTH 10
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/*
49 * Per-touchscreen data.
50 */
51
52struct gunze {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050053 struct input_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 struct serio *serio;
55 int idx;
56 unsigned char data[GUNZE_MAX_LENGTH];
57 char phys[32];
58};
59
David Howells7d12e782006-10-05 14:55:46 +010060static void gunze_process_packet(struct gunze* gunze)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050062 struct input_dev *dev = gunze->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
65 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
Dmitry Torokhova07461e2005-05-28 02:12:00 -050066 printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 return;
68 }
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 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,
David Howells7d12e782006-10-05 14:55:46 +010077 unsigned char data, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 struct gunze* gunze = serio_get_drvdata(serio);
80
81 if (data == '\r') {
David Howells7d12e782006-10-05 14:55:46 +010082 gunze_process_packet(gunze);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 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 * gunze_disconnect() is the opposite of gunze_connect()
93 */
94
95static void gunze_disconnect(struct serio *serio)
96{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050097 struct gunze *gunze = serio_get_drvdata(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050099 input_get_device(gunze->dev);
100 input_unregister_device(gunze->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 serio_close(serio);
102 serio_set_drvdata(serio, NULL);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500103 input_put_device(gunze->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 kfree(gunze);
105}
106
107/*
108 * gunze_connect() is the routine that is called when someone adds a
109 * new serio device that supports Gunze protocol and registers it as
110 * an input device.
111 */
112
113static int gunze_connect(struct serio *serio, struct serio_driver *drv)
114{
115 struct gunze *gunze;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500116 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 int err;
118
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500119 gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);
120 input_dev = input_allocate_device();
121 if (!gunze || !input_dev) {
122 err = -ENOMEM;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500123 goto fail1;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 gunze->serio = serio;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500127 gunze->dev = input_dev;
Dmitry Torokhova21466c2006-06-26 01:46:04 -0400128 snprintf(gunze->phys, sizeof(serio->phys), "%s/input0", serio->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500130 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;
Dmitry Torokhova5394fb02007-04-12 01:35:14 -0400136 input_dev->dev.parent = &serio->dev;
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700137 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
138 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500139 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 serio_set_drvdata(serio, gunze);
143
144 err = serio_open(serio, drv);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500145 if (err)
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500146 goto fail2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500148 err = input_register_device(gunze->dev);
149 if (err)
150 goto fail3;
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 return 0;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500153
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500154 fail3: serio_close(serio);
155 fail2: serio_set_drvdata(serio, NULL);
156 fail1: input_free_device(input_dev);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500157 kfree(gunze);
158 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161/*
162 * The serio driver structure.
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
Axel Lin65ac9f72012-04-03 23:50:17 -0700188module_serio_driver(gunze_drv);