aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLan Tianyu <tianyu.lan@intel.com>2013-01-19 12:53:32 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-20 19:09:53 -0500
commitcef7468caff29d3333fba4d0ececd82063ce80d5 (patch)
tree5e3a3409f3dc4a37336b2ba05f4893b8f6cb8710
parent9f7344fbaf191de63df315c7e0fa4c976e2ea419 (diff)
usb: Add "portX/connect_type" attribute to expose usb port's connect type
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>
-rw-r--r--Documentation/ABI/testing/sysfs-bus-usb9
-rw-r--r--drivers/usb/core/port.c43
2 files changed, 52 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
index b6fbe514a869..c8baaf53594a 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -227,3 +227,12 @@ Contact: Lan Tianyu <tianyu.lan@intel.com>
227Description: 227Description:
228 The /sys/bus/usb/devices/.../(hub interface)/portX 228 The /sys/bus/usb/devices/.../(hub interface)/portX
229 is usb port device's sysfs directory. 229 is usb port device's sysfs directory.
230
231What: /sys/bus/usb/devices/.../(hub interface)/portX/connect_type
232Date: January 2013
233Contact: Lan Tianyu <tianyu.lan@intel.com>
234Description:
235 Some platforms provide usb port connect types through ACPI.
236 This attribute is to expose these information to user space.
237 The file will read "hotplug", "wired" and "not used" if the
238 information is available, and "unknown" otherwise.
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 3734850120ae..fe5959fc021b 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -20,6 +20,48 @@
20 20
21#include "hub.h" 21#include "hub.h"
22 22
23static const struct attribute_group *port_dev_group[];
24
25static ssize_t show_port_connect_type(struct device *dev,
26 struct device_attribute *attr, char *buf)
27{
28 struct usb_port *port_dev = to_usb_port(dev);
29 char *result;
30
31 switch (port_dev->connect_type) {
32 case USB_PORT_CONNECT_TYPE_HOT_PLUG:
33 result = "hotplug";
34 break;
35 case USB_PORT_CONNECT_TYPE_HARD_WIRED:
36 result = "hardwired";
37 break;
38 case USB_PORT_NOT_USED:
39 result = "not used";
40 break;
41 default:
42 result = "unknown";
43 break;
44 }
45
46 return sprintf(buf, "%s\n", result);
47}
48static DEVICE_ATTR(connect_type, S_IRUGO, show_port_connect_type,
49 NULL);
50
51static struct attribute *port_dev_attrs[] = {
52 &dev_attr_connect_type.attr,
53 NULL,
54};
55
56static struct attribute_group port_dev_attr_grp = {
57 .attrs = port_dev_attrs,
58};
59
60static const struct attribute_group *port_dev_group[] = {
61 &port_dev_attr_grp,
62 NULL,
63};
64
23static void usb_port_device_release(struct device *dev) 65static void usb_port_device_release(struct device *dev)
24{ 66{
25 struct usb_port *port_dev = to_usb_port(dev); 67 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)
45 87
46 hub->ports[port1 - 1] = port_dev; 88 hub->ports[port1 - 1] = port_dev;
47 port_dev->dev.parent = hub->intfdev; 89 port_dev->dev.parent = hub->intfdev;
90 port_dev->dev.groups = port_dev_group;
48 port_dev->dev.type = &usb_port_device_type; 91 port_dev->dev.type = &usb_port_device_type;
49 dev_set_name(&port_dev->dev, "port%d", port1); 92 dev_set_name(&port_dev->dev, "port%d", port1);
50 93