Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/kernel.h> |
2 | #include <linux/slab.h> | |
1da177e4 LT |
3 | #include <linux/module.h> |
4 | #include <linux/init.h> | |
ae0dadcf | 5 | #include <linux/usb/input.h> |
1da177e4 | 6 | #include <asm/unaligned.h> |
1da177e4 LT |
7 | |
8 | /* | |
9 | * Version Information | |
10 | * v0.0.1 - Original, extremely basic version, 2.4.xx only | |
11 | * v0.0.2 - Updated, works with 2.5.62 and 2.4.20; | |
12 | * - added pressure-threshold modules param code from | |
13 | * Alex Perry <alex.perry@ieee.org> | |
14 | */ | |
15 | ||
16 | #define DRIVER_VERSION "v0.0.2" | |
17 | #define DRIVER_AUTHOR "Josh Myer <josh@joshisanerd.com>" | |
18 | #define DRIVER_DESC "USB KB Gear JamStudio Tablet driver" | |
19 | #define DRIVER_LICENSE "GPL" | |
20 | ||
21 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
22 | MODULE_DESCRIPTION(DRIVER_DESC); | |
23 | MODULE_LICENSE(DRIVER_LICENSE); | |
24 | ||
25 | #define USB_VENDOR_ID_KBGEAR 0x084e | |
26 | ||
27 | static int kb_pressure_click = 0x10; | |
28 | module_param(kb_pressure_click, int, 0); | |
29 | MODULE_PARM_DESC(kb_pressure_click, "pressure threshold for clicks"); | |
30 | ||
31 | struct kbtab { | |
4ee1fc8e | 32 | unsigned char *data; |
1da177e4 | 33 | dma_addr_t data_dma; |
c5b7c7c3 | 34 | struct input_dev *dev; |
1da177e4 | 35 | struct usb_device *usbdev; |
ed2b2f2d | 36 | struct usb_interface *intf; |
1da177e4 | 37 | struct urb *irq; |
1da177e4 LT |
38 | char phys[32]; |
39 | }; | |
40 | ||
7d12e780 | 41 | static void kbtab_irq(struct urb *urb) |
1da177e4 LT |
42 | { |
43 | struct kbtab *kbtab = urb->context; | |
44 | unsigned char *data = kbtab->data; | |
c5b7c7c3 | 45 | struct input_dev *dev = kbtab->dev; |
f3192090 | 46 | int pressure; |
1da177e4 LT |
47 | int retval; |
48 | ||
49 | switch (urb->status) { | |
50 | case 0: | |
51 | /* success */ | |
52 | break; | |
53 | case -ECONNRESET: | |
54 | case -ENOENT: | |
55 | case -ESHUTDOWN: | |
56 | /* this urb is terminated, clean up */ | |
ed2b2f2d GKH |
57 | dev_dbg(&kbtab->intf->dev, |
58 | "%s - urb shutting down with status: %d\n", | |
6d0f7dcb | 59 | __func__, urb->status); |
1da177e4 LT |
60 | return; |
61 | default: | |
ed2b2f2d GKH |
62 | dev_dbg(&kbtab->intf->dev, |
63 | "%s - nonzero urb status received: %d\n", | |
6d0f7dcb | 64 | __func__, urb->status); |
1da177e4 LT |
65 | goto exit; |
66 | } | |
67 | ||
1da177e4 LT |
68 | |
69 | input_report_key(dev, BTN_TOOL_PEN, 1); | |
70 | ||
f3192090 DT |
71 | input_report_abs(dev, ABS_X, get_unaligned_le16(&data[1])); |
72 | input_report_abs(dev, ABS_Y, get_unaligned_le16(&data[3])); | |
1da177e4 LT |
73 | |
74 | /*input_report_key(dev, BTN_TOUCH , data[0] & 0x01);*/ | |
75 | input_report_key(dev, BTN_RIGHT, data[0] & 0x02); | |
76 | ||
f3192090 DT |
77 | pressure = data[5]; |
78 | if (kb_pressure_click == -1) | |
79 | input_report_abs(dev, ABS_PRESSURE, pressure); | |
80 | else | |
81 | input_report_key(dev, BTN_LEFT, pressure > kb_pressure_click ? 1 : 0); | |
05f091ab | 82 | |
1da177e4 LT |
83 | input_sync(dev); |
84 | ||
85 | exit: | |
f3192090 | 86 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
1da177e4 | 87 | if (retval) |
ed2b2f2d | 88 | dev_err(&kbtab->intf->dev, |
202712c2 GKH |
89 | "%s - usb_submit_urb failed with result %d\n", |
90 | __func__, retval); | |
1da177e4 LT |
91 | } |
92 | ||
93 | static struct usb_device_id kbtab_ids[] = { | |
94 | { USB_DEVICE(USB_VENDOR_ID_KBGEAR, 0x1001), .driver_info = 0 }, | |
95 | { } | |
96 | }; | |
97 | ||
98 | MODULE_DEVICE_TABLE(usb, kbtab_ids); | |
99 | ||
100 | static int kbtab_open(struct input_dev *dev) | |
101 | { | |
7791bdae | 102 | struct kbtab *kbtab = input_get_drvdata(dev); |
1da177e4 | 103 | |
1da177e4 | 104 | kbtab->irq->dev = kbtab->usbdev; |
65cde54b | 105 | if (usb_submit_urb(kbtab->irq, GFP_KERNEL)) |
1da177e4 | 106 | return -EIO; |
1da177e4 LT |
107 | |
108 | return 0; | |
109 | } | |
110 | ||
111 | static void kbtab_close(struct input_dev *dev) | |
112 | { | |
7791bdae | 113 | struct kbtab *kbtab = input_get_drvdata(dev); |
1da177e4 | 114 | |
65cde54b | 115 | usb_kill_urb(kbtab->irq); |
1da177e4 LT |
116 | } |
117 | ||
118 | static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *id) | |
119 | { | |
120 | struct usb_device *dev = interface_to_usbdev(intf); | |
121 | struct usb_endpoint_descriptor *endpoint; | |
122 | struct kbtab *kbtab; | |
c5b7c7c3 | 123 | struct input_dev *input_dev; |
5014186d | 124 | int error = -ENOMEM; |
1da177e4 | 125 | |
3f25fb3f JH |
126 | if (intf->cur_altsetting->desc.bNumEndpoints < 1) |
127 | return -ENODEV; | |
128 | ||
c5b7c7c3 DT |
129 | kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL); |
130 | input_dev = input_allocate_device(); | |
131 | if (!kbtab || !input_dev) | |
132 | goto fail1; | |
1da177e4 | 133 | |
997ea58e | 134 | kbtab->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &kbtab->data_dma); |
c5b7c7c3 DT |
135 | if (!kbtab->data) |
136 | goto fail1; | |
1da177e4 LT |
137 | |
138 | kbtab->irq = usb_alloc_urb(0, GFP_KERNEL); | |
c5b7c7c3 DT |
139 | if (!kbtab->irq) |
140 | goto fail2; | |
1da177e4 | 141 | |
c5b7c7c3 | 142 | kbtab->usbdev = dev; |
ed2b2f2d | 143 | kbtab->intf = intf; |
c5b7c7c3 | 144 | kbtab->dev = input_dev; |
05f091ab | 145 | |
c5b7c7c3 DT |
146 | usb_make_path(dev, kbtab->phys, sizeof(kbtab->phys)); |
147 | strlcat(kbtab->phys, "/input0", sizeof(kbtab->phys)); | |
1da177e4 | 148 | |
c5b7c7c3 DT |
149 | input_dev->name = "KB Gear Tablet"; |
150 | input_dev->phys = kbtab->phys; | |
151 | usb_to_input_id(dev, &input_dev->id); | |
c0f82d57 | 152 | input_dev->dev.parent = &intf->dev; |
7791bdae DT |
153 | |
154 | input_set_drvdata(input_dev, kbtab); | |
1da177e4 | 155 | |
c5b7c7c3 DT |
156 | input_dev->open = kbtab_open; |
157 | input_dev->close = kbtab_close; | |
1da177e4 | 158 | |
f3192090 DT |
159 | input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
160 | input_dev->keybit[BIT_WORD(BTN_LEFT)] |= | |
161 | BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); | |
162 | input_dev->keybit[BIT_WORD(BTN_DIGI)] |= | |
163 | BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_TOUCH); | |
c5b7c7c3 | 164 | input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0); |
19947544 | 165 | input_set_abs_params(input_dev, ABS_Y, 0, 0x1750, 4, 0); |
c5b7c7c3 | 166 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, 0xff, 0, 0); |
1da177e4 LT |
167 | |
168 | endpoint = &intf->cur_altsetting->endpoint[0].desc; | |
169 | ||
170 | usb_fill_int_urb(kbtab->irq, dev, | |
171 | usb_rcvintpipe(dev, endpoint->bEndpointAddress), | |
172 | kbtab->data, 8, | |
173 | kbtab_irq, kbtab, endpoint->bInterval); | |
174 | kbtab->irq->transfer_dma = kbtab->data_dma; | |
175 | kbtab->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | |
176 | ||
5014186d DT |
177 | error = input_register_device(kbtab->dev); |
178 | if (error) | |
179 | goto fail3; | |
1da177e4 LT |
180 | |
181 | usb_set_intfdata(intf, kbtab); | |
5014186d | 182 | |
1da177e4 | 183 | return 0; |
c5b7c7c3 | 184 | |
5014186d | 185 | fail3: usb_free_urb(kbtab->irq); |
7a9b1492 | 186 | fail2: usb_free_coherent(dev, 8, kbtab->data, kbtab->data_dma); |
5014186d | 187 | fail1: input_free_device(input_dev); |
c5b7c7c3 | 188 | kfree(kbtab); |
5014186d | 189 | return error; |
1da177e4 LT |
190 | } |
191 | ||
192 | static void kbtab_disconnect(struct usb_interface *intf) | |
193 | { | |
c5b7c7c3 | 194 | struct kbtab *kbtab = usb_get_intfdata(intf); |
1da177e4 LT |
195 | |
196 | usb_set_intfdata(intf, NULL); | |
331cb022 DT |
197 | |
198 | input_unregister_device(kbtab->dev); | |
199 | usb_free_urb(kbtab->irq); | |
7a9b1492 | 200 | usb_free_coherent(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma); |
331cb022 | 201 | kfree(kbtab); |
1da177e4 LT |
202 | } |
203 | ||
204 | static struct usb_driver kbtab_driver = { | |
1da177e4 LT |
205 | .name = "kbtab", |
206 | .probe = kbtab_probe, | |
207 | .disconnect = kbtab_disconnect, | |
208 | .id_table = kbtab_ids, | |
209 | }; | |
210 | ||
08642e7c | 211 | module_usb_driver(kbtab_driver); |