GPIO子系统之---方法获取中断号和申请中断

1、环境:

1、平台:mtk
2、内核版本:kernel-4.14
3、通用性说明:各平台通用,属于内核的gpio子系统

2、dts的配置

dws生成的cust.dtsi如下:

&accdet {
	interrupt-parent = <&pio>;
	interrupts = <9 IRQ_TYPE_LEVEL_LOW 9 0>;//中断号----用于映射中断号
	deb-gpios = <&pio 9 0>;//gpio 编号
	debounce = <256000>;//消抖时间
	status = "okay";
};

mt6739(cpu型号)中的节点描述信息:

	//定义了一个节点
	accdet: accdet {
		compatible = "mediatek,pmic-accdet";
	};

3、驱动获取的方法

3.1 驱动找到dts中的节点

struct device_node *node = NULL;
static u32 gpiopin;//gpio 编号
static u32 accdet_irq;//中断号
static u32 gpio_headset_deb;//消抖时间
node = of_find_matching_node(node, accdet_of_match);//注意:of_find_matching_node的参数一应为NULL
	if (!node) {
		printk("accdet %s can't find compatible node\n", __func__);
		return -1;
	}
gpiopin = of_get_named_gpio(node, "deb-gpios", 0);//找到dts中的管脚----可用于输出高低电平
ret = of_property_read_u32(node, "debounce", &gpio_headset_deb);//获取dts中的信息
if (ret < 0) {
	pr_notice("accdet %s gpiodebounce not found,ret:%d\n",__func__, ret);
}
gpio_set_debounce(gpiopin, gpio_headset_deb);//设置gpio消抖时间---gpio和中断是同一管脚,所以消抖的是中断
//方法1:
accdet_irq = irq_of_parse_and_map(node, 0);//映射中断号
//方法2:
accdet_irq = gpio_to_irq(gpiopin);//gpio转成中断
ret = request_irq(accdet_irq, ex_eint_handler, IRQF_TRIGGER_NONE,"accdet-eint", NULL);//申请中断
if (ret) {
	pr_notice("accdet %s request_irq fail, ret:%d.\n", __func__,ret);
	return ret;
}

4、总结

4.1、驱动找到dts节点的方法:of_find_matching_node

4.2、获取管脚gpio:of_get_named_gpio

4.3、设置中断消抖时间:gpio_set_debounce

4.4、驱动通过节点获取中断号:irq_of_parse_and_map

4.5、通过gpio转成中断:gpio_to_irq

4.6、申请中断:request_irq

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值