MUSB (3) --- OMAP2430 USB OTG Controller(device)

分类: Android平台

1. Makefile
fudan_abc在他的《Linux那些事儿之我是USB》中反复提到了Makefile.作为整个软件架构分析的map.
这里拾人牙慧也按照这种方式来描述MUSB的软件架构.
红色部分是指arch/arm/configs/XXXX_config中已经定义的.

点击(此处)折叠或打开

  1. #
  2. for USB OTG silicon based on Mentor Graphics INVENTRA designs
  3. #

  4. ccflags-$(CONFIG_USB_MUSB_DEBUG) := -DDEBUG

  5. obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o

  6. musb_hdrc-:= musb_core.o

  7. musb_hdrc-$(CONFIG_USB_GADGET_MUSB_HDRC)    += musb_gadget_ep0.o musb_gadget.o
  8. musb_hdrc-$(CONFIG_USB_MUSB_HDRC_HCD)        += musb_virthub.o musb_host.o
  9. musb_hdrc-$(CONFIG_DEBUG_FS)            += musb_debugfs.o
  10. ifeq ($(CONFIG_USB_MUSB_DEBUG),y)
  11.     musb_hdrc-$(CONFIG_PROC_FS) += musb_procfs.o
  12. endif
  13. # Hardware Glue Layer
  14. obj-$(CONFIG_USB_MUSB_OMAP2PLUS_GLUE)        += omap2430.o
  15. obj-$(CONFIG_USB_MUSB_AM35X_GLUE)        += am35x.o
  16. obj-$(CONFIG_USB_MUSB_TI81XX_GLUE)        += ti81xx.o
  17. obj-$(CONFIG_USB_MUSB_TUSB6010_GLUE)        += tusb6010.o
  18. obj-$(CONFIG_USB_MUSB_DAVINCI_GLUE)            += davinci.o
  19. obj-$(CONFIG_USB_MUSB_DA8XX_GLUE)            += da8xx.o
  20. obj-$(CONFIG_USB_MUSB_BLACKFIN_GLUE)        += blackfin.o
  21. obj-$(CONFIG_USB_MUSB_UX500_GLUE)            += ux500.o

  22. # the kconfig must guarantee that only one of the
  23. # possible I/O schemes will be enabled at a time ...
  24. # PIO only, or DMA (several potential schemes).
  25. # though PIO is always there to back up DMA, and for ep0

  26. obj-$(CONFIG_USB_INVENTRA_DMA_HW)        += musbhsdma.o
  27. obj-$(CONFIG_USB_TI_CPPI_DMA_HW)        += cppi_dma.o
  28. obj-$(CONFIG_USB_TI_CPPI41_DMA_HW)        += cppi41dma.o
  29. cppi41dma-y                    += cppi41.o cppi41_dma.o
  30. obj-$(CONFIG_USB_TUSB_OMAP_DMA_HW)        += tusb6010_omap.o

从上图中,我把Makefile中的源文件分为了三类:
(1) Controller相关
主要源文件2个:OMAP2430.c & musbhsdma.c
(2) Host 相关
这部分是很困难的部分,在后续的章节中要仔细分析他们是如何跟USB core关联起来的.
musb_hdrc.c
musb_gadget_ep0.c
musb_gadget.c
musb_virthub.c
musb_host.c
(3) debugfs
不做分析.
2. Host Controller
众所周知,在Linux的驱动架构中.有device和driver两部分.在最后他们会配对.
(1) device

点击(此处)折叠或打开

  1. static struct omap_musb_board_data musb_board_data = {
  2.     .interface_type        = MUSB_INTERFACE_ULPI,
  3.     .mode            = MUSB_OTG,
  4.     .power            = 100,
  5. };
-->这就是device开始注册的起点. power域由原来的100mA修改为了500mA.这部分的详细描述参见USB spec. 最为让人奇怪的是extbus这个域.顾名思义是引用外部的电源.这个后续遇到了再做讨论.

