问题:手机作为otg host时,怎样才能进入待机休眠?
参考高通文档:《80-NF283-1_C_Linux_USB_Implementation_Guide》
section: 7.1.2 Host mode state transition
As shown in Figure 7-1, the USB enters LPM when:
●The USB A-Cable is removed, with or without a B-Device connected.
●USB bus suspend – USB Host mode provides the Autosuspend feature via CONFIG_USB_SUSPEND, defined by default. The host controller driver monitors each device connected on the bus and, if any device is idle for a period more than a predefined timeout, it selectively suspends the device. However, if any one of the drivers corresponding to an interface in the USB device does not support Autosuspend, the device cannot be suspended. The mass storage driver does not support Autosuspend.Hence, if a mass storage device is connected, it is not suspended. The HUB driver supports Autosuspend. More information is available at Documentation/usb/power-management.txt.
高通case回复Answer:
Linux Android USB host driver stack(UHCI&EHCI&XHCI) have support for suspend/power collapse, but most device class drivers do not enabled auto suspend. We need to enable autosuspend for those devices,can call usb_enable_autosuspend() function in the driver device probe routine.
An example for HID device is as below:(如下的例子是一个HID设备休眠的修改)
drivers/hid/usbhid/hid-core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index ff052c8…399d964 100644
— a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1338,6 +1338,9 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
goto err_free;
}
+/* enable suspend/resume support for HID devices. */
+usb_enable_autosuspend(dev);
return 0;
err_free:
kfree(usbhid);
@@ -1349,11 +1352,13 @@ err:
static void usbhid_disconnect(struct usb_interface *intf)
{
struct hid_device *hid = usb_get_intfdata(intf);
+struct usb_device *dev = interface_to_usbdev(intf);
struct usbhid_device *usbhid;
if (WARN_ON(!hid))
return;
+usb_disable_autosuspend(dev);
usbhid = hid->driver_data;
hid_destroy_device(hid);
kfree(usbhid);
按照上面的修改后,otg侧连上鼠标是可以进入休眠了,主机功耗满足要求;点击鼠标是可以正常唤醒手机的。
注意点1:
on 8994/8992, host bus suspend is not supported due to some HW issue.
static int dwc3_otg_start_host(struct usb_otg *otg, int on)
{
…
/**
*WORKAROUND: currently host mode suspend isn't working well.
*Disable xHCI's runtime PM for now.
*/
pm_runtime_disable(&dwc->xhci->dev);
注意点2:
需要检查设备是否支持remotewakeup,如果不支持的话,autosuspend就不会执行下去的。autosuspend_check函数会去检查设备是否支持remotewakeup:
if (w &&