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