meta-ampere: mtmitchell: use standard gpio commands

Change to use gpioset and gpioget to set value for output GPIOs and read
value for input GPIOs.
This commit also corrects GPIO base numbers which are changed in Linux
kernel 6.5

Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: I802f9d777537ff28f94945006b6582b15523e3a8
diff --git a/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_spi_util.sh b/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_spi_util.sh
index ad3df4e..204fd86 100755
--- a/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_spi_util.sh
+++ b/meta-ampere/meta-common/recipes-ampere/platform/ampere-utils/ampere_spi_util.sh
@@ -1,8 +1,6 @@
 #!/bin/bash
 
 # shellcheck disable=SC2046
-# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
-source /usr/sbin/gpio-lib.sh
 
 spi_address="1e630000.spi"
 spi_bind="/sys/bus/platform/drivers/spi-aspeed-smc/bind"
@@ -21,7 +19,7 @@
 	fi
 
 	# BMC access SPI-NOR resource
-	gpio_name_set spi0-program-sel 1
+	gpioset $(gpiofind spi0-program-sel)=1
 	sleep 0.1
 	echo "Bind the ASpeed SMC driver"
 	echo "${spi_address}" > "${spi_bind}"  2>/dev/null
@@ -33,7 +31,7 @@
 		echo "${spi_address}" > "${spi_bind}"
 	fi
 	# BMC release SPI-NOR resource
-	gpio_name_set spi0-program-sel 0
+	gpioset $(gpiofind spi0-program-sel)=0
 	return 0
 }
 
@@ -65,15 +63,15 @@
 	if [ -n "$HOST_MTD" ]; then
 		# If the HNOR partition is available, then unbind driver
 		# BMC access SPI-NOR resource
-		gpio_name_set spi0-program-sel 1
+		gpioset $(gpiofind spi0-program-sel)=1
 		sleep 0.1
 		echo "Unbind the ASpeed SMC driver"
 		echo "${spi_address}" > "${spi_unbind}"
 	fi
 	# BMC release SPI-NOR resource
-	gpio_name_set spi0-program-sel 0
+	gpioset $(gpiofind spi0-program-sel)=0
 	# Deassert BMC access SPI-NOR pin
-	gpio_name_set spi-nor-access 0
+	gpioset $(gpiofind spi-nor-access)=0
 	sleep 0.5
 	return 0
 }
@@ -130,7 +128,7 @@
 	cnt=10
 	while [ $cnt -gt 0 ]
 	do
-		spinor_access=$(gpio_name_get soc-spi-nor-access)
+		spinor_access=$(gpioget $(gpiofind soc-spi-nor-access))
 		if [ "$spinor_access" == "1" ]; then
 			sleep 1
 			cnt=$((cnt - 1))
@@ -146,9 +144,9 @@
 	echo "Start handshake SPI-NOR"
 	# Grant BMC access SPI-NOR. The process call the scripts should only
 	# claim the bus for only maximum period 500ms.
-	gpio_name_set spi-nor-access 1
+	gpioset $(gpiofind spi-nor-access)=1
 	# Switch the Host SPI-NOR to BMC
-	gpio_name_set spi0-program-sel 1
+	gpioset $(gpiofind spi0-program-sel)=1
 }
 
 stop_handshake_spi() {
@@ -162,9 +160,9 @@
 	fi
 	echo "Stop handshake SPI-NOR"
 	# Switch the Host SPI-NOR to HOST
-	gpio_name_set spi0-program-sel 0
+	gpioset $(gpiofind spi0-program-sel)=0
 	# Deassert BMC access SPI-NOR pin
-	gpio_name_set spi-nor-access 0
+	gpioset $(gpiofind spi-nor-access)=0
 }
 
 
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-defs.sh b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-defs.sh
index 2f2a4d6..4414f79 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-defs.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-defs.sh
@@ -6,8 +6,7 @@
 GPIO_CHIP1_IDX=1
 
 # Base of GPIO chip in /sys/class/gpio
-GPIO_CHIP0_BASE=792
-GPIO_CHIP1_BASE=780
+GPIO_CHIP0_BASE=512
 
 ### Power control configuration
 # Power control gpios
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-fault-monitor/ampere_fault_monitor.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-fault-monitor/ampere_fault_monitor.sh
index 299e13b..b1cf785 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-fault-monitor/ampere_fault_monitor.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-fault-monitor/ampere_fault_monitor.sh
@@ -1,9 +1,7 @@
 #!/bin/bash
 # This script monitors fan, over-temperature, PSU, CPU/SCP failure and update fault LED status
 
