|
@@ -50,6 +50,72 @@ static ssize_t connect_type_show(struct device *dev,
|
|
|
}
|
|
|
static DEVICE_ATTR_RO(connect_type);
|
|
|
|
|
|
+static ssize_t usb3_lpm_permit_show(struct device *dev,
|
|
|
+ struct device_attribute *attr, char *buf)
|
|
|
+{
|
|
|
+ struct usb_port *port_dev = to_usb_port(dev);
|
|
|
+ const char *p;
|
|
|
+
|
|
|
+ if (port_dev->usb3_lpm_u1_permit) {
|
|
|
+ if (port_dev->usb3_lpm_u2_permit)
|
|
|
+ p = "u1_u2";
|
|
|
+ else
|
|
|
+ p = "u1";
|
|
|
+ } else {
|
|
|
+ if (port_dev->usb3_lpm_u2_permit)
|
|
|
+ p = "u2";
|
|
|
+ else
|
|
|
+ p = "0";
|
|
|
+ }
|
|
|
+
|
|
|
+ return sprintf(buf, "%s\n", p);
|
|
|
+}
|
|
|
+
|
|
|
+static ssize_t usb3_lpm_permit_store(struct device *dev,
|
|
|
+ struct device_attribute *attr,
|
|
|
+ const char *buf, size_t count)
|
|
|
+{
|
|
|
+ struct usb_port *port_dev = to_usb_port(dev);
|
|
|
+ struct usb_device *udev = port_dev->child;
|
|
|
+ struct usb_hcd *hcd;
|
|
|
+
|
|
|
+ if (!strncmp(buf, "u1_u2", 5)) {
|
|
|
+ port_dev->usb3_lpm_u1_permit = 1;
|
|
|
+ port_dev->usb3_lpm_u2_permit = 1;
|
|
|
+
|
|
|
+ } else if (!strncmp(buf, "u1", 2)) {
|
|
|
+ port_dev->usb3_lpm_u1_permit = 1;
|
|
|
+ port_dev->usb3_lpm_u2_permit = 0;
|
|
|
+
|
|
|
+ } else if (!strncmp(buf, "u2", 2)) {
|
|
|
+ port_dev->usb3_lpm_u1_permit = 0;
|
|
|
+ port_dev->usb3_lpm_u2_permit = 1;
|
|
|
+
|
|
|
+ } else if (!strncmp(buf, "0", 1)) {
|
|
|
+ port_dev->usb3_lpm_u1_permit = 0;
|
|
|
+ port_dev->usb3_lpm_u2_permit = 0;
|
|
|
+ } else
|
|
|
+ return -EINVAL;
|
|
|
+
|
|
|
+ /* If device is connected to the port, disable or enable lpm
|
|
|
+ * to make new u1 u2 setting take effect immediately.
|
|
|
+ */
|
|
|
+ if (udev) {
|
|
|
+ hcd = bus_to_hcd(udev->bus);
|
|
|
+ if (!hcd)
|
|
|
+ return -EINVAL;
|
|
|
+ usb_lock_device(udev);
|
|
|
+ mutex_lock(hcd->bandwidth_mutex);
|
|
|
+ if (!usb_disable_lpm(udev))
|
|
|
+ usb_enable_lpm(udev);
|
|
|
+ mutex_unlock(hcd->bandwidth_mutex);
|
|
|
+ usb_unlock_device(udev);
|
|
|
+ }
|
|
|
+
|
|
|
+ return count;
|
|
|
+}
|
|
|
+static DEVICE_ATTR_RW(usb3_lpm_permit);
|
|
|
+
|
|
|
static struct attribute *port_dev_attrs[] = {
|
|
|
&dev_attr_connect_type.attr,
|
|
|
NULL,
|
|
@@ -64,6 +130,21 @@ static const struct attribute_group *port_dev_group[] = {
|
|
|
NULL,
|
|
|
};
|
|
|
|
|
|
+static struct attribute *port_dev_usb3_attrs[] = {
|
|
|
+ &dev_attr_usb3_lpm_permit.attr,
|
|
|
+ NULL,
|
|
|
+};
|
|
|
+
|
|
|
+static struct attribute_group port_dev_usb3_attr_grp = {
|
|
|
+ .attrs = port_dev_usb3_attrs,
|
|
|
+};
|
|
|
+
|
|
|
+static const struct attribute_group *port_dev_usb3_group[] = {
|
|
|
+ &port_dev_attr_grp,
|
|
|
+ &port_dev_usb3_attr_grp,
|
|
|
+ NULL,
|
|
|
+};
|
|
|
+
|
|
|
static void usb_port_device_release(struct device *dev)
|
|
|
{
|
|
|
struct usb_port *port_dev = to_usb_port(dev);
|
|
@@ -401,6 +482,7 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
|
|
|
int usb_hub_create_port_device(struct usb_hub *hub, int port1)
|
|
|
{
|
|
|
struct usb_port *port_dev;
|
|
|
+ struct usb_device *hdev = hub->hdev;
|
|
|
int retval;
|
|
|
|
|
|
port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL);
|
|
@@ -417,7 +499,12 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
|
|
|
port_dev->portnum = port1;
|
|
|
set_bit(port1, hub->power_bits);
|
|
|
port_dev->dev.parent = hub->intfdev;
|
|
|
- port_dev->dev.groups = port_dev_group;
|
|
|
+ if (hub_is_superspeed(hdev)) {
|
|
|
+ port_dev->usb3_lpm_u1_permit = 1;
|
|
|
+ port_dev->usb3_lpm_u2_permit = 1;
|
|
|
+ port_dev->dev.groups = port_dev_usb3_group;
|
|
|
+ } else
|
|
|
+ port_dev->dev.groups = port_dev_group;
|
|
|
port_dev->dev.type = &usb_port_device_type;
|
|
|
port_dev->dev.driver = &usb_port_driver;
|
|
|
if (hub_is_superspeed(hub->hdev))
|