点击(此处)折叠或打开

  1. static int __init xxx_musb_init(void) {

  2.     int ret;

  3.     /* EVM REV >= E can supply 500mA with EXTVBUS programming */
  4.     musb_board_data.power = 500;
  5.     musb_board_data.extvbus = 1;
  6.     usb_musb_init(&musb_board_data);

  7.     return 0;
  8. }
-->那么接下来就是usb_musb_init

点击(此处)折叠或打开

  1. void __init usb_musb_init(struct omap_musb_board_data *board_data)
  2. {
  3.     int i;

  4.     if (cpu_is_omap243x()) {
  5.         musb_resources[0].start = OMAP243X_HS_BASE;
  6.     } else if (cpu_is_omap3517() || cpu_is_omap3505()) {
  7.         musb_device[0].name = "musb-am35x";
  8.         musb_resources[0].start = AM35XX_IPSS_USBOTGSS_BASE;
  9.         musb_resources[1].start = INT_35XX_USBOTG_IRQ;
  10.         board_data->set_phy_power = am35x_musb_phy_power;
  11.         board_data->clear_irq = am35x_musb_clear_irq;
  12.         board_data->set_mode = am35x_musb_set_mode;
  13.         board_data->reset = am35x_musb_reset;
  14.     } else if (cpu_is_omap34xx()) {
  15.         musb_resources[0].start = OMAP34XX_HSUSB_OTG_BASE;
  16.     } else if (cpu_is_omap44xx()) {
  17.         musb_resources[0].start = OMAP44XX_HSUSB_OTG_BASE;
  18.         musb_resources[1].start = OMAP44XX_IRQ_HS_USB_MC_N;
  19.         musb_resources[2].start = OMAP44XX_IRQ_HS_USB_DMA_N;
  20.     } else if (cpu_is_ti81xx()) {

  21.         /* disable musb multipoint support for ti8168 */
  22.         if (cpu_is_ti816x())
  23.             musb_config.multipoint = 0;

  24.         /* only usb0 port enabled in peripheral mode*/
  25.         if (board_data->mode == MUSB_PERIPHERAL)
  26.             board_data->instances = 0;

  27.         musb_resources[0].start = TI81XX_USB0_BASE;
  28.         musb_resources[1].start = TI81XX_IRQ_USB0;
  29.         musb_resources[0].end = musb_resources[0].start + SZ_2K - 1;

  30.         for (= 0; i <= board_data->instances; i++) {
  31.             musb_device[i].name = "musb-ti81xx";
  32.             musb_device[i].num_resources = 0;
  33.         }

  34.         musb_config.fifo_mode = 4;
  35.         board_data->set_phy_power = ti81xx_musb_phy_power;
  36.     }

  37.     if (cpu_is_omap3517() || cpu_is_omap3505())
  38.         musb_resources[0].end = musb_resources[0].start + SZ_32K - 1;
  39.     else if (!cpu_is_ti81xx())
  40.         musb_resources[0].end = musb_resources[0].start + SZ_4K - 1;

  41.     /*
  42.      * OMAP3630/AM35x platform has MUSB RTL-1.8 which has the fix for the
  43.      * issue restricting active endpoints to use first 8K of FIFO space.
  44.      * This issue restricts OMAP35x platform to use fifo_mode '5'.
  45.      */
  46.     if (cpu_is_omap3430())
  47.         musb_config.fifo_mode = 5;

  48.     for (= 0; i <= board_data->instances; i++) {
  49.         if (cpu_is_ti816x())
  50.             musb_plat[i].clock = "usbotg_ick";
  51.         else if (cpu_is_ti814x())
  52.             musb_plat[i].clock = "usb_ick";

  53.         musb_plat[i].board_data = board_data;
  54.         musb_plat[i].power = board_data->power >> 1;
  55.         musb_plat[i].mode = board_data->mode;
  56.         musb_plat[i].extvbus = board_data->extvbus;

  57.         if (platform_device_register(&musb_device[i]) < 0)
  58.             printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
  59.     }

  60.     usb_musb_pm_init();
  61. }
