1 /******************************************************************************
2 * mtouchusb.c -- Driver for Microtouch (Now 3M) USB Touchscreens
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.
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.
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.
18 * Based upon original work by Radoslaw Garbacz (usb-support@ite.pl)
19 * (http://freshmeat.net/projects/3mtouchscreendriver)
23 * 0.3 & 0.4 2002 (TEJ) tejohnson@yahoo.com
24 * Updated to 2.4.18, then 2.4.19
25 * Old version still relied on stealing a minor
27 * 0.5 02/26/2004 (TEJ) tejohnson@yahoo.com
28 * Complete rewrite using Linux Input in 2.6.3
29 * Unfortunately no calibration support at this time
31 * 1.4 04/25/2004 (TEJ) tejohnson@yahoo.com
32 * Changed reset from standard USB dev reset to vendor reset
33 * Changed data sent to host from compensated to raw coordinates
34 * Eliminated vendor/product module params
35 * Performed multiple successfull tests with an EXII-5010UC
37 *****************************************************************************/
39 #include <linux/config.h>
41 #ifdef CONFIG_USB_DEBUG
47 #include <linux/kernel.h>
48 #include <linux/slab.h>
49 #include <linux/input.h>
50 #include <linux/module.h>
51 #include <linux/init.h>
52 #include <linux/usb.h>
54 #define MTOUCHUSB_MIN_XC 0x0
55 #define MTOUCHUSB_MAX_XC 0x4000
56 #define MTOUCHUSB_XC_FUZZ 0x0
57 #define MTOUCHUSB_XC_FLAT 0x0
58 #define MTOUCHUSB_MIN_YC 0x0
59 #define MTOUCHUSB_MAX_YC 0x4000
60 #define MTOUCHUSB_YC_FUZZ 0x0
61 #define MTOUCHUSB_YC_FLAT 0x0
63 #define MTOUCHUSB_ASYNC_REPORT 1
64 #define MTOUCHUSB_RESET 7
65 #define MTOUCHUSB_REPORT_DATA_SIZE 11
66 #define MTOUCHUSB_REQ_CTRLLR_ID 10
68 #define MTOUCHUSB_GET_XC(data) (data[8]<<8 | data[7])
69 #define MTOUCHUSB_GET_YC(data) (data[10]<<8 | data[9])
70 #define MTOUCHUSB_GET_TOUCHED(data) ((data[2] & 0x40) ? 1:0)
72 #define DRIVER_VERSION "v1.4"
73 #define DRIVER_AUTHOR "Todd E. Johnson, tejohnson@yahoo.com"
74 #define DRIVER_DESC "3M USB Touchscreen Driver"
75 #define DRIVER_LICENSE "GPL"
81 struct usb_device
*udev
;
82 struct input_dev input
;
88 static struct usb_device_id mtouchusb_devices
[] = {
89 { USB_DEVICE(0x0596, 0x0001) },
93 static void mtouchusb_irq(struct urb
*urb
, struct pt_regs
*regs
)
95 struct mtouch_usb
*mtouch
= urb
->context
;
98 switch (urb
->status
) {
103 /* this urb is timing out */
104 dbg("%s - urb timed out - was the device unplugged?",
110 /* this urb is terminated, clean up */
111 dbg("%s - urb shutting down with status: %d",
112 __FUNCTION__
, urb
->status
);
115 dbg("%s - nonzero urb status received: %d",
116 __FUNCTION__
, urb
->status
);
120 input_regs(&mtouch
->input
, regs
);
121 input_report_key(&mtouch
->input
, BTN_TOUCH
,
122 MTOUCHUSB_GET_TOUCHED(mtouch
->data
));
123 input_report_abs(&mtouch
->input
, ABS_X
,
124 MTOUCHUSB_GET_XC(mtouch
->data
));
125 input_report_abs(&mtouch
->input
, ABS_Y
,
126 MTOUCHUSB_GET_YC(mtouch
->data
));
127 input_sync(&mtouch
->input
);
130 retval
= usb_submit_urb (urb
, GFP_ATOMIC
);
132 err ("%s - usb_submit_urb failed with result: %d",
133 __FUNCTION__
, retval
);
136 static int mtouchusb_open (struct input_dev
*input
)
138 struct mtouch_usb
*mtouch
= input
->private;
143 mtouch
->irq
->dev
= mtouch
->udev
;
145 if (usb_submit_urb (mtouch
->irq
, GFP_ATOMIC
)) {
153 static void mtouchusb_close (struct input_dev
*input
)
155 struct mtouch_usb
*mtouch
= input
->private;
158 usb_unlink_urb (mtouch
->irq
);
161 static int mtouchusb_alloc_buffers(struct usb_device
*udev
, struct mtouch_usb
*mtouch
)
163 dbg("%s - called", __FUNCTION__
);
165 mtouch
->data
= usb_buffer_alloc(udev
, MTOUCHUSB_REPORT_DATA_SIZE
,
166 SLAB_ATOMIC
, &mtouch
->data_dma
);
174 static void mtouchusb_free_buffers(struct usb_device
*udev
, struct mtouch_usb
*mtouch
)
176 dbg("%s - called", __FUNCTION__
);
179 usb_buffer_free(udev
, MTOUCHUSB_REPORT_DATA_SIZE
,
180 mtouch
->data
, mtouch
->data_dma
);
183 static int mtouchusb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
185 struct mtouch_usb
*mtouch
;
186 struct usb_host_interface
*interface
;
187 struct usb_endpoint_descriptor
*endpoint
;
188 struct usb_device
*udev
= interface_to_usbdev (intf
);
193 dbg("%s - called", __FUNCTION__
);
195 dbg("%s - setting interface", __FUNCTION__
);
196 interface
= intf
->cur_altsetting
;
198 dbg("%s - setting endpoint", __FUNCTION__
);
199 endpoint
= &interface
->endpoint
[0].desc
;
201 if (!(mtouch
= kmalloc (sizeof (struct mtouch_usb
), GFP_KERNEL
))) {
202 err("%s - Out of memory.", __FUNCTION__
);
206 memset(mtouch
, 0, sizeof(struct mtouch_usb
));
209 dbg("%s - allocating buffers", __FUNCTION__
);
210 if (mtouchusb_alloc_buffers(udev
, mtouch
)) {
211 mtouchusb_free_buffers(udev
, mtouch
);
216 mtouch
->input
.private = mtouch
;
217 mtouch
->input
.open
= mtouchusb_open
;
218 mtouch
->input
.close
= mtouchusb_close
;
220 usb_make_path(udev
, path
, 64);
221 sprintf(mtouch
->phys
, "%s/input0", path
);
223 mtouch
->input
.name
= mtouch
->name
;
224 mtouch
->input
.phys
= mtouch
->phys
;
225 mtouch
->input
.id
.bustype
= BUS_USB
;
226 mtouch
->input
.id
.vendor
= udev
->descriptor
.idVendor
;
227 mtouch
->input
.id
.product
= udev
->descriptor
.idProduct
;
228 mtouch
->input
.id
.version
= udev
->descriptor
.bcdDevice
;
229 mtouch
->input
.dev
= &intf
->dev
;
231 mtouch
->input
.evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
232 mtouch
->input
.absbit
[0] = BIT(ABS_X
) | BIT(ABS_Y
);
233 mtouch
->input
.keybit
[LONG(BTN_TOUCH
)] = BIT(BTN_TOUCH
);
235 /* Used to Scale Compensated Data and Flip Y */
236 mtouch
->input
.absmin
[ABS_X
] = MTOUCHUSB_MIN_XC
;
237 mtouch
->input
.absmax
[ABS_X
] = MTOUCHUSB_MAX_XC
;
238 mtouch
->input
.absfuzz
[ABS_X
] = MTOUCHUSB_XC_FUZZ
;
239 mtouch
->input
.absflat
[ABS_X
] = MTOUCHUSB_XC_FLAT
;
240 mtouch
->input
.absmin
[ABS_Y
] = MTOUCHUSB_MIN_YC
;
241 mtouch
->input
.absmax
[ABS_Y
] = MTOUCHUSB_MAX_YC
;
242 mtouch
->input
.absfuzz
[ABS_Y
] = MTOUCHUSB_YC_FUZZ
;
243 mtouch
->input
.absflat
[ABS_Y
] = MTOUCHUSB_YC_FLAT
;
245 if (!(buf
= kmalloc(63, GFP_KERNEL
))) {
250 if (udev
->descriptor
.iManufacturer
&&
251 usb_string(udev
, udev
->descriptor
.iManufacturer
, buf
, 63) > 0)
252 strcat(mtouch
->name
, buf
);
253 if (udev
->descriptor
.iProduct
&&
254 usb_string(udev
, udev
->descriptor
.iProduct
, buf
, 63) > 0)
255 sprintf(mtouch
->name
, "%s %s", mtouch
->name
, buf
);
257 if (!strlen(mtouch
->name
))
258 sprintf(mtouch
->name
, "USB Touchscreen %04x:%04x",
259 mtouch
->input
.id
.vendor
, mtouch
->input
.id
.product
);
263 nRet
= usb_control_msg(mtouch
->udev
,
264 usb_rcvctrlpipe(udev
, 0),
266 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
271 HZ
* USB_CTRL_SET_TIMEOUT
);
272 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
275 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__
);
276 mtouch
->irq
= usb_alloc_urb(0, GFP_KERNEL
);
278 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__
);
279 mtouchusb_free_buffers(udev
, mtouch
);
284 dbg("%s - usb_fill_int_urb", __FUNCTION__
);
285 usb_fill_int_urb(mtouch
->irq
,
287 usb_rcvintpipe(mtouch
->udev
, 0x81),
289 MTOUCHUSB_REPORT_DATA_SIZE
,
292 endpoint
->bInterval
);
294 dbg("%s - input_register_device", __FUNCTION__
);
295 input_register_device(&mtouch
->input
);
297 nRet
= usb_control_msg(mtouch
->udev
,
298 usb_rcvctrlpipe(udev
, 0),
299 MTOUCHUSB_ASYNC_REPORT
,
300 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
305 HZ
* USB_CTRL_SET_TIMEOUT
);
306 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
309 printk(KERN_INFO
"input: %s on %s\n", mtouch
->name
, path
);
310 usb_set_intfdata(intf
, mtouch
);
315 static void mtouchusb_disconnect(struct usb_interface
*intf
)
317 struct mtouch_usb
*mtouch
= usb_get_intfdata (intf
);
319 dbg("%s - called", __FUNCTION__
);
320 usb_set_intfdata(intf
, NULL
);
322 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__
);
323 usb_unlink_urb(mtouch
->irq
);
324 input_unregister_device(&mtouch
->input
);
325 usb_free_urb(mtouch
->irq
);
326 mtouchusb_free_buffers(interface_to_usbdev(intf
), mtouch
);
331 MODULE_DEVICE_TABLE (usb
, mtouchusb_devices
);
333 static struct usb_driver mtouchusb_driver
= {
334 .owner
= THIS_MODULE
,
336 .probe
= mtouchusb_probe
,
337 .disconnect
= mtouchusb_disconnect
,
338 .id_table
= mtouchusb_devices
,
341 static int __init
mtouchusb_init(void) {
342 dbg("%s - called", __FUNCTION__
);
343 return usb_register(&mtouchusb_driver
);
346 static void __exit
mtouchusb_cleanup(void) {
347 dbg("%s - called", __FUNCTION__
);
348 usb_deregister(&mtouchusb_driver
);
351 module_init(mtouchusb_init
);
352 module_exit(mtouchusb_cleanup
);
354 MODULE_AUTHOR( DRIVER_AUTHOR
);
355 MODULE_DESCRIPTION( DRIVER_DESC
);
356 MODULE_LICENSE("GPL");