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