imx8mp kernel L5.4.70 driver/tty/serial/imx.c can not control gpio

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

imx8mp kernel L5.4.70 driver/tty/serial/imx.c can not control gpio

1,140 Views
yqa
Contributor I

问题:
设备树uart3中增加 txen-gpios = <&gpio4 23 GPIO_ACTIVE_HIGH>;以实现485流控该方法,之前在imx6平台,linux4.9.11上实现并获得验证。
&uart3 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_uart3>;
assigned-clocks = <&clk IMX8MP_CLK_UART3>;
assigned-clock-parents = <&clk IMX8MP_SYS_PLL1_80M>;
txen-gpios = <&gpio4 23 GPIO_ACTIVE_HIGH>;
linux,rs485-enabled-at-boot-time;
status = "okay";
};

drivers/tty/serial/imx.c imx_uart_probe_dt函数增加如下
已添加头文件
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/gpio/consumer.h>

if (of_get_property(np, "txen-gpios", NULL))
sport->have_txengpio = 1;
else
sport->txen_gpio = -1;

if (sport->have_txengpio){
sport->txen_gpio = devm_gpiod_get(&pdev->dev, "txen",gflags);
printk("###sport->txen_gpio=%d",sport->txen_gpio);
if (IS_ERR(sport->txen_gpio)){
sport->txen_gpio = -1;
}
}

驱动运行后打印
###sport->txen_gpio=-517
源码跟踪
drivers/gpio/gpiolib-of.c
static struct gpio_desc *of_get_named_gpiod_flags
chip = of_find_gpiochip_by_xlate(&gpiospec);
if (!chip) {
printk("####err=%d",-EPROBE_DEFER);
desc = ERR_PTR(-EPROBE_DEFER);
goto out;
}

返回错误-EPROBE_DEFER为-517
gpio4_23在用户层可操作,表明该GPIO未被其他驱动占用。
echo 119 >/sys/class/gpio/export
echo out >/sys/class/gpio/gpio119/direction
echo 1 >/sys/class/gpio/gpio119/value

验证1:
设备树中添加
test:test {
compatible = "Jason_hello";
txen-gpios111;
hello = <&gpio4 23 GPIO_ACTIVE_HIGH>;
};
添加模块驱动gpio.c
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_gpio.h>

static int __init mypinctrl_init(void)
{
int gpionum = 0;
int ret = 0;
struct device_node *node = NULL;
node = of_find_compatible_node(NULL,NULL,"Jason_hello");
if(!node){
printk("get node error\n");
return ret;
}
gpionum = of_get_named_gpio(node,"hello",0);
if(gpionum < 0){
printk("get gpionum error=%d\n",gpionum);
return ret;
}
ret = gpio_request(gpionum,"hello");
if(ret){
printk("gpio_request error\n");
return ret;
}
printk("gpio(%d) value = %d\n",gpionum,ret);
ret = gpio_get_value(gpionum);
printk("gpio(%d) value = %d\n",gpionum,ret);
gpio_direction_output(gpionum,1); // 设置 gpio 输出低电平
ret = gpio_get_value(gpionum);
printk("gpio(%d) value = %d\n",gpionum,ret);
return 0;
}
static void __exit mypinctrl_exit(void)
{
printk("%s\n",__func__);
}

module_init(mypinctrl_init);
module_exit(mypinctrl_exit);
MODULE_LICENSE("GPL");


编译后加载模块驱动,该io可以被驱动正常申请控制。
insmod gpio.ko
[ 30.910031] gpio(119) value = 0
[ 30.913236] gpio(119) value = 0
[ 30.916442] gpio(119) value = 1
验证2:
将上述控制函数修改后添加到drivers/tty/serial/imx.c中运行,依旧无法申请gpio,报错依旧为-517

验证3:
在drivers/tty/serial/imx.c 直接添加
gpio_request(119,"hello");依旧报错gpio_request error=-517

0 Kudos
Reply
3 Replies

1,126 Views
jimmychan
NXP TechSupport
NXP TechSupport
0 Kudos
Reply

736 Views
chenhongsheng
Contributor I

I meet the same problem but I couldn't open the website that you given, could you give the newer again? Thank you very much!

0 Kudos
Reply

715 Views
jimmychan
NXP TechSupport
NXP TechSupport
0 Kudos
Reply