您的位置:首页 > 其它

platform device driver

2010-09-09 14:51 435 查看
platform总线是在linux 2.6 内核中加入的一种虚拟总线。platform机制有两部分组成platform_device和platform_driver.

Platform device是linux上一种具有自我管理功能的一个subsystem。它包含了一些基于port的legacy device以及一些host bridge 连接外部总线的设备再者就是embedded system中的许多设备也是platform device。不管是什么设备,只要它属于platform device都有一个共同的特点:
CPU bus直接寻址!
还有一种很少的情况:platform device连接在其他bus的某个segment上但是它的registers是直接寻址的!

struct platform_device {
const char * name;
int 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);

platform机制开发设备驱动的流程如下:

定义platform_device--->注册platform_device--->定义platform_driver--->注册 platform_driver.

下面介绍下在linux s3c6410中加入 led平台驱动的方法:

首先要在bsp文件中加入

///*led driver support*/
static struct gpio_led s3c6410_leds[] = {
[0] = {
.name = "LED10",
.gpio = S3C64XX_GPK(4),
},
[1] = {
.name = "LED12",
.gpio = S3C64XX_GPK(5),
},
[2] = {
.name = "LED13",
.gpio = S3C64XX_GPK(6),
},
[3] = {
.name = "LED14",
.gpio = S3C64XX_GPK(7),
},
};

static struct gpio_led_platform_data s3c6410_gpio_led_pdata = {
.num_leds = ARRAY_SIZE(s3c6410_leds),
.leds = s3c6410_leds,
};

static struct platform_device s3c_device_led = {
.name = "leds-gpio",
.id = 1,
.dev = {
.platform_data = &s3c6410_gpio_led_pdata,
},

};
仔细看你就会发现与设备相关的信息都是在bsp中,即在bsp 中主要实现了platform_device 这个结构体。

而在驱动root@wsh-desktop:/home/mini/linux-2.6.28.6/drivers/leds# emacs leds-gpio.c主要是实现了platform_driver

static struct platform_driver gpio_led_driver = {
.probe = gpio_led_probe,
.remove = __devexit_p(gpio_led_remove),
.suspend = gpio_led_suspend,
.resume = gpio_led_resume,
.driver = {
.name = "leds-gpio",//设备名
.owner = THIS_MODULE,
},

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: