QM2150平台 配置SPI死机

项目场景:

由于在该平台上需要调试一个spi设备,但是在调试过程发现:一旦在spi总线下挂载设备节点就会出现死机。


问题描述:

首先我们打开spi-log:
kernel/msm-4.9/drivers/spi/spi_qsd.c

@@ -47,6 +47,15 @@

 #define SPI_MAX_BYTES_PER_WORD                 (4)

+#if 1
+#define DEBUG
+
+#undef dev_dbg
+#define dev_dbg dev_err
+#undef pr_debug
+#define pr_debug pr_err
+#endif
+
 static int msm_spi_pm_resume_runtime(struct device *device);
 static int msm_spi_pm_suspend_runtime(struct device *device);

发现log死在4s左右

[    4.419623] qcrypto 720000.qcrypto: qcrypto-rfc4309-aes-ccm
[    4.425892] qcom_ice_get_device_tree_data: No vdd-hba-supply regulator, assuming not needed---正常加载的也有此log,不是问题原因
[    4.430015] ICE IRQ = 93
[    4.439629] SCSI Media Changer driver v0.25
[    4.442651] spi_qsd 7af7000.spi: DT entry ret:0 name:spi-max-frequency val:50000000
[    4.445236] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,infinite-mode val:0
[    4.452741] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,master-id val:84
[    4.459904] spi_qsd 7af7000.spi: DT entry ret:-22 name:qcom,bus-width val:0
[    4.466700] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,ver-reg-exists val:1
[    4.473564] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,use-bam val:1
[    4.480844] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,use-pinctrl val:1
[    4.487334] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,bam-consumer-pipe-index val:8
[    4.494312] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,bam-producer-pipe-index val:9
[    4.502291] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-clk val:0
[    4.510280] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-miso val:0
[    4.517196] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-mosi val:0
[    4.523989] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-cs0 val:0
[    4.530852] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-cs1 val:0
[    4.537682] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-cs2 val:0
[    4.544486] spi_qsd 7af7000.spi: DT entry ret:-2 name:qcom,gpio-cs3 val:0
[    4.551302] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,rt-priority val:256
[    4.557995] spi_qsd 7af7000.spi: DT entry ret:0 name:qcom,shared val:0
[    4.565838] spi_qsd 7af7000.spi: pm_runtime: resuming...

Format: Log Type - Time(microsec) - Message - Optional Info

msm8917.dtsi

spi_7: spi@7af7000 { // BLSP2 QUP2 /
		compatible = "qcom,spi-qup-v2";
		#address-cells = <1>;
		#size-cells = <0>;
		reg-names = "spi_physical", "spi_bam_physical";
		reg = <0x7af7000 0x600>,
				<0x7ac4000 0x1d000>;
		interrupt-names = "spi_irq", "spi_bam_irq";
		interrupts = <0 301 0>, <0 239 0>;
		spi-max-frequency = <19200000>;
		pinctrl-names = "spi_default", "spi_sleep";
		pinctrl-0 = <&spi7_default &spi7_cs0_active>;
		pinctrl-1 = <&spi7_sleep &spi7_cs0_sleep>;
		clocks = <&clock_gcc clk_gcc_blsp2_ahb_clk>,
				<&clock_gcc clk_gcc_blsp2_qup3_spi_apps_clk>;
		clock-names = "iface_clk", "core_clk";
		qcom,infinite-mode = <0>;
		qcom,use-bam;
		qcom,use-pinctrl;
		qcom,ver-reg-exists;
		qcom,bam-consumer-pipe-index = <8>;
		qcom,bam-producer-pipe-index = <9>;
		qcom,master-id = <84>;
		status = "okay";
		
		ncx@0 {
			compatible = "ncx,pn512";
			reg = <0>;
			spi-max-frequency = <10000000>;
			interrupt-parent = <&tlmm>;
			interrupts = <128 0x4>;
			regulator-name = "smb1360_otg_vreg";
			ncx,rstpd-gpio = <&tlmm 98 0>;
			ncx,int-gpio = <&tlmm 99 0x4>;
	};

		
};

