加载中…
个人资料
散人
散人
  • 博客等级:
  • 博客积分:0
  • 博客访问:15,347
  • 关注人气:4
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

4.4 usb core

(2011-01-25 14:04:47)
标签:

linux

上一节讲到了usb 主机控制器的创建,每一个主机控制器都会集成一个roothub,roothub也是一个特殊usb device,也需要给它分配一个usb_device , 它的parent指向主机控制器.如果不是roothub,同样需要分配一个usb_device,只不过dev->parent并不指向了主机控制器.

1.         struct usb_device保存了一个USB设备的信息,包括设备地址,设备描述符,设置描述符,设备所属,设备在文件系统中的信息,设备usb已发送或连接信息。

 * struct usb_device - kernel's representation of a USB device

 * @ devnum: device number; address on a USB bus  设备号在总线上的地址 roothub为0

 * @ devpath: device ID string for use in messages (e.g., /port/...)设备ID字符串

 * @ state: device state: configured, not attached, etc. 设备装备 已配置 或 未连接

 * @ speed: device speed: high/full/low (or error) usb设备类型 低速/高速/全速

 * @ tt: Transaction Translator info; used with low/full speed dev, highspeed hub 传输信息

 * @ ttport: device port on that tt hub

 * @ toggle: one bit for each endpoint, with ([0] = IN, [1] = OUT) endpoints

 * @ parent: our hub, unless we're the root -> root_hub

 * @ bus: bus we're part of ->所属总线 设备于总线之间通过此接口发生关系

 * @ ep0: endpoint 0 data (default control pipe) 端点0数据包

 * @ dev: generic device interface 通用设备接口

 * @ descriptor: USB device descriptor USB设备描述符

 * @ config: all of the device's configs 设备的所有配置

 * @ actconfig: the active configuration 有效配置

 * @ ep_in: array of IN endpoints 输入端点组(有些设备支持DMA传输)

 * @ ep_out: array of OUT endpoints 输出端点组

 * @ rawdescriptors: raw descriptors for each config

 * @ bus_mA: Current available from the bus

 * @ portnum: parent port number (origin 1)

 * @ level: number of USB hub ancestors

 * @ can_submit: URBs may be submitted

 * @ discon_suspended: disconnected while suspended

 * @ persist_enabled:  USB_PERSIST enabled for this device

 * @ have_langid: whether string_langid is valid

 * @ authorized: policy has said we can use it;

    (user space) policy determines if we authorize this device to be

    used or not. By default, wired USB devices are authorized.

    WUSB devices are not, until we authorize them from user space.

    FIXME -- complete doc

 * @ authenticated: Crypto authentication passed

 * @ wusb: device is Wireless USB

 * @ string_langid: language ID for strings

 * @ product: iProduct string, if present (static) 产品号

 * @ manufacturer: iManufacturer string, if present (static) 厂商号

 * @ serial: iSerialNumber string, if present (static) 序列号

 * @ filelist: usbfs files that are open to this device 操作usb的文件系统函数列表

 * @ usb_classdev: USB class device that was created for usbfs device

    access from userspace

 * @ usbfs_dentry: usbfs dentry entry for the device usb设备入口目录

 * @ maxchild: number of ports if hub  HUB的最大端口数

 * @ children: child devices - USB devices that are attached to this hub

 * @ pm_usage_cnt: usage counter for autosuspend

 * @ quirks: quirks of the whole device

 * @ urbnum: number of URBs submitted for the whole device

 * @ active_duration: total time device is not suspended

 * @ autosuspend: for delayed autosuspends

 * @ autoresume: for autoresumes requested while in_interrupt

 * @ pm_mutex: protects PM operations

 * @ last_busy: time of last use

 * @ autosuspend_delay: in jiffies

 * @ connect_time: time device was first connected

 * @ auto_pm: autosuspend/resume in progress

 * @ do_remote_wakeup:  remote wakeup should be enabled

 * @ reset_resume: needs reset instead of resume

 * @ autosuspend_disabled: autosuspend disabled by the user

 * @ autoresume_disabled: autoresume disabled by the user

 * @ skip_sys_resume: skip the next system resume

 * @ wusb_dev: if this is a Wireless USB device, link to the WUSB

* Usbcore drivers should not set usbdev->state directly.  Instead use

 * usb_set_device_state().

 

2.         struct usb_bus 客户端总线

* @ int busnum; 当前总线系统的序列号,Linux支持多总线系统并*

* @ 为他们编号
* @ #ifdef DEVNUM_ROUND_ROBIN
* @   int devnum_next;     
* @ #endif 给连接到子系统上的设备分配设备号的数据结构

* @ struct usb_devmap devmap;       给连接到子系统上的设备分配设备号的数据结构 

