packaging: install license for rpm package instead of license package
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / usb / gadget / f_sdb.c
1 /*
2  * Gadget Driver for Samsung SDB (based on Android ADB)
3  *
4  * Copyright (C) 2008 Google, Inc.
5  * Author: Mike Lockwood <lockwood@android.com>
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17
18 /* #define DEBUG */
19 /* #define VERBOSE_DEBUG */
20
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/poll.h>
24 #include <linux/delay.h>
25 #include <linux/sched.h>
26 #include <linux/wait.h>
27 #include <linux/err.h>
28 #include <linux/interrupt.h>
29
30 #include <linux/types.h>
31 #include <linux/device.h>
32 #include <linux/miscdevice.h>
33
34 #define SDB_BULK_BUFFER_SIZE           4096
35
36 /* number of tx requests to allocate */
37 #define SDB_TX_REQ_MAX 4
38
39 static const char sdb_shortname[] = "samsung_sdb";
40
41 static DEFINE_MUTEX(sdb_lock);
42
43 struct sdb_ep_descs {
44         struct usb_endpoint_descriptor  *in;
45         struct usb_endpoint_descriptor  *out;
46 };
47
48 struct f_sdb {
49         struct usb_function function;
50         u8      inf_id;
51
52         struct sdb_ep_descs     fs;
53         struct sdb_ep_descs hs;
54
55         struct usb_ep *ep_in;
56         struct usb_ep *ep_out;
57
58         struct list_head bulk_in_q;
59 };
60
61 struct sdb_dev {
62         struct f_sdb *sdb_func;
63         spinlock_t lock;
64
65         int online;
66         int error;
67
68         atomic_t read_excl;
69         atomic_t write_excl;
70         atomic_t open_excl;
71
72         struct list_head *tx_idle;
73
74         wait_queue_head_t read_wq;
75         wait_queue_head_t write_wq;
76
77         struct usb_request *rx_req;
78         int rx_done;
79 };
80
81 static struct usb_interface_descriptor sdb_interface_desc = {
82         .bLength                = USB_DT_INTERFACE_SIZE,
83         .bDescriptorType        = USB_DT_INTERFACE,
84         /* .bInterfaceNumber    = DYNAMIC */
85         .bNumEndpoints          = 2,
86         .bInterfaceClass        = 0xFF,
87         .bInterfaceSubClass     = 0x20,
88         .bInterfaceProtocol     = 0x02,
89         /* .iInterface                  = DYNAMIC */
90 };
91
92 static struct usb_endpoint_descriptor sdb_fullspeed_in_desc = {
93         .bLength                = USB_DT_ENDPOINT_SIZE,
94         .bDescriptorType        = USB_DT_ENDPOINT,
95         .bEndpointAddress       = USB_DIR_IN,
96         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
97         /* .wMaxPacketSize set by autoconfiguration */
98 };
99
100 static struct usb_endpoint_descriptor sdb_fullspeed_out_desc = {
101         .bLength                = USB_DT_ENDPOINT_SIZE,
102         .bDescriptorType        = USB_DT_ENDPOINT,
103         .bEndpointAddress       = USB_DIR_OUT,
104         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
105         /* .wMaxPacketSize set by autoconfiguration */
106 };
107
108 static struct usb_descriptor_header *fs_sdb_descs[] = {
109         (struct usb_descriptor_header *) &sdb_interface_desc,
110         (struct usb_descriptor_header *) &sdb_fullspeed_in_desc,
111         (struct usb_descriptor_header *) &sdb_fullspeed_out_desc,
112         NULL,
113 };
114
115 static struct usb_endpoint_descriptor sdb_highspeed_in_desc = {
116         .bLength                = USB_DT_ENDPOINT_SIZE,
117         .bDescriptorType        = USB_DT_ENDPOINT,
118         /* bEndpointAddress copied from sdb_fullspeed_in_desc
119                 during sdb_function_bind() */
120         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
121         .wMaxPacketSize         = cpu_to_le16(512),
122 };
123
124 static struct usb_endpoint_descriptor sdb_highspeed_out_desc = {
125         .bLength                = USB_DT_ENDPOINT_SIZE,
126         .bDescriptorType        = USB_DT_ENDPOINT,
127         /* bEndpointAddress copied from sdb_fullspeed_in_desc
128                 during sdb_function_bind() */
129         .bmAttributes           = USB_ENDPOINT_XFER_BULK,
130         .wMaxPacketSize         = cpu_to_le16(512),
131 };
132
133 static struct usb_descriptor_header *hs_sdb_descs[] = {
134         (struct usb_descriptor_header *) &sdb_interface_desc,
135         (struct usb_descriptor_header *) &sdb_highspeed_in_desc,
136         (struct usb_descriptor_header *) &sdb_highspeed_out_desc,
137         NULL,
138 };
139
140 /* string descriptors: */
141
142 #define F_SDB_IDX       0
143
144 /* static strings, in UTF-8 */
145 static struct usb_string sdb_string_defs[] = {
146         [F_SDB_IDX].s = "Samsung SDB",
147         {  /* ZEROES END LIST */ },
148 };
149
150 static struct usb_gadget_strings sdb_string_table = {
151         .language =             0x0409, /* en-us */
152         .strings =              sdb_string_defs,
153 };
154
155 static struct usb_gadget_strings *sdb_strings[] = {
156         &sdb_string_table,
157         NULL,
158 };
159
160 /* temporary variable used between sdb_open() and sdb_gadget_bind() */
161 static struct sdb_dev *_sdb_dev;
162
163 static inline struct f_sdb *func_to_sdb(struct usb_function *f)
164 {
165         return container_of(f, struct f_sdb, function);
166 }
167
168 static struct usb_request *sdb_request_new(struct usb_ep *ep, int buffer_size)
169 {
170         struct usb_request *req = usb_ep_alloc_request(ep, GFP_KERNEL);
171         if (!req)
172                 return NULL;
173
174         /* now allocate buffers for the requests */
175         req->buf = kmalloc(buffer_size, GFP_KERNEL);
176         if (!req->buf) {
177                 usb_ep_free_request(ep, req);
178                 return NULL;
179         }
180
181         return req;
182 }
183
184 static void sdb_request_free(struct usb_request *req, struct usb_ep *ep)
185 {
186         if (req) {
187                 kfree(req->buf);
188                 usb_ep_free_request(ep, req);
189         }
190 }
191
192 static inline int _sdb_lock(atomic_t *excl)
193 {
194         if (atomic_inc_return(excl) == 1) {
195                 return 0;
196         } else {
197                 atomic_dec(excl);
198                 return -EBUSY;
199         }
200 }
201
202 static inline void _sdb_unlock(atomic_t *excl)
203 {
204         atomic_dec(excl);
205 }
206
207 /* add a request to the tail of a list */
208 static void sdb_req_put(struct sdb_dev *dev, struct list_head *head,
209                 struct usb_request *req)
210 {
211         unsigned long flags;
212
213         if (!dev || !req)
214                 return;
215
216         spin_lock_irqsave(&dev->lock, flags);
217         if (head)
218                 list_add_tail(&req->list, head);
219         spin_unlock_irqrestore(&dev->lock, flags);
220 }
221
222 /* remove a request from the head of a list */
223 static struct usb_request *sdb_req_get(struct sdb_dev *dev,
224                                 struct list_head *head)
225 {
226         unsigned long flags;
227         struct usb_request *req;
228
229         if (!dev)
230                 return NULL;
231
232         spin_lock_irqsave(&dev->lock, flags);
233         if (!head)
234                 req = NULL;
235         else {
236                 if (list_empty(head)) {
237                         req = NULL;
238                 } else {
239                         req = list_first_entry(head, struct usb_request, list);
240                         list_del(&req->list);
241                 }
242         }
243         spin_unlock_irqrestore(&dev->lock, flags);
244         return req;
245 }
246
247 static void sdb_complete_in(struct usb_ep *ep, struct usb_request *req)
248 {
249         struct sdb_dev *dev = _sdb_dev;
250         struct f_sdb *sdb_func = ep->driver_data;
251
252         if (req->status != 0)
253                 dev->error = 1;
254
255         sdb_req_put(dev, &sdb_func->bulk_in_q, req);
256         wake_up(&dev->write_wq);
257 }
258
259 static void sdb_complete_out(struct usb_ep *ep, struct usb_request *req)
260 {
261         struct sdb_dev *dev = _sdb_dev;
262
263         dev->rx_done = 1;
264         if (req->status != 0)
265                 dev->error = 1;
266
267         wake_up(&dev->read_wq);
268 }
269
270 static int sdb_create_bulk_endpoints(struct f_sdb *sdb_func,
271                                 struct usb_endpoint_descriptor *in_desc,
272                                 struct usb_endpoint_descriptor *out_desc)
273 {
274         struct usb_composite_dev *cdev = sdb_func->function.config->cdev;
275         struct usb_request *req;
276         struct sdb_dev *dev = _sdb_dev;
277         struct usb_ep *ep;
278         int i;
279
280         DBG(cdev, "sdb_create_bulk_endpoints dev: %p\n", dev);
281
282         ep = usb_ep_autoconfig(cdev->gadget, in_desc);
283         if (!ep) {
284                 ERROR(cdev, "usb_ep_autoconfig for ep_in failed\n");
285                 return -ENODEV;
286         }
287         DBG(cdev, "usb_ep_autoconfig for ep_in got %s\n", ep->name);
288         ep->driver_data = cdev;         /* claim the endpoint */
289         sdb_func->ep_in = ep;
290
291         ep = usb_ep_autoconfig(cdev->gadget, out_desc);
292         if (!ep) {
293                 ERROR(cdev, "usb_ep_autoconfig for ep_out failed\n");
294                 return -ENODEV;
295         }
296         DBG(cdev, "usb_ep_autoconfig for sdb ep_out got %s\n", ep->name);
297         ep->driver_data = cdev;         /* claim the endpoint */
298         sdb_func->ep_out = ep;
299
300         /* now allocate requests for our endpoints */
301         req = sdb_request_new(sdb_func->ep_out, SDB_BULK_BUFFER_SIZE);
302         if (!req)
303                 return -ENOMEM;
304         req->complete = sdb_complete_out;
305         dev->rx_req = req;
306
307         for (i = 0; i < SDB_TX_REQ_MAX; i++) {
308                 req = sdb_request_new(sdb_func->ep_in, SDB_BULK_BUFFER_SIZE);
309                 if (!req)
310                         goto fail;
311                 req->complete = sdb_complete_in;
312                 sdb_req_put(dev, &sdb_func->bulk_in_q, req);
313         }
314
315         return 0;
316
317 fail:
318         while (!!(req = sdb_req_get(dev, &sdb_func->bulk_in_q)))
319                 sdb_request_free(req, sdb_func->ep_in);
320
321         sdb_request_free(dev->rx_req, sdb_func->ep_out);
322         dev->rx_req = NULL;
323
324         if (sdb_func->ep_in)
325                 sdb_func->ep_in->driver_data = NULL;
326         if (sdb_func->ep_out)
327                 sdb_func->ep_out->driver_data = NULL;
328
329         printk(KERN_ERR "sdb_bind() could not allocate requests\n");
330         return -ENOMEM;
331 }
332
333 static ssize_t sdb_read(struct file *fp, char __user *buf,
334                                 size_t count, loff_t *pos)
335 {
336         struct sdb_dev *dev = fp->private_data;
337         int r = count, xfer;
338         int ret;
339
340         if (count > SDB_BULK_BUFFER_SIZE)
341                 return -EINVAL;
342
343         if (_sdb_lock(&dev->read_excl))
344                 return -EBUSY;
345
346         /* we will block until we're online */
347         while (!(dev->online || dev->error)) {
348                 ret = wait_event_interruptible(dev->read_wq,
349                                 (dev->online || dev->error));
350                 if (ret < 0) {
351                         _sdb_unlock(&dev->read_excl);
352                         return ret;
353                 }
354         }
355         if (dev->error) {
356                 r = -EIO;
357                 goto done;
358         }
359
360         /* queue a request */
361         mutex_lock(&sdb_lock);
362         if (!dev->sdb_func || !dev->rx_req)
363                 ret = -ENODEV;
364         else {
365 requeue_req:
366                 dev->rx_req->length = count;
367                 dev->rx_done = 0;
368                 ret = usb_ep_queue(dev->sdb_func->ep_out,
369                                 dev->rx_req, GFP_ATOMIC);
370         }
371         mutex_unlock(&sdb_lock);
372
373         if (ret < 0) {
374                 r = -EIO;
375                 dev->error = 1;
376                 goto done;
377         }
378
379         /* wait for a request to complete */
380         ret = wait_event_interruptible(dev->read_wq, dev->rx_done);
381         if (ret < 0) {
382                 dev->error = 1;
383                 r = ret;
384                 goto done;
385         }
386         if (!dev->error) {
387                 mutex_lock(&sdb_lock);
388                 if (!dev->sdb_func || !dev->rx_req)
389                         r = -ENODEV;
390                 else if (dev->rx_req->actual == 0)
391                 /* If we got a 0-len packet, throw it back and try again. */
392                         goto requeue_req;
393                 else {
394                         xfer = (dev->rx_req->actual < count)
395                                         ? dev->rx_req->actual : count;
396                         if (copy_to_user(buf, dev->rx_req->buf, xfer))
397                                 r = -EFAULT;
398                 }
399                 mutex_unlock(&sdb_lock);
400         } else
401                 r = -EIO;
402
403 done:
404         _sdb_unlock(&dev->read_excl);
405         return r;
406 }
407
408 static ssize_t sdb_write(struct file *fp, const char __user *buf,
409                                  size_t count, loff_t *pos)
410 {
411         struct sdb_dev *dev = fp->private_data;
412         struct usb_request *req = 0;
413         int r = count, xfer;
414         int ret;
415
416         if (_sdb_lock(&dev->write_excl))
417                 return -EBUSY;
418
419         while (count > 0) {
420                 if (dev->error) {
421                         r = -EIO;
422                         break;
423                 }
424
425                 /* get an idle tx request to use */
426                 req = 0;
427                 ret = wait_event_interruptible(dev->write_wq,
428                                 (!!(req = sdb_req_get(dev, dev->tx_idle))
429                                  || dev->error));
430
431                 if (ret < 0) {
432                         r = ret;
433                         break;
434                 }
435
436                 if (req != 0) {
437                         if (count > SDB_BULK_BUFFER_SIZE)
438                                 xfer = SDB_BULK_BUFFER_SIZE;
439                         else
440                                 xfer = count;
441
442                         mutex_lock(&sdb_lock);
443                         if (!dev->sdb_func) {
444                                 mutex_unlock(&sdb_lock);
445                                 r = -ENODEV;
446                                 break;
447                         } else if (copy_from_user(req->buf, buf, xfer)) {
448                                 mutex_unlock(&sdb_lock);
449                                 r = -EFAULT;
450                                 break;
451                         }
452
453                         req->length = xfer;
454                         ret = usb_ep_queue(dev->sdb_func->ep_in,
455                                         req, GFP_ATOMIC);
456                         mutex_unlock(&sdb_lock);
457
458                         if (ret < 0) {
459                                 dev->error = 1;
460                                 r = -EIO;
461                                 break;
462                         }
463
464                         buf += xfer;
465                         count -= xfer;
466
467                         /* zero this so we don't try to free it on error exit */
468                         req = 0;
469                 }
470         }
471
472         if (req)
473                 sdb_req_put(dev, dev->tx_idle, req);
474
475         _sdb_unlock(&dev->write_excl);
476         return r;
477 }
478
479 static int sdb_open(struct inode *ip, struct file *fp)
480 {
481         printk(KERN_INFO "sdb_open\n");
482         if (_sdb_lock(&_sdb_dev->open_excl))
483                 return -EBUSY;
484
485         fp->private_data = _sdb_dev;
486
487         /* clear the error latch */
488         _sdb_dev->error = 0;
489
490         return 0;
491 }
492
493 static int sdb_release(struct inode *ip, struct file *fp)
494 {
495         printk(KERN_INFO "sdb_release\n");
496
497         if (_sdb_dev != NULL)
498                 _sdb_unlock(&_sdb_dev->open_excl);
499
500         return 0;
501 }
502
503 /* file operations for SDB device /dev/samsung_sdb */
504 static const struct file_operations sdb_fops = {
505         .owner = THIS_MODULE,
506         .read = sdb_read,
507         .write = sdb_write,
508         .open = sdb_open,
509         .release = sdb_release,
510 };
511
512 static struct miscdevice sdb_device = {
513         .minor = MISC_DYNAMIC_MINOR,
514         .name = sdb_shortname,
515         .fops = &sdb_fops,
516 };
517
518 static int
519 sdb_function_bind(struct usb_configuration *c, struct usb_function *f)
520 {
521         struct usb_composite_dev *cdev = c->cdev;
522         struct f_sdb *sdb_func = func_to_sdb(f);
523         int                     id;
524         int                     ret;
525
526         DBG(cdev, "sdb_function_bind sdb_func: %p\n", sdb_func);
527
528         /* allocate interface ID(s) */
529         id = usb_interface_id(c, f);
530         if (id < 0)
531                 return id;
532
533         sdb_func->inf_id = id;
534         sdb_interface_desc.bInterfaceNumber = id;
535
536         /* allocate endpoints */
537         ret = sdb_create_bulk_endpoints(sdb_func, &sdb_fullspeed_in_desc,
538                         &sdb_fullspeed_out_desc);
539         if (ret)
540                 return ret;
541
542         f->fs_descriptors = usb_copy_descriptors(fs_sdb_descs);
543         if (!f->fs_descriptors)
544                 goto desc_alloc_fail;
545
546         /* support high speed hardware */
547         if (gadget_is_dualspeed(cdev->gadget)) {
548                 sdb_highspeed_in_desc.bEndpointAddress =
549                         sdb_fullspeed_in_desc.bEndpointAddress;
550                 sdb_highspeed_out_desc.bEndpointAddress =
551                         sdb_fullspeed_out_desc.bEndpointAddress;
552
553                 f->hs_descriptors = usb_copy_descriptors(hs_sdb_descs);
554                 if (!f->hs_descriptors)
555                         goto desc_alloc_fail;
556         }
557
558         return 0;
559
560 desc_alloc_fail:
561         if (f->fs_descriptors)
562                 usb_free_descriptors(f->fs_descriptors);
563
564         return -ENOMEM;
565 }
566
567 static void
568 sdb_function_unbind(struct usb_configuration *c, struct usb_function *f)
569 {
570         struct sdb_dev *dev = _sdb_dev;
571         struct f_sdb *sdb_func = func_to_sdb(f);
572         struct usb_request *req;
573
574         dev->online = 0;
575         dev->error = 1;
576
577         if (gadget_is_dualspeed(c->cdev->gadget))
578                 usb_free_descriptors(f->hs_descriptors);
579         usb_free_descriptors(f->fs_descriptors);
580
581         mutex_lock(&sdb_lock);
582
583         while (!!(req = sdb_req_get(dev, &sdb_func->bulk_in_q)))
584                 sdb_request_free(req, sdb_func->ep_in);
585
586         sdb_request_free(dev->rx_req, sdb_func->ep_out);
587
588         kfree(sdb_func);
589         dev->sdb_func = NULL;
590         dev->rx_req = NULL;
591
592         mutex_unlock(&sdb_lock);
593
594         wake_up(&dev->read_wq);
595         wake_up(&dev->write_wq);
596 }
597
598 static int sdb_function_set_alt(struct usb_function *f,
599                 unsigned intf, unsigned alt)
600 {
601         struct f_sdb *sdb_func = func_to_sdb(f);
602         struct usb_composite_dev *cdev = f->config->cdev;
603         struct sdb_dev *dev = _sdb_dev;
604         int ret;
605
606         if (sdb_func->inf_id != intf) {
607                 printk(KERN_ERR "sdb_function_set_alt error wrong intf:%d alt:%d\n",
608                                                 intf, alt);
609                 return -EINVAL;
610         }
611
612         if (sdb_func->ep_in->driver_data)
613                 usb_ep_disable(sdb_func->ep_in);
614         else if (config_ep_by_speed(cdev->gadget, f, sdb_func->ep_in))
615                 return -EINVAL;
616
617         ret = usb_ep_enable(sdb_func->ep_in);
618         if (ret) {
619                 printk(KERN_ERR "error, usb_ep_enable for sdb ep_in\n");
620                 return ret;
621         }
622         sdb_func->ep_in->driver_data = sdb_func;
623
624         if (sdb_func->ep_out->driver_data)
625                 usb_ep_disable(sdb_func->ep_out);
626         else if (config_ep_by_speed(cdev->gadget, f, sdb_func->ep_out)) {
627                 usb_ep_disable(sdb_func->ep_in);
628                 sdb_func->ep_in->driver_data = NULL;
629                 return -EINVAL;
630         }
631
632         ret = usb_ep_enable(sdb_func->ep_out);
633         if (ret) {
634                 usb_ep_disable(sdb_func->ep_in);
635                 sdb_func->ep_in->driver_data = NULL;
636                 printk(KERN_ERR "error, usb_ep_enable for sdb ep_out\n");
637                 return ret;
638         }
639         sdb_func->ep_out->driver_data = sdb_func;
640
641         dev->tx_idle = &sdb_func->bulk_in_q;
642         dev->sdb_func = sdb_func;
643         dev->online = 1;
644
645         /* readers may be blocked waiting for us to go online */
646         wake_up(&dev->read_wq);
647         return 0;
648 }
649
650 static void sdb_function_disable(struct usb_function *f)
651 {
652         struct sdb_dev *dev = _sdb_dev;
653         struct f_sdb *sdb_func = func_to_sdb(f);
654
655         dev->online = 0;
656         dev->error = 1;
657
658         spin_lock(&dev->lock);
659         dev->tx_idle = NULL;
660         spin_unlock(&dev->lock);
661
662         usb_ep_disable(sdb_func->ep_in);
663         sdb_func->ep_in->driver_data = NULL;
664
665         usb_ep_disable(sdb_func->ep_out);
666         sdb_func->ep_out->driver_data = NULL;
667
668         /* readers may be blocked waiting for us to go online */
669         wake_up(&dev->read_wq);
670         wake_up(&dev->write_wq);
671 }
672
673 static int sdb_setup(struct usb_composite_dev *cdev)
674 {
675         struct sdb_dev *dev;
676         int ret;
677
678         printk(KERN_INFO "sdb_bind_config\n");
679
680         dev = kzalloc(sizeof(*dev), GFP_KERNEL);
681         if (!dev)
682                 return -ENOMEM;
683
684         if (sdb_string_defs[F_SDB_IDX].id == 0) {
685                 ret = usb_string_id(cdev);
686                 if (ret < 0) {
687                         kfree(dev);
688                         return ret;
689                 }
690                 sdb_string_defs[F_SDB_IDX].id = ret;
691                 sdb_interface_desc.iInterface = ret;
692         }
693
694         spin_lock_init(&dev->lock);
695
696         init_waitqueue_head(&dev->read_wq);
697         init_waitqueue_head(&dev->write_wq);
698
699         atomic_set(&dev->open_excl, 0);
700         atomic_set(&dev->read_excl, 0);
701         atomic_set(&dev->write_excl, 0);
702
703
704         /* _sdb_dev must be set before calling usb_gadget_register_driver */
705         _sdb_dev = dev;
706
707         ret = misc_register(&sdb_device);
708         if (ret)
709                 goto err1;
710
711         return 0;
712
713 err1:
714         kfree(dev);
715         _sdb_dev = NULL;
716         printk(KERN_ERR "sdb gadget driver failed to initialize\n");
717         return ret;
718 }
719
720 static int sdb_bind_config(struct usb_configuration *c)
721 {
722         int ret;
723         struct f_sdb *sdb_func;
724
725         if (!_sdb_dev) {
726                 printk(KERN_ERR "Error There is no _sdb_dev!!\n");
727                 return -ENODEV;
728         }
729
730         sdb_func = kzalloc(sizeof(*sdb_func), GFP_KERNEL);
731         if (!sdb_func) {
732                 printk(KERN_ERR "sdb_func memory alloc failed !!!\n");
733                 return -ENOMEM;
734         }
735
736         INIT_LIST_HEAD(&sdb_func->bulk_in_q);
737
738         sdb_func->function.name = "sdb";
739         sdb_func->function.strings = sdb_strings;
740         sdb_func->function.bind = sdb_function_bind;
741         sdb_func->function.unbind = sdb_function_unbind;
742         sdb_func->function.set_alt = sdb_function_set_alt;
743         sdb_func->function.disable = sdb_function_disable;
744
745         ret = usb_add_function(c, &sdb_func->function);
746         if (ret)
747                 printk(KERN_ERR "Error in usb_add_function failed for sdb\n");
748
749         return ret;
750 }
751
752 static void sdb_cleanup(void)
753 {
754         struct sdb_dev  *dev = _sdb_dev;
755
756         misc_deregister(&sdb_device);
757
758         if (!dev)
759                 return;
760         _sdb_dev = NULL;
761         kfree(dev);
762 }