acecad.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. unsigned char *data;
  51. dma_addr_t data_dma;
  52. };
  53. static void usb_acecad_irq(struct urb *urb)
  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", __func__, urb->status);
  68. return;
  69. default:
  70. dbg("%s - nonzero urb status received: %d", __func__, 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 = input_get_drvdata(dev);
  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 = input_get_drvdata(dev);
  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. int err = -ENOMEM;
  120. if (interface->desc.bNumEndpoints != 1)
  121. return -ENODEV;
  122. endpoint = &interface->endpoint[0].desc;
  123. if (!usb_endpoint_is_int_in(endpoint))
  124. return -ENODEV;
  125. pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
  126. maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  127. acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL);
  128. input_dev = input_allocate_device();
  129. if (!acecad || !input_dev) {
  130. err = -ENOMEM;
  131. goto fail1;
  132. }
  133. acecad->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &acecad->data_dma);
  134. if (!acecad->data) {
  135. err= -ENOMEM;
  136. goto fail1;
  137. }
  138. acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
  139. if (!acecad->irq) {
  140. err = -ENOMEM;
  141. goto fail2;
  142. }
  143. acecad->usbdev = dev;
  144. acecad->input = input_dev;
  145. if (dev->manufacturer)
  146. strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
  147. if (dev->product) {
  148. if (dev->manufacturer)
  149. strlcat(acecad->name, " ", sizeof(acecad->name));
  150. strlcat(acecad->name, dev->product, sizeof(acecad->name));
  151. }
  152. usb_make_path(dev, acecad->phys, sizeof(acecad->phys));
  153. strlcat(acecad->phys, "/input0", sizeof(acecad->phys));
  154. input_dev->name = acecad->name;
  155. input_dev->phys = acecad->phys;
  156. usb_to_input_id(dev, &input_dev->id);
  157. input_dev->dev.parent = &intf->dev;
  158. input_set_drvdata(input_dev, acecad);
  159. input_dev->open = usb_acecad_open;
  160. input_dev->close = usb_acecad_close;
  161. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  162. input_dev->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
  163. BIT_MASK(ABS_PRESSURE);
  164. input_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
  165. BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
  166. input_dev->keybit[BIT_WORD(BTN_DIGI)] = BIT_MASK(BTN_TOOL_PEN) |
  167. BIT_MASK(BTN_TOUCH) | BIT_MASK(BTN_STYLUS) |
  168. BIT_MASK(BTN_STYLUS2);
  169. switch (id->driver_info) {
  170. case 0:
  171. input_dev->absmax[ABS_X] = 5000;
  172. input_dev->absmax[ABS_Y] = 3750;
  173. input_dev->absmax[ABS_PRESSURE] = 512;
  174. if (!strlen(acecad->name))
  175. snprintf(acecad->name, sizeof(acecad->name),
  176. "USB Acecad Flair Tablet %04x:%04x",
  177. le16_to_cpu(dev->descriptor.idVendor),
  178. le16_to_cpu(dev->descriptor.idProduct));
  179. break;
  180. case 1:
  181. input_dev->absmax[ABS_X] = 3000;
  182. input_dev->absmax[ABS_Y] = 2250;
  183. input_dev->absmax[ABS_PRESSURE] = 1024;
  184. if (!strlen(acecad->name))
  185. snprintf(acecad->name, sizeof(acecad->name),
  186. "USB Acecad 302 Tablet %04x:%04x",
  187. le16_to_cpu(dev->descriptor.idVendor),
  188. le16_to_cpu(dev->descriptor.idProduct));
  189. break;
  190. }
  191. input_dev->absfuzz[ABS_X] = 4;
  192. input_dev->absfuzz[ABS_Y] = 4;
  193. usb_fill_int_urb(acecad->irq, dev, pipe,
  194. acecad->data, maxp > 8 ? 8 : maxp,
  195. usb_acecad_irq, acecad, endpoint->bInterval);
  196. acecad->irq->transfer_dma = acecad->data_dma;
  197. acecad->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  198. err = input_register_device(acecad->input);
  199. if (err)
  200. goto fail2;
  201. usb_set_intfdata(intf, acecad);
  202. return 0;
  203. fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma);
  204. fail1: input_free_device(input_dev);
  205. kfree(acecad);
  206. return err;
  207. }
  208. static void usb_acecad_disconnect(struct usb_interface *intf)
  209. {
  210. struct usb_acecad *acecad = usb_get_intfdata(intf);
  211. usb_set_intfdata(intf, NULL);
  212. if (acecad) {
  213. usb_kill_urb(acecad->irq);
  214. input_unregister_device(acecad->input);
  215. usb_free_urb(acecad->irq);
  216. usb_buffer_free(interface_to_usbdev(intf), 10, acecad->data, acecad->data_dma);
  217. kfree(acecad);
  218. }
  219. }
  220. static struct usb_device_id usb_acecad_id_table [] = {
  221. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
  222. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
  223. { }
  224. };
  225. MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
  226. static struct usb_driver usb_acecad_driver = {
  227. .name = "usb_acecad",
  228. .probe = usb_acecad_probe,
  229. .disconnect = usb_acecad_disconnect,
  230. .id_table = usb_acecad_id_table,
  231. };
  232. static int __init usb_acecad_init(void)
  233. {
  234. int result = usb_register(&usb_acecad_driver);
  235. if (result == 0)
  236. info(DRIVER_VERSION ":" DRIVER_DESC);
  237. return result;
  238. }
  239. static void __exit usb_acecad_exit(void)
  240. {
  241. usb_deregister(&usb_acecad_driver);
  242. }
  243. module_init(usb_acecad_init);
  244. module_exit(usb_acecad_exit);