diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2011-09-28 13:04:21 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-09-28 13:24:14 -0400 |
commit | f01536e3d68bacaf827325b716c743c542d20b64 (patch) | |
tree | 21133f78e14f9c9c97b55a625af2d178cdc673c2 /drivers/input/touchscreen | |
parent | 5eb9f900e5b524682ace6771529826c4ce26b6ea (diff) |
Input: add a driver for TSC-40 serial touchscreen
This patch adds the TSC-40 serial touchscreen driver and should be
compatible with TSC-10 and TSC-25.
The driver was written by Linutronix on behalf of Bachmann electronic GmbH.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 12 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/touchscreen/tsc40.c | 184 |
3 files changed, 197 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index cabd9e54863f..3488ffe1fa0a 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -651,6 +651,18 @@ config TOUCHSCREEN_TOUCHIT213 | |||
651 | To compile this driver as a module, choose M here: the | 651 | To compile this driver as a module, choose M here: the |
652 | module will be called touchit213. | 652 | module will be called touchit213. |
653 | 653 | ||
654 | config TOUCHSCREEN_TSC_SERIO | ||
655 | tristate "TSC-10/25/40 serial touchscreen support" | ||
656 | select SERIO | ||
657 | help | ||
658 | Say Y here if you have a TSC-10, 25 or 40 serial touchscreen connected | ||
659 | to your system. | ||
660 | |||
661 | If unsure, say N. | ||
662 | |||
663 | To compile this driver as a module, choose M here: the | ||
664 | module will be called tsc40. | ||
665 | |||
654 | config TOUCHSCREEN_TSC2005 | 666 | config TOUCHSCREEN_TSC2005 |
655 | tristate "TSC2005 based touchscreens" | 667 | tristate "TSC2005 based touchscreens" |
656 | depends on SPI_MASTER && GENERIC_HARDIRQS | 668 | depends on SPI_MASTER && GENERIC_HARDIRQS |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 282d6f76ae26..f957676035a4 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -46,6 +46,7 @@ obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o | |||
46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o | 46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o |
47 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o | 47 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o |
48 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o | 48 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o |
49 | obj-$(CONFIG_TOUCHSCREEN_TSC_SERIO) += tsc40.o | ||
49 | obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o | 50 | obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o |
50 | obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o | 51 | obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o |
51 | obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o | 52 | obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o |
diff --git a/drivers/input/touchscreen/tsc40.c b/drivers/input/touchscreen/tsc40.c new file mode 100644 index 000000000000..29d5ed4dd31c --- /dev/null +++ b/drivers/input/touchscreen/tsc40.c | |||
@@ -0,0 +1,184 @@ | |||
1 | /* | ||
2 | * TSC-40 serial touchscreen driver. It should be compatible with | ||
3 | * TSC-10 and 25. | ||
4 | * | ||
5 | * Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> | ||
6 | * License: GPLv2 as published by the FSF. | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/input.h> | ||
13 | #include <linux/serio.h> | ||
14 | #include <linux/init.h> | ||
15 | |||
16 | #define PACKET_LENGTH 5 | ||
17 | struct tsc_ser { | ||
18 | struct input_dev *dev; | ||
19 | struct serio *serio; | ||
20 | u32 idx; | ||
21 | unsigned char data[PACKET_LENGTH]; | ||
22 | char phys[32]; | ||
23 | }; | ||
24 | |||
25 | static void tsc_process_data(struct tsc_ser *ptsc) | ||
26 | { | ||
27 | struct input_dev *dev = ptsc->dev; | ||
28 | u8 *data = ptsc->data; | ||
29 | u32 x; | ||
30 | u32 y; | ||
31 | |||
32 | x = ((data[1] & 0x03) << 8) | data[2]; | ||
33 | y = ((data[3] & 0x03) << 8) | data[4]; | ||
34 | |||
35 | input_report_abs(dev, ABS_X, x); | ||
36 | input_report_abs(dev, ABS_Y, y); | ||
37 | input_report_key(dev, BTN_TOUCH, 1); | ||
38 | |||
39 | input_sync(dev); | ||
40 | } | ||
41 | |||
42 | static irqreturn_t tsc_interrupt(struct serio *serio, | ||
43 | unsigned char data, unsigned int flags) | ||
44 | { | ||
45 | struct tsc_ser *ptsc = serio_get_drvdata(serio); | ||
46 | struct input_dev *dev = ptsc->dev; | ||
47 | |||
48 | ptsc->data[ptsc->idx] = data; | ||
49 | switch (ptsc->idx++) { | ||
50 | case 0: | ||
51 | if (unlikely((data & 0x3e) != 0x10)) { | ||
52 | dev_dbg(&serio->dev, | ||
53 | "unsynchronized packet start (0x%02x)\n", data); | ||
54 | ptsc->idx = 0; | ||
55 | } else if (!(data & 0x01)) { | ||
56 | input_report_key(dev, BTN_TOUCH, 0); | ||
57 | input_sync(dev); | ||
58 | ptsc->idx = 0; | ||
59 | } | ||
60 | break; | ||
61 | |||
62 | case 1: | ||
63 | case 3: | ||
64 | if (unlikely(data & 0xfc)) { | ||
65 | dev_dbg(&serio->dev, | ||
66 | "unsynchronized data 0x%02x at offset %d\n", | ||
67 | data, ptsc->idx - 1); | ||
68 | ptsc->idx = 0; | ||
69 | } | ||
70 | break; | ||
71 | |||
72 | case 4: | ||
73 | tsc_process_data(ptsc); | ||
74 | ptsc->idx = 0; | ||
75 | break; | ||
76 | } | ||
77 | |||
78 | return IRQ_HANDLED; | ||
79 | } | ||
80 | |||
81 | static int tsc_connect(struct serio *serio, struct serio_driver *drv) | ||
82 | { | ||
83 | struct tsc_ser *ptsc; | ||
84 | struct input_dev *input_dev; | ||
85 | int error; | ||
86 | |||
87 | ptsc = kzalloc(sizeof(struct tsc_ser), GFP_KERNEL); | ||
88 | input_dev = input_allocate_device(); | ||
89 | if (!ptsc || !input_dev) { | ||
90 | error = -ENOMEM; | ||
91 | goto fail1; | ||
92 | } | ||
93 | |||
94 | ptsc->serio = serio; | ||
95 | ptsc->dev = input_dev; | ||
96 | snprintf(ptsc->phys, sizeof(ptsc->phys), "%s/input0", serio->phys); | ||
97 | |||
98 | input_dev->name = "TSC-10/25/40 Serial TouchScreen"; | ||
99 | input_dev->phys = ptsc->phys; | ||
100 | input_dev->id.bustype = BUS_RS232; | ||
101 | input_dev->id.vendor = SERIO_TSC40; | ||
102 | input_dev->id.product = 40; | ||
103 | input_dev->id.version = 0x0001; | ||
104 | input_dev->dev.parent = &serio->dev; | ||
105 | |||
106 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); | ||
107 | __set_bit(BTN_TOUCH, input_dev->keybit); | ||
108 | input_set_abs_params(ptsc->dev, ABS_X, 0, 0x3ff, 0, 0); | ||
109 | input_set_abs_params(ptsc->dev, ABS_Y, 0, 0x3ff, 0, 0); | ||
110 | input_set_abs_params(ptsc->dev, ABS_PRESSURE, 0, 0, 0, 0); | ||
111 | |||
112 | serio_set_drvdata(serio, ptsc); | ||
113 | |||
114 | error = serio_open(serio, drv); | ||
115 | if (error) | ||
116 | goto fail2; | ||
117 | |||
118 | error = input_register_device(ptsc->dev); | ||
119 | if (error) | ||
120 | goto fail3; | ||
121 | |||
122 | return 0; | ||
123 | |||
124 | fail3: | ||
125 | serio_close(serio); | ||
126 | fail2: | ||
127 | serio_set_drvdata(serio, NULL); | ||
128 | fail1: | ||
129 | input_free_device(input_dev); | ||
130 | kfree(ptsc); | ||
131 | return error; | ||
132 | } | ||
133 | |||
134 | static void tsc_disconnect(struct serio *serio) | ||
135 | { | ||
136 | struct tsc_ser *ptsc = serio_get_drvdata(serio); | ||
137 | |||
138 | serio_close(serio); | ||
139 | |||
140 | input_unregister_device(ptsc->dev); | ||
141 | kfree(ptsc); | ||
142 | |||
143 | serio_set_drvdata(serio, NULL); | ||
144 | } | ||
145 | |||
146 | static struct serio_device_id tsc_serio_ids[] = { | ||
147 | { | ||
148 | .type = SERIO_RS232, | ||
149 | .proto = SERIO_TSC40, | ||
150 | .id = SERIO_ANY, | ||
151 | .extra = SERIO_ANY, | ||
152 | }, | ||
153 | { 0 } | ||
154 | }; | ||
155 | MODULE_DEVICE_TABLE(serio, tsc_serio_ids); | ||
156 | |||
157 | #define DRIVER_DESC "TSC-10/25/40 serial touchscreen driver" | ||
158 | |||
159 | static struct serio_driver tsc_drv = { | ||
160 | .driver = { | ||
161 | .name = "tsc40", | ||
162 | }, | ||
163 | .description = DRIVER_DESC, | ||
164 | .id_table = tsc_serio_ids, | ||
165 | .interrupt = tsc_interrupt, | ||
166 | .connect = tsc_connect, | ||
167 | .disconnect = tsc_disconnect, | ||
168 | }; | ||
169 | |||
170 | static int __init tsc_ser_init(void) | ||
171 | { | ||
172 | return serio_register_driver(&tsc_drv); | ||
173 | } | ||
174 | module_init(tsc_ser_init); | ||
175 | |||
176 | static void __exit tsc_exit(void) | ||
177 | { | ||
178 | serio_unregister_driver(&tsc_drv); | ||
179 | } | ||
180 | module_exit(tsc_exit); | ||
181 | |||
182 | MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>"); | ||
183 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
184 | MODULE_LICENSE("GPL v2"); | ||