一步一步解决kernel2.6 usb host driver

嵌入式技术

1368人已加入

描述


(以下讨论基于kernel 2.6.11,ARM9 s3c2410,arm-linux-gcc 3.4.1 )
=================================================

2.6在s3c2410上usb host不工作的直接结果就是提示110错误:
usb 1-1: device descriptor read/64, error -110

追踪错误代码,我们来看看能不能找到导致这个错误的线索。

include/asm-generic/errno.h
#define EPROTO 71 /* Protocol error */
#define EILSEQ 84 /* Illegal byte sequence */
#define ETIMEDOUT 110 /* Connection timed out */

Documentation/usb/error-codes.txt
-EPROTO (*, **) a) bitstuff error
b) no response packet received within the
prescribed bus turn-around time
c) unknown USB error

-EILSEQ (*, **) a) CRC mismatch
b) no response packet received within the
prescribed bus turn-around time
c) unknown USB error

-ETIMEDOUT (**) No response packet received within the prescribed
bus turn-around time. This error may instead be
reported as -EPROTO or -EILSEQ.

由此我们可以判断,这个错误与 usb 设备的超时有关。报告这个错误的地方在drivers/usb/core/hub.c中的hub_port_init部分,由于usb_get_device_descriptor获取 usb 设备信息的时候产生了超时。这样基本可以确定三种情况,1、usb 设备及接口有问题;2、usb core有问题;3、usb driver有问题。
我们可以很容易地排除1和2的可能性,问题应该在usb driver implement部分造成的。2.6的usb driver把usb规范中对usb接口的操作集中到了core里面,针对不同设备的implement分别归为host、gadget、storage等。基本确定问题就在ohci-s3c2410.c里。

跟踪进入ohci-s3c2410.c,这里面主要完成s3c2410 usb host设备的初始化工作,包括电源、时钟、寄存器等。

其实很多问题在互联网上已经被遇到和解决,我们要做的就是多参考别人的成功经验,这样可以节省时间,同时能够帮助我们找到一些思路。借助google这双强大的翅膀,我们来看看能找到什么:

http://www.linux-usb.org/FAQ.html#ts6

Q: Why doesn’t USB work at all? I get “device not accepting address”.

A: You may have some problem with your PCI setup that’s preventing your USB host controller from getting hardware interrupts. When Linux submits a request, but never hears back from the controller, this is the diagnostic you’ll see. To see if this is the problem, look at /proc/interrupts to see if the interrupt count for your host controller driver ever goes up. If it doesn’t, this is the problem: either your BIOS isn’t telling the truth to Linux (ACPI sometimes confuses these things, or setting the expected OS to windows in your BIOS), or Linux doesn’t understand what it’s saying.

Sometimes a BIOS fix will be available for your motherboard, and in other cases a more recent kernel will have a Linux fix. You may be able to work around this by passing the noapic boot option to your kernel, or (when you’re using an add-in PCI card) moving the USB adapter to some other PCI slot. If you’re using a current kernel and BIOS, report this problem to the Linux-kernel mailing list, with details about your motherboard and BIOS.

google返回的大量结果中有个建议是设置old_scheme_first标志,让驱动程序优先处理采用老式结构的设备:
设置old_scheme_first=y
测试结果并没有太大帮助,不是这个原因引发的。

linux-usb-devel mail list 上Ben大哥正在不断更新他的ohci-s3c2410 driver,但好像还没最终完成。
http://www.mail-archive.com/linux-usb-devel%40lists.sourceforge.net/msg33670.html

跟踪ohci-s3c2410.c,发现to_s3c2410_info返回NULL,很明显,是platform_data没有定义,在 include/asm/arch/usb-control.h中已经有struct s3c2410_hcd_info,那么仿照simtec的usb-simtec.c,来构造自己的platform_data。

static struct s3c2410_hcd_info smdk2410_usbcfg = {
.port[0] = {
.flags = S3C_HCDFLG_USED
},
};

然后在smdk2410_init中完成初始化:

s3c_device_usb.dev.platform_data = &smdk2410_usbcfg;

重新make zImage,情况有所变化:
初始化usb controller的过程中有一行debug信息:
s3c2410-ohci: CTRL: TypeReq=0x2303 val=0x8 idx=0x1 len=0 ==> -115

include/asm-generic/errno.h中查了一下这个错误代码:
#define EINPROGRESS 115 /* Operation now in progress */

Documentation/usb/error-codes.txt中的解释是:
-EINPROGRESS URB still pending, no results yet
(That is, if drivers see this it’s a bug.)

这时无论插入什么USB设备,USB鼠标、U盘、USB无线网卡,都报告:
<6>usb 1-1: new full speed USB device using s3c2410-ohci and address 2
<7>s3c2410-ohci s3c2410-ohci: urb c3c430c0 path 1 ep0in 5ec20000 cc 5 –> status -110

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 相关推荐

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分