acecad.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 *input;
  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->input;
  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. struct input_dev *input_dev;
  120. int pipe, maxp;
  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. input_dev = input_allocate_device();
  132. if (!acecad || !input_dev)
  133. goto fail1;
  134. acecad->data = usb_buffer_alloc(dev, 8, SLAB_KERNEL, &acecad->data_dma);
  135. if (!acecad->data)
  136. goto fail1;
  137. acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
  138. if (!acecad->irq)
  139. goto fail2;
  140. acecad->usbdev = dev;
  141. acecad->input = input_dev;
  142. if (dev->manufacturer)
  143. strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
  144. if (dev->product) {
  145. if (dev->manufacturer)
  146. strlcat(acecad->name, " ", sizeof(acecad->name));
  147. strlcat(acecad->name, dev->product, sizeof(acecad->name));
  148. }
  149. usb_make_path(dev, acecad->phys, sizeof(acecad->phys));
  150. strlcat(acecad->phys, "/input0", sizeof(acecad->phys));
  151. input_dev->name = acecad->name;
  152. input_dev->phys = acecad->phys;
  153. usb_to_input_id(dev, &input_dev->id);
  154. input_dev->cdev.dev = &intf->dev;
  155. input_dev->private = acecad;
  156. input_dev->open = usb_acecad_open;
  157. input_dev->close = usb_acecad_close;
  158. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
  159. input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);
  160. input_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
  161. input_dev->keybit[LONG(BTN_DIGI)] = BIT(BTN_TOOL_PEN) |BIT(BTN_TOUCH) | BIT(BTN_STYLUS) | BIT(BTN_STYLUS2);
  162. switch (id->driver_info) {
  163. case 0:
  164. input_dev->absmax[ABS_X] = 5000;
  165. input_dev->absmax[ABS_Y] = 3750;
  166. input_dev->absmax[ABS_PRESSURE] = 512;
  167. if (!strlen(acecad->name))
  168. snprintf(acecad->name, sizeof(acecad->name),
  169. "USB Acecad Flair Tablet %04x:%04x",
  170. le16_to_cpu(dev->descriptor.idVendor),
  171. le16_to_cpu(dev->descriptor.idProduct));
  172. break;
  173. case 1:
  174. input_dev->absmax[ABS_X] = 3000;
  175. input_dev->absmax[ABS_Y] = 2250;
  176. input_dev->absmax[ABS_PRESSURE] = 1024;
  177. if (!strlen(acecad->name))
  178. snprintf(acecad->name, sizeof(acecad->name),
  179. "USB Acecad 302 Tablet %04x:%04x",
  180. le16_to_cpu(dev->descriptor.idVendor),
  181. le16_to_cpu(dev->descriptor.idProduct));
  182. break;
  183. }
  184. input_dev->absfuzz[ABS_X] = 4;
  185. input_dev->absfuzz[ABS_Y] = 4;
  186. usb_fill_int_urb(acecad->irq, dev, pipe,
  187. acecad->data, maxp > 8 ? 8 : maxp,
  188. usb_acecad_irq, acecad, endpoint->bInterval);
  189. acecad->irq->transfer_dma = acecad->data_dma;
  190. acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  191. input_register_device(acecad->input);
  192. usb_set_intfdata(intf, acecad);
  193. return 0;
  194. fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
  195. fail1: input_free_device(input_dev);
  196. kfree(acecad);
  197. return -ENOMEM;
  198. }
  199. static void usb_acecad_disconnect(struct usb_interface *intf)
  200. {
  201. struct usb_acecad *acecad = usb_get_intfdata(intf);
  202. usb_set_intfdata(intf, NULL);
  203. if (acecad) {
  204. usb_kill_urb(acecad->irq);
  205. input_unregister_device(acecad->input);
  206. usb_free_urb(acecad->irq);
  207. usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
  208. kfree(acecad);
  209. }
  210. }
  211. static struct usb_device_id usb_acecad_id_table [] = {
  212. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
  213. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
  214. { }
  215. };
  216. MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
  217. static struct usb_driver usb_acecad_driver = {
  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);