AGX Xavier GPIO debug

  • AGX Xavier GPIO Resources:

dts:
tegra194-p2888-0001-p2822-0000.dts
tegra194-p2888-0001-p2822-0000-common.dtsi
tegra194-p2822-0000-a00.dtsi
tegra194-p2888-0000-a00.dtsi
cfg:
pinmux:
galen\bct\pinmux\tegra19x-mb1-pinmux-p2888-0000-a00-p2822-0000-a00.cfg
IO定义:MAIN/AON
t19x/common/bct/gpio-intmap/tegra194-mb1-bct-gpio-int-to-all-int0.cfg:gpio-intmap.port.B.pin.0 = 0; # GPIO B0 to INT0
文档:
Jetson_AGX_Devkit_Pinmux_Configuration_Template.xlsm
Jetson_AGX_Xavier_Pin_and_Function_Names_Guide_Application_Note.pdf


  • 案例一、通过普通GPIO检测风扇运行状态

要求:
两路风扇状态检测
1、两个风扇任何一个未接入,要求红灯亮起;
2、两个风扇任何一个运行过程中出现停转(比如故障,拔出任意一个风扇),要求红灯亮起;
3、两个风扇任何一个出现停转(比如拔出、故障),要求红灯亮起;
4、两个风扇同时正常运行,风扇灯不亮
5、A501 硬件风扇状态检测Pin为(K52,K51),风扇故障LED指示灯控制GPIO为L15/GPIO14

思路:
1、选型的风扇需带 “停转报警” 功能,即风扇停止转动时会有一个Pin输出一个高电平(如3.3V),接入到载板普通GPIO,如K52
2、将两个风扇停转状态Pin 接入到Xavier 普通GPIO(K52-GPIO3_PM.00-No.GPIO384/K51-GPIO3_PM.01-No.GPIO385),当出现停转后此GPIO为低电平,软件检测到低后,触发GPIO-KEY (如KEY_F24)上报APP,同时将FAN LED 点亮
3、Kernel Driver调用LED GPIO控制FAN LED(L15-GPIO3_PT.04-No.GPIO444) 点亮(Hi)或点灭(Lo)
4、 参考代码文件及内容如下

hardware\nvidia\platform\t19x\galen\kernel-dts\common\tegra194-p2822-0000-a00.dtsi      
>   (FAN Running State KEY 上报) 内容如下:
/* CONFIG_TW_A501_FAN */
fan_state {
    label = "fan-state";
    gpios = <&tegra_main_gpio TEGRA  194_MAIN_GPIO(M, 0) GPIO_ACTIVE_LOW>;
    linux,code = ;
    gpio-key,wakeup;
};

fan2_state {
    label = "fan2-state";
    gpios = <&tegra_main_gpio TEGRA194_MAIN_GPIO(M, 1) GPIO_ACTIVE_LOW>;
    linux,code = ;
    gpio-key,wakeup;
};
hardware\nvidia\platform\t19x\common\kernel-dts\t19x-common-platforms\tegra194-pwm-fan.dtsi  
>> 添加(FAN State & LED GPIO)如下:
/* TW_A501 FAN LEDs */
fan_led_gpio = <&tegra_main_gpio TEGRA194_MAIN_GPIO(T, 4) GPIO_ACTIVE_LOW>; 
fan_state_gpio = <&tegra_main_gpio TEGRA194_MAIN_GPIO(M, 0) GPIO_ACTIVE_HIGH>; /*Pin--K52--GPIO3PM.00*/
fan2_state_gpio = <&tegra_main_gpio TEGRA194_MAIN_GPIO(M, 1) GPIO_ACTIVE_HIGH>;/*Pin--K51--GPIO3PM.01*/

