uboot - pinctrl - FPGA回片前测试阶段 - 设置GPIO引脚复用失败

本文主要是介绍uboot - pinctrl - FPGA回片前测试阶段 - 设置GPIO引脚复用失败,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

问题描述

pinctrl设置引脚复用失败,没有调用到controller中的set_groups_function函数。

问题定位

  1. pinctrl如何注册dm节点
  2. 如何进行设备树中各个设备节点下的复用配置
  3. 为什么没调用到控制器实现的set_groups_function函数
&gpio0 {status = "okay";pinctrl-names = "default";pinctrl-0 = <&gpioa15_pinctrl>;
};&pinctrl {gpioa15 {gpioa15_pinctrl: gpioa15_grp {ts,pins = <PB7>;mux,val = <5>;function = "gpioa15";groups = "gpioa15_grp";};};
};

pinctrl如何注册dm节点

调用过程:

[uboot/drivers/core/device.c]
int device_probe(struct udevice *dev)/* Process pinctrl for everything except the root device, and* continue regardless of the result of pinctrl. Don't process pinctrl* settings for pinctrl devices since the device may not yet be* probed. * */pinctrl_select_state(dev, "default");pinctrl_select_state_simple(dev);/** Try full-implemented pinctrl first.* If it fails or is not implemented, try simple one.*/if (pinctrl_select_state_full(dev, statename))return pinctrl_select_state_simple(dev);UCLASS_DRIVER(pinctrl) = {.id = UCLASS_PINCTRL,.post_bind = pinctrl_post_bind,.flags = DM_UC_FLAG_SEQ_ALIAS,.name = "pinctrl",ret = uclass_pre_probe_device(dev);ret = uclass_post_probe_device(dev);uc_drv->post_probepinctrl_post_bindreturn pinconfig_post_bind(dev);pinctrl_select_state(dev, "default");pinctrl_select_state_full(dev, statename)ret = pinctrl_config_one(config);ops = pinctrl_get_ops(pctldev);/* this ops was set by controller */return ops->set_state(pctldev, config);};

上面的调用过程是通过加log找出来的,log如下:

__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
initr_nand bypass                                                                                                                   
MMC:   __file:drivers/core/device.c __func:device_probe __line:431                                                                  
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
dev 0x00000000bf741ec0, size 0xa0, name mmc@f0512000, ofnode 10c4, mmc@f0512000                                                     
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
dev 0x00000000bf742260, size 0xa0, name mmc@f0513000, ofnode 1158, mmc@f0513000                                                     
__file:drivers/core/device.c __func:device_probe __line:431        

看着就是在pinctrl_select_state_full 函数里出了问题:
每次进入pinctrl_select_state_full 函数只能打印到68行,下面的打印出不来,没有调到pinctrl_config_one,所以设备树里注册的gpioa15_pinctrl没有被配置。

/*** pinctrl_select_state_full() - full implementation of pinctrl_select_state** @dev: peripheral device* @statename: state name, like "default"* @return: 0 on success, or negative error code on failure*/
static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
{char propname[32]; /* long enough */const fdt32_t *list;uint32_t phandle;struct udevice *config;int state, size, i, ret;printf("__file:%s __func:%s __line:%d\n", __FILE__, __func__, __LINE__);state = dev_read_stringlist_search(dev, "pinctrl-names", statename);if (state < 0) {char *end;/** If statename is not found in "pinctrl-names",* assume statename is just the integer state ID.*/state = simple_strtoul(statename, &end, 10);if (*end)return -EINVAL;}
printf("__file:%s __func:%s __line:%d\n", __FILE__, __func__, __LINE__);snprintf(propname, sizeof(propname), "pinctrl-%d", state);list = dev_read_prop(dev, propname, &size);if (!list)return -EINVAL;size /= sizeof(*list);printf("__file:%s __func:%s __line:%d size:%d\n", __FILE__, __func__, __LINE__, size);for (i = 0; i < size; i++) {phandle = fdt32_to_cpu(*list++);ret = uclass_get_device_by_phandle_id(UCLASS_PINCONFIG, phandle,&config);if (ret) {dev_warn(dev, "%s: uclass_get_device_by_phandle_id: err=%d\n",__func__, ret);continue;}
printf("__file:%s __func:%s __line:%d\n", __FILE__, __func__, __LINE__);ret = pinctrl_config_one(config);if (ret) {dev_warn(dev, "%s: pinctrl_config_one: err=%d\n",__func__, ret);continue;}}return 0;
}

初步怀疑是69行这里state = dev_read_stringlist_search(dev, "pinctrl-names", statename); 返回的state是个非法值。打印出来看看:
果然都是非法值,-61!!!

pinctrl_probe                                                                                                                       
reg_base:f0389000                                                                                                                   
npins  : 78                                                                                                                         
nfuncs : 1                                                                                                                          
ngroups: 1                                                                                                                          func:gpioa15, ngroups = 1                                                                                                           
grp_index = 0                                                                                                                       
group[0] name gpioa15_grp                                                                                                           
mux_val: 0x5                                                                                                                        
npins: 1                                                                                                                            
15                                                                                                                                  
ts_pinctrl_parse_dt done                                                                                                            
ts pinctrl initialized                                                                                                              
__file:drivers/core/device.c __func:device_probe __line:523                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70  state:-61                                       
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70  state:-61                                       
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
initr_nand bypass                                                                                                                   
MMC:   __file:drivers/core/device.c __func:device_probe __line:431                                                                  
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70  state:-61                                       
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
dev 0x00000000bf741ec0, size 0xa0, name mmc@f0512000, ofnode 10c4, mmc@f0512000                                                     
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:68                                                  
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70  state:-61                                       
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                          

uboot的异常宏号码列表
uboot/include/linux/errno.h

#define	EBFONT		59	/* Bad font file format */
#define	ENOSTR		60	/* Device not a stream */
#define	ENODATA		61	/* No data available */

dev_read_stringlist_search的定义:

static inline int dev_read_stringlist_search(const struct udevice *dev,const char *propname,const char *string)
{return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
}int ofnode_stringlist_search(ofnode node, const char *property,const char *string)
{if (ofnode_is_np(node)) {//maybe bug here?return of_property_match_string(ofnode_to_np(node),property, string);} else {int ret;ret = fdt_stringlist_search(gd->fdt_blob,ofnode_to_offset(node), property,string);if (ret == -FDT_ERR_NOTFOUND)//maybe bug here?return -ENODATA;else if (ret < 0)return -EINVAL;return ret;}
}

上面注释中有两个位置可能返回了ENODATA,此处已经开始怀疑是不是设备树描述地有问题了。回头看了一下dts中,pinctrl-names属性是存在的。。。
但是dts虽然有,编译出dtb到后不一定还是存在的,这里通过请教前辈,有哪些fdt的调试手段,前辈推荐了fdt命令,在uboot中可以用于显示设备树信息:
如何使用:

  1. 通过printenv,找到fdtcontroladdr属性的值,此为fdt所在地址
  2. 运行fdt fdtcontroladdr
  3. 运行fdt list
    找到gpio和pinctrl节点所在:
    在这里插入图片描述
    可以看到gpio及其pinctrl配置,实际已经配置进去了。
    从这里开始,我就觉得不对劲了,只能开始请神了,所以我找了原先的pinctrl mantainer。原先的mantainer说:
    uboot中GPIO节点的pinctrl配置,是必须在gpio命令运行完毕之后,才会进行pinctrl的配置的!

恍然大悟,之前没有注意过这个特性,我运行了gpio set 15 1后:

=> gpio set 15 1                                                                                                                    
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
dev->name:gpio@f0390000                                                                                                             
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70                                                  
fdt_stringlist_search len:8                                                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:72  state:0 name:default                            
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:83                                                  
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:90 size:1                                           
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
dev->name:gpioa15                                                                                                                   
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70                                                  
const fdt_stringlist_search == FDT_ERR_NOTFOUND                                                                                     
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:72  state:-61 name:default                          
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
dev->name:gpioa15_grp                                                                                                               
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70                                                  
const fdt_stringlist_search == FDT_ERR_NOTFOUND                                                                                     
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:72  state:-61 name:default                          
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:100                                                 
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:32                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:34                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:36                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:38                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:44                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:36                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:38                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:44                                                         
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_config_one __line:50                                                         
__func:pinctrl_generic_set_state line:340                                                                                           
__func:pinctrl_generic_set_state_subnode line:301                                                                                   
>>>get group[0] gpioa15_grp                                                                                                         
__func:pinctrl_generic_set_state_subnode line:326                                                                                   
__func:pinctrl_generic_set_state_one line:250                                                                                       
__func:pinctrl_generic_set_state_one line:261                                                                                       
__func:pinmux_enable_setting line:119                                                                                               
set_mux, function:0, group:0                                                                                                        
group name:gpioa15_grp, func name:gpioa15 mux_val:5                                                                                 
pin15, wr 0x00000000f038912c, val 0x50000000                                                                                        
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
failed to get gpio clock                                                                                                            
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:460                                                                         
__file:drivers/core/device.c __func:device_probe __line:476                                                                         
__file:drivers/core/device.c __func:device_probe __line:479                                                                         
dev->name:pa                                                                                                                        
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:70                                                  
const fdt_stringlist_search == FDT_ERR_NOTFOUND                                                                                     
__file:drivers/pinctrl/pinctrl-uclass.c __func:pinctrl_select_state_full __line:72  state:-61 name:default                          
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:482                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
gpio: pin 15 (gpio 15) value is 1                                                                                                   
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431                                                                         
__file:drivers/core/device.c __func:device_probe __line:431  

可以看到name:default已经找到了,再使用devmem查看pinctrl对应的B组寄存器值:

=> md 0xf038912c                                                                                                                    
f038912c: 50000000 00000000 00000000 00000000    ...P............                                                                   
f038913c: 00000000 00000000 00000000 00000000    ................                                                                   
f038914c: 00000000 00000000 00000000 00000000    ................                                                                   
f038915c: 00000000 00000000 00000000 00000000    ................                                                                   
f038916c: 00000000 00000000 00000000 00000000    ................                                                                   
f038917c: 00000000 00000000 00000000 00000000    ................                                                                   
f038918c: 00000000 00000000 00000000 00000000    ................                                                                   
f038919c: 00000000 00000000 00000000 00000000    ................                                                                   
f03891ac: 00000000 00000000 00000000 00000000    ................                                                                   
f03891bc: 00000000 00000000 00000000 00000000    ................                                                                   
f03891cc: 00000000 00000000 00000000 00000000    ................                                                                   
f03891dc: 00000000 00000000 00000000 00000000    ................                                                                   
f03891ec: 00000000 00000000 00000000 00000000    ................                                                                   
f03891fc: 00000000 000000ff 00000000 00000000    ................                                                                   
f038920c: 00000000 000000ff 00000000 00000000    ................                                                                   
f038921c: 00000000 00000000 00000000 00000000    ................                                                                   
=>   

func5配置成功。

TODO:gpio中如何调用到pinctrl配置接口

推荐链接:
https://blog.csdn.net/ZHONGCAI0901/article/details/117986327

这篇关于uboot - pinctrl - FPGA回片前测试阶段 - 设置GPIO引脚复用失败的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/831997

相关文章

如何设置vim永久显示行号

《如何设置vim永久显示行号》在Linux环境下,vim默认不显示行号,这在程序编译出错时定位错误语句非常不便,通过修改vim配置文件vimrc,可以在每次打开vim时永久显示行号... 目录设置vim永久显示行号1.临时显示行号2.永www.chinasem.cn久显示行号总结设置vim永久显示行号在li

Linux:alias如何设置永久生效

《Linux:alias如何设置永久生效》在Linux中设置别名永久生效的步骤包括:在/root/.bashrc文件中配置别名,保存并退出,然后使用source命令(或点命令)使配置立即生效,这样,别... 目录linux:alias设置永久生效步骤保存退出后功能总结Linux:alias设置永久生效步骤

Spring MVC如何设置响应

《SpringMVC如何设置响应》本文介绍了如何在Spring框架中设置响应,并通过不同的注解返回静态页面、HTML片段和JSON数据,此外,还讲解了如何设置响应的状态码和Header... 目录1. 返回静态页面1.1 Spring 默认扫描路径1.2 @RestController2. 返回 html2

四种简单方法 轻松进入电脑主板 BIOS 或 UEFI 固件设置

《四种简单方法轻松进入电脑主板BIOS或UEFI固件设置》设置BIOS/UEFI是计算机维护和管理中的一项重要任务,它允许用户配置计算机的启动选项、硬件设置和其他关键参数,该怎么进入呢?下面... 随着计算机技术的发展,大多数主流 PC 和笔记本已经从传统 BIOS 转向了 UEFI 固件。很多时候,我们也

Xshell远程连接失败以及解决方案

《Xshell远程连接失败以及解决方案》本文介绍了在Windows11家庭版和CentOS系统中解决Xshell无法连接远程服务器问题的步骤,在Windows11家庭版中,需要通过设置添加SSH功能并... 目录一.问题描述二.原因分析及解决办法2.1添加ssh功能2.2 在Windows中开启ssh服务2

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re

Linux中chmod权限设置方式

《Linux中chmod权限设置方式》本文介绍了Linux系统中文件和目录权限的设置方法,包括chmod、chown和chgrp命令的使用,以及权限模式和符号模式的详细说明,通过这些命令,用户可以灵活... 目录设置基本权限命令:chmod1、权限介绍2、chmod命令常见用法和示例3、文件权限详解4、ch

SpringBoot项目引入token设置方式

《SpringBoot项目引入token设置方式》本文详细介绍了JWT(JSONWebToken)的基本概念、结构、应用场景以及工作原理,通过动手实践,展示了如何在SpringBoot项目中实现JWT... 目录一. 先了解熟悉JWT(jsON Web Token)1. JSON Web Token是什么鬼

使用Spring Cache时设置缓存键的注意事项详解

《使用SpringCache时设置缓存键的注意事项详解》在现代的Web应用中,缓存是提高系统性能和响应速度的重要手段之一,Spring框架提供了强大的缓存支持,通过​​@Cacheable​​、​​... 目录引言1. 缓存键的基本概念2. 默认缓存键生成器3. 自定义缓存键3.1 使用​​@Cacheab

java如何调用kettle设置变量和参数

《java如何调用kettle设置变量和参数》文章简要介绍了如何在Java中调用Kettle,并重点讨论了变量和参数的区别,以及在Java代码中如何正确设置和使用这些变量,避免覆盖Kettle中已设置... 目录Java调用kettle设置变量和参数java代码中变量会覆盖kettle里面设置的变量总结ja