platform_driver.c
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/platform_device.h>
#include<linux/miscdevice.h>
#include<linux/fs.h>
struct resource *Platform_device_resource;
struct resource *Platform_device_tmp;
struct file_operations misc_fops ={
.owner=THIS_MODULE
};
struct miscdevice misc_dev={
.minor=MISC_DYNAMIC_MINOR,
.name="misc_test",
.fops=&misc_fops
};
int Platform_driver_probe(struct platform_device *Device)
{
int ret;
printk("Platform_driver_probe enter\n");
Platform_device_resource=platform_get_resource(Device,IORESOURCE_MEM,0);
if(Platform_device_resource==NULL)
{
printk("Platform_device_resource==NULL device is busy");
return -EBUSY;
}
printk("start=%#x\n",Platform_device_resource->start);
printk("end=%#x\n",Platform_device_resource->end);
printk("name=%s\n",Platform_device_resource->name);
ret=misc_register(&misc_dev);
if(ret)
{
printk("%s register fail",__FUNCTION__);
return -1;
}
printk("%s register successful\n",__FUNCTION__);
printk("hello----------misc\n");
return 0;
}
int Platform_driver_remove(struct platform_device *Device)
{
printk("platform_driver_probe remove\n");
return 0;
}
const struct platform_device_id Platform_driver_id_tables={
};
struct platform_driver platform_driver_test = {
.probe=Platform_driver_probe,
.remove=Platform_driver_remove,
.driver={
.name="platform_device_test",
.owner=THIS_MODULE
},
};
static int __init lcx_driver_init(void)
{ int ret;
ret=platform_driver_register(&platform_driver_test);
if(ret)
{
printk("register fail\n");
}
printk("platform_driver_init\n");
return 0;
}
static void __exit lcx_driver_remove(void)
{
platform_driver_unregister(&platform_driver_test);
misc_deregister(&misc_dev);
printk("platform_driver_remove\n");
}
module_init(lcx_driver_init);
module_exit(lcx_driver_remove);
MODULE_LICENSE("GPL");