opl_minte.c
浏览该文件的文档。00001 00017 #include <linux/init.h> 00018 #include <linux/kernel.h> 00019 #include <linux/module.h> 00020 #include <linux/sched.h> 00021 #include <linux/wait.h> 00022 #include <asm/uaccess.h> 00023 #include <asm/io.h> 00024 #include <linux/slab.h> 00025 #include <linux/types.h> 00026 #include <linux/errno.h> 00027 00028 #include <opl_minte.h> 00029 #include <ipmux_interrupt.h> 00030 00034 /*--------------------------Macro definition------------------------- */ 00035 #define OPL_MINTE_MAJOR 120 00036 #define OPL_MINTE_DEVICE "opl_minte" 00037 00038 00044 /*--------------------------type definition------------------------- */ 00045 00051 /*-----------------global varible/function declaration--------------- */ 00052 extern u32 get_irq_pending(void); 00053 extern void clear_irq_pending(void); 00054 extern void ipmux_irq_enable(unsigned int irq); 00055 extern void ipmux_irq_disable(unsigned int irq); 00061 u32 g_opl_chip_irq_event = 0; 00062 wait_queue_head_t g_opl_chip_waitq; 00063 00069 /*--------------local function declaration------------- */ 00070 static int opl_minte_open(struct inode *inode, struct file *filp); 00071 static ssize_t opl_minte_read(struct file *filp, char *buffer, size_t length, loff_t *offset); 00072 static ssize_t opl_minte_write(struct file *filp, const char *buffer, size_t length, loff_t *offset); 00073 static int opl_minte_release(struct inode *inode, struct file *filp); 00074 00080 /*--------------local varible declaration and definition------------- */ 00081 static u32 opl_minte_open_count = 0; 00082 static u32 opl_minte_is_open = 0; 00083 struct file_operations opl_minte_fops = { 00084 .read = opl_minte_read, 00085 .write = opl_minte_write, 00086 .open = opl_minte_open, 00087 .release = opl_minte_release, 00088 }; 00089 00095 /*------------local function declaration and definition-------------- */ 00096 00109 static ssize_t opl_minte_read(struct file *filp, char *buffer, size_t length, loff_t *offset) 00110 { 00111 u32 pending = 0; 00112 if(test_bit(0,&opl_minte_is_open)){ 00113 /* TBD: add debug message */ 00114 wait_event_interruptible(g_opl_chip_waitq,g_opl_chip_irq_event); 00115 if(!test_and_clear_bit(0,&g_opl_chip_irq_event)){ 00116 /* TBD:add debug message ,if return 0,indicate more process read it.*/ 00117 printk("clear g_opl_chip_irq_event event failed\n"); 00118 return -ENODEV; 00119 } 00120 pending = get_irq_pending(); 00121 /* should add lock later */ 00122 clear_irq_pending(); 00123 if(!(copy_to_user((void *)buffer,(void *)&pending,4))){ 00124 /* TBD: add debug message. */ 00125 return 4; 00126 } 00127 } 00128 return -ENODEV; 00129 } 00146 static ssize_t opl_minte_write(struct file *filp, const char *buffer, size_t length, loff_t *offset) 00147 { 00148 int irq_enable = 0; 00149 if(test_bit(0,&opl_minte_is_open)){ 00150 if(!(copy_from_user(&irq_enable,buffer,4))){ 00151 if(irq_enable){ 00152 ipmux_irq_enable(OPL_IPMUX_IRQ); 00153 }else{ 00154 ipmux_irq_disable(OPL_IPMUX_IRQ); 00155 } 00156 return 0; 00157 } 00158 } 00159 return -ENODEV; 00160 } 00161 00162 00163 static int opl_minte_open(struct inode *inode, struct file *filp) 00164 { 00165 if (test_and_set_bit(0, &opl_minte_is_open)) 00166 printk(KERN_DEBUG "the/dev/opl_minte is opened\n"); 00167 opl_minte_open_count ++; 00168 MOD_INC_USE_COUNT; 00169 return 0; 00170 } 00171 00172 static int opl_minte_release(struct inode *inode, struct file *filp) 00173 { 00174 opl_minte_open_count --; 00175 if(!opl_minte_open_count) 00176 clear_bit(0, &opl_minte_is_open); 00177 MOD_DEC_USE_COUNT; 00178 return 0; 00179 } 00189 static int __init opl_minte_init(void) 00190 { 00191 int ret; 00192 printk("enter minte module\n"); 00193 ret = register_chrdev(OPL_MINTE_MAJOR,OPL_MINTE_DEVICE,&opl_minte_fops); 00194 if(ret<0){ 00195 /* TBD add debug message */ 00196 printk("error1\n"); 00197 goto fail1; 00198 } 00199 ret = opl_minte_hw0_irqinit(); 00200 if(ret){ 00201 /*TBD add debug message */ 00202 goto fail2; 00203 } 00204 init_waitqueue_head(&g_opl_chip_waitq); 00205 return 0; 00206 fail2: 00207 unregister_chrdev(OPL_MINTE_MAJOR,OPL_MINTE_DEVICE); 00208 fail1: 00209 return ret; 00210 } 00219 static void __exit opl_minte_exit(void) 00220 { 00221 int ret; 00222 opl_minte_hw0_irqexit(); 00223 ret = unregister_chrdev(OPL_MINTE_MAJOR,OPL_MINTE_DEVICE); 00224 if(ret < 0){ 00225 /*TBD:add debug message */ 00226 } 00227 return; 00228 } 00229 00230 module_init(opl_minte_init); 00231 module_exit(opl_minte_exit); 00232 MODULE_LICENSE("GPL2"); 00233 MODULE_AUTHOR("stephanxu <[email protected]>"); 00234 MODULE_DESCRIPTION("control interface for opulan ipmux-e switch chip");
Generated at Mon Jul 30 16:43:48 2007 for IPMUX1IPMUX2IPMUX3 by
