1 #include <linux/kernel.h>
2 #include <linux/slab.h>
3 #include <linux/module.h>
4 #include <linux/usb/input.h>
5 #include <asm/unaligned.h>
9 * v0.0.1 - Original, extremely basic version, 2.4.xx only
10 * v0.0.2 - Updated, works with 2.5.62 and 2.4.20;
11 * - added pressure-threshold modules param code from
12 * Alex Perry <alex.perry@ieee.org>
15 #define DRIVER_VERSION "v0.0.2"
16 #define DRIVER_AUTHOR "Josh Myer <josh@joshisanerd.com>"
17 #define DRIVER_DESC "USB KB Gear JamStudio Tablet driver"
18 #define DRIVER_LICENSE "GPL"
20 MODULE_AUTHOR(DRIVER_AUTHOR);
21 MODULE_DESCRIPTION(DRIVER_DESC);
22 MODULE_LICENSE(DRIVER_LICENSE);
24 #define USB_VENDOR_ID_KBGEAR 0x084e
26 static int kb_pressure_click = 0x10;
27 module_param(kb_pressure_click, int, 0);
28 MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks");
33 struct input_dev *dev;
34 struct usb_device *usbdev;
35 struct usb_interface *intf;
40 static void kbtab_irq(struct urb *urb)
42 struct kbtab *kbtab = urb->context;
43 unsigned char *data = kbtab->data;
44 struct input_dev *dev = kbtab->dev;
48 switch (urb->status) {
55 /* this urb is terminated, clean up */
56 dev_dbg(&kbtab->intf->dev,
57 "%s - urb shutting down with status: %d\n",
58 __func__, urb->status);
61 dev_dbg(&kbtab->intf->dev,
62 "%s - nonzero urb status received: %d\n",
63 __func__, urb->status);
68 input_report_key(dev, BTN_TOOL_PEN, 1);
70 input_report_abs(dev, ABS_X, get_unaligned_le16(&data[1]));
71 input_report_abs(dev, ABS_Y, get_unaligned_le16(&data[3]));
73 /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/
74 input_report_key(dev, BTN_RIGHT, data[0] & 0x02);
77 if (kb_pressure_click == -1)
78 input_report_abs(dev, ABS_PRESSURE, pressure);
80 input_report_key(dev, BTN_LEFT, pressure > kb_pressure_click ? 1 : 0);
85 retval = usb_submit_urb(urb, GFP_ATOMIC);
87 dev_err(&kbtab->intf->dev,
88 "%s - usb_submit_urb failed with result %d\n",
92 static struct usb_device_id kbtab_ids[] = {
93 { USB_DEVICE(USB_VENDOR_ID_KBGEAR, 0x1001), .driver_info = 0 },
97 MODULE_DEVICE_TABLE(usb, kbtab_ids);
99 static int kbtab_open(struct input_dev *dev)
101 struct kbtab *kbtab = input_get_drvdata(dev);
103 kbtab->irq->dev = kbtab->usbdev;
104 if (usb_submit_urb(kbtab->irq, GFP_KERNEL))
110 static void kbtab_close(struct input_dev *dev)
112 struct kbtab *kbtab = input_get_drvdata(dev);
114 usb_kill_urb(kbtab->irq);
117 static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id)
119 struct usb_device *dev = interface_to_usbdev(intf);
120 struct usb_endpoint_descriptor *endpoint;
122 struct input_dev *input_dev;
125 kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL);
126 input_dev = input_allocate_device();
127 if (!kbtab || !input_dev)
130 kbtab->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &kbtab->data_dma);
134 kbtab->irq = usb_alloc_urb(0, GFP_KERNEL);
140 kbtab->dev = input_dev;
142 usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys));
143 strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys));
145 input_dev->name = "KB Gear Tablet";
146 input_dev->phys = kbtab->phys;
147 usb_to_input_id(dev, &input_dev->id);
148 input_dev->dev.parent = &intf->dev;
150 input_set_drvdata(input_dev, kbtab);
152 input_dev->open = kbtab_open;
153 input_dev->close = kbtab_close;
155 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
156 input_dev->keybit[BIT_WORD(BTN_LEFT)] |=
157 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT);
158 input_dev->keybit[BIT_WORD(BTN_DIGI)] |=
159 BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH);
160 input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0);
161 input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0);
162 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0);
164 endpoint = &intf->cur_altsetting->endpoint[0].desc;
166 usb_fill_int_urb(kbtab->irq, dev,
167 usb_rcvintpipe(dev, endpoint->bEndpointAddress),
169 kbtab_irq, kbtab, endpoint->bInterval);
170 kbtab->irq->transfer_dma = kbtab->data_dma;
171 kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
173 error = input_register_device(kbtab->dev);
177 usb_set_intfdata(intf, kbtab);
181 fail3: usb_free_urb(kbtab->irq);
182 fail2: usb_free_coherent(dev, 8, kbtab->data, kbtab->data_dma);
183 fail1: input_free_device(input_dev);
188 static void kbtab_disconnect(struct usb_interface *intf)
190 struct kbtab *kbtab = usb_get_intfdata(intf);
192 usb_set_intfdata(intf, NULL);
194 input_unregister_device(kbtab->dev);
195 usb_free_urb(kbtab->irq);
196 usb_free_coherent(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma);
200 static struct usb_driver kbtab_driver = {
202 .probe = kbtab_probe,
203 .disconnect = kbtab_disconnect,
204 .id_table = kbtab_ids,
207 module_usb_driver(kbtab_driver);