acecad.c 7.3 KB

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