⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key.c

📁 fft的工业级的EP9315的开发板的所有驱动程序
💻 C
字号:

/**********Copyright (c)*********************************
**                                  西安傅立叶电子有限公司
**                                     研    发    部
**                              http://www.FFTChina.com
**------------------------------------------------------
**文   件   名: cantest.c
**创   建   人: 
**最后修改日期: 2005年6月30日
**描        述: CAN模块测试驱动程序(查询模式)
**--------------------------------------------------------
*********************************************************/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif

#include  "linux/capability.h"
#include  "linux/smp_lock.h"
#include "linux/module.h"
#include "asm/hardware.h"
#include "asm/io.h"
#include "linux/devfs_fs_kernel.h"
#include "linux/init.h"
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
#include  "linux/smp_lock.h"
#endif 

#define SCANINIT_DIS3KY 0x00008000
#define  FFTKEY_MAJOR  17

char         kernel_version[]=UTS_RELEASE;
devfs_handle_t  dev_handle2; 

static void  ep93xx_scan_kbd_hw_init( void)
{
	int	i=3;
	unsigned int uiTemp;
    printk( "Entering ep93xx_scan_kbd_hw_init()\n");
    uiTemp = inl(SYSCON_DEVCFG);                           //read the syscon register value
	//printk("sysdevcfg1 is %x\n",uiTemp);
	uiTemp &= ~(SYSCON_DEVCFG_KEYS | SYSCON_DEVCFG_GONK|SYSCON_DEVCFG_A1onG);  // or the setting value,activate the matrix 
	//printk("sysdevcfg2 is %x\n",uiTemp);
	SysconSetLocked(SYSCON_DEVCFG, uiTemp);                //write the register
	outl( (0x00FC00FA | SCANINIT_DIS3KY), SCANINIT );      //three times scan,enable three key reset
	uiTemp = inl(SYSCON_KTDIV) | SYSCON_KTDIV_KEN;         //key matrix clock enable
	SysconSetLocked(SYSCON_KTDIV, uiTemp);                 //about 17ms scan time
    i = inl(KEY_REG);
    //printk("sysdevcfg1 is %x\n",i);                                      // Reading status clears any pending keyboard interrupt.
	printk( "Leaving ep93xx_scan_kbd_hw_init()\n");
}
static ssize_t key_read (struct file *file, char *buf, size_t count,
                            loff_t *offset)
{
   int key;
   key = inl(KEY_REG);
   if(key&(1<<12))
   {  
      *buf = (char)(key&0x3f);
   } else {
   *buf= 0xff;
   }
   return 0;	
}

static ssize_t key_write (struct file *file, const char *buf, size_t count,
                             loff_t *offset)
{
	
	return 0;
}

static int key_ioctrl (struct inode *inode, struct file *file, unsigned int cmd, 
                  unsigned long arg)
{
    return 0;
}

static int key_open (struct inode *inode, struct file *file)
{
    MOD_INC_USE_COUNT;
	return 0;
}

/*******************************************************
*函数原形:open_fftiic(struct inode *inode,struct file *file)
*参数:               
*返回值 : 
*函数说明:
/*******************************************************/
static int key_release(struct inode *inode,struct file *file)
{
    MOD_DEC_USE_COUNT;
    return 0;
}

static struct file_operations fftkey_fops = {
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
	owner:		THIS_MODULE,
#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */
	read:		key_read,
	write:		key_write,
	ioctl:		key_ioctrl,
	open:		key_open,
	release:    key_release,
};

static int __init fftkey_init_module(void)
{
	
    int key;
    int result;
    char *buf;
    int keybuf;
    /*result=register_chrdev(0,"fftkey",&fftkey_fops);           //??????,?????????
    if(result<0)
    {
      printk("cannot get fftkey major number\n");           //????
      return result;
    }*/
    dev_handle2 = devfs_register( NULL, "fftkey", DEVFS_FL_DEFAULT, FFTKEY_MAJOR, 0, S_IFCHR, &fftkey_fops, NULL);
    ep93xx_scan_kbd_hw_init();
    outl(0xff,GPIO_PADDR);
    outl(0x00,GPIO_PADR);
    printk("congraulation,fftkey are successful registed\n");
    /*if(fftkey_major==0)
    {
       fftkey_major=result;                                 //???????
    }*/
    return 0;
}

static void __exit fftclrkey_module(void)
{
	
	    int res;
	    outl(0xff,GPIO_PADR);
       /* if ((res = unregister_chrdev(fftkey_major,"fftkey"))) 
	    {
		
			printk("i2c-dev.o: unable to release major %d for i2c bus\n",
			fftkey_major);
		}*/
		devfs_unregister (dev_handle2);
        printk("exit fftkey\n");
		
}

EXPORT_NO_SYMBOLS;

MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Simon G. Vogl <simon@tk.uni-linz.ac.at>");
MODULE_DESCRIPTION("KEY /dev entries driver");
MODULE_LICENSE("GPL");

module_init(fftkey_init_module);
module_exit(fftclrkey_module);



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -