acecad.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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/usb/input.h>
  30. /*
  31. * Version Information
  32. */
  33. #define DRIVER_VERSION "v3.2"
  34. #define DRIVER_DESC "USB Acecad Flair tablet driver"
  35. #define DRIVER_LICENSE "GPL"
  36. #define DRIVER_AUTHOR "Edouard TISSERANT <edouard.tisserant@wanadoo.fr>"
  37. MODULE_AUTHOR(DRIVER_AUTHOR);
  38. MODULE_DESCRIPTION(DRIVER_DESC);
  39. MODULE_LICENSE(DRIVER_LICENSE);
  40. #define USB_VENDOR_ID_ACECAD 0x0460
  41. #define USB_DEVICE_ID_FLAIR 0x0004
  42. #define USB_DEVICE_ID_302 0x0008
  43. struct usb_acecad {
  44. char name[128];
  45. char phys[64];
  46. struct usb_device *usbdev;
  47. struct usb_interface *intf;
  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. struct usb_interface *intf = acecad->intf;
  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. dev_dbg(&intf->dev, "%s - urb shutting down with status: %d\n",
  69. __func__, urb->status);
  70. return;
  71. default:
  72. dev_dbg(&intf->dev, "%s - nonzero urb status received: %d\n",
  73. __func__, urb->status);
  74. goto resubmit;
  75. }
  76. prox = (data[0] & 0x04) >> 2;
  77. input_report_key(dev, BTN_TOOL_PEN, prox);
  78. if (prox) {
  79. int x = data[1] | (data[2] << 8);
  80. int y = data[3] | (data[4] << 8);
  81. /* Pressure should compute the same way for flair and 302 */
  82. int pressure = data[5] | (data[6] << 8);
  83. int touch = data[0] & 0x01;
  84. int stylus = (data[0] & 0x10) >> 4;
  85. int stylus2 = (data[0] & 0x20) >> 5;
  86. input_report_abs(dev, ABS_X, x);
  87. input_report_abs(dev, ABS_Y, y);
  88. input_report_abs(dev, ABS_PRESSURE, pressure);
  89. input_report_key(dev, BTN_TOUCH, touch);
  90. input_report_key(dev, BTN_STYLUS, stylus);
  91. input_report_key(dev, BTN_STYLUS2, stylus2);
  92. }
  93. /* event termination */
  94. input_sync(dev);
  95. resubmit:
  96. status = usb_submit_urb(urb, GFP_ATOMIC);
  97. if (status)
  98. dev_err(&intf->dev,
  99. "can't resubmit intr, %s-%s/input0, status %d\n",
  100. acecad->usbdev->bus->bus_name,
  101. acecad->usbdev->devpath, status);
  102. }
  103. static int usb_acecad_open(struct input_dev *dev)
  104. {
  105. struct usb_acecad *acecad = input_get_drvdata(dev);
  106. acecad->irq->dev = acecad->usbdev;
  107. if (usb_submit_urb(acecad->irq, GFP_KERNEL))
  108. return -EIO;
  109. return 0;
  110. }
  111. static void usb_acecad_close(struct input_dev *dev)
  112. {
  113. struct usb_acecad *acecad = input_get_drvdata(dev);
  114. usb_kill_urb(acecad->irq);
  115. }
  116. static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_id *id)
  117. {
  118. struct usb_device *dev = interface_to_usbdev(intf);
  119. struct usb_host_interface *interface = intf->cur_altsetting;
  120. struct usb_endpoint_descriptor *endpoint;
  121. struct usb_acecad *acecad;
  122. struct input_dev *input_dev;
  123. int pipe, maxp;
  124. int err;
  125. if (interface->desc.bNumEndpoints != 1)
  126. return -ENODEV;
  127. endpoint = &interface->endpoint[0].desc;
  128. if (!usb_endpoint_is_int_in(endpoint))
  129. return -ENODEV;
  130. pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
  131. maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  132. acecad = kzalloc(sizeof(struct usb_acecad), GFP_KERNEL);
  133. input_dev = input_allocate_device();
  134. if (!acecad || !input_dev) {
  135. err = -ENOMEM;
  136. goto fail1;
  137. }
  138. acecad->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &acecad->data_dma);
  139. if (!acecad->data) {
  140. err= -ENOMEM;
  141. goto fail1;
  142. }
  143. acecad->irq = usb_alloc_urb(0, GFP_KERNEL);
  144. if (!acecad->irq) {
  145. err = -ENOMEM;
  146. goto fail2;
  147. }
  148. acecad->usbdev = dev;
  149. acecad->intf = intf;
  150. acecad->input = input_dev;
  151. if (dev->manufacturer)
  152. strlcpy(acecad->name, dev->manufacturer, sizeof(acecad->name));
  153. if (dev->product) {
  154. if (dev->manufacturer)
  155. strlcat(acecad->name, " ", sizeof(acecad->name));
  156. strlcat(acecad->name, dev->product, sizeof(acecad->name));
  157. }
  158. usb_make_path(dev, acecad->phys, sizeof(acecad->phys));
  159. strlcat(acecad->phys, "/input0", sizeof(acecad->phys));
  160. input_dev->name = acecad->name;
  161. input_dev->phys = acecad->phys;
  162. usb_to_input_id(dev, &input_dev->id);
  163. input_dev->dev.parent = &intf->dev;
  164. input_set_drvdata(input_dev, acecad);
  165. input_dev->open = usb_acecad_open;
  166. input_dev->close = usb_acecad_close;
  167. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  168. input_dev->keybit[BIT_WORD(BTN_DIGI)] = BIT_MASK(BTN_TOOL_PEN) |
  169. BIT_MASK(BTN_TOUCH) | BIT_MASK(BTN_STYLUS) |
  170. BIT_MASK(BTN_STYLUS2);
  171. switch (id->driver_info) {
  172. case 0:
  173. input_set_abs_params(input_dev, ABS_X, 0, 5000, 4, 0);
  174. input_set_abs_params(input_dev, ABS_Y, 0, 3750, 4, 0);
  175. input_set_abs_params(input_dev, ABS_PRESSURE, 0, 512, 0, 0);
  176. if (!strlen(acecad->name))
  177. snprintf(acecad->name, sizeof(acecad->name),
  178. "USB Acecad Flair Tablet %04x:%04x",
  179. le16_to_cpu(dev->descriptor.idVendor),
  180. le16_to_cpu(dev->descriptor.idProduct));
  181. break;
  182. case 1:
  183. input_set_abs_params(input_dev, ABS_X, 0, 53000, 4, 0);
  184. input_set_abs_params(input_dev, ABS_Y, 0, 2250, 4, 0);
  185. input_set_abs_params(input_dev, ABS_PRESSURE, 0, 1024, 0, 0);
  186. if (!strlen(acecad->name))
  187. snprintf(acecad->name, sizeof(acecad->name),
  188. "USB Acecad 302 Tablet %04x:%04x",
  189. le16_to_cpu(dev->descriptor.idVendor),
  190. le16_to_cpu(dev->descriptor.idProduct));
  191. break;
  192. }
  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 fail3;
  201. usb_set_intfdata(intf, acecad);
  202. return 0;
  203. fail3: usb_free_urb(acecad->irq);
  204. fail2: usb_free_coherent(dev, 8, acecad->data, acecad->data_dma);
  205. fail1: input_free_device(input_dev);
  206. kfree(acecad);
  207. return err;
  208. }
  209. static void usb_acecad_disconnect(struct usb_interface *intf)
  210. {
  211. struct usb_acecad *acecad = usb_get_intfdata(intf);
  212. usb_set_intfdata(intf, NULL);
  213. input_unregister_device(acecad->input);
  214. usb_free_urb(acecad->irq);
  215. usb_free_coherent(acecad->usbdev, 8, acecad->data, acecad->data_dma);
  216. kfree(acecad);
  217. }
  218. static struct usb_device_id usb_acecad_id_table [] = {
  219. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_FLAIR), .driver_info = 0 },
  220. { USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_302), .driver_info = 1 },
  221. { }
  222. };
  223. MODULE_DEVICE_TABLE(usb, usb_acecad_id_table);
  224. static struct usb_driver usb_acecad_driver = {
  225. .name = "usb_acecad",
  226. .probe = usb_acecad_probe,
  227. .disconnect = usb_acecad_disconnect,
  228. .id_table = usb_acecad_id_table,
  229. };
  230. module_usb_driver(usb_acecad_driver);