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;
}