acecad.c 7.6 KB

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