1 /******************************************************************************
2 * itmtouch.c -- Driver for ITM touchscreen panel
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 Chris Collins <xfire-itmtouch@xware.cx>.
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
24 * It has meant that I've been able to correct my interpretation of the
25 * protocol packets however.
30 * 1.0 & 1.1 2003 (CC) vojtech@suse.cz
31 * Original version for 2.4.x kernels
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.
37 * 1.2.1 09/03/2005 (HCE) hc@mivu.no
38 * Code cleanup and adjusting syntax to start matching kernel standards
40 *****************************************************************************/
42 #include <linux/config.h>
44 #ifdef CONFIG_USB_DEBUG
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>
57 /* only an 8 byte buffer necessary for a single packet */
61 #define USB_VENDOR_ID_ITMINC 0x0403
62 #define USB_PRODUCT_ID_TOUCHPANEL 0xf9e9
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"
69 MODULE_AUTHOR( DRIVER_AUTHOR
);
70 MODULE_DESCRIPTION( DRIVER_DESC
);
71 MODULE_LICENSE( DRIVER_LICENSE
);
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 */
83 static struct usb_device_id itmtouch_ids
[] = {
84 { USB_DEVICE(USB_VENDOR_ID_ITMINC
, USB_PRODUCT_ID_TOUCHPANEL
) },
88 static void itmtouch_irq(struct urb
*urb
, struct pt_regs
*regs
)
90 struct itmtouch_dev
* itmtouch
= urb
->context
;
91 unsigned char *data
= urb
->transfer_buffer
;
92 struct input_dev
*dev
= &itmtouch
->inputdev
;
95 switch (urb
->status
) {
100 /* this urb is timing out */
101 dbg("%s - urb timed out - was the device unplugged?",
107 /* this urb is terminated, clean up */
108 dbg("%s - urb shutting down with status: %d",
109 __FUNCTION__
, urb
->status
);
112 dbg("%s - nonzero urb status received: %d",
113 __FUNCTION__
, urb
->status
);
117 input_regs(dev
, regs
);
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));
125 input_report_abs(dev
, ABS_PRESSURE
, (data
[2] & 1) << 7 | (data
[5] & 0x7F));
126 input_report_key(dev
, BTN_TOUCH
, ~data
[7] & 0x20);
130 retval
= usb_submit_urb (urb
, GFP_ATOMIC
);
132 printk(KERN_ERR
"%s - usb_submit_urb failed with result: %d",
133 __FUNCTION__
, retval
);
136 static int itmtouch_open(struct input_dev
*input
)
138 struct itmtouch_dev
*itmtouch
= input
->private;
140 itmtouch
->readurb
->dev
= itmtouch
->usbdev
;
142 if (usb_submit_urb(itmtouch
->readurb
, GFP_KERNEL
))
148 static void itmtouch_close(struct input_dev
*input
)
150 struct itmtouch_dev
*itmtouch
= input
->private;
152 usb_kill_urb(itmtouch
->readurb
);
155 static int itmtouch_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
157 struct itmtouch_dev
*itmtouch
;
158 struct usb_host_interface
*interface
;
159 struct usb_endpoint_descriptor
*endpoint
;
160 struct usb_device
*udev
= interface_to_usbdev(intf
);
163 char path
[PATH_SIZE
];
165 interface
= intf
->cur_altsetting
;
166 endpoint
= &interface
->endpoint
[0].desc
;
168 if (!(itmtouch
= kcalloc(1, sizeof(struct itmtouch_dev
), GFP_KERNEL
))) {
169 err("%s - Out of memory.", __FUNCTION__
);
173 itmtouch
->usbdev
= udev
;
175 itmtouch
->inputdev
.private = itmtouch
;
176 itmtouch
->inputdev
.open
= itmtouch_open
;
177 itmtouch
->inputdev
.close
= itmtouch_close
;
179 usb_make_path(udev
, path
, PATH_SIZE
);
181 itmtouch
->inputdev
.evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
182 itmtouch
->inputdev
.absbit
[0] = BIT(ABS_X
) | BIT(ABS_Y
) | BIT(ABS_PRESSURE
);
183 itmtouch
->inputdev
.keybit
[LONG(BTN_TOUCH
)] = BIT(BTN_TOUCH
);
185 itmtouch
->inputdev
.name
= itmtouch
->name
;
186 itmtouch
->inputdev
.phys
= itmtouch
->phys
;
187 itmtouch
->inputdev
.id
.bustype
= BUS_USB
;
188 itmtouch
->inputdev
.id
.vendor
= udev
->descriptor
.idVendor
;
189 itmtouch
->inputdev
.id
.product
= udev
->descriptor
.idProduct
;
190 itmtouch
->inputdev
.id
.version
= udev
->descriptor
.bcdDevice
;
191 itmtouch
->inputdev
.dev
= &intf
->dev
;
193 if (!strlen(itmtouch
->name
))
194 sprintf(itmtouch
->name
, "USB ITM touchscreen");
197 /* as specified by the ITM datasheet, X and Y are 12bit,
198 * Z (pressure) is 8 bit. However, the fields are defined up
199 * to 14 bits for future possible expansion.
201 input_set_abs_params(&itmtouch
->inputdev
, ABS_X
, 0, 0x0FFF, 2, 0);
202 input_set_abs_params(&itmtouch
->inputdev
, ABS_Y
, 0, 0x0FFF, 2, 0);
203 input_set_abs_params(&itmtouch
->inputdev
, ABS_PRESSURE
, 0, 0xFF, 2, 0);
205 /* initialise the URB so we can read from the transport stream */
206 pipe
= usb_rcvintpipe(itmtouch
->usbdev
, endpoint
->bEndpointAddress
);
207 maxp
= usb_maxpacket(udev
, pipe
, usb_pipeout(pipe
));
209 if (maxp
> ITM_BUFSIZE
)
212 itmtouch
->readurb
= usb_alloc_urb(0, GFP_KERNEL
);
214 if (!itmtouch
->readurb
) {
215 dbg("%s - usb_alloc_urb failed: itmtouch->readurb", __FUNCTION__
);
220 usb_fill_int_urb(itmtouch
->readurb
, itmtouch
->usbdev
, pipe
, itmtouch
->rbuf
,
221 maxp
, itmtouch_irq
, itmtouch
, endpoint
->bInterval
);
223 input_register_device(&itmtouch
->inputdev
);
225 printk(KERN_INFO
"itmtouch: %s registered on %s\n", itmtouch
->name
, path
);
226 usb_set_intfdata(intf
, itmtouch
);
231 static void itmtouch_disconnect(struct usb_interface
*intf
)
233 struct itmtouch_dev
*itmtouch
= usb_get_intfdata(intf
);
235 usb_set_intfdata(intf
, NULL
);
238 input_unregister_device(&itmtouch
->inputdev
);
239 usb_kill_urb(itmtouch
->readurb
);
240 usb_free_urb(itmtouch
->readurb
);
245 MODULE_DEVICE_TABLE(usb
, itmtouch_ids
);
247 static struct usb_driver itmtouch_driver
= {
248 .owner
= THIS_MODULE
,
250 .probe
= itmtouch_probe
,
251 .disconnect
= itmtouch_disconnect
,
252 .id_table
= itmtouch_ids
,
255 static int __init
itmtouch_init(void)
257 info(DRIVER_DESC
" " DRIVER_VERSION
);
259 return usb_register(&itmtouch_driver
);
262 static void __exit
itmtouch_exit(void)
264 usb_deregister(&itmtouch_driver
);
267 module_init(itmtouch_init
);
268 module_exit(itmtouch_exit
);