blob: 56cf1a1ea3ea8279540a83b7d4a76f46f0750fcb [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
25#include <linux/errno.h>
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/slab.h>
29#include <linux/input.h>
30#include <linux/serio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#define DRIVER_DESC "Gunze AHL-51S touchscreen driver"
33
34MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
35MODULE_DESCRIPTION(DRIVER_DESC);
36MODULE_LICENSE("GPL");
37
38/*
39 * Definitions & global arrays.
40 */
41
42#define GUNZE_MAX_LENGTH 10
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/*
45 * Per-touchscreen data.
46 */
47
48struct gunze {
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050049 struct input_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 struct serio *serio;
51 int idx;
52 unsigned char data[GUNZE_MAX_LENGTH];
53 char phys[32];
54};
55
Hardik Singh Rathore249d1bb22018-12-21 01:06:42 -080056static void gunze_process_packet(struct gunze *gunze)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050058 struct input_dev *dev = gunze->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 if (gunze->idx != GUNZE_MAX_LENGTH || gunze->data[5] != ',' ||
61 (gunze->data[0] != 'T' && gunze->data[0] != 'R')) {
Dmitry Torokhova07461e2005-05-28 02:12:00 -050062 printk(KERN_WARNING "gunze.c: bad packet: >%.*s<\n", GUNZE_MAX_LENGTH, gunze->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return;
64 }
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 input_report_abs(dev, ABS_X, simple_strtoul(gunze->data + 1, NULL, 10));
67 input_report_abs(dev, ABS_Y, 1024 - simple_strtoul(gunze->data + 6, NULL, 10));
68 input_report_key(dev, BTN_TOUCH, gunze->data[0] == 'T');
69 input_sync(dev);
70}
71
72static irqreturn_t gunze_interrupt(struct serio *serio,
David Howells7d12e782006-10-05 14:55:46 +010073 unsigned char data, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Hardik Singh Rathore249d1bb22018-12-21 01:06:42 -080075 struct gunze *gunze = serio_get_drvdata(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 if (data == '\r') {
David Howells7d12e782006-10-05 14:55:46 +010078 gunze_process_packet(gunze);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 gunze->idx = 0;
80 } else {
81 if (gunze->idx < GUNZE_MAX_LENGTH)
82 gunze->data[gunze->idx++] = data;
83 }
84 return IRQ_HANDLED;
85}
86
87/*
88 * gunze_disconnect() is the opposite of gunze_connect()
89 */
90
91static void gunze_disconnect(struct serio *serio)
92{
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050093 struct gunze *gunze = serio_get_drvdata(serio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050095 input_get_device(gunze->dev);
96 input_unregister_device(gunze->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 serio_close(serio);
98 serio_set_drvdata(serio, NULL);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -050099 input_put_device(gunze->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 kfree(gunze);
101}
102
103/*
104 * gunze_connect() is the routine that is called when someone adds a
105 * new serio device that supports Gunze protocol and registers it as
106 * an input device.
107 */
108
109static int gunze_connect(struct serio *serio, struct serio_driver *drv)
110{
111 struct gunze *gunze;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500112 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 int err;
114
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500115 gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);
116 input_dev = input_allocate_device();
117 if (!gunze || !input_dev) {
118 err = -ENOMEM;
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500119 goto fail1;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 gunze->serio = serio;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500123 gunze->dev = input_dev;
Dmitry Torokhova21466c2006-06-26 01:46:04 -0400124 snprintf(gunze->phys, sizeof(serio->phys), "%s/input0", serio->phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500126 input_dev->name = "Gunze AHL-51S TouchScreen";
127 input_dev->phys = gunze->phys;
128 input_dev->id.bustype = BUS_RS232;
129 input_dev->id.vendor = SERIO_GUNZE;
130 input_dev->id.product = 0x0051;
131 input_dev->id.version = 0x0100;
Dmitry Torokhova5394fb02007-04-12 01:35:14 -0400132 input_dev->dev.parent = &serio->dev;
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700133 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
134 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500135 input_set_abs_params(input_dev, ABS_X, 24, 1000, 0, 0);
136 input_set_abs_params(input_dev, ABS_Y, 24, 1000, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 serio_set_drvdata(serio, gunze);
139
140 err = serio_open(serio, drv);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500141 if (err)
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500142 goto fail2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500144 err = input_register_device(gunze->dev);
145 if (err)
146 goto fail3;
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return 0;
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500149
Dmitry Torokhov52c1f572006-11-05 22:40:03 -0500150 fail3: serio_close(serio);
151 fail2: serio_set_drvdata(serio, NULL);
152 fail1: input_free_device(input_dev);
Dmitry Torokhoveca1ed12005-09-15 02:01:46 -0500153 kfree(gunze);
154 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
157/*
158 * The serio driver structure.
159 */
160
Arvind Yadav73300902017-08-18 17:11:12 -0700161static const struct serio_device_id gunze_serio_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 {
163 .type = SERIO_RS232,
164 .proto = SERIO_GUNZE,
165 .id = SERIO_ANY,
166 .extra = SERIO_ANY,
167 },
168 { 0 }
169};
170
171MODULE_DEVICE_TABLE(serio, gunze_serio_ids);
172
173static struct serio_driver gunze_drv = {
174 .driver = {
175 .name = "gunze",
176 },
177 .description = DRIVER_DESC,
178 .id_table = gunze_serio_ids,
179 .interrupt = gunze_interrupt,
180 .connect = gunze_connect,
181 .disconnect = gunze_disconnect,
182};
183
Axel Lin65ac9f7a2012-04-03 23:50:17 -0700184module_serio_driver(gunze_drv);