1 EHCI和Companion UHCI端口切换
1.1 ICH6 EHCI
如果PCI控制器包括了伴随控制器,那么USB 2.0 HC(Host Controller)必须作为一个多功能PCI设备使用。伴随HC的功能码必须小于EHCI HC功能码。如果一个 PCI设备仅仅包括一个EHCI控制器(即没有其他伴随控制器和其它PCI功能)那么根据PCI规范, EHCI HC功能码必须是0。 结构参数寄存器HCSPARAMS的 N_CC(Num of Companion Controllers)域指示EHCI HC是否包括伴随HC。当N_CC域有一个非0值时表示EHCI HC存在伴随HC,如果N_CC域为0时,EHCI HC不包含伴随HC。
1.2 USB Rate Matching Hub
If the SoC has USB Rate Matching Hub (RMH), then EHCI does not need companion OHCI, the RMH connects to port1 of 4-port EHCI. The USB RMH Think Time is equal to hub descriptor register of 8 full-speed bit times. Refer to Atom C2000 EHCI chapter.
1.3 Companion HC和嵌入式TT的区别
本章讨论的是PC机的USB Host架构,对于嵌入式系统来说,由于EHCI(ARC、DWC2、TDI)在RootHub中集成了TT,所以不需要执行端口切换,仅仅使用宏ehci_is_TDI(ehci)进行判断即可。
当EHCI RootHub集成了TT时,由于标准的EHCI PORTSCx寄存器没有外接设备速度描述,所以Vendor针对这个问题进行了扩展:
- 一种是使用PORTSCx的B27...26作为外接设备的速度显示,for example 40nm iMX 6Quad
- 另外一种是扩展一个额外的寄存器HOSTPCx(Host Port Control,which are extensions to PORTSCx,Linux内核关键字是has_hostpc),主要包含PHCD(PHy Clock Disable)和PSPD(Port SPeed Detection)2个bit位,for example Intel Moorestown SoC (45nm Atom Z600, released on May 05, 2010)
1.4 github NT5.1
IoConnectInterrupt()
base/ntos/io/pnpmgr
drivers/wdm/usb/driver/hub.pnp/usbhub.c
USBH_SubmitInterruptTransfer()
当port连接改变时,usbhub调用USBH_IoInvalidateDeviceRelations()通知PNP管理器,接下来PNP管理器通知usbccgp驱动去读取设备和配置描述符,并创建PDO。
drivers/wdm/usb/usbccgp/parent.c
TryGetConfigDescriptor()
PNP: IoInvalidateDeviceRelations()
创建类PDO并通知PNP管理器加载USB类驱动。
2 EHCI知识点
2.1 IAAD - Interrupt on Async Advance Doorbell
不同类型的传输如何处理unlink urb
- unlink control/bulk urb,调用start_unlink_async()处理,两阶段处理,先从链表中删除,再通知HC更新缓冲的地址(作用类似于更新CPU cache的函数flush_all_cache()),HC更新完成后会触发STS_IAA中断,通知CPU已经安全unlink了
- unlink interrupt urb,可以参考ehci_urb_dequeue()以及qh_completions()中的处理
- unlink isochronous urb,可以参考ehci_urb_dequeue()以及scan_periodic(),itd_complete()中的处理
Figure 2-1 Generic Queue Head Unlink Scenario
[PATCH 17/25] USB: EHCI: use hrtimer for the IAA watchdog
https://www.spinics.net/lists/linux-usb/msg67160.html
2.2 Watchdog Timer
Watchdog Timer - 主要用于发现和处理EHCI irq lost(主要给Isochronous或者对于irq有bug的EHCI使用need_io_watchdog强制打开)的情况
ehci_irq()
ehci_work() - 假如EHCI irq lost,这个函数也可以充当polling的角色
turn_on_io_watchdog()
3 SoC showcase
3.1 Amlogic 28nm S912
S912 was released in 2016. One dwc2 OTG 0xC900_0000 and one dwc2 EHCI 0xC910_0000. Phicomm OTT Box T1 used S912.
3.2 Atmel SAMA7G54
SAMA7G54 was released in May 2022. It integrated 3-port MPH EHCI, port1 and port2 are shared with two independent USB devices.
UDPHS_CTRL.bit8 of each USB device instance is used to mux EHCI port1 or port2 with USB device. UDPHS means USB Device High Speed Port. Refer to SAMA7G54 datasheet 71.5.2 UTMI Transceiver Sharing.
UHPHS_OHCI: 0x0040_0000
UHPHS_EHCI: 0x0050_0000
UDPHSA: 0xE081_4000
UDPHSB: 0xE081_8000
TCPCA: 0xE084_0000
TCPCB: 0xE084_4000
Atmel SAM V71 (vehicle) has a single port USB mini host, every host pipe has an independent FIFO. Host Address 1/2/3 Register include 7bits USB device address.
3.3 iMX51
iMX51 was released in 2009. Refer to github imx51.dtsi.
QSB: Quick Start Board
SABRE: NXP Smart Application Blueprint for Rapid Engineering
USBOTG: 0x73f8_0000, ARC
USBH1: 0x73f8_0200, USB3317
USBH2: 0x73f8_0400
USBH3: 0x73f8_0600
3.4 iMX 6Quad SABRE
iMX 6 was released in 2011. Refer to github imx6qdl.dtsi, 6qdl means 6Quad and 6DualLite.
iMX 6Quad有4个Chipidea SPH (Single Port Host) USB EHCI,其中第一个SPH具有OTG功能,第3和第4个是HSIC。
USBOTG: 0x0218_4000
USBH1: 0x0218_4200
USBH2: 0x0218_4400
USBH3: 0x0218_4600
USBPHY1: 0x020C_9000
USBPHY2: 0x020C_A000
3.5 ISP1362
Refer to datasheet: 11.3 USB ports
2-port MPH ISP1362 = PSHC + ISP1181B
Refer to datasheet: 11.6 Features of the interrupt transfer
An interrupt transaction causes an interrupt to the CPU only if the transaction is ACK-ed or has error conditions, such as STALL or no respond. An ACK condition occurs if data is received on the IN token or data is sent out on the OUT token.
ISP: Philips' integrated host solution pairs
Firms introduce USB host controllers
https://www.eetimes.com/firms-introduce-usb-host-controllers/#
4 Abbreviations
ARC:Argonant RISC Core
Atmel SAMA7G54: SAM means Smart ARM-based Microcontroller Cortex A7
CCGP:Windows USB Common Class Generic Parent,Linux内核类似的驱动就是usb_generic_driver(generic.c)
CCGP MI_:Common Class Generic Parent Multi Interface
CYPRESS TD_Poll:Task Dispatch
giveback:归还 - ehci_urb_done() -> usb_hcd_giveback_urb()。USB PD中的giveback(= 1)指sink会响应source的GotoMin请求,返还部分电力给source。
halt:停车或者站住,来自于德语;USB endpoint停止运行,返回stall handshake。recovery方法:control ep接收下一次SETUP PID时,自动清除halt标志;其它ep使用clear_feature复位ep halt。
IAAD:EHCI Interrupt on Async Advance Doorbell
ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054
MPH:USB Multi-Port Host,Intel的MPH的Port1作为OTG使用,和DWC3(仅作为slave)使用一个MUX开关来控制Host还是UDC连接到该Port1
SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当
SPH:USB Single-Port Host
TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购
TT:Transaction Translator(事务转换器,将USB2.0的包转换成USB1.1的包)
USB Host枚举时-71错误码可能原因:DP和DM走线太长导致眼图差;DP和DM接反了