项目场景:MTK平台按键中断触发功能,TP调试简记
提示:仅供参考,学习笔记
例如:项目场景:背部pogopin加按键功能
原因分析:
提示:背部pogo引脚需要增加按键触发扫码功能,由此开始调试,硬件上需要拉高GPIO27、28、44,GPIO44为上拉触发中断的方式,GPIO27、28拉高使IC为GPIO44供电。
1、dws文件添加修改
系统使用DWS文件来编写设备树的源码,然后将DWS文件编译成DTS文件。最终,DTS文件将被编译成DTSI或DTSB文件,供Linux内核在启动时使用。
正常情况,使用vendor\mediatek\proprietary\tools\dct下的DrvGen.exe工具,在里面打开对应芯片文件如T695应该为mt6833文件夹下的dws文件,但T695需要在方案商定的其他路径修改,具体分别为kernel-4.19\drivers\misc\mediatek\dws\mt6853\codegen.dws和vendor\mediatek\proprietary\bootable\bootloader\lk\target\k6833v1_64_k419\dct\dct\codegen.dws这两文件,配置GPIO27、28、44。
例如:Handler
发送消息有两种方式,分别是 Handler.obtainMessage()
和 Handler.sendMessage()
,其中 obtainMessage
方式当数据量过大时,由于 MessageQuene
大小也有限,所以当 message
处理不及时时,会造成先传的数据被覆盖,进而导致数据丢失。
dws文件设置具体如下
2、dts文件修改
配置好dws文件后就需要配置dts文件,在设备树文件中也需要配好中断等。
---`@@ -786,14 +813,27 @@ awinic_haptic@5a{
#endif
#endif
};
+ yft_customkey4_pin_eint_as_int:yft_customkey4_pin_def{
+#ifdef __YFT_CUSTOMKEY_F4_SUPPORT__
+ #if __YFT_CUSTOMKEY_F4_SUPPORT__
+ pins_cmd_dat {
+ pinmux = <__YFT_CUSTOMKEY_F4_SUPPORT__>;
+ slew-rate=<0>; /*direction 0:in,1:out*/
+ //bias-pull-up= <00> ;
+ bias-disable;
+ };
+ #endif
+ #endif
+ };
};
&keypad{
- pinctrl-names ="default","yft_customkey_as_int","yft_customkey2_as_int", "yft_customkey3_as_int";
+ pinctrl-names = "default", "yft_customkey_as_int","yft_customkey2_as_int","yft_customkey3_as_int","yft_customkey4_as_int";
pinctrl-0 = <&yft_customkey_pin_default>;
pinctrl-1 = <&yft_customkey_pin_eint_as_int>;
pinctrl-2 = <&yft_customkey2_pin_eint_as_int>;
pinctrl-3 = <&yft_customkey3_pin_eint_as_int>;
+ pinctrl-4 = <&yft_customkey4_pin_eint_as_int>;
customkeyf1@__YFT_INTERCOMKEY_EINT_EN_PIN_NUM__ {
compatible = "mediatek,yft_customkey";
@@ -827,8 +867,19 @@ awinic_haptic@5a{
};
#endif
#endif
-};
+#ifdef __YFT_CUSTOMKEY_F4_SUPPORT__
+ #if __YFT_CUSTOMKEY_F4_SUPPORT__
+ customkeyf4@__YFT_INTERCOMKEY4_EINT_EN_PIN_NUM__ {
+ compatible = "mediatek,yft_customkey4";
+ interrupt-parent = <&pio>;
+ interrupts = <__YFT_INTERCOMKEY4_EINT_EN_PIN_NUM__ IRQ_TYPE_EDGE_FALLING __YFT_INTERCOMKEY4_EINT_EN_PIN_NUM__ 0>;
+ customkey_f4_gpio = <&pio __YFT_INTERCOMKEY4_EINT_GPIO_NUM__ 0>;
+ debounce = <__YFT_INTERCOMKEY4_EINT_EN_PIN_NUM__ 10>;
+ };
+ #endif
+#endif
+};
#endif
#endif
上面是GPIO44的配置,使用pinctr的方式,需要在源码中找到中断对应的宏,把节点加好后要写好配置,且要在相应的驱动文件里面对该节点做解析,要注意,除了这些定义好还需要将新增的驱动文件和宏加入到相应的Makefile和对用的头文件中,如下:
diff --git a/kernel-4.19/drivers/input/keyboard/mediatek/Makefile b/kernel-4.19/drivers/input/keyboard/mediatek/Makefile
index 47d6650169e..1a6a7d22b78 100644
--- a/kernel-4.19/drivers/input/keyboard/mediatek/Makefile
+++ b/kernel-4.19/drivers/input/keyboard/mediatek/Makefile
@@ -27,6 +27,6 @@ endif
subdir-ccflags-y += -Werror -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_KPD_PLATFORM)/include/
subdir-ccflags-y += -I$(srctree)/drivers/input/keyboard/mediatek/$(MTK_KPD_PLATFORM)/
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/
-obj-$(CONFIG_KEYBOARD_MTK) := kpd.o kpd_customkey_one.o kpd_customkey_two.o kpd_customkey_three.o
+obj-$(CONFIG_KEYBOARD_MTK) := kpd.o kpd_customkey_one.o kpd_customkey_two.o kpd_customkey_three.o kpd_customkey_pogo.o
obj-y += $(subst ",,$(MTK_KPD_PLATFORM))/
diff --git a/vendor/yft/drivers/proj_dts/m601_yft_board_dts_config.h b/vendor/yft/drivers/proj_dts/m601_yft_board_dts_config.h
index 45f9dbddc31..170e531f6d8 100644
--- a/vendor/yft/drivers/proj_dts/m601_yft_board_dts_config.h
+++ b/vendor/yft/drivers/proj_dts/m601_yft_board_dts_config.h
@@ -47,6 +47,10 @@
#define __YFT_INTERCOMKEY3_EINT_PIN__ PINMUX_GPIO74__FUNC_GPIO74
#define __YFT_INTERCOMKEY3_EINT_GPIO_NUM__ 74
+#define __YFT_INTERCOMKEY4_EINT_EN_PIN_NUM__ 44
+#define __YFT_INTERCOMKEY4_EINT_PIN__ PINMUX_GPIO44__FUNC_GPIO44
+#define __YFT_INTERCOMKEY4_EINT_GPIO_NUM__ 44
+
/************************** Hall Related*********/
#if __YFT_HALL_SUPPORT__
#define __YFT_HALL_EINT_PIN_NUM__ 2
同时在不清楚平台编译规则的情况下可以去工程目录下再搜一下以往定义的宏,就会发现还有一些地方需要编译进来,不然就算没有报错,修改也不会生效!!
diff --git a/dists/targets/z200_mt33_L/z200-remdun-rd695-64g4g-hdp-s0-bom3-k419-eea-cts/vendor/yft/drivers/yft_include/yft_custom_config.h b/dists/targets/z200_mt33_L/z200-remdun-rd695-64g4g-hdp-s0-bom3-k419-eea-cts/vendor/yft/drivers/yft_include/yft_custom_config.h
index 3bad2dc6d01..99f1a1023c1 100644
--- a/dists/targets/z200_mt33_L/z200-remdun-rd695-64g4g-hdp-s0-bom3-k419-eea-cts/vendor/yft/drivers/yft_include/yft_custom_config.h
+++ b/dists/targets/z200_mt33_L/z200-remdun-rd695-64g4g-hdp-s0-bom3-k419-eea-cts/vendor/yft/drivers/yft_include/yft_custom_config.h
@@ -7,6 +7,7 @@
#define __YFT_CUSTOMKEY_F1_SUPPORT__ YFT_YES
#define __YFT_CUSTOMKEY_F2_SUPPORT__ YFT_YES
+#define __YFT_CUSTOMKEY_F4_SUPPORT__ YFT_YES
#define __YFT_DUAL_CAMERA_USEDBY_YUV_MODE__ YFT_NO
#define __YFT_MAIN_FAKE_I2C_USE_MAIN2__ YFT_NO
下面简单介绍pintrl配置GPIO和标准配置GPIO方式来拉高GPIO27、28。
(1)pinctr方式
在节点处写好引脚的信息,对于新节点用于描述GPIO27、28的信息,将原来的设备树节点的pinctrl属性进行了更新,添加了对新添加的三个节点的引用。这样,设备树中的引脚控制器(pinctrl)将包含这些新的节点,以便在设备初始化过程,即驱动文件中正确配置这些引脚。
@@ -600,7 +600,7 @@ awinic_haptic@5a{
&yft_finger {
pinctrl-names = "default","finger_reset_en0","finger_reset_en1","finger_spi0_mi_as_spi0_mi","finger_spi0_mi_as_gpio",
"finger_spi0_mo_as_spi0_mo","finger_spi0_mo_as_gpio","finger_spi0_clk_as_spi0_clk","finger_spi0_clk_as_gpio","finger_spi0_cs_as_spi0_cs",
- "finger_spi0_cs_as_gpio","finger_eint_pull_down","finger_eint_pull_up","finger_eint_pull_dis";
+ "finger_spi0_cs_as_gpio","finger_eint_pull_down","finger_eint_pull_up","finger_eint_pull_dis","kpdpad_spi1_clk_as_gpio","kpdpad_reset_en0","kpdpad_reset_en1";
pinctrl-0 = <&finger_pins_default>;
pinctrl-1 = <&finger_reset_en0>;
pinctrl-2 = <&finger_reset_en1>;
@@ -615,7 +615,10 @@ awinic_haptic@5a{
pinctrl-11= <&finger_eint_pull_down>;
pinctrl-12= <&finger_eint_pull_up>;
pinctrl-13= <&finger_eint_pull_dis>;
+ pinctrl-14 = <&kpdpad_reset_en0>;
+ pinctrl-15 = <&kpdpad_reset_en1>;
+ pinctrl-16 = <&kpdpad_setlow_en0>;
+ pinctrl-17 = <&kpdpad_sethigh_en1>;
+
};
#endif
&pio {
@@ -738,6 +742,29 @@ awinic_haptic@5a{
bias-disable;
};
};+ kpdpad_reset_en0:kpdpad_reset_en@0{
+ pins_cmd_dat {
+ pinmux = <PINMUX_GPIO27__FUNC_GPIO27>;
+ slew-rate = <1>;
+ output-low;
+ };
+ };
+ kpdpad_reset_en1:kpdpad_reset_en@1{
+ pins_cmd_dat {
+ pinmux = <PINMUX_GPIO27__FUNC_GPIO27>;
+ slew-rate = <1>;
+ output-high;
+ };
+ };
+ kpdpad_setlow_en0:kpdpad_setlow_en@0{
+ pins_cmd_dat {
+ pinmux = <PINMUX_GPIO28__FUNC_GPIO28>;
+ slew-rate = <1>;
+ output-low;
+ };
+ };
+ kpdpad_sethigh_en1:kpdpad_sethigh_en@1{
+ pins_cmd_dat {
+ pinmux = <PINMUX_GPIO28__FUNC_GPIO28>;
+ slew-rate = <1>;
+ output-high;
+ };
+ };
对于这两个引脚的dts中pinctrl方式已设置完毕。
(2)标准GPIO配置方式
而标准GPIO设置方式则更简单些,直接在一定会使用的节点添加即可:
@@ -621,12 +621,15 @@ awinic_haptic@5a{
&yft_finger {
reset-gpio = <&pio __YFT_FINGERPRINT_RESET_PIN_NUM__ 0>;
int-gpio = <&pio __YFT_FINGERPRINT_EINT_EN_PIN_NUM__ 0>;
+ powerpogo27-gpio27 = <&pio PINMUX_GPIO27__FUNC_GPIO27 0>;
+ setuppogo28-gpio28 = <&pio PINMUX_GPIO28__FUNC_GPIO28 0>;
interrupt-parent = <&pio>;
interrupts = <__YFT_FINGERPRINT_EINT_EN_PIN_NUM__ IRQ_TYPE_EDGE_RISING __YFT_FINGERPRINT_EINT_EN_PIN_NUM__ 0>;
debounce = <__YFT_FINGERPRINT_EINT_EN_PIN_NUM__ 0>;
status = "okay";
};
3、按键驱动文件修改
做好dts的配置后要去相应的驱动文件中解析dts,解析dts也分为pinctrl的解析和标准GPIO方式解析方式,思路都是先获取GPIO的状态然后设置GPIO的模式和对应值。
(1)pinctrl方式
--- a/kernel-4.19/drivers/misc/mediatek/fingerprint/fingerprint.c
+++ b/kernel-4.19/drivers/misc/mediatek/fingerprint/fingerprint.c
@@ -29,7 +29,8 @@ int yft_finger_probe_isok = 0;//add for yft finger jianrong
struct pinctrl *yft_finger_pinctrl;
struct pinctrl_state *yft_finger_reset_high,*yft_finger_reset_low,*yft_finger_spi0_mi_as_spi0_mi,*yft_finger_spi0_mi_as_gpio,
*yft_finger_spi0_mo_as_spi0_mo,*yft_finger_spi0_mo_as_gpio,*yft_finger_spi0_clk_as_spi0_clk,*yft_finger_spi0_clk_as_gpio,
-*yft_finger_spi0_cs_as_spi0_cs,*yft_finger_spi0_cs_as_gpio,*yft_finger_eint_pull_down,*yft_finger_eint_pull_up,*yft_finger_eint_pull_dis;
+*yft_finger_spi0_cs_as_spi0_cs,*yft_finger_spi0_cs_as_gpio,*yft_finger_eint_pull_down,*yft_finger_eint_pull_up,*yft_finger_eint_pull_dis,
+*yft_kpdpad_reset_low,*yft_kpdpad_reset_high;
int yft_finger_get_gpio_info(struct platform_device *pdev)
{
@@ -55,7 +56,19 @@ int yft_finger_get_gpio_info(struct platform_device *pdev)
dev_err(&pdev->dev, " Cannot find yft_finger pinctrl yft_finger_reset_high!\n");
return ret;
}
- yft_finger_reset_low = pinctrl_lookup_state(yft_finger_pinctrl, "finger_reset_en0");
+ yft_kpdpad_reset_low = pinctrl_lookup_state(yft_finger_pinctrl, "finger_reset_en0");
+ if (IS_ERR(yft_kpdpad_reset_low)) {
+ ret = PTR_ERR(yft_kpdpad_reset_low);
+ dev_err(&pdev->dev, " Cannot find yft_finger pinctrl yft_kpdpad_reset_low!\n");
+ return ret;
+ }
+ yft_kpdpad_reset_high = pinctrl_lookup_state(yft_finger_pinctrl, "kpdpad_reset_en1");
+ if (IS_ERR(yft_kpdpad_reset_high)) {
+ ret = PTR_ERR(yft_kpdpad_reset_high);
+ dev_err(&pdev->dev, " Cannot find yft_finger pinctrl yft_kpdpad_reset_high!\n");
+ return ret;
+ }
+ yft_finger_reset_low = pinctrl_lookup_state(yft_finger_pinctrl, "kpdpad_reset_en0");
if (IS_ERR(yft_finger_reset_low)) {
ret = PTR_ERR(yft_finger_reset_low);
dev_err(&pdev->dev, " Cannot find yft_finger pinctrl yft_finger_reset_low!\n");
上面设置状态,查找dts设置的GPIO名
pinctrl_select_state(yft_finger_pinctrl, yft_finger_sethi_high);
pinctrl_select_state(yft_finger_pinctrl, yft_kpdpad_reset_high);
接着用 pinctrl_select_state函数设置引脚拉高或拉低。
(2)标准GPIO设置方式
同样先获取GPIO,请求GPIO,成功后可以设置引脚状态
+ gpio_pin_27 = of_get_named_gpio(gl_node, "powerpogo27-gpio27", 0);
+ gpio_pin_28 = of_get_named_gpio(gl_node, "setuppogo28-gpio28", 0);
+ printk("ysj: test_power_delay_work_func gpio_pin_27 = %d, gpio_pin_28 = %d\n",gpio_pin_27,gpio_pin_28);
+ // 申请
+ ret = gpio_request(73, "powerpogo27-gpio27"); //由于mtk的引脚号有偏移,所以会出现申请失败的可能,要自己添加偏移量,这个偏移量为46。
+ if (ret != 0)
+ {
+ printk("ysj: gpio27 request failed %d\n",ret);
+ } else {
+ printk("ysj: gpio27 request success\n");
+ }
+
+ ret = gpio_request(74, "setuppogo28-gpio28");
+ if (ret != 0)
+ {
+ printk("ysj: gpio28 request failed %d\n",ret);
+ } else {
+ printk("ysj: gpio28 request success\n");
+ }
+ gpio_direction_output(73, 1);
+ gpio_direction_output(74, 1);
4、如何查看是否申请引脚成功的两种方法
(1)使用 cat sys/kernel/debug/gpio,这里面会有引脚复用的功能,还有引脚的模式
(2)使用 cat ./sys/devices/platform/pinctrl/driver/pinctrl/mt_gpio,用一串数字表示状态的变化
TP调试,调整参数等,看log是否驱动有做接口提供下发组
转载学习链接:
https://www.cnblogs.com/kn-zheng/p/17529462.html
https://cloud.tencent.com/developer/article/1867378
有什么需要补充再稍后补充吧