acecad.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. #include <linux/usb_input.h>
  33. /*
  34. * Version Information
  35. */
  36. #define DRIVER_VERSION "v3.2"
  37. #define DRIVER_DESC "USB Acecad Flair tablet driver"
  38. #define DRIVER_LICENSE "GPL"
  39. #define DRIVER_AUTHOR "Edouard TISSERANT <edouard.tisserant@wanadoo.fr>"
  40. MODULE_AUTHOR(DRIVER_AUTHOR);
  41. MODULE_DESCRIPTION(DRIVER_DESC);
  42. MODULE_LICENSE(DRIVER_LICENSE);
  43. #define USB_VENDOR_ID_ACECAD 0x0460
  44. #define USB_DEVICE_ID_FLAIR 0x0004
  45. #define USB_DEVICE_ID_302 0x0008
  46. struct usb_acecad {
  47. char name[128];
  48. char phys[64];
  49. struct usb_device *usbdev;
  50. struct input_dev dev;
  51. struct urb *irq;
  52. signed char *data;
  53. dma_addr_t data_dma;
  54. };
  55. static void usb_acecad_irq(struct urb *urb, struct pt_regs *regs)
  56. {
  57. struct usb_acecad *acecad = urb->context;
  58. unsigned char *data = acecad->data;
  59. struct input_dev *dev = &acecad->dev;
  60. int prox, status;
  61. switch (urb->status) {
  62. case 0:
  63. /* success */
  64. break;
  65. case -ECONNRESET:
  66. case -ENOENT:
  67. case -ESHUTDOWN:
  68. /* this urb is terminated, clean up */
  69. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  70. return;
  71. default:
  72. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  73. goto resubmit;
  74. }
  75. prox = (data[0] & 0x04) >> 2;
  76. input_report_key(dev, BTN_TOOL_PEN, prox);
  77. if (prox) {
  78. int x = data[1] | (data[2] << 8);
  79. int y = data[3] | (data[4] << 8);
  80. /* Pressure should compute the same way for flair and 302 */
  81. int pressure = data[5] | (data[6] << 8);
  82. int touch = data[0] & 0x01;
  83. int stylus = (data[0] & 0x10) >> 4;
  84. int stylus2 = (data[0] & 0x20) >> 5;
  85. input_report_abs(dev, ABS_X, x);
  86. input_report_abs(dev, ABS_Y, y);
  87. input_report_abs(dev, ABS_PRESSURE, pressure);
  88. input_report_key(dev, BTN_TOUCH, touch);
  89. input_report_key(dev, BTN_STYLUS, stylus);
  90. input_report_key(dev, BTN_STYLUS2, stylus2);
  91. }
  92. /* event termination */
  93. input_sync(dev);
  94. resubmit:
  95. status = usb_submit_urb(urb, GFP_ATOMIC);
  96. if (status)
  97. err("can't resubmit intr, %s-%s/input0, status %d",
  98. acecad->usbdev->bus->bus_name, acecad->usbdev->devpath, status);
  99. }
  100. static int usb_acecad_open(struct input_dev *dev)
  101. {
  102. struct usb_acecad *acecad = dev->private;
  103. acecad->irq->dev = acecad->usbdev;
  104. if (usb_submit_urb(acecad->irq, GFP_KERNEL))
  105. return -EIO;
  106. return 0;
  107. }
  108. static void usb_acecad_close(struct input_dev *dev)
  109. {
  110. struct usb_acecad *acecad = dev->private;
  111. usb_kill_urb(acecad->irq);
  112. }
  113. static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_id *id)
  114. {
  115. struct usb_device *dev = interface_to_usbdev(intf);
  116. struct usb_host_interface *interface = intf->cur_altsetting;
  117. struct usb_endpoint_descriptor *endpoint;
  118. struct usb_acecad *acecad;
  119. int pipe, maxp;
  120. char path[64];
  121. if (interface->desc.bNumEndpoints != 1)
  122. return -ENODEV;
  123. endpoint = &interface->endpoint[0].desc;
  124. if (!(endpoint->bEndpointAddress & 0x80))
  125. return -ENODEV;
  126. if ((endpoint->bmAttributes & 3) != 3)
  127. return -ENODEV;
  128. pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
  129. maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  130. acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL);
  131. if (!acecad)
  132. return -ENOMEM;
  133. acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma);
  134. if (!acecad->data)
  135. goto fail1;
  136. acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
  137. if (!acecad->irq)
  138. goto fail2;
  139. if (dev->manufacturer)
  140. strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
  141. if (dev->product) {
  142. if (dev->manufacturer)
  143. strlcat(acecad->name, " ", sizeof(acecad->name));
  144. strlcat(acecad->name, dev->product, sizeof(acecad->name));
  145. }
  146. usb_make_path(dev, path, sizeof(path));
  147. snprintf(acecad->phys, sizeof(acecad->phys), "%s/input0", path);
  148. acecad->usbdev = dev;
  149. acecad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  150. acecad->dev.absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
  151. acecad->dev.keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
  152. acecad->dev.keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
  153. switch (id->driver_info) {
  154. case 0:
  155. acecad->dev.absmax[ABS_X] = 5000;
  156. acecad->dev.absmax[ABS_Y] = 3750;
  157. acecad->dev.absmax[ABS_PRESSURE] = 512;
  158. if (!strlen(acecad->name))
  159. snprintf(acecad->name, sizeof(acecad->name),
  160. "USB Acecad Flair Tablet %04x:%04x",
  161. dev->descriptor.idVendor, dev->descriptor.idProduct);
  162. break;
  163. case 1:
  164. acecad->dev.absmax[ABS_X] = 3000;
  165. acecad->dev.absmax[ABS_Y] = 2250;
  166. acecad->dev.absmax[ABS_PRESSURE] = 1024;
  167. if (!strlen(acecad->name))
  168. snprintf(acecad->name, sizeof(acecad->name),
  169. "USB Acecad 302 Tablet %04x:%04x",
  170. dev->descriptor.idVendor, dev->descriptor.idProduct);
  171. break;
  172. }
  173. acecad->dev.absfuzz[ABS_X] = 4;
  174. acecad->dev.absfuzz[ABS_Y] = 4;
  175. acecad->dev.private = acecad;
  176. acecad->dev.open = usb_acecad_open;
  177. acecad->dev.close = usb_acecad_close;
  178. acecad->dev.name = acecad->name;
  179. acecad->dev.phys = acecad->phys;
  180. usb_to_input_id(dev, &acecad->dev.id);
  181. acecad->dev.dev = &intf->dev;
  182. usb_fill_int_urb(acecad->irq, dev, pipe,
  183. acecad->data, maxp > 8 ? 8 : maxp,
  184. usb_acecad_irq, acecad, endpoint->bInterval);
  185. acecad->irq->transfer_dma = acecad->data_dma;
  186. acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  187. input_register_device(&acecad->dev);
  188. printk(KERN_INFO "input: %s with packet size %d on %s\n",
  189. acecad->name, maxp, path);
  190. usb_set_intfdata(intf, acecad);
  191. return 0;
  192. fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
  193. fail1: kfree(acecad);
  194. return -ENOMEM;
  195. }
  196. static void usb_acecad_disconnect(struct usb_interface *intf)
  197. {
  198. struct usb_acecad *acecad = usb_get_intfdata(intf);
  199. usb_set_intfdata(intf, NULL);
  200. if (acecad) {
  201. usb_kill_urb(acecad->irq);
  202. input_unregister_device(&acecad->dev);
  203. usb_free_urb(acecad->irq);
  204. usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
  205. kfree(acecad);
  206. }
  207. }
  208. static struct usb_device_id usb_acecad_id_table [] = {
  209. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
  210. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
  211. { }
  212. };
  213. MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
  214. static struct usb_driver usb_acecad_driver = {
  215. .owner = THIS_MODULE,
  216. .name = "usb_acecad",
  217. .probe = usb_acecad_probe,
  218. .disconnect = usb_acecad_disconnect,
  219. .id_table = usb_acecad_id_table,
  220. };
  221. static int __init usb_acecad_init(void)
  222. {
  223. int result = usb_register(&usb_acecad_driver);
  224. if (result == 0)
  225. info(DRIVER_VERSION ":" DRIVER_DESC);
  226. return result;
  227. }
  228. static void __exit usb_acecad_exit(void)
  229. {
  230. usb_deregister(&usb_acecad_driver);
  231. }
  232. module_init(usb_acecad_init);
  233. module_exit(usb_acecad_exit);