* @ struct usb_operations *op;      HCD为USB内核提供的一系统函数集指针
* @ struct usb_device *root_hub;    指向根Hub的指针
* @ struct list_head bus_list;       双向链表指针,USB内核用一个双向链表来维护系统中所有USB总线系* @ 统
* @ void *hcpriv; 和主机控制器相关数据,对USB内核层是透明的
* @ int bandwidth_allocated; 当前子系统的带宽使用情况,单位是毫秒/帧,取值范围

* @ [0,900]
* @ int bandwidth_int_reqs;        子系统中当前的中断传输的数量
* @ int bandwidth_isoc_reqs;       子系统中当前的实时传输的数量
* @ #ifdef CONFIG_USB_DEVICEFS

* @     struct dentry *usbfs_dentry; 

* @ #endif

* @ struct device *dev; 总线与设备通过此单元产生作用

 

* @ #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)

* @     struct mon_bus *mon_bus;   use for debug

* @     int monitored;              

* @ #endif
};

 

3.        struct usb_driver 客户端驱动程式

* @ const char *name; //客户端驱动程式的字符串名称,用于避免重复安装和卸载

* @ int (*probe) (struct usb_interface *intf, const struct usb_device_id *id); 给USB内核提供的函

* @ 数,用于判断驱动程式是* @ 否能对设备的某个接口进行驱动,如能则分配资源2.6.35内核不存在dev参

* @ 数。

* @ void (*disconnect) (struct usb_interface *intf); 给USB内核提供的函数,用于释放设备的某个接口所* @ 占用的资源

* @ int (*ioctl) (struct usb_interface *intf, unsigned int code,void *buf); 用户空间可以通过此接口* @ 于usbfs交流

* @ 

* @ int (*suspend) (struct usb_interface *intf, pm_message_t message);

* @ int (*resume) (struct usb_interface *intf);

* @ int (*reset_resume)(struct usb_interface *intf);

* @ int (*pre_reset)(struct usb_interface *intf);

* @ int (*post_reset)(struct usb_interface *intf);const struct usb_device_id *id_table;

* @ struct usb_dynids dynids;struct usbdrv_wrap drvwrap;

* @ unsigned int no_dynamic_id:1;

* @ unsigned int supports_autosuspend:1;

* @ unsigned int soft_unbind:1;

 

int usb_add_hcd(struct usb_hcd *hcd,unsigned int irqnum, unsigned long irqflags)
{

    //分配一个usb_device

    if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {
    dev_err(hcd->self.controller, "unable to allocate root hub\n");
    retval = -ENOMEM;
        goto err_allocate_root_hub;

   

    //usb主机控制器类型(低速/全速/高速)

    switch (hcd->driver->flags & HCD_MASK) {
        case HCD_USB11:
            rhdev->speed = USB_SPEED_FULL;//全速     12Mbps
        break;
        case HCD_USB2:
            rhdev->speed = USB_SPEED_HIGH;//高速     480Mbps

        break;
        case HCD_USB3:
            rhdev->speed = USB_SPEED_SUPER;//超高速  5Gbps
        break;
        default:
            goto err_allocate_root_hub;
     }

    //register irq

   
    if (hcd->driver->irq) {

        if (irqflags & IRQF_SHARED)
            irqflags &= ~IRQF_DISABLED;

        snprintf(hcd->irq_descr, sizeof(hcd->irq_descr), "%s:usb%d",
        hcd->driver->description, hcd->self.busnum);
        if ((retval = request_irq(irqnum, &usb_hcd_irq, irqflags,hcd->irq_descr, hcd)) != 0) {

            //注册中断号为pdev->resource[1].start的usb_hcd_irq函数
            dev_err(hcd->self.controller,"request interrupt %d failed\n", irqnum);
            goto err_request_irq;
        }
        hcd->irq = irqnum;
        dev_info(hcd->self.controller, "irq %d, %s 0xllx\n", irqnum,(hcd->driver->flags &    

        HCD_MEMORY) ?"io mem" : "io base",(unsigned long long)hcd->rsrc_start);
    } else {
        hcd->irq = -1;
        if (hcd->rsrc_start)
        dev_info(hcd->self.controller, "%s 0xllx\n",(hcd->driver->flags & HCD_MEMORY) ?
        "io mem" : "io base",(unsigned long long)hcd->rsrc_start);
    }

    if ((retval = hcd->driver->start(hcd)) < 0){//启动主机控制器 , 此函数执行后主机控制可以urb发送
        dev_err(hcd->self.controller, "startup error %d\n", retval);
        goto err_hcd_driver_start;
    }

    rhdev->bus_mA = min(500u, hcd->power_budget);//为root-hub配置最小500u的电流
    if ((retval = register_root_hub(hcd)) != 0)  //此为设备枚举入口
        goto err_register_root_hub;

}

 

0

阅读 收藏 禁止转载 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

新浪公司 版权所有