android 9.0上usb otg休眠问题

本文探讨了在Android 9.0系统中,如何解决USB OTG(On-The-Go)模式下设备进入休眠的问题。通过参考高通文档,了解到当USB设备空闲超过预设时间时,可通过启用autosuspend功能实现休眠。但需要注意,某些设备类驱动未开启autosuspend,例如mass storage设备。示例中展示了针对HID设备启用autosuspend的代码修改。此外,文章还提醒在8994/8992平台上,主机总线挂起不支持,并强调检查设备是否支持远程唤醒,以及在配置描述符中设备如何报告该能力。最后,讨论了不同场景下USB远程唤醒的使用和主机休眠状态的维持策略。
摘要由CSDN通过智能技术生成

问题:手机作为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 &&
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

归心2020

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值