$ vi kernel\kernel-4.9\drivers\thermal\pwm_fan.c (添加 函数控制LED 状态GPIO)
int fan_running_state(int state)
{
    //Stop running is Low_0, Start running is High 1
    ret = gpio_get_value(fan_dev_data_static->fan_state_gpio);
    printk("%s:fan_run:%d---fan_led=%d\n",
            __func__, ret, fan_dev_data_static->fan_led_gpio);
    if(ret == 0x00) {
        fan_stop_state = true;
        gpio_set_value(fan_dev_data_static->fan_led_gpio, state); //led on
    }
    else if(ret == 0x01) {
        if(fan_stop_state == true) {
            fan_stop_state = true;
            gpio_set_value(fan_dev_data_static->fan_led_gpio, 0x01); //led off
        }
    }
}
EXPORT_SYMBOL(fan_running_state);
--------------------------------
$ vi kernel\kernel-4.9\drivers\input\keyboard\gpio_keys.c(添加按键响应信息)
static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
{ 
    if(button->code == 194 /*KEY_F24*/) {
        fan_running_state(0);
        printk("FAN Stop_KEY_F24: 0x%x \r\n", button->code);
    }
  }
AGX Xavier GPIO debug_第1张图片
image.png
image.png
image.png

案例二、GPIO 添加GPU 温度LED 指示灯

功能需求
当GPU 达到一定温度,必须亮起高温报警灯,以方便现场人员查看当前设备状态信息!
设计思路
1、通过GPIO 控制GPU温度LED灯(如B62-GPIO3-PBB.00-No.GPIO256)
2、采用轮询方式,定时查询GPU温度 (通过thermal_zone_device_update),当温度达到68°以上,控制LED亮起(Hi),当温度低于65°时,再将LED 灭掉(Lo)
快速验证方法
1、CPU 高负载(100% )运行方法:
$sudo apt-get install stress-ng
$stress-ng --cpu 8 --io 4 --vm 2 --vm-bytes 128M --fork 4
2、GPU 高负载(90%以上)运行方法:
$ cd VisionWorks-SFM-0.90-Samples/bin/aarch64/linux/release/
$ ./nvx_sample_sfm

参考资料:
Linux Thermal
Linux Thermal 是Linux 系统下温度控制相关的模块,主要用来控制系统运行过程中芯片产生的热量,使得芯片温度和设备外壳维持在一个安全的范围。
Thermal 的主要框架 :
要实现一个温度控制的需求,就需要包含获取温度的设备和控制温度的设备,以及一些使用温度控制设备的策略。
获取温度的设备:在Thermal框架中被抽象为Thermal Zone Device;
控制温度的设备:在Thermal框架中被抽象为Thermal Cooling Device;

Jetson 设备运行状态查询,如"频率"、"温度":
$sudo ./tegrastats
读取的设备状态信息位于:/sys/kernel/debug/bpmp/debug/soctherm/
设备状态对应的代码位于:kernel4.9/drivers/thermal/tegra/soctherm.c
NTC芯片TI TMP451,对应代码为 kernel\nvidia\drivers\misc\nct1008.c

Jetson Thermal设备节点信息查看:
/sys/firmware/devicetree/base/thermal-zones/
/sys/devices/bpmp_i2c/i2c-4/4-004c/
/sys/kernel/debug/bpmp/debug/soctherm/
/sys/devices/virtual/thermal/

