|
/* 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 |
|