Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 * Elo serial touchscreen driver
  3 *
  4 * Copyright (c) 2004 Vojtech Pavlik
  5 */
  6
  7/*
  8 * This program is free software; you can redistribute it and/or modify it
  9 * under the terms of the GNU General Public License version 2 as published by
 10 * the Free Software Foundation.
 11 */
 12
 13/*
 14 * This driver can handle serial Elo touchscreens using either the Elo standard
 15 * 'E271-2210' 10-byte protocol, Elo legacy 'E281A-4002' 6-byte protocol, Elo
 16 * legacy 'E271-140' 4-byte protocol and Elo legacy 'E261-280' 3-byte protocol.
 17 */
 18
 19#include <linux/errno.h>
 20#include <linux/kernel.h>
 21#include <linux/module.h>
 22#include <linux/slab.h>
 23#include <linux/input.h>
 24#include <linux/serio.h>
 25#include <linux/init.h>
 26#include <linux/ctype.h>
 27
 28#define DRIVER_DESC	"Elo serial touchscreen driver"
 29
 30MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 31MODULE_DESCRIPTION(DRIVER_DESC);
 32MODULE_LICENSE("GPL");
 33
 34/*
 35 * Definitions & global arrays.
 36 */
 37
 38#define ELO_MAX_LENGTH		10
 39
 40#define ELO10_PACKET_LEN	8
 41#define ELO10_TOUCH		0x03
 42#define ELO10_PRESSURE		0x80
 43
 44#define ELO10_LEAD_BYTE		'U'
 45
 46#define ELO10_ID_CMD		'i'
 47
 48#define ELO10_TOUCH_PACKET	'T'
 49#define ELO10_ACK_PACKET	'A'
 50#define ELI10_ID_PACKET		'I'
 51
 52/*
 53 * Per-touchscreen data.
 54 */
 55
 56struct elo {
 57	struct input_dev *dev;
 58	struct serio *serio;
 59	struct mutex cmd_mutex;
 60	struct completion cmd_done;
 61	int id;
 62	int idx;
 63	unsigned char expected_packet;
 64	unsigned char csum;
 65	unsigned char data[ELO_MAX_LENGTH];
 66	unsigned char response[ELO10_PACKET_LEN];
 67	char phys[32];
 68};
 69
 70static void elo_process_data_10(struct elo *elo, unsigned char data)
 71{
 72	struct input_dev *dev = elo->dev;
 73
 74	elo->data[elo->idx] = data;
 75
 76	switch (elo->idx++) {
 77	case 0:
 78		elo->csum = 0xaa;
 79		if (data != ELO10_LEAD_BYTE) {
 80			dev_dbg(&elo->serio->dev,
 81				"unsynchronized data: 0x%02x\n", data);
 82			elo->idx = 0;
 83		}
 84		break;
 85
 86	case 9:
 87		elo->idx = 0;
 88		if (data != elo->csum) {
 89			dev_dbg(&elo->serio->dev,
 90				"bad checksum: 0x%02x, expected 0x%02x\n",
 91				 data, elo->csum);
 92			break;
 93		}
 94		if (elo->data[1] != elo->expected_packet) {
 95			if (elo->data[1] != ELO10_TOUCH_PACKET)
 96				dev_dbg(&elo->serio->dev,
 97					"unexpected packet: 0x%02x\n",
 98					 elo->data[1]);
 99			break;
100		}
101		if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) {
102			input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
103			input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
104			if (elo->data[2] & ELO10_PRESSURE)
105				input_report_abs(dev, ABS_PRESSURE,
106						(elo->data[8] << 8) | elo->data[7]);
107			input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH);
108			input_sync(dev);
109		} else if (elo->data[1] == ELO10_ACK_PACKET) {
110			if (elo->data[2] == '0')
111				elo->expected_packet = ELO10_TOUCH_PACKET;
112			complete(&elo->cmd_done);
113		} else {
114			memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN);
115			elo->expected_packet = ELO10_ACK_PACKET;
116		}
117		break;
118	}
119	elo->csum += data;
120}
121
122static void elo_process_data_6(struct elo *elo, unsigned char data)
123{
124	struct input_dev *dev = elo->dev;
125
126	elo->data[elo->idx] = data;
127
128	switch (elo->idx++) {
129
130	case 0:
131		if ((data & 0xc0) != 0xc0)
132			elo->idx = 0;
133		break;
134
135	case 1:
136		if ((data & 0xc0) != 0x80)
137			elo->idx = 0;
138		break;
139
140	case 2:
141		if ((data & 0xc0) != 0x40)
142			elo->idx = 0;
143		break;
144
145	case 3:
146		if (data & 0xc0) {
147			elo->idx = 0;
148			break;
149		}
150
151		input_report_abs(dev, ABS_X, ((elo->data[0] & 0x3f) << 6) | (elo->data[1] & 0x3f));
152		input_report_abs(dev, ABS_Y, ((elo->data[2] & 0x3f) << 6) | (elo->data[3] & 0x3f));
153
154		if (elo->id == 2) {
155			input_report_key(dev, BTN_TOUCH, 1);
156			input_sync(dev);
157			elo->idx = 0;
158		}
159
160		break;
161
162	case 4:
163		if (data) {
164			input_sync(dev);
165			elo->idx = 0;
166		}
167		break;
168
169	case 5:
170		if ((data & 0xf0) == 0) {
171			input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
172			input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
173		}
174		input_sync(dev);
175		elo->idx = 0;
176		break;
177	}
178}
179
180static void elo_process_data_3(struct elo *elo, unsigned char data)
181{
182	struct input_dev *dev = elo->dev;
183
184	elo->data[elo->idx] = data;
185
186	switch (elo->idx++) {
187
188	case 0:
189		if ((data & 0x7f) != 0x01)
190			elo->idx = 0;
191		break;
192	case 2:
193		input_report_key(dev, BTN_TOUCH, !(elo->data[1] & 0x80));
194		input_report_abs(dev, ABS_X, elo->data[1]);
195		input_report_abs(dev, ABS_Y, elo->data[2]);
196		input_sync(dev);
197		elo->idx = 0;
198		break;
199	}
200}
201
202static irqreturn_t elo_interrupt(struct serio *serio,
203		unsigned char data, unsigned int flags)
204{
205	struct elo *elo = serio_get_drvdata(serio);
206
207	switch (elo->id) {
208	case 0:
209		elo_process_data_10(elo, data);
210		break;
211
212	case 1:
213	case 2:
214		elo_process_data_6(elo, data);
215		break;
216
217	case 3:
218		elo_process_data_3(elo, data);
219		break;
220	}
221
222	return IRQ_HANDLED;
223}
224
225static int elo_command_10(struct elo *elo, unsigned char *packet)
226{
227	int rc = -1;
228	int i;
229	unsigned char csum = 0xaa + ELO10_LEAD_BYTE;
230
231	mutex_lock(&elo->cmd_mutex);
232
233	serio_pause_rx(elo->serio);
234	elo->expected_packet = toupper(packet[0]);
235	init_completion(&elo->cmd_done);
236	serio_continue_rx(elo->serio);
237
238	if (serio_write(elo->serio, ELO10_LEAD_BYTE))
239		goto out;
240
241	for (i = 0; i < ELO10_PACKET_LEN; i++) {
242		csum += packet[i];
243		if (serio_write(elo->serio, packet[i]))
244			goto out;
245	}
246
247	if (serio_write(elo->serio, csum))
248		goto out;
249
250	wait_for_completion_timeout(&elo->cmd_done, HZ);
251
252	if (elo->expected_packet == ELO10_TOUCH_PACKET) {
253		/* We are back in reporting mode, the command was ACKed */
254		memcpy(packet, elo->response, ELO10_PACKET_LEN);
255		rc = 0;
256	}
257
258 out:
259	mutex_unlock(&elo->cmd_mutex);
260	return rc;
261}
262
263static int elo_setup_10(struct elo *elo)
264{
265	static const char *elo_types[] = { "Accu", "Dura", "Intelli", "Carroll" };
266	struct input_dev *dev = elo->dev;
267	unsigned char packet[ELO10_PACKET_LEN] = { ELO10_ID_CMD };
268
269	if (elo_command_10(elo, packet))
270		return -1;
271
272	dev->id.version = (packet[5] << 8) | packet[4];
273
274	input_set_abs_params(dev, ABS_X, 96, 4000, 0, 0);
275	input_set_abs_params(dev, ABS_Y, 96, 4000, 0, 0);
276	if (packet[3] & ELO10_PRESSURE)
277		input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
278
279	dev_info(&elo->serio->dev,
280		 "%sTouch touchscreen, fw: %02x.%02x, features: 0x%02x, controller: 0x%02x\n",
281		 elo_types[(packet[1] -'0') & 0x03],
282		 packet[5], packet[4], packet[3], packet[7]);
283
284	return 0;
285}
286
287/*
288 * elo_disconnect() is the opposite of elo_connect()
289 */
290
291static void elo_disconnect(struct serio *serio)
292{
293	struct elo *elo = serio_get_drvdata(serio);
294
295	input_get_device(elo->dev);
296	input_unregister_device(elo->dev);
297	serio_close(serio);
298	serio_set_drvdata(serio, NULL);
299	input_put_device(elo->dev);
300	kfree(elo);
301}
302
303/*
304 * elo_connect() is the routine that is called when someone adds a
305 * new serio device that supports Gunze protocol and registers it as
306 * an input device.
307 */
308
309static int elo_connect(struct serio *serio, struct serio_driver *drv)
310{
311	struct elo *elo;
312	struct input_dev *input_dev;
313	int err;
314
315	elo = kzalloc(sizeof(struct elo), GFP_KERNEL);
316	input_dev = input_allocate_device();
317	if (!elo || !input_dev) {
318		err = -ENOMEM;
319		goto fail1;
320	}
321
322	elo->serio = serio;
323	elo->id = serio->id.id;
324	elo->dev = input_dev;
325	elo->expected_packet = ELO10_TOUCH_PACKET;
326	mutex_init(&elo->cmd_mutex);
327	init_completion(&elo->cmd_done);
328	snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys);
329
330	input_dev->name = "Elo Serial TouchScreen";
331	input_dev->phys = elo->phys;
332	input_dev->id.bustype = BUS_RS232;
333	input_dev->id.vendor = SERIO_ELO;
334	input_dev->id.product = elo->id;
335	input_dev->id.version = 0x0100;
336	input_dev->dev.parent = &serio->dev;
337
338	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
339	input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
340
341	serio_set_drvdata(serio, elo);
342	err = serio_open(serio, drv);
343	if (err)
344		goto fail2;
345
346	switch (elo->id) {
347
348	case 0: /* 10-byte protocol */
349		if (elo_setup_10(elo))
 
350			goto fail3;
 
351
352		break;
353
354	case 1: /* 6-byte protocol */
355		input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0);
 
356
357	case 2: /* 4-byte protocol */
358		input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
359		input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
360		break;
361
362	case 3: /* 3-byte protocol */
363		input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
364		input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
365		break;
366	}
367
368	err = input_register_device(elo->dev);
369	if (err)
370		goto fail3;
371
372	return 0;
373
374 fail3: serio_close(serio);
375 fail2:	serio_set_drvdata(serio, NULL);
376 fail1:	input_free_device(input_dev);
377	kfree(elo);
378	return err;
379}
380
381/*
382 * The serio driver structure.
383 */
384
385static struct serio_device_id elo_serio_ids[] = {
386	{
387		.type	= SERIO_RS232,
388		.proto	= SERIO_ELO,
389		.id	= SERIO_ANY,
390		.extra	= SERIO_ANY,
391	},
392	{ 0 }
393};
394
395MODULE_DEVICE_TABLE(serio, elo_serio_ids);
396
397static struct serio_driver elo_drv = {
398	.driver		= {
399		.name	= "elo",
400	},
401	.description	= DRIVER_DESC,
402	.id_table	= elo_serio_ids,
403	.interrupt	= elo_interrupt,
404	.connect	= elo_connect,
405	.disconnect	= elo_disconnect,
406};
407
408/*
409 * The functions for inserting/removing us as a module.
410 */
411
412static int __init elo_init(void)
413{
414	return serio_register_driver(&elo_drv);
415}
416
417static void __exit elo_exit(void)
418{
419	serio_unregister_driver(&elo_drv);
420}
421
422module_init(elo_init);
423module_exit(elo_exit);
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Elo serial touchscreen driver
  4 *
  5 * Copyright (c) 2004 Vojtech Pavlik
  6 */
  7
 
 
 
 
 
  8
  9/*
 10 * This driver can handle serial Elo touchscreens using either the Elo standard
 11 * 'E271-2210' 10-byte protocol, Elo legacy 'E281A-4002' 6-byte protocol, Elo
 12 * legacy 'E271-140' 4-byte protocol and Elo legacy 'E261-280' 3-byte protocol.
 13 */
 14
 15#include <linux/errno.h>
 16#include <linux/kernel.h>
 17#include <linux/module.h>
 18#include <linux/slab.h>
 19#include <linux/input.h>
 20#include <linux/serio.h>
 
 21#include <linux/ctype.h>
 22
 23#define DRIVER_DESC	"Elo serial touchscreen driver"
 24
 25MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
 26MODULE_DESCRIPTION(DRIVER_DESC);
 27MODULE_LICENSE("GPL");
 28
 29/*
 30 * Definitions & global arrays.
 31 */
 32
 33#define ELO_MAX_LENGTH		10
 34
 35#define ELO10_PACKET_LEN	8
 36#define ELO10_TOUCH		0x03
 37#define ELO10_PRESSURE		0x80
 38
 39#define ELO10_LEAD_BYTE		'U'
 40
 41#define ELO10_ID_CMD		'i'
 42
 43#define ELO10_TOUCH_PACKET	'T'
 44#define ELO10_ACK_PACKET	'A'
 45#define ELI10_ID_PACKET		'I'
 46
 47/*
 48 * Per-touchscreen data.
 49 */
 50
 51struct elo {
 52	struct input_dev *dev;
 53	struct serio *serio;
 54	struct mutex cmd_mutex;
 55	struct completion cmd_done;
 56	int id;
 57	int idx;
 58	unsigned char expected_packet;
 59	unsigned char csum;
 60	unsigned char data[ELO_MAX_LENGTH];
 61	unsigned char response[ELO10_PACKET_LEN];
 62	char phys[32];
 63};
 64
 65static void elo_process_data_10(struct elo *elo, unsigned char data)
 66{
 67	struct input_dev *dev = elo->dev;
 68
 69	elo->data[elo->idx] = data;
 70
 71	switch (elo->idx++) {
 72	case 0:
 73		elo->csum = 0xaa;
 74		if (data != ELO10_LEAD_BYTE) {
 75			dev_dbg(&elo->serio->dev,
 76				"unsynchronized data: 0x%02x\n", data);
 77			elo->idx = 0;
 78		}
 79		break;
 80
 81	case 9:
 82		elo->idx = 0;
 83		if (data != elo->csum) {
 84			dev_dbg(&elo->serio->dev,
 85				"bad checksum: 0x%02x, expected 0x%02x\n",
 86				 data, elo->csum);
 87			break;
 88		}
 89		if (elo->data[1] != elo->expected_packet) {
 90			if (elo->data[1] != ELO10_TOUCH_PACKET)
 91				dev_dbg(&elo->serio->dev,
 92					"unexpected packet: 0x%02x\n",
 93					 elo->data[1]);
 94			break;
 95		}
 96		if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) {
 97			input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
 98			input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
 99			if (elo->data[2] & ELO10_PRESSURE)
100				input_report_abs(dev, ABS_PRESSURE,
101						(elo->data[8] << 8) | elo->data[7]);
102			input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH);
103			input_sync(dev);
104		} else if (elo->data[1] == ELO10_ACK_PACKET) {
105			if (elo->data[2] == '0')
106				elo->expected_packet = ELO10_TOUCH_PACKET;
107			complete(&elo->cmd_done);
108		} else {
109			memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN);
110			elo->expected_packet = ELO10_ACK_PACKET;
111		}
112		break;
113	}
114	elo->csum += data;
115}
116
117static void elo_process_data_6(struct elo *elo, unsigned char data)
118{
119	struct input_dev *dev = elo->dev;
120
121	elo->data[elo->idx] = data;
122
123	switch (elo->idx++) {
124
125	case 0:
126		if ((data & 0xc0) != 0xc0)
127			elo->idx = 0;
128		break;
129
130	case 1:
131		if ((data & 0xc0) != 0x80)
132			elo->idx = 0;
133		break;
134
135	case 2:
136		if ((data & 0xc0) != 0x40)
137			elo->idx = 0;
138		break;
139
140	case 3:
141		if (data & 0xc0) {
142			elo->idx = 0;
143			break;
144		}
145
146		input_report_abs(dev, ABS_X, ((elo->data[0] & 0x3f) << 6) | (elo->data[1] & 0x3f));
147		input_report_abs(dev, ABS_Y, ((elo->data[2] & 0x3f) << 6) | (elo->data[3] & 0x3f));
148
149		if (elo->id == 2) {
150			input_report_key(dev, BTN_TOUCH, 1);
151			input_sync(dev);
152			elo->idx = 0;
153		}
154
155		break;
156
157	case 4:
158		if (data) {
159			input_sync(dev);
160			elo->idx = 0;
161		}
162		break;
163
164	case 5:
165		if ((data & 0xf0) == 0) {
166			input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
167			input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
168		}
169		input_sync(dev);
170		elo->idx = 0;
171		break;
172	}
173}
174
175static void elo_process_data_3(struct elo *elo, unsigned char data)
176{
177	struct input_dev *dev = elo->dev;
178
179	elo->data[elo->idx] = data;
180
181	switch (elo->idx++) {
182
183	case 0:
184		if ((data & 0x7f) != 0x01)
185			elo->idx = 0;
186		break;
187	case 2:
188		input_report_key(dev, BTN_TOUCH, !(elo->data[1] & 0x80));
189		input_report_abs(dev, ABS_X, elo->data[1]);
190		input_report_abs(dev, ABS_Y, elo->data[2]);
191		input_sync(dev);
192		elo->idx = 0;
193		break;
194	}
195}
196
197static irqreturn_t elo_interrupt(struct serio *serio,
198		unsigned char data, unsigned int flags)
199{
200	struct elo *elo = serio_get_drvdata(serio);
201
202	switch (elo->id) {
203	case 0:
204		elo_process_data_10(elo, data);
205		break;
206
207	case 1:
208	case 2:
209		elo_process_data_6(elo, data);
210		break;
211
212	case 3:
213		elo_process_data_3(elo, data);
214		break;
215	}
216
217	return IRQ_HANDLED;
218}
219
220static int elo_command_10(struct elo *elo, unsigned char *packet)
221{
222	int rc = -1;
223	int i;
224	unsigned char csum = 0xaa + ELO10_LEAD_BYTE;
225
226	mutex_lock(&elo->cmd_mutex);
227
228	scoped_guard(serio_pause_rx, elo->serio) {
229		elo->expected_packet = toupper(packet[0]);
230		init_completion(&elo->cmd_done);
231	}
232
233	if (serio_write(elo->serio, ELO10_LEAD_BYTE))
234		goto out;
235
236	for (i = 0; i < ELO10_PACKET_LEN; i++) {
237		csum += packet[i];
238		if (serio_write(elo->serio, packet[i]))
239			goto out;
240	}
241
242	if (serio_write(elo->serio, csum))
243		goto out;
244
245	wait_for_completion_timeout(&elo->cmd_done, HZ);
246
247	if (elo->expected_packet == ELO10_TOUCH_PACKET) {
248		/* We are back in reporting mode, the command was ACKed */
249		memcpy(packet, elo->response, ELO10_PACKET_LEN);
250		rc = 0;
251	}
252
253 out:
254	mutex_unlock(&elo->cmd_mutex);
255	return rc;
256}
257
258static int elo_setup_10(struct elo *elo)
259{
260	static const char *elo_types[] = { "Accu", "Dura", "Intelli", "Carroll" };
261	struct input_dev *dev = elo->dev;
262	unsigned char packet[ELO10_PACKET_LEN] = { ELO10_ID_CMD };
263
264	if (elo_command_10(elo, packet))
265		return -1;
266
267	dev->id.version = (packet[5] << 8) | packet[4];
268
269	input_set_abs_params(dev, ABS_X, 96, 4000, 0, 0);
270	input_set_abs_params(dev, ABS_Y, 96, 4000, 0, 0);
271	if (packet[3] & ELO10_PRESSURE)
272		input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
273
274	dev_info(&elo->serio->dev,
275		 "%sTouch touchscreen, fw: %02x.%02x, features: 0x%02x, controller: 0x%02x\n",
276		 elo_types[(packet[1] -'0') & 0x03],
277		 packet[5], packet[4], packet[3], packet[7]);
278
279	return 0;
280}
281
282/*
283 * elo_disconnect() is the opposite of elo_connect()
284 */
285
286static void elo_disconnect(struct serio *serio)
287{
288	struct elo *elo = serio_get_drvdata(serio);
289
290	input_get_device(elo->dev);
291	input_unregister_device(elo->dev);
292	serio_close(serio);
293	serio_set_drvdata(serio, NULL);
294	input_put_device(elo->dev);
295	kfree(elo);
296}
297
298/*
299 * elo_connect() is the routine that is called when someone adds a
300 * new serio device that supports Gunze protocol and registers it as
301 * an input device.
302 */
303
304static int elo_connect(struct serio *serio, struct serio_driver *drv)
305{
306	struct elo *elo;
307	struct input_dev *input_dev;
308	int err;
309
310	elo = kzalloc(sizeof(*elo), GFP_KERNEL);
311	input_dev = input_allocate_device();
312	if (!elo || !input_dev) {
313		err = -ENOMEM;
314		goto fail1;
315	}
316
317	elo->serio = serio;
318	elo->id = serio->id.id;
319	elo->dev = input_dev;
320	elo->expected_packet = ELO10_TOUCH_PACKET;
321	mutex_init(&elo->cmd_mutex);
322	init_completion(&elo->cmd_done);
323	snprintf(elo->phys, sizeof(elo->phys), "%s/input0", serio->phys);
324
325	input_dev->name = "Elo Serial TouchScreen";
326	input_dev->phys = elo->phys;
327	input_dev->id.bustype = BUS_RS232;
328	input_dev->id.vendor = SERIO_ELO;
329	input_dev->id.product = elo->id;
330	input_dev->id.version = 0x0100;
331	input_dev->dev.parent = &serio->dev;
332
333	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
334	input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
335
336	serio_set_drvdata(serio, elo);
337	err = serio_open(serio, drv);
338	if (err)
339		goto fail2;
340
341	switch (elo->id) {
342
343	case 0: /* 10-byte protocol */
344		if (elo_setup_10(elo)) {
345			err = -EIO;
346			goto fail3;
347		}
348
349		break;
350
351	case 1: /* 6-byte protocol */
352		input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0);
353		fallthrough;
354
355	case 2: /* 4-byte protocol */
356		input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
357		input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
358		break;
359
360	case 3: /* 3-byte protocol */
361		input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
362		input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
363		break;
364	}
365
366	err = input_register_device(elo->dev);
367	if (err)
368		goto fail3;
369
370	return 0;
371
372 fail3: serio_close(serio);
373 fail2:	serio_set_drvdata(serio, NULL);
374 fail1:	input_free_device(input_dev);
375	kfree(elo);
376	return err;
377}
378
379/*
380 * The serio driver structure.
381 */
382
383static const struct serio_device_id elo_serio_ids[] = {
384	{
385		.type	= SERIO_RS232,
386		.proto	= SERIO_ELO,
387		.id	= SERIO_ANY,
388		.extra	= SERIO_ANY,
389	},
390	{ 0 }
391};
392
393MODULE_DEVICE_TABLE(serio, elo_serio_ids);
394
395static struct serio_driver elo_drv = {
396	.driver		= {
397		.name	= "elo",
398	},
399	.description	= DRIVER_DESC,
400	.id_table	= elo_serio_ids,
401	.interrupt	= elo_interrupt,
402	.connect	= elo_connect,
403	.disconnect	= elo_disconnect,
404};
405
406module_serio_driver(elo_drv);