-# shellcheck disable=SC2004
-# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
-source /usr/sbin/gpio-lib.sh
+# shellcheck disable=SC2046
 
 # common variables
 	on=1
@@ -112,23 +110,23 @@
 	local psu0_value
 	local psu1_value
 
-	psu0_presence=$(gpio_name_get presence-ps0)
+	psu0_presence=$(gpioget $(gpiofind presence-ps0))
 	psu0_failed="true"
 	if [ "$psu0_presence" == "0" ]; then
 		# PSU0 presence, monitor the PSUs using pmbus, check the STATUS_WORD
 		psu0_value=$(i2cget -f -y $psu_bus $psu0_addr $status_word_cmd w)
-		psu0_bit_fault=$(($psu0_value & $psu_fault_bitmask))
+		psu0_bit_fault=$((psu0_value & psu_fault_bitmask))
 		if [ "$psu0_bit_fault" == "0" ]; then
 			psu0_failed="false"
 		fi
 	fi
 
-	psu1_presence=$(gpio_name_get presence-ps1)
+	psu1_presence=$(gpioget $(gpiofind presence-ps1))
 	psu1_failed="true"
 	if [ "$psu1_presence" == "0" ]; then
 		# PSU1 presence, monitor the PSUs using pmbus, check the STATUS_WORD
 		psu1_value=$(i2cget -f -y $psu_bus $psu1_addr $status_word_cmd w)
-		psu1_bit_fault=$(($psu1_value & $psu_fault_bitmask))
+		psu1_bit_fault=$((psu1_value & psu_fault_bitmask))
 		if [ "$psu1_bit_fault" == "0" ]; then
 			psu1_failed="false"
 		fi
@@ -189,9 +187,9 @@
 control_sys_fault_led() {
 	# Turn on/off the System Fault Led
 	if [ "$fault" == "true" ]; then
-		gpio_name_set led-fault $on
+		gpioset $(gpiofind led-fault)=1
 	else
-		gpio_name_set led-fault $off
+		gpioset $(gpiofind led-fault)=0
 	fi
 }
 
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_bmc_heartbeat.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_bmc_heartbeat.sh
index b9bba7b..0180996 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_bmc_heartbeat.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_bmc_heartbeat.sh
@@ -1,19 +1,18 @@
 #!/bin/bash
 
-# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
-source /usr/sbin/gpio-lib.sh
+# shellcheck disable=SC2046
 
 value=0
 while true;
 do
 	if [[ $value -eq 0 ]]; then
 		value=1
-		gpio_name_set led-sw-hb 1
-		gpio_name_set led-bmc-hb 0
+		gpioset $(gpiofind led-sw-hb)=1
+		gpioset $(gpiofind led-bmc-hb)=0
 	else
 		value=0
-		gpio_name_set led-sw-hb 0
-		gpio_name_set led-bmc-hb 1
+		gpioset $(gpiofind led-sw-hb)=0
+		gpioset $(gpiofind led-bmc-hb)=1
 	fi
 	sleep 1s
 done
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
index cae866e..4d737a7 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
@@ -1,7 +1,6 @@
 #!/bin/bash
 
-# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
-source /usr/sbin/gpio-lib.sh
+# shellcheck disable=SC2046
 # shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
 source /usr/sbin/platform_gpios_init.sh
 source /usr/sbin/ampere_uart_console_setup.sh
@@ -15,15 +14,15 @@
 if [ "$bootstatus" == '32' ]; then
     echo "CONFIGURE: gpio pins to output high after AC power"
     for gpioName in "${output_high_gpios_in_ac[@]}"; do
-        gpio_name_set "$gpioName" 1
+        gpioset $(gpiofind "$gpioName")=1
     done
     echo "CONFIGURE: gpio pins to output low after AC power"
     for gpioName in "${output_low_gpios_in_ac[@]}"; do
-        gpio_name_set "$gpioName" 0
+        gpioset $(gpiofind "$gpioName")=0
     done
     echo "CONFIGURE: gpio pins to input after AC power"
     for gpioName in "${input_gpios_in_ac[@]}"; do
