📄 pc104drv_io_int.c
字号:
/*
* pc104drv_io_int.c
*
*
* Author: wbin <wbinbuaa@163.com>
* Date : $Date: 2006/09/11 $
*
* $Revision: 1.0.0.1 $
*
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive
* for more details.
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
//#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <asm/hardware.h>
//#include <asm/semaphore.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/sizes.h>
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h>
#endif
#include <asm/arch/pxa-regs.h>
#include "../include/pc104.h"
#undef DEBUG
//#define DEBUG
#ifdef DEBUG
#define DPRINTK(fmt, args...) printk("%s: " fmt, __FUNCTION__ , ## args)
#else
#define DPRINTK(x...) (void)(0)
#endif
#define PC104_BASE (0xf0000000+0x200000)
#define PC104_IRQ_IN1 (3) // IO PORT NO.
#define PC104_IO_IN0 (0)
#define PC104_DEVICE "UP-TECH PC104 IO & INT"
#define PC104II_MINOR 2
#define pc104ii_devfs_path "pc104/1"
static int pc104iiMajor = 0;
static irqreturn_t pc104ii_interrupt(int , void *, struct pt_regs *);
static int
pc104ii_open(struct inode *inode, struct file *filp)
{
DPRINTK( "pc104ii device open!\n");
return 0;
}
static int
pc104ii_release(struct inode *inode, struct file *filp)
{
DPRINTK( "pc104ii device release!\n");
return 0;
}
//pc104ii ioctl method
static int pc104ii_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
switch(cmd){
default:
DPRINTK("IO ioctl test\n");
}
return 0;
}
static struct file_operations pxa270_fops = {
owner: THIS_MODULE,
open: pc104ii_open,
// read: pc104ii_read,
// write: pc104ii_write,
ioctl: pc104ii_ioctl,
release: pc104ii_release,
};
/*set the gpio into the right mode before transmit, added by wbn */
static int
pc104ii_set_irq(void)
{
pxa_gpio_mode(PC104_IRQ_IN1|GPIO_IN); //gpio mode in input
GRER0 |=1<<PC104_IRQ_IN1; // 31:16 -> GPIO<15:0>
set_irq_type(IRQ_GPIO(PC104_IRQ_IN1), IRQT_RISING); //IRQT_LOW IRQT_RISING
return 0;
}
static irqreturn_t pc104ii_interrupt(int irq, void *_dev, struct pt_regs *r)
{
int iostatus;
printk(PC104_DEVICE "pc104ii interrupt happened! \n");
iostatus=read_gpio_bit(PC104_IO_IN0);
printk(PC104_DEVICE "pc104ii read IO %d \n", iostatus);
return IRQ_HANDLED;
}
/*
read_gpio_bit(x) read gpio status
set_gpio_bit(x) set gpio
clear_gpio_bit(x) clear gpio
*/
static int
pc104ii_set_gpio(void)
{
pxa_gpio_mode(PC104_IO_IN0|GPIO_IN); //gpio mode in input
GRER0 |=1<<PC104_IO_IN0; // 31:16 -> GPIO<15:0>
return 0;
}
int __init pc104ii_init(void)
{
int ret;
pc104ii_set_irq();
pc104ii_set_gpio();
if (request_irq(IRQ_GPIO(PC104_IRQ_IN1),pc104ii_interrupt,SA_SHIRQ,PC104_DEVICE,pc104ii_interrupt))
return -EAGAIN;
ret = register_chrdev(0, PC104_DEVICE, &pxa270_fops);
if (ret < 0) {
printk(PC104_DEVICE " can't get major number\n");
return ret;
}
pc104iiMajor=ret;
#ifdef CONFIG_DEVFS_FS
devfs_mk_cdev(MKDEV(pc104iiMajor, PC104II_MINOR),
S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP, pc104ii_devfs_path);
#endif
printk (PC104_DEVICE"\tdevice initialized\n");
return 0;
}
module_init(pc104ii_init);
#ifdef MODULE
void __exit pc104ii_exit(void)
{
free_irq(IRQ_GPIO(PC104_IRQ_IN1), pc104ii_interrupt);
#ifdef CONFIG_DEVFS_FS
devfs_remove(pc104ii_devfs_path);
#endif
unregister_chrdev(pc104iiMajor, PC104_DEVICE);
}
#endif
module_exit(pc104ii_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("wbin<wbinmsn@msn.com>");
MODULE_DESCRIPTION("Extend PC104 board driver for PXA270");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -