1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2000-2001 Vojtech Pavlik
7 * Gunze AHL-51S touchscreen driver for Linux
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>
17 #define DRIVER_DESC "Gunze AHL-51S touchscreen driver"
19 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
20 MODULE_DESCRIPTION(DRIVER_DESC
);
21 MODULE_LICENSE("GPL");
24 * Definitions & global arrays.
27 #define GUNZE_MAX_LENGTH 10
30 * Per-touchscreen data.
34 struct input_dev
*dev
;
37 unsigned char data
[GUNZE_MAX_LENGTH
];
41 static void gunze_process_packet(struct gunze
*gunze
)
43 struct input_dev
*dev
= gunze
->dev
;
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
);
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');
57 static irqreturn_t
gunze_interrupt(struct serio
*serio
,
58 unsigned char data
, unsigned int flags
)
60 struct gunze
*gunze
= serio_get_drvdata(serio
);
63 gunze_process_packet(gunze
);
66 if (gunze
->idx
< GUNZE_MAX_LENGTH
)
67 gunze
->data
[gunze
->idx
++] = data
;
73 * gunze_disconnect() is the opposite of gunze_connect()
76 static void gunze_disconnect(struct serio
*serio
)
78 struct gunze
*gunze
= serio_get_drvdata(serio
);
80 input_get_device(gunze
->dev
);
81 input_unregister_device(gunze
->dev
);
83 serio_set_drvdata(serio
, NULL
);
84 input_put_device(gunze
->dev
);
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
94 static int gunze_connect(struct serio
*serio
, struct serio_driver
*drv
)
97 struct input_dev
*input_dev
;
100 gunze
= kzalloc(sizeof(*gunze
), GFP_KERNEL
);
101 input_dev
= input_allocate_device();
102 if (!gunze
|| !input_dev
) {
107 gunze
->serio
= serio
;
108 gunze
->dev
= input_dev
;
109 snprintf(gunze
->phys
, sizeof(serio
->phys
), "%s/input0", serio
->phys
);
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);
123 serio_set_drvdata(serio
, gunze
);
125 err
= serio_open(serio
, drv
);
129 err
= input_register_device(gunze
->dev
);
135 fail3
: serio_close(serio
);
136 fail2
: serio_set_drvdata(serio
, NULL
);
137 fail1
: input_free_device(input_dev
);
143 * The serio driver structure.
146 static const struct serio_device_id gunze_serio_ids
[] = {
149 .proto
= SERIO_GUNZE
,
156 MODULE_DEVICE_TABLE(serio
, gunze_serio_ids
);
158 static struct serio_driver gunze_drv
= {
162 .description
= DRIVER_DESC
,
163 .id_table
= gunze_serio_ids
,
164 .interrupt
= gunze_interrupt
,
165 .connect
= gunze_connect
,
166 .disconnect
= gunze_disconnect
,
169 module_serio_driver(gunze_drv
);