/**//*
* 作者:龙涛
*/
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/version.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <linux/errno.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/config.h>
#include <linux/mm.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
#include <asm/hardware.h>
#include <asm/uaccess.h>
#undef DEBUG_Mc35i
//#define DEBUG_Mc35i 1
#ifdef DEBUG_Mc35i
#define DBG_Mc35i(fmt, args...) printk(fmt,## args)
#else
#define DBG_Mc35i(fmt, args...)
#endif
static int Mc35i_open(struct inode *, struct file *);
static int Mc35i_close(struct inode *, struct file *);
static int Mc35i_read(struct file *, int *, size_t, loff_t *);
static int Mc35i_write(struct file *, const char *, size_t, loff_t *);
//static void Mc35i_interrupt(int, void *, struct pt_regs *);
static void Mc35i_hardware_init(void);
#define Mc35i_MAJOR 253
#define TRAN_CMD 1
#define TRAN_CMD_DATA 2
#define READ_CMD_DATA 3
/**//* User CMD */
#define CMD_IGT '0'
#define CMD_EMERGOFF '1'
/**//* PC14, PC15, PC5 for Mc35i */
#define MC35_IGT AT91C_PIO_PC14
#define MC35_EMERGOFF AT91C_PIO_PC15
#define MC35_ST AT91C_PIO_PC5
static struct file_operations Mc35i_fops = ...{
open: Mc35i_open,
read: Mc35i_read,
write: Mc35i_write,
release: Mc35i_close,
};
static int input_flag = 0;
static unsigned char input_data = 0xff;
static void Mc35i_hardware_init (void)
...{
DBG_Mc35i("Mc35i_hardware_init ");
AT91_SYS->PIOC_PER |= MC35_IGT | MC35_EMERGOFF|MC35_ST;
AT91_SYS->PIOC_OER |= MC35_IGT | MC35_EMERGOFF;
AT91_SYS->PIOC_ODR |= MC35_ST;
AT91_SYS->PIOC_CODR |= MC35_IGT| MC35_EMERGOFF; //ignition when system init
}
static int Mc35i_open (struct inode *inode, struct file *file)
...{
DBG_Mc35i("Mc35i_open ");
MOD_INC_USE_COUNT;
return 0;
}
static int Mc35i_close (struct inode *inode, struct file *file)
...{
DBG_Mc35i("Mc35i_close ");
MOD_DEC_USE_COUNT;
return 0;
}
static int Mc35i_read (struct file *file, int *buf, size_t count, loff_t *ppos)
...{
unsigned int data;
DBG_Mc35i("Mc35i_read: input_flag %d ", input_flag);
data = AT91_SYS->PIOC_PDSR & MC35_ST;
printk("status of PC5 is %d ", data);
put_user(data, buf);
return count;
}
static int Mc35i_write (struct file *file, const char *buf, size_t count, loff_t *ppos)
...{
unsigned char cmd_type;
DBG_Mc35i("Mc35i_write: %p ", buf);
get_user(cmd_type, buf);
switch (cmd_type) ...{
case CMD_IGT:
AT91_SYS->PIOC_SODR |= MC35_IGT; //enable /IGT
mdelay(10);
AT91_SYS->PIOC_CODR |= MC35_IGT; //disable /IGT
mdelay(100);
AT91_SYS->PIOC_SODR |= MC35_IGT; //enable /IGT
break;
case CMD_EMERGOFF:
AT91_SYS->PIOC_CODR |= MC35_EMERGOFF;
break;
default:
DBG_Mc35i("Mc35i_write: cmd_type = %d error ", cmd_type);
break;
}
return count;
}
static void __init Mc35i_init (void)
...{
//int ret;
Mc35i_hardware_init();
if(register_chrdev(Mc35i_MAJOR, "Mc35i", &Mc35i_fops))...{
DBG_Mc35i("register_chrdev for Mc35i error ");
goto fail_register_chrdev;
}
printk(KERN_INFO __FILE__ ": gprsMc35i for AT91RM9200 ");
return;
fail_register_chrdev:
return;
}
static void __exit Mc35i_cleanup (void)
...{
unregister_chrdev(Mc35i_MAJOR, "Mc35i");
return;
}
module_init(Mc35i_init);
module_exit(Mc35i_cleanup);