中断API之irq_set_chip

int irq_set_chip(unsigned int irq, struct irq_chip *chip)为形参的irq设置对应的irq_chip
其使用的例程如下:
void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
			     unsigned int clr, unsigned int set)
{
	unsigned int i = gc->irq_base;

	raw_spin_lock(&gc_lock);
	list_del(&gc->list);
	raw_spin_unlock(&gc_lock);

	for (; msk; msk >>= 1, i++) {
		if (!(msk & 0x01))
			continue;

		/* Remove handler first. That will mask the irq line */
		irq_set_handler(i, NULL);
		irq_set_chip(i, &no_irq_chip);
		irq_set_chip_data(i, NULL);
		irq_modify_status(i, clr, set);
	}
}

其源码分析如下:
int irq_set_chip(unsigned int irq, struct irq_chip *chip)
{
	unsigned long flags;
	#根据中断号得到中断描述符
	struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
	#中断描述符为null,则退出
	if (!desc)
		return -EINVAL;
	#要设置的形参chip为null的话,则设置为no_irq_chip
	if (!chip)
		chip = &no_irq_chip;
	#更新中断描述符的irq_data.chip,从这里看到irq_set_chip 可以被反复调用,新值会覆盖旧值
	desc->irq_data.chip = chip;
	irq_put_desc_unlock(desc, flags);
	/*
	 * For !CONFIG_SPARSE_IRQ make the irq show up in
	 * allocated_irqs.
	 */
	 #在allocated_irqs中设置irq对应的bit
	irq_mark_irq(irq);
	return 0;
}
void irq_mark_irq(unsigned int irq)
{
	mutex_lock(&sparse_irq_lock);
	bitmap_set(allocated_irqs, irq, 1);
	mutex_unlock(&sparse_irq_lock);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值