国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

詳解linux usb host驅動編寫入門

2024-08-28 00:03:21
字體:
來源:轉載
供稿:網友

usb協議是一個復雜的協議,目前涉及到的版本就有usb1.0, usb2.0, usb3.0。大家如果打開kernel usb host目錄,就會發現下面包含了ohci,uhci,ehci,xhci,whci等多種形式的控制器驅動。那么,對于我們這些不是很了解usb的開發人員,如何了解usb的代碼結構呢?

1、代碼分布

drivers/usb目錄下面,host目錄包括了host驅動代碼,core目錄包含了主要的api接口代碼,而其他目錄則主要是device驅動代碼。

2、device驅動怎么看

device驅動大多數和上層協議有關,不涉及到具體的寄存器讀寫。示例代碼可以參考usb-skeleton.c

3、host驅動怎么看

a,不妨以s3c2410的host作為范例進行分析,首先找到Makefile,

obj-$(CONFIG_USB_OHCI_HCD_S3C2410) += ohci-s3c2410.o 

b,再查看一下Kconfig,

config USB_OHCI_HCD_S3C2410     tristate "OHCI support for Samsung S3C24xx/S3C64xx SoC series"     depends on USB_OHCI_HCD && (ARCH_S3C24XX || ARCH_S3C64XX)     default y     ---help---      Enables support for the on-chip OHCI controller on      S3C24xx/S3C64xx chips. 

c,通過Makefile和Kconfig發現,s3c2410依賴于USB_OHCI_HCD_S3C2410 和 USB_OHCI_HCD,那USB_OHCI_HCD呢?

config USB_OHCI_HCD   tristate "OHCI HCD (USB 1.1) support"   depends on HAS_DMA && HAS_IOMEM   ---help---    The Open Host Controller Interface (OHCI) is a standard for accessing    USB 1.1 host controller hardware. It does more in hardware than Intel's    UHCI specification. If your USB host controller follows the OHCI spec,    say Y. On most non-x86 systems, and on x86 hardware that's not using a    USB controller from Intel or VIA, this is appropriate. If your host    controller doesn't use PCI, this is probably appropriate. For a PCI    based system where you're not sure, the "lspci -v" entry will list the    right "prog-if" for your USB controller(s): EHCI, OHCI, or UHCI.     To compile this driver as a module, choose M here: the    module will be called ohci-hcd. 

d,USB_OHCI_HCD只依賴于DMA和IOMEM。繼續回到Makefile,判斷USB_OHCI_HCD會編譯哪些文件

obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 

e,看到這里,我們明白要打開s3c2410的host功能,只需要編譯ohci-hcd.c和ohci-s3c2410.c兩個文件就好了

f,通過觀察,發現ohci-hcd.c和ohci-s3c2410.c的代碼都很少,這原因是什么?下面這段代碼來自于ohci-hcd.c。

static const char  hcd_name [] = "ohci_hcd";  #define STATECHANGE_DELAY  msecs_to_jiffies(300) #define IO_WATCHDOG_DELAY  msecs_to_jiffies(275) #define IO_WATCHDOG_OFF   0xffffff00  #include "ohci.h" #include "pci-quirks.h"  static void ohci_dump(struct ohci_hcd *ohci); static void ohci_stop(struct usb_hcd *hcd); static void io_watchdog_func(struct timer_list *t);  #include "ohci-hub.c" #include "ohci-dbg.c" #include "ohci-mem.c" #include "ohci-q.c" 

g,通過觀察ohci-hcd.c文件,發現其實它其實已經包括了很多其他的ohci文件。那么寄存器又是怎么操作的呢?下面這段代碼來自于ohci.h文件。

static inline unsigned int _ohci_readl (const struct ohci_hcd *ohci,           __hc32 __iomem * regs) { #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO   return big_endian_mmio(ohci) ?     readl_be (regs) :     readl (regs); #else   return readl (regs); #endif }  static inline void _ohci_writel (const struct ohci_hcd *ohci,          const unsigned int val, __hc32 __iomem *regs) { #ifdef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO   big_endian_mmio(ohci) ?     writel_be (val, regs) :     writel (val, regs); #else     writel (val, regs); #endif }  #define ohci_readl(o,r)   _ohci_readl(o,r) #define ohci_writel(o,v,r) _ohci_writel(o,v,r) 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清原| 三门峡市| 淮南市| 互助| 姜堰市| 泗水县| 化德县| 岳阳县| 比如县| 河北省| 荆州市| 邓州市| 孝感市| 政和县| 嘉义县| 苍梧县| 永泰县| 江山市| 武冈市| 武城县| 昌图县| 平度市| 宽城| 吴川市| 孝昌县| 晋宁县| 红桥区| 车险| 乌审旗| 二连浩特市| 钟祥市| 南丰县| 赣榆县| 城口县| 木兰县| 同德县| 张家港市| 夏邑县| 郧西县| 郧西县| 济南市|