我总是急功近利的,line:68 就将device注册进系统了.这也是整个device部分的终结点.
那么注册device到底涉及到了哪些方方面面的内容呢?仔细分析这部分是十分有必要的.首先,这可以帮助我们了解到MUSB这个device到底包含了哪些资源,对MUSB的硬件结构有了一个更为数字化的印象;其次再遇到其它设备的时候我们也能够以彼之道还施彼身,彼这里就是指MUSB了.也就是一法通万法通.
cpu_is_omap34xx ( )的返回值为true.
所以line:16  musb_resources [ 0 ] . start  =  OMAP34XX_HSUSB_OTG_BASE ;
跟它对应的是line:47,这个是分配OTG controller的register物理地址

line 55: musb_config全局变量
line 63: musb_plat全局变量
line 68: 是最后注册的,我们要了解的就是:

点击(此处)折叠或打开

  1. static struct platform_device musb_device[] = {
  2.     {
  3.         .name        = "musb-omap2430",
  4.         .id        = 0,
  5.         .dev = {
  6.             .dma_mask        = &musb_dmamask,
  7.             .coherent_dma_mask    = DMA_BIT_MASK(32),
  8.             .platform_data        = &musb_plat[0],
  9.         },
  10.         .num_resources    = 3,
  11.         .resource    = &musb_resources[0],
  12.     },
  13.     {
  14.         .name        = "musb-omap2430",
  15.         .id        = 1,
  16.         .dev = {
  17.             .dma_mask        = &musb_dmamask,
  18.             .coherent_dma_mask    = DMA_BIT_MASK(32),
  19.             .platform_data        = &musb_plat[1],
  20.         },
  21.         .num_resources    = 3,
  22.         .resource    = &musb_resources[3],
  23.     },

  24. };
--->

点击(此处)折叠或打开

  1. static struct musb_hdrc_platform_data musb_plat[] = {
  2.     {
  3.         .config = &musb_config,
  4.         .clock = "ick",
  5.     },
  6.     {
  7.         .config = &musb_config,
  8.         .clock = "ick",
  9.     },
  10. };
--->

点击(此处)折叠或打开

  1. static struct musb_hdrc_config musb_config = {
  2.     .fifo_mode    = 4,
  3.     .multipoint    = 1,
  4.     .dyn_fifo    = 1,
  5.     .num_eps    = 16,
  6.     .ram_bits    = 12,
  7. };
这里fifo_mode 被设置成了 5.

点击(此处)折叠或打开

  1. static struct resource musb_resources[] = {
  2.     [0] = { /* start and end set dynamically */
  3.         .flags    = IORESOURCE_MEM,
  4.     },
  5.     [1] = {    /* general IRQ */
  6.         .start    = INT_243X_HS_USB_MC,
  7.         .flags    = IORESOURCE_IRQ,
  8.         .name    = "mc",
  9.     },
  10.     [2] = {    /* DMA IRQ */
  11.         .start    = INT_243X_HS_USB_DMA,
  12.         .flags    = IORESOURCE_IRQ,
  13.         .name = "dma",
  14.     },
  15.     [3] = { /* MEM for TI81x'second musb */
  16.         .flags = IORESOURCE_MEM,
  17.         .start    = TI81XX_USB1_BASE,
  18.         .end    = TI81XX_USB1_BASE + SZ_2K - 1,
  19.     },
  20.     [4] = {    /* IRQ for TI81x'second musb */
  21.         .start    = TI81XX_IRQ_USB1,
  22.         .flags    = IORESOURCE_IRQ,
  23.         .name    = "mc",
  24.     },
  25. };
在line:2~3中我们注意到只有flag,其它部分譬如说start,是在usb_musb_init中根据CPU的类型而进行裁定的.
上述就是所有注册device相关的内容.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值