Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1132866
  • 博文数量: 91
  • 博客积分: 10053
  • 博客等级: 上将
  • 技术积分: 1335
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-01 12:46
文章分类
文章存档

2011年(4)

2010年(22)

2009年(22)

2008年(43)

分类: LINUX

2010-07-09 16:11:03

 
 
 
void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks)
{

       unsigned  i;
       struct at91_gpio_chip *at91_gpio, *last = NULL;
 BUG_ON(nr_banks > MAX_GPIO_BANKS);
 gpio_banks = nr_banks;
 for (i = 0; i < nr_banks; i++)
 {
        at91_gpio = &gpio_chip[i];
  at91_gpio->bank = &data[i];
  at91_gpio->chip.base = PIN_BASE + i * 32;
  at91_gpio->regbase = at91_gpio->bank->offset +
   (void __iomem *)AT91_VA_BASE_SYS;
  /* enable PIO controller's clock */
  clk_enable(at91_gpio->bank->clock);
  /* AT91SAM9263_ID_PIOCDE groups PIOC, PIOD, PIOE */
  if (last && last->bank->id == at91_gpio->bank->id)
   last->next = at91_gpio;
  last = at91_gpio;
  gpiochip_add(&at91_gpio->chip);
}
 }
 

 
static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
{

      unsigned pin;
      struct irq_desc *gpio;
      struct at91_gpio_chip *at91_gpio;
      void __iomem *pio;
      u32  isr;
 at91_gpio = get_irq_chip_data(irq);
 pio = at91_gpio->regbase;
 /* temporarily mask (level sensitive) parent IRQ */
 desc->chip->ack(irq);
 for (;;) {
  /* Reading ISR acks pending (edge triggered) GPIO interrupts.
   * When there none are pending, we're finished unless we need
   * to process multiple banks (like ID_PIOCDE on sam9263).
   */
  isr = __raw_readl(pio + PIO_ISR) & __raw_readl(pio + PIO_IMR);
  if (!isr)
  {
   if (!at91_gpio->next)
    break;
   at91_gpio = at91_gpio->next;
   pio = at91_gpio->regbase;
   continue;
  }
  pin = at91_gpio->chip.base;
  gpio = &irq_desc[pin];
 
  while (isr)
  {
   
if (isr & 1) 
{
    if (unlikely(gpio->depth))
    {
     /*
      * The core ARM interrupt handler lazily disables IRQs so
      * another IRQ must be generated before it actually gets
      * here to be disabled on the GPIO controller.
      */
     gpio_irq_mask(pin);
    }
    else
     generic_handle_irq(pin);
   }
   pin++;
   gpio++;
   isr >>= 1;
  }
 }
 desc->chip->unmask(irq);
 /* now it may re-trigger */
}
 
 
 
阅读(3514) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~