aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/input/mtouchusb.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/input/mtouchusb.c')
-rw-r--r--drivers/usb/input/mtouchusb.c415
1 files changed, 201 insertions, 214 deletions
diff --git a/drivers/usb/input/mtouchusb.c b/drivers/usb/input/mtouchusb.c
index ab1a2a30ce7c..ec1dd6278f7b 100644
--- a/drivers/usb/input/mtouchusb.c
+++ b/drivers/usb/input/mtouchusb.c
@@ -42,9 +42,9 @@
42#include <linux/config.h> 42#include <linux/config.h>
43 43
44#ifdef CONFIG_USB_DEBUG 44#ifdef CONFIG_USB_DEBUG
45 #define DEBUG 45 #define DEBUG
46#else 46#else
47 #undef DEBUG 47 #undef DEBUG
48#endif 48#endif
49 49
50#include <linux/kernel.h> 50#include <linux/kernel.h>
@@ -93,275 +93,262 @@ module_param(raw_coordinates, bool, S_IRUGO | S_IWUSR);
93MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)"); 93MODULE_PARM_DESC(raw_coordinates, "report raw coordinate values (y, default) or hardware-calibrated coordinate values (n)");
94 94
95struct mtouch_usb { 95struct mtouch_usb {
96 unsigned char *data; 96 unsigned char *data;
97 dma_addr_t data_dma; 97 dma_addr_t data_dma;
98 struct urb *irq; 98 struct urb *irq;
99 struct usb_device *udev; 99 struct usb_device *udev;
100 struct input_dev input; 100 struct input_dev input;
101 int open; 101 int open;
102 char name[128]; 102 char name[128];
103 char phys[64]; 103 char phys[64];
104}; 104};
105 105
106static struct usb_device_id mtouchusb_devices [] = { 106static struct usb_device_id mtouchusb_devices[] = {
107 { USB_DEVICE(0x0596, 0x0001) }, 107 { USB_DEVICE(0x0596, 0x0001) },
108 { } 108 { }
109}; 109};
110 110
111static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs) 111static void mtouchusb_irq(struct urb *urb, struct pt_regs *regs)
112{ 112{
113 struct mtouch_usb *mtouch = urb->context; 113 struct mtouch_usb *mtouch = urb->context;
114 int retval; 114 int retval;
115 115
116 switch (urb->status) { 116 switch (urb->status) {
117 case 0: 117 case 0:
118 /* success */ 118 /* success */
119 break; 119 break;
120 case -ETIMEDOUT: 120 case -ETIMEDOUT:
121 /* this urb is timing out */ 121 /* this urb is timing out */
122 dbg("%s - urb timed out - was the device unplugged?", 122 dbg("%s - urb timed out - was the device unplugged?",
123 __FUNCTION__); 123 __FUNCTION__);
124 return; 124 return;
125 case -ECONNRESET: 125 case -ECONNRESET:
126 case -ENOENT: 126 case -ENOENT:
127 case -ESHUTDOWN: 127 case -ESHUTDOWN:
128 /* this urb is terminated, clean up */ 128 /* this urb is terminated, clean up */
129 dbg("%s - urb shutting down with status: %d", 129 dbg("%s - urb shutting down with status: %d",
130 __FUNCTION__, urb->status); 130 __FUNCTION__, urb->status);
131 return; 131 return;
132 default: 132 default:
133 dbg("%s - nonzero urb status received: %d", 133 dbg("%s - nonzero urb status received: %d",
134 __FUNCTION__, urb->status); 134 __FUNCTION__, urb->status);
135 goto exit; 135 goto exit;
136 } 136 }
137 137
138 input_regs(&mtouch->input, regs); 138 input_regs(&mtouch->input, regs);
139 input_report_key(&mtouch->input, BTN_TOUCH, 139 input_report_key(&mtouch->input, BTN_TOUCH,
140 MTOUCHUSB_GET_TOUCHED(mtouch->data)); 140 MTOUCHUSB_GET_TOUCHED(mtouch->data));
141 input_report_abs(&mtouch->input, ABS_X, 141 input_report_abs(&mtouch->input, ABS_X, MTOUCHUSB_GET_XC(mtouch->data));
142 MTOUCHUSB_GET_XC(mtouch->data)); 142 input_report_abs(&mtouch->input, ABS_Y,
143 input_report_abs(&mtouch->input, ABS_Y,
144 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC) 143 (raw_coordinates ? MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC)
145 - MTOUCHUSB_GET_YC(mtouch->data)); 144 - MTOUCHUSB_GET_YC(mtouch->data));
146 input_sync(&mtouch->input); 145 input_sync(&mtouch->input);
147 146
148exit: 147exit:
149 retval = usb_submit_urb (urb, GFP_ATOMIC); 148 retval = usb_submit_urb(urb, GFP_ATOMIC);
150 if (retval) 149 if (retval)
151 err ("%s - usb_submit_urb failed with result: %d", 150 err("%s - usb_submit_urb failed with result: %d",
152 __FUNCTION__, retval); 151 __FUNCTION__, retval);
153} 152}
154 153
155static int mtouchusb_open (struct input_dev *input) 154static int mtouchusb_open(struct input_dev *input)
156{ 155{
157 struct mtouch_usb *mtouch = input->private; 156 struct mtouch_usb *mtouch = input->private;
158 157
159 if (mtouch->open++) 158 if (mtouch->open++)
160 return 0; 159 return 0;
161 160
162 mtouch->irq->dev = mtouch->udev; 161 mtouch->irq->dev = mtouch->udev;
163 162
164 if (usb_submit_urb (mtouch->irq, GFP_ATOMIC)) { 163 if (usb_submit_urb(mtouch->irq, GFP_ATOMIC)) {
165 mtouch->open--; 164 mtouch->open--;
166 return -EIO; 165 return -EIO;
167 } 166 }
168 167
169 return 0; 168 return 0;
170} 169}
171 170
172static void mtouchusb_close (struct input_dev *input) 171static void mtouchusb_close(struct input_dev *input)
173{ 172{
174 struct mtouch_usb *mtouch = input->private; 173 struct mtouch_usb *mtouch = input->private;
175 174
176 if (!--mtouch->open) 175 if (!--mtouch->open)
177 usb_kill_urb (mtouch->irq); 176 usb_kill_urb(mtouch->irq);
178} 177}
179 178
180static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) 179static int mtouchusb_alloc_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
181{ 180{
182 dbg("%s - called", __FUNCTION__); 181 dbg("%s - called", __FUNCTION__);
183 182
184 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE, 183 mtouch->data = usb_buffer_alloc(udev, MTOUCHUSB_REPORT_DATA_SIZE,
185 SLAB_ATOMIC, &mtouch->data_dma); 184 SLAB_ATOMIC, &mtouch->data_dma);
186 185
187 if (!mtouch->data) 186 if (!mtouch->data)
188 return -1; 187 return -1;
189 188
190 return 0; 189 return 0;
191} 190}
192 191
193static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch) 192static void mtouchusb_free_buffers(struct usb_device *udev, struct mtouch_usb *mtouch)
194{ 193{
195 dbg("%s - called", __FUNCTION__); 194 dbg("%s - called", __FUNCTION__);
196 195
197 if (mtouch->data) 196 if (mtouch->data)
198 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE, 197 usb_buffer_free(udev, MTOUCHUSB_REPORT_DATA_SIZE,
199 mtouch->data, mtouch->data_dma); 198 mtouch->data, mtouch->data_dma);
200} 199}
201 200
202static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 201static int mtouchusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
203{ 202{
204 struct mtouch_usb *mtouch; 203 struct mtouch_usb *mtouch;
205 struct usb_host_interface *interface; 204 struct usb_host_interface *interface;
206 struct usb_endpoint_descriptor *endpoint; 205 struct usb_endpoint_descriptor *endpoint;
207 struct usb_device *udev = interface_to_usbdev (intf); 206 struct usb_device *udev = interface_to_usbdev(intf);
208 char path[64]; 207 char path[64];
209 int nRet; 208 int nRet;
210 209
211 dbg("%s - called", __FUNCTION__); 210 dbg("%s - called", __FUNCTION__);
212 211
213 dbg("%s - setting interface", __FUNCTION__); 212 dbg("%s - setting interface", __FUNCTION__);
214 interface = intf->cur_altsetting; 213 interface = intf->cur_altsetting;
215 214
216 dbg("%s - setting endpoint", __FUNCTION__); 215 dbg("%s - setting endpoint", __FUNCTION__);
217 endpoint = &interface->endpoint[0].desc; 216 endpoint = &interface->endpoint[0].desc;
218 217
219 if (!(mtouch = kmalloc (sizeof (struct mtouch_usb), GFP_KERNEL))) { 218 if (!(mtouch = kmalloc(sizeof(struct mtouch_usb), GFP_KERNEL))) {
220 err("%s - Out of memory.", __FUNCTION__); 219 err("%s - Out of memory.", __FUNCTION__);
221 return -ENOMEM; 220 return -ENOMEM;
222 } 221 }
223 222
224 memset(mtouch, 0, sizeof(struct mtouch_usb)); 223 memset(mtouch, 0, sizeof(struct mtouch_usb));
225 mtouch->udev = udev; 224 mtouch->udev = udev;
226 225
227 dbg("%s - allocating buffers", __FUNCTION__); 226 dbg("%s - allocating buffers", __FUNCTION__);
228 if (mtouchusb_alloc_buffers(udev, mtouch)) { 227 if (mtouchusb_alloc_buffers(udev, mtouch)) {
229 mtouchusb_free_buffers(udev, mtouch); 228 mtouchusb_free_buffers(udev, mtouch);
230 kfree(mtouch); 229 kfree(mtouch);
231 return -ENOMEM; 230 return -ENOMEM;
232 } 231 }
233 232
234 mtouch->input.private = mtouch; 233 mtouch->input.private = mtouch;
235 mtouch->input.open = mtouchusb_open; 234 mtouch->input.open = mtouchusb_open;
236 mtouch->input.close = mtouchusb_close; 235 mtouch->input.close = mtouchusb_close;
237 236
238 usb_make_path(udev, path, 64); 237 usb_make_path(udev, path, 64);
239 sprintf(mtouch->phys, "%s/input0", path); 238 sprintf(mtouch->phys, "%s/input0", path);
240 239
241 mtouch->input.name = mtouch->name; 240 mtouch->input.name = mtouch->name;
242 mtouch->input.phys = mtouch->phys; 241 mtouch->input.phys = mtouch->phys;
243 mtouch->input.id.bustype = BUS_USB; 242 mtouch->input.id.bustype = BUS_USB;
244 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor); 243 mtouch->input.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
245 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct); 244 mtouch->input.id.product = le16_to_cpu(udev->descriptor.idProduct);
246 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice); 245 mtouch->input.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
247 mtouch->input.dev = &intf->dev; 246 mtouch->input.dev = &intf->dev;
248 247
249 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 248 mtouch->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
250 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y); 249 mtouch->input.absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
251 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 250 mtouch->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
252 251
253 /* Used to Scale Compensated Data and Flip Y */ 252 /* Used to Scale Compensated Data and Flip Y */
254 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC; 253 mtouch->input.absmin[ABS_X] = MTOUCHUSB_MIN_XC;
255 mtouch->input.absmax[ABS_X] = raw_coordinates ? \ 254 mtouch->input.absmax[ABS_X] = raw_coordinates ?
256 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC; 255 MTOUCHUSB_MAX_RAW_XC : MTOUCHUSB_MAX_CALIB_XC;
257 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ; 256 mtouch->input.absfuzz[ABS_X] = MTOUCHUSB_XC_FUZZ;
258 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT; 257 mtouch->input.absflat[ABS_X] = MTOUCHUSB_XC_FLAT;
259 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC; 258 mtouch->input.absmin[ABS_Y] = MTOUCHUSB_MIN_YC;
260 mtouch->input.absmax[ABS_Y] = raw_coordinates ? \ 259 mtouch->input.absmax[ABS_Y] = raw_coordinates ?
261 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC; 260 MTOUCHUSB_MAX_RAW_YC : MTOUCHUSB_MAX_CALIB_YC;
262 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ; 261 mtouch->input.absfuzz[ABS_Y] = MTOUCHUSB_YC_FUZZ;
263 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT; 262 mtouch->input.absflat[ABS_Y] = MTOUCHUSB_YC_FLAT;
264 263
265 if (udev->manufacturer) 264 if (udev->manufacturer)
266 strcat(mtouch->name, udev->manufacturer); 265 strcat(mtouch->name, udev->manufacturer);
267 if (udev->product) 266 if (udev->product)
268 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product); 267 sprintf(mtouch->name, "%s %s", mtouch->name, udev->product);
269 268
270 if (!strlen(mtouch->name)) 269 if (!strlen(mtouch->name))
271 sprintf(mtouch->name, "USB Touchscreen %04x:%04x", 270 sprintf(mtouch->name, "USB Touchscreen %04x:%04x",
272 mtouch->input.id.vendor, mtouch->input.id.product); 271 mtouch->input.id.vendor, mtouch->input.id.product);
273 272
274 nRet = usb_control_msg(mtouch->udev, 273 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
275 usb_rcvctrlpipe(udev, 0), 274 MTOUCHUSB_RESET,
276 MTOUCHUSB_RESET, 275 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
277 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 276 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
278 1, 277 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
279 0, 278 __FUNCTION__, nRet);
280 NULL, 279
281 0, 280 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__);
282 USB_CTRL_SET_TIMEOUT); 281 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
283 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d", 282 if (!mtouch->irq) {
284 __FUNCTION__, nRet); 283 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__);
285 284 mtouchusb_free_buffers(udev, mtouch);
286 dbg("%s - usb_alloc_urb: mtouch->irq", __FUNCTION__); 285 kfree(mtouch);
287 mtouch->irq = usb_alloc_urb(0, GFP_KERNEL); 286 return -ENOMEM;
288 if (!mtouch->irq) { 287 }
289 dbg("%s - usb_alloc_urb failed: mtouch->irq", __FUNCTION__); 288
290 mtouchusb_free_buffers(udev, mtouch); 289 dbg("%s - usb_fill_int_urb", __FUNCTION__);
291 kfree(mtouch); 290 usb_fill_int_urb(mtouch->irq, mtouch->udev,
292 return -ENOMEM; 291 usb_rcvintpipe(mtouch->udev, 0x81),
293 } 292 mtouch->data, MTOUCHUSB_REPORT_DATA_SIZE,
294 293 mtouchusb_irq, mtouch, endpoint->bInterval);
295 dbg("%s - usb_fill_int_urb", __FUNCTION__); 294
296 usb_fill_int_urb(mtouch->irq, 295 dbg("%s - input_register_device", __FUNCTION__);
297 mtouch->udev, 296 input_register_device(&mtouch->input);
298 usb_rcvintpipe(mtouch->udev, 0x81), 297
299 mtouch->data, 298 nRet = usb_control_msg(mtouch->udev, usb_rcvctrlpipe(udev, 0),
300 MTOUCHUSB_REPORT_DATA_SIZE, 299 MTOUCHUSB_ASYNC_REPORT,
301 mtouchusb_irq, 300 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
302 mtouch, 301 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
303 endpoint->bInterval); 302 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
304 303 __FUNCTION__, nRet);
305 dbg("%s - input_register_device", __FUNCTION__); 304
306 input_register_device(&mtouch->input); 305 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
307 306 usb_set_intfdata(intf, mtouch);
308 nRet = usb_control_msg(mtouch->udev, 307
309 usb_rcvctrlpipe(udev, 0), 308 return 0;
310 MTOUCHUSB_ASYNC_REPORT,
311 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
312 1,
313 1,
314 NULL,
315 0,
316 USB_CTRL_SET_TIMEOUT);
317 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
318 __FUNCTION__, nRet);
319
320 printk(KERN_INFO "input: %s on %s\n", mtouch->name, path);
321 usb_set_intfdata(intf, mtouch);
322
323 return 0;
324} 309}
325 310
326static void mtouchusb_disconnect(struct usb_interface *intf) 311static void mtouchusb_disconnect(struct usb_interface *intf)
327{ 312{
328 struct mtouch_usb *mtouch = usb_get_intfdata (intf); 313 struct mtouch_usb *mtouch = usb_get_intfdata(intf);
329 314
330 dbg("%s - called", __FUNCTION__); 315 dbg("%s - called", __FUNCTION__);
331 usb_set_intfdata(intf, NULL); 316 usb_set_intfdata(intf, NULL);
332 if (mtouch) { 317 if (mtouch) {
333 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__); 318 dbg("%s - mtouch is initialized, cleaning up", __FUNCTION__);
334 usb_kill_urb(mtouch->irq); 319 usb_kill_urb(mtouch->irq);
335 input_unregister_device(&mtouch->input); 320 input_unregister_device(&mtouch->input);
336 usb_free_urb(mtouch->irq); 321 usb_free_urb(mtouch->irq);
337 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch); 322 mtouchusb_free_buffers(interface_to_usbdev(intf), mtouch);
338 kfree(mtouch); 323 kfree(mtouch);
339 } 324 }
340} 325}
341 326
342MODULE_DEVICE_TABLE (usb, mtouchusb_devices); 327MODULE_DEVICE_TABLE(usb, mtouchusb_devices);
343 328
344static struct usb_driver mtouchusb_driver = { 329static struct usb_driver mtouchusb_driver = {
345 .owner = THIS_MODULE, 330 .owner = THIS_MODULE,
346 .name = "mtouchusb", 331 .name = "mtouchusb",
347 .probe = mtouchusb_probe, 332 .probe = mtouchusb_probe,
348 .disconnect = mtouchusb_disconnect, 333 .disconnect = mtouchusb_disconnect,
349 .id_table = mtouchusb_devices, 334 .id_table = mtouchusb_devices,
350}; 335};
351 336
352static int __init mtouchusb_init(void) { 337static int __init mtouchusb_init(void)
353 dbg("%s - called", __FUNCTION__); 338{
354 return usb_register(&mtouchusb_driver); 339 dbg("%s - called", __FUNCTION__);
340 return usb_register(&mtouchusb_driver);
355} 341}
356 342
357static void __exit mtouchusb_cleanup(void) { 343static void __exit mtouchusb_cleanup(void)
358 dbg("%s - called", __FUNCTION__); 344{
359 usb_deregister(&mtouchusb_driver); 345 dbg("%s - called", __FUNCTION__);
346 usb_deregister(&mtouchusb_driver);
360} 347}
361 348
362module_init(mtouchusb_init); 349module_init(mtouchusb_init);
363module_exit(mtouchusb_cleanup); 350module_exit(mtouchusb_cleanup);
364 351
365MODULE_AUTHOR( DRIVER_AUTHOR ); 352MODULE_AUTHOR(DRIVER_AUTHOR);
366MODULE_DESCRIPTION( DRIVER_DESC ); 353MODULE_DESCRIPTION(DRIVER_DESC);
367MODULE_LICENSE("GPL"); 354MODULE_LICENSE("GPL");