platform_driver_register函数注册失败
insmod insmod Myled2410Prj.ko以后,显示
# insmod Myled2410Prj.ko
HELLO WORLD enter!
DriverState is 0
# cat /proc/devices
为啥DriverState = platform_driver_register(&hello_driver);注册失败,返回0值,并没有显示initialized?
驱动源码:
#include <linux/kernel.h>//
#include <linux/fs.h>//
#include <linux/init.h>//
#include <linux/delay.h>//
#include <asm/uaccess.h>
#include <asm/irq.h>//
#include <asm/io.h>//
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
#include <linux/platform_device.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#define DRIVER_NAME "hello_ctl" //驱动名称
#define DEVICE_NAME "hello_ctl" //设备名称
static int major;
static struct class *cls;
static struct device *dev;
static long hello_ioctl( struct file *files, unsigned int cmd, unsigned long arg){
printk("first_drv_ioctl\n");
return 0;
}
static int hello_release(struct inode *inode, struct file *file){
printk( "hello release\n");
return 0;
}
static int hello_open(struct inode *inode, struct file *file){
printk("hello open\n");
return 0;
}
static struct file_operations hello_ops = {
.owner = THIS_MODULE,
.open = hello_open,
.release = hello_release,
.unlocked_ioctl = hello_ioctl,
};
static int hello_probe(struct platform_device *pdv)
{
int ret;
printk("\tinitialized\n");
// 注册设备驱动 创建设备节点
major = register_chrdev(0, "My2410Prj", &hello_ops);
// 创建类
cls = class_create(THIS_MODULE, "My2410Prj");
// 创建设备节点
dev = device_create(cls, NULL, MKDEV(major, 0), NULL, "My_Dev_2410Prj");
return 0;
}
static int hello_remove(struct platform_device *pdv){
printk("\tremove\n");
return 0;
}
static void hello_shutdown(struct platform_device *pdv){
return 0;
}
static int hello_suspend(struct platform_device *pdv,pm_message_t pmt){
return 0;
}
static int hello_resume(struct platform_device *pdv){
return 0;
}
struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = hello_remove,
.shutdown = hello_shutdown,
.suspend = hello_suspend,
.resume = hello_resume,
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
}
};
static int hello_init(void)
{
int DriverState;
printk("HELLO WORLD enter!\n");
DriverState = platform_driver_register(&hello_driver);
printk("\tDriverState is %d\n",DriverState);
return 0;
}
static void hello_exit(void)
{
printk("HELLO WORLD exit!\n");
platform_driver_unregister(&hello_driver);
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");