mini6410 platform设备驱动

来源:互联网 发布:进入别人网站数据库 编辑:程序博客网 时间:2024/04/29 20:08

platform设备的思想就是将注册函数在linux/platform_device.h定义了platform_device_register 和 platform_driver 函数 ,使得挂接在该总线上的 设备和驱动由其管理

一、可以看到在platform.c 中有 platform_bus的定义和match函数

struct bus_type platform_bus_type = {.name= "platform",.dev_attrs= platform_dev_attrs,.match= platform_match,.uevent= platform_uevent,.pm= &platform_dev_pm_ops,};


static int platform_match(struct device *dev, struct device_driver *drv){struct platform_device *pdev = to_platform_device(dev);struct platform_driver *pdrv = to_platform_driver(drv);/* Attempt an OF style match first */if (of_driver_match_device(dev, drv))return 1;/* Then try to match against the id table */if (pdrv->id_table)return platform_match_id(pdrv->id_table, pdev) != NULL;/* fall-back to driver name match */return (strcmp(pdev->name, drv->name) == 0);}


在内核启动的时候就注册了platform总线。


二、再看platform对应的platform_device的结构

struct platform_device {const char* name;   //名字,这将代替内嵌的device中的名字 intid;        ///设备id,用于给插入相同的名字的设备编号,只有一个的话填-1struct devicedev;      //内嵌的Dev的结构u32num_resources;  //资源的数目struct resource* resource;    //指向资源数组的指针const struct platform_device_id*id_entry;/* arch specific additions */struct pdev_archdataarchdata;};


platform_device 的注册和注销函数

int platform_device_register(struct platform_device *);</span>
void platform_device_unregister(struct platform_device *);</span>

注册成功后会在/sys/bbus/platform/device中创建一个软连接,指向/sys/device目录

注意:两者定义在linux/base/platform.c 中,也就是说他们是由总线一起管理的


三、再看platform对应的platform_driver 结构

struct platform_driver {int (*probe)(struct platform_device *);int (*remove)(struct platform_device *);void (*shutdown)(struct platform_device *);int (*suspend)(struct platform_device *, pm_message_t state);int (*resume)(struct platform_device *);struct device_driver driver;const struct platform_device_id *id_table;};

里面同样内嵌了 device_driver 结构 还有 probe 探针函数


platform_driver 的注册和注销函数

int platform_driver_register(struct platform_driver *);</span>

void platform_driver_unregister(struct platform_driver *);</span>
注册成功后会在/sys/bus/platform/driver 下创建一个名为name的目录


三、platform的资源

现在我们来关注 platform_device 结构体中的resource 

u32 num_resources;  //资源的数目struct resource* resource;    //指向资源数组的指针</span>

struct resource {resource_size_t start;resource_size_t end;const char *name;unsigned long flags;struct resource *parent, *sibling, *child;};
定义在/include/linux/ioport.h 中

resource 中的 start和end分别代表资源的起始地址和结束地址,flags 代表资源的类型,一般有 IORESOURECE_MEM 和 IOSOURCE_IRQ

当为iosource时 start 和end 分别代表起始和结束的中断号

 

还有很多...包括资源的具体定义。还有platform设备的静态注册、、、、




0 0