From 2b91b4ac614888aaa2d67d88a2f3c9647e122463 Mon Sep 17 00:00:00 2001 From: leimingsheng Date: Thu, 13 Mar 2025 16:34:05 +0800 Subject: [PATCH] code sync --- tool/plugin/i2c_m6.sh | 13 ++- tool/plugin/nicsensor.sh | 28 ++++-- tool/plugin/platform_5280m7.sh | 14 +-- tool/plugin/platform_5688m7.sh | 161 +++++++++++++++++++++++++++++++++ tool/plugin/plugin_adc128.sh | 118 +++++++++++++++++++++++- tool/plugin/plugin_emc1413.sh | 58 +++++++++++- tool/plugin/plugin_ina3221.sh | 86 +++++++++++++++++- tool/plugin/plugin_tmp112.sh | 35 ++++++- tool/plugin/plugin_tmp468.sh | 77 +++++++++++++++- 9 files changed, 567 insertions(+), 23 deletions(-) create mode 100644 tool/plugin/platform_5688m7.sh diff --git a/tool/plugin/i2c_m6.sh b/tool/plugin/i2c_m6.sh index a489524..890ccc7 100644 --- a/tool/plugin/i2c_m6.sh +++ b/tool/plugin/i2c_m6.sh @@ -6,4 +6,15 @@ slave=$3 data=$4 rc=$5 -i2c_test -b $i2c_bus -s $slave -rc $rc -d $data | awk 'NR==3{for(i=1;i<=NF;i++){printf("0x%s ",$i)}}' \ No newline at end of file +path=`pwd` +fmt_print="${path}/format_print.sh" + +if [ $rc -eq 0 ];then + cmd=`i2c-test -b $i2c_bus -s $slave -w -d $data` +else + cmd=`i2c-test -b $i2c_bus -s $slave -m 1 -rc $rc -d $data | awk 'NR==2{for(i=1;i<=NF;i++){printf("0x%s ",$i)}}'` +fi + +$fmt_print "log" "Info" "[M6 i2c Command]: $cmd" +$cmd + diff --git a/tool/plugin/nicsensor.sh b/tool/plugin/nicsensor.sh index 226b3b8..df45386 100644 --- a/tool/plugin/nicsensor.sh +++ b/tool/plugin/nicsensor.sh @@ -1,6 +1,7 @@ #!/bin/sh -server_type="5280m7" +script_version="v2.0" +server_type="5688m7" server_platform="m7" slot_name=$1 @@ -18,8 +19,11 @@ i2c_script="${path}/i2c_${server_platform}.sh" fmt_print="${path}/format_print.sh" print_helper(){ - echo "Usage : ./nicsensor.sh [slot] [sensor] [i2c slave]" - echo "For Detect: ./nicsensor.sh detect [ocp/pcie]" + echo "======>>> nicsensor Scirpt Usage <<<======" + echo "Genenral Usage : ./nicsensor.sh [slot] [sensor] [i2c slave]" + echo "For Detect : ./nicsensor.sh detect [ocp/pcie]" + echo "Current Server : $server_type" + echo "Script Version : $script_version" } perform_detect(){ @@ -38,11 +42,6 @@ conf_pre_check(){ exit 0 fi - # init debug log - if [ -e "/tmp/nicsensor_debug.log" ];then - rm /tmp/nicsensor_debug.log - fi - if [ ! -e $fmt_print ];then echo "Missing file $fmt_print !!!" exit 1 @@ -62,6 +61,12 @@ conf_pre_check(){ $fmt_print "console" "Error" "$i2c_script not exist!" exit 1 fi + + res_date=`date +%Y-%m-%dT%H:%M:%S` + $fmt_print "log" "Info" "Start Time : $res_date" + $fmt_print "log" "Info" "Script Version : $script_version" + $fmt_print "log" "Info" "Server Type : $server_type" + $fmt_print "log" "Info" "Slot Name : $slot_name" } parse_slot_name(){ @@ -100,6 +105,11 @@ start_sensor_reading(){ # --------------------------------------------------------- # Start Execute Script # --------------------------------------------------------- +# init debug log +if [ -e "/tmp/nicsensor_debug.log" ];then + rm /tmp/nicsensor_debug.log +fi + # check if is detect option if [ "$1" = "detect" ];then perform_detect @@ -112,7 +122,7 @@ parse_slot_name i2c_bus=`connect_i2c` if [ $? -ne 0 ];then - $fmt_print "console" "Error" "An Error occured when build i2c connection with ${slot_name}" + $fmt_print "console" "Error" "An Error occured when build i2c connection with ${nic_type} ${slot_id}" exit 1 fi diff --git a/tool/plugin/platform_5280m7.sh b/tool/plugin/platform_5280m7.sh index e396fab..a933c59 100644 --- a/tool/plugin/platform_5280m7.sh +++ b/tool/plugin/platform_5280m7.sh @@ -28,7 +28,7 @@ record_i2c_status(){ set_i2c_config(){ # set pca9641 address && I2C BUS - if [ "${nic_type}" = "ocp" ];then + if [ "${nic_type}" == "ocp" ];then is_have_pca9641=0 pca9548_slave="0x70" i2c_bus=3 @@ -46,7 +46,7 @@ set_i2c_config(){ fi # set pca9548 switch channel - if [ "${nic_type}" = "ocp" ];then + if [ "${nic_type}" == "ocp" ];then if [ $slot_id -eq 0 ];then pca9548_channel="0x01" elif [ $slot_id -eq 1 ];then @@ -81,14 +81,14 @@ get_pca9641_control(){ # Request 9641 lock res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1` - $fmt_print "log" "Info" "[platform_5280m7]After request 9641 lock, The REG value is $res_lock" + $fmt_print "log" "Info" "[platform_5280m7] After request 9641 lock, The REG value is $res_lock" # Build 9641 Connection res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1` - $fmt_print "log" "Info" "[platform_5280m7]After Build 9641 connection, The REG value is $res_build" + $fmt_print "log" "Info" "[platform_5280m7] After Build 9641 connection, The REG value is $res_build" if [ "$res_build" != "0x87" ];then - $fmt_print "log" "Error" "Cannot establish connection with pca9641 !!!" + $fmt_print "console" "Error" "Cannot establish connection with pca9641 !!!" exit 1 fi } @@ -117,7 +117,7 @@ build_i2c_connect(){ # @Param4 pca9548 channel # @Param5 pcie slot number do_i2c_detect(){ - if [ $nic_type == "ocp" ];then + if [ "${nic_type}" == "ocp" ];then $fmt_print "log" "Info" "OCP slot $5 : bus$1 9548channel$4" else $fmt_print "log" "Info" "PCIe slot $5 : bus$1 9548channel$4" @@ -129,7 +129,7 @@ do_i2c_detect(){ detect_on_server(){ $fmt_print "console" "Info" "[platform_5280m7] Start i2c detect" - if [ "${nic_type}" = "ocp" ];then + if [ "${nic_type}" == "ocp" ];then i2c_bus=3 do_i2c_detect 3 0x70 0x01 0 0 do_i2c_detect 3 0x70 0x02 1 1 diff --git a/tool/plugin/platform_5688m7.sh b/tool/plugin/platform_5688m7.sh new file mode 100644 index 0000000..d3be9d9 --- /dev/null +++ b/tool/plugin/platform_5688m7.sh @@ -0,0 +1,161 @@ +#!/bin/sh + +action=$1 +nic_type=$2 +slot_id=$3 + +path=`pwd` +i2c_script="${path}/i2c_m7.sh" +fmt_print="${path}/format_print.sh" + +pca9548_slave="" +pca9641_slave="" +i2c_bus="" +pca9548_channel="" + +is_have_pca9641=0 + +record_i2c_status(){ + $fmt_print "log" "Info" "[platform_5688m7] Start record i2c configuration" + $fmt_print "log" "Info" "Nic Type: $nic_type" + $fmt_print "log" "Info" "Nic slot: $slot_id" + $fmt_print "log" "Info" "i2c bus: $i2c_bus" + $fmt_print "log" "Info" "is have pca9641: $is_have_pca9641" + $fmt_print "log" "Info" "pca9641 slave: $is_have_pca9641" + $fmt_print "log" "Info" "pca9548 slave: $pca9548_slave" + $fmt_print "log" "Info" "pca9548 channel: $pca9548_channel" +} + +set_i2c_config(){ + # set pca9641 address && I2C BUS + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic" + exit 1 + else + is_have_pca9641=1 + i2c_bus=12 + pca9641_slave="0x31" + if [ $slot_id -le 3 ];then + pca9548_slave="0x71" + else + pca9548_slave="0x72" + fi + fi + + # set pca9548 switch channel + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic" + exit 1 + else + if [ $slot_id -eq 0 ];then + pca9548_channel="0x01" + elif [ $slot_id -eq 1 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 2 ];then + pca9548_channel="0x04" + elif [ $slot_id -eq 3 ];then + pca9548_channel="0x08" + elif [ $slot_id -eq 4 ];then + pca9548_channel="0x01" + elif [ $slot_id -eq 5 ];then + pca9548_channel="0x02" + elif [ $slot_id -eq 6 ];then + pca9548_channel="0x04" + elif [ $slot_id -eq 7 ];then + pca9548_channel="0x08" + else + $fmt_print "console" "Warning" "Unspecified card slot!" + fi + fi + record_i2c_status +} + +get_pca9641_control(){ + $fmt_print "log" "Info" "[platform_5688m7] Start Get pca9641 control" + + # Request 9641 lock + res_lock=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x81 r1` + $fmt_print "log" "Info" "[platform_5688m7] After request 9641 lock, The REG value is $res_lock" + + # Build 9641 Connection + res_build=`i2ctransfer -y $i2c_bus w2@$pca9641_slave 0x01 0x85 r1` + $fmt_print "log" "Info" "[platform_5688m7] After Build 9641 connection, The REG value is $res_build" + + if [ "$res_build" != "0x87" ];then + $fmt_print "console" "Error" "Cannot establish connection with pca9641 !!!" + exit 1 + fi +} + +select_pca9548_channel(){ + $fmt_print "log" "Info" "[platform_5688m7] Start Switch PCA9548" + $i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0 +} + +build_i2c_connect(){ + $fmt_print "log" "Info" "[platform_5688m7] Start build i2c connect" + set_i2c_config + + if [ $is_have_pca9641 -eq 1 ];then + get_pca9641_control + fi + + select_pca9548_channel + echo "$i2c_bus" +} + +# switch pca9548 channels then do i2cdetect one times +# @Param1 i2c bus number +# @Param2 pca9548 slave address +# @Param3 pca9548 channel hex value +# @Param4 pca9548 channel +# @Param5 pcie slot number +do_i2c_detect(){ + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Info" "OCP slot $5 : bus$1 9548channel$4" + else + $fmt_print "console" "Info" "PCIe slot $5 : bus$1 9548channel$4" + fi + i2ctransfer -y $1 w1@$2 $3 + i2cdetect -y $1 +} + +detect_on_server(){ + $fmt_print "console" "Info" "[platform_5688m7] Start i2c detect" + + if [ "${nic_type}" == "ocp" ];then + $fmt_print "console" "Error" "[platform_5688m7] Unsupport OCP Nic I2C Detect" + else + i2c_bus=12 + pca9641_slave="0x31" + get_pca9641_control + + do_i2c_detect $i2c_bus 0x71 0x01 0 0 + do_i2c_detect $i2c_bus 0x71 0x02 1 1 + do_i2c_detect $i2c_bus 0x71 0x04 2 2 + do_i2c_detect $i2c_bus 0x71 0x08 3 3 + do_i2c_detect $i2c_bus 0x72 0x01 0 4 + do_i2c_detect $i2c_bus 0x72 0x02 1 5 + do_i2c_detect $i2c_bus 0x72 0x04 2 6 + do_i2c_detect $i2c_bus 0x72 0x08 3 7 + fi +} + +# --------------------------------------------------- +# Start Execute Script +# --------------------------------------------------- +case "${action}" in + "connect") + build_i2c_connect + ;; + "detect") + detect_on_server + ;; + *) + $fmt_print "console" "Error" "[platform_5688m7] Unspecified Operation : $action" + exit 1 + ;; +esac + +exit 0 + diff --git a/tool/plugin/plugin_adc128.sh b/tool/plugin/plugin_adc128.sh index 1b577ab..e6f5d8d 100644 --- a/tool/plugin/plugin_adc128.sh +++ b/tool/plugin/plugin_adc128.sh @@ -1,14 +1,86 @@ #!/bin/sh +# ADC128 Division factor +votage_division_factor_0="1" +votage_division_factor_1="1" +votage_division_factor_2="1" +votage_division_factor_3="0.8" +votage_division_factor_4="0.6" +votage_division_factor_5="0.6" +votage_division_factor_6="0.2326" +votage_division_factor_7="1" + +# ADC128 channel name +ADC128_Channel0_name="Channel0" +ADC128_Channel1_name="Channel1" +ADC128_Channel2_name="Channel2" +ADC128_Channel3_name="Channel3" +ADC128_Channel4_name="Channel4" +ADC128_Channel5_name="Channel5" +ADC128_Channel6_name="Channel6" +ADC128_Channel7_name="Channel7" + mode=$1 i2c_bus=$2 chip_slave=$3 server_platform=$4 +# Only for test purpose +test_data1=$2 +test_data2=$3 +test_factor=$4 + path=`pwd` fmt_print="${path}/format_print.sh" i2c_script="${path}/i2c_${server_platform}.sh" +REG_adc128_config="0x00" +REG_adc128_advance="0x0b" +REG_adc128_status="0x0c" +REG_adc128_ch0="0x20" +REG_adc128_ch1="0x21" +REG_adc128_ch2="0x22" +REG_adc128_ch3="0x23" +REG_adc128_ch4="0x24" +REG_adc128_ch5="0x25" +REG_adc128_ch6="0x26" +REG_adc128_ch7="0x27" + +print_help(){ + echo "---------------------------------------------------------" + echo "