Linux Audio

Check our new training course

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