usb: gadget: udc: add a 'function' sysfs file
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Wed, 7 Jun 2017 11:07:01 +0000 (14:07 +0300)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 13 Jun 2017 10:21:04 +0000 (13:21 +0300)
This file will print out the name of the currently running USB Gadget
Driver. It can be read even when there are no functions loaded.

Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Documentation/ABI/stable/sysfs-class-udc
drivers/usb/gadget/udc/core.c

index 85d3dac..7370deb 100644 (file)
@@ -91,3 +91,11 @@ Description:
                'configured', and 'suspended'; however not all USB Device
                Controllers support reporting all states.
 Users:
+
+What:          /sys/class/udc/<udc>/function
+Date:          June 2017
+KernelVersion: 4.13
+Contact:       Felipe Balbi <balbi@kernel.org>
+Description:
+               Prints out name of currently running USB Gadget Driver.
+Users:
index eec388b..08facba 100644 (file)
@@ -1460,6 +1460,18 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(state);
 
+static ssize_t function_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct usb_udc          *udc = container_of(dev, struct usb_udc, dev);
+       struct usb_gadget_driver *drv = udc->driver;
+
+       if (!drv || !drv->function)
+               return 0;
+       return scnprintf(buf, PAGE_SIZE, "%s\n", drv->function);
+}
+static DEVICE_ATTR_RO(function);
+
 #define USB_UDC_SPEED_ATTR(name, param)                                        \
 ssize_t name##_show(struct device *dev,                                        \
                struct device_attribute *attr, char *buf)               \
@@ -1495,6 +1507,7 @@ static struct attribute *usb_udc_attrs[] = {
        &dev_attr_srp.attr,
        &dev_attr_soft_connect.attr,
        &dev_attr_state.attr,
+       &dev_attr_function.attr,
        &dev_attr_current_speed.attr,
        &dev_attr_maximum_speed.attr,