Linux USB subsystem --- EHCI host controller register

本文深入分析了 Linux USB EHCI 子系统的初始化过程,包括函数实现、USB状态检查、警告信息输出、debugfs目录创建及平台驱动注册等关键步骤。此外,还详细介绍了初始化顺序和相关技术细节。

[Linux 3.2] [driver/usb/host/ehci-hcd.c]

函数:ehci_hcd_init()

  1. static int __init ehci_hcd_init(void)  
  2. {  
  3.     int retval = 0;  
  4.   
  5.     if (usb_disabled())  
  6.         return -ENODEV;  
  7.   
  8.     printk(KERN_INFO "%s: " DRIVER_DESC "\n", hcd_name);  
  9.     set_bit(USB_EHCI_LOADED, &usb_hcds_loaded);  
  10.     if (test_bit(USB_UHCI_LOADED, &usb_hcds_loaded) ||  
  11.             test_bit(USB_OHCI_LOADED, &usb_hcds_loaded))  
  12.         printk(KERN_WARNING "Warning! ehci_hcd should always be loaded"  
  13.                 " before uhci_hcd and ohci_hcd, not after\n");  
  14.   
  15.     pr_debug("%s: block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd\n",  
  16.          hcd_name,  
  17.          sizeof(struct ehci_qh), sizeof(struct ehci_qtd),  
  18.          sizeof(struct ehci_itd), sizeof(struct ehci_sitd));  
  19.   
  20. #ifdef DEBUG  
  21.     ehci_debug_root = debugfs_create_dir("ehci", usb_debug_root);  
  22.     if (!ehci_debug_root) {  
  23.         retval = -ENOENT;  
  24.         goto err_debug;  
  25.     }  
  26. #endif  
  27.   
  28. #ifdef PLATFORM_DRIVER  
  29.     retval = platform_driver_register(&PLATFORM_DRIVER);  
  30.     if (retval < 0)  
  31.         goto clean0;  
  32. #endif  

此函数实现的功能如下:

1. 判断USB是否被禁用了,如果有,直接退出。

2. 打印一条信息:ehci_hcd:    USB 2.0 'Enhanced' Host Controller (EHCI) Driver.

3. 判断UHCI和OHCI是否已经被加载,如果是打印输入warning 信息。

4. pr_debug: 根据编译内核的debug选项,决定是否输出此段信息。

5. 如果定义了DEBUG,则在debugfs下面的usb目录里面创建一个ehci的目录。

6. 注册一个platform驱动。这个platform驱动是根据PLATFORM_DRIVER的定义而决定。platform_driver_register最后还是调用driver_register实现。

(例:对atmel的EHCI来说,如下所示:)

  1. #ifdef CONFIG_ARCH_AT91  
  2. #include "ehci-atmel.c"  
  3. #define PLATFORM_DRIVER     ehci_atmel_driver  
  4. #endif  
其中echi_atmel_driver在ehci-atmel.c文件里面定义。 接下来ehci_atmel_driver里的probe函数(ehci_atmel_drv_probe)就会被调用(为什么呢?本文结尾分析)。

ehci_atmel_drv_proble会调用两个关键函数:usb_create_hcd 与 usb_add_hcd。后篇文章对此进行分析。



备注:内核中的初始化顺序。

start_kernel --> reset_init --> kernel_init --> do_basic_setup --> do_initcalls。do_initcalls的实现如下:

  1. extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[];  
  2.   
  3. static void __init do_initcalls(void)  
  4. {  
  5.     initcall_t *fn;  
  6.   
  7.     for (fn = __early_initcall_end; fn < __initcall_end; fn++)  
  8.         do_one_initcall(*fn);  
  9. }  
其中__early_initcall_end, __initcall_end, __early_initcall_end是在vmlinux.lds文件里面定义。 arch_initcall();首先被调用。在arch/arm/kernel/setup.c中有arch_initcall(customize_machine),所以先执行mdes->init_machine(). 这是在board文件中定义。对atmel的at91sam9m10g45ek板子,就会先注册ohci和ehci。在platform_driver_register-->driver_register-->bus_add_driver-->driver_attach --> 最后调用到probe函数。
dmesg | grep -i usb [ 21.897910] init: Command 'insmod /vendor/lib/usb/dwc3/dwc3.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:161) took 52ms and succeeded [ 21.987854] init: Command 'insmod /vendor/lib/usb/dwc3/dwc3-tcc.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:162) took 89ms and succeeded [ 22.006846] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 22.020681] tcc-ehci 11a00000.ehci: new USB bus registered, assigned bus number 1 [ 22.063784] tcc-ehci 11a00000.ehci: USB 2.0 started, EHCI 1.00 [ 22.064100] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002 [ 22.064114] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.064120] usb usb1: Product: EHCI Host Controller [ 22.064127] usb usb1: Manufacturer: Linux 4.14.65-tcc ehci_hcd [ 22.064131] usb usb1: SerialNumber: 11a00000.ehci [ 22.066712] hub 1-0:1.0: USB hub found [ 22.070177] init: Command 'insmod /vendor/lib/usb/host/ehci-tcc.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:164) took 63ms and succeeded [ 22.088711] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 22.094676] tcc-ohci 11a80000.ohci: new USB bus registered, assigned bus number 2 [ 22.169167] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001 [ 22.169183] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.169188] usb usb2: Product: OHCI Host Controller [ 22.169192] usb usb2: Manufacturer: Linux 4.14.65-tcc ohci_hcd [ 22.169196] usb usb2: SerialNumber: tcc [ 22.175045] hub 2-0:1.0: USB hub found [ 22.179510] init: Command 'insmod /vendor/lib/usb/host/ohci-tcc.ko' action=sys.boot_completed=1 (/vendor/etc/init/init.tcc803x.rc:166) took 90ms and succeeded [ 22.237866] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 3 [ 22.256510] usb usb3: New USB device found, idVendor=1d6b, idProduct=0002 [ 22.256518] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.256523] usb usb3: Product: xHCI Host Controller [ 22.256526] usb usb3: Manufacturer: Linux 4.14.65-tcc xhci-hcd [ 22.256530] usb usb3: SerialNumber: xhci-hcd.0.auto [ 22.262338] hub 3-0:1.0: USB hub found [ 22.267979] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 4 [ 22.267999] xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed [ 22.268097] usb usb4: We don't know the algorithms for LPM for this host, disabling LPM. [ 22.268188] usb usb4: New USB device found, idVendor=1d6b, idProduct=0003 [ 22.268193] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1 [ 22.268197] usb usb4: Product: xHCI Host Controller [ 22.268200] usb usb4: Manufacturer: Linux 4.14.65-tcc xhci-hcd
07-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值