nicsensor/tool/plugin/platform_5280m7.sh

174 lines
4.5 KiB
Bash
Raw Normal View History

2025-02-19 13:43:50 +08:00
#!/bin/sh
action=$1
nic_type=$2
slot_id=$3
2025-02-20 18:10:19 +08:00
path=`pwd`
i2c_script="${path}/i2c_m7.sh"
fmt_print="${path}/format_print.sh"
2025-02-19 13:43:50 +08:00
pca9548_slave=""
pca9641_slave=""
i2c_bus=""
pca9548_channel=""
2025-02-20 18:10:19 +08:00
is_have_pca9641=0
2025-02-24 20:15:41 +08:00
record_i2c_status(){
$fmt_print "log" "Info" "[platform_5280m7] 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"
}
2025-02-19 13:43:50 +08:00
set_i2c_config(){
# set pca9641 address && I2C BUS
2025-02-20 18:10:19 +08:00
if [ "${nic_type}" = "ocp" ];then
is_have_pca9641=0
2025-02-19 13:43:50 +08:00
pca9548_slave="0x70"
i2c_bus=3
else
2025-02-20 18:10:19 +08:00
is_have_pca9641=1
2025-02-19 13:43:50 +08:00
if [ $slot_id -le 2 ];then
pca9641_slave="0x41"
pca9548_slave="0x72"
i2c_bus=12
else
pca9641_slave="0x42"
pca9548_slave="0x72"
i2c_bus=13
fi
fi
# set pca9548 switch channel
2025-02-20 18:10:19 +08:00
if [ "${nic_type}" = "ocp" ];then
2025-02-19 13:43:50 +08:00
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"
else
$fmt_print "console" "Warning" "Unspecified card slot!"
fi
else
if [ $slot_id -eq 0 ];then
pca9548_channel="0x02"
elif [ $slot_id -eq 1 ];then
pca9548_channel="0x04"
elif [ $slot_id -eq 2 ];then
pca9548_channel="0x08"
elif [ $slot_id -eq 3 ];then
pca9548_channel="0x02"
elif [ $slot_id -eq 4 ];then
pca9548_channel="0x04"
elif [ $slot_id -eq 5 ];then
pca9548_channel="0x08"
else
$fmt_print "console" "Warning" "Unspecified card slot!"
fi
fi
2025-02-24 20:15:41 +08:00
record_i2c_status
2025-02-20 18:10:19 +08:00
}
get_pca9641_control(){
$fmt_print "log" "Info" "[platform_5280m7] Start Get pca9641 control"
2025-02-24 20:15:41 +08:00
# 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"
# 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"
if [ "$res_build" != "0x87" ];then
$fmt_print "log" "Error" "Cannot establish connection with pca9641 !!!"
exit 1
fi
2025-02-20 18:10:19 +08:00
}
select_pca9548_channel(){
$fmt_print "log" "Info" "[platform_5280m7] Start Switch PCA9548"
2025-02-21 09:33:20 +08:00
$i2c_script "$i2c_bus" 1 "$pca9548_slave" "$pca9548_channel" 0
2025-02-20 18:10:19 +08:00
}
2025-02-19 13:43:50 +08:00
build_i2c_connect(){
$fmt_print "log" "Info" "[platform_5280m7] Start build i2c connect"
2025-02-20 18:10:19 +08:00
set_i2c_config
if [ $is_have_pca9641 -eq 1 ];then
get_pca9641_control
fi
select_pca9548_channel
echo "$i2c_bus"
2025-02-19 13:43:50 +08:00
}
2025-02-24 20:15:41 +08:00
# 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 "log" "Info" "OCP slot $5 : bus$1 9548channel$4"
else
$fmt_print "log" "Info" "PCIe slot $5 : bus$1 9548channel$4"
fi
i2ctransfer -y $1 w1@$2 $3
i2cdetect -y $1
}
2025-02-19 13:43:50 +08:00
detect_on_server(){
2025-02-24 20:15:41 +08:00
$fmt_print "console" "Info" "[platform_5280m7] Start i2c detect"
if [ "${nic_type}" = "ocp" ];then
i2c_bus=3
do_i2c_detect 3 0x70 0x01 0 0
do_i2c_detect 3 0x70 0x02 1 1
do_i2c_detect 3 0x70 0x04 2 2
else
i2c_bus=12
pca9641_slave="0x41"
get_pca9641_control
do_i2c_detect 12 0x72 0x02 1 0
do_i2c_detect 12 0x72 0x04 2 1
do_i2c_detect 12 0x72 0x08 3 2
i2c_bus=13
pca9641_slave="0x42"
get_pca9641_control
do_i2c_detect 13 0x72 0x02 1 3
do_i2c_detect 13 0x72 0x04 2 4
do_i2c_detect 13 0x72 0x08 3 5
fi
2025-02-19 13:43:50 +08:00
}
# ---------------------------------------------------
# Start Execute Script
# ---------------------------------------------------
case "${action}" in
"connect")
build_i2c_connect
;;
"detect")
detect_on_server
;;
*)
$fmt_print "console" "Error" "[platform_5280m7] Unspecified Operation : $action"
exit 1
;;
esac
exit 0