USB(isp1763)驱动在uboot中的流程分析

本文详细分析了isp1763 USB驱动在uboot中的实现流程,包括uboot配置选项、CMD、USB枚举、ISP 1763驱动、usb_mass_storage驱动等关键步骤。讲解了从初始化到USB设备枚举、设备描述符获取、控制消息传输的过程,以及ISP 1763寄存器操作和FAT32文件系统处理。
摘要由CSDN通过智能技术生成

uboot配置选项

CONFIG_USB=y

CONFIG_DM_USB=y

CONFIG_USB_ISP1760=y

CONFIG_USB_STORAGE=y

CMD

U_BOOT_CMD(

            usb,      5,         1,         do_usb,

            "USB sub-system",

            "start - start (scan) USB controller\n"

            "usb reset - reset (rescan) USB controller\n"

            "usb stop [f] - stop USB [f]=force stop\n"

            "usb tree - show USB device tree\n"

            "usb info [dev] - show available USB devices\n"

            "usb test [dev] [port] [mode] - set USB 2.0 test mode\n"

            "    (specify port 0 to indicate the device's upstream port)\n"

            "    Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]\n"

#ifdef CONFIG_USB_STORAGE

            "usb storage - show details of USB storage devices\n"

            "usb dev [dev] - show or set current USB storage device\n"

            "usb part [dev] - print partition table of one or all USB storage"

            "    devices\n"

            "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"

            "    to memory address `addr'\n"

            "usb write addr blk# cnt - write `cnt' blocks starting at block `blk#'\n"

            "    from memory address `addr'"

#endif /* CONFIG_USB_STORAGE */

);

do_usb

do_usb

            -》do_usb_start()

            -》usb_show_tree()

            -》usb_init()

 1763 USB 枚举

 Dts

usb: usb@40200000 {

                        compatible = "nxp,usb-isp1763";

                        reg = <0x40200000 0x100000>;

                        interrupts-parent = <&gic>;

                        interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH>;

                        bus-width = <16>;

                        dr_mode = "host";

            };

UCLASS_USB

Uclass_get(UCLASS_USB, &uc) 会找如下的结构体定义:

UCLASS_DRIVER(usb) = {

            .id                    = UCLASS_USB,

            .name               = "usb",

            .flags                = DM_UC_FLAG_SEQ_ALIAS,

            .post_bind        = dm_scan_fdt_dev,

            .priv_auto         = sizeof(struct usb_uclass_priv),

            .per_child_auto = sizeof(struct usb_device),

            .per_device_auto          = sizeof(struct usb_bus_priv),

            .child_post_bind = usb_child_post_bind,

            .child_pre_probe = usb_child_pre_probe,

            .per_child_plat_auto      = sizeof(struct usb_dev_plat),

};

ISP 1763 driver

static const struct udevice_id isp1760_ids[] = {

            { .compatible = "nxp,usb-isp1760", },

            { .compatible = "nxp,usb-isp1761", },

            { .compatible = "nxp,usb-isp1763", },

            { },

};

U_BOOT_DRIVER(isp1760) = {

            .name               = "isp1760",

            .id                    = UCLASS_USB,

            .of_match         = isp1760_ids,

            .of_to_plat        = isp1760_of_to_plat,

            .ops                  = &isp1760_usb_ops,

            .probe              = isp1760_plat_probe,

            .remove            = isp1760_plat_remove,

            .plat_auto         = sizeof(struct isp1760_device),

            .priv_auto         = sizeof(struct isp1760_host_data),

};

usb_mass_storage driver

//common/usb_storage.c

U_BOOT_DRIVER(usb_mass_storage) = {

               .name     = "usb_mass_storage",

               .id           = UCLASS_MASS_STORAGE,

               .of_match = usb_mass_storage_ids,

               .probe = usb_mass_storage_probe,

#if CONFIG_IS_ENABLED(BLK)

               .plat_auto              = sizeof(struct us_data),

#endif

};

对应的UCLASS定义如下:

UCLASS_DRIVER(usb_mass_storage) = {

               .id                          = UCLASS_MASS_STORAGE,

               .name                    = "usb_mass_storage",

};

//静态定义struct usb_driver_entry

static const struct usb_device_id mass_storage_id_table[] = {

               {

                              .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,   //通过这里来匹配

                              .bInterfaceClass = USB_CLASS_MASS_STORAGE

               },

               { }                           /* Terminating entry */

};

U_BOOT_USB_DEVICE(usb_mass_storage, mass_storage_id_table);

​​​​​​​usb_init()

usb_init  //drivers/usb/host/usb-uclass.c

               -》uclass_get(UCLASS_USB, &uc)  //获取到如下定义的 UCLASS_DRIVER(usb) 结构体

                              -》uc = uclass_find(id)

               -》uclass_foreach_dev(bus, uc)  //依次遍历uc->dev_head 链表中的所有udevice,这些udevice是在扫描DTB 时自动创建的

                    device_probe(bus)

                              -》drv = dev->driver

                              -》uclass_pre_probe_device(dev)

                                             -》uc_drv->child_pre_probe(dev)  //调用uclass_driver中定义的child_pre_probe()

                              -》drv->probe(dev)  //调用udevice driver定义的probe函数,即isp1760_plat_probe()

                              -》uclass_post_probe_device(dev)

                                             -》uc_drv->child_post_probe(dev) //调用uclass_driver中定义的child_post_probe()

               -》uclass_foreach_dev(bus, uc)

               -》usb_scan_bus(bus, true)  //扫描USB 总线 的设备

                              -》usb_scan_device(bus, 0, USB_SPEED_FULL, &dev)  //这里扫描到的应该是 HUB 设备,其他的设备,会在usb_hub_post_probe() 中依次被扫描到

                                             -》ALLOC_CACHE_ALIGN_BUFFER(struct usb_device, udev, 1);

                                             -》struct usb_interface_descriptor *iface = &udev->config.if_de

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值