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_USAGE_CONTACTMAX 0x55
32 #define HID_COLLECTION 0xa1
33 #define HID_COLLECTION_LOGICAL 0x02
34 #define HID_COLLECTION_END 0xc0
52 #define USB_REQ_GET_REPORT 0x01
53 #define USB_REQ_SET_REPORT 0x09
55 #define WAC_HID_FEATURE_REPORT 0x03
56 #define WAC_MSG_RETRIES 5
58 #define WAC_CMD_LED_CONTROL 0x20
59 #define WAC_CMD_ICON_START 0x21
60 #define WAC_CMD_ICON_XFER 0x23
61 #define WAC_CMD_RETRIES 10
66 struct usb_device *
dev = interface_to_usbdev(intf);
75 intf->altsetting[0].desc.bInterfaceNumber,
85 struct usb_device *
dev = interface_to_usbdev(intf);
93 intf->altsetting[0].desc.bInterfaceNumber,
100 static void wacom_sys_irq(
struct urb *
urb)
106 switch (urb->status) {
114 dev_dbg(dev,
"%s - urb shutting down with status: %d\n",
115 __func__, urb->status);
118 dev_dbg(dev,
"%s - nonzero urb status received: %d\n",
119 __func__, urb->status);
126 usb_mark_last_busy(wacom->
usbdev);
129 dev_err(dev,
"%s - usb_submit_urb failed with result %d\n",
133 static int wacom_open(
struct input_dev *dev)
135 struct wacom *wacom = input_get_drvdata(dev);
138 if (usb_autopm_get_interface(wacom->
intf) < 0)
149 wacom->
intf->needs_remote_wakeup = 1;
153 usb_autopm_put_interface(wacom->
intf);
157 static void wacom_close(
struct input_dev *dev)
159 struct wacom *wacom = input_get_drvdata(dev);
162 autopm_error = usb_autopm_get_interface(wacom->
intf);
167 wacom->
intf->needs_remote_wakeup = 0;
171 usb_autopm_put_interface(wacom->
intf);
178 static int wacom_calc_hid_res(
int logical_extents,
int physical_extents,
181 int prev, unit_exponent;
184 if (logical_extents <= 0 || physical_extents <= 0)
189 if (unit_exponent > 7)
195 }
else if (unit == 0x13) {
196 prev = physical_extents;
197 physical_extents *= 254;
198 if (physical_extents < prev)
206 for (; unit_exponent < 0; unit_exponent++) {
207 prev = logical_extents;
208 logical_extents *= 10;
209 if (logical_extents < prev)
213 for (; unit_exponent > 0; unit_exponent--) {
214 prev = physical_extents;
215 physical_extents *= 10;
216 if (physical_extents < prev)
221 return logical_extents / physical_extents;
233 int xres = wacom_calc_hid_res(features->
x_max, features->
x_phy,
235 int yres = wacom_calc_hid_res(features->
y_max, features->
y_phy,
238 if (xres > 0 && yres > 0) {
239 features->
x_phy = (100 * features->
x_max) / xres;
240 features->
y_phy = (100 * features->
y_max) / yres;
251 static void wacom_set_phy_from_res(
struct wacom_features *features)
257 static int wacom_parse_logical_collection(
unsigned char *
report,
268 wacom_set_phy_from_res(features);
271 get_unaligned_le16(&report[10]);
278 static void wacom_retrieve_report_data(
struct usb_interface *intf,
282 unsigned char *rep_data;
289 rep_data[0], rep_data, 2,
292 if (result >= 0 && rep_data[1] > 2)
339 struct usb_device *dev = interface_to_usbdev(intf);
356 intf->altsetting[0].desc.bInterfaceNumber,
370 switch (report[i + 1]) {
384 switch (report[i + 1]) {
401 get_unaligned_le16(&report[i + 5]);
403 get_unaligned_le16(&report[i + 8]);
407 get_unaligned_le16(&report[i + 3]);
409 get_unaligned_le16(&report[i + 8]);
410 features->
unit = report[i - 1];
415 get_unaligned_le16(&report[i + 3]);
417 get_unaligned_le16(&report[i + 6]);
418 features->
unit = report[i + 9];
419 features->
unitExpo = report[i + 11];
428 get_unaligned_le16(&report[i + 3]);
437 int type = features->
type;
441 get_unaligned_le16(&report[i + 3]);
443 get_unaligned_le16(&report[i + 6]);
447 get_unaligned_le16(&report[i + 3]);
449 get_unaligned_le16(&report[i - 2]);
453 get_unaligned_le16(&report[i + 3]);
455 get_unaligned_le16(&report[i + 6]);
461 get_unaligned_le16(&report[i + 3]);
466 get_unaligned_le16(&report[i + 3]);
490 wacom_retrieve_report_data(intf, features);
505 i += wacom_parse_logical_collection(&report[i],
519 static int wacom_set_device_mode(
struct usb_interface *intf,
int report_id,
int length,
int mode)
521 unsigned char *rep_data;
528 rep_data[0] = report_id;
533 report_id, rep_data, length, 1);
536 report_id, rep_data, length, 1);
537 }
while ((error < 0 || rep_data[1] != mode) && limit++ <
WAC_MSG_RETRIES);
541 return error < 0 ? error : 0;
556 return wacom_set_device_mode(intf, 3, 4, 4);
559 return wacom_set_device_mode(intf, 18, 3, 2);
563 return wacom_set_device_mode(intf, 2, 2, 2);
570 static int wacom_retrieve_hid_descriptor(
struct usb_interface *intf,
574 struct usb_host_interface *
interface = intf->cur_altsetting;
591 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
593 }
else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
606 error = usb_get_extra_descriptor(&
interface->endpoint[0],
610 "can not retrieve extra class descriptor\n");
614 error = wacom_parse_hid(intf, hid_desc, features);
617 wacom_fix_phy_from_hid(features);
633 static struct usb_device *wacom_get_sibling(
struct usb_device *dev,
int vendor,
int product)
636 struct usb_device *sibling;
638 if (vendor == 0 && product == 0)
641 if (dev->parent ==
NULL)
644 usb_hub_for_each_child(dev->parent, port1, sibling) {
649 d = &sibling->descriptor;
662 if (data->
dev == dev) {
663 kref_get(&data->
kref);
671 static int wacom_add_shared_data(
struct wacom_wac *wacom,
672 struct usb_device *dev)
679 data = wacom_get_usbdev_data(dev);
687 kref_init(&data->
kref);
699 static void wacom_release_shared_data(
struct kref *
kref)
711 static void wacom_remove_shared_data(
struct wacom_wac *wacom)
717 kref_put(&data->
kref, wacom_release_shared_data);
722 static int wacom_led_control(
struct wacom *wacom)
738 int ring_led = wacom->
led.select[0] & 0x03;
739 int ring_lum = (((wacom->
led.llv & 0x60) >> 5) - 1) & 0x03;
743 buf[1] = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
746 int led = wacom->
led.select[0] | 0x4;
750 led |= (wacom->
led.select[1] << 4) | 0x40;
754 buf[2] = wacom->
led.llv;
755 buf[3] = wacom->
led.hlv;
756 buf[4] = wacom->
led.img_lum;
766 static int wacom_led_putimage(
struct wacom *wacom,
int button_id,
const void *img)
784 buf[1] = button_id & 0x07;
785 for (i = 0; i < 4; i++) {
787 memcpy(buf + 3, img + i * 256, 256);
806 static ssize_t wacom_led_select_store(
struct device *dev,
int set_id,
807 const char *buf,
size_t count)
819 wacom->
led.select[set_id] =
id & 0x3;
820 err = wacom_led_control(wacom);
824 return err < 0 ? err :
count;
827 #define DEVICE_LED_SELECT_ATTR(SET_ID) \
828 static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
829 struct device_attribute *attr, const char *buf, size_t count) \
831 return wacom_led_select_store(dev, SET_ID, buf, count); \
833 static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
834 struct device_attribute *attr, char *buf) \
836 struct wacom *wacom = dev_get_drvdata(dev); \
837 return snprintf(buf, 2, "%d\n", wacom->led.select[SET_ID]); \
839 static DEVICE_ATTR(status_led##SET_ID##_select, S_IWUSR | S_IRUSR, \
840 wacom_led##SET_ID##_select_show, \
841 wacom_led##SET_ID##_select_store)
846 static ssize_t wacom_luminance_store(
struct wacom *wacom,
u8 *
dest,
847 const char *buf,
size_t count)
858 *dest = value & 0x7f;
859 err = wacom_led_control(wacom);
863 return err < 0 ? err :
count;
866 #define DEVICE_LUMINANCE_ATTR(name, field) \
867 static ssize_t wacom_##name##_luminance_store(struct device *dev, \
868 struct device_attribute *attr, const char *buf, size_t count) \
870 struct wacom *wacom = dev_get_drvdata(dev); \
872 return wacom_luminance_store(wacom, &wacom->led.field, \
875 static DEVICE_ATTR(name##_luminance, S_IWUSR, \
876 NULL, wacom_##name##_luminance_store)
882 static ssize_t wacom_button_image_store(
struct device *dev,
int button_id,
883 const char *buf,
size_t count)
893 err = wacom_led_putimage(wacom, button_id, buf);
897 return err < 0 ? err :
count;
900 #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
901 static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
902 struct device_attribute *attr, const char *buf, size_t count) \
904 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
906 static DEVICE_ATTR(button##BUTTON_ID##_rawimg, S_IWUSR, \
907 NULL, wacom_btnimg##BUTTON_ID##_store)
918 static struct attribute *cintiq_led_attrs[] = {
919 &dev_attr_status_led0_select.attr,
920 &dev_attr_status_led1_select.attr,
926 .attrs = cintiq_led_attrs,
929 static struct attribute *intuos4_led_attrs[] = {
930 &dev_attr_status0_luminance.attr,
931 &dev_attr_status1_luminance.attr,
932 &dev_attr_status_led0_select.attr,
933 &dev_attr_buttons_luminance.attr,
934 &dev_attr_button0_rawimg.attr,
935 &dev_attr_button1_rawimg.attr,
936 &dev_attr_button2_rawimg.attr,
937 &dev_attr_button3_rawimg.attr,
938 &dev_attr_button4_rawimg.attr,
939 &dev_attr_button5_rawimg.attr,
940 &dev_attr_button6_rawimg.attr,
941 &dev_attr_button7_rawimg.attr,
947 .attrs = intuos4_led_attrs,
950 static struct attribute *intuos5_led_attrs[] = {
951 &dev_attr_status0_luminance.attr,
952 &dev_attr_status_led0_select.attr,
958 .attrs = intuos5_led_attrs,
961 static int wacom_initialize_leds(
struct wacom *wacom)
966 switch (wacom->
wacom_wac.features.type) {
970 wacom->
led.select[0] = 0;
971 wacom->
led.select[1] = 0;
974 wacom->
led.img_lum = 10;
976 &intuos4_led_attr_group);
981 wacom->
led.select[0] = 0;
982 wacom->
led.select[1] = 0;
985 wacom->
led.img_lum = 0;
988 &cintiq_led_attr_group);
994 wacom->
led.select[0] = 0;
995 wacom->
led.select[1] = 0;
998 wacom->
led.img_lum = 0;
1001 &intuos5_led_attr_group);
1010 "cannot create sysfs group err: %d\n", error);
1013 wacom_led_control(wacom);
1018 static void wacom_destroy_leds(
struct wacom *wacom)
1020 switch (wacom->
wacom_wac.features.type) {
1025 &intuos4_led_attr_group);
1031 &cintiq_led_attr_group);
1038 &intuos5_led_attr_group);
1047 static int wacom_battery_get_property(
struct power_supply *psy,
1057 wacom->
wacom_wac.battery_capacity * 100 / 31;
1067 static int wacom_initialize_battery(
struct wacom *wacom)
1072 wacom->
battery.properties = wacom_battery_props;
1074 wacom->
battery.get_property = wacom_battery_get_property;
1075 wacom->
battery.name =
"wacom_battery";
1077 wacom->
battery.use_for_apm = 0;
1090 static void wacom_destroy_battery(
struct wacom *wacom)
1099 static int wacom_register_input(
struct wacom *wacom)
1101 struct input_dev *input_dev;
1103 struct usb_device *dev = interface_to_usbdev(intf);
1107 input_dev = input_allocate_device();
1113 input_dev->name = wacom_wac->
name;
1114 input_dev->dev.parent = &intf->dev;
1115 input_dev->open = wacom_open;
1116 input_dev->close = wacom_close;
1117 usb_to_input_id(dev, &input_dev->id);
1118 input_set_drvdata(input_dev, wacom);
1120 wacom_wac->
input = input_dev;
1125 error = input_register_device(input_dev);
1132 input_free_device(input_dev);
1140 struct wacom *wacom =
container_of(work,
struct wacom, work);
1141 struct usb_device *usbdev = wacom->
usbdev;
1142 struct wacom_wac *wacom_wac = &wacom->
wacom_wac;
1143 struct wacom *wacom1, *wacom2;
1144 struct wacom_wac *wacom_wac1, *wacom_wac2;
1152 wacom_destroy_battery(wacom);
1155 wacom1 = usb_get_intfdata(usbdev->config->interface[1]);
1157 if (wacom_wac1->
input)
1158 input_unregister_device(wacom_wac1->
input);
1162 wacom2 = usb_get_intfdata(usbdev->config->interface[2]);
1164 if (wacom_wac2->
input)
1165 input_unregister_device(wacom_wac2->
input);
1168 if (wacom_wac->
pid == 0) {
1169 dev_info(&wacom->
intf->dev,
"wireless tablet disconnected\n");
1174 "wireless tablet connected with PID %x\n",
1186 "ignoring unknown PID.\n");
1194 error = wacom_register_input(wacom1);
1203 wacom_set_phy_from_res(&wacom_wac2->
features);
1205 error = wacom_register_input(wacom2);
1209 error = wacom_initialize_battery(wacom);
1217 input_unregister_device(wacom_wac2->
input);
1220 input_unregister_device(wacom_wac1->
input);
1228 struct usb_device *dev = interface_to_usbdev(intf);
1230 struct wacom *wacom;
1231 struct wacom_wac *wacom_wac;
1235 if (!id->driver_info)
1238 wacom = kzalloc(
sizeof(
struct wacom),
GFP_KERNEL);
1252 if (!wacom_wac->
data) {
1267 usb_make_path(dev, wacom->
phys,
sizeof(wacom->
phys));
1270 endpoint = &intf->cur_altsetting->endpoint[0].desc;
1273 error = wacom_retrieve_hid_descriptor(intf, features);
1287 wacom_set_phy_from_res(features);
1289 features->
x_max = 4096;
1290 features->
y_max = 4096;
1301 struct usb_device *other_dev;
1307 sizeof(wacom_wac->
name));
1310 other_dev = wacom_get_sibling(dev, features->
oVid, features->
oPid);
1311 if (other_dev ==
NULL || wacom_get_usbdev_data(other_dev) ==
NULL)
1313 error = wacom_add_shared_data(wacom_wac, other_dev);
1318 usb_fill_int_urb(wacom->
irq, dev,
1321 wacom_sys_irq, wacom, endpoint->
bInterval);
1323 wacom->
irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1325 error = wacom_initialize_leds(wacom);
1330 error = wacom_register_input(wacom);
1336 wacom_query_tablet_data(intf, features);
1338 usb_set_intfdata(intf, wacom);
1347 fail5: wacom_destroy_leds(wacom);
1348 fail4: wacom_remove_shared_data(wacom_wac);
1351 fail1:
kfree(wacom);
1357 struct wacom *wacom = usb_get_intfdata(intf);
1359 usb_set_intfdata(intf,
NULL);
1364 input_unregister_device(wacom->
wacom_wac.input);
1365 wacom_destroy_battery(wacom);
1366 wacom_destroy_leds(wacom);
1370 wacom_remove_shared_data(&wacom->
wacom_wac);
1376 struct wacom *wacom = usb_get_intfdata(intf);
1387 struct wacom *wacom = usb_get_intfdata(intf);
1394 wacom_query_tablet_data(intf, features);
1395 wacom_led_control(wacom);
1408 return wacom_resume(intf);
1411 static struct usb_driver wacom_driver = {
1414 .probe = wacom_probe,
1415 .disconnect = wacom_disconnect,
1416 .suspend = wacom_suspend,
1417 .resume = wacom_resume,
1418 .reset_resume = wacom_reset_resume,
1419 .supports_autosuspend = 1,