2011-03-10 00:33:46 +05:30
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/usb/input.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2011-09-22 13:12:58 +05:30
|
|
|
#define DRIVER_VERSION "v0.3b"
|
2011-03-10 00:33:46 +05:30
|
|
|
#define DRIVER_AUTHOR "Ondra Havel <ondra.havel@gmail.com>"
|
2011-09-22 13:12:58 +05:30
|
|
|
#define DRIVER_DESC "USB Hanvon AM0806,AM1209 tablet driver"
|
2011-03-10 00:33:46 +05:30
|
|
|
#define DRIVER_LICENSE "GPL"
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE(DRIVER_LICENSE);
|
|
|
|
|
|
|
|
#define USB_VENDOR_ID_HANVON 0x0b57
|
|
|
|
|
2011-06-15 04:35:11 +05:30
|
|
|
#define B0 BTN_0
|
|
|
|
#define B1 BTN_1
|
|
|
|
#define B2 BTN_2
|
|
|
|
#define B3 BTN_3
|
|
|
|
#define WHEEL_THRESHOLD 4
|
2011-03-10 00:33:46 +05:30
|
|
|
|
|
|
|
struct hanvon {
|
|
|
|
unsigned char *data;
|
|
|
|
dma_addr_t data_dma;
|
|
|
|
struct input_dev *dev;
|
|
|
|
struct usb_device *usbdev;
|
|
|
|
struct urb *irq;
|
2011-03-11 01:14:42 +05:30
|
|
|
int old_wheel_pos;
|
2011-03-10 00:33:46 +05:30
|
|
|
char phys[32];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void hanvon_irq(struct urb *urb)
|
|
|
|
{
|
|
|
|
struct hanvon *hanvon = urb->context;
|
|
|
|
unsigned char *data = hanvon->data;
|
|
|
|
struct input_dev *dev = hanvon->dev;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
switch (urb->status) {
|
|
|
|
case 0:
|
|
|
|
/* success */
|
|
|
|
break;
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ENOENT:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* this urb is terminated, clean up */
|
|
|
|
dbg("%s - urb shutting down with status: %d", __func__, urb->status);
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
dbg("%s - nonzero urb status received: %d", __func__, urb->status);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(data[0]) {
|
|
|
|
case 0x01: // button press
|
|
|
|
if((data[2] & 0xf0) == 0xa0) {
|
2011-06-15 04:35:11 +05:30
|
|
|
input_report_key(dev, B1, data[2] & 0x02);
|
|
|
|
input_report_key(dev, B2, data[2] & 0x04);
|
|
|
|
input_report_key(dev, B3, data[2] & 0x08);
|
2011-03-10 00:33:46 +05:30
|
|
|
} else {
|
2011-03-11 01:10:16 +05:30
|
|
|
if(data[2] <= 0x3f) { // slider area active
|
2011-03-11 01:14:42 +05:30
|
|
|
int diff = data[2] - hanvon->old_wheel_pos;
|
|
|
|
if(abs(diff) < WHEEL_THRESHOLD)
|
2011-06-15 02:14:09 +05:30
|
|
|
input_report_rel(dev, REL_WHEEL, diff);
|
2011-03-11 01:10:16 +05:30
|
|
|
|
|
|
|
hanvon->old_wheel_pos = data[2];
|
|
|
|
}
|
2011-03-10 00:33:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02: // position change
|
|
|
|
if((data[1] & 0xf0) != 0) {
|
2011-06-15 04:35:11 +05:30
|
|
|
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_TILT_X, data[7] & 0x3f);
|
|
|
|
input_report_abs(dev, ABS_TILT_Y, data[8]);
|
|
|
|
input_report_abs(dev, ABS_PRESSURE, get_unaligned_be16(&data[6])>>6);
|
2011-03-10 00:33:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
input_report_key(dev, BTN_LEFT, data[1] & 0x1);
|
|
|
|
input_report_key(dev, BTN_RIGHT, data[1] & 0x2); // stylus button pressed (right click)
|
2011-06-15 04:35:11 +05:30
|
|
|
input_report_key(dev, B0, data[1] & 0x20);
|
2011-03-10 00:33:46 +05:30
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_sync(dev);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
retval = usb_submit_urb (urb, GFP_ATOMIC);
|
|
|
|
if (retval)
|
|
|
|
err("%s - usb_submit_urb failed with result %d", __func__, retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_device_id hanvon_ids[] = {
|
2011-09-22 13:12:58 +05:30
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_HANVON, 0x8501), .driver_info = 0 }, // ArtMaster 1209
|
|
|
|
{ USB_DEVICE(USB_VENDOR_ID_HANVON, 0x8502), .driver_info = 0 }, // ArtMaster 0806
|
2011-03-10 00:33:46 +05:30
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(usb, hanvon_ids);
|
|
|
|
|
|
|
|
static int hanvon_open(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct hanvon *hanvon = input_get_drvdata(dev);
|
|
|
|
|
2011-03-11 01:14:42 +05:30
|
|
|
hanvon->old_wheel_pos = -WHEEL_THRESHOLD-1;
|
2011-03-10 00:33:46 +05:30
|
|
|
hanvon->irq->dev = hanvon->usbdev;
|
|
|
|
if (usb_submit_urb(hanvon->irq, GFP_KERNEL))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hanvon_close(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct hanvon *hanvon = input_get_drvdata(dev);
|
|
|
|
|
|
|
|
usb_kill_urb(hanvon->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hanvon_probe(struct usb_interface *intf, const struct usb_device_id *id)
|
|
|
|
{
|
|
|
|
struct usb_device *dev = interface_to_usbdev(intf);
|
|
|
|
struct usb_endpoint_descriptor *endpoint;
|
|
|
|
struct hanvon *hanvon;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
int error = -ENOMEM;
|
|
|
|
|
|
|
|
hanvon = kzalloc(sizeof(struct hanvon), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!hanvon || !input_dev)
|
|
|
|
goto fail1;
|
|
|
|
|
|
|
|
hanvon->data = (unsigned char *)usb_alloc_coherent(dev, 10, GFP_KERNEL, &hanvon->data_dma);
|
|
|
|
if (!hanvon->data)
|
|
|
|
goto fail1;
|
|
|
|
|
|
|
|
hanvon->irq = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!hanvon->irq)
|
|
|
|
goto fail2;
|
|
|
|
|
|
|
|
hanvon->usbdev = dev;
|
|
|
|
hanvon->dev = input_dev;
|
|
|
|
|
|
|
|
usb_make_path(dev, hanvon->phys, sizeof(hanvon->phys));
|
|
|
|
strlcat(hanvon->phys, "/input0", sizeof(hanvon->phys));
|
|
|
|
|
|
|
|
input_dev->name = "Hanvon AM0806 Tablet";
|
|
|
|
input_dev->phys = hanvon->phys;
|
|
|
|
usb_to_input_id(dev, &input_dev->id);
|
|
|
|
input_dev->dev.parent = &intf->dev;
|
|
|
|
|
|
|
|
input_set_drvdata(input_dev, hanvon);
|
|
|
|
|
|
|
|
input_dev->open = hanvon_open;
|
|
|
|
input_dev->close = hanvon_close;
|
|
|
|
|
2011-06-15 02:14:09 +05:30
|
|
|
input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT_MASK(EV_REL);
|
2011-06-15 04:35:11 +05:30
|
|
|
//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);
|
2011-06-15 02:14:09 +05:30
|
|
|
input_dev->keybit[BIT_WORD(BTN_LEFT)] |= BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
|
2011-06-15 04:35:11 +05:30
|
|
|
__set_bit(B0, input_dev->keybit);
|
|
|
|
__set_bit(B1, input_dev->keybit);
|
|
|
|
__set_bit(B2, input_dev->keybit);
|
|
|
|
__set_bit(B3, input_dev->keybit);
|
2011-06-15 02:14:09 +05:30
|
|
|
|
2011-03-10 00:33:46 +05:30
|
|
|
input_set_abs_params(input_dev, ABS_X, 0, 0x27de, 4, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_Y, 0, 0x1cfe, 4, 0);
|
2011-06-15 04:35:11 +05:30
|
|
|
input_set_abs_params(input_dev, ABS_TILT_X, 0, 0x3f, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_TILT_Y, 0, 0x7f, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0x400, 0, 0);
|
2011-06-15 02:14:09 +05:30
|
|
|
input_set_capability(input_dev, EV_REL, REL_WHEEL);
|
2011-03-10 00:33:46 +05:30
|
|
|
|
|
|
|
endpoint = &intf->cur_altsetting->endpoint[0].desc;
|
|
|
|
|
|
|
|
usb_fill_int_urb(hanvon->irq, dev,
|
|
|
|
usb_rcvintpipe(dev, endpoint->bEndpointAddress),
|
|
|
|
hanvon->data, 10,
|
|
|
|
hanvon_irq, hanvon, endpoint->bInterval);
|
|
|
|
hanvon->irq->transfer_dma = hanvon->data_dma;
|
|
|
|
hanvon->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
|
|
|
|
|
|
|
error = input_register_device(hanvon->dev);
|
|
|
|
if (error)
|
|
|
|
goto fail3;
|
|
|
|
|
|
|
|
usb_set_intfdata(intf, hanvon);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail3: usb_free_urb(hanvon->irq);
|
|
|
|
fail2: usb_free_coherent(dev, 10, hanvon->data, hanvon->data_dma);
|
|
|
|
fail1: input_free_device(input_dev);
|
|
|
|
kfree(hanvon);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hanvon_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
struct hanvon *hanvon = usb_get_intfdata(intf);
|
|
|
|
|
|
|
|
usb_set_intfdata(intf, NULL);
|
|
|
|
if (hanvon) {
|
|
|
|
usb_kill_urb(hanvon->irq);
|
|
|
|
input_unregister_device(hanvon->dev);
|
|
|
|
usb_free_urb(hanvon->irq);
|
|
|
|
usb_free_coherent(interface_to_usbdev(intf), 10, hanvon->data, hanvon->data_dma);
|
|
|
|
kfree(hanvon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_driver hanvon_driver = {
|
|
|
|
.name = "hanvon",
|
|
|
|
.probe = hanvon_probe,
|
|
|
|
.disconnect = hanvon_disconnect,
|
|
|
|
.id_table = hanvon_ids,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hanvon_init(void)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if((rv = usb_register(&hanvon_driver)) != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
printk(DRIVER_VERSION ":" DRIVER_DESC "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit hanvon_exit(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&hanvon_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(hanvon_init);
|
|
|
|
module_exit(hanvon_exit);
|