linux驱动开发:总线,设备,驱动三要素

平台总线和IIC,SPI,IIS都是总线类型,一般的,总线下,挂载对应的设备。但实际上,设备要正常运转,是需要驱动程序来未知提供驱动的。所以linux内核也把驱动挂载在对应的总线下。总线,驱动,设备三者缺一不可.
相应的,内核衍生出来的平台总线,那么便衍生出来了平台设备和凭条驱动。他们均有自己的专属函数来注册,注销。这个是成一套体系结构的.在以后的驱动开发中,很是常见与重要.

一)内核中的总线,设备,驱动
1)总线

struct bus_type {
    const char      *name;
    const char      *dev_name;
    struct device       *dev_root;
    struct bus_attribute    *bus_attrs;//总线属性
    struct device_attribute *dev_attrs;//设备属性
    struct driver_attribute *drv_attrs;//驱动属性

    int (*match)(struct device *dev, struct device_driver *drv);//匹配总线下的设备和驱动
    int (*uevent)(struct device *dev, struct kobj_uevent_env *env);//用于总线环境变量的添加
    int (*probe)(struct device *dev);//回调函数
    int (*remove)(struct device *dev);
    void (*shutdown)(struct device *dev);

    int (*suspend)(struct device *dev, pm_message_t state);
    int (*resume)(struct device *dev);

    const struct dev_pm_ops *pm;//电源管理

    struct iommu_ops *iommu_ops;

    struct subsys_private *p;//将bus device sysfs联系起来
    struct lock_class_key lock_key;
};

注册:bus_register(struct bus_type *bus);
注销:bus_unregister(struct bus_type *bus);

2)设备

struct device {
    struct device       *parent;

    struct device_private   *p;

    struct kobject kobj;
    const char      *init_name; /* initial name of the device */
    const struct device_type *type;

    struct mutex        mutex;  /* mutex to synchronize calls to
                     * its driver.
                     */

    struct bus_type *bus;       /* type of bus device is on  设备所属的总线*/
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值