平台总线驱动模型

来源:互联网 发布:程序员上的网站 编辑:程序博客网 时间:2024/05/01 23:01
arch/arm/plat-s3c24xx/devs.c 这个函数实现的平台总线模型中的
platform_device
/* 1. 注册各种资源 */
struct resource s3c2410_uart0_resource等各种资源
static struct resource s3c_lcd_resource[] = {
[0] = {
.start = S3C24XX_PA_LCD,
.end   = S3C24XX_PA_LCD + S3C24XX_SZ_LCD - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_LCD,
.end   = IRQ_LCD,
.flags = IORESOURCE_IRQ,
}
}

/* 2. 并分配平台设备 */
struct platform_device s3c_device_xxx = {
.name  = "s3c2410-xxx",
.id  = -1,
.num_resources = ARRAY_SIZE(s3c_xxx_resource),
.resource  = s3c_xxx_resource,
.dev              = {
.dma_mask = &s3c_device_xxx_dmamask,
.coherent_dma_mask= 0xffffffffUL

}

/* 3. 注册在哪platform_device_register? */
platform_driver
struct platform_driver led_drv = {
.probe= xxx_probe,
.remove= xxx_remove,
.driver= {
.name= "xxx",
}
};
platform_driver_register
xxx_probe
设置:platform_get_resource等进行各种资源的设置
register_chrdev( major, name, struct file_operations *fops)
class_create
class_device_create

当然对于具体的driver函数可以用input输入子系统来完成,
对于LCD, register_chrdev→register_framebuffer, fops→s3c_fb
对于gpio_keys.c中输入子系统,当然实际上只是内核中的一个例程,内核并没有分配资源给它
gpio_keys_probe(struct platform_device *pdev)
input = input_allocate_device();
相关设置
input_register_device(input);
对于s3c2410ts.c中也用到了输入子系统,它的platform_device就是在devs.c实现的
platform_driver
s3c2410_ts_probe
input = input_allocate_device();
相关设置
input_register_device(input);

总线平台:
platform_device  需要自己实现:1. 注册资源 2. 分配平台设备 3. 注册平台设备
platform_driver    比较稳定的代码
input->device  需要自己实现 1.分配一个input_dev结构体  2.设置能产生哪些事件 3. 注册input_register_device(buttons_dev) 4. 硬件相关的操作
input->handler 一般的handler由内核实现