LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 786|回复: 1

从网上找的个驱动程序,编译和加载时出现错误???

[复制链接]
发表于 2007-1-4 20:04:01 | 显示全部楼层 |阅读模式
/* driver/char/keybd.c
*  this is a keybd char device driver.
* Any problem pls contact support@hhcn.com
*/
#ifndef __KERNEL__
#define __KERNEL__
#endif

#ifndef MODULE
#define MODULE
#endif

//#include<unistd.h>
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/fs.h>
#include<asm/hardware.h>
#include<linux/init.h>
#include<asm/delay.h>
#include<asm/io.h>
#include<asm/uaccess.h>
#include<linux/types.h>
#include<linux/config.h>
#include<linux/mm.h>
#include<linux/errno.h>
#include<asm/segment.h>


MODULE_LICENSE("GPL");

#define INPUT_MAJOR 200

#define NOKEY   0

#define name "inputkey"

static char key=NOKEY;


static devfs_handle_t devfs_keybd;


/*
* Open/close code for raw IO.
*/

int keybd_open(struct inode *inode, struct file *filp)
{

printk("open ok\n");
set_gpio_ctrl(GPIO_MODE_IN|GPIO_F0);
return 0;

}

int keybd_read(struct file *fp, char * buf,size_t size)
{
   
  udelay(10000);
  if(read_gpio_bit(GPIO_F0)==1)
{
key=1;
}  
  put_user(key,buf);
key = NOKEY;
return 1;
}


int keybd_release(struct inode *inode, struct file *filp)
{
printk("release ok\n");
return 0;
}


static struct file_operations keybd_fops = {
open:keybd_open,
read:keybd_read,                                 
release:keybd_release,
};



int __init keybd_init(void)
{
      int ret;
printk("*********************keybd_init**************\n");


ret=register_chrdev(INPUT_MAJOR,name,&keybd_fops);

     devfs_keybd = devfs_register(NULL,name, DEVFS_FL_DEFAULT,
      INPUT_MAJOR, 0,
       S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
        &keybd_fops, NULL);

printk("*********************keybd_init**************\n");
      return 0;
}


static void __exit keybd_exit(void)
{
     
devfs_unregister(devfs_keybd);
unregister_chrdev(INPUT_MAJOR,name);
      printk("rmmod ok!\n");
}

module_init(keybd_init);
module_exit(keybd_exit);


编译时出现
xkey.c:85: warning: initialization from incompatible pointer type
85行就是先面read所在行
static struct file_operations keybd_fops = {
open:keybd_open,
read:keybd_read,                                 
release:keybd_release,
};

加载上面驱动程序的时候出现
insmod: unresolved symbol __put_user_bad
发表于 2007-1-6 22:04:51 | 显示全部楼层
好像你贴出来的这个文件跟出错误的文件不是同一个文件。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表