diff options
author | Rick Koch <n1gp@hotmail.com> | 2006-08-05 00:32:30 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor@insightbb.com> | 2006-08-05 00:32:30 -0400 |
commit | 11ea3173d5f2de71d037ef58ac43395795fed2bc (patch) | |
tree | 6ce61a0d8ce70767ee5cc47f74d3355a7be3b414 /drivers/input/touchscreen | |
parent | 4003dff41e65ad338a60dde90019bffcb5531fb6 (diff) |
Input: add driver for Touchwin serial touchscreens
Signed-off-by: Rick Koch <n1gp@hotmail.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/touchwin.c | 203 |
3 files changed, 216 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 216db1229376..9418bbe47072 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -132,4 +132,16 @@ config TOUCHSCREEN_TOUCHRIGHT | |||
132 | To compile this driver as a module, choose M here: the | 132 | To compile this driver as a module, choose M here: the |
133 | module will be called touchright. | 133 | module will be called touchright. |
134 | 134 | ||
135 | config TOUCHSCREEN_TOUCHWIN | ||
136 | tristate "Touchwin serial touchscreen" | ||
137 | select SERIO | ||
138 | help | ||
139 | Say Y here if you have a Touchwin serial touchscreen connected to | ||
140 | your system. | ||
141 | |||
142 | If unsure, say N. | ||
143 | |||
144 | To compile this driver as a module, choose M here: the | ||
145 | module will be called touchwin. | ||
146 | |||
135 | endif | 147 | endif |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index deda25e36807..1abb8f10d608 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -14,3 +14,4 @@ obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o | |||
14 | obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o | 14 | obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o |
15 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o | 15 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o |
16 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o | 16 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o |
17 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o | ||
diff --git a/drivers/input/touchscreen/touchwin.c b/drivers/input/touchscreen/touchwin.c new file mode 100644 index 000000000000..a7b4c755958e --- /dev/null +++ b/drivers/input/touchscreen/touchwin.c | |||
@@ -0,0 +1,203 @@ | |||
1 | /* | ||
2 | * Touchwindow serial touchscreen driver | ||
3 | * | ||
4 | * Copyright (c) 2006 Rick Koch <n1gp@hotmail.com> | ||
5 | * | ||
6 | * Based on MicroTouch driver (drivers/input/touchscreen/mtouch.c) | ||
7 | * Copyright (c) 2004 Vojtech Pavlik | ||
8 | * and Dan Streetman <ddstreet@ieee.org> | ||
9 | */ | ||
10 | |||
11 | /* | ||
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. | ||
15 | */ | ||
16 | |||
17 | /* | ||
18 | * 2005/02/19 Rick Koch: | ||
19 | * The Touchwindow I used is made by Edmark Corp. and | ||
20 | * constantly outputs a stream of 0's unless it is touched. | ||
21 | * It then outputs 3 bytes: X, Y, and a copy of Y. | ||
22 | */ | ||
23 | |||
24 | #include <linux/errno.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/input.h> | ||
29 | #include <linux/serio.h> | ||
30 | #include <linux/init.h> | ||
31 | |||
32 | #define DRIVER_DESC "Touchwindow serial touchscreen driver" | ||
33 | |||
34 | MODULE_AUTHOR("Rick Koch <n1gp@hotmail.com>"); | ||
35 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
36 | MODULE_LICENSE("GPL"); | ||
37 | |||
38 | /* | ||
39 | * Definitions & global arrays. | ||
40 | */ | ||
41 | |||
42 | #define TW_LENGTH 3 | ||
43 | |||
44 | #define TW_MIN_XC 0 | ||
45 | #define TW_MAX_XC 0xff | ||
46 | #define TW_MIN_YC 0 | ||
47 | #define TW_MAX_YC 0xff | ||
48 | |||
49 | /* | ||
50 | * Per-touchscreen data. | ||
51 | */ | ||
52 | |||
53 | struct tw { | ||
54 | struct input_dev *dev; | ||
55 | struct serio *serio; | ||
56 | int idx; | ||
57 | int touched; | ||
58 | unsigned char data[TW_LENGTH]; | ||
59 | char phys[32]; | ||
60 | }; | ||
61 | |||
62 | static irqreturn_t tw_interrupt(struct serio *serio, | ||
63 | unsigned char data, unsigned int flags, struct pt_regs *regs) | ||
64 | { | ||
65 | struct tw *tw = serio_get_drvdata(serio); | ||
66 | struct input_dev *dev = tw->dev; | ||
67 | |||
68 | if (data) { /* touch */ | ||
69 | tw->touched = 1; | ||
70 | tw->data[tw->idx++] = data; | ||
71 | /* verify length and that the two Y's are the same */ | ||
72 | if (tw->idx == TW_LENGTH && tw->data[1] == tw->data[2]) { | ||
73 | input_regs(dev, regs); | ||
74 | input_report_abs(dev, ABS_X, tw->data[0]); | ||
75 | input_report_abs(dev, ABS_Y, tw->data[1]); | ||
76 | input_report_key(dev, BTN_TOUCH, 1); | ||
77 | input_sync(dev); | ||
78 | tw->idx = 0; | ||
79 | } | ||
80 | } else if (tw->touched) { /* untouch */ | ||
81 | input_report_key(dev, BTN_TOUCH, 0); | ||
82 | input_sync(dev); | ||
83 | tw->idx = 0; | ||
84 | tw->touched = 0; | ||
85 | } | ||
86 | |||
87 | return IRQ_HANDLED; | ||
88 | } | ||
89 | |||
90 | /* | ||
91 | * tw_disconnect() is the opposite of tw_connect() | ||
92 | */ | ||
93 | |||
94 | static void tw_disconnect(struct serio *serio) | ||
95 | { | ||
96 | struct tw *tw = serio_get_drvdata(serio); | ||
97 | |||
98 | input_get_device(tw->dev); | ||
99 | input_unregister_device(tw->dev); | ||
100 | serio_close(serio); | ||
101 | serio_set_drvdata(serio, NULL); | ||
102 | input_put_device(tw->dev); | ||
103 | kfree(tw); | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * tw_connect() is the routine that is called when someone adds a | ||
108 | * new serio device that supports the Touchwin protocol and registers it as | ||
109 | * an input device. | ||
110 | */ | ||
111 | |||
112 | static int tw_connect(struct serio *serio, struct serio_driver *drv) | ||
113 | { | ||
114 | struct tw *tw; | ||
115 | struct input_dev *input_dev; | ||
116 | int err; | ||
117 | |||
118 | tw = kzalloc(sizeof(struct tw), GFP_KERNEL); | ||
119 | input_dev = input_allocate_device(); | ||
120 | if (!tw || !input_dev) { | ||
121 | err = -ENOMEM; | ||
122 | goto fail1; | ||
123 | } | ||
124 | |||
125 | tw->serio = serio; | ||
126 | tw->dev = input_dev; | ||
127 | snprintf(tw->phys, sizeof(tw->phys), "%s/input0", serio->phys); | ||
128 | |||
129 | input_dev->private = tw; | ||
130 | input_dev->name = "Touchwindow Serial TouchScreen"; | ||
131 | input_dev->phys = tw->phys; | ||
132 | input_dev->id.bustype = BUS_RS232; | ||
133 | input_dev->id.vendor = SERIO_TOUCHWIN; | ||
134 | input_dev->id.product = 0; | ||
135 | input_dev->id.version = 0x0100; | ||
136 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
137 | input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); | ||
138 | input_set_abs_params(tw->dev, ABS_X, TW_MIN_XC, TW_MAX_XC, 0, 0); | ||
139 | input_set_abs_params(tw->dev, ABS_Y, TW_MIN_YC, TW_MAX_YC, 0, 0); | ||
140 | |||
141 | serio_set_drvdata(serio, tw); | ||
142 | |||
143 | err = serio_open(serio, drv); | ||
144 | if (err) | ||
145 | goto fail2; | ||
146 | |||
147 | err = input_register_device(tw->dev); | ||
148 | if (err) | ||
149 | goto fail3; | ||
150 | |||
151 | return 0; | ||
152 | |||
153 | fail3: serio_close(serio); | ||
154 | fail2: serio_set_drvdata(serio, NULL); | ||
155 | fail1: input_free_device(input_dev); | ||
156 | kfree(tw); | ||
157 | return err; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * The serio driver structure. | ||
162 | */ | ||
163 | |||
164 | static struct serio_device_id tw_serio_ids[] = { | ||
165 | { | ||
166 | .type = SERIO_RS232, | ||
167 | .proto = SERIO_TOUCHWIN, | ||
168 | .id = SERIO_ANY, | ||
169 | .extra = SERIO_ANY, | ||
170 | }, | ||
171 | { 0 } | ||
172 | }; | ||
173 | |||
174 | MODULE_DEVICE_TABLE(serio, tw_serio_ids); | ||
175 | |||
176 | static struct serio_driver tw_drv = { | ||
177 | .driver = { | ||
178 | .name = "touchwin", | ||
179 | }, | ||
180 | .description = DRIVER_DESC, | ||
181 | .id_table = tw_serio_ids, | ||
182 | .interrupt = tw_interrupt, | ||
183 | .connect = tw_connect, | ||
184 | .disconnect = tw_disconnect, | ||
185 | }; | ||
186 | |||
187 | /* | ||
188 | * The functions for inserting/removing us as a module. | ||
189 | */ | ||
190 | |||
191 | static int __init tw_init(void) | ||
192 | { | ||
193 | serio_register_driver(&tw_drv); | ||
194 | return 0; | ||
195 | } | ||
196 | |||
197 | static void __exit tw_exit(void) | ||
198 | { | ||
199 | serio_unregister_driver(&tw_drv); | ||
200 | } | ||
201 | |||
202 | module_init(tw_init); | ||
203 | module_exit(tw_exit); | ||