diff options
author | Hans-Christian Egtvedt <hc@mivu.no> | 2005-05-29 03:27:45 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-05-29 03:27:45 -0400 |
commit | 8608471262ddf4b8ed4120d7211251e8b8dcbda9 (patch) | |
tree | ea04fb639028f4f4f2f7ea2577922a07497df180 /drivers/usb/input | |
parent | 6af2cf59c22fbf5a5466928f29a9545b65fe0e96 (diff) |
Input: Add driver for ITM Touch USB touchscreens.
From: Hans-Christian Egtvedt <hc@mivu.no>
Signed-off-by: Vojtech Pavlik <vojtech@suse.cz>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/usb/input')
-rw-r--r-- | drivers/usb/input/Kconfig | 12 | ||||
-rw-r--r-- | drivers/usb/input/Makefile | 1 | ||||
-rw-r--r-- | drivers/usb/input/itmtouch.c | 281 |
3 files changed, 294 insertions, 0 deletions
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig index d28e7eab6f98..fcae574f3106 100644 --- a/drivers/usb/input/Kconfig +++ b/drivers/usb/input/Kconfig | |||
@@ -190,6 +190,18 @@ config USB_MTOUCH | |||
190 | To compile this driver as a module, choose M here: the | 190 | To compile this driver as a module, choose M here: the |
191 | module will be called mtouchusb. | 191 | module will be called mtouchusb. |
192 | 192 | ||
193 | config USB_ITMTOUCH | ||
194 | tristate "ITM Touch USB Touchscreen Driver" | ||
195 | depends on USB && INPUT | ||
196 | ---help--- | ||
197 | Say Y here if you want to use a ITM Touch USB | ||
198 | Touchscreen controller. | ||
199 | |||
200 | This touchscreen is used in LG 1510SF monitors. | ||
201 | |||
202 | To compile this driver as a module, choose M here: the | ||
203 | module will be called itmtouch. | ||
204 | |||
193 | config USB_EGALAX | 205 | config USB_EGALAX |
194 | tristate "eGalax TouchKit USB Touchscreen Driver" | 206 | tristate "eGalax TouchKit USB Touchscreen Driver" |
195 | depends on USB && INPUT | 207 | depends on USB && INPUT |
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile index 6bcedd16b0a1..f0fd02e00d32 100644 --- a/drivers/usb/input/Makefile +++ b/drivers/usb/input/Makefile | |||
@@ -33,6 +33,7 @@ obj-$(CONFIG_USB_KBD) += usbkbd.o | |||
33 | obj-$(CONFIG_USB_KBTAB) += kbtab.o | 33 | obj-$(CONFIG_USB_KBTAB) += kbtab.o |
34 | obj-$(CONFIG_USB_MOUSE) += usbmouse.o | 34 | obj-$(CONFIG_USB_MOUSE) += usbmouse.o |
35 | obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o | 35 | obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o |
36 | obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o | ||
36 | obj-$(CONFIG_USB_EGALAX) += touchkitusb.o | 37 | obj-$(CONFIG_USB_EGALAX) += touchkitusb.o |
37 | obj-$(CONFIG_USB_POWERMATE) += powermate.o | 38 | obj-$(CONFIG_USB_POWERMATE) += powermate.o |
38 | obj-$(CONFIG_USB_WACOM) += wacom.o | 39 | obj-$(CONFIG_USB_WACOM) += wacom.o |
diff --git a/drivers/usb/input/itmtouch.c b/drivers/usb/input/itmtouch.c new file mode 100644 index 000000000000..4c27c104f63e --- /dev/null +++ b/drivers/usb/input/itmtouch.c | |||
@@ -0,0 +1,281 @@ | |||
1 | /****************************************************************************** | ||
2 | * itmtouch.c -- Driver for ITM touchscreen panel | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of the | ||
7 | * License, or (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, but | ||
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | * | ||
18 | * Based upon original work by Chris Collins <xfire-itmtouch@xware.cx>. | ||
19 | * | ||
20 | * Kudos to ITM for providing me with the datasheet for the panel, | ||
21 | * even though it was a day later than I had finished writing this | ||
22 | * driver. | ||
23 | * | ||
24 | * It has meant that I've been able to correct my interpretation of the | ||
25 | * protocol packets however. | ||
26 | * | ||
27 | * CC -- 2003/9/29 | ||
28 | * | ||
29 | * History | ||
30 | * 1.0 & 1.1 2003 (CC) vojtech@suse.cz | ||
31 | * Original version for 2.4.x kernels | ||
32 | * | ||
33 | * 1.2 02/03/2005 (HCE) hc@mivu.no | ||
34 | * Complete rewrite to support Linux 2.6.10, thanks to mtouchusb.c for hints. | ||
35 | * Unfortunately no calibration support at this time. | ||
36 | * | ||
37 | * 1.2.1 09/03/2005 (HCE) hc@mivu.no | ||
38 | * Code cleanup and adjusting syntax to start matching kernel standards | ||
39 | * | ||
40 | *****************************************************************************/ | ||
41 | |||
42 | #include <linux/config.h> | ||
43 | |||
44 | #ifdef CONFIG_USB_DEBUG | ||
45 | #define DEBUG | ||
46 | #else | ||
47 | #undef DEBUG | ||
48 | #endif | ||
49 | |||
50 | #include <linux/kernel.h> | ||
51 | #include <linux/slab.h> | ||
52 | #include <linux/input.h> | ||
53 | #include <linux/module.h> | ||
54 | #include <linux/init.h> | ||
55 | #include <linux/usb.h> | ||
56 | |||
57 | /* only an 8 byte buffer necessary for a single packet */ | ||
58 | #define ITM_BUFSIZE 8 | ||
59 | #define PATH_SIZE 64 | ||
60 | |||
61 | #define USB_VENDOR_ID_ITMINC 0x0403 | ||
62 | #define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9 | ||
63 | |||
64 | #define DRIVER_AUTHOR "Hans-Christian Egtvedt <hc@mivu.no>" | ||
65 | #define DRIVER_VERSION "v1.2.1" | ||
66 | #define DRIVER_DESC "USB ITM Inc Touch Panel Driver" | ||
67 | #define DRIVER_LICENSE "GPL" | ||
68 | |||
69 | MODULE_AUTHOR( DRIVER_AUTHOR ); | ||
70 | MODULE_DESCRIPTION( DRIVER_DESC ); | ||
71 | MODULE_LICENSE( DRIVER_LICENSE ); | ||
72 | |||
73 | struct itmtouch_dev { | ||
74 | struct usb_device *usbdev; /* usb device */ | ||
75 | struct input_dev inputdev; /* input device */ | ||
76 | struct urb *readurb; /* urb */ | ||
77 | char rbuf[ITM_BUFSIZE]; /* data */ | ||
78 | int users; | ||
79 | char name[128]; | ||
80 | char phys[64]; | ||
81 | }; | ||
82 | |||
83 | static struct usb_device_id itmtouch_ids [] = { | ||
84 | { USB_DEVICE(USB_VENDOR_ID_ITMINC, USB_PRODUCT_ID_TOUCHPANEL) }, | ||
85 | { } | ||
86 | }; | ||
87 | |||
88 | static void itmtouch_irq(struct urb *urb, struct pt_regs *regs) | ||
89 | { | ||
90 | struct itmtouch_dev * itmtouch = urb->context; | ||
91 | unsigned char *data = urb->transfer_buffer; | ||
92 | struct input_dev *dev = &itmtouch->inputdev; | ||
93 | int retval; | ||
94 | |||
95 | switch (urb->status) { | ||
96 | case 0: | ||
97 | /* success */ | ||
98 | break; | ||
99 | case -ETIMEDOUT: | ||
100 | /* this urb is timing out */ | ||
101 | dbg("%s - urb timed out - was the device unplugged?", | ||
102 | __FUNCTION__); | ||
103 | return; | ||
104 | case -ECONNRESET: | ||
105 | case -ENOENT: | ||
106 | case -ESHUTDOWN: | ||
107 | /* this urb is terminated, clean up */ | ||
108 | dbg("%s - urb shutting down with status: %d", | ||
109 | __FUNCTION__, urb->status); | ||
110 | return; | ||
111 | default: | ||
112 | dbg("%s - nonzero urb status received: %d", | ||
113 | __FUNCTION__, urb->status); | ||
114 | goto exit; | ||
115 | } | ||
116 | |||
117 | input_regs(dev, regs); | ||
118 | |||
119 | /* if pressure has been released, then don't report X/Y */ | ||
120 | if (data[7] & 0x20) { | ||
121 | input_report_abs(dev, ABS_X, (data[0] & 0x1F) << 7 | (data[3] & 0x7F)); | ||
122 | input_report_abs(dev, ABS_Y, (data[1] & 0x1F) << 7 | (data[4] & 0x7F)); | ||
123 | } | ||
124 | |||
125 | input_report_abs(dev, ABS_PRESSURE, (data[2] & 1) << 7 | (data[5] & 0x7F)); | ||
126 | input_report_key(dev, BTN_TOUCH, ~data[7] & 0x20); | ||
127 | input_sync(dev); | ||
128 | |||
129 | exit: | ||
130 | retval = usb_submit_urb (urb, GFP_ATOMIC); | ||
131 | if (retval) | ||
132 | printk(KERN_ERR "%s - usb_submit_urb failed with result: %d", | ||
133 | __FUNCTION__, retval); | ||
134 | } | ||
135 | |||
136 | static int itmtouch_open(struct input_dev *input) | ||
137 | { | ||
138 | struct itmtouch_dev *itmtouch = input->private; | ||
139 | |||
140 | if (itmtouch->users++) | ||
141 | return 0; | ||
142 | |||
143 | itmtouch->readurb->dev = itmtouch->usbdev; | ||
144 | |||
145 | if (usb_submit_urb(itmtouch->readurb, GFP_KERNEL)) | ||
146 | { | ||
147 | itmtouch->users--; | ||
148 | return -EIO; | ||
149 | } | ||
150 | |||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | static void itmtouch_close(struct input_dev *input) | ||
155 | { | ||
156 | struct itmtouch_dev *itmtouch = input->private; | ||
157 | |||
158 | if (!--itmtouch->users) | ||
159 | usb_kill_urb(itmtouch->readurb); | ||
160 | } | ||
161 | |||
162 | static int itmtouch_probe(struct usb_interface *intf, const struct usb_device_id *id) | ||
163 | { | ||
164 | struct itmtouch_dev *itmtouch; | ||
165 | struct usb_host_interface *interface; | ||
166 | struct usb_endpoint_descriptor *endpoint; | ||
167 | struct usb_device *udev = interface_to_usbdev(intf); | ||
168 | unsigned int pipe; | ||
169 | unsigned int maxp; | ||
170 | char path[PATH_SIZE]; | ||
171 | |||
172 | interface = intf->cur_altsetting; | ||
173 | endpoint = &interface->endpoint[0].desc; | ||
174 | |||
175 | if (!(itmtouch = kcalloc(1, sizeof(struct itmtouch_dev), GFP_KERNEL))) { | ||
176 | err("%s - Out of memory.", __FUNCTION__); | ||
177 | return -ENOMEM; | ||
178 | } | ||
179 | |||
180 | itmtouch->usbdev = udev; | ||
181 | |||
182 | itmtouch->inputdev.private = itmtouch; | ||
183 | itmtouch->inputdev.open = itmtouch_open; | ||
184 | itmtouch->inputdev.close = itmtouch_close; | ||
185 | |||
186 | usb_make_path(udev, path, PATH_SIZE); | ||
187 | |||
188 | itmtouch->inputdev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
189 | itmtouch->inputdev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE); | ||
190 | itmtouch->inputdev.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); | ||
191 | |||
192 | itmtouch->inputdev.name = itmtouch->name; | ||
193 | itmtouch->inputdev.phys = itmtouch->phys; | ||
194 | itmtouch->inputdev.id.bustype = BUS_USB; | ||
195 | itmtouch->inputdev.id.vendor = udev->descriptor.idVendor; | ||
196 | itmtouch->inputdev.id.product = udev->descriptor.idProduct; | ||
197 | itmtouch->inputdev.id.version = udev->descriptor.bcdDevice; | ||
198 | itmtouch->inputdev.dev = &intf->dev; | ||
199 | |||
200 | if (!strlen(itmtouch->name)) | ||
201 | sprintf(itmtouch->name, "USB ITM touchscreen"); | ||
202 | |||
203 | /* device limits */ | ||
204 | /* as specified by the ITM datasheet, X and Y are 12bit, | ||
205 | * Z (pressure) is 8 bit. However, the fields are defined up | ||
206 | * to 14 bits for future possible expansion. | ||
207 | */ | ||
208 | input_set_abs_params(&itmtouch->inputdev, ABS_X, 0, 0x0FFF, 2, 0); | ||
209 | input_set_abs_params(&itmtouch->inputdev, ABS_Y, 0, 0x0FFF, 2, 0); | ||
210 | input_set_abs_params(&itmtouch->inputdev, ABS_PRESSURE, 0, 0xFF, 2, 0); | ||
211 | |||
212 | /* initialise the URB so we can read from the transport stream */ | ||
213 | pipe = usb_rcvintpipe(itmtouch->usbdev, endpoint->bEndpointAddress); | ||
214 | maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); | ||
215 | |||
216 | if (maxp > ITM_BUFSIZE) | ||
217 | maxp = ITM_BUFSIZE; | ||
218 | |||
219 | itmtouch->readurb = usb_alloc_urb(0, GFP_KERNEL); | ||
220 | |||
221 | if (!itmtouch->readurb) { | ||
222 | dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__); | ||
223 | kfree(itmtouch); | ||
224 | return -ENOMEM; | ||
225 | } | ||
226 | |||
227 | usb_fill_int_urb(itmtouch->readurb, | ||
228 | itmtouch->usbdev, | ||
229 | pipe, | ||
230 | itmtouch->rbuf, | ||
231 | maxp, | ||
232 | itmtouch_irq, | ||
233 | itmtouch, | ||
234 | endpoint->bInterval); | ||
235 | |||
236 | input_register_device(&itmtouch->inputdev); | ||
237 | |||
238 | printk(KERN_INFO "itmtouch: %s registered on %s\n", itmtouch->name, path); | ||
239 | usb_set_intfdata(intf, itmtouch); | ||
240 | |||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static void itmtouch_disconnect(struct usb_interface *intf) | ||
245 | { | ||
246 | struct itmtouch_dev *itmtouch = usb_get_intfdata(intf); | ||
247 | |||
248 | usb_set_intfdata(intf, NULL); | ||
249 | |||
250 | if (itmtouch) { | ||
251 | input_unregister_device(&itmtouch->inputdev); | ||
252 | usb_kill_urb(itmtouch->readurb); | ||
253 | usb_free_urb(itmtouch->readurb); | ||
254 | kfree(itmtouch); | ||
255 | } | ||
256 | } | ||
257 | |||
258 | MODULE_DEVICE_TABLE(usb, itmtouch_ids); | ||
259 | |||
260 | static struct usb_driver itmtouch_driver = { | ||
261 | .owner = THIS_MODULE, | ||
262 | .name = "itmtouch", | ||
263 | .probe = itmtouch_probe, | ||
264 | .disconnect = itmtouch_disconnect, | ||
265 | .id_table = itmtouch_ids, | ||
266 | }; | ||
267 | |||
268 | static int __init itmtouch_init(void) | ||
269 | { | ||
270 | info(DRIVER_DESC " " DRIVER_VERSION); | ||
271 | info(DRIVER_AUTHOR); | ||
272 | return usb_register(&itmtouch_driver); | ||
273 | } | ||
274 | |||
275 | static void __exit itmtouch_exit(void) | ||
276 | { | ||
277 | usb_deregister(&itmtouch_driver); | ||
278 | } | ||
279 | |||
280 | module_init(itmtouch_init); | ||
281 | module_exit(itmtouch_exit); | ||