1 // SPDX-License-Identifier: GPL-2.0-only
3 * Sahara TouchIT-213 serial touchscreen driver
5 * Copyright (c) 2007-2008 Claudio Nieder <private@claudio.ch>
7 * Based on Touchright driver (drivers/input/touchscreen/touchright.c)
8 * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com>
9 * Copyright (c) 2004 Vojtech Pavlik
10 * and Dan Streetman <ddstreet@ieee.org>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/input.h>
19 #include <linux/serio.h>
21 #define DRIVER_DESC "Sahara TouchIT-213 serial touchscreen driver"
23 MODULE_AUTHOR("Claudio Nieder <private@claudio.ch>");
24 MODULE_DESCRIPTION(DRIVER_DESC
);
25 MODULE_LICENSE("GPL");
28 * Definitions & global arrays.
32 * Data is received through COM1 at 9600bit/s,8bit,no parity in packets
35 * +--------+ +--------+ +--------+ +--------+ +--------+
36 * |1000000p| |0xxxxxxx| |0xxxxxxx| |0yyyyyyy| |0yyyyyyy|
37 * +--------+ +--------+ +--------+ +--------+ +--------+
40 * The value of p is 1 as long as the screen is touched and 0 when
41 * reporting the location where touching stopped, e.g. where the pen was
42 * lifted from the screen.
44 * When holding the screen in landscape mode as the BIOS text output is
45 * presented, x is the horizontal axis with values growing from left to
46 * right and y is the vertical axis with values growing from top to
49 * When holding the screen in portrait mode with the Sahara logo in its
50 * correct position, x ist the vertical axis with values growing from
51 * top to bottom and y is the horizontal axis with values growing from
55 #define T213_FORMAT_TOUCH_BIT 0x01
56 #define T213_FORMAT_STATUS_BYTE 0x80
57 #define T213_FORMAT_STATUS_MASK ~T213_FORMAT_TOUCH_BIT
60 * On my Sahara Touch-IT 213 I have observed x values from 0 to 0x7f0
61 * and y values from 0x1d to 0x7e9, so the actual measurement is
62 * probably done with an 11 bit precision.
65 #define T213_MAX_XC 0x07ff
67 #define T213_MAX_YC 0x07ff
70 * Per-touchscreen data.
74 struct input_dev
*dev
;
78 unsigned char data
[5];
82 static irqreturn_t
touchit213_interrupt(struct serio
*serio
,
83 unsigned char data
, unsigned int flags
)
85 struct touchit213
*touchit213
= serio_get_drvdata(serio
);
86 struct input_dev
*dev
= touchit213
->dev
;
88 touchit213
->data
[touchit213
->idx
] = data
;
90 switch (touchit213
->idx
++) {
92 if ((touchit213
->data
[0] & T213_FORMAT_STATUS_MASK
) !=
93 T213_FORMAT_STATUS_BYTE
) {
94 pr_debug("unsynchronized data: 0x%02x\n", data
);
101 input_report_abs(dev
, ABS_X
,
102 (touchit213
->data
[1] << 7) | touchit213
->data
[2]);
103 input_report_abs(dev
, ABS_Y
,
104 (touchit213
->data
[3] << 7) | touchit213
->data
[4]);
105 input_report_key(dev
, BTN_TOUCH
,
106 touchit213
->data
[0] & T213_FORMAT_TOUCH_BIT
);
115 * touchit213_disconnect() is the opposite of touchit213_connect()
118 static void touchit213_disconnect(struct serio
*serio
)
120 struct touchit213
*touchit213
= serio_get_drvdata(serio
);
122 input_get_device(touchit213
->dev
);
123 input_unregister_device(touchit213
->dev
);
125 serio_set_drvdata(serio
, NULL
);
126 input_put_device(touchit213
->dev
);
131 * touchit213_connect() is the routine that is called when someone adds a
132 * new serio device that supports the Touchright protocol and registers it as
136 static int touchit213_connect(struct serio
*serio
, struct serio_driver
*drv
)
138 struct touchit213
*touchit213
;
139 struct input_dev
*input_dev
;
142 touchit213
= kzalloc(sizeof(*touchit213
), GFP_KERNEL
);
143 input_dev
= input_allocate_device();
144 if (!touchit213
|| !input_dev
) {
149 touchit213
->serio
= serio
;
150 touchit213
->dev
= input_dev
;
151 snprintf(touchit213
->phys
, sizeof(touchit213
->phys
),
152 "%s/input0", serio
->phys
);
154 input_dev
->name
= "Sahara Touch-iT213 Serial TouchScreen";
155 input_dev
->phys
= touchit213
->phys
;
156 input_dev
->id
.bustype
= BUS_RS232
;
157 input_dev
->id
.vendor
= SERIO_TOUCHIT213
;
158 input_dev
->id
.product
= 0;
159 input_dev
->id
.version
= 0x0100;
160 input_dev
->dev
.parent
= &serio
->dev
;
161 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_ABS
);
162 input_dev
->keybit
[BIT_WORD(BTN_TOUCH
)] = BIT_MASK(BTN_TOUCH
);
163 input_set_abs_params(touchit213
->dev
, ABS_X
,
164 T213_MIN_XC
, T213_MAX_XC
, 0, 0);
165 input_set_abs_params(touchit213
->dev
, ABS_Y
,
166 T213_MIN_YC
, T213_MAX_YC
, 0, 0);
168 serio_set_drvdata(serio
, touchit213
);
170 err
= serio_open(serio
, drv
);
174 err
= input_register_device(touchit213
->dev
);
180 fail3
: serio_close(serio
);
181 fail2
: serio_set_drvdata(serio
, NULL
);
182 fail1
: input_free_device(input_dev
);
188 * The serio driver structure.
191 static const struct serio_device_id touchit213_serio_ids
[] = {
194 .proto
= SERIO_TOUCHIT213
,
201 MODULE_DEVICE_TABLE(serio
, touchit213_serio_ids
);
203 static struct serio_driver touchit213_drv
= {
205 .name
= "touchit213",
207 .description
= DRIVER_DESC
,
208 .id_table
= touchit213_serio_ids
,
209 .interrupt
= touchit213_interrupt
,
210 .connect
= touchit213_connect
,
211 .disconnect
= touchit213_disconnect
,
214 module_serio_driver(touchit213_drv
);