Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1 | /* |
Dmitry Torokhov | 4104d13 | 2007-05-07 16:16:29 -0400 | [diff] [blame] | 2 | * drivers/input/tablet/wacom_sys.c |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 3 | * |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 4 | * USB Wacom tablet support - system specific code |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 14 | #include "wacom_wac.h" |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 15 | #include "wacom.h" |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 16 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 17 | /* defines to get HID report descriptor */ |
| 18 | #define HID_DEVICET_HID (USB_TYPE_CLASS | 0x01) |
| 19 | #define HID_DEVICET_REPORT (USB_TYPE_CLASS | 0x02) |
| 20 | #define HID_USAGE_UNDEFINED 0x00 |
| 21 | #define HID_USAGE_PAGE 0x05 |
| 22 | #define HID_USAGE_PAGE_DIGITIZER 0x0d |
| 23 | #define HID_USAGE_PAGE_DESKTOP 0x01 |
| 24 | #define HID_USAGE 0x09 |
| 25 | #define HID_USAGE_X 0x30 |
| 26 | #define HID_USAGE_Y 0x31 |
| 27 | #define HID_USAGE_X_TILT 0x3d |
| 28 | #define HID_USAGE_Y_TILT 0x3e |
| 29 | #define HID_USAGE_FINGER 0x22 |
| 30 | #define HID_USAGE_STYLUS 0x20 |
| 31 | #define HID_COLLECTION 0xc0 |
| 32 | |
| 33 | enum { |
| 34 | WCM_UNDEFINED = 0, |
| 35 | WCM_DESKTOP, |
| 36 | WCM_DIGITIZER, |
| 37 | }; |
| 38 | |
| 39 | struct hid_descriptor { |
| 40 | struct usb_descriptor_header header; |
| 41 | __le16 bcdHID; |
| 42 | u8 bCountryCode; |
| 43 | u8 bNumDescriptors; |
| 44 | u8 bDescriptorType; |
| 45 | __le16 wDescriptorLength; |
| 46 | } __attribute__ ((packed)); |
| 47 | |
| 48 | /* defines to get/set USB message */ |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 49 | #define USB_REQ_GET_REPORT 0x01 |
| 50 | #define USB_REQ_SET_REPORT 0x09 |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 51 | #define WAC_HID_FEATURE_REPORT 0x03 |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 52 | |
| 53 | static int usb_get_report(struct usb_interface *intf, unsigned char type, |
| 54 | unsigned char id, void *buf, int size) |
| 55 | { |
| 56 | return usb_control_msg(interface_to_usbdev(intf), |
| 57 | usb_rcvctrlpipe(interface_to_usbdev(intf), 0), |
| 58 | USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 59 | (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber, |
| 60 | buf, size, 100); |
| 61 | } |
| 62 | |
| 63 | static int usb_set_report(struct usb_interface *intf, unsigned char type, |
| 64 | unsigned char id, void *buf, int size) |
| 65 | { |
| 66 | return usb_control_msg(interface_to_usbdev(intf), |
| 67 | usb_sndctrlpipe(interface_to_usbdev(intf), 0), |
| 68 | USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE, |
| 69 | (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber, |
| 70 | buf, size, 1000); |
| 71 | } |
| 72 | |
| 73 | static struct input_dev * get_input_dev(struct wacom_combo *wcombo) |
| 74 | { |
| 75 | return wcombo->wacom->dev; |
| 76 | } |
| 77 | |
Adrian Bunk | 54c9b226 | 2006-11-20 03:23:58 +0100 | [diff] [blame] | 78 | static void wacom_sys_irq(struct urb *urb) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 79 | { |
| 80 | struct wacom *wacom = urb->context; |
| 81 | struct wacom_combo wcombo; |
| 82 | int retval; |
| 83 | |
| 84 | switch (urb->status) { |
| 85 | case 0: |
| 86 | /* success */ |
| 87 | break; |
| 88 | case -ECONNRESET: |
| 89 | case -ENOENT: |
| 90 | case -ESHUTDOWN: |
| 91 | /* this urb is terminated, clean up */ |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 92 | dbg("%s - urb shutting down with status: %d", __func__, urb->status); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 93 | return; |
| 94 | default: |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 95 | dbg("%s - nonzero urb status received: %d", __func__, urb->status); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 96 | goto exit; |
| 97 | } |
| 98 | |
| 99 | wcombo.wacom = wacom; |
| 100 | wcombo.urb = urb; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 101 | |
Dmitry Torokhov | 73a97f4 | 2010-03-19 22:18:15 -0700 | [diff] [blame^] | 102 | if (wacom_wac_irq(&wacom->wacom_wac, &wcombo)) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 103 | input_sync(get_input_dev(&wcombo)); |
| 104 | |
| 105 | exit: |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 106 | usb_mark_last_busy(wacom->usbdev); |
Dmitry Torokhov | 73a97f4 | 2010-03-19 22:18:15 -0700 | [diff] [blame^] | 107 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 108 | if (retval) |
| 109 | err ("%s - usb_submit_urb failed with result %d", |
Harvey Harrison | ea3e6c5 | 2008-05-05 11:36:18 -0400 | [diff] [blame] | 110 | __func__, retval); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void wacom_report_key(void *wcombo, unsigned int key_type, int key_data) |
| 114 | { |
| 115 | input_report_key(get_input_dev((struct wacom_combo *)wcombo), key_type, key_data); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data) |
| 119 | { |
| 120 | input_report_abs(get_input_dev((struct wacom_combo *)wcombo), abs_type, abs_data); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data) |
| 124 | { |
| 125 | input_report_rel(get_input_dev((struct wacom_combo *)wcombo), rel_type, rel_data); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value) |
| 129 | { |
| 130 | input_event(get_input_dev((struct wacom_combo *)wcombo), type, code, value); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | __u16 wacom_be16_to_cpu(unsigned char *data) |
| 134 | { |
| 135 | __u16 value; |
| 136 | value = be16_to_cpu(*(__be16 *) data); |
| 137 | return value; |
| 138 | } |
| 139 | |
| 140 | __u16 wacom_le16_to_cpu(unsigned char *data) |
| 141 | { |
| 142 | __u16 value; |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 143 | value = le16_to_cpu(*(__le16 *) data); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 144 | return value; |
| 145 | } |
| 146 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 147 | void wacom_input_sync(void *wcombo) |
| 148 | { |
| 149 | input_sync(get_input_dev((struct wacom_combo *)wcombo)); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static int wacom_open(struct input_dev *dev) |
| 153 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 154 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 155 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 156 | mutex_lock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 157 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 158 | wacom->irq->dev = wacom->usbdev; |
| 159 | |
| 160 | if (usb_autopm_get_interface(wacom->intf) < 0) { |
| 161 | mutex_unlock(&wacom->lock); |
| 162 | return -EIO; |
| 163 | } |
| 164 | |
| 165 | if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { |
| 166 | usb_autopm_put_interface(wacom->intf); |
| 167 | mutex_unlock(&wacom->lock); |
| 168 | return -EIO; |
| 169 | } |
| 170 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 171 | wacom->open = true; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 172 | wacom->intf->needs_remote_wakeup = 1; |
| 173 | |
| 174 | mutex_unlock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static void wacom_close(struct input_dev *dev) |
| 179 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 180 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 181 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 182 | mutex_lock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 183 | usb_kill_urb(wacom->irq); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 184 | wacom->open = false; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 185 | wacom->intf->needs_remote_wakeup = 0; |
| 186 | mutex_unlock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Ping Cheng | 7ecfbfd | 2007-06-14 23:32:48 -0400 | [diff] [blame] | 189 | void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 190 | { |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 191 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_1) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 192 | BIT_MASK(BTN_5); |
Ping Cheng | 7ecfbfd | 2007-06-14 23:32:48 -0400 | [diff] [blame] | 193 | input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0); |
| 194 | } |
| 195 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 196 | void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 197 | { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 198 | input_dev->evbit[0] |= BIT_MASK(EV_MSC); |
| 199 | input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL); |
| 200 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 201 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 202 | BIT_MASK(BTN_4); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 206 | { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 207 | input_dev->evbit[0] |= BIT_MASK(EV_REL); |
| 208 | input_dev->relbit[0] |= BIT_MASK(REL_WHEEL); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 209 | input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 210 | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE); |
| 211 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 212 | BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 213 | BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 214 | input_set_abs_params(input_dev, ABS_DISTANCE, |
| 215 | 0, wacom_wac->features.distance_max, 0, 0); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 218 | void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 219 | { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 220 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 221 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 222 | BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3); |
Ping Cheng | 071e0a2 | 2006-12-05 17:09:51 -0800 | [diff] [blame] | 223 | input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0); |
Ping Cheng | 0e1763f | 2008-03-13 16:46:46 -0400 | [diff] [blame] | 224 | input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0); |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 228 | { |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 229 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 230 | BIT_MASK(BTN_5) | BIT_MASK(BTN_6) | BIT_MASK(BTN_7); |
Ping Cheng | 071e0a2 | 2006-12-05 17:09:51 -0800 | [diff] [blame] | 231 | input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Ping Cheng | 6f660f1 | 2009-05-08 18:30:33 -0700 | [diff] [blame] | 234 | void input_dev_i4s(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 235 | { |
| 236 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER); |
| 237 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) | BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3); |
| 238 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) | BIT_MASK(BTN_5) | BIT_MASK(BTN_6); |
| 239 | input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0); |
| 240 | } |
| 241 | |
| 242 | void input_dev_i4(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 243 | { |
| 244 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_7) | BIT_MASK(BTN_8); |
| 245 | } |
| 246 | |
Ping Cheng | 0e1763f | 2008-03-13 16:46:46 -0400 | [diff] [blame] | 247 | void input_dev_bee(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 248 | { |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 249 | input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_8) | BIT_MASK(BTN_9); |
Ping Cheng | 0e1763f | 2008-03-13 16:46:46 -0400 | [diff] [blame] | 250 | } |
| 251 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 252 | void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 253 | { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 254 | input_dev->evbit[0] |= BIT_MASK(EV_MSC) | BIT_MASK(EV_REL); |
| 255 | input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL); |
| 256 | input_dev->relbit[0] |= BIT_MASK(REL_WHEEL); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 257 | input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 258 | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE) | |
| 259 | BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA); |
| 260 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 261 | BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 262 | BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) | |
| 263 | BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) | |
| 264 | BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 265 | input_set_abs_params(input_dev, ABS_DISTANCE, |
| 266 | 0, wacom_wac->features.distance_max, 0, 0); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 267 | input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0); |
| 268 | input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0); |
| 269 | input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0); |
| 270 | input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0); |
| 271 | input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0); |
| 272 | } |
| 273 | |
| 274 | void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 275 | { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 276 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) | |
| 277 | BIT_MASK(BTN_STYLUS) | BIT_MASK(BTN_STYLUS2); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 281 | { |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 282 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 285 | void input_dev_tpc(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 286 | { |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 287 | struct wacom_features *features = &wacom_wac->features; |
| 288 | |
| 289 | if (features->device_type == BTN_TOOL_DOUBLETAP || |
| 290 | features->device_type == BTN_TOOL_TRIPLETAP) { |
| 291 | input_set_abs_params(input_dev, ABS_RX, 0, features->x_phy, 0, 0); |
| 292 | input_set_abs_params(input_dev, ABS_RY, 0, features->y_phy, 0, 0); |
| 293 | __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | void input_dev_tpc2fg(struct input_dev *input_dev, struct wacom_wac *wacom_wac) |
| 298 | { |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 299 | if (wacom_wac->features.device_type == BTN_TOOL_TRIPLETAP) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 300 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_TRIPLETAP); |
| 301 | input_dev->evbit[0] |= BIT_MASK(EV_MSC); |
| 302 | input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL); |
| 303 | } |
| 304 | } |
| 305 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 306 | static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 307 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 308 | { |
| 309 | struct usb_device *dev = interface_to_usbdev(intf); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 310 | char limit = 0; |
| 311 | /* result has to be defined as int for some devices */ |
| 312 | int result = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 313 | int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0; |
| 314 | unsigned char *report; |
| 315 | |
| 316 | report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL); |
| 317 | if (!report) |
| 318 | return -ENOMEM; |
| 319 | |
| 320 | /* retrive report descriptors */ |
| 321 | do { |
| 322 | result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 323 | USB_REQ_GET_DESCRIPTOR, |
| 324 | USB_RECIP_INTERFACE | USB_DIR_IN, |
| 325 | HID_DEVICET_REPORT << 8, |
| 326 | intf->altsetting[0].desc.bInterfaceNumber, /* interface */ |
| 327 | report, |
| 328 | hid_desc->wDescriptorLength, |
| 329 | 5000); /* 5 secs */ |
| 330 | } while (result < 0 && limit++ < 5); |
| 331 | |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 332 | /* No need to parse the Descriptor. It isn't an error though */ |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 333 | if (result < 0) |
| 334 | goto out; |
| 335 | |
| 336 | for (i = 0; i < hid_desc->wDescriptorLength; i++) { |
| 337 | |
| 338 | switch (report[i]) { |
| 339 | case HID_USAGE_PAGE: |
| 340 | switch (report[i + 1]) { |
| 341 | case HID_USAGE_PAGE_DIGITIZER: |
| 342 | usage = WCM_DIGITIZER; |
| 343 | i++; |
| 344 | break; |
| 345 | |
| 346 | case HID_USAGE_PAGE_DESKTOP: |
| 347 | usage = WCM_DESKTOP; |
| 348 | i++; |
| 349 | break; |
| 350 | } |
| 351 | break; |
| 352 | |
| 353 | case HID_USAGE: |
| 354 | switch (report[i + 1]) { |
| 355 | case HID_USAGE_X: |
| 356 | if (usage == WCM_DESKTOP) { |
| 357 | if (finger) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 358 | features->device_type = BTN_TOOL_DOUBLETAP; |
| 359 | if (features->type == TABLETPC2FG) { |
| 360 | /* need to reset back */ |
| 361 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
| 362 | features->device_type = BTN_TOOL_TRIPLETAP; |
| 363 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 364 | features->x_max = |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 365 | wacom_le16_to_cpu(&report[i + 3]); |
| 366 | features->x_phy = |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 367 | wacom_le16_to_cpu(&report[i + 6]); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 368 | features->unit = report[i + 9]; |
| 369 | features->unitExpo = report[i + 11]; |
| 370 | i += 12; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 371 | } else if (pen) { |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 372 | /* penabled only accepts exact bytes of data */ |
| 373 | if (features->type == TABLETPC2FG) |
Ping Cheng | 57e413d | 2010-03-01 23:50:24 -0800 | [diff] [blame] | 374 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 375 | features->device_type = BTN_TOOL_PEN; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 376 | features->x_max = |
| 377 | wacom_le16_to_cpu(&report[i + 3]); |
| 378 | i += 4; |
| 379 | } |
| 380 | } else if (usage == WCM_DIGITIZER) { |
| 381 | /* max pressure isn't reported |
| 382 | features->pressure_max = (unsigned short) |
| 383 | (report[i+4] << 8 | report[i + 3]); |
| 384 | */ |
| 385 | features->pressure_max = 255; |
| 386 | i += 4; |
| 387 | } |
| 388 | break; |
| 389 | |
| 390 | case HID_USAGE_Y: |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 391 | if (usage == WCM_DESKTOP) { |
| 392 | if (finger) { |
| 393 | features->device_type = BTN_TOOL_DOUBLETAP; |
| 394 | if (features->type == TABLETPC2FG) { |
| 395 | /* need to reset back */ |
| 396 | features->pktlen = WACOM_PKGLEN_TPC2FG; |
| 397 | features->device_type = BTN_TOOL_TRIPLETAP; |
| 398 | features->y_max = |
| 399 | wacom_le16_to_cpu(&report[i + 3]); |
| 400 | features->y_phy = |
| 401 | wacom_le16_to_cpu(&report[i + 6]); |
| 402 | i += 7; |
| 403 | } else { |
| 404 | features->y_max = |
| 405 | features->x_max; |
| 406 | features->y_phy = |
| 407 | wacom_le16_to_cpu(&report[i + 3]); |
| 408 | i += 4; |
| 409 | } |
| 410 | } else if (pen) { |
| 411 | /* penabled only accepts exact bytes of data */ |
| 412 | if (features->type == TABLETPC2FG) |
Ping Cheng | 57e413d | 2010-03-01 23:50:24 -0800 | [diff] [blame] | 413 | features->pktlen = WACOM_PKGLEN_GRAPHIRE; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 414 | features->device_type = BTN_TOOL_PEN; |
| 415 | features->y_max = |
| 416 | wacom_le16_to_cpu(&report[i + 3]); |
| 417 | i += 4; |
| 418 | } |
| 419 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 420 | break; |
| 421 | |
| 422 | case HID_USAGE_FINGER: |
| 423 | finger = 1; |
| 424 | i++; |
| 425 | break; |
| 426 | |
| 427 | case HID_USAGE_STYLUS: |
| 428 | pen = 1; |
| 429 | i++; |
| 430 | break; |
| 431 | |
| 432 | case HID_USAGE_UNDEFINED: |
| 433 | if (usage == WCM_DESKTOP && finger) /* capacity */ |
| 434 | features->pressure_max = |
| 435 | wacom_le16_to_cpu(&report[i + 3]); |
| 436 | i += 4; |
| 437 | break; |
| 438 | } |
| 439 | break; |
| 440 | |
| 441 | case HID_COLLECTION: |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 442 | /* reset UsagePage and Finger */ |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 443 | finger = usage = 0; |
| 444 | break; |
| 445 | } |
| 446 | } |
| 447 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 448 | out: |
Ping Cheng | 384318e | 2009-04-28 07:49:54 -0700 | [diff] [blame] | 449 | result = 0; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 450 | kfree(report); |
| 451 | return result; |
| 452 | } |
| 453 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 454 | static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 455 | { |
| 456 | unsigned char *rep_data; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 457 | int limit = 0, report_id = 2; |
| 458 | int error = -ENOMEM; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 459 | |
| 460 | rep_data = kmalloc(2, GFP_KERNEL); |
| 461 | if (!rep_data) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 462 | return error; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 463 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 464 | /* ask to report tablet data if it is 2FGT or not a Tablet PC */ |
| 465 | if (features->device_type == BTN_TOOL_TRIPLETAP) { |
| 466 | do { |
| 467 | rep_data[0] = 3; |
| 468 | rep_data[1] = 4; |
| 469 | report_id = 3; |
| 470 | error = usb_set_report(intf, WAC_HID_FEATURE_REPORT, |
| 471 | report_id, rep_data, 2); |
| 472 | if (error >= 0) |
| 473 | error = usb_get_report(intf, |
| 474 | WAC_HID_FEATURE_REPORT, report_id, |
| 475 | rep_data, 3); |
| 476 | } while ((error < 0 || rep_data[1] != 4) && limit++ < 5); |
| 477 | } else if (features->type != TABLETPC && features->type != TABLETPC2FG) { |
| 478 | do { |
| 479 | rep_data[0] = 2; |
| 480 | rep_data[1] = 2; |
| 481 | error = usb_set_report(intf, WAC_HID_FEATURE_REPORT, |
| 482 | report_id, rep_data, 2); |
| 483 | if (error >= 0) |
| 484 | error = usb_get_report(intf, |
| 485 | WAC_HID_FEATURE_REPORT, report_id, |
| 486 | rep_data, 2); |
| 487 | } while ((error < 0 || rep_data[1] != 2) && limit++ < 5); |
| 488 | } |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 489 | |
| 490 | kfree(rep_data); |
| 491 | |
| 492 | return error < 0 ? error : 0; |
| 493 | } |
| 494 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 495 | static int wacom_retrieve_hid_descriptor(struct usb_interface *intf, |
| 496 | struct wacom_features *features) |
| 497 | { |
| 498 | int error = 0; |
| 499 | struct usb_host_interface *interface = intf->cur_altsetting; |
| 500 | struct hid_descriptor *hid_desc; |
| 501 | |
| 502 | /* default device to penabled */ |
| 503 | features->device_type = BTN_TOOL_PEN; |
| 504 | |
| 505 | /* only Tablet PCs need to retrieve the info */ |
| 506 | if ((features->type != TABLETPC) && (features->type != TABLETPC2FG)) |
| 507 | goto out; |
| 508 | |
| 509 | if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) { |
| 510 | if (usb_get_extra_descriptor(&interface->endpoint[0], |
| 511 | HID_DEVICET_REPORT, &hid_desc)) { |
| 512 | printk("wacom: can not retrieve extra class descriptor\n"); |
| 513 | error = 1; |
| 514 | goto out; |
| 515 | } |
| 516 | } |
| 517 | error = wacom_parse_hid(intf, hid_desc, features); |
| 518 | if (error) |
| 519 | goto out; |
| 520 | |
| 521 | /* touch device found but size is not defined. use default */ |
| 522 | if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) { |
| 523 | features->x_max = 1023; |
| 524 | features->y_max = 1023; |
| 525 | } |
| 526 | |
| 527 | out: |
| 528 | return error; |
| 529 | } |
| 530 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 531 | struct wacom_usbdev_data { |
| 532 | struct list_head list; |
| 533 | struct kref kref; |
| 534 | struct usb_device *dev; |
| 535 | struct wacom_shared shared; |
| 536 | }; |
| 537 | |
| 538 | static LIST_HEAD(wacom_udev_list); |
| 539 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 540 | |
| 541 | static struct wacom_usbdev_data *wacom_get_usbdev_data(struct usb_device *dev) |
| 542 | { |
| 543 | struct wacom_usbdev_data *data; |
| 544 | |
| 545 | list_for_each_entry(data, &wacom_udev_list, list) { |
| 546 | if (data->dev == dev) { |
| 547 | kref_get(&data->kref); |
| 548 | return data; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | return NULL; |
| 553 | } |
| 554 | |
| 555 | static int wacom_add_shared_data(struct wacom_wac *wacom, |
| 556 | struct usb_device *dev) |
| 557 | { |
| 558 | struct wacom_usbdev_data *data; |
| 559 | int retval = 0; |
| 560 | |
| 561 | mutex_lock(&wacom_udev_list_lock); |
| 562 | |
| 563 | data = wacom_get_usbdev_data(dev); |
| 564 | if (!data) { |
| 565 | data = kzalloc(sizeof(struct wacom_usbdev_data), GFP_KERNEL); |
| 566 | if (!data) { |
| 567 | retval = -ENOMEM; |
| 568 | goto out; |
| 569 | } |
| 570 | |
| 571 | kref_init(&data->kref); |
| 572 | data->dev = dev; |
| 573 | list_add_tail(&data->list, &wacom_udev_list); |
| 574 | } |
| 575 | |
| 576 | wacom->shared = &data->shared; |
| 577 | |
| 578 | out: |
| 579 | mutex_unlock(&wacom_udev_list_lock); |
| 580 | return retval; |
| 581 | } |
| 582 | |
| 583 | static void wacom_release_shared_data(struct kref *kref) |
| 584 | { |
| 585 | struct wacom_usbdev_data *data = |
| 586 | container_of(kref, struct wacom_usbdev_data, kref); |
| 587 | |
| 588 | mutex_lock(&wacom_udev_list_lock); |
| 589 | list_del(&data->list); |
| 590 | mutex_unlock(&wacom_udev_list_lock); |
| 591 | |
| 592 | kfree(data); |
| 593 | } |
| 594 | |
| 595 | static void wacom_remove_shared_data(struct wacom_wac *wacom) |
| 596 | { |
| 597 | struct wacom_usbdev_data *data; |
| 598 | |
| 599 | if (wacom->shared) { |
| 600 | data = container_of(wacom->shared, struct wacom_usbdev_data, shared); |
| 601 | kref_put(&data->kref, wacom_release_shared_data); |
| 602 | wacom->shared = NULL; |
| 603 | } |
| 604 | } |
| 605 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 606 | static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 607 | { |
| 608 | struct usb_device *dev = interface_to_usbdev(intf); |
| 609 | struct usb_endpoint_descriptor *endpoint; |
| 610 | struct wacom *wacom; |
| 611 | struct wacom_wac *wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 612 | struct wacom_features *features; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 613 | struct input_dev *input_dev; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 614 | int error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 615 | |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 616 | if (!id->driver_info) |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 617 | return -EINVAL; |
| 618 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 619 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 620 | input_dev = input_allocate_device(); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 621 | if (!wacom || !input_dev) { |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 622 | error = -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 623 | goto fail1; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 624 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 625 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 626 | wacom_wac = &wacom->wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 627 | wacom_wac->features = *((struct wacom_features *)id->driver_info); |
| 628 | features = &wacom_wac->features; |
| 629 | if (features->pktlen > WACOM_PKGLEN_MAX) { |
| 630 | error = -EINVAL; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 631 | goto fail1; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX, |
| 635 | GFP_KERNEL, &wacom->data_dma); |
| 636 | if (!wacom_wac->data) { |
| 637 | error = -ENOMEM; |
| 638 | goto fail1; |
| 639 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 640 | |
| 641 | wacom->irq = usb_alloc_urb(0, GFP_KERNEL); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 642 | if (!wacom->irq) { |
| 643 | error = -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 644 | goto fail2; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 645 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 646 | |
| 647 | wacom->usbdev = dev; |
| 648 | wacom->dev = input_dev; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 649 | wacom->intf = intf; |
| 650 | mutex_init(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 651 | usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); |
| 652 | strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); |
| 653 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 654 | usb_to_input_id(dev, &input_dev->id); |
| 655 | |
Dmitry Torokhov | c0f82d5 | 2007-04-12 01:35:03 -0400 | [diff] [blame] | 656 | input_dev->dev.parent = &intf->dev; |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 657 | |
| 658 | input_set_drvdata(input_dev, wacom); |
| 659 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 660 | input_dev->open = wacom_open; |
| 661 | input_dev->close = wacom_close; |
| 662 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 663 | endpoint = &intf->cur_altsetting->endpoint[0].desc; |
| 664 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 665 | /* Retrieve the physical and logical size for OEM devices */ |
| 666 | error = wacom_retrieve_hid_descriptor(intf, features); |
| 667 | if (error) |
| 668 | goto fail2; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 669 | |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 670 | strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); |
| 671 | |
| 672 | if (features->type == TABLETPC || features->type == TABLETPC2FG) { |
| 673 | /* Append the device type to the name */ |
| 674 | strlcat(wacom_wac->name, |
| 675 | features->device_type == BTN_TOOL_PEN ? |
| 676 | " Pen" : " Finger", |
| 677 | sizeof(wacom_wac->name)); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 678 | |
| 679 | error = wacom_add_shared_data(wacom_wac, dev); |
| 680 | if (error) |
| 681 | goto fail3; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | input_dev->name = wacom_wac->name; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 685 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 686 | input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 687 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOUCH); |
| 688 | |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 689 | input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0); |
| 690 | input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0); |
| 691 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0); |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 692 | input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 693 | |
| 694 | wacom_init_input_dev(input_dev, wacom_wac); |
| 695 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 696 | usb_fill_int_urb(wacom->irq, dev, |
| 697 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 698 | wacom_wac->data, features->pktlen, |
Ping Cheng | 8d32e3a | 2006-09-26 13:34:47 -0700 | [diff] [blame] | 699 | wacom_sys_irq, wacom, endpoint->bInterval); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 700 | wacom->irq->transfer_dma = wacom->data_dma; |
| 701 | wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 702 | |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 703 | error = input_register_device(wacom->dev); |
| 704 | if (error) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 705 | goto fail4; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 706 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 707 | /* Note that if query fails it is not a hard failure */ |
| 708 | wacom_query_tablet_data(intf, features); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 709 | |
| 710 | usb_set_intfdata(intf, wacom); |
| 711 | return 0; |
| 712 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 713 | fail4: wacom_remove_shared_data(wacom_wac); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 714 | fail3: usb_free_urb(wacom->irq); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 715 | fail2: usb_buffer_free(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 716 | fail1: input_free_device(input_dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 717 | kfree(wacom); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 718 | return error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static void wacom_disconnect(struct usb_interface *intf) |
| 722 | { |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 723 | struct wacom *wacom = usb_get_intfdata(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 724 | |
| 725 | usb_set_intfdata(intf, NULL); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 726 | |
| 727 | usb_kill_urb(wacom->irq); |
| 728 | input_unregister_device(wacom->dev); |
| 729 | usb_free_urb(wacom->irq); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 730 | usb_buffer_free(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 731 | wacom->wacom_wac.data, wacom->data_dma); |
| 732 | wacom_remove_shared_data(&wacom->wacom_wac); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 733 | kfree(wacom); |
| 734 | } |
| 735 | |
| 736 | static int wacom_suspend(struct usb_interface *intf, pm_message_t message) |
| 737 | { |
| 738 | struct wacom *wacom = usb_get_intfdata(intf); |
| 739 | |
| 740 | mutex_lock(&wacom->lock); |
| 741 | usb_kill_urb(wacom->irq); |
| 742 | mutex_unlock(&wacom->lock); |
| 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | static int wacom_resume(struct usb_interface *intf) |
| 748 | { |
| 749 | struct wacom *wacom = usb_get_intfdata(intf); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 750 | struct wacom_features *features = &wacom->wacom_wac.features; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 751 | int rv; |
| 752 | |
| 753 | mutex_lock(&wacom->lock); |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 754 | |
| 755 | /* switch to wacom mode first */ |
| 756 | wacom_query_tablet_data(intf, features); |
| 757 | |
| 758 | if (wacom->open) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 759 | rv = usb_submit_urb(wacom->irq, GFP_NOIO); |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 760 | else |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 761 | rv = 0; |
Ping Cheng | 3810147 | 2010-04-13 23:07:52 -0700 | [diff] [blame] | 762 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 763 | mutex_unlock(&wacom->lock); |
| 764 | |
| 765 | return rv; |
| 766 | } |
| 767 | |
| 768 | static int wacom_reset_resume(struct usb_interface *intf) |
| 769 | { |
| 770 | return wacom_resume(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | static struct usb_driver wacom_driver = { |
| 774 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 775 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 776 | .probe = wacom_probe, |
| 777 | .disconnect = wacom_disconnect, |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 778 | .suspend = wacom_suspend, |
| 779 | .resume = wacom_resume, |
| 780 | .reset_resume = wacom_reset_resume, |
| 781 | .supports_autosuspend = 1, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 782 | }; |
| 783 | |
| 784 | static int __init wacom_init(void) |
| 785 | { |
| 786 | int result; |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 787 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 788 | result = usb_register(&wacom_driver); |
| 789 | if (result == 0) |
Greg Kroah-Hartman | 899ef6e | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 790 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 791 | DRIVER_DESC "\n"); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 792 | return result; |
| 793 | } |
| 794 | |
| 795 | static void __exit wacom_exit(void) |
| 796 | { |
| 797 | usb_deregister(&wacom_driver); |
| 798 | } |
| 799 | |
| 800 | module_init(wacom_init); |
| 801 | module_exit(wacom_exit); |