平台总线和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 设备所属的总线*/