#include <linux/module.h>
#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>
static struct class *seconddrv_class;
static struct Class_device *seconddrv_class_dev;
volatile unsigned long *gpfcon;
volatile unsigned long *gpfdat;
volatile unsigned long *gpgcon;
volatile unsigned long *gpgdat;
static int Second_drv_open (struct inode *inode, struct file *file) {
/* Configure gpf0,2 as input pin
*/ *
Gpgcon &=~ ((0x3<< (0*2)) | (0x3<< (2*2)));
/* Configure gpf3,11 as input pin */
*gpfcon &=~ ((0x3<< (3*2)) | (0x3<< (11*2)));
return 0;
}
ssize_t second_drv_read (struct file *file, char __user *buf, size_t size, loff_t *ppos) {
/* Returns the level of four pins */
unsigned char key_vals[4];
int regval;
if (Size! = sizeof (key_vals))
Return-einval;
/* Read gpf0,2*/
Regval= *gpfdat;
Key_vals [0]= (Regval & (1<<0))? 1:0;
Key_vals [1]= (Regval & (1<<2))? 1:0;
/* Read gpf3,11*/
Regval= *gpgdat;
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 second_drv_fops= {
. Owner=this_module,
. open = Second_drv_open,
. read= Second_drv_read,};
int major;
static int Second_drv_init () {
Major=register_chrdev (0, "Second_drv", & Second_drv_fops);
Seconddrv_class = Class_create (This_module, "seconddrv");
/*if (Is_err (Firstdrv_class))
Return Ptr_err (Firstdrv_class); */
seconddrv_class_dev= class_device_create (Seconddrv_class, NULL, MKDEV (major, 0), NULL, "buttons");
/*if (Unlikely (Is_err (Firstdrv_class_dev)))
Return Ptr_err (FIRSTDRV_CLASS_DEV); */
Gpfcon = (volatile unsigned long *) Ioremap (0x56000050,16);
gpfdat=gpfcon+1;
Gpgcon = (volatile unsigned long *) Ioremap (0x56000060,16);
gpgdat=gpgcon+1;
return 0;
}
static void Second_drv_exit () {
Unregister_chrdev (Major, "second_drv");
Class_device_unregister (Seconddrv_class_dev);
Class_destroy (Seconddrv_class);
Iounmap (Gpfcon);
Iounmap (Gpgcon);
return 0;
}
Module_init (Second_drv_init);
Module_exit (Second_drv_exit);
Module_license ("GPL");
Read key value Driver