Linux平台总线设计
来源:互联网 发布:电脑数据连接线 编辑:程序博客网 时间:2024/05/01 22:47
平台总线(Platform bus)是Linux2.6内核加入的一种虚拟总线,其优势在于采用了总线的模型对设备与驱动进行了管理,这样提高了程序可移植性。
用户不用自己创建虚拟总线,可直接调用此总线使用。
通过平台总线机制开发设备驱动流程图:
平台设备匹配函数:
/** * platform_match - bind platform device to platform driver. * @dev: device. * @drv: driver. * * Platform device IDs are assumed to be encoded like this: * "<name><instance>", where <name> is a short description of the type of * device, like "pci" or "floppy", and <instance> is the enumerated * instance of the device, like '0' or '42'. Driver IDs are simply * "<name>". So, extract the <name> from the platform_device structure, * and compare it against the name of the driver. Return whether they match * or not. */static int platform_match(struct device *dev, struct device_driver *drv){struct platform_device *pdev;pdev = container_of(dev, struct platform_device, dev);return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);}
平台设备使用struct platform_device来描述:
struct platform_device {const char* name;<span style="white-space:pre"></span>设备名intid;<span style="white-space:pre"></span>设备编号,配合设备名使用struct devicedev;u32num_resources;struct resource* resource;<span style="white-space:pre"></span>设备资源(基地址、中断号、DMA...)};
struct resource*resource结构体:
struct resource {resource_size_t start;<span style="white-space:pre"></span>起始地址(寄存器、中断号)resource_size_t end;const char *name;unsigned long flags;<span style="white-space:pre"></span>资源的类型(中断号、内存...)struct resource *parent, *sibling, *child;};
int platform_device_register(struct platform_device *pdev)
void platform_device_unregister(struct platform_device *pdev)
struct platform_driver {int (*probe)(struct platform_device *);<span style="white-space:pre"></span>//平台设备匹配上后调用此函数,实现此函数时必须加上返回值,不然会报错</span>int (*remove)(struct platform_device *);<span style="white-space:pre"></span>//平台设备从总线移出后调用此函数void (*shutdown)(struct platform_device *);int (*suspend)(struct platform_device *, pm_message_t state);int (*suspend_late)(struct platform_device *, pm_message_t state);int (*resume_early)(struct platform_device *);int (*resume)(struct platform_device *);struct pm_ext_ops *pm;struct device_driver driver;};平台驱动注册函数:
int platform_driver_register(struct platform_driver *drv)
平台设备注销函数:
void platform_driver_unregister(struct platform_driver *drv)
平台设备获取资源函数:
struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num)
*dev:设备结构体中的设备名字
type:需要获取的设备资源类型
num:第几个资源(start->end之间的资源)
0 0
- Linux平台总线设计
- 平台总线驱动设计
- 平台总线设备驱动设计
- linux驱动之--平台总线
- 13.总线设备驱动模型(2)-平台总线设备设计
- linux下的平台总线与专用总线
- Linux学习:platform平台总线、平台设备、平台驱动
- Linux平台总线驱动设备模型
- Linux平台总线驱动设备模型
- Linux平台总线驱动设备模型
- linux驱动platform平台设备总线
- Linux内核之platform平台总线
- Linux平台总线驱动设备模型
- Linux平台总线驱动设备模型
- Linux平台总线驱动设备模型
- Linux平台总线驱动设备模型
- linux 设备驱动之平台总线
- Linux平台总线驱动设备模型
- DDNS
- C++数据访问声明的思考
- 自定义属性(xml中可插入)
- 动态排序实例(函数回调)
- 23种设计模式(7):中介者模式
- Linux平台总线设计
- c++中的静态成员
- iOS设置系统键盘右下角按钮不可点击状态
- 【bzoj2152】【聪聪可可】【点分治】
- 23种设计模式(8):观察者模式
- 在windows 和 linux下引入hash_set、hash_map头文件(转)
- web即时通信1--WebSocket与WebRTC的三种实现方式对比
- java 内联函数
- 《从0到1》阅读笔记