www.pudn.com > int_driver.rar > s3c2410-int.c, change:2007-04-11,size:5871b



#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/delay.h>

#include <asm/hardware.h>
//#include <asm/arch/spi.h>

#include <asm/arch/S3C2410.h>
#include <asm/arch/irqs.h>

/* debug macros */
//#undef DEBUG
#define DEBUG
#ifdef DEBUG
#define DPRINTK( x... )	printk("s3c2410-int: " ##x)
#else
#define DPRINTK( x... )
#endif


#define DEVICE_NAME  "s3c2410 int"
#define s3c2410_IRQ3		IRQ_EINT3	//IRQ_EINT3
#define s3c2410_IRQ5		IRQ_EINT5	//IRQ_EINT4
#define s3c2410_IRQ9		IRQ_EINT9	//IRQ_EINT5



#define GPIO_key_int01  (GPIO_MODE_IN | GPIO_PULLUP_DIS | GPIO_F3)
#define GPIO_key_int02  (GPIO_MODE_IN | GPIO_PULLUP_DIS | GPIO_F5)
#define GPIO_key_int03  (GPIO_MODE_IN | GPIO_PULLUP_DIS | GPIO_G1)



#define led01_enable() \
	({ 	GPCCON &=~ 0xc00;		\
		GPCCON |= 0x400;              \
		GPCDAT&=~ 0x20;          \
		GPCDAT |= 0x0;     \
})

#define led01_disable() \
		({ GPCDAT&=~ 0x20;          \
		GPCDAT |= 0x20;   \
})


#define led02_enable() \
    ({  GPCCON &=~ 0x3000;       \
        GPCCON |= 0x1000;              \
        GPCDAT&=~ 0x40;          \
        GPCDAT |= 0x0;     \
           })

#define led02_disable() \
        ({ GPCDAT&=~ 0x40;          \
           GPCDAT |= 0x40;   \
            })

#define led03_enable() \
    ({  GPCCON &=~ 0xc000;       \
        GPCCON |= 0x4000;              \
        GPCDAT&=~ 0x80;          \
        GPCDAT |= 0x0;     \
         })

#define led03_disable() \
        ({ GPCDAT&=~ 0x80;          \
           GPCDAT |= 0x80;   \
            })


static void s3c2410_IRQ3_fun(int irq, void *dev_id, struct pt_regs *reg)
{
	unsigned char byte;
      int i =0 ;
  	DPRINTK("enter interrupt 3 !\n");
        for (i=0;i<2;i++)
        	{
         led01_enable();
		 mdelay(800);
	     led01_disable();
	     mdelay(800);
         led02_enable();
         mdelay(800);
         led02_disable();
         mdelay(800);
         led03_enable();
         mdelay(800);
         led03_disable();
		}
}


static void s3c2410_IRQ5_fun(int irq, void *dev_id, struct pt_regs *reg)
{
    unsigned char byte;
    int i =0 ;
    DPRINTK("enter interrupt 5 ! \n");
    for (i=0;i<2;i++)
    {
        led01_enable();
        mdelay(1000);
        led01_disable();
        mdelay(1000);
        led02_enable();
        mdelay(1000);
        led02_disable();
        mdelay(1000);
        led03_enable();
        mdelay(1000);
        led03_disable();
    }
}


static void s3c2410_IRQ9_fun(int irq, void *dev_id, struct pt_regs *reg)
{
    unsigned char byte;
    int i =0 ;
    DPRINTK("enter interrupt 9 !\n");
    for (i=0;i<2;i++)
    {
        led01_enable();
        mdelay(400);
        led01_disable();
        mdelay(400);
        led02_enable();
        mdelay(400);
        led02_disable();
        mdelay(400);
        led03_enable();
        mdelay(400);
        led03_disable();
    }
}

