免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1655 | 回复: 1
打印 上一主题 下一主题

自己写的一个按键驱动,insmod出错。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-11-15 14:55 |只看该作者 |倒序浏览
jz2440开发板,2.6.22.6内核
自己书写的按键驱动程序    好的驱动到我那里能加载成功,也就是整个系统搭建没有问题,只是自己书写的程序有问题。
insmod之后出现:  insmod bottuns.ko
register succsessfull//这里是在入口函数里加的打印信息,证明进入到了入口函数
insmod: cannot insert 'bottuns.ko': Success (-997531552)


结果用这个lsmod查看之后,发现没有挂载上
源码如下:

#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/fs.h>
#include<linux/init.h>
#include<linux/delay.h>
#include<asm/irq.h>
#include<asm/io.h>
#include<asm/arch/regs-gpio.h>
#include<asm/hardware.h>
#include<asm/uaccess.h>
//这定义一个类,一会先建立一个类,然后再在类的下面
//
volatile unsigned long *gpfcon;
volatile unsigned long *gpgcon;
volatile unsigned long *gpfdat;
volatile unsigned long *gpgdat;


static struct class *button_class;
static struct class_device        *button_class_dev;


/*函数整体规划open函数里设置管脚
read 函数里进行管脚值的读取,但是
对引脚进行操作之前要注意一点,应该将
物理地址映射成虚拟地址
*/
static int button_open(struct inode *inode,struct file *file)
{
        /*将引脚配置为输入
        因为现在查询模式,所以都设为输入引脚
        GPF0,GPF2.GPG3.GPG11,
        */
        *gpfcon&=~((0x3<<(0*2))|(0x3<<(2*2)));
        *gpgcon&=~((0x3<<(3*2))|(0x3<<(11*2)));
       
        return 0;
}

ssize_t button_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
{
        /*该函数的作用是读
        也就是返回四个引脚的点平
        所以要读取dat寄存器
        取相应的按键值*/
        unsigned char key_vals[4];
        int regval;
        if (size != sizeof(key_vals))
                return -EINVAL;
        /*读gpf0,2*/
        regval=*gpfdat;//先把寄存器整体的值读回来
        key_vals[0]=(regval&(1<<0))?1:0;
        key_vals[1]=(regval&(1<<2))?1:0;
        /*读取这个gpg3,gpg11*/
        key_vals[2]=(regval&(1<<3))?1:0;
        key_vals[3]=(regval&(1<<11))?1:0;
        /*将数据回传给用户空间*/
        copy_to_user(buf,key_vals,sizeof( key_vals));
        return sizeof( key_vals);
}


static struct file_operations button_fops={
.owner= THIS_MODULE,
.open= button_open,
.read=button_read,
};


/*入口函数,
进行地质映射
加载驱动程序*/
int major;
static int button_init(void)
{
       
        major = register_chrdev(0, "button", &button_fops);

        button_class = class_create(THIS_MODULE, "button");

        button_class_dev = class_device_create(button_class, NULL, MKDEV(major, 0), NULL, "buttons"); /* /dev/buttons */
        printk("register succsessfull\n");
        gpfcon = (volatile unsigned long *)ioremap(0x56000050, 16);
        gpfdat = gpfcon + 1;

        gpgcon = (volatile unsigned long *)ioremap(0x56000060, 16);
        gpgdat = gpgcon + 1;

       
}
/*出口函数,卸载驱动程序,取消映射*/
static int button_exit(void)
{
        unregister_chrdev(major,"button");
        /*刚才是自动分配主设备号码,以及创建设备节点*/
        /*现在要自动的移除主设备号码,以及设备节点*/
        class_device_unregister(button_class_dev);
        class_destroy(button_class);
        printk("unregister succsesful\n");
        iounmap(gpfcon);
        iounmap(gpgcon);
}
/*入口函数和这个出口函数都需要修饰一下*/
module_init(button_init);
module_exit(button_exit);
MODULE_LICENSE("GPL");


论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
2 [报告]
发表于 2014-11-21 16:12 |只看该作者
button_init无返回值吗?你编译时都不管警告的吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP