meta-ampere: mtjade: initialize GPIOs
Several GPIOs should be configured properly when booting BMC. Currently,
these GPIOs are configured in u-boot. However, some must be configured
in Linux. For example, the BMC_READY GPIO should be set only after BMC
is ready to work.
This commit introduce platform-init service which starts after BMC boots
to configure GPIOs pins required by hardware design.
Tested:
1. Do A/C power, check GPIO227 is set to 0.
2. Reboot BMC, check GPIO227 is set to 0.
3. Run gpioinfo and check GPIO directions
Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: Ie0cfe171659ad740c6a25297f2fcce259870d43d
diff --git a/meta-ampere/meta-jade/conf/machine/mtjade.conf b/meta-ampere/meta-jade/conf/machine/mtjade.conf
index 2c948df..b0826a9 100644
--- a/meta-ampere/meta-jade/conf/machine/mtjade.conf
+++ b/meta-ampere/meta-jade/conf/machine/mtjade.conf
@@ -32,6 +32,7 @@
ampere-mac-update \
mtjade-gpio-config \
mtd-utils \
+ ampere-platform-init \
"
PREFERRED_PROVIDER_virtual/obmc-chassis-mgmt = "packagegroup-ampere-apps"
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init.bb b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init.bb
new file mode 100644
index 0000000..aaeb33f
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init.bb
@@ -0,0 +1,28 @@
+SUMMARY = "Phosphor OpenBMC Mt.Jade Platform Init Service"
+DESCRIPTION = "Phosphor OpenBMC Mt.Jade Platform Init Daemon"
+
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit systemd
+inherit obmc-phosphor-systemd
+
+DEPENDS += "systemd"
+RDEPENDS:${PN} += "libsystemd"
+RDEPENDS:${PN} += "bash"
+
+SRC_URI = " \
+ file://ampere_platform_init.sh \
+ file://ampere-platform-init.service \
+ "
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE:${PN} = "ampere-platform-init.service"
+
+do_install () {
+ install -d ${D}${sbindir}
+ install -m 0755 ${WORKDIR}/ampere_platform_init.sh ${D}${sbindir}/
+ install -d ${D}${systemd_unitdir}/system/
+ install -m 0644 ${WORKDIR}/ampere-platform-init.service ${D}${systemd_unitdir}/system
+}
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere-platform-init.service b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere-platform-init.service
new file mode 100644
index 0000000..51b3caa
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere-platform-init.service
@@ -0,0 +1,12 @@
+[Unit]
+Description = Mt.Jade Platform Initialization
+
+[Service]
+Restart=no
+RemainAfterExit=true
+Type=oneshot
+ExecStart=/usr/sbin/ampere_platform_init.sh
+StandardOutput=syslog
+
+[Install]
+WantedBy=sysinit.target
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
new file mode 100644
index 0000000..a15be60
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+source /usr/sbin/gpio-lib.sh
+
+# GPIOAC3 BMC_SPI0_BACKUP_SEL Boot from MAIN SPI-HOST
+gpio_configure_output 227 0
+
+# GPIOM4 S0_I2C9_ALERT_L
+gpio_configure_input 100
+
+# GPIOM5 S1_I2C9_ALERT_L
+gpio_configure_input 101
+
+# GPIOQ7 GPIO_BMC_VGA_FRONT_PRES_L
+gpio_configure_input 135
+
+# GPIOS0 GPIO_S0_VRHOT_L
+gpio_configure_input 144
+
+# GPIOS1 GPIO_S1_VRHOT_L
+gpio_configure_input 145
+
+# GPIOY3 BMC_VGA_SEL
+gpio_direction_output 195 1
+
+# GPIO_BMC_READY
+gpio_direction_output 229 1
+
+# =======================================================
+# Below GPIOs are controlled by other services so just
+# initialize in A/C power only.
+cmdline=`cat /proc/cmdline`
+if [[ $cmdline == *resetreason=power* ]]; then
+ # BMC_GPIOR2_EXT_HIGHTEMP_L
+ gpio_direction_output 138 1
+
+ # GPIOS5 GPIO_BMC_VR_PMBUS_SEL_L
+ gpio_direction_output 149 1
+
+ # GPIOH7 GPIO_BMC_I2C6_RESET_L
+ gpio_configure_output 63 1
+
+ # GPIO_BMC_OCP_AUX_PWREN
+ gpio_configure_output 139 1
+
+ # GPIO_BMC_OCP_MAIN_PWREN
+ gpio_configure_output 140 0
+
+ # BMC_GPIOAC2_SPI0_PROGRAM_SEL
+ gpio_configure_output 226 0
+
+ # BMC_GPIOB0_I2C_BACKUP_SEL
+ gpio_configure_output 8 1
+fi