static int __init s3c2410_interrupt_init(void)
{
	int  i, ret;
	int flags;

	//set_gpio_ctrl(GPIO_MCP2510_CS);
	//printGPE();
  	//printSPI();
	//printRegisters();

    set_gpio_ctrl(GPIO_key_int01);
    set_gpio_ctrl(GPIO_key_int02);
    set_gpio_ctrl(GPIO_key_int03);

    

    led01_disable();
    led02_disable();
    led03_disable();
 
    
    for (i=0;i<2;i++)
    {
        led01_enable();
        led02_enable();
        led03_enable();
        // printk(DEVICE_NAME"GPCCON:%x\t GPCDAT:%x\t\n", GPCCON, GPCDAT );
        mdelay(500);
        led01_disable();
        led02_disable();
        led03_disable();
        //  printk (DEVICE_NAME"GPCCON:%x\t GPCDAT:%x\t\n",GPCCON, GPCDAT );
        mdelay(500);
        
        

    }
     

    local_irq_save(flags);
	
	//init_MCP2510(BandRate_250kbps);
	/* Register IRQ handlers */
	
	ret = set_external_irq(s3c2410_IRQ3, EXT_RISING_EDGE, GPIO_PULLUP_DIS);
	if (ret){
		
              printk("s3c2410_IRQ3  set_external_irq  failure\n");
		return ret;
		
		}
	local_irq_restore(flags);




	local_irq_save(flags);
	ret = set_external_irq(s3c2410_IRQ5, EXT_RISING_EDGE, GPIO_PULLUP_DIS);
	if (ret){
		
              printk("s3c2410_IRQ5  set_external_irq  failure\n");
		return ret;
		
		}
	local_irq_restore(flags);

		local_irq_save(flags);
	
	
	ret = set_external_irq(s3c2410_IRQ9, EXT_RISING_EDGE, GPIO_PULLUP_DIS);
	if (ret){
		
              printk("s3c2410_IRQ9  set_external_irq  failure\n");
		return ret;
		
		}
	local_irq_restore(flags);



	

	//ret = register_chrdev(0, DEVICE_NAME, &s3c2410_fops);
	//if (ret < 0) {
	//	printk(DEVICE_NAME " can't get major number\n");
	//	return ret;
	//}
	//Major = ret;

	/* Enable touch interrupt */

    
	ret = request_irq(s3c2410_IRQ3, s3c2410_IRQ3_fun, SA_INTERRUPT, "s3c2410_IRQ3", s3c2410_IRQ3_fun);
	if (ret)
    {
        printk("s3c2410_IRQ3 request_irq  failure\n");

        return ret;
    }


//*
    ret = request_irq(s3c2410_IRQ5, s3c2410_IRQ5_fun, SA_INTERRUPT, "s3c2410_IRQ5", s3c2410_IRQ5_fun);
    if (ret)
    {
        printk("s3c2410_IRQ5 request_irq  failure\n" );

        return ret;
    }

    ret = request_irq(s3c2410_IRQ9, s3c2410_IRQ9_fun, SA_INTERRUPT,"s3c2410_IRQ9", s3c2410_IRQ9_fun);
    if (ret)
    {
        printk("s3c2410_IRQ9  request_irq  failure\n");

        return ret;
    }

//*/


    /*
	MCP2510_CLOSE_INT();

#ifdef CONFIG_DEVFS_FS
	devfs_spi_dir = devfs_mk_dir(NULL, "can", NULL);
	devfs_spiraw = devfs_register(devfs_spi_dir, "0", DEVFS_FL_DEFAULT,
			Major, SPIRAW_MINOR, S_IFCHR | S_IRUSR | S_IWUSR,
			&s3c2410_fops, NULL);
#endif

*/

	printk(DEVICE_NAME " harrr   initialized\n");
	
	return 0;
}

static void __exit s3c2410_interrupt_exit(void)
{

	printk(DEVICE_NAME " unloaded\n");
}

module_init(s3c2410_interrupt_init);
module_exit(s3c2410_interrupt_exit);