Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6] / drivers / usb / misc / phidgetkit.c
1 /*
2  * USB PhidgetInterfaceKit driver 1.0
3  *
4  * Copyright (C) 2004, 2006 Sean Young <sean@mess.org>
5  * Copyright (C) 2005 Daniel Saakes <daniel@saakes.net>
6  * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This is a driver for the USB PhidgetInterfaceKit.
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
21 #include <linux/usb.h>
22
23 #include "phidget.h"
24
25 #define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
26 #define DRIVER_DESC "USB PhidgetInterfaceKit Driver"
27
28 #define USB_VENDOR_ID_GLAB              0x06c2
29 #define USB_DEVICE_ID_INTERFACEKIT004   0x0040
30 #define USB_DEVICE_ID_INTERFACEKIT01616 0x0044
31 #define USB_DEVICE_ID_INTERFACEKIT888   0x0045
32 #define USB_DEVICE_ID_INTERFACEKIT047   0x0051
33 #define USB_DEVICE_ID_INTERFACEKIT088   0x0053
34
35 #define USB_VENDOR_ID_WISEGROUP         0x0925
36 #define USB_DEVICE_ID_INTERFACEKIT884   0x8201
37
38 #define MAX_INTERFACES                  16
39
40 #define URB_INT_SIZE                    8
41
42 struct driver_interfacekit {
43         int sensors;
44         int inputs;
45         int outputs;
46         int has_lcd;
47 };
48 #define ifkit(_sensors, _inputs, _outputs, _lcd)                        \
49 static struct driver_interfacekit ph_##_sensors##_inputs##_outputs = {  \
50         .sensors        = _sensors,                                     \
51         .inputs         = _inputs,                                      \
52         .outputs        = _outputs,                                     \
53         .has_lcd        = _lcd,                                         \
54 };
55 ifkit(0, 0, 4, 0);
56 ifkit(8, 8, 8, 0);
57 ifkit(0, 4, 7, 1);
58 ifkit(8, 8, 4, 0);
59 ifkit(0, 8, 8, 1);
60 ifkit(0, 16, 16, 0);
61
62 static unsigned long device_no;
63
64 struct interfacekit {
65         struct usb_device *udev;
66         struct usb_interface *intf;
67         struct driver_interfacekit *ifkit;
68         struct device *dev;
69         unsigned long outputs;
70         int dev_no;
71         u8 inputs[MAX_INTERFACES];
72         u16 sensors[MAX_INTERFACES];
73         u8 lcd_files_on;
74
75         struct urb *irq;
76         unsigned char *data;
77         dma_addr_t data_dma;
78
79         struct work_struct do_notify;
80         unsigned long input_events;
81         unsigned long sensor_events;
82 };
83
84 static struct usb_device_id id_table[] = {
85         {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004),
86                 .driver_info = (kernel_ulong_t)&ph_004},
87         {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888),
88                 .driver_info = (kernel_ulong_t)&ph_888},
89         {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047),
90                 .driver_info = (kernel_ulong_t)&ph_047},
91         {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088),
92                 .driver_info = (kernel_ulong_t)&ph_088},
93         {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT01616),
94                 .driver_info = (kernel_ulong_t)&ph_01616},
95         {USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_INTERFACEKIT884),
96                 .driver_info = (kernel_ulong_t)&ph_884},
97         {}
98 };
99 MODULE_DEVICE_TABLE(usb, id_table);
100
101 static int change_outputs(struct interfacekit *kit, int output_num, int enable)
102 {
103         u8 *buffer;
104         int retval;
105
106         if (enable)
107                 set_bit(output_num, &kit->outputs);
108         else
109                 clear_bit(output_num, &kit->outputs);
110
111         buffer = kzalloc(4, GFP_KERNEL);
112         if (!buffer) {
113                 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
114                 return -ENOMEM;
115         }
116         buffer[0] = (u8)kit->outputs;
117         buffer[1] = (u8)(kit->outputs >> 8);
118
119         dev_dbg(&kit->udev->dev, "sending data: 0x%04x\n", (u16)kit->outputs);
120
121         retval = usb_control_msg(kit->udev,
122                          usb_sndctrlpipe(kit->udev, 0),
123                          0x09, 0x21, 0x0200, 0x0000, buffer, 4, 2000);
124
125         if (retval != 4)
126                 dev_err(&kit->udev->dev, "usb_control_msg returned %d\n", 
127                                 retval);
128         kfree(buffer);
129
130         return retval < 0 ? retval : 0;
131 }
132
133 static int change_string(struct interfacekit *kit, const char *display, unsigned char row)
134 {
135         unsigned char *buffer;
136         unsigned char *form_buffer;
137         int retval = -ENOMEM;
138         int i,j, len, buf_ptr;
139         
140         buffer = kmalloc(8, GFP_KERNEL);
141         form_buffer = kmalloc(30, GFP_KERNEL);
142         if ((!buffer) || (!form_buffer)) {
143                 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
144                 goto exit;
145         }
146
147         len = strlen(display);
148         if (len > 20)
149                 len = 20;
150
151         dev_dbg(&kit->udev->dev, "Setting LCD line %d to %s\n", row, display);
152
153         form_buffer[0] = row * 0x40 + 0x80;
154         form_buffer[1] = 0x02;
155         buf_ptr = 2;
156         for (i = 0; i<len; i++)
157                 form_buffer[buf_ptr++] = display[i];
158
159         for (i = 0; i < (20 - len); i++)
160                 form_buffer[buf_ptr++] = 0x20;
161         form_buffer[buf_ptr++] = 0x01;
162         form_buffer[buf_ptr++] = row * 0x40 + 0x80 + strlen(display);
163
164         for (i = 0; i < buf_ptr; i += 7) {
165                 if ((buf_ptr - i) > 7)
166                         len = 7;
167                 else
168                         len = (buf_ptr - i);
169                 for (j = 0; j < len; j++)
170                         buffer[j] = form_buffer[i + j];
171                 buffer[7] = len;
172
173                 retval = usb_control_msg(kit->udev,
174                                  usb_sndctrlpipe(kit->udev, 0),
175                                  0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
176                 if (retval < 0)
177                         goto exit;
178         }
179
180         retval = 0;
181 exit:
182         kfree(buffer);
183         kfree(form_buffer);
184
185         return retval;
186 }
187
188 #define set_lcd_line(number)    \
189 static ssize_t lcd_line_##number(struct device *dev,                    \
190                                         struct device_attribute *attr,  \
191                                         const char *buf, size_t count)  \
192 {                                                                       \
193         struct interfacekit *kit = dev_get_drvdata(dev);                \
194         change_string(kit, buf, number - 1);                            \
195         return count;                                                   \
196 }
197
198 #define lcd_line_attr(number)                                           \
199         __ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number)
200
201 set_lcd_line(1);
202 set_lcd_line(2);
203
204 static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
205 {
206         struct interfacekit *kit = dev_get_drvdata(dev);
207         int enabled;
208         unsigned char *buffer;
209         int retval = -ENOMEM;
210         
211         buffer = kzalloc(8, GFP_KERNEL);
212         if (!buffer) {
213                 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
214                 goto exit;
215         }
216
217         if (sscanf(buf, "%d", &enabled) < 1) {
218                 retval = -EINVAL;
219                 goto exit;
220         }
221         if (enabled)
222                 buffer[0] = 0x01;
223         buffer[7] = 0x11;
224
225         dev_dbg(&kit->udev->dev, "Setting backlight to %s\n", enabled ? "on" : "off");
226         
227         retval = usb_control_msg(kit->udev,
228                          usb_sndctrlpipe(kit->udev, 0),
229                          0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
230         if (retval < 0)
231                 goto exit;
232
233         retval = count;
234 exit:
235         kfree(buffer);
236         return retval;
237 }
238
239 static struct device_attribute dev_lcd_line_attrs[] = {
240         lcd_line_attr(1),
241         lcd_line_attr(2),
242         __ATTR(backlight, S_IWUGO, NULL, set_backlight)
243 };
244
245 static void remove_lcd_files(struct interfacekit *kit)
246 {
247         int i;
248
249         if (kit->lcd_files_on) {
250                 dev_dbg(&kit->udev->dev, "Removing lcd files\n");
251
252                 for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++)
253                         device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
254         }
255 }
256
257 static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
258 {
259         struct interfacekit *kit = dev_get_drvdata(dev);
260         int enable;
261         int i, rc;
262         
263         if (kit->ifkit->has_lcd == 0)
264                 return -ENODEV;
265
266         if (sscanf(buf, "%d", &enable) < 1)
267                 return -EINVAL;
268
269         if (enable) {
270                 if (!kit->lcd_files_on) {
271                         dev_dbg(&kit->udev->dev, "Adding lcd files\n");
272                         for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++) {
273                                 rc = device_create_file(kit->dev,
274                                         &dev_lcd_line_attrs[i]);
275                                 if (rc)
276                                         goto out;
277                         }
278                         kit->lcd_files_on = 1;
279                 }
280         } else {
281                 if (kit->lcd_files_on) {
282                         remove_lcd_files(kit);
283                         kit->lcd_files_on = 0;
284                 }
285         }
286         
287         return count;
288 out:
289         while (i-- > 0)
290                 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
291
292         return rc;
293 }
294
295 static DEVICE_ATTR(lcd, S_IWUGO, NULL, enable_lcd_files);
296
297 static void interfacekit_irq(struct urb *urb, struct pt_regs *regs)
298 {
299         struct interfacekit *kit = urb->context;
300         unsigned char *buffer = kit->data;
301         int i, level, sensor;
302         int status;
303
304         switch (urb->status) {
305         case 0:                 /* success */
306                 break;
307         case -ECONNRESET:       /* unlink */
308         case -ENOENT:
309         case -ESHUTDOWN:
310                 return;
311         /* -EPIPE:  should clear the halt */
312         default:                /* error */
313                 goto resubmit;
314         }
315
316         /* digital inputs */
317         if (kit->ifkit->inputs == 16) {
318                 for (i=0; i < 8; i++) {
319                         level = (buffer[0] >> i) & 1;
320                         if (kit->inputs[i] != level) {
321                                 kit->inputs[i] = level;
322                                 set_bit(i, &kit->input_events);
323                         }
324                         level = (buffer[1] >> i) & 1;
325                         if (kit->inputs[8 + i] != level) {
326                                 kit->inputs[8 + i] = level;
327                                 set_bit(8 + i, &kit->input_events);
328                         }
329                 }
330         }
331         else if (kit->ifkit->inputs == 8) {
332                 for (i=0; i < 8; i++) {
333                         level = (buffer[1] >> i) & 1;
334                         if (kit->inputs[i] != level) {
335                                 kit->inputs[i] = level;
336                                 set_bit(i, &kit->input_events);
337                         }
338                 }
339         }
340
341         /* analog inputs */
342         if (kit->ifkit->sensors) {
343                 sensor = (buffer[0] & 1) ? 4 : 0;
344
345                 level = buffer[2] + (buffer[3] & 0x0f) * 256;
346                 if (level != kit->sensors[sensor]) {
347                         kit->sensors[sensor] = level;
348                         set_bit(sensor, &kit->sensor_events);
349                 }
350                 sensor++;
351                 level = buffer[4] + (buffer[3] & 0xf0) * 16;
352                 if (level != kit->sensors[sensor]) {
353                         kit->sensors[sensor] = level;
354                         set_bit(sensor, &kit->sensor_events);
355                 }
356                 sensor++;
357                 level = buffer[5] + (buffer[6] & 0x0f) * 256;
358                 if (level != kit->sensors[sensor]) {
359                         kit->sensors[sensor] = level;
360                         set_bit(sensor, &kit->sensor_events);
361                 }
362                 sensor++;
363                 level = buffer[7] + (buffer[6] & 0xf0) * 16;
364                 if (level != kit->sensors[sensor]) {
365                         kit->sensors[sensor] = level;
366                         set_bit(sensor, &kit->sensor_events);
367                 }
368         }
369
370         if (kit->input_events || kit->sensor_events)
371                 schedule_work(&kit->do_notify);
372
373 resubmit:
374         status = usb_submit_urb(urb, SLAB_ATOMIC);
375         if (status)
376                 err("can't resubmit intr, %s-%s/interfacekit0, status %d",
377                         kit->udev->bus->bus_name,
378                         kit->udev->devpath, status);
379 }
380
381 static void do_notify(void *data)
382 {
383         struct interfacekit *kit = data;
384         int i;
385         char sysfs_file[8];
386
387         for (i=0; i<kit->ifkit->inputs; i++) {
388                 if (test_and_clear_bit(i, &kit->input_events)) {
389                         sprintf(sysfs_file, "input%d", i + 1);
390                         sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
391                 }
392         }
393
394         for (i=0; i<kit->ifkit->sensors; i++) {
395                 if (test_and_clear_bit(i, &kit->sensor_events)) {
396                         sprintf(sysfs_file, "sensor%d", i + 1);
397                         sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
398                 }
399         }
400 }
401
402 #define show_set_output(value)          \
403 static ssize_t set_output##value(struct device *dev,                    \
404                                         struct device_attribute *attr,  \
405                                         const char *buf, size_t count)  \
406 {                                                                       \
407         struct interfacekit *kit = dev_get_drvdata(dev);                \
408         int enabled;                                                    \
409         int retval;                                                     \
410                                                                         \
411         if (sscanf(buf, "%d", &enabled) < 1)                            \
412                 return -EINVAL;                                         \
413                                                                         \
414         retval = change_outputs(kit, value - 1, enabled);               \
415                                                                         \
416         return retval ? retval : count;                                 \
417 }                                                                       \
418                                                                         \
419 static ssize_t show_output##value(struct device *dev,                   \
420                                         struct device_attribute *attr,  \
421                                         char *buf)                      \
422 {                                                                       \
423         struct interfacekit *kit = dev_get_drvdata(dev);                \
424                                                                         \
425         return sprintf(buf, "%d\n", !!test_bit(value - 1, &kit->outputs));\
426 }
427
428 #define output_attr(value)                                              \
429         __ATTR(output##value, S_IWUGO | S_IRUGO,                        \
430                 show_output##value, set_output##value)
431
432 show_set_output(1);
433 show_set_output(2);
434 show_set_output(3);
435 show_set_output(4);
436 show_set_output(5);
437 show_set_output(6);
438 show_set_output(7);
439 show_set_output(8);
440 show_set_output(9);
441 show_set_output(10);
442 show_set_output(11);
443 show_set_output(12);
444 show_set_output(13);
445 show_set_output(14);
446 show_set_output(15);
447 show_set_output(16);
448
449 static struct device_attribute dev_output_attrs[] = {
450         output_attr(1), output_attr(2), output_attr(3), output_attr(4),
451         output_attr(5), output_attr(6), output_attr(7), output_attr(8),
452         output_attr(9), output_attr(10), output_attr(11), output_attr(12),
453         output_attr(13), output_attr(14), output_attr(15), output_attr(16)
454 };
455
456 #define show_input(value)       \
457 static ssize_t show_input##value(struct device *dev,                    \
458                         struct device_attribute *attr, char *buf)       \
459 {                                                                       \
460         struct interfacekit *kit = dev_get_drvdata(dev);                \
461                                                                         \
462         return sprintf(buf, "%d\n", (int)kit->inputs[value - 1]);       \
463 }
464
465 #define input_attr(value)                                               \
466         __ATTR(input##value, S_IRUGO, show_input##value, NULL)
467
468 show_input(1);
469 show_input(2);
470 show_input(3);
471 show_input(4);
472 show_input(5);
473 show_input(6);
474 show_input(7);
475 show_input(8);
476 show_input(9);
477 show_input(10);
478 show_input(11);
479 show_input(12);
480 show_input(13);
481 show_input(14);
482 show_input(15);
483 show_input(16);
484
485 static struct device_attribute dev_input_attrs[] = {
486         input_attr(1), input_attr(2), input_attr(3), input_attr(4),
487         input_attr(5), input_attr(6), input_attr(7), input_attr(8),
488         input_attr(9), input_attr(10), input_attr(11), input_attr(12),
489         input_attr(13), input_attr(14), input_attr(15), input_attr(16)
490 };
491
492 #define show_sensor(value)      \
493 static ssize_t show_sensor##value(struct device *dev,                   \
494                                         struct device_attribute *attr,  \
495                                         char *buf)                      \
496 {                                                                       \
497         struct interfacekit *kit = dev_get_drvdata(dev);                \
498                                                                         \
499         return sprintf(buf, "%d\n", (int)kit->sensors[value - 1]);      \
500 }
501
502 #define sensor_attr(value)                                              \
503         __ATTR(sensor##value, S_IRUGO, show_sensor##value, NULL)
504
505 show_sensor(1);
506 show_sensor(2);
507 show_sensor(3);
508 show_sensor(4);
509 show_sensor(5);
510 show_sensor(6);
511 show_sensor(7);
512 show_sensor(8);
513
514 static struct device_attribute dev_sensor_attrs[] = {
515         sensor_attr(1), sensor_attr(2), sensor_attr(3), sensor_attr(4),
516         sensor_attr(5), sensor_attr(6), sensor_attr(7), sensor_attr(8)
517 };
518
519 static int interfacekit_probe(struct usb_interface *intf, const struct usb_device_id *id)
520 {
521         struct usb_device *dev = interface_to_usbdev(intf);
522         struct usb_host_interface *interface;
523         struct usb_endpoint_descriptor *endpoint;
524         struct interfacekit *kit;
525         struct driver_interfacekit *ifkit;
526         int pipe, maxp, rc = -ENOMEM;
527         int bit, value, i;
528
529         ifkit = (struct driver_interfacekit *)id->driver_info;
530         if (!ifkit)
531                 return -ENODEV;
532
533         interface = intf->cur_altsetting;
534         if (interface->desc.bNumEndpoints != 1)
535                 return -ENODEV;
536
537         endpoint = &interface->endpoint[0].desc;
538         if (!(endpoint->bEndpointAddress & 0x80)) 
539                 return -ENODEV;
540         /*
541          * bmAttributes
542          */
543         pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
544         maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
545         
546         kit = kzalloc(sizeof(*kit), GFP_KERNEL);
547         if (!kit)
548                 goto out;
549
550         kit->dev_no = -1;
551         kit->ifkit = ifkit;
552         kit->data = usb_buffer_alloc(dev, URB_INT_SIZE, SLAB_ATOMIC, &kit->data_dma);
553         if (!kit->data)
554                 goto out;
555
556         kit->irq = usb_alloc_urb(0, GFP_KERNEL);
557         if (!kit->irq)
558                 goto out;
559
560         kit->udev = usb_get_dev(dev);
561         kit->intf = intf;
562         INIT_WORK(&kit->do_notify, do_notify, kit);
563         usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data,
564                         maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
565                         interfacekit_irq, kit, endpoint->bInterval);
566         kit->irq->transfer_dma = kit->data_dma;
567         kit->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
568
569         usb_set_intfdata(intf, kit);
570
571         do {
572                 bit = find_first_zero_bit(&device_no, sizeof(device_no));
573                 value = test_and_set_bit(bit, &device_no);
574         } while(value);
575         kit->dev_no = bit;
576
577         kit->dev = device_create(phidget_class, &kit->udev->dev, 0,
578                         "interfacekit%d", kit->dev_no);
579         if (IS_ERR(kit->dev)) {
580                 rc = PTR_ERR(kit->dev);
581                 kit->dev = NULL;
582                 goto out;
583         }
584         dev_set_drvdata(kit->dev, kit);
585
586         if (usb_submit_urb(kit->irq, GFP_KERNEL)) {
587                 rc = -EIO;
588                 goto out;
589         }
590
591         for (i=0; i<ifkit->outputs; i++ ) {
592                 rc = device_create_file(kit->dev, &dev_output_attrs[i]);
593                 if (rc)
594                         goto out2;
595         }
596
597         for (i=0; i<ifkit->inputs; i++ ) {
598                 rc = device_create_file(kit->dev, &dev_input_attrs[i]);
599                 if (rc)
600                         goto out3;
601         }
602
603         for (i=0; i<ifkit->sensors; i++ ) {
604                 rc = device_create_file(kit->dev, &dev_sensor_attrs[i]);
605                 if (rc)
606                         goto out4;
607         }
608
609         if (ifkit->has_lcd) {
610                 rc = device_create_file(kit->dev, &dev_attr_lcd);
611                 if (rc)
612                         goto out4;
613
614         }
615
616         dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n",
617                         ifkit->sensors, ifkit->inputs, ifkit->outputs);
618
619         return 0;
620
621 out4:
622         while (i-- > 0)
623                 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
624
625         i = ifkit->inputs;
626 out3:
627         while (i-- > 0)
628                 device_remove_file(kit->dev, &dev_input_attrs[i]);
629
630         i = ifkit->outputs;
631 out2:
632         while (i-- > 0)
633                 device_remove_file(kit->dev, &dev_output_attrs[i]);
634 out:
635         if (kit) {
636                 if (kit->irq)
637                         usb_free_urb(kit->irq);
638                 if (kit->data)
639                         usb_buffer_free(dev, URB_INT_SIZE, kit->data, kit->data_dma);
640                 if (kit->dev)
641                         device_unregister(kit->dev);
642                 if (kit->dev_no >= 0)
643                         clear_bit(kit->dev_no, &device_no);
644
645                 kfree(kit);
646         }
647
648         return rc;
649 }
650
651 static void interfacekit_disconnect(struct usb_interface *interface)
652 {
653         struct interfacekit *kit;
654         int i;
655
656         kit = usb_get_intfdata(interface);
657         usb_set_intfdata(interface, NULL);
658         if (!kit)
659                 return;
660
661         usb_kill_urb(kit->irq);
662         usb_free_urb(kit->irq);
663         usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma);
664
665         cancel_delayed_work(&kit->do_notify);
666
667         for (i=0; i<kit->ifkit->outputs; i++)
668                 device_remove_file(kit->dev, &dev_output_attrs[i]);
669
670         for (i=0; i<kit->ifkit->inputs; i++)
671                 device_remove_file(kit->dev, &dev_input_attrs[i]);
672
673         for (i=0; i<kit->ifkit->sensors; i++)
674                 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
675
676         if (kit->ifkit->has_lcd) {
677                 device_remove_file(kit->dev, &dev_attr_lcd);
678                 remove_lcd_files(kit);
679         }
680
681         device_unregister(kit->dev);
682
683         dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n",
684                 kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs);
685
686         usb_put_dev(kit->udev);
687         clear_bit(kit->dev_no, &device_no);
688
689         kfree(kit);
690 }
691
692 static struct usb_driver interfacekit_driver = {
693         .name = "phidgetkit",
694         .probe = interfacekit_probe,
695         .disconnect = interfacekit_disconnect,
696         .id_table = id_table
697 };
698
699 static int __init interfacekit_init(void)
700 {
701         int retval = 0;
702
703         retval = usb_register(&interfacekit_driver);
704         if (retval)
705                 err("usb_register failed. Error number %d", retval);
706
707         return retval;
708 }
709
710 static void __exit interfacekit_exit(void)
711 {
712         usb_deregister(&interfacekit_driver);
713 }
714
715 module_init(interfacekit_init);
716 module_exit(interfacekit_exit);
717
718 MODULE_AUTHOR(DRIVER_AUTHOR);
719 MODULE_DESCRIPTION(DRIVER_DESC);
720 MODULE_LICENSE("GPL");