Edit online

Device (struct usb_interface)

Read time: 1 minute(s)
如上一节描述, USB Interface Device 对应的数据结构为 struct usb_interface ,会在 USB Device Driver 驱动 probe() 时 被创建:
usb_probe_device() → usb_generic_driver_probe() → usb_set_configuration():

int usb_set_configuration(struct usb_device *dev, int configuration)
{

    /* (1) 创建和初始化 `struct usb_interface` */
    for (i = 0; i < nintf; ++i) {
        /* (1.1) dev 总线初始化为 usb_bus_type */
        intf->dev.bus = &usb_bus_type;
        /* (1.2) dev 类型初始化为 usb_if_device_type,标明自己是一个 usb interface */
        intf->dev.type = &usb_if_device_type;
        intf->dev.groups = usb_interface_groups;
    }

    /* (2) 注册 `struct usb_interface` */
    for (i = 0; i < nintf; ++i) {
        ret = device_add(&intf->dev);
    }

}