USB/ACPI: Add usb port's acpi power control in the xhci PORT_POWER feature request process.
Subsystems (3)
RFC PATCH v3 2/3 USB/ACPI: Add usb port's acpi power control in the xhci PORT_POWER feature request process.
In reply to a message not in the archiveOn our developping machine, bios can provide usb port's power control via acpi. This patch is to provide usb port's power control way through setting or clearing PORT_POWER feature requests. Add two functions usb_acpi_power_manageable() and usb_acpi_set_power_state(). The first one is used to find whether the usb port has acpi power resource and the second is to set the power state. They are invoked in the xhci_hub_control() where clearing or setting PORT_POWER feature requests are processed.
--- drivers/usb/core/usb-acpi.c | 28 ++++++++++++++++++++++++++++ drivers/usb/host/xhci-hub.c | 10 ++++++++++ include/linux/usb.h | 10 ++++++++++ 3 files changed, 48 insertions(+), 0 deletions(-)
drivers/usb/core/usb-acpi.c +28 -0
@@ -19,6 +19,34 @@#include "usb.h" +bool usb_acpi_power_manageable (struct usb_device *hdev,int port1) +{ +acpi_handle port_handle; + + port_handle =usb_get_hub_port_acpi_handle (hdev, + port1); +return port_handle ?acpi_bus_power_manageable (port_handle) : false; +} +EXPORT_SYMBOL_GPL (usb_acpi_power_manageable); + +int usb_acpi_set_power_state (struct usb_device *hdev,int port1,bool enable) +{ +acpi_handle port_handle; +unsigned char state; +int error = -EINVAL ; + + port_handle = (acpi_handle )usb_get_hub_port_acpi_handle (hdev, + port1); + state = enable ?ACPI_STATE_D0 :ACPI_STATE_D3_COLD ; + error =acpi_bus_set_power (port_handle, state); +if (!error) +dev_dbg (&hdev->dev,"The power of hub port %d was set to %s\n" , + port1, enable ?"enable" :"disabe" ); + +return error; +} +EXPORT_SYMBOL_GPL (usb_acpi_set_power_state); +static int usb_acpi_check_port_connect_type (struct usb_device *hdev,acpi_handle handle,int port1) {
drivers/usb/host/xhci-hub.c +10 -0
@@ -728,6 +728,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, temp =xhci_readl (xhci, port_array[wIndex]);xhci_dbg (xhci,"set port power, actual port %d status = 0x%x\n" , wIndex, temp); + +if (usb_acpi_power_manageable (hcd->self.root_hub, + wIndex +1 )) +usb_acpi_set_power_state (hcd->self.root_hub, + wIndex +1 , true);break ;case USB_PORT_FEAT_RESET : temp = (temp |PORT_RESET );
@@ -830,6 +835,11 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,case USB_PORT_FEAT_POWER :xhci_writel (xhci, temp & ~PORT_POWER , port_array[wIndex]); + +if (usb_acpi_power_manageable (hcd->self.root_hub, + wIndex +1 )) +usb_acpi_set_power_state (hcd->self.root_hub, + wIndex +1 , false);break ;default : goto error;
include/linux/usb.h +10 -0
@@ -599,6 +599,16 @@ extern int usb_lock_device_for_reset(struct usb_device *udev,extern int usb_reset_device (struct usb_device *dev);extern void usb_queue_reset_device (struct usb_interface *dev); +#ifdef CONFIG_ACPI +extern int usb_acpi_set_power_state (struct usb_device *hdev,int port, +bool enable); +extern bool usb_acpi_power_manageable (struct usb_device *hdev,int port); +#else +static inline int usb_acpi_set_power_state (struct usb_device *hdev,int port, +bool enable) {return 0 ; } +static inline bool usb_acpi_power_manageable (struct usb_device *hdev,int port) + {return 0 ; } +#endif /* USB autosuspend and autoresume */ #ifdef CONFIG_USB_SUSPEND
Signature · 1 line
1.7.6.rc2.8.g28eb
RFC PATCH v3 3/3 usb : Add sysfs files to control usb port's power
In reply to a message not in the archiveChange since v2: add ABI descripters for new sysfs files and with some small modification.
Change since v1: move sysfs files from usb hub device sysfs directory to usb hub interface sysfs directory.
This patch is to add two sys files for each usb hub ports to control port's power. Control port's power through setting or clearing PORT_POWER feature.
The new sys files is under the usb hub interface sysfs portx directory. ls /sys/bus/usb/devices/1-0:1.0
bAlternateSetting bInterfaceClass bInterfaceNumber bInterfaceProtocol bInterfaceSubClass bNumEndpoints driver ep_81 modalias power subsystem supports_autosuspend uevent port1 port2 port3 port4
ls /sys/bus/usb/devices/1-0:1.0/port1
control state
control has three options. "auto", "on" and "off"
"auto" - For ports with device, there is a proposal that if the device was not
in the suspend at that pointer, the power would remain on but it would power off when it was suspended. If the the device was in the suspend, "auto" means the device could be put into much lower state so the device need to resume and suspend again.
"on" - port must be power on.
"off" - port must be power off.
state reports usb ports' power state
"on" - power on
"off" - power off
"error" - can't get power state
--- Documentation/ABI/testing/sysfs-bus-usb | 37 +++++++ drivers/usb/core/hub.c | 172 +++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 0 deletions(-)
Documentation/ABI/testing/sysfs-bus-usb +37 -0
@@ -208,3 +208,40 @@ Description: such as ACPI. This file will read either "removable" or "fixed" if the information is available, and "unknown" otherwise. + +What: /sys/bus/usb/devices/.../(hub interface)/port1, port2,...portX +Date: June 2012 +Contact Lan Tianyu <[email protected]> +Description: + The /sys/bus/usb/device/.../(hub interface)/portX directory + contains attributes allowing the user space to check and modify + some usb port related properties of associated port. + +What: /sys/bus/usb/devices/.../(hub interface)/portX/control +Date: June 2012 +Contact Lan Tianyu <[email protected]> +Description: + The /sys/bus/usb/devices/.../(hub interface)/portX/control attribue + allows the user space to control the power policy on the usb port + + All ports have one of the following three values for portX/control + "auto" - For ports with device, if the device was not in the suspend + at that pointer, the power would remain on but it would power + off when it was suspended. If the the device was in the suspend, + "auto" means the device could be put into much lower state so + the device would be resumed and suspended again. + "on" - port must be power on. + "off" - port must be power off. + +What: /sys/bus/usb/devices/.../(hub interface)/portX/state +Date: June 2012 +Contact Lan Tianyu <[email protected]> +Description: + The /sys/bus/usb/devices/.../(hub interface)/portX/state attribue + allows the user space to check hub port's power state. + + All ports have three following states + "on" - port power on + "off" - port power off + "error" - can't get the hub port's power state +
drivers/usb/core/hub.c +172 -0
220 lines not on this page · raw message
Signature · 1 line
1.7.6.rc2.8.g28eb
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
In reply to a message not in the archiveQuoted 2 lines · Lan Tianyu
Change since v2: add ABI descripters for new sysfs files and with some small modification.
Better, but it still can be improved.
Quoted 12 lines
Change since v1: move sysfs files from usb hub device sysfs directory to usb hub interface sysfs directory.
This patch is to add two sys files for each usb hub ports to control port's power. Control port's power through setting or clearing
PORT_POWERfeature.The new sys files is under the usb hub interface sysfs portx directory. ls /sys/bus/usb/devices/1-0:1.0
bAlternateSetting bInterfaceClass bInterfaceNumber bInterfaceProtocol bInterfaceSubClass bNumEndpoints driverep_81modalias power subsystemsupports_autosuspenduevent port1 port2 port3 port4
Quoted 6 lines
ls /sys/bus/usb/devices/1-0:1.0/port1
control statecontrol has three options. "auto", "on" and "off"
"auto" - For ports with device, there is a proposal that if the device was not
in the suspend at that pointer, the power would remain on but it would
s/in the suspend/suspended/ -- this change is needed throughout the patch.
s/pointer/point/
Quoted 3 lines
power off when it was suspended. If the the device was in the suspend, "auto" means the device could be put into much lower state so the device need to resume and suspend again.
Get rid of "so the device...". You don't need to resume a suspended port before powering it off.
Quoted 4 lines
"on" - port must be power on.
"off" - port must be power off.state reports usb ports' power state
s/ports'/port's/
Quoted 15 lines
"on" - power on
"off" - power off
"error" - can't get power stateSigned-off-by Lan Tianyu <[email protected]>--- Documentation/ABI/testing/sysfs-bus-usb | 37 +++++++ drivers/usb/core/hub.c | 172 +++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 0 deletions(-)Documentation/ABI/testing/sysfs-bus-usb +0
-0
Documentation/ABI/testing/sysfs-bus-usb Description: · line 212
Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-usb +2
-0@@ -208,3 +208,40 @@ Description: such as ACPI. This file will read either "removable" or "fixed" if the information is available, and "unknown" otherwise. + +What: /sys/bus/usb/devices/.../(hub interface)/port1, port2,...portX
Just portX, not port1, port2, ...
Documentation/ABI/testing/sysfs-bus-usb Description: · line 217
Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-usb +5
-0+Date: June 2012 +Contact Lan Tianyu <[email protected]> +Description: + The /sys/bus/usb/device/.../(hub interface)/portX directory + contains attributes allowing the user space to check and modify
s/the user/user/ -- here and below
Documentation/ABI/testing/sysfs-bus-usb Description: · line 218
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-usb +1
-0+ some usb port related properties of associated port.
Change to: properties of the associated USB port.
Documentation/ABI/testing/sysfs-bus-usb Description: · line 223
Quoted 5 lines
Documentation/ABI/testing/sysfs-bus-usb +5
-0+ +What: /sys/bus/usb/devices/.../(hub interface)/portX/control +Date: June 2012 +Contact Lan Tianyu <[email protected]> +Description:
Lines should not extend past column 76 or so.
Documentation/ABI/testing/sysfs-bus-usb Description: · line 224
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-usb +1
-0+ The /sys/bus/usb/devices/.../(hub interface)/portX/control attribue
s/attribue/attribute/ -- here and below
Documentation/ABI/testing/sysfs-bus-usb Description: · line 232
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-usb +8
-0+ allows the user space to control the power policy on the usb port + + All ports have one of the following three values for portX/control + "auto" - For ports with device, if the device was not in the suspend + at that pointer, the power would remain on but it would power + off when it was suspended. If the the device was in the suspend, + "auto" means the device could be put into much lower state so + the device would be resumed and suspended again.
The patch does not implement anything at all for "auto". It should do _something_.
Documentation/ABI/testing/sysfs-bus-usb Description: · line 233
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-usb +1
-0+ "on" - port must be power on.
Change to: port power must be on.
Documentation/ABI/testing/sysfs-bus-usb Description: · line 234
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-usb +1
-0+ "off" - port must be power off.
Change to: port power must be off.
Quoted 24 lines
Documentation/ABI/testing/sysfs-bus-usb +13
-0+ +What: /sys/bus/usb/devices/.../(hub interface)/portX/state +Date: June 2012 +Contact Lan Tianyu <[email protected]> +Description: + The /sys/bus/usb/devices/.../(hub interface)/portX/state attribue + allows the user space to check hub port's power state. + + All ports have three following states + "on" - port power on + "off" - port power off + "error" - can't get the hub port's power state +drivers/usb/core/hub.c +3
-0@@ -41,12 +41,22 @@#endif #endif +enum port_power_policy { +USB_PORT_POWER_ON =0 , +USB_PORT_POWER_OFF ,
drivers/usb/core/hub.c line 56
Quoted 10 lines
drivers/usb/core/hub.c +4
-0+ USB_PORT_POWER_AUTO, +}; +struct usb_hub_port {void *port_owner;struct usb_device *child;#ifdef CONFIG_ACPI acpi_handle port_acpi_handle;#endif +struct attribute_group port_attr_group;
I think you don't need the attribute_group at all. See below.
Quoted 4 lines
drivers/usb/core/hub.c +0
-0@@ -2558,6 +2577,25 @@ static int port_is_power_on(struct usb_hub *hub, unsigned portstatus)return ret; }
drivers/usb/core/hub.c static int port_is_power_on(struct usb_hub *hub, unsigned portstatus) · line 2589
Quoted 10 lines
drivers/usb/core/hub.c +10
-0+static int usb_get_hub_port_power_state (struct usb_device *hdev,int port1) +{ +struct usb_hub *hub =hdev_to_hub (hdev); +struct usb_port_status data; +u16 portstatus; +int ret; + + ret =get_port_status (hub->hdev, port1, &data); +if (ret <4 ) { + dev_err (hub->intfdev,
checkpatch will complain about the ' ' before the '('. You should fix such problems before posting.
Quoted 6 lines
drivers/usb/core/hub.c +2
-0@@ -4499,6 +4537,139 @@ static int hub_thread(void *__unused)return 0 ; } +static ssize_t show_port_power_state (struct device *dev, +struct device_attribute *attr,char *buf)
drivers/usb/core/hub.c static int hub_thread(void *__unused) · line 4551
Quoted 10 lines
drivers/usb/core/hub.c +10
-0+{ +struct usb_device *udev =to_usb_device (dev->parent); +struct usb_hub_port *hub_port =container_of (attr, + struct usb_hub_port, port_state_attr); +int power_state; +const char *result; +int port1; + +if (sscanf (hub_port->port_attr_group.name,"port%d" , &port1) !=1 ) +return -EINVAL ;
You can determine the port number without using the attribute group:
struct usb_hub *hub = dev_get_drvdata(dev); int port1 = hub_port - hub->port_data + 1;
drivers/usb/core/hub.c static int hub_thread(void *__unused) · line 4624
Quoted 4 lines
drivers/usb/core/hub.c +4
-0+static void usb_hub_port_sysfs_add (struct usb_hub *hub) +{ +int i, rc; +struct attribute * port_attrs[3 ];
s/e* p/e *p/
Make port_attr_group another local variable rather than part of hub->port_data[i].
Quoted 14 lines
drivers/usb/core/hub.c +14
-0+ +for (i =0 ; i < hub->hdev->maxchild; i++) { + hub->port_data[i].port_control_attr = (struct device_attribute ) +__ATTR (control,S_IRUGO |S_IWUSR , + show_port_power_control, + store_port_power_control); + hub->port_data[i].port_state_attr = (struct device_attribute ) +__ATTR (state,S_IRUGO , show_port_power_state,NULL ); + + port_attrs[0 ] = &hub->port_data[i].port_control_attr.attr; + port_attrs[1 ] = &hub->port_data[i].port_state_attr.attr; + port_attrs[2 ] =NULL ; + hub->port_data[i].port_attr_group = (struct attribute_group ) { + .name = port_name[i],
drivers/usb/core/hub.c static int hub_thread(void *__unused) · line 4648
Quoted 10 lines
drivers/usb/core/hub.c +10
-0+ .attrs = port_attrs + }; + + rc =sysfs_create_group (&hub->intfdev->kobj, + &hub->port_data[i].port_attr_group); +if (rc <0 ) +dev_err (hub->intfdev,"can't create sys " \ +"files for port%d\n" , i +1 ); + } +}
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
In reply to a message not in the archiveQuoted 15 lines · Alan Stern
On Mon, 4 Jun 2012, Lan Tianyu wrote:
s/attribue/attribute/ -- here and belowDocumentation/ABI/testing/sysfs-bus-usb Description: · line 232
Quoted 8 lines
Documentation/ABI/testing/sysfs-bus-usb +8
-0+ allows the user space to control the power policy on the usb port + + All ports have one of the following three values for portX/control + "auto" - For ports with device, if the device was not in the suspend + at that pointer, the power would remain on but it would power + off when it was suspended. If the the device was in the suspend, + "auto" means the device could be put into much lower state so + the device would be resumed and suspended again.The patch does not implement anything at all for "auto". It should do _something_.
Yeah, if we don't power off port without device when echo "auto" > portX/control, this patch does nothing about "auto". Original plan is to deal with port without devices firstly. Do you mean I should add the process of port with device in this patch?
Signature · 7 lines
Best Regards Tianyu Lan linux kernel enabling team -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
Quoted 7 lines · Lan Tianyu
Quoted 3 lines
The patch does not implement anything at all for "auto". It should do _something_.
Yeah, if we don't power off port without device when echo "auto" > portX/control, this patch does nothing about "auto". Original plan is to deal with port without devices firstly. Do you mean I should add the process of port with device in this patch?
At least make a start. For example, have "auto" turn off the power if no device is attached to the port.
If "auto" does nothing, there's no reason to put it in this patch at all. It could be added in a later patch, along with its implementation.
Alan Stern
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
In reply to a message not in the archiveQuoted 5 lines · Alan Stern
Quoted 3 lines · Lan Tianyu
Quoted 3 lines
The patch does not implement anything at all for "auto". It should do _something_.
Quoted 7 lines
Quoted 4 lines
Yeah, if we don't power off port without device when echo "auto" > portX/control, this patch does nothing about "auto". Original plan is to deal with port without devices firstly. Do you mean I should add the process of port with device in this patch?
At least make a start. For example, have "auto" turn off the power if no device is attached to the port.
Auto should only turn off power if no device is attached to the port *and* we know it's an internal port through ACPI. Don't forget that we'll lose port connect events when the power is off.
Sarah Sharp
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
In reply to Alan SternQuoted 5 lines · Alan Stern
Quoted 3 lines · Lan Tianyu
Quoted 3 lines
The patch does not implement anything at all for "auto". It should do _something_.
Quoted 7 lines
Quoted 4 lines
Yeah, if we don't power off port without device when echo "auto"> portX/control, this patch does nothing about "auto". Original plan is to deal with port without devices firstly. Do you mean I should add the process of port with device in this patch?
At least make a start. For example, have "auto" turn off the power if no device is attached to the port.
In your reply for v2, hint that user space can power off port without device, so I removed related code. Did I misunderstand?
Quoted 17 lines
Quoted 3 lines
control has three options. "auto", "on" and "off" "auto" - if port without device, power off the port.
(This patch only cover ports without device)Is this option really needed? Can't userspace check first to see whether there is a device, and then write "off" if there isn't?
Quoted 5 lines
For ports with device, there is a proposal that if the device was not in the suspend at that pointer, the power would remain on but it would power off when it was suspended. If the the device was in the suspend, "auto" means the device could be put into much lower state so the device need to resume and suspend again.
That makes more sense. Without this, however, there is no need for "auto".
Quoted 3 lines
If "auto" does nothing, there's no reason to put it in this patch at all. It could be added in a later patch, along with its implementation.
OK. I prefer to remove "auto" option in this patch. We can further discuss the function of "auto".
Quoted 3 lines
Alan Stern
Signature · 7 lines
Best Regards Tianyu Lan linux kernel enabling team -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
Quoted 5 lines · Lan Tianyu
Quoted 3 lines
If "auto" does nothing, there's no reason to put it in this patch at all. It could be added in a later patch, along with its implementation.
OK. I prefer to remove "auto" option in this patch. We can further discuss the function of "auto".
Sounds good.
One more problem -- your implementation of "off" isn't quite right. You need to update hub_power_on() too.
Alan Stern
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
Quoted 5 lines · Alan Stern
Quoted 3 lines · Lan Tianyu
Quoted 3 lines
If "auto" does nothing, there's no reason to put it in this patch at all. It could be added in a later patch, along with its implementation.
Quoted 8 lines
Quoted 2 lines
OK. I prefer to remove "auto" option in this patch. We can further discuss the function of "auto".
Sounds good.
One more problem -- your implementation of "off" isn't quite right. You need to update
hub_power_on()too.
How about this?
drivers/usb/core/hub.c +3 -1
@@ -861,7 +861,9 @@ static unsigned hub_power_on(struct usb_hub *hub, bool do_delay)dev_dbg (hub->intfdev,"trying to enable port power on " "non-switchable hub\n" );for (port1 =1 ; port1 <= hub->descriptor->bNbrPorts; port1++) -set_port_feature (hub->hdev, port1,USB_PORT_FEAT_POWER ); +if (hub->port_data[port1 -1 ].port_power_policy + ==USB_PORT_POWER_ON ) +set_port_feature (hub->hdev, port1,USB_PORT_FEAT_POWER );/* Wait at least 100 msec for power to become stable */ delay =max (pgood_delay, (unsigned )100 );
Quoted 2 lines
Alan Stern
Signature · 7 lines
Best Regards Tianyu Lan linux kernel enabling team -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH V3 3/3] usb : Add sysfs files to control usb port's power
Quoted 8 lines · Lan Tianyu
Quoted 3 lines
One more problem -- your implementation of "off" isn't quite right. You need to update
hub_power_on()too.How about this?
drivers/usb/core/hub.c static unsigned hub_power_on(struct usb_hub *hub, bool do_delay) · line 866
Quoted 7 lines
drivers/usb/core/hub.c +3
-1@@ -861,7 +861,9 @@ static unsigned hub_power_on(struct usb_hub *hub, bool do_delay)dev_dbg (hub->intfdev,"trying to enable port power on " "non-switchable hub\n" );for (port1 =1 ; port1 <= hub->descriptor->bNbrPorts; port1++) -set_port_feature (hub->hdev, port1,USB_PORT_FEAT_POWER ); +if (hub->port_data[port1 -1 ].port_power_policy + ==USB_PORT_POWER_ON ) +set_port_feature (hub->hdev, port1,USB_PORT_FEAT_POWER );
Yes, that's the idea.
Alan Stern