blob: 71ec621fbefae537e35dbffe4702aecb7bdf1a63 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * A driver for the Griffin Technology, Inc. "PowerMate" USB controller dial.
3 *
4 * v1.1, (c)2002 William R Sowerbutts <will@sowerbutts.com>
5 *
6 * This device is a anodised aluminium knob which connects over USB. It can measure
7 * clockwise and anticlockwise rotation. The dial also acts as a pushbutton with
8 * a spring for automatic release. The base contains a pair of LEDs which illuminate
9 * the translucent base. It rotates without limit and reports its relative rotation
10 * back to the host when polled by the USB controller.
11 *
12 * Testing with the knob I have has shown that it measures approximately 94 "clicks"
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -050013 * for one full rotation. Testing with my High Speed Rotation Actuator (ok, it was
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * a variable speed cordless electric drill) has shown that the device can measure
15 * speeds of up to 7 clicks either clockwise or anticlockwise between pollings from
16 * the host. If it counts more than 7 clicks before it is polled, it will wrap back
17 * to zero and start counting again. This was at quite high speed, however, almost
18 * certainly faster than the human hand could turn it. Griffin say that it loses a
19 * pulse or two on a direction change; the granularity is so fine that I never
20 * noticed this in practice.
21 *
22 * The device's microcontroller can be programmed to set the LED to either a constant
23 * intensity, or to a rhythmic pulsing. Several patterns and speeds are available.
24 *
25 * Griffin were very happy to provide documentation and free hardware for development.
26 *
27 * Some userspace tools are available on the web: http://sowerbutts.com/powermate/
28 *
29 */
30
31#include <linux/kernel.h>
32#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/spinlock.h>
David Brownellae0dadc2006-06-13 10:04:34 -070036#include <linux/usb/input.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#define POWERMATE_VENDOR 0x077d /* Griffin Technology, Inc. */
39#define POWERMATE_PRODUCT_NEW 0x0410 /* Griffin PowerMate */
40#define POWERMATE_PRODUCT_OLD 0x04AA /* Griffin soundKnob */
41
42#define CONTOUR_VENDOR 0x05f3 /* Contour Design, Inc. */
43#define CONTOUR_JOG 0x0240 /* Jog and Shuttle */
44
45/* these are the command codes we send to the device */
46#define SET_STATIC_BRIGHTNESS 0x01
47#define SET_PULSE_ASLEEP 0x02
48#define SET_PULSE_AWAKE 0x03
49#define SET_PULSE_MODE 0x04
50
51/* these refer to bits in the powermate_device's requires_update field. */
52#define UPDATE_STATIC_BRIGHTNESS (1<<0)
53#define UPDATE_PULSE_ASLEEP (1<<1)
54#define UPDATE_PULSE_AWAKE (1<<2)
55#define UPDATE_PULSE_MODE (1<<3)
56
57/* at least two versions of the hardware exist, with differing payload
58 sizes. the first three bytes always contain the "interesting" data in
59 the relevant format. */
60#define POWERMATE_PAYLOAD_SIZE_MAX 6
61#define POWERMATE_PAYLOAD_SIZE_MIN 3
62struct powermate_device {
63 signed char *data;
64 dma_addr_t data_dma;
65 struct urb *irq, *config;
66 struct usb_ctrlrequest *configcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct usb_device *udev;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -050068 struct input_dev *input;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 spinlock_t lock;
70 int static_brightness;
71 int pulse_speed;
72 int pulse_table;
73 int pulse_asleep;
74 int pulse_awake;
75 int requires_update; // physical settings which are out of sync
76 char phys[64];
77};
78
79static char pm_name_powermate[] = "Griffin PowerMate";
80static char pm_name_soundknob[] = "Griffin SoundKnob";
81
David Howells7d12e782006-10-05 14:55:46 +010082static void powermate_config_complete(struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/* Callback for data arriving from the PowerMate over the USB interrupt pipe */
David Howells7d12e782006-10-05 14:55:46 +010085static void powermate_irq(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 struct powermate_device *pm = urb->context;
88 int retval;
89
90 switch (urb->status) {
91 case 0:
92 /* success */
93 break;
94 case -ECONNRESET:
95 case -ENOENT:
96 case -ESHUTDOWN:
97 /* this urb is terminated, clean up */
Harvey Harrisonea3e6c52008-05-05 11:36:18 -040098 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return;
100 default:
Harvey Harrisonea3e6c52008-05-05 11:36:18 -0400101 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 goto exit;
103 }
104
105 /* handle updates to device state */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500106 input_report_key(pm->input, BTN_0, pm->data[0] & 0x01);
107 input_report_rel(pm->input, REL_DIAL, pm->data[1]);
108 input_sync(pm->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110exit:
111 retval = usb_submit_urb (urb, GFP_ATOMIC);
112 if (retval)
Greg Kroah-Hartman2385f3c2012-04-25 14:48:30 -0700113 dev_err(&pm->udev->dev,
114 "%s - usb_submit_urb failed with result: %d\n",
115 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
118/* Decide if we need to issue a control message and do so. Must be called with pm->lock taken */
119static void powermate_sync_state(struct powermate_device *pm)
120{
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500121 if (pm->requires_update == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return; /* no updates are required */
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500123 if (pm->config->status == -EINPROGRESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return; /* an update is already in progress; it'll issue this update when it completes */
125
126 if (pm->requires_update & UPDATE_PULSE_ASLEEP){
127 pm->configcr->wValue = cpu_to_le16( SET_PULSE_ASLEEP );
128 pm->configcr->wIndex = cpu_to_le16( pm->pulse_asleep ? 1 : 0 );
129 pm->requires_update &= ~UPDATE_PULSE_ASLEEP;
130 }else if (pm->requires_update & UPDATE_PULSE_AWAKE){
131 pm->configcr->wValue = cpu_to_le16( SET_PULSE_AWAKE );
132 pm->configcr->wIndex = cpu_to_le16( pm->pulse_awake ? 1 : 0 );
133 pm->requires_update &= ~UPDATE_PULSE_AWAKE;
134 }else if (pm->requires_update & UPDATE_PULSE_MODE){
135 int op, arg;
136 /* the powermate takes an operation and an argument for its pulse algorithm.
137 the operation can be:
138 0: divide the speed
139 1: pulse at normal speed
140 2: multiply the speed
141 the argument only has an effect for operations 0 and 2, and ranges between
142 1 (least effect) to 255 (maximum effect).
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 thus, several states are equivalent and are coalesced into one state.
145
146 we map this onto a range from 0 to 510, with:
147 0 -- 254 -- use divide (0 = slowest)
148 255 -- use normal speed
149 256 -- 510 -- use multiple (510 = fastest).
150
151 Only values of 'arg' quite close to 255 are particularly useful/spectacular.
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500152 */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500153 if (pm->pulse_speed < 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 op = 0; // divide
155 arg = 255 - pm->pulse_speed;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500156 } else if (pm->pulse_speed > 255) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 op = 2; // multiply
158 arg = pm->pulse_speed - 255;
159 } else {
160 op = 1; // normal speed
161 arg = 0; // can be any value
162 }
163 pm->configcr->wValue = cpu_to_le16( (pm->pulse_table << 8) | SET_PULSE_MODE );
164 pm->configcr->wIndex = cpu_to_le16( (arg << 8) | op );
165 pm->requires_update &= ~UPDATE_PULSE_MODE;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500166 } else if (pm->requires_update & UPDATE_STATIC_BRIGHTNESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 pm->configcr->wValue = cpu_to_le16( SET_STATIC_BRIGHTNESS );
168 pm->configcr->wIndex = cpu_to_le16( pm->static_brightness );
169 pm->requires_update &= ~UPDATE_STATIC_BRIGHTNESS;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500170 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 printk(KERN_ERR "powermate: unknown update required");
172 pm->requires_update = 0; /* fudge the bug */
173 return;
174 }
175
176/* printk("powermate: %04x %04x\n", pm->configcr->wValue, pm->configcr->wIndex); */
177
178 pm->configcr->bRequestType = 0x41; /* vendor request */
179 pm->configcr->bRequest = 0x01;
180 pm->configcr->wLength = 0;
181
182 usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
183 (void *) pm->configcr, NULL, 0,
184 powermate_config_complete, pm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 if (usb_submit_urb(pm->config, GFP_ATOMIC))
187 printk(KERN_ERR "powermate: usb_submit_urb(config) failed");
188}
189
190/* Called when our asynchronous control message completes. We may need to issue another immediately */
David Howells7d12e782006-10-05 14:55:46 +0100191static void powermate_config_complete(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 struct powermate_device *pm = urb->context;
194 unsigned long flags;
195
196 if (urb->status)
197 printk(KERN_ERR "powermate: config urb returned %d\n", urb->status);
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 spin_lock_irqsave(&pm->lock, flags);
200 powermate_sync_state(pm);
201 spin_unlock_irqrestore(&pm->lock, flags);
202}
203
204/* Set the LED up as described and begin the sync with the hardware if required */
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500205static void powermate_pulse_led(struct powermate_device *pm, int static_brightness, int pulse_speed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 int pulse_table, int pulse_asleep, int pulse_awake)
207{
208 unsigned long flags;
209
210 if (pulse_speed < 0)
211 pulse_speed = 0;
212 if (pulse_table < 0)
213 pulse_table = 0;
214 if (pulse_speed > 510)
215 pulse_speed = 510;
216 if (pulse_table > 2)
217 pulse_table = 2;
218
219 pulse_asleep = !!pulse_asleep;
220 pulse_awake = !!pulse_awake;
221
222
223 spin_lock_irqsave(&pm->lock, flags);
224
225 /* mark state updates which are required */
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500226 if (static_brightness != pm->static_brightness) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 pm->static_brightness = static_brightness;
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500228 pm->requires_update |= UPDATE_STATIC_BRIGHTNESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500230 if (pulse_asleep != pm->pulse_asleep) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 pm->pulse_asleep = pulse_asleep;
232 pm->requires_update |= (UPDATE_PULSE_ASLEEP | UPDATE_STATIC_BRIGHTNESS);
233 }
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500234 if (pulse_awake != pm->pulse_awake) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 pm->pulse_awake = pulse_awake;
236 pm->requires_update |= (UPDATE_PULSE_AWAKE | UPDATE_STATIC_BRIGHTNESS);
237 }
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500238 if (pulse_speed != pm->pulse_speed || pulse_table != pm->pulse_table) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 pm->pulse_speed = pulse_speed;
240 pm->pulse_table = pulse_table;
241 pm->requires_update |= UPDATE_PULSE_MODE;
242 }
243
244 powermate_sync_state(pm);
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 spin_unlock_irqrestore(&pm->lock, flags);
247}
248
249/* Callback from the Input layer when an event arrives from userspace to configure the LED */
250static int powermate_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int _value)
251{
252 unsigned int command = (unsigned int)_value;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400253 struct powermate_device *pm = input_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 if (type == EV_MSC && code == MSC_PULSELED){
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500256 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 bits 0- 7: 8 bits: LED brightness
258 bits 8-16: 9 bits: pulsing speed modifier (0 ... 510); 0-254 = slower, 255 = standard, 256-510 = faster.
259 bits 17-18: 2 bits: pulse table (0, 1, 2 valid)
260 bit 19: 1 bit : pulse whilst asleep?
261 bit 20: 1 bit : pulse constantly?
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500262 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 int static_brightness = command & 0xFF; // bits 0-7
264 int pulse_speed = (command >> 8) & 0x1FF; // bits 8-16
265 int pulse_table = (command >> 17) & 0x3; // bits 17-18
266 int pulse_asleep = (command >> 19) & 0x1; // bit 19
267 int pulse_awake = (command >> 20) & 0x1; // bit 20
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 powermate_pulse_led(pm, static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake);
270 }
271
272 return 0;
273}
274
275static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_device *pm)
276{
Daniel Mack997ea582010-04-12 13:17:25 +0200277 pm->data = usb_alloc_coherent(udev, POWERMATE_PAYLOAD_SIZE_MAX,
278 GFP_ATOMIC, &pm->data_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (!pm->data)
280 return -1;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500281
Alan Stern0ede76f2010-03-05 15:10:17 -0500282 pm->configcr = kmalloc(sizeof(*(pm->configcr)), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (!pm->configcr)
Davidlohr Bueso6792cbb2010-09-29 18:53:35 -0700284 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 return 0;
287}
288
289static void powermate_free_buffers(struct usb_device *udev, struct powermate_device *pm)
290{
Daniel Mack997ea582010-04-12 13:17:25 +0200291 usb_free_coherent(udev, POWERMATE_PAYLOAD_SIZE_MAX,
292 pm->data, pm->data_dma);
Alan Stern0ede76f2010-03-05 15:10:17 -0500293 kfree(pm->configcr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
296/* Called whenever a USB device matching one in our supported devices table is connected */
297static int powermate_probe(struct usb_interface *intf, const struct usb_device_id *id)
298{
299 struct usb_device *udev = interface_to_usbdev (intf);
300 struct usb_host_interface *interface;
301 struct usb_endpoint_descriptor *endpoint;
302 struct powermate_device *pm;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500303 struct input_dev *input_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 int pipe, maxp;
Dmitry Torokhov50141862007-04-12 01:33:39 -0400305 int error = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 interface = intf->cur_altsetting;
308 endpoint = &interface->endpoint[0].desc;
Luiz Fernando N. Capitulino60ca1262006-09-27 11:58:53 -0700309 if (!usb_endpoint_is_int_in(endpoint))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return -EIO;
311
312 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
313 0x0a, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
314 0, interface->desc.bInterfaceNumber, NULL, 0,
315 USB_CTRL_SET_TIMEOUT);
316
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500317 pm = kzalloc(sizeof(struct powermate_device), GFP_KERNEL);
318 input_dev = input_allocate_device();
319 if (!pm || !input_dev)
320 goto fail1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500322 if (powermate_alloc_buffers(udev, pm))
323 goto fail2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 pm->irq = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500326 if (!pm->irq)
327 goto fail2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 pm->config = usb_alloc_urb(0, GFP_KERNEL);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500330 if (!pm->config)
331 goto fail3;
332
333 pm->udev = udev;
334 pm->input = input_dev;
335
336 usb_make_path(udev, pm->phys, sizeof(pm->phys));
Márton Németh6236dfa2009-11-23 08:26:38 -0800337 strlcat(pm->phys, "/input0", sizeof(pm->phys));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 spin_lock_init(&pm->lock);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500340
341 switch (le16_to_cpu(udev->descriptor.idProduct)) {
342 case POWERMATE_PRODUCT_NEW:
343 input_dev->name = pm_name_powermate;
344 break;
345 case POWERMATE_PRODUCT_OLD:
346 input_dev->name = pm_name_soundknob;
347 break;
348 default:
349 input_dev->name = pm_name_soundknob;
350 printk(KERN_WARNING "powermate: unknown product id %04x\n",
351 le16_to_cpu(udev->descriptor.idProduct));
352 }
353
354 input_dev->phys = pm->phys;
355 usb_to_input_id(udev, &input_dev->id);
Dmitry Torokhovc0f82d52007-04-12 01:35:03 -0400356 input_dev->dev.parent = &intf->dev;
Dmitry Torokhov7791bda2007-04-12 01:34:39 -0400357
358 input_set_drvdata(input_dev, pm);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500359
360 input_dev->event = powermate_input_event;
361
Jiri Slaby7b19ada2007-10-18 23:40:32 -0700362 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL) |
363 BIT_MASK(EV_MSC);
364 input_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
365 input_dev->relbit[BIT_WORD(REL_DIAL)] = BIT_MASK(REL_DIAL);
366 input_dev->mscbit[BIT_WORD(MSC_PULSELED)] = BIT_MASK(MSC_PULSELED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 /* get a handle to the interrupt data pipe */
369 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
370 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
371
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500372 if (maxp < POWERMATE_PAYLOAD_SIZE_MIN || maxp > POWERMATE_PAYLOAD_SIZE_MAX) {
373 printk(KERN_WARNING "powermate: Expected payload of %d--%d bytes, found %d bytes!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 POWERMATE_PAYLOAD_SIZE_MIN, POWERMATE_PAYLOAD_SIZE_MAX, maxp);
375 maxp = POWERMATE_PAYLOAD_SIZE_MAX;
376 }
377
378 usb_fill_int_urb(pm->irq, udev, pipe, pm->data,
379 maxp, powermate_irq,
380 pm, endpoint->bInterval);
381 pm->irq->transfer_dma = pm->data_dma;
382 pm->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
383
384 /* register our interrupt URB with the USB system */
385 if (usb_submit_urb(pm->irq, GFP_KERNEL)) {
Dmitry Torokhov50141862007-04-12 01:33:39 -0400386 error = -EIO;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500387 goto fail4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389
Dmitry Torokhov50141862007-04-12 01:33:39 -0400390 error = input_register_device(pm->input);
391 if (error)
392 goto fail5;
393
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 /* force an update of everything */
396 pm->requires_update = UPDATE_PULSE_ASLEEP | UPDATE_PULSE_AWAKE | UPDATE_PULSE_MODE | UPDATE_STATIC_BRIGHTNESS;
397 powermate_pulse_led(pm, 0x80, 255, 0, 1, 0); // set default pulse parameters
Dmitry Torokhov05f091ab2005-05-29 02:29:01 -0500398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 usb_set_intfdata(intf, pm);
400 return 0;
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500401
Dmitry Torokhov50141862007-04-12 01:33:39 -0400402 fail5: usb_kill_urb(pm->irq);
403 fail4: usb_free_urb(pm->config);
404 fail3: usb_free_urb(pm->irq);
405 fail2: powermate_free_buffers(udev, pm);
406 fail1: input_free_device(input_dev);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500407 kfree(pm);
Dmitry Torokhov50141862007-04-12 01:33:39 -0400408 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411/* Called when a USB device we've accepted ownership of is removed */
412static void powermate_disconnect(struct usb_interface *intf)
413{
414 struct powermate_device *pm = usb_get_intfdata (intf);
415
416 usb_set_intfdata(intf, NULL);
417 if (pm) {
418 pm->requires_update = 0;
419 usb_kill_urb(pm->irq);
Dmitry Torokhovc5b7c7c2005-09-15 02:01:47 -0500420 input_unregister_device(pm->input);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 usb_free_urb(pm->irq);
422 usb_free_urb(pm->config);
423 powermate_free_buffers(interface_to_usbdev(intf), pm);
424
425 kfree(pm);
426 }
427}
428
429static struct usb_device_id powermate_devices [] = {
430 { USB_DEVICE(POWERMATE_VENDOR, POWERMATE_PRODUCT_NEW) },
431 { USB_DEVICE(POWERMATE_VENDOR, POWERMATE_PRODUCT_OLD) },
432 { USB_DEVICE(CONTOUR_VENDOR, CONTOUR_JOG) },
433 { } /* Terminating entry */
434};
435
436MODULE_DEVICE_TABLE (usb, powermate_devices);
437
438static struct usb_driver powermate_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .name = "powermate",
440 .probe = powermate_probe,
441 .disconnect = powermate_disconnect,
442 .id_table = powermate_devices,
443};
444
Greg Kroah-Hartman08642e72011-11-18 09:48:31 -0800445module_usb_driver(powermate_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447MODULE_AUTHOR( "William R Sowerbutts" );
448MODULE_DESCRIPTION( "Griffin Technology, Inc PowerMate driver" );
449MODULE_LICENSE("GPL");