usb: Add "portX/connect_type" attribute to expose usb port's connect type
authorLan Tianyu <tianyu.lan@intel.com>
Sat, 19 Jan 2013 17:53:32 +0000 (01:53 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 21 Jan 2013 00:09:53 +0000 (16:09 -0800)
Some platforms provide usb port connect types through ACPI. This
patch is to add this new attribute to expose these information
to user space.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/ABI/testing/sysfs-bus-usb
drivers/usb/core/port.c

index b6fbe514a869a311bea16c1918061128c8f9d6dc..c8baaf53594a862fb8be7fadd880cb534de8acea 100644 (file)
@@ -227,3 +227,12 @@ Contact:   Lan Tianyu <tianyu.lan@intel.com>
 Description:
                The /sys/bus/usb/devices/.../(hub interface)/portX
                is usb port device's sysfs directory.
+
+What:          /sys/bus/usb/devices/.../(hub interface)/portX/connect_type
+Date:          January 2013
+Contact:       Lan Tianyu <tianyu.lan@intel.com>
+Description:
+               Some platforms provide usb port connect types through ACPI.
+               This attribute is to expose these information to user space.
+               The file will read "hotplug", "wired" and "not used" if the
+               information is available, and "unknown" otherwise.
index 3734850120ae65de8d44f1697202cb0f5a409256..fe5959fc021b387a7de72d39dd95a216e728738b 100644 (file)
 
 #include "hub.h"
 
+static const struct attribute_group *port_dev_group[];
+
+static ssize_t show_port_connect_type(struct device *dev,
+       struct device_attribute *attr, char *buf)
+{
+       struct usb_port *port_dev = to_usb_port(dev);
+       char *result;
+
+       switch (port_dev->connect_type) {
+       case USB_PORT_CONNECT_TYPE_HOT_PLUG:
+               result = "hotplug";
+               break;
+       case USB_PORT_CONNECT_TYPE_HARD_WIRED:
+               result = "hardwired";
+               break;
+       case USB_PORT_NOT_USED:
+               result = "not used";
+               break;
+       default:
+               result = "unknown";
+               break;
+       }
+
+       return sprintf(buf, "%s\n", result);
+}
+static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type,
+               NULL);
+
+static struct attribute *port_dev_attrs[] = {
+       &dev_attr_connect_type.attr,
+       NULL,
+};
+
+static struct attribute_group port_dev_attr_grp = {
+       .attrs = port_dev_attrs,
+};
+
+static const struct attribute_group *port_dev_group[] = {
+       &port_dev_attr_grp,
+       NULL,
+};
+
 static void usb_port_device_release(struct device *dev)
 {
        struct usb_port *port_dev = to_usb_port(dev);
@@ -45,6 +87,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 
        hub->ports[port1 - 1] = port_dev;
        port_dev->dev.parent = hub->intfdev;
+       port_dev->dev.groups = port_dev_group;
        port_dev->dev.type = &usb_port_device_type;
        dev_set_name(&port_dev->dev, "port%d", port1);