msm8917-pinctrl.dtsi

spi7 {
			spi7_default: spi7_default {
			/* active state */
				mux {
					/* MOSI, MISO, CLK */
					pins = "gpio85", "gpio86", "gpio88";
					function = "blsp_spi7";
					};
	
				config {
					pins = "gpio85", "gpio86", "gpio88";
					drive-strength = <12>; /* 12 MA */
					bias-disable = <0>; /* No PULL */
					};
			};
	
			spi7_sleep: spi7_sleep {
				/* suspended state */
				mux {
					/* MOSI, MISO, CLK */
					pins = "gpio85", "gpio86", "gpio88";
					function = "gpio";
					};
	
				config {
					pins = "gpio85", "gpio86", "gpio88";
					drive-strength = <2>; /* 2 MA */
					bias-pull-down; /* PULL Down */
					};
			};
	
			spi7_cs0_active: cs0_active {
				/* CS */
				mux {
					pins = "gpio87";
					function = "blsp_spi7";
					};
	
				config {
					pins = "gpio87";
					drive-strength = <2>;
					bias-disable = <0>;
					};
			};
	
			spi7_cs0_sleep: cs0_sleep {
				/* CS */
					mux {
					pins = "gpio87";
					function = "gpio";
					};
	
				config {
					pins = "gpio87";
					drive-strength = <2>;
					bias-disable = <0>;
				};
			};
	};

ncx这个节点挂在spi3下不会死机,单添加spi7总线不会死机,挂在spi7下4s左右死机。对照log发现spi3 clk比spi7低,改低spi7-clk还是死机。


原因分析:

1.首先我们检查spi总线的配置。 我们发现如果单纯配置spi总线不会死机。 spi3下挂载设备节点不会死机,spi7下挂载会死。 总线配置没有问题。

在这里插入图片描述
2.擦掉NON-HOLS.bin 排除ADSP和modem占用:
adsp_proc/core/buses/api/spi/SpiDriver.h
这里数量限制也会导致死机,通过擦modem排除:

在这里插入图片描述
modem占用这里就不说了。
可以检查下这些个文件,不过走8917还是8937需要你确认下:
adsp_proc/core/systemdrivers/tlmm/config/msm8937/PlatformIO_QRD.xml
modem_proc/core/systemdrivers/tlmm/config/msm8937/PlatformIO_QRD.xml
modem_proc/core/systemdrivers/tlmm/config/msm8937/PlatformIO_QRD_QM215.xml

3.修改TZ:
trustzone_images/core/buses/qup_accesscontrol/bear/config/QUPAC_8937_Access.xml
将SPI7 改为AC_HOLS,没有作用。

4,解析dump:
还是死在TZ,此时将trustzone_images/core/buses/qup_accesscontrol/bear/config/目录下的所有xml的spi7(GPIO85 86 87 88)都改为AC_HOLS,这个时候不死机了。
在这里插入图片描述


解决方案:

最后发现是因为之前拷贝项目的时候,用的是8937.xml,而实际我们走的是8917.xml,修改脚本,将默认走位8917.xml并修改即可。之前不知道谁搞的,被坑了一波。 trustzone_images/build/ms/fg_build_qm215.sh

