Linux上Platform device and drive…

Linux上Platform device and driver介绍
引言
计算机上的设备都是连接到bus上的而我们知道一颗CPU它的端口数目是有限,各种各样的设备直接连接CPU的bus上是无法想象的,这直接导致计算机总线的发展。对于解决这个瓶颈的办法是让一个中间人负责对CPU总线时分复用,其余的设备大都不是直接连接到CPU bus上的而是连在中间人那里。列举个最著名的“中间人”:PCI总线。理由很简单通用PC几乎清一色PCI总线,置于PCI总线我不做介绍。我要介绍的是Linux下描述直接连接CPU bus的机制以及它与driver之间的关系。
Platform device是linux上一种具有自我管理功能的一个subsystem。它包含了一些基于port的legacy device以及一些host bridge 连接外部总线的设备再者就是embedded system中的许多设备也是platform device。不管是什么设备,只要它属于platform device都有一个共同的特点:
CPU bus直接寻址!
还有一种很少的情况:platform device连接在其他bus的某个segment上但是它的registers是直接寻址的!
Plarform device会有一个名字用于driver binding(在注册driver的时候会查找driver的目标设备的bus位置,这个过程称为driver binding),另外IRQ以及地址空间等资源也要给出 。下面给出platform device的相关数据结构:
struct platform_device {
const char *name;
u32 id;
struct device dev;
u32 num_resources;
struct resource *resource;
};
Platform device是一种device自己是不会做事情的,要有人为它做事情,那就是platform driver。下面介绍platform driver。
platform driver遵循linux系统的driver model(这个内容是很大的内容有兴趣的可以自己学习)。对于device的discovery/enumerate都不是driver自己完成的而是有由系统的driver注册机制完成。driver编写人员只要将注册必须的数据结构初始化并调用注册driver的kernel API就可以了。以下是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 (*suspend_late)(struct platform_device *, pm_message_t state);
int (*resume_early)(struct platform_device *);
int (*resume)(struct platform_device *);
struct device_driver driver;
};
API:
int platform_device_register(struct platform_device *pdev);
int platform_add_devices(struct platform_device **pdevs, int ndev);
int platform_driver_register(struct platform_driver *drv);
更为详尽的信息可以查看Linuxkernel以及driver方面的书籍。
<script type="text/javascript" id="wumiiRelatedItems"> </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值