v0.4 linux patch approach

This commit is contained in:
Ondra Havel 2011-11-02 20:39:35 +01:00
parent a8f4e3a2bd
commit c5f01d41af

View File

@ -5,9 +5,9 @@
#include <linux/usb/input.h> #include <linux/usb/input.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
#define DRIVER_VERSION "v0.3b" #define DRIVER_VERSION "0.4"
#define DRIVER_AUTHOR "Ondra Havel <ondra.havel@gmail.com>" #define DRIVER_AUTHOR "Ondra Havel <ondra.havel@gmail.com>"
#define DRIVER_DESC "USB Hanvon AM0806,AM1209 tablet driver" #define DRIVER_DESC "USB Hanvon Art Master I (AM0806 and AM1209) tablet driver"
#define DRIVER_LICENSE "GPL" #define DRIVER_LICENSE "GPL"
MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_AUTHOR(DRIVER_AUTHOR);
@ -15,12 +15,21 @@ MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE(DRIVER_LICENSE); MODULE_LICENSE(DRIVER_LICENSE);
#define USB_VENDOR_ID_HANVON 0x0b57 #define USB_VENDOR_ID_HANVON 0x0b57
#define USB_PRODUCT_ID_AM0806 0x8502
#define USB_PRODUCT_ID_AM1209 0x8501
#define USB_AM_PACKET_LEN 10
#define B0 BTN_0 #define AM_BUTTON_0 BTN_0
#define B1 BTN_1 #define AM_BUTTON_1 BTN_1
#define B2 BTN_2 #define AM_BUTTON_2 BTN_2
#define B3 BTN_3 #define AM_BUTTON_3 BTN_3
#define WHEEL_THRESHOLD 4 #define AM_WHEEL_THRESHOLD 4
#define AM_MAX_ABS_X 0x27de
#define AM_MAX_ABS_Y 0x1cfe
#define AM_MAX_TILT_X 0x3f
#define AM_MAX_TILT_Y 0x7f
#define AM_MAX_PRESSURE 0x400
struct hanvon { struct hanvon {
unsigned char *data; unsigned char *data;
@ -55,24 +64,23 @@ static void hanvon_irq(struct urb *urb)
} }
switch(data[0]) { switch(data[0]) {
case 0x01: // button press case 0x01: /* button press */
if((data[2] & 0xf0) == 0xa0) { if((data[2] & 0xf0) == 0xa0) {
input_report_key(dev, B1, data[2] & 0x02); input_report_key(dev, AM_BUTTON_1, data[2] & 0x02);
input_report_key(dev, B2, data[2] & 0x04); input_report_key(dev, AM_BUTTON_2, data[2] & 0x04);
input_report_key(dev, B3, data[2] & 0x08); input_report_key(dev, AM_BUTTON_3, data[2] & 0x08);
} else { } else {
if(data[2] <= 0x3f) { // slider area active if(data[2] <= 0x3f) { /* slider area active */
int diff = data[2] - hanvon->old_wheel_pos; int diff = data[2] - hanvon->old_wheel_pos;
if(abs(diff) < WHEEL_THRESHOLD) if(abs(diff) < AM_WHEEL_THRESHOLD)
input_report_rel(dev, REL_WHEEL, diff); input_report_rel(dev, REL_WHEEL, diff);
hanvon->old_wheel_pos = data[2]; hanvon->old_wheel_pos = data[2];
} }
} }
break; break;
case 0x02: // position change case 0x02: /* position change */
if((data[1] & 0xf0) != 0) { if((data[1] & 0xf0) != 0) {
input_report_abs(dev, ABS_X, get_unaligned_be16(&data[2])); input_report_abs(dev, ABS_X, get_unaligned_be16(&data[2]));
input_report_abs(dev, ABS_Y, get_unaligned_be16(&data[4])); input_report_abs(dev, ABS_Y, get_unaligned_be16(&data[4]));
@ -82,9 +90,8 @@ static void hanvon_irq(struct urb *urb)
} }
input_report_key(dev, BTN_LEFT, data[1] & 0x1); input_report_key(dev, BTN_LEFT, data[1] & 0x1);
input_report_key(dev, BTN_RIGHT, data[1] & 0x2); // stylus button pressed (right click) input_report_key(dev, BTN_RIGHT, data[1] & 0x2); /* stylus button pressed (right click) */
input_report_key(dev, B0, data[1] & 0x20); input_report_key(dev, AM_BUTTON_0, data[1] & 0x20);
break; break;
} }
@ -97,8 +104,8 @@ exit:
} }
static struct usb_device_id hanvon_ids[] = { static struct usb_device_id hanvon_ids[] = {
{ USB_DEVICE(USB_VENDOR_ID_HANVON, 0x8501), .driver_info = 0 }, // ArtMaster 1209 { USB_DEVICE(USB_VENDOR_ID_HANVON, USB_PRODUCT_ID_AM1209) },
{ USB_DEVICE(USB_VENDOR_ID_HANVON, 0x8502), .driver_info = 0 }, // ArtMaster 0806 { USB_DEVICE(USB_VENDOR_ID_HANVON, USB_PRODUCT_ID_AM0806) },
{ } { }
}; };
@ -108,7 +115,7 @@ static int hanvon_open(struct input_dev *dev)
{ {
struct hanvon *hanvon = input_get_drvdata(dev); struct hanvon *hanvon = input_get_drvdata(dev);
hanvon->old_wheel_pos = -WHEEL_THRESHOLD-1; hanvon->old_wheel_pos = -AM_WHEEL_THRESHOLD-1;
hanvon->irq->dev = hanvon->usbdev; hanvon->irq->dev = hanvon->usbdev;
if (usb_submit_urb(hanvon->irq, GFP_KERNEL)) if (usb_submit_urb(hanvon->irq, GFP_KERNEL))
return -EIO; return -EIO;
@ -136,7 +143,7 @@ static int hanvon_probe(struct usb_interface *intf, const struct usb_device_id *
if (!hanvon || !input_dev) if (!hanvon || !input_dev)
goto fail1; goto fail1;
hanvon->data = (unsigned char *)usb_alloc_coherent(dev, 10, GFP_KERNEL, &hanvon->data_dma); hanvon->data = (unsigned char *)usb_alloc_coherent(dev, USB_AM_PACKET_LEN, GFP_KERNEL, &hanvon->data_dma);
if (!hanvon->data) if (!hanvon->data)
goto fail1; goto fail1;
@ -150,7 +157,7 @@ static int hanvon_probe(struct usb_interface *intf, const struct usb_device_id *
usb_make_path(dev, hanvon->phys, sizeof(hanvon->phys)); usb_make_path(dev, hanvon->phys, sizeof(hanvon->phys));
strlcat(hanvon->phys, "/input0", sizeof(hanvon->phys)); strlcat(hanvon->phys, "/input0", sizeof(hanvon->phys));
input_dev->name = "Hanvon AM0806 Tablet"; input_dev->name = "Hanvon Art Master Tablet";
input_dev->phys = hanvon->phys; input_dev->phys = hanvon->phys;
usb_to_input_id(dev, &input_dev->id); usb_to_input_id(dev, &input_dev->id);
input_dev->dev.parent = &intf->dev; input_dev->dev.parent = &intf->dev;
@ -161,26 +168,25 @@ static int hanvon_probe(struct usb_interface *intf, const struct usb_device_id *
input_dev->close = hanvon_close; input_dev->close = hanvon_close;
input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT_MASK(EV_REL); input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT_MASK(EV_REL);
//input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(B0) | BIT_MASK(B1) | BIT_MASK(B2) | BIT_MASK(B3) |
input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH); input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH);
input_dev->keybit[BIT_WORD(BTN_LEFT)] |= BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); input_dev->keybit[BIT_WORD(BTN_LEFT)] |= BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
__set_bit(B0, input_dev->keybit); __set_bit(AM_BUTTON_0, input_dev->keybit);
__set_bit(B1, input_dev->keybit); __set_bit(AM_BUTTON_1, input_dev->keybit);
__set_bit(B2, input_dev->keybit); __set_bit(AM_BUTTON_2, input_dev->keybit);
__set_bit(B3, input_dev->keybit); __set_bit(AM_BUTTON_3, input_dev->keybit);
input_set_abs_params(input_dev, ABS_X, 0, 0x27de, 4, 0); input_set_abs_params(input_dev, ABS_X, 0, AM_MAX_ABS_X, 4, 0);
input_set_abs_params(input_dev, ABS_Y, 0, 0x1cfe, 4, 0); input_set_abs_params(input_dev, ABS_Y, 0, AM_MAX_ABS_Y, 4, 0);
input_set_abs_params(input_dev, ABS_TILT_X, 0, 0x3f, 0, 0); input_set_abs_params(input_dev, ABS_TILT_X, 0, AM_MAX_TILT_X, 0, 0);
input_set_abs_params(input_dev, ABS_TILT_Y, 0, 0x7f, 0, 0); input_set_abs_params(input_dev, ABS_TILT_Y, 0, AM_MAX_TILT_Y, 0, 0);
input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0x400, 0, 0); input_set_abs_params(input_dev, ABS_PRESSURE, 0, AM_MAX_PRESSURE, 0, 0);
input_set_capability(input_dev, EV_REL, REL_WHEEL); input_set_capability(input_dev, EV_REL, REL_WHEEL);
endpoint = &intf->cur_altsetting->endpoint[0].desc; endpoint = &intf->cur_altsetting->endpoint[0].desc;
usb_fill_int_urb(hanvon->irq, dev, usb_fill_int_urb(hanvon->irq, dev,
usb_rcvintpipe(dev, endpoint->bEndpointAddress), usb_rcvintpipe(dev, endpoint->bEndpointAddress),
hanvon->data, 10, hanvon->data, USB_AM_PACKET_LEN,
hanvon_irq, hanvon, endpoint->bInterval); hanvon_irq, hanvon, endpoint->bInterval);
hanvon->irq->transfer_dma = hanvon->data_dma; hanvon->irq->transfer_dma = hanvon->data_dma;
hanvon->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; hanvon->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
@ -192,9 +198,9 @@ static int hanvon_probe(struct usb_interface *intf, const struct usb_device_id *
usb_set_intfdata(intf, hanvon); usb_set_intfdata(intf, hanvon);
return 0; return 0;
fail3: usb_free_urb(hanvon->irq); fail3: usb_free_urb(hanvon->irq);
fail2: usb_free_coherent(dev, 10, hanvon->data, hanvon->data_dma); fail2: usb_free_coherent(dev, USB_AM_PACKET_LEN, hanvon->data, hanvon->data_dma);
fail1: input_free_device(input_dev); fail1: input_free_device(input_dev);
kfree(hanvon); kfree(hanvon);
return error; return error;
} }
@ -208,7 +214,7 @@ static void hanvon_disconnect(struct usb_interface *intf)
usb_kill_urb(hanvon->irq); usb_kill_urb(hanvon->irq);
input_unregister_device(hanvon->dev); input_unregister_device(hanvon->dev);
usb_free_urb(hanvon->irq); usb_free_urb(hanvon->irq);
usb_free_coherent(interface_to_usbdev(intf), 10, hanvon->data, hanvon->data_dma); usb_free_coherent(interface_to_usbdev(intf), USB_AM_PACKET_LEN, hanvon->data, hanvon->data_dma);
kfree(hanvon); kfree(hanvon);
} }
} }
@ -227,7 +233,7 @@ static int __init hanvon_init(void)
if((rv = usb_register(&hanvon_driver)) != 0) if((rv = usb_register(&hanvon_driver)) != 0)
return rv; return rv;
printk(DRIVER_VERSION ":" DRIVER_DESC "\n"); printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" DRIVER_DESC "\n");
return 0; return 0;
} }