- 论坛徽章:
- 0
|
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/irq.h>
#include <linux/delay.h>
#include <asm/hardware.h>
#define DEVICE_NAME "touchsensor"
#define BUTTON_MAJOR 234
#define IDX_REG 0x10000000
#define CON_REG 0x10000001
#define CMD_REG 0x00
#define DAT_REG 0x01
#define STA_REG 0x02
#define INT_REG 0x03
#define AUX_REG 0x05
#define CID0_REG 0x06
#define CID1_REG 0x07
#define OPS_REG 0x08
#define BUFC_REG 0x09
#define CLK0_REG 0x10
#define IOC_REG 0x14
#define IEN_REG 0x16
#define F0T0_REG 0x20
#define F0T1_REG 0x21
#define F1T0_REG 0x22
#define F1T1_REG 0x23
static int touch_value = 0;
static DECLARE_WAIT_QUEUE_HEAD(touch_wait);
static int touchsensor_read(struct file * file, char * buffer, size_t count, loff_t *ppos)
{
if ( copy_to_user(buffer, &touch_value, sizeof touch_value))
{printk("aaa\n");
return -EFAULT;}
return sizeof touch_value;
}
static int touchsensor_write(struct file * file, const char * buffer, size_t count, loff_t *ppos)
{
return -EINVAL;;
}
static int touchsensor_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
default:
return -EINVAL;
}
}
static int touchsensor_open(struct inode *inode, struct file *filp)
{
printk("open success \n");
MOD_INC_USE_COUNT;
return 0;
}
static int touchsensor_release(struct inode *inode, struct file *file)
{
MOD_DEC_USE_COUNT;
return 0;
}
static struct file_operations touchsensor_fops = {
owner: THIS_MODULE,
ioctl: touchsensor_ioctl,
read: touchsensor_read,
write: touchsensor_write,
open: touchsensor_open,
release: touchsensor_release,
};
static devfs_handle_t devfs_handle;
static int __init touchsensor_init(void)
{
int ret;
int *a,*b,*c;
ret = register_chrdev(BUTTON_MAJOR, DEVICE_NAME, &touchsensor_fops);
if (ret < 0) {
printk(DEVICE_NAME " can't register major number\n");
return ret;
}
devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT,
BUTTON_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR, &touchsensor_fops, NULL);
printk("hello \n");
c=GPACON;
* c=0x0002001;
a=IDX_REG;
* a=CMD_REG;
b=CON_REG;
* b=0x82;
* b=0x02;
* b=0x42;
* a=CID0_REG;
touch_value=* b;
printk("%d\n",touch_value);
return 0;
}
static void __exit touchsensor_exit(void)
{
devfs_unregister(devfs_handle);
unregister_chrdev(BUTTON_MAJOR, DEVICE_NAME);
}
module_init(touchsensor_init);
module_exit(touchsensor_exit);
MODULE_LICENSE("GPL");
运行后insmod,在dmesg下显示:
hello
Unable to handle kernel paging request at virtual address 007fffff
pgd = c3dc4000
*pgd = 00000000, *pmd = 00000000
Internal error: Oops: ffffffff
CPU: 0
pc : [<c4840210>] lr : [<c0023950>] Not tainted
sp : c3d83edc ip : c3d83e94 fp : c3d83f04
r10: c3d82000 r9 : 02027948 r8 : ffffffea
r7 : 00000060 r6 : c4840400 r5 : c48403ac r4 : 00000000
r3 : 00002001 r2 : 007fffff r1 : 10000000 r0 : c48403ec
Flags: nZCv IRQs on FIQs on Mode SVC_32 Segment user
Control: C000317F Table: 33DC4000 DAC: 00000015
Process insmod (pid: 29, stackpage=c3d83000)
Stack: (0xc3d83ecc to 0xc3d84000)
3ec0: c0023950 c4840210 60000013 ffffffff 00000000
3ee0: 00002180 c4840400 00000000 c4840000 00000000 c3d33000 c3d83fa4 c3d83f08
3f00: c0024804 c48401a0 c3d33000 c3d83f1c c3d35000 0000000c c029cb20 00000060
3f20: c015761c c4840060 00000580 00000000 00000000 00000000 0000 |
|