platform_driver_register函数注册失败

DwyaneCV 2018-03-30 06:36:31
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");
...全文
1311 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
枫叶会再红吗 2018-04-01
  • 打赏
  • 举报
回复
返回负值才是失败,platform_device注册没,名字一样就调用probe
jklinux 2018-03-30
  • 打赏
  • 举报
回复
返回值0表示成功注册了啊,你可以在/sys/bus/platform/drivers/目录找到你驱动名 没有打印是没有platform_device与你的platform_driver发生匹配。 只有平台设备与平台驱动匹配后才会触发调用probe函数成员的
zhxianbin 2018-03-30
  • 打赏
  • 举报
回复
dmesg 看看

1,318

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