-        gpio_name_input "$gpioName"
+        gpioget $(gpiofind "$gpioName")
     done
 fi
 
@@ -31,15 +30,15 @@
 # Setting default value for others gpio pins
 echo "CONFIGURE: gpio pins to output high"
 for gpioName in "${output_high_gpios_in_bmc_reboot[@]}"; do
-    gpio_name_set "$gpioName" 1
+    gpioset $(gpiofind "$gpioName")=1
 done
 echo "CONFIGURE: gpio pins to output low"
 for gpioName in "${output_low_gpios_in_bmc_reboot[@]}"; do
-    gpio_name_set "$gpioName" 0
+    gpioset $(gpiofind "$gpioName")=0
 done
 echo "CONFIGURE: gpio pins to input"
 for gpioName in "${input_gpios_in_bmc_reboot[@]}"; do
-    gpio_name_input "$gpioName"
+    gpioget $(gpiofind "$gpioName")
 done
 
 # =======================================================
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
index 5fbbbcc..c9eb2b9 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
@@ -2,8 +2,8 @@
 
 # Configure GPIO as output and set its value
 AST2600_GPIO_BASE=(
-    816
-    780
+    512
+    720
 )
 
 function gpio_configure_output() {
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
index 65acfc5..f5fefc3 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
@@ -1,7 +1,6 @@
 #!/bin/bash
 
-# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
-source /usr/sbin/gpio-lib.sh
+# shellcheck disable=SC2046
 
 function bind_rtc_driver() {
     # If rtc device can not present, bind the device
@@ -34,20 +33,20 @@
 
     if [ "$pgood" == '1' ]; then
         echo "PSU is on. Setting PSON to 0"
-        gpio_name_set power-chassis-control 0
+        gpioset $(gpiofind power-chassis-control)=0
     else
         echo "pgood D-Bus property response as 0. PSU is off."
         # for unknown reason when stress reboot bmc power-control.exe detect power-chassis-good is 1 (power on)
         # But "busctl get-property org.openbmc.control.Power /org/openbmc/control/power0 org.openbmc.control.Power pgood" responses 0 (power off)
         # Add sleep 3 seconds after the pgood dbus reponse (power off) and recheck the power-chassis-good to confirm about the PSU power state
         sleep 3
-        pgood=$(gpio_name_get power-chassis-good)
+        pgood=$(gpioget $(gpiofind power-chassis-good))
         if [ "$pgood" == '0' ]; then
             echo "power-chassis-good reponse as 0. Confirm PSU is off. Setting PSON to 1."
-            gpio_name_set power-chassis-control 1
+            gpioset $(gpiofind power-chassis-control)=1
         fi
     fi
-    gpio_name_set host0-sysreset-n 1
+    gpioset $(gpiofind host0-sysreset-n)=1
 
     # gpio-leds is controlling bmc-ready, not by gpio
     echo 1 > /sys/class/leds/bmc-ready/brightness
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-utils/ampere_power_util.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-utils/ampere_power_util.sh
index 330861a..78f54bc 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-utils/ampere_power_util.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-utils/ampere_power_util.sh
@@ -1,7 +1,6 @@
 #!/bin/bash
 
-# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
-source /usr/sbin/gpio-lib.sh
+# shellcheck disable=SC2046
 
 # Usage of this utility
 function usage() {
@@ -31,9 +30,9 @@
 soft_off() {
 	# Trigger shutdown_req
 	touch /run/openbmc/host@0-softpoweroff
-	gpio_name_set host0-shd-req-n 0
+	gpioset $(gpiofind host0-shd-req-n)=0
 	sleep 0.05
-	gpio_name_set host0-shd-req-n 1
+	gpioset $(gpiofind host0-shd-req-n)=1
 
 	# Wait for shutdown_ack from the host in 30 seconds
 	cnt=30
@@ -79,9 +78,9 @@
 	fi
 	rm -f /run/openbmc/host@0-on
 	echo "Triggering sysreset pin"
-	gpio_name_set host0-sysreset-n 0
+	gpioset $(gpiofind host0-sysreset-n)=0
 	sleep 1
-	gpio_name_set host0-sysreset-n 1
+	gpioset $(gpiofind host0-sysreset-n)=1
 }
 
 host_reboot_wa() {