12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/hid.h>
17 #include <linux/poll.h>
19 #include <linux/wait.h>
20 #include <linux/sched.h>
23 static int major, minors;
24 static struct class *hidg_class;
72 .bLength =
sizeof hidg_interface_desc,
75 .bAlternateSetting = 0,
84 .bLength =
sizeof hidg_desc,
88 .bNumDescriptors = 0x1,
181 #define READ_COND (!list_empty(&hidg->completed_out_req))
185 spin_unlock_irqrestore(&hidg->
spinlock, flags);
200 spin_unlock_irqrestore(&hidg->
spinlock, flags);
216 spin_unlock_irqrestore(&hidg->
spinlock, flags);
233 "End Point Request ERROR: %d\n", req->
status);
240 static ssize_t f_hidg_write(
struct file *file,
const char __user *buffer,
241 size_t count, loff_t *offp)
251 #define WRITE_COND (!hidg->write_pending)
254 while (!WRITE_COND) {
271 "copy_from_user error\n");
276 hidg->
req->status = 0;
279 hidg->
req->complete = f_hidg_req_complete;
280 hidg->
req->context = hidg;
286 "usb_ep_queue error on int endpoint %zd\n", status);
298 static unsigned int f_hidg_poll(
struct file *file,
poll_table *
wait)
301 unsigned int ret = 0;
318 static int f_hidg_release(
struct inode *
inode,
struct file *
fd)
324 static int f_hidg_open(
struct inode *
inode,
struct file *
fd)
346 usb_ep_free_request(ep, req);
359 req_list = kzalloc(
sizeof(*req_list),
GFP_ATOMIC);
367 spin_unlock_irqrestore(&hidg->
spinlock, flags);
375 struct f_hidg *hidg = func_to_hidg(f);
384 VDBG(cdev,
"hid_setup crtl_request : bRequestType:0x%x bRequest:0x%x "
390 VDBG(cdev,
"get_report\n");
401 VDBG(cdev,
"get_protocol\n");
407 VDBG(cdev,
"set_report | wLenght=%d\n", ctrl->
wLength);
413 VDBG(cdev,
"set_protocol\n");
419 switch (value >> 8) {
421 VDBG(cdev,
"USB_REQ_GET_DESCRIPTOR: HID\n");
422 length =
min_t(
unsigned short, length,
428 VDBG(cdev,
"USB_REQ_GET_DESCRIPTOR: REPORT\n");
429 length =
min_t(
unsigned short, length,
436 VDBG(cdev,
"Unknown descriptor request 0x%x\n",
444 VDBG(cdev,
"Unknown request 0x%x\n",
458 ERROR(cdev,
"usb_ep_queue error on ep0 %d\n", value);
464 struct f_hidg *hidg = func_to_hidg(f);
467 usb_ep_disable(hidg->
in_ep);
470 usb_ep_disable(hidg->
out_ep);
479 static int hidg_set_alt(
struct usb_function *f,
unsigned intf,
unsigned alt)
482 struct f_hidg *hidg = func_to_hidg(f);
485 VDBG(cdev,
"hidg_set_alt intf:%d alt:%d\n", intf, alt);
490 usb_ep_disable(hidg->
in_ep);
495 ERROR(cdev,
"config_ep_by_speed FAILED!\n");
498 status = usb_ep_enable(hidg->
in_ep);
500 ERROR(cdev,
"Enable IN endpoint FAILED!\n");
503 hidg->
in_ep->driver_data = hidg;
510 usb_ep_disable(hidg->
out_ep);
515 ERROR(cdev,
"config_ep_by_speed FAILED!\n");
518 status = usb_ep_enable(hidg->
out_ep);
520 ERROR(cdev,
"Enable IN endpoint FAILED!\n");
523 hidg->
out_ep->driver_data = hidg;
528 for (i = 0; i < hidg->
qlen && status == 0; i++) {
530 hidg_alloc_ep_req(hidg->
out_ep,
533 req->
complete = hidg_set_report_complete;
535 status = usb_ep_queue(hidg->
out_ep, req,
538 ERROR(cdev,
"%s queue req --> %d\n",
539 hidg->
out_ep->name, status);
541 usb_ep_disable(hidg->
out_ep);
556 .release = f_hidg_release,
557 .write = f_hidg_write,
566 struct f_hidg *hidg = func_to_hidg(f);
609 hidg_desc.
desc[0].wDescriptorLength =
617 if (gadget_is_dualspeed(c->
cdev->gadget)) {
649 usb_ep_free_request(hidg->
in_ep, hidg->
req);
660 struct f_hidg *hidg = func_to_hidg(f);
666 usb_ep_disable(hidg->
in_ep);
667 usb_ep_dequeue(hidg->
in_ep, hidg->
req);
669 usb_ep_free_request(hidg->
in_ep, hidg->
req);
682 #define CT_FUNC_HID_IDX 0
684 static struct usb_string ct_func_string_defs[] = {
691 .strings = ct_func_string_defs,
695 &ct_func_string_table,
738 hidg->
func.name =
"hid";
739 hidg->
func.strings = ct_func_strings;
740 hidg->
func.bind = hidg_bind;
741 hidg->
func.unbind = hidg_unbind;
742 hidg->
func.set_alt = hidg_set_alt;
743 hidg->
func.disable = hidg_disable;
744 hidg->
func.setup = hidg_setup;