2 * f_hid.c -- USB HID function driver
4 * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/hid.h>
15 #include <linux/idr.h>
16 #include <linux/cdev.h>
17 #include <linux/mutex.h>
18 #include <linux/poll.h>
19 #include <linux/uaccess.h>
20 #include <linux/wait.h>
21 #include <linux/sched.h>
22 #include <linux/usb/g_hid.h>
29 static int major, minors;
30 static struct class *hidg_class;
31 #ifndef USBF_HID_INCLUDED
32 static DEFINE_IDA(hidg_ida);
33 static DEFINE_MUTEX(hidg_ida_lock); /* protects access to hidg_ida */
36 /*-------------------------------------------------------------------------*/
37 /* HID gadget struct */
39 struct f_hidg_req_list {
40 struct usb_request *req;
42 struct list_head list;
47 unsigned char bInterfaceSubClass;
48 unsigned char bInterfaceProtocol;
49 unsigned short report_desc_length;
51 unsigned short report_length;
54 struct list_head completed_out_req;
56 wait_queue_head_t read_queue;
62 wait_queue_head_t write_queue;
63 struct usb_request *req;
67 struct usb_function func;
70 struct usb_ep *out_ep;
73 static inline struct f_hidg *func_to_hidg(struct usb_function *f)
75 return container_of(f, struct f_hidg, func);
78 /*-------------------------------------------------------------------------*/
79 /* Static descriptors */
81 static struct usb_interface_descriptor hidg_interface_desc = {
82 .bLength = sizeof hidg_interface_desc,
83 .bDescriptorType = USB_DT_INTERFACE,
84 /* .bInterfaceNumber = DYNAMIC */
85 .bAlternateSetting = 0,
87 .bInterfaceClass = USB_CLASS_HID,
88 /* .bInterfaceSubClass = DYNAMIC */
89 /* .bInterfaceProtocol = DYNAMIC */
90 /* .iInterface = DYNAMIC */
93 static struct hid_descriptor hidg_desc = {
94 .bLength = sizeof hidg_desc,
95 .bDescriptorType = HID_DT_HID,
98 .bNumDescriptors = 0x1,
99 /*.desc[0].bDescriptorType = DYNAMIC */
100 /*.desc[0].wDescriptorLenght = DYNAMIC */
103 /* High-Speed Support */
105 static struct usb_endpoint_descriptor hidg_hs_in_ep_desc = {
106 .bLength = USB_DT_ENDPOINT_SIZE,
107 .bDescriptorType = USB_DT_ENDPOINT,
108 .bEndpointAddress = USB_DIR_IN,
109 .bmAttributes = USB_ENDPOINT_XFER_INT,
110 /*.wMaxPacketSize = DYNAMIC */
111 .bInterval = 4, /* FIXME: Add this field in the
112 * HID gadget configuration?
113 * (struct hidg_func_descriptor)
117 static struct usb_endpoint_descriptor hidg_hs_out_ep_desc = {
118 .bLength = USB_DT_ENDPOINT_SIZE,
119 .bDescriptorType = USB_DT_ENDPOINT,
120 .bEndpointAddress = USB_DIR_OUT,
121 .bmAttributes = USB_ENDPOINT_XFER_INT,
122 /*.wMaxPacketSize = DYNAMIC */
123 .bInterval = 4, /* FIXME: Add this field in the
124 * HID gadget configuration?
125 * (struct hidg_func_descriptor)
129 static struct usb_descriptor_header *hidg_hs_descriptors[] = {
130 (struct usb_descriptor_header *)&hidg_interface_desc,
131 (struct usb_descriptor_header *)&hidg_desc,
132 (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
133 (struct usb_descriptor_header *)&hidg_hs_out_ep_desc,
137 /* Full-Speed Support */
139 static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT,
142 .bEndpointAddress = USB_DIR_IN,
143 .bmAttributes = USB_ENDPOINT_XFER_INT,
144 /*.wMaxPacketSize = DYNAMIC */
145 .bInterval = 10, /* FIXME: Add this field in the
146 * HID gadget configuration?
147 * (struct hidg_func_descriptor)
151 static struct usb_endpoint_descriptor hidg_fs_out_ep_desc = {
152 .bLength = USB_DT_ENDPOINT_SIZE,
153 .bDescriptorType = USB_DT_ENDPOINT,
154 .bEndpointAddress = USB_DIR_OUT,
155 .bmAttributes = USB_ENDPOINT_XFER_INT,
156 /*.wMaxPacketSize = DYNAMIC */
157 .bInterval = 10, /* FIXME: Add this field in the
158 * HID gadget configuration?
159 * (struct hidg_func_descriptor)
163 static struct usb_descriptor_header *hidg_fs_descriptors[] = {
164 (struct usb_descriptor_header *)&hidg_interface_desc,
165 (struct usb_descriptor_header *)&hidg_desc,
166 (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
167 (struct usb_descriptor_header *)&hidg_fs_out_ep_desc,
171 /*-------------------------------------------------------------------------*/
174 #define CT_FUNC_HID_IDX 0
176 static struct usb_string ct_func_string_defs[] = {
177 [CT_FUNC_HID_IDX].s = "HID Interface",
178 {}, /* end of list */
181 static struct usb_gadget_strings ct_func_string_table = {
182 .language = 0x0409, /* en-US */
183 .strings = ct_func_string_defs,
186 static struct usb_gadget_strings *ct_func_strings[] = {
187 &ct_func_string_table,
191 /*-------------------------------------------------------------------------*/
194 static ssize_t f_hidg_read(struct file *file, char __user *buffer,
195 size_t count, loff_t *ptr)
197 struct f_hidg *hidg = file->private_data;
198 struct f_hidg_req_list *list;
199 struct usb_request *req;
206 if (!access_ok(VERIFY_WRITE, buffer, count))
209 spin_lock_irqsave(&hidg->spinlock, flags);
211 #define READ_COND (!list_empty(&hidg->completed_out_req))
213 /* wait for at least one buffer to complete */
215 spin_unlock_irqrestore(&hidg->spinlock, flags);
216 if (file->f_flags & O_NONBLOCK)
219 if (wait_event_interruptible(hidg->read_queue, READ_COND))
222 spin_lock_irqsave(&hidg->spinlock, flags);
225 /* pick the first one */
226 list = list_first_entry(&hidg->completed_out_req,
227 struct f_hidg_req_list, list);
229 count = min_t(unsigned int, count, req->actual - list->pos);
230 spin_unlock_irqrestore(&hidg->spinlock, flags);
232 /* copy to user outside spinlock */
233 count -= copy_to_user(buffer, req->buf + list->pos, count);
237 * if this request is completely handled and transfered to
238 * userspace, remove its entry from the list and requeue it
239 * again. Otherwise, we will revisit it again upon the next
240 * call, taking into account its current read position.
242 if (list->pos == req->actual) {
243 spin_lock_irqsave(&hidg->spinlock, flags);
244 list_del(&list->list);
246 spin_unlock_irqrestore(&hidg->spinlock, flags);
248 req->length = hidg->report_length;
249 ret = usb_ep_queue(hidg->out_ep, req, GFP_KERNEL);
257 static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
259 struct f_hidg *hidg = (struct f_hidg *)ep->driver_data;
261 if (req->status != 0) {
262 ERROR(hidg->func.config->cdev,
263 "End Point Request ERROR: %d\n", req->status);
266 hidg->write_pending = 0;
267 wake_up(&hidg->write_queue);
270 static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
271 size_t count, loff_t *offp)
273 struct f_hidg *hidg = file->private_data;
274 ssize_t status = -ENOMEM;
276 if (!access_ok(VERIFY_READ, buffer, count))
279 mutex_lock(&hidg->lock);
281 #define WRITE_COND (!hidg->write_pending)
284 while (!WRITE_COND) {
285 mutex_unlock(&hidg->lock);
286 if (file->f_flags & O_NONBLOCK)
289 if (wait_event_interruptible_exclusive(
290 hidg->write_queue, WRITE_COND))
293 mutex_lock(&hidg->lock);
296 count = min_t(unsigned, count, hidg->report_length);
297 status = copy_from_user(hidg->req->buf, buffer, count);
300 ERROR(hidg->func.config->cdev,
301 "copy_from_user error\n");
302 mutex_unlock(&hidg->lock);
306 hidg->req->status = 0;
308 hidg->req->length = count;
309 hidg->req->complete = f_hidg_req_complete;
310 hidg->req->context = hidg;
311 hidg->write_pending = 1;
313 status = usb_ep_queue(hidg->in_ep, hidg->req, GFP_ATOMIC);
315 ERROR(hidg->func.config->cdev,
316 "usb_ep_queue error on int endpoint %zd\n", status);
317 hidg->write_pending = 0;
318 wake_up(&hidg->write_queue);
323 mutex_unlock(&hidg->lock);
328 static unsigned int f_hidg_poll(struct file *file, poll_table *wait)
330 struct f_hidg *hidg = file->private_data;
331 unsigned int ret = 0;
333 poll_wait(file, &hidg->read_queue, wait);
334 poll_wait(file, &hidg->write_queue, wait);
337 ret |= POLLOUT | POLLWRNORM;
340 ret |= POLLIN | POLLRDNORM;
348 static int f_hidg_release(struct inode *inode, struct file *fd)
350 fd->private_data = NULL;
354 static int f_hidg_open(struct inode *inode, struct file *fd)
356 struct f_hidg *hidg =
357 container_of(inode->i_cdev, struct f_hidg, cdev);
359 fd->private_data = hidg;
364 /*-------------------------------------------------------------------------*/
367 static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep,
370 return alloc_ep_req(ep, length, length);
373 static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
375 struct f_hidg *hidg = (struct f_hidg *) req->context;
376 struct f_hidg_req_list *req_list;
379 req_list = kzalloc(sizeof(*req_list), GFP_ATOMIC);
385 spin_lock_irqsave(&hidg->spinlock, flags);
386 list_add_tail(&req_list->list, &hidg->completed_out_req);
387 spin_unlock_irqrestore(&hidg->spinlock, flags);
389 wake_up(&hidg->read_queue);
392 static int hidg_setup(struct usb_function *f,
393 const struct usb_ctrlrequest *ctrl)
395 struct f_hidg *hidg = func_to_hidg(f);
396 struct usb_composite_dev *cdev = f->config->cdev;
397 struct usb_request *req = cdev->req;
401 value = __le16_to_cpu(ctrl->wValue);
402 length = __le16_to_cpu(ctrl->wLength);
404 VDBG(cdev, "hid_setup crtl_request : bRequestType:0x%x bRequest:0x%x "
405 "Value:0x%x\n", ctrl->bRequestType, ctrl->bRequest, value);
407 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
408 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
409 | HID_REQ_GET_REPORT):
410 VDBG(cdev, "get_report\n");
412 /* send an empty report */
413 length = min_t(unsigned, length, hidg->report_length);
414 memset(req->buf, 0x0, length);
419 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
420 | HID_REQ_GET_PROTOCOL):
421 VDBG(cdev, "get_protocol\n");
425 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
426 | HID_REQ_SET_REPORT):
427 VDBG(cdev, "set_report | wLenght=%d\n", ctrl->wLength);
431 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
432 | HID_REQ_SET_PROTOCOL):
433 VDBG(cdev, "set_protocol\n");
437 case ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8
438 | USB_REQ_GET_DESCRIPTOR):
439 switch (value >> 8) {
441 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: HID\n");
442 length = min_t(unsigned short, length,
444 memcpy(req->buf, &hidg_desc, length);
448 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n");
449 length = min_t(unsigned short, length,
450 hidg->report_desc_length);
451 memcpy(req->buf, hidg->report_desc, length);
456 VDBG(cdev, "Unknown descriptor request 0x%x\n",
464 VDBG(cdev, "Unknown request 0x%x\n",
475 req->length = length;
476 status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
478 ERROR(cdev, "usb_ep_queue error on ep0 %d\n", value);
482 static void hidg_disable(struct usb_function *f)
484 struct f_hidg *hidg = func_to_hidg(f);
485 struct f_hidg_req_list *list, *next;
487 usb_ep_disable(hidg->in_ep);
488 hidg->in_ep->driver_data = NULL;
490 usb_ep_disable(hidg->out_ep);
491 hidg->out_ep->driver_data = NULL;
493 list_for_each_entry_safe(list, next, &hidg->completed_out_req, list) {
494 list_del(&list->list);
499 static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
501 struct usb_composite_dev *cdev = f->config->cdev;
502 struct f_hidg *hidg = func_to_hidg(f);
505 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
507 if (hidg->in_ep != NULL) {
508 /* restart endpoint */
509 if (hidg->in_ep->driver_data != NULL)
510 usb_ep_disable(hidg->in_ep);
512 status = config_ep_by_speed(f->config->cdev->gadget, f,
515 ERROR(cdev, "config_ep_by_speed FAILED!\n");
518 status = usb_ep_enable(hidg->in_ep);
520 ERROR(cdev, "Enable IN endpoint FAILED!\n");
523 hidg->in_ep->driver_data = hidg;
527 if (hidg->out_ep != NULL) {
528 /* restart endpoint */
529 if (hidg->out_ep->driver_data != NULL)
530 usb_ep_disable(hidg->out_ep);
532 status = config_ep_by_speed(f->config->cdev->gadget, f,
535 ERROR(cdev, "config_ep_by_speed FAILED!\n");
538 status = usb_ep_enable(hidg->out_ep);
540 ERROR(cdev, "Enable IN endpoint FAILED!\n");
543 hidg->out_ep->driver_data = hidg;
546 * allocate a bunch of read buffers and queue them all at once.
548 for (i = 0; i < hidg->qlen && status == 0; i++) {
549 struct usb_request *req =
550 hidg_alloc_ep_req(hidg->out_ep,
551 hidg->report_length);
553 req->complete = hidg_set_report_complete;
555 status = usb_ep_queue(hidg->out_ep, req,
558 ERROR(cdev, "%s queue req --> %d\n",
559 hidg->out_ep->name, status);
561 usb_ep_disable(hidg->out_ep);
562 hidg->out_ep->driver_data = NULL;
573 const struct file_operations f_hidg_fops = {
574 .owner = THIS_MODULE,
576 .release = f_hidg_release,
577 .write = f_hidg_write,
580 .llseek = noop_llseek,
583 static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
586 struct f_hidg *hidg = func_to_hidg(f);
587 struct device *device;
591 /* maybe allocate device-global string IDs, and patch descriptors */
592 if (ct_func_string_defs[CT_FUNC_HID_IDX].id == 0) {
593 status = usb_string_id(c->cdev);
596 ct_func_string_defs[CT_FUNC_HID_IDX].id = status;
597 hidg_interface_desc.iInterface = status;
600 /* allocate instance-specific interface IDs, and patch descriptors */
601 status = usb_interface_id(c, f);
604 hidg_interface_desc.bInterfaceNumber = status;
606 /* allocate instance-specific endpoints */
608 ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_in_ep_desc);
611 ep->driver_data = c->cdev; /* claim */
614 ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_out_ep_desc);
617 ep->driver_data = c->cdev; /* claim */
620 /* preallocate request and buffer */
622 hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
626 hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
630 /* set descriptor dynamic values */
631 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
632 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
633 hidg_hs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
634 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
635 hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
636 hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
637 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT;
638 hidg_desc.desc[0].wDescriptorLength =
639 cpu_to_le16(hidg->report_desc_length);
641 hidg_hs_in_ep_desc.bEndpointAddress =
642 hidg_fs_in_ep_desc.bEndpointAddress;
643 hidg_hs_out_ep_desc.bEndpointAddress =
644 hidg_fs_out_ep_desc.bEndpointAddress;
646 status = usb_assign_descriptors(f, hidg_fs_descriptors,
647 hidg_hs_descriptors, NULL);
651 mutex_init(&hidg->lock);
652 spin_lock_init(&hidg->spinlock);
653 init_waitqueue_head(&hidg->write_queue);
654 init_waitqueue_head(&hidg->read_queue);
655 INIT_LIST_HEAD(&hidg->completed_out_req);
657 /* create char device */
658 cdev_init(&hidg->cdev, &f_hidg_fops);
659 dev = MKDEV(major, hidg->minor);
660 status = cdev_add(&hidg->cdev, dev, 1);
662 goto fail_free_descs;
664 device = device_create(hidg_class, NULL, dev, NULL,
665 "%s%d", "hidg", hidg->minor);
666 if (IS_ERR(device)) {
667 status = PTR_ERR(device);
673 cdev_del(&hidg->cdev);
675 usb_free_all_descriptors(f);
677 ERROR(f->config->cdev, "hidg_bind FAILED\n");
678 if (hidg->req != NULL) {
679 kfree(hidg->req->buf);
680 if (hidg->in_ep != NULL)
681 usb_ep_free_request(hidg->in_ep, hidg->req);
687 #ifdef USBF_HID_INCLUDED
688 static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
690 struct f_hidg *hidg = func_to_hidg(f);
692 device_destroy(hidg_class, MKDEV(major, hidg->minor));
693 cdev_del(&hidg->cdev);
695 /* disable/free request and end point */
696 usb_ep_disable(hidg->in_ep);
697 usb_ep_dequeue(hidg->in_ep, hidg->req);
698 kfree(hidg->req->buf);
699 usb_ep_free_request(hidg->in_ep, hidg->req);
701 usb_free_all_descriptors(f);
703 kfree(hidg->report_desc);
707 /*-------------------------------------------------------------------------*/
708 /* usb_configuration */
709 int __init hidg_bind_config(struct usb_configuration *c,
710 struct hidg_func_descriptor *fdesc, int index)
718 /* allocate and initialize one new instance */
719 hidg = kzalloc(sizeof *hidg, GFP_KERNEL);
724 hidg->bInterfaceSubClass = fdesc->subclass;
725 hidg->bInterfaceProtocol = fdesc->protocol;
726 hidg->report_length = fdesc->report_length;
727 hidg->report_desc_length = fdesc->report_desc_length;
728 hidg->report_desc = kmemdup(fdesc->report_desc,
729 fdesc->report_desc_length,
731 if (!hidg->report_desc) {
736 hidg->func.name = "hid";
737 hidg->func.strings = ct_func_strings;
738 hidg->func.bind = hidg_bind;
739 hidg->func.unbind = hidg_unbind;
740 hidg->func.set_alt = hidg_set_alt;
741 hidg->func.disable = hidg_disable;
742 hidg->func.setup = hidg_setup;
744 /* this could me made configurable at some point */
747 status = usb_add_function(c, &hidg->func);
756 static inline int hidg_get_minor(void)
760 ret = ida_simple_get(&hidg_ida, 0, 0, GFP_KERNEL);
765 static inline void hidg_put_minor(int minor)
767 ida_simple_remove(&hidg_ida, minor);
770 static void hidg_free_inst(struct usb_function_instance *f)
772 struct f_hid_opts *opts;
774 opts = container_of(f, struct f_hid_opts, func_inst);
776 mutex_lock(&hidg_ida_lock);
778 hidg_put_minor(opts->minor);
779 if (idr_is_empty(&hidg_ida.idr))
782 mutex_unlock(&hidg_ida_lock);
784 if (opts->report_desc_alloc)
785 kfree(opts->report_desc);
790 static struct usb_function_instance *hidg_alloc_inst(void)
792 struct f_hid_opts *opts;
793 struct usb_function_instance *ret;
796 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
798 return ERR_PTR(-ENOMEM);
800 opts->func_inst.free_func_inst = hidg_free_inst;
801 ret = &opts->func_inst;
803 mutex_lock(&hidg_ida_lock);
805 if (idr_is_empty(&hidg_ida.idr)) {
806 status = ghid_setup(NULL, HIDG_MINORS);
808 ret = ERR_PTR(status);
814 opts->minor = hidg_get_minor();
815 if (opts->minor < 0) {
816 ret = ERR_PTR(opts->minor);
818 if (idr_is_empty(&hidg_ida.idr))
823 mutex_unlock(&hidg_ida_lock);
827 static void hidg_free(struct usb_function *f)
831 hidg = func_to_hidg(f);
832 kfree(hidg->report_desc);
836 static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
838 struct f_hidg *hidg = func_to_hidg(f);
840 device_destroy(hidg_class, MKDEV(major, hidg->minor));
841 cdev_del(&hidg->cdev);
843 /* disable/free request and end point */
844 usb_ep_disable(hidg->in_ep);
845 usb_ep_dequeue(hidg->in_ep, hidg->req);
846 kfree(hidg->req->buf);
847 usb_ep_free_request(hidg->in_ep, hidg->req);
849 usb_free_all_descriptors(f);
852 struct usb_function *hidg_alloc(struct usb_function_instance *fi)
855 struct f_hid_opts *opts;
857 /* allocate and initialize one new instance */
858 hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);
860 return ERR_PTR(-ENOMEM);
862 opts = container_of(fi, struct f_hid_opts, func_inst);
864 hidg->minor = opts->minor;
865 hidg->bInterfaceSubClass = opts->subclass;
866 hidg->bInterfaceProtocol = opts->protocol;
867 hidg->report_length = opts->report_length;
868 hidg->report_desc_length = opts->report_desc_length;
869 if (opts->report_desc) {
870 hidg->report_desc = kmemdup(opts->report_desc,
871 opts->report_desc_length,
873 if (!hidg->report_desc) {
875 return ERR_PTR(-ENOMEM);
879 hidg->func.name = "hid";
880 hidg->func.strings = ct_func_strings;
881 hidg->func.bind = hidg_bind;
882 hidg->func.unbind = hidg_unbind;
883 hidg->func.set_alt = hidg_set_alt;
884 hidg->func.disable = hidg_disable;
885 hidg->func.setup = hidg_setup;
886 hidg->func.free_func = hidg_free;
888 /* this could me made configurable at some point */
894 DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc);
895 MODULE_LICENSE("GPL");
896 MODULE_AUTHOR("Fabien Chouteau");
900 int ghid_setup(struct usb_gadget *g, int count)
905 hidg_class = class_create(THIS_MODULE, "hidg");
906 if (IS_ERR(hidg_class)) {
908 return PTR_ERR(hidg_class);
911 status = alloc_chrdev_region(&dev, 0, count, "hidg");
920 void ghid_cleanup(void)
923 unregister_chrdev_region(MKDEV(major, 0), minors);
927 class_destroy(hidg_class);