static struct at91_gpio_bank *gpio;
void __init at91_gpio_irq_setup(void)
{
unsigned pioc, pin;
for (pioc = 0, pin = PIN_BASE;
pioc < gpio_banks;
pioc++) {
void __iomem *controller;
unsigned id = gpio[pioc].id;
unsigned i;
clk_enable(gpio[pioc].clock);
//处理/* enable PIO controller's clock */
controller = (void __iomem *) AT91_VA_BASE_SYS + gpio[pioc].offset;
__raw_writel(~0, controller + PIO_IDR);
set_irq_data(id, (void *) pin);
set_irq_chip_data(id, controller);
for (i = 0; i < 32; i++, pin++) {
/*
* Can use the "simple" and not "edge" handler since it's
* shorter, and the AIC handles interupts sanely.
*/
set_irq_chip(pin, &gpio_irqchip);
set_irq_handler(pin, handle_simple_irq);
set_irq_flags(pin, IRQF_VALID);
}
set_irq_chained_handler(id, gpio_irq_handler);
}
如果使用PIO IO:
直接用int at91_get_gpio_value(unsigned pin)
int at91_set_gpio_value(unsigned pin, int value)
就可以实现读写啦
如果使用PIO的中断呢?
一 设置为输入.
二 设置毛刺(也可以不设置)
三 调用 REQUEST_IRQ()
at91_set_gpio_input(AT91_PIN_PB5,1);
result = request_irq(AT91_PIN_PB5, kirq_interrupt, SA_INTERRUPT, "kirq", &kirq_dev);
if (result < 0){
printk("register irq fail.%d\r\n",result);
return result;
}
/************************************************************************************/
实验的结果(查看中断是否产生)
/teset/irq # cat /proc/interrupts
CPU0
1: 72905 AIC at91_tick, atmel_serial
10: 0 AIC at91_udc
20: 0 AIC ohci_hcd:usb1
21: 4754 AIC eth0
69: 0 GPIO kirq
101: 1 GPIO at91_udc
at91_set_gpio_input(AT91_PIN_PA5,1);
result = request_irq(AT91_PIN_PA5, kirq_interrupt, SA_INTERRUPT, "kirq", &kirq_dev);
if (result < 0){
printk("register irq fail.%d\r\n",result);
return result;
}