版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kris_fei/article/details/84065481
Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83
背景:
由于rk3399四个usb口不能满足数量需求,对其中的usb3.0(非OTG口)进行外接Hub做扩展成3个USB2.0+1一个USB3.0。
原理图如下:
现象:
插上U盘后出现error:
[ 23.102908] usb 2-1.3: new high-speed USB device number 4 using ehci-platform
[ 23.198825] usb 2-1.3: New USB device found, idVendor=0bda, idProduct=0316
[ 23.198975] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 23.199005] usb 2-1.3: Product: USB3.0-CRW
[ 23.199030] usb 2-1.3: Manufacturer: Generic
[ 23.199054] usb 2-1.3: SerialNumber: 20120501030900000
[ 23.202782] usb 2-1.3: rejected 1 configuration due to insufficient available bus power
[ 23.202980] usb 2-1.3: no configuration chosen from 1 choice
原因:
由于外接Hub没有使用自供电(4个USB口总电流超过500mA),而Hub驱动中对Hub的每个端口配置电流是100mA,导致错误出现。
解决方法:
-
硬件使用Hub芯片自供电方式,满足电流需求。
-
临时解决方法
rk3399_mid:/ #echo 1 > /sys/bus/usb/devices/2-1.2/bConfigurationValue
- 源代码修改方式
是的hub能接受最大电流为500*4=2000mA,这个只是软件的控制。
硬件会对每个端口限流,所以不必担心会出问题。
hub驱动对电流的计算在hub_configure()以及hub_power_remaining()中。
kris@eco:~/rk3399/kernel$ g df
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index fb9223c..50e38b3 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1482,8 +1482,19 @@ static int hub_configure(struct usb_hub *hub,
hub->limited_power = 1;
}
} else if ((hubstatus & (1 << USB_DEVICE_SELF_POWERED)) == 0) {
+
+#if 1
+ int remaining;
+ full_load = 2000;
+ hdev->bus_mA = full_load;
+ unit_load = 500;
+ hub->descriptor->bHubContrCurrent = unit_load;
+ remaining = hdev->bus_mA -
+ hub->descriptor->bHubContrCurrent;
+#else
int remaining = hdev->bus_mA -
hub->descriptor->bHubContrCurrent;
+#endif
dev_dbg(hub_dev, "hub controller current requirement: %dmA\n",
hub->descriptor->bHubContrCurrent);
参考:
USB error: no configuration chosen from 1 choice
USB小知识——500mA的总线供电模式