25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
33 #define DRIVER_DESC "USB Hanwang tablet driver"
34 #define DRIVER_LICENSE "GPL"
40 #define USB_VENDOR_ID_HANWANG 0x0b57
41 #define HANWANG_TABLET_INT_CLASS 0x0003
42 #define HANWANG_TABLET_INT_SUB_CLASS 0x0001
43 #define HANWANG_TABLET_INT_PROTOCOL 0x0002
45 #define ART_MASTER_PKGLEN_MAX 10
48 #define STYLUS_DEVICE_ID 0x02
49 #define TOUCH_DEVICE_ID 0x03
50 #define CURSOR_DEVICE_ID 0x06
51 #define ERASER_DEVICE_ID 0x0A
52 #define PAD_DEVICE_ID 0x0F
55 #define HANWANG_TABLET_DEVICE(vend, cl, sc, pr) \
56 .match_flags = USB_DEVICE_ID_MATCH_VENDOR \
57 | USB_DEVICE_ID_MATCH_INT_INFO, \
59 .bInterfaceClass = (cl), \
60 .bInterfaceSubClass = (sc), \
61 .bInterfaceProtocol = (pr)
72 struct input_dev *
dev;
107 static const int hw_eventtypes[] = {
111 static const int hw_absevents[] = {
116 static const int hw_btnevents[] = {
122 static const int hw_mscevents[] = {
128 unsigned char *
data = hanwang->
data;
129 struct input_dev *input_dev = hanwang->
dev;
130 struct usb_device *
dev = hanwang->
usbdev;
146 input_report_key(input_dev,
154 input_report_key(input_dev,
160 switch (data[3] & 0xf0) {
176 "unknown tablet tool %02x\n", data[0]);
185 ((data[7] & 0xc0) >> 5) |
191 p = (data[7] >> 6) | (data[6] << 2);
199 input_report_abs(input_dev,
ABS_X,
201 input_report_abs(input_dev,
ABS_Y,
204 input_report_abs(input_dev,
ABS_TILT_X, data[7] & 0x3f);
205 input_report_abs(input_dev,
ABS_TILT_Y, data[8] & 0x7f);
206 input_report_key(input_dev,
BTN_STYLUS, data[1] & 0x02);
229 data[1] || data[2] || data[3]);
230 input_report_abs(input_dev,
ABS_WHEEL, data[1]);
231 input_report_key(input_dev,
BTN_0, data[2]);
232 for (i = 0; i < 8; i++)
233 input_report_key(input_dev,
234 BTN_1 + i, data[3] & (1 << i));
239 data[2] || data[3] || data[4] ||
241 input_report_abs(input_dev,
ABS_RX,
242 ((data[1] & 0x1f) << 8) | data[2]);
243 input_report_abs(input_dev,
ABS_RY,
244 ((data[3] & 0x1f) << 8) | data[4]);
245 input_report_key(input_dev,
BTN_0, data[5] & 0x01);
246 for (i = 0; i < 4; i++) {
247 input_report_key(input_dev,
248 BTN_1 + i, data[5] & (1 << i));
249 input_report_key(input_dev,
250 BTN_5 + i, data[6] & (1 << i));
255 dev_dbg(&dev->dev,
"error packet %02x\n", data[0]);
264 dev_dbg(&dev->dev,
"error packet %02x\n", data[0]);
268 input_sync(input_dev);
271 static void hanwang_irq(
struct urb *
urb)
273 struct hanwang *hanwang = urb->context;
274 struct usb_device *dev = hanwang->
usbdev;
277 switch (urb->status) {
280 hanwang_parse_packet(hanwang);
286 dev_err(&dev->dev,
"%s - urb shutting down with status: %d",
287 __func__, urb->status);
290 dev_err(&dev->dev,
"%s - nonzero urb status received: %d",
291 __func__, urb->status);
297 dev_err(&dev->dev,
"%s - usb_submit_urb failed with result %d",
301 static int hanwang_open(
struct input_dev *dev)
303 struct hanwang *hanwang = input_get_drvdata(dev);
312 static void hanwang_close(
struct input_dev *dev)
314 struct hanwang *hanwang = input_get_drvdata(dev);
319 static bool get_features(
struct usb_device *dev,
struct hanwang *hanwang)
323 for (i = 0; i <
ARRAY_SIZE(features_array); i++) {
325 features_array[
i].
pid) {
337 struct usb_device *dev = interface_to_usbdev(intf);
339 struct hanwang *hanwang;
340 struct input_dev *input_dev;
344 hanwang = kzalloc(
sizeof(
struct hanwang),
GFP_KERNEL);
345 input_dev = input_allocate_device();
346 if (!hanwang || !input_dev) {
351 if (!get_features(dev, hanwang)) {
358 if (!hanwang->
data) {
370 hanwang->
dev = input_dev;
372 usb_make_path(dev, hanwang->
phys,
sizeof(hanwang->
phys));
376 input_dev->name = hanwang->
name;
377 input_dev->phys = hanwang->
phys;
378 usb_to_input_id(dev, &input_dev->id);
379 input_dev->dev.parent = &intf->dev;
381 input_set_drvdata(input_dev, hanwang);
383 input_dev->open = hanwang_open;
384 input_dev->close = hanwang_close;
387 __set_bit(hw_eventtypes[i], input_dev->evbit);
390 __set_bit(hw_absevents[i], input_dev->absbit);
393 __set_bit(hw_btnevents[i], input_dev->keybit);
396 __set_bit(hw_mscevents[i], input_dev->mscbit);
398 input_set_abs_params(input_dev,
ABS_X,
400 input_set_abs_params(input_dev,
ABS_Y,
403 0, hanwang->
features->max_tilt_x, 0, 0);
405 0, hanwang->
features->max_tilt_y, 0, 0);
407 0, hanwang->
features->max_pressure, 0, 0);
409 endpoint = &intf->cur_altsetting->endpoint[0].desc;
410 usb_fill_int_urb(hanwang->
irq, dev,
413 hanwang_irq, hanwang, endpoint->
bInterval);
415 hanwang->
irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
417 error = input_register_device(hanwang->
dev);
421 usb_set_intfdata(intf, hanwang);
428 fail1: input_free_device(input_dev);
436 struct hanwang *hanwang = usb_get_intfdata(intf);
438 input_unregister_device(hanwang->
dev);
444 usb_set_intfdata(intf,
NULL);
455 static struct usb_driver hanwang_driver = {
457 .probe = hanwang_probe,
458 .disconnect = hanwang_disconnect,
459 .id_table = hanwang_ids,