文章目录
- 【RK3288 Android6, T8PRO 快捷按键 gpio 配置上拉输入】
- 需求
- 开发过程
- 尝试找到没有用的上拉gpio
- 尝试修改pwm1的gpio的默认上拉模式
- 改动
【RK3288 Android6, T8PRO 快捷按键 gpio 配置上拉输入】
需求
T8pro想要模仿T10 的 快捷按键,选择pwm1来作为快捷按键的输入引脚,但是由于硬件设计,需要一个上拉输入的gpio,按键按下,将该gpio接低,实现低处发。
开发过程
尝试找到没有用的上拉gpio
原本硬件同事选择pwm1来作为快捷按键的输入gpio,但是由于手动申请后发现是下拉输入,查看原理图后面的_d 表示的下拉
这里的下拉指的是rk3288芯片内部 gpio电路的默认选择模式
于是找了另外一个上拉的gpio来作为gpio,于是我找到了uart4_rx, 把这个用来上拉gpio
但是实际使用发现功能上是可行的,但是硬件在测量电压电流时,发现在按下后电平从高电平变成低电平的时候电流过大,容易把芯片的这个gpio端子烧坏。
尝试修改pwm1的gpio的默认上拉模式
通过询问光韬,得知pinctrl 这个驱动,是负责将gpio设置上拉下拉的,但是添加节点后,发现没有什么用
通过查看rk3288-pinctrl.dtsi 中 pinctrl的根节点的结构,并且在驱动中打印,发现pinctrl的驱动只是解析了dts里面的每个节点的内容,并保存在内存里面,但是具体的设置pull模式的ops操作函数却没有调用,只是向上层注册,pinctrl这里只是执行了probe。
通过加入日志,打印出bank(第几组) 和 pin_num (第几个)
发现probe的时候确实加载到gpio7_gpio了,但是后面设置pull只有gpio6的那么几个gpio调用到了。
发现gpio6_20 是gpio6_C4, 查看dts发现
基本都是i2c2 和 sdmmc 里面在调用。发现他们的根节点都有pinctrl的配置
这个时候才理解pinctrl的驱动的意义是为了设置gpio的默认状态,在其他驱动里面调用的
所以改动应该在rk_key这个快捷按键的驱动中加入pinctrl的驱动接口,具体可以仿照uart_dbg这个。然后用chatgpt写一个驱动加入到rk_key的probe中。
改动如下
改动
kernel
From f3c5c1ee8a908ca647bbc35c812061d6905f2361 Mon Sep 17 00:00:00 2001
From: liangji <liangji@keenon.com>
Date: Mon, 4 Mar 2024 16:33:47 +0800
Subject: [PATCH] feat: support pwm1 as pull up function key inputChange-Id: Ib088d50d6af66d6cc1db5026b821ffc0c8ac15b0
Signed-off-by: liangji <liangji@keenon.com>
---arch/arm/boot/dts/keenon_t8pro_8846.dts | 16 +++++++++++++---arch/arm/boot/dts/keenon_t8pro_lcd_b116xan.dtsi | 4 ++++drivers/input/keyboard/rk_keys.c | 18 ++++++++++++++++++3 files changed, 35 insertions(+), 3 deletions(-)diff --git a/arch/arm/boot/dts/keenon_t8pro_8846.dts b/arch/arm/boot/dts/keenon_t8pro_8846.dts
index 06347be..619ee10 100644
--- a/arch/arm/boot/dts/keenon_t8pro_8846.dts
+++ b/arch/arm/boot/dts/keenon_t8pro_8846.dts
@@ -188,6 +188,7 @@&gpio0 GPIO_B5 GPIO_ACTIVE_LOW&gpio8 GPIO_A0 GPIO_ACTIVE_HIGH&gpio0 GPIO_C1 GPIO_ACTIVE_LOW
+ &gpio7 GPIO_A2 GPIO_ACTIVE_LOW //BL_EN for T8pro&gpio7 GPIO_C3 GPIO_ACTIVE_HIGH&gpio7 GPIO_C4 GPIO_ACTIVE_LOW&gpio5 GPIO_C3 GPIO_ACTIVE_HIGH>; // Set W_DIS=1 may cause EC20-CEHC reset fail
@@ -224,6 +225,11 @@};gpio7_gpio {
+ gpio7_a1: gpio7-a1 {
+ rockchip,pins = <GPIO7_A1>;
+ rockchip,pull = <VALUE_PULL_UP>;
+ };
+gpio7_b7: gpio7-b7 {rockchip,pins = <GPIO7_B7>;rockchip,pull = <VALUE_PULL_UP>;
@@ -674,6 +680,11 @@key {compatible = "rockchip,key";io-channels = <&adc 1>;
+
+ /* add pinctrl into key, to set function key gpio default pull mode */
+ pinctrl-names = "default";
+ pinctrl-0 = <&gpio7_a1>;
+/*vol-up-key {linux,code = <115>;
@@ -704,7 +715,7 @@*/function-key {
- gpios = <&gpio5 GPIO_B7 GPIO_ACTIVE_HIGH>;
+ gpios = <&gpio7 GPIO_A1 GPIO_ACTIVE_LOW>;linux,code = <249>;label = "function";gpio-key;
@@ -741,10 +752,9 @@};&pwm1 {
- status = "okay";
+ status = "disabled";};-&clk_core_dvfs_table {operating-points = </* KHz uV */
diff --git a/arch/arm/boot/dts/keenon_t8pro_lcd_b116xan.dtsi b/arch/arm/boot/dts/keenon_t8pro_lcd_b116xan.dtsi
index f22d2b0..45a7855 100644
--- a/arch/arm/boot/dts/keenon_t8pro_lcd_b116xan.dtsi
+++ b/arch/arm/boot/dts/keenon_t8pro_lcd_b116xan.dtsi
@@ -20,6 +20,10 @@236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255>;default-brightness-level = <200>;enable-gpios = <&gpio7 GPIO_A2 GPIO_ACTIVE_HIGH>;
+ /* T8pro backlight is controlled by hardware, disabled backlight to
+ * release pwm1, and enable BL_EN in init-gpio
+ */
+ status = "disabled";};custom {status = "disabled";
diff --git a/drivers/input/keyboard/rk_keys.c b/drivers/input/keyboard/rk_keys.c
index 1071b54..d708ccee7 100755
--- a/drivers/input/keyboard/rk_keys.c
+++ b/drivers/input/keyboard/rk_keys.c
@@ -24,6 +24,7 @@#include <linux/adc.h>#include <linux/slab.h>#include <linux/wakelock.h>
+#include <linux/pinctrl/consumer.h>#include <linux/iio/iio.h>#include <linux/iio/machine.h>
@@ -320,6 +321,23 @@ static int keys_probe(struct platform_device *pdev)struct input_dev *input = NULL;int i, error = 0;int wakeup, key_num = 0;
+ /* keenon liangji add start */
+ /* add pinctrl to set gpio default pull mode.
+ *
+ * this change is only for the purpose of T8pro function gpio pull up input,
+ * and will not have any impact on other models
+ */
+ struct pinctrl *pinctrl;
+ struct pinctrl_state *state;
+
+ pinctrl = devm_pinctrl_get(dev);
+ state = pinctrl_lookup_state(pinctrl, "default");
+
+ if (!IS_ERR(state) && pinctrl_select_state(pinctrl, state) < 0) {
+ dev_err(dev, "Failed to select pinctrl state\n");
+ goto fail0;
+ }
+ /* keenon liangji add end */key_num = of_get_child_count(np);if (key_num == 0)
--
2.7.4