错误一、(dmesg log)
[4.207065] nct1008_nct72 4-004c: Missing temp-alert-gpio prop
[4.213033] gpiod_set_value: invalid GPIO (errorpointer)
[4.216544] tegra_nvdisp_handle_pd_enable: Unpowergated Head0 pd
[4.216745] tegra_nvdisp_handle_pd_enable: Unpowergated Head1 pd
代码:
$bpmp_i2c {
temp_led_gpio = <&tegra_aon_gpio TEGRA194_AON_GPIO(BB, 0) GPIO_ACTIVE_LOW>;
解决:
修改nct1008.c 代码中的获取GPIO设备句柄的方法

错误二、
采用GPIO8 (即默认为CAN1_STB----can1_stb_pbb0)时,开机会自动亮起,查找根源时NVIDIA Xavier默认代码将此GPIO 配置为输入口导致此PIN为Tri State,当接LED时,LED则为亮起状态!
解决:
修改去掉此配置为Input,在tegra194-platforms-audio-pinmux.dtsi 进行配置

cooling_device0  cooling_device1  cooling_device2  cooling_device3   cooling_device4  cooling_device5  cooling_device6  cooling_device7  cooling_device8   
thermal_zone0-CPU thermal_zone1-GPU thermal_zone2  thermal_zone3 thermal_zone4    thermal_zone5    thermal_zone6    thermal_zone7  
CONFIG_TEGRA_SOCTHERM=y
CONFIG_TEGRA_AOTAG=y
CONFIG_TEGRA_TJ_THERMAL=y
CONFIG_TEGRA_CORE_CAPS=y
CONFIG_TEGRA_DFLL_CAPS=y
# CONFIG_QCOM_SPMI_TEMP_ALARM is not set
# CONFIG_GENERIC_ADC_THERMAL is not set
# CONFIG_USERSPACE_THERM_ALERT is not set
CONFIG_THERMAL_GOV_PID=y
CONFIG_TEGRA_THERMAL_THROTTLE=y

通用GPIO function 调试方法(DTS+设备节点文件)

设备节点查看:
$sudo cat /sys/kernel/debug/gpio (查看GPIO 状态)

$sudo cd /sys/class/gpio (Debug GPIO)

$root


echo 256 > export
echo in > gpio256/direction
cat gpio256/values

echo 256 > export
echo out > gpio256/direction
cat gpio2566/value

AGX Xavier A501 default GPIO state(2019-03-05)

root@jetson-0423718017025:/sys/class/gpio# cat /sys/kernel/debug/gpio 
gpiochip2: GPIOs 240-247, parent: platform/max77620-gpio, max77620-gpio, can sleep:
 gpio-246 (                    |gpio_default        ) out hi    
 gpio-247 (                    |gpio_default        ) out hi    

gpiochip1: GPIOs 248-287, parent: platform/c2f0000.gpio, tegra-gpio-aon:
 gpio-253 (                    |pex-refclk-sel-low  ) out lo    
 gpio-256 (                    |fan-state           ) in  hi    
 gpio-257 (                    |sysfs               ) in  lo    
 gpio-258 (                    |sysfs               ) in  lo    
 gpio-284 (                    |power-key           ) in  hi    

gpiochip0: GPIOs 288-511, parent: platform/2200000.gpio, tegra-gpio:
 gpio-288 (                    |vdd-1v8-sd          ) out lo    
 gpio-291 (                    |vdd-hdmi-5v0        ) out hi    
 gpio-336 (                    |force-recovery      ) in  hi    
 gpio-339 (                    |wifi-enable         ) out hi    
 gpio-341 (                    |eqos_phy_reset      ) out hi    
 gpio-343 (                    |cd                  ) in  hi    
 gpio-346 (                    |temp-alert          ) in  hi    
 gpio-378 (                    |pcie_wake           ) in  hi    
 gpio-386 (                    |hdmi2.0_hpd         ) in  lo    
 gpio-389 (                    |vdd_sys_en          ) out lo    
 gpio-390 (                    |reset_gpio          ) out lo    
 gpio-391 (                    |bt_ext_wake         ) out hi    
 gpio-392 (                    |avdd-cam-2v8        ) out lo    
 gpio-480 (                    |bt_host_wake        ) in  lo    
 gpio-489 (                    |vdd-5v-sata         ) out hi    

AGX Xavier default GPIO state(2019-03-05)

root@jetson-0423718017025:/sys/kernel/debug# cat gpio 
gpiochip2: GPIOs 240-247, parent: platform/max77620-gpio, max77620-gpio, can sleep:
 gpio-246 (                    |gpio_default        ) out hi    
 gpio-247 (                    |gpio_default        ) out hi    

gpiochip1: GPIOs 248-287, parent: platform/c2f0000.gpio, tegra-gpio-aon:
 gpio-253 (                    |pex-refclk-sel-low  ) out lo    
 gpio-284 (                    |power-key           ) in  hi    

gpiochip0: GPIOs 288-511, parent: platform/2200000.gpio, tegra-gpio:
 gpio-288 (                    |vdd-1v8-sd          ) out hi    
 gpio-289 (                    |?                   ) out hi    
 gpio-291 (                    |vdd-hdmi-5v0        ) out hi    
 gpio-336 (                    |force-recovery      ) in  hi    
 gpio-339 (                    |wifi-enable         ) out hi    
 gpio-341 (                    |eqos_phy_reset      ) out hi    
 gpio-343 (                    |cd                  ) in  hi    
 gpio-346 (                    |temp-alert          ) in  hi    
 gpio-378 (                    |pcie_wake           ) in  hi    
 gpio-386 (                    |hdmi2.0_hpd         ) in  lo    
 gpio-389 (                    |vdd_sys_en          ) out lo    
 gpio-390 (                    |reset_gpio          ) out lo    
 gpio-391 (                    |bt_ext_wake         ) out hi    
 gpio-392 (                    |avdd-cam-2v8        ) out lo    
 gpio-480 (                    |bt_host_wake        ) in  lo    
 gpio-489 (                    |vdd-5v-sata         ) out hi    
 gpio-490 (                    |?                   ) out lo    

查看输入设备及节点信息: cat /proc/bus/input/devices

root@jetson-0423718017025:/sys/class/gpio# cat /proc/bus/input/devices 
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="tegra-hda-galen-t194 HDMI/DP,pcm=3"
P: Phys=ALSA
S: Sysfs=/devices/3510000.hda/sound/card0/input0
U: Uniq=
E: Enabled=0
H: Handlers=event0 
B: PROP=0
B: EV=21
B: SW=140

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="tegra-hda-galen-t194 HDMI/DP,pcm=7"
P: Phys=ALSA
S: Sysfs=/devices/3510000.hda/sound/card0/input1
U: Uniq=
E: Enabled=0
H: Handlers=event1 
B: PROP=0
B: EV=21
B: SW=140

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="tegra-hda-galen-t194 HDMI/DP,pcm=8"
P: Phys=ALSA
S: Sysfs=/devices/3510000.hda/sound/card0/input2
U: Uniq=
E: Enabled=0
H: Handlers=event2 
B: PROP=0
B: EV=21
B: SW=140

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="tegra-hda-galen-t194 HDMI/DP,pcm=9"
P: Phys=ALSA
S: Sysfs=/devices/3510000.hda/sound/card0/input3
U: Uniq=
E: Enabled=0
H: Handlers=event3 
B: PROP=0
B: EV=21
B: SW=140

I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="gpio-keys"
P: Phys=gpio-keys/input0
S: Sysfs=/devices/gpio-keys/input/input4
U: Uniq=
E: Enabled=0
H: Handlers=kbd event4 
B: PROP=0
B: EV=3
B: KEY=6 0 0 10000000000000 0

I: Bus=0003 Vendor=046d Product=c534 Version=0111
N: Name="Logitech USB Receiver"
P: Phys=usb-3610000.xhci-4/input0
S: Sysfs=/devices/3610000.xhci/usb1/1-4/1-4:1.0/0003:046D:C534.0001/input/input5
U: Uniq=
E: Enabled=0
H: Handlers=sysrq kbd leds event5 
B: PROP=0
B: EV=120013
B: KEY=1000000000007 ff800000000007ff febeffdfffefffff fffffffffffffffe
B: MSC=10
B: LED=1f

I: Bus=0003 Vendor=046d Product=c534 Version=0111
N: Name="Logitech USB Receiver"
P: Phys=usb-3610000.xhci-4/input1
S: Sysfs=/devices/3610000.xhci/usb1/1-4/1-4:1.1/0003:046D:C534.0002/input/input6
U: Uniq=
E: Enabled=0
H: Handlers=kbd mouse0 event6 
B: PROP=0
B: EV=1f
B: KEY=3007f 0 0 483ffff17aff32d bf54444600000000 ffff0001 130f938b17c000 677bfad941dfed 9ed68000004400 10000002
B: REL=1c3
B: ABS=100000000
B: MSC=10

你可能感兴趣的:(AGX Xavier GPIO debug)