@@ -35,6 +35,10 @@ if [ -f "../../core/buses/qup_accesscontrol/bear/config/QUPAC_8937_Access_$1.xml
     cp ../../core/buses/qup_accesscontrol/bear/config/QUPAC_8937_Access_$1.xml ../../core/buses/qup_accesscontrol/bear/config/QUPAC_8937_Access.xml
 fi

+git checkout ../../core/buses/qup_accesscontrol/bear/config/QUPAC_8917_Access.xml
+if [ "$1" = "PROJECT" ];then
+    cp ../../core/buses/qup_accesscontrol/bear/config/QUPAC_8917_Access_$1.xml ../../core/buses/qup_accesscontrol/bear/config/QUPAC_8917_Access.xml
+fi

trustzone_images/core/buses/qup_accesscontrol/bear/config/QUPAC_8917_Access.xml

  <device id=BLSP_QUP_7_DEV_ACCESS>
      <props name="CHIP_BUS_INDEX"      type=DALPROP_ATTR_TYPE_UINT32>     BLSP_QUP_7                </props>
      <props name="BUS_PROTOCOL"        type=DALPROP_ATTR_TYPE_UINT32>     PROTOCOL_SPI              </props>
      <props name="IS_GPIO_PROTECTED"   type=DALPROP_ATTR_TYPE_UINT32>     0                         </props>
      <props name="GPIO_NUMBERS"        type=DALPROP_ATTR_TYPE_BYTE_SEQ>   85, 86, 87, 88, end       </props>
      <props name="GPIO_RG_INDEX"       type=DALPROP_ATTR_TYPE_BYTE_SEQ>   end                       </props>
      <props name="SUBSYSTEM_ID"        type=DALPROP_ATTR_TYPE_UINT32>     AC_ADSP_Q6_ELF(改成AC_HOLS,正常AC_NONE也是不会死机的-可以给AP+BP使用)                  </props>
      <props name="IS_PERSISTENT"       type=DALPROP_ATTR_TYPE_UINT32>     0                         </props>
      <props name="CORE_RG_INDEX"       type=DALPROP_ATTR_TYPE_UINT32>     11                        </props>
   </device>

DEBUG:

后续又新发现一个问题,如下只有在spi设备调通后才能验证:
第一次开机后的情况spi被占用:
qcm2150:/ # /system/bin/r 0x01055000 //MOSI GPIO85 管脚功能被设置为 GPIO 功能
01055000: 00000201
qcm2150:/ # /system/bin/r 0x01056000 //MISO GPIO86 管脚功能被设置为 GPIO 功能
01056000: 00000201
qcm2150:/ # /system/bin/r 0x01057000 //CS GPIO87
01057000: 00000008
qcm2150:/ # /system/bin/r 0x01058000 //CLK GPIO88
01058000: 00000148
休眠唤醒一次后的情况正常:
qcm2150:/ # /system/bin/r 0x01055000 //MOSI GPIO85
01055000: 00000348
qcm2150:/ # /system/bin/r 0x01056000 //MISO GPIO86
01056000: 00000348
qcm2150:/ # /system/bin/r 0x01057000 //CS GPIO87
01057000: 00000008
qcm2150:/ # /system/bin/r 0x01058000 //CLK GPIO88
01058000: 00000148

参考:
擦掉modem是正常的,那么要么是adsp这边的sensor占用,要么是BP侧的modem占用。
https://www.wangt.cc/2021/01/%E9%AB%98%E9%80%9A%E5%B9%B3%E5%8F%B0%E6%9F%90%E9%A1%B9%E7%9B%AEuart%E4%B8%B2%E5%8F%A3%E4%B8%8D%E8%83%BD%E6%AD%A3%E5%B8%B8%E5%B7%A5%E4%BD%9C%E7%9A%84%E6%95%85%E9%9A%9C%E8%A7%A3%E5%86%B3/
首先分析是不是sensor占用,删掉
/vendor/etc/sensors/sensor_def_qcomdev.conf
/mnt/vendor/persist/sensors/sns.reg
后正常。那么是sensor占用,去掉sensor_def_qcomdev.conf所有的spi,并将版本号从1改为2;push进去没有生效。

检查BP侧modem,如下修改后正常,提交代码
modem_proc/core/systemdrivers/tlmm/config/msm8937/PlatformIO_QRD_QM215.xml

在这里插入图片描述

其中/system/bin/r是高通提供的一个工具,用于读取gpio寄存器。如果想使用这个工具,必须在kernel defconfig文件中设置宏CONFIG_DEVMEM=y CONFIG_DEVKMEM=y ,重新编译烧写内核。
使用方法如下:
/system/bin/r register_gpio

mmm system/core/toolbox/生成r

其实modem 那里注释掉没用,根本原因还是sensor占用,别人调试时没加宏控影响到该项目:
adsp_proc/Sensors/smgr/src/sns_smgr_hw.c



SMGR_STATIC void sns_smgr_spi_gpio_config(bool is_sleep)
{
  DALResult result = DAL_SUCCESS;
  
  if ( sns_smgr_hw.gpio_handle == NULL )
  {
    SNS_SMGR_PRINTF1(ERROR, "gpio_config - sleep=%u", is_sleep);
    result = DAL_DeviceAttach(DALDEVICEID_TLMM, &sns_smgr_hw.gpio_handle);
  }
  
  if ( result == DAL_SUCCESS && sns_smgr_hw.gpio_handle != NULL )
  {
    DALGpioSignalType gpio_config;
    DALGpioPullType pull = is_sleep ? DAL_GPIO_PULL_DOWN : DAL_GPIO_PULL_UP;

    if(is_sleep)
	  {
#if defined(ODM_PROJECT_当前项目)	
        //22	SPI_CS_N; fun select : 0, 	General Purpose;1, blsp_spi_cs_n[6]
	    gpio_config = DAL_GPIO_CFG(22, 0, 
                               DAL_GPIO_OUTPUT, pull, DAL_GPIO_2MA);
        DalTlmm_ConfigGpio(sns_smgr_hw.gpio_handle, gpio_config, DAL_TLMM_GPIO_ENABLE);
	
        //23 SPI_CLK; fun select : 0, 	General Purpose;1, blsp_spi_clk[6]
	    gpio_config = DAL_GPIO_CFG(23, 0, 
                               DAL_GPIO_OUTPUT, pull, DAL_GPIO_2MA);
#else					   
	            //22	SPI_CS_N; fun select : 0, 	General Purpose;1, blsp_spi_cs_n[6]
	    gpio_config = DAL_GPIO_CFG(85, 0, 
                               DAL_GPIO_OUTPUT, pull, DAL_GPIO_2MA);
        DalTlmm_ConfigGpio(sns_smgr_hw.gpio_handle, gpio_config, DAL_TLMM_GPIO_ENABLE);
	
        //23 SPI_CLK; fun select : 0, 	General Purpose;1, blsp_spi_clk[6]
	    gpio_config = DAL_GPIO_CFG(86, 0, 
                               DAL_GPIO_OUTPUT, pull, DAL_GPIO_2MA);
							   
#endif							   
        DalTlmm_ConfigGpio(sns_smgr_hw.gpio_handle, gpio_config, DAL_TLMM_GPIO_ENABLE);
	
#if defined(BRINGUP_8953)
       //47	SPI_CS2_N; fun select : 0, 	General Purpose;1, blsp6_spi_cs2_n
	    gpio_config = DAL_GPIO_CFG(47, 0, 
                               DAL_GPIO_OUTPUT, pull, DAL_GPIO_2MA);
        DalTlmm_ConfigGpio(sns_smgr_hw.gpio_handle, gpio_config, DAL_TLMM_GPIO_ENABLE);


#endif

版权声明:本文为CSDN博主「墨染天姬」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40970718/article/details/121468316

生成海报
点赞 0

墨染天姬

我还没有学会写个人说明!

暂无评论

发表评论

相关推荐

[Exynos4412][iTOP4412]LCD背光驱动(PWM)

0 前言 不同于《[Exynos4412][Tiny4412]LCD背光驱动(1wire)》,iTOP4412的LCD背光亮度通过PWM来调节,本文基于linux-3.0.15分析iTOP4412塑胶壳7寸LCD的背光驱动。 注:由