Chinaunix首页 | 论坛 | 博客
  • 博客访问: 827312
  • 博文数量: 168
  • 博客积分: 5431
  • 博客等级: 大校
  • 技术积分: 1560
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-22 11:56
文章存档

2015年(2)

2014年(1)

2013年(12)

2012年(12)

2011年(15)

2010年(5)

2009年(16)

2008年(41)

2007年(64)

分类: LINUX

2007-11-15 11:12:54

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方面的书籍。

阅读(4767) | 评论(4) | 转发(1) |
给主人留下些什么吧!~~

stephen_du2009-12-22 20:31:14

谢谢大家的关注,互相交流互相学习

chinaunix网友2009-08-31 21:17:54

挺不错的, 简单了一点

chinaunix网友2009-08-21 18:51:55

非常好的一篇文章

chinaunix网友2009-05-30 19:50:24

谢谢你的文章