1、platform架构
硬件资源是在plat from_device里面用u32 num_resources
(资源个数)和struct resource *resource
(资源)来表示
2、增加硬件信息
flags:
start和end:
如果这个寄存器占四个地址,那么
start:开始地址
end:最后一个(开始地址+0x3)
3、举例
这是内核里面数组的一种赋值方式,[0]{} 表示数组第一个成员,里面的元素用.来赋值
4、示例代码
device:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
void hello_release(struct device *dev)
{
printk("hello_release\n");
return;
}
struct resource res[]={
[0] ={
.start = 0x139d0000,
.end = 0x139d0000 + 0x3,
.flags = IORESOURCE_MEM,
},
[1] ={
.start = 199,
.end = 199,
.flags = IORESOURCE_IRQ,
},
};
struct platform_device hello_device ={
.name = "yikoulinux",
.id = -1,
.dev.release = hello_release,
//hardware TBD
.num_resources = ARRAY_SIZE(res),
.resource = res,
};
static int hello_init(void)
{
printk("hello_init\n");
return platform_device_register(&hello_device);
}
static void hello_exit(void)
{
printk("hello_exit\n");
platform_device_unregister(&hello_device);
return;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
driver:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
int hello_probe(struct platform_device *pdev)
{
printk("match ok\n");
printk("mem = %x \n",pdev->resource[0].start);
printk("irq = %d \n",pdev->resource[1].start);
//ioremap
//request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char * name, void * dev)
return 0;
}
int hello_remove(struct platform_device *pdev)
{
printk("hello_remove\n");
return 0 ;
}
struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = hello_remove,
.driver.name = "yikoulinux",
};
static int hello_init(void)
{
printk("hello_init\n");
return platform_driver_register(&hello_driver);
}
static void hello_exit(void)
{
printk("hello_exit\n");
platform_driver_unregister(&hello_driver);
return;
}
MODULE_LICENSE("GPL");
module_init(hello_init);
module_exit(hello_exit);
5、效果
6、注册代码流程详解
捋架构的好处,就是可以帮助我们定位问题
1. match函数何时被调用到?
2. probe函数何时被调用到
以下是上述两个问题代码的调用流程:
7、没有设备树,硬件信息存放在哪里
以三星为例:
●mach-smdkc100.c arch\arm\mach-s5pc100
●arch\arm\plat-samsung