2 * Touchright serial touchscreen driver
4 * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com>
6 * Based on MicroTouch driver (drivers/input/touchscreen/mtouch.c)
7 * Copyright (c) 2004 Vojtech Pavlik
8 * and Dan Streetman <ddstreet@ieee.org>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published
14 * by the Free Software Foundation.
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/input.h>
22 #include <linux/serio.h>
24 #define DRIVER_DESC "Touchright serial touchscreen driver"
26 MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>");
27 MODULE_DESCRIPTION(DRIVER_DESC
);
28 MODULE_LICENSE("GPL");
31 * Definitions & global arrays.
34 #define TR_FORMAT_TOUCH_BIT 0x01
35 #define TR_FORMAT_STATUS_BYTE 0x40
36 #define TR_FORMAT_STATUS_MASK ~TR_FORMAT_TOUCH_BIT
41 #define TR_MAX_XC 0x1ff
43 #define TR_MAX_YC 0x1ff
46 * Per-touchscreen data.
50 struct input_dev
*dev
;
53 unsigned char data
[TR_LENGTH
];
57 static irqreturn_t
tr_interrupt(struct serio
*serio
,
58 unsigned char data
, unsigned int flags
)
60 struct tr
*tr
= serio_get_drvdata(serio
);
61 struct input_dev
*dev
= tr
->dev
;
63 tr
->data
[tr
->idx
] = data
;
65 if ((tr
->data
[0] & TR_FORMAT_STATUS_MASK
) == TR_FORMAT_STATUS_BYTE
) {
66 if (++tr
->idx
== TR_LENGTH
) {
67 input_report_abs(dev
, ABS_X
,
68 (tr
->data
[1] << 5) | (tr
->data
[2] >> 1));
69 input_report_abs(dev
, ABS_Y
,
70 (tr
->data
[3] << 5) | (tr
->data
[4] >> 1));
71 input_report_key(dev
, BTN_TOUCH
,
72 tr
->data
[0] & TR_FORMAT_TOUCH_BIT
);
82 * tr_disconnect() is the opposite of tr_connect()
85 static void tr_disconnect(struct serio
*serio
)
87 struct tr
*tr
= serio_get_drvdata(serio
);
89 input_get_device(tr
->dev
);
90 input_unregister_device(tr
->dev
);
92 serio_set_drvdata(serio
, NULL
);
93 input_put_device(tr
->dev
);
98 * tr_connect() is the routine that is called when someone adds a
99 * new serio device that supports the Touchright protocol and registers it as
103 static int tr_connect(struct serio
*serio
, struct serio_driver
*drv
)
106 struct input_dev
*input_dev
;
109 tr
= kzalloc(sizeof(struct tr
), GFP_KERNEL
);
110 input_dev
= input_allocate_device();
111 if (!tr
|| !input_dev
) {
118 snprintf(tr
->phys
, sizeof(tr
->phys
), "%s/input0", serio
->phys
);
120 input_dev
->name
= "Touchright Serial TouchScreen";
121 input_dev
->phys
= tr
->phys
;
122 input_dev
->id
.bustype
= BUS_RS232
;
123 input_dev
->id
.vendor
= SERIO_TOUCHRIGHT
;
124 input_dev
->id
.product
= 0;
125 input_dev
->id
.version
= 0x0100;
126 input_dev
->dev
.parent
= &serio
->dev
;
127 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
128 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
129 input_set_abs_params(tr
->dev
, ABS_X
, TR_MIN_XC
, TR_MAX_XC
, 0, 0);
130 input_set_abs_params(tr
->dev
, ABS_Y
, TR_MIN_YC
, TR_MAX_YC
, 0, 0);
132 serio_set_drvdata(serio
, tr
);
134 err
= serio_open(serio
, drv
);
138 err
= input_register_device(tr
->dev
);
144 fail3
: serio_close(serio
);
145 fail2
: serio_set_drvdata(serio
, NULL
);
146 fail1
: input_free_device(input_dev
);
152 * The serio driver structure.
155 static struct serio_device_id tr_serio_ids
[] = {
158 .proto
= SERIO_TOUCHRIGHT
,
165 MODULE_DEVICE_TABLE(serio
, tr_serio_ids
);
167 static struct serio_driver tr_drv
= {
169 .name
= "touchright",
171 .description
= DRIVER_DESC
,
172 .id_table
= tr_serio_ids
,
173 .interrupt
= tr_interrupt
,
174 .connect
= tr_connect
,
175 .disconnect
= tr_disconnect
,
178 module_serio_driver(tr_drv
);