acecad.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * Copyright (c) 2001-2005 Edouard TISSERANT <edouard.tisserant@wanadoo.fr>
  3. * Copyright (c) 2004-2005 Stephane VOLTZ <svoltz@numericable.fr>
  4. *
  5. * USB Acecad "Acecad Flair" tablet support
  6. *
  7. * Changelog:
  8. * v3.2 - Added sysfs support
  9. */
  10. /*
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/input.h>
  29. #include <linux/module.h>
  30. #include <linux/init.h>
  31. #include <linux/usb.h>
  32. /*
  33. * Version Information
  34. */
  35. #define DRIVER_VERSION "v3.2"
  36. #define DRIVER_DESC "USB Acecad Flair tablet driver"
  37. #define DRIVER_LICENSE "GPL"
  38. #define DRIVER_AUTHOR "Edouard TISSERANT <edouard.tisserant@wanadoo.fr>"
  39. MODULE_AUTHOR(DRIVER_AUTHOR);
  40. MODULE_DESCRIPTION(DRIVER_DESC);
  41. MODULE_LICENSE(DRIVER_LICENSE);
  42. #define USB_VENDOR_ID_ACECAD 0x0460
  43. #define USB_DEVICE_ID_FLAIR 0x0004
  44. #define USB_DEVICE_ID_302 0x0008
  45. struct usb_acecad {
  46. char name[128];
  47. char phys[64];
  48. struct usb_device *usbdev;
  49. struct input_dev dev;
  50. struct urb *irq;
  51. signed char *data;
  52. dma_addr_t data_dma;
  53. };
  54. static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
  55. {
  56. struct usb_acecad *acecad = urb->context;
  57. unsigned char *data = acecad->data;
  58. struct input_dev *dev = &acecad->dev;
  59. int prox, status;
  60. switch (urb->status) {
  61. case 0:
  62. /* success */
  63. break;
  64. case -ECONNRESET:
  65. case -ENOENT:
  66. case -ESHUTDOWN:
  67. /* this urb is terminated, clean up */
  68. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  69. return;
  70. default:
  71. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  72. goto resubmit;
  73. }
  74. prox = (data[0] & 0x04) >> 2;
  75. input_report_key(dev, BTN_TOOL_PEN, prox);
  76. if (prox) {
  77. int x = data[1] | (data[2] << 8);
  78. int y = data[3] | (data[4] << 8);
  79. /*Pressure should compute the same way for flair and 302*/
  80. int pressure = data[5] | ((int)data[6] << 8);
  81. int touch = data[0] & 0x01;
  82. int stylus = (data[0] & 0x10) >> 4;
  83. int stylus2 = (data[0] & 0x20) >> 5;
  84. input_report_abs(dev, ABS_X, x);
  85. input_report_abs(dev, ABS_Y, y);
  86. input_report_abs(dev, ABS_PRESSURE, pressure);
  87. input_report_key(dev, BTN_TOUCH, touch);
  88. input_report_key(dev, BTN_STYLUS, stylus);
  89. input_report_key(dev, BTN_STYLUS2, stylus2);
  90. }
  91. /* event termination */
  92. input_sync(dev);
  93. resubmit:
  94. status = usb_submit_urb (urb, GFP_ATOMIC);
  95. if (status)
  96. err ("can't resubmit intr, %s-%s/input0, status %d",
  97. acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status);
  98. }
  99. static int usb_acecad_open(struct input_dev *dev)
  100. {
  101. struct usb_acecad *acecad = dev->private;
  102. acecad->irq->dev = acecad->usbdev;
  103. if (usb_submit_urb(acecad->irq, GFP_KERNEL))
  104. return -EIO;
  105. return 0;
  106. }
  107. static void usb_acecad_close(struct input_dev *dev)
  108. {
  109. struct usb_acecad *acecad = dev->private;
  110. usb_kill_urb(acecad->irq);
  111. }
  112. static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_id *id)
  113. {
  114. struct usb_device *dev = interface_to_usbdev(intf);
  115. struct usb_host_interface *interface = intf->cur_altsetting;
  116. struct usb_endpoint_descriptor *endpoint;
  117. struct usb_acecad *acecad;
  118. int pipe, maxp;
  119. char path[64];
  120. if (interface->desc.bNumEndpoints != 1)
  121. return -ENODEV;
  122. endpoint = &interface->endpoint[0].desc;
  123. if (!(endpoint->bEndpointAddress & 0x80))
  124. return -ENODEV;
  125. if ((endpoint->bmAttributes & 3) != 3)
  126. return -ENODEV;
  127. pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
  128. maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  129. acecad = kcalloc(1, sizeof(struct usb_acecad), GFP_KERNEL);
  130. if (!acecad)
  131. return -ENOMEM;
  132. acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma);
  133. if (!acecad->data)
  134. goto fail1;
  135. acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
  136. if (!acecad->irq)
  137. goto fail2;
  138. if (dev->manufacturer)
  139. strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
  140. if (dev->product) {
  141. if (dev->manufacturer)
  142. strlcat(acecad->name, " ", sizeof(acecad->name));
  143. strlcat(acecad->name, dev->product, sizeof(acecad->name));
  144. }
  145. usb_make_path(dev, path, sizeof(path));
  146. snprintf(acecad->phys, sizeof(acecad->phys), "%s/input0", path);
  147. acecad->usbdev = dev;
  148. acecad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  149. acecad->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
  150. acecad->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
  151. acecad->dev.keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
  152. switch (id->driver_info) {
  153. case 0:
  154. acecad->dev.absmax[ABS_X] = 5000;
  155. acecad->dev.absmax[ABS_Y] = 3750;
  156. acecad->dev.absmax[ABS_PRESSURE] = 512;
  157. if (!strlen(acecad->name))
  158. snprintf(acecad->name, sizeof(acecad->name),
  159. "USB Acecad Flair Tablet %04x:%04x",
  160. dev->descriptor.idVendor, dev->descriptor.idProduct);
  161. break;
  162. case 1:
  163. acecad->dev.absmax[ABS_X] = 3000;
  164. acecad->dev.absmax[ABS_Y] = 2250;
  165. acecad->dev.absmax[ABS_PRESSURE] = 1024;
  166. if (!strlen(acecad->name))
  167. snprintf(acecad->name, sizeof(acecad->name),
  168. "USB Acecad 302 Tablet %04x:%04x",
  169. dev->descriptor.idVendor, dev->descriptor.idProduct);
  170. break;
  171. }
  172. acecad->dev.absfuzz[ABS_X] = 4;
  173. acecad->dev.absfuzz[ABS_Y] = 4;
  174. acecad->dev.private = acecad;
  175. acecad->dev.open = usb_acecad_open;
  176. acecad->dev.close = usb_acecad_close;
  177. acecad->dev.name = acecad->name;
  178. acecad->dev.phys = acecad->phys;
  179. acecad->dev.id.bustype = BUS_USB;
  180. acecad->dev.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
  181. acecad->dev.id.product = le16_to_cpu(dev->descriptor.idProduct);
  182. acecad->dev.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
  183. acecad->dev.dev = &intf->dev;
  184. usb_fill_int_urb(acecad->irq, dev, pipe,
  185. acecad->data, maxp > 8 ? 8 : maxp,
  186. usb_acecad_irq, acecad, endpoint->bInterval);
  187. acecad->irq->transfer_dma = acecad->data_dma;
  188. acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  189. input_register_device(&acecad->dev);
  190. printk(KERN_INFO "input: %s with packet size %d on %s\n",
  191. acecad->name, maxp, path);
  192. usb_set_intfdata(intf, acecad);
  193. return 0;
  194. fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
  195. fail1: kfree(acecad);
  196. return -ENOMEM;
  197. }
  198. static void usb_acecad_disconnect(struct usb_interface *intf)
  199. {
  200. struct usb_acecad *acecad = usb_get_intfdata(intf);
  201. usb_set_intfdata(intf, NULL);
  202. if (acecad) {
  203. usb_kill_urb(acecad->irq);
  204. input_unregister_device(&acecad->dev);
  205. usb_free_urb(acecad->irq);
  206. usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
  207. kfree(acecad);
  208. }
  209. }
  210. static struct usb_device_id usb_acecad_id_table [] = {
  211. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
  212. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
  213. { }
  214. };
  215. MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
  216. static struct usb_driver usb_acecad_driver = {
  217. .owner = THIS_MODULE,
  218. .name = "usb_acecad",
  219. .probe = usb_acecad_probe,
  220. .disconnect = usb_acecad_disconnect,
  221. .id_table = usb_acecad_id_table,
  222. };
  223. static int __init usb_acecad_init(void)
  224. {
  225. int result = usb_register(&usb_acecad_driver);
  226. if (result == 0)
  227. info(DRIVER_VERSION ":" DRIVER_DESC);
  228. return result;
  229. }
  230. static void __exit usb_acecad_exit(void)
  231. {
  232. usb_deregister(&usb_acecad_driver);
  233. }
  234. module_init(usb_acecad_init);
  235. module_exit(usb_acecad_exit);