platform_driver.c源代码如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/sysfs.h>
#include <linux/platform_device.h>
static int my_platform_probe(struct platform_device *);
static int my_platform_remove(struct platform_device *);
struct platform_driver my_platform_driver = {
.probe = my_platform_probe,
.remove = my_platform_remove,
.driver = {
.owner = THIS_MODULE,
.name = "my_dev",
},
};
static int __init my_platform_init(void)
{
if(platform_driver_register(&my_platform_driver))
printk("platform_driver_register error~~~\n");
return 0;
}
static void __exit my_platform_exit(void)
{
platform_driver_unregister(&my_platform_driver);
}
MODULE_LICENSE("Dual BSD/GPL");
module_init(my_platform_init);
module_exit(my_platform_exit);
static int my_platform_probe(struct platform_device * dev)
{
struct resource *temp;
printk("my_platform_probe work~~~\n");
temp=platform_get_resource(dev,IORESOURCE_MEM,0);
if (temp ==NULL)
{
printk("platform_ger_resource error~~~\n");
}
return 0;
}
static int my_platform_remove(struct platform_device *dev)
{
printk("my_platform_remove work~~~~\n");
return 0;
}
我的platform_device.c代码如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/ioport.h>
struct resource platform_resource[] = {
[0]={
.start =0x56000000,
.end =0x560000ff,
.flags =IORESOURCE_MEM,
},
[1]={
.start =0x57000000,
.end =0x570000ff,
.flags =IORESOURCE_MEM,
},
};
struct platform_device my_platform_device= {
.name = "my_dev",
.id=-1,
.num_resources=2,
.resource = platform_resource,
};
//EXPORT_SYMBOL(my_platform_device);
static int __init my_platform_init(void)
{
int ret;
ret=platform_device_register(&my_platform_device);
if(ret)
{
printk("platform_device_add error~~~~\n");
platform_device_put(&my_platform_device);
}
return 0;
}
static void __exit my_platform_exit(void)
{
platform_device_unregister(&my_platform_device);
}
MODULE_LICENSE("Dual BSD/GPL");
module_init(my_platform_init);
module_exit(my_platform_exit);
8 个解决方案
#1
你得到的resource是空的??????
#2
拿个小板凳学习中....
#3
#4
不行,就把device 注册部分,移到平台代码里/arch/xxx/mach-xxx/这样的文件。
#5
通常,platform device都是在arch/xxx/mach-xxx/中的machine_desc->init_machine函数中调用platform_device_register注册。
#6
#7
先加载device模块,再加载driver模块,试试呗
#8
num_resources是不是要写资源的大小啊?
#1
你得到的resource是空的??????
#2
拿个小板凳学习中....
#3
#4
不行,就把device 注册部分,移到平台代码里/arch/xxx/mach-xxx/这样的文件。
#5
通常,platform device都是在arch/xxx/mach-xxx/中的machine_desc->init_machine函数中调用platform_device_register注册。
#6
#7
先加载device模块,再加载driver模块,试试呗
#8
num_resources是不是要写资源的大小啊?