request_irq

int request_irq(unsigned int irq,
        irq_handler_t handler,
        unsigned long flags, const char *devname, void *dev_id)
{
    struct irq_node *node;
    int res;

    node = new_irq_node();
    if (!node)
        return -ENOMEM;

    node->handler = handler;
    node->flags   = flags;
    node->dev_id  = dev_id;
    node->devname = devname;

    res = setup_irq(irq, node);
    if (res)
        node->handler = NULL;

    return res;
}

EXPORT_SYMBOL(request_irq);

 

int setup_irq(unsigned int irq, struct irq_node *node)
{
    struct irq_controller *contr;
    struct irq_node **prev;
    unsigned long flags;

    if (irq >= NR_IRQS || !(contr = irq_controller[irq])) {
        printk("%s: Incorrect IRQ %d from %s\n",
               __FUNCTION__, irq, node->devname);
        return -ENXIO;
    }

    spin_lock_irqsave(&contr->lock, flags);

    prev = irq_list + irq;
    if (*prev) {
        /* Can't share interrupts unless both agree to */
        if (!((*prev)->flags & node->flags & IRQF_SHARED)) {
            spin_unlock_irqrestore(&contr->lock, flags);
            return -EBUSY;
        }
        while (*prev)
            prev = &(*prev)->next;
    }

    if (!irq_list[irq]) {
        if (contr->startup)
            contr->startup(irq);
        else
            contr->enable(irq);
    }
    node->next = NULL;
    *prev = node;

    spin_unlock_irqrestore(&contr->lock, flags);

    return 0;
}

/arch/arm/plat-s3c24xx

void __init s3c24xx_init_irq(void)

......

  /* external interrupts */

    for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {
        irqdbf("registering irq %d (ext int)\n", irqno);
        set_irq_chip(irqno, &s3c_irq_eint0t4);
        set_irq_handler(irqno, handle_edge_irq);
        set_irq_flags(irqno, IRQF_VALID);
    }

    for (irqno = IRQ_EINT4; irqno <= IRQ_EINT23; irqno++) {
        irqdbf("registering irq %d (extended s3c irq)\n", irqno);
        set_irq_chip(irqno, &s3c_irqext_chip);
        set_irq_handler(irqno, handle_edge_irq);
        set_irq_flags(irqno, IRQF_VALID);
    }

.....

 

static struct irq_chip s3c_irqext_chip = {
    .name        = "s3c-ext",
    .mask        = s3c_irqext_mask,
    .unmask        = s3c_irqext_unmask,
    .ack        = s3c_irqext_ack,
    .set_type    = s3c_irqext_type,
    .set_wake    = s3c_irqext_wake
};

static struct irq_chip s3c_irq_eint0t4 = {
    .name        = "s3c-ext0",
    .ack        = s3c_irq_ack,
    .mask        = s3c_irq_mask,
    .unmask        = s3c_irq_unmask,
    .set_wake    = s3c_irq_wake,
    .set_type    = s3c_irqext_type,
};

 

int
s3c_irqext_type(unsigned int irq, unsigned int type)

....

/* Set the external interrupt to pointed trigger type */
    switch (type)
    {
        case IRQT_NOEDGE:
            printk(KERN_WARNING "No edge setting!\n");
            break;

        case IRQT_RISING:
            newvalue = S3C2410_EXTINT_RISEEDGE;
            break;

        case IRQT_FALLING:
            newvalue = S3C2410_EXTINT_FALLEDGE;
            break;

        case IRQT_BOTHEDGE:
            newvalue = S3C2410_EXTINT_BOTHEDGE;
            break;

        case IRQT_LOW:
            newvalue = S3C2410_EXTINT_LOWLEV;
            break;

        case IRQT_HIGH:
            newvalue = S3C2410_EXTINT_HILEV;
            break;

        default:
            printk(KERN_ERR "No such irq type %d", type);
            return -1;
    }

    value = __raw_readl(extint_reg);
    value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
    __raw_writel(value, extint_reg);

    return 0;

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值