?? cpld.c
字號:
/*
* Copyright (C) 2004 Gexin TECH
* <hrhr0319@163.com>
*
This file just for GX-ARM9-2410EP
Sat Feb 7 2004 Huo Ran <hrhr0319@163.com>
*
* 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/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/interrupt.h> /* for in_interrupt */
#include <linux/timer.h>
#include <linux/init.h>
#include <linux/delay.h> /* for udelay */
#include <linux/modversions.h>
#include <linux/version.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/hardware.h>
#include "OURS_DEF.h"
#define CPLD_MAJOR 99
static int CPLD_CTL_ADDR;
static int CPLD_ID_ADDR;
static int XGPIO_IN_ADDR;
static int XGPIO_OUT_ADDR;
devfs_handle_t dev_handle; /* register handle to store device fs */
int CPLD_temp_count=0;
static long ioremap_addr;
ssize_t CPLD_read (struct file * file ,char * buf, size_t count, loff_t * f_ops)
{
printk("s3c2410: device file-read operation!\n");
return count;
}
/*=========== SimpleD Write =======================*/
ssize_t CPLD_write (struct file * file ,const char * buf, size_t count, loff_t * f_ops)
{
printk("s3c2410: device file-write operation!\n");
return count;
}
/*=========== SimpleD Ioctl =======================*/
ssize_t CPLD_ioctl (struct inode * inode ,struct file * file,
unsigned int cmd, long data)
{
//printk("s3c2410: device ioctl operation!\n");
switch (cmd)
{
case READ_XGPIO_IN :
return inw(XGPIO_IN_ADDR);
case READ_XGPIO_OUT :
return inw(XGPIO_OUT_ADDR);
case WRITE_XGPIO_OUT :
outw(data, XGPIO_OUT_ADDR);
return 0;
case READ_CPLD_CTL :
return inw(CPLD_CTL_ADDR);
case WRITE_CPLD_CTL :
outw(data, CPLD_CTL_ADDR);
return 0;
case READ_CPLD_ID :
return inw(CPLD_ID_ADDR);
default :
return 0;
}
}
/*============ SimpleD device open ==============*/
ssize_t CPLD_open (struct inode * inode ,struct file * file)
{
return 0;
}
/*============ SimpleD device close =============*/
ssize_t CPLD_release (struct inode * inode ,struct file * file)
{
printk("s3c2410: device release operation!\n");
return 0;
}
struct file_operations CPLD_ops ={
open: CPLD_open,
read: CPLD_read,
write: CPLD_write,
ioctl: CPLD_ioctl,
release: CPLD_release,
};
static int __init HW_CPLD_init(void)
{
int ret = -ENODEV;
int delay,i ;
ret = devfs_register_chrdev(CPLD_MAJOR, "CPLD", &CPLD_ops);
if( ret < 0 ){
printk (" s3c2410: init_module failed with %d\n", ret);
return ret;
}
else
{
printk(KERN_INFO" S3c2410 CPLD register success!!!\n");
;
}
dev_handle = devfs_register( NULL, "CPLD", DEVFS_FL_DEFAULT,
CPLD_MAJOR, 0, S_IFCHR, &CPLD_ops, NULL);
//*************************************************************************************
//remap the address of the registers
CPLD_CTL_ADDR = ioremap(0x21000000,0x0f);
CPLD_ID_ADDR = ioremap(0x22400000,0x0f);
XGPIO_IN_ADDR = ioremap(0x21800000,0x0f);
XGPIO_OUT_ADDR = ioremap(0x21400000,0x0f);
printk(" CPLD_ID is %x\n", inb(CPLD_ID_ADDR)); //read the ID of CPLD
//!!!!!!!!!!!!!!
return ret;
}
int __init s3c2410_CPLD_init(void) {
int ret = -ENODEV;
ret = HW_CPLD_init();
if (ret)
return ret;
return 0;
}
int init_module()
{
s3c2410_CPLD_init();
}
void cleanup_module()
{
devfs_unregister_chrdev(CPLD_MAJOR, "CPLD" );
devfs_unregister( dev_handle );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -