usb: gadget: f_fs: add ioctl returning ep descriptor
authorRobert Baldyga <r.baldyga@samsung.com>
Tue, 9 Sep 2014 06:23:16 +0000 (08:23 +0200)
committerFelipe Balbi <balbi@ti.com>
Tue, 9 Sep 2014 15:04:45 +0000 (10:04 -0500)
This patch introduces ioctl named FUNCTIONFS_ENDPOINT_DESC, which
returns endpoint descriptor to userspace. It works only if function
is active.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Acked-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/function/f_fs.c
include/uapi/linux/usb/functionfs.h

index 1aad353c1f116335a1cd013be55453e4fbc87fe1..a345385a5abe2f439ee1556cd7b10d543a770656 100644 (file)
@@ -1026,6 +1026,29 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
                case FUNCTIONFS_ENDPOINT_REVMAP:
                        ret = epfile->ep->num;
                        break;
+               case FUNCTIONFS_ENDPOINT_DESC:
+               {
+                       int desc_idx;
+                       struct usb_endpoint_descriptor *desc;
+
+                       switch (epfile->ffs->gadget->speed) {
+                       case USB_SPEED_SUPER:
+                               desc_idx = 2;
+                               break;
+                       case USB_SPEED_HIGH:
+                               desc_idx = 1;
+                               break;
+                       default:
+                               desc_idx = 0;
+                       }
+                       desc = epfile->ep->descs[desc_idx];
+
+                       spin_unlock_irq(&epfile->ffs->eps_lock);
+                       ret = copy_to_user((void *)value, desc, sizeof(*desc));
+                       if (ret)
+                               ret = -EFAULT;
+                       return ret;
+               }
                default:
                        ret = -ENOTTY;
                }
index 6d2a16b834bf19f3a75abce80388e2c10e02bf2a..7c7a2feb0e6e7770457bd69452c9bb9deca20850 100644 (file)
@@ -275,6 +275,12 @@ struct usb_functionfs_event {
  */
 #define        FUNCTIONFS_ENDPOINT_REVMAP      _IO('g', 129)
 
+/*
+ * Returns endpoint descriptor. If function is not active returns -ENODEV.
+ */
+#define        FUNCTIONFS_ENDPOINT_DESC        _IOR('g', 130, \
+                                            struct usb_endpoint_descriptor)
+
 
 
 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */