meta-ampere: Initial AmpereOne(TM) Mt. Mitchell's non-DC-SCM BMC support

Add new Mt.Mitchell platform with basic features so that it can be
compiled and works.

Tested:
1. Compile for Mt.Mitchell successful.
2. Flash and check for the firmware can boot on the Mt.Mitchell
non-DC-SCM system without issue

Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com>
Change-Id: I8dc9db9029b27c0c6325c31d368cdbb614a3c8b6
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/packagegroups/packagegroup-obmc-ampere-apps.bb b/meta-ampere/meta-mitchell/recipes-ampere/packagegroups/packagegroup-obmc-ampere-apps.bb
new file mode 100644
index 0000000..d1c7e7e
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/packagegroups/packagegroup-obmc-ampere-apps.bb
@@ -0,0 +1,53 @@
+SUMMARY = "OpenBMC for Ampere - Applications"
+PR = "r1"
+
+inherit packagegroup
+
+PROVIDES = "${PACKAGES}"
+PACKAGES = " \
+        ${PN}-chassis \
+        ${PN}-flash \
+        ${PN}-system \
+        "
+
+PROVIDES += "virtual/obmc-chassis-mgmt"
+PROVIDES += "virtual/obmc-flash-mgmt"
+PROVIDES += "virtual/obmc-system-mgmt"
+
+RPROVIDES:${PN}-chassis += "virtual-obmc-chassis-mgmt"
+RPROVIDES:${PN}-flash += "virtual-obmc-flash-mgmt"
+RPROVIDES:${PN}-system += "virtual-obmc-system-mgmt"
+
+SUMMARY:${PN}-chassis = "Ampere Chassis"
+RDEPENDS:${PN}-chassis = " \
+                            obmc-phosphor-buttons-signals \
+                            obmc-phosphor-buttons-handler \
+                            obmc-op-control-power \
+                            ampere-hostctrl \
+                            phosphor-hostlogger \
+                            phosphor-sel-logger \
+                            phosphor-logging \
+                         "
+
+SUMMARY:${PN}-system = "Ampere System"
+RDEPENDS:${PN}-system = " \
+                         smbios-mdr \
+                        "
+
+SUMMARY:${PN}-flash = "Ampere Flash"
+RDEPENDS:${PN}-flash = " \
+                        phosphor-software-manager \
+                       "
+
+RDEPENDS:${PN}-inventory:append = " \
+                                   dbus-sensors \
+                                   entity-manager \
+                                  "
+
+RDEPENDS:${PN}-extras:append = " \
+                                webui-vue \
+                                phosphor-virtual-sensor \
+                               "
+RDEPENDS:${PN}-extras:remove = " phosphor-hwmon"
+
+VIRTUAL-RUNTIME_obmc-sensors-hwmon ?= "dbus-sensors"
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb
new file mode 100644
index 0000000..dd5f599
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb
@@ -0,0 +1,35 @@
+SUMMARY = "Phosphor OpenBMC Platform Init Service"
+DESCRIPTION = "Phosphor OpenBMC 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.service \
+           file://ampere-bmc-heartbeat.service \
+           file://ampere_platform_init.sh \
+           file://ampere_bmc_heartbeat.sh \
+           file://${MACHINE}_platform_gpios_init.sh \
+           file://gpio-lib.sh \
+          "
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE:${PN} = "ampere-platform-init.service ampere-bmc-heartbeat.service"
+
+do_install () {
+    install -d ${D}${sbindir}
+    install -m 0755 ${WORKDIR}/gpio-lib.sh ${D}${sbindir}/
+    install -m 0755 ${WORKDIR}/ampere_platform_init.sh ${D}${sbindir}/
+    install -m 0755 ${WORKDIR}/ampere_bmc_heartbeat.sh ${D}${sbindir}/
+    install -m 0755 ${WORKDIR}/${MACHINE}_platform_gpios_init.sh ${D}${sbindir}/platform_gpios_init.sh
+    install -d ${D}${systemd_unitdir}/system/
+    install -m 0644 ${WORKDIR}/ampere-platform-init.service ${D}${systemd_unitdir}/system
+}
+
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere-bmc-heartbeat.service b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere-bmc-heartbeat.service
new file mode 100644
index 0000000..d491fd9
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere-bmc-heartbeat.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Ampere BMC heartbeat service
+Wants=obmc-mapper.target
+After=obmc-mapper.target
+
+[Service]
+Type=simple
+Restart=always
+ExecStart=/usr/bin/env ampere_bmc_heartbeat.sh
+SyslogIdentifier = "ampere-bmc-heartbeat"
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere-platform-init.service b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere-platform-init.service
new file mode 100644
index 0000000..72a34cb
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere-platform-init.service
@@ -0,0 +1,11 @@
+[Unit]
+Description = Ampere Platform Initialization
+
+[Service]
+Restart=no
+RemainAfterExit=true
+Type=oneshot
+ExecStart=/usr/sbin/ampere_platform_init.sh
+
+[Install]
+WantedBy=sysinit.target
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
new file mode 100644
index 0000000..5ecea31
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_bmc_heartbeat.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# shellcheck disable=SC2154
+# shellcheck source=/dev/null
+
+source /usr/sbin/gpio-lib.sh
+
+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
+	else
+		value=0
+		gpio_name_set led-sw-hb 0
+		gpio_name_set 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
new file mode 100644
index 0000000..33dc7ea
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+# shellcheck disable=SC2154
+# shellcheck source=/dev/null
+
+source /usr/sbin/gpio-lib.sh
+source /usr/sbin/platform_gpios_init.sh
+
+#pre platform init function. implemented in platform_gpios_init.sh
+pre-platform-init
+
+# =======================================================
+# Setting default value for device sel and mux
+bootstatus=$(cat /sys/class/watchdog/watchdog0/bootstatus)
+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
+    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
+    done
+    echo "CONFIGURE: gpio pins to input after AC power"
+    for gpioName in "${input_gpios_in_ac[@]}"; do
+        gpio_name_input "$gpioName"
+    done
+fi
+
+# =======================================================
+# 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
+done
+echo "CONFIGURE: gpio pins to output low"
+for gpioName in "${output_low_gpios_in_bmc_reboot[@]}"; do
+    gpio_name_set "$gpioName" 0
+done
+echo "CONFIGURE: gpio pins to input"
+for gpioName in "${input_gpios_in_bmc_reboot[@]}"; do
+    gpio_name_input "$gpioName"
+done
+
+#post platform init function. implemented in platform_gpios_init.sh
+post-platform-init
+
+exit 0
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
new file mode 100644
index 0000000..3e503c4
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# shellcheck disable=SC2154
+# shellcheck source=/dev/null
+
+# Configure GPIO as output and set its value
+AST2600_GPIO_BASE=(
+    816
+    780
+)
+
+function gpio_configure_output() {
+	echo "$1" > /sys/class/gpio/export
+	echo out > /sys/class/gpio/gpio"$1"/direction
+	echo "$2" > /sys/class/gpio/gpio"$1"/value
+	echo "$1" > /sys/class/gpio/unexport
+}
+
+function gpio_get_val() {
+	echo "$1" > /sys/class/gpio/export
+	cat /sys/class/gpio/gpio"$1"/value
+	echo "$1" > /sys/class/gpio/unexport
+}
+
+# Configure GPIO as input
+function gpio_configure_input() {
+	echo "$1" > /sys/class/gpio/export
+	echo "in" > /sys/class/gpio/gpio"$1"/direction
+	echo "$1" > /sys/class/gpio/unexport
+}
+
+function gpio_name_set()
+{
+    str=$(gpiofind "$1")
+    #Verify error code when run gpiofind
+    if [ "$?" == '1' ]; then
+        echo "Invalid gpio name $1"
+    else
+        gpioid=$(echo "$str"|cut -c 9)
+        offset=$(echo "$str"|cut -d " " -f 2)
+        gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
+        gpio_configure_output "$gpioPin" "$2"
+    fi
+}
+
+function gpio_name_get()
+{
+    str=$(gpiofind "$1")
+    #Verify error code when run gpiofind
+    if [ "$?" == '1' ]; then
+        echo "Invalid gpio name $1"
+    else
+        offset=$(echo "$str"|cut -d " " -f 2)
+        gpioid=$(echo "$str"|cut -c 9)
+        gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
+        gpio_get_val "$gpioPin"
+    fi
+}
+
+function gpio_name_input()
+{
+    str=$(gpiofind "$1")
+    #Verify error code when run gpiofind
+    if [ "$?" == '1' ]; then
+        echo "Invalid gpio name $1"
+    else
+        gpioid=$(echo "$str"|cut -c 9)
+        offset=$(echo "$str"|cut -d " " -f 2)
+        gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
+        gpio_configure_input "$gpioPin"
+    fi
+}
\ No newline at end of file
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
new file mode 100644
index 0000000..4c30466
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
@@ -0,0 +1,105 @@
+#!/bin/bash
+
+# shellcheck disable=SC2154
+# shellcheck source=/dev/null
+
+source /usr/sbin/gpio-lib.sh
+
+function bind_rtc_driver() {
+    # If rtc device can not present, bind the device
+    if [[ ! -e /dev/rtc0 ]]; then
+        echo "Bind rtc driver"
+        echo 6-0051 > /sys/bus/i2c/drivers/rtc-pcf85063/bind
+    fi
+}
+
+function pre-platform-init() {
+    echo "Do pre platform init"
+}
+
+function post-platform-init() {
+    # gpio-leds is controlling bmc-ready, not by gpio
+    echo 1 > /sys/class/leds/bmc-ready/brightness
+
+    # Bind rtc driver
+    bind_rtc_driver
+}
+
+export output_high_gpios_in_ac=(
+    # add device enable, mux setting, device select gpios
+    "spi0-backup-sel"
+    "i2c-backup-sel"
+)
+
+export output_low_gpios_in_ac=(
+    # add device enable, mux setting, device select gpios
+    "spi0-program-sel"
+    "ocp-main-pwren"
+)
+
+export input_gpios_in_ac=(
+    # add device enable, mux setting, device select gpios
+)
+
+export output_high_gpios_in_bmc_reboot=(
+    "host0-sysreset-n"
+    "host0-pmin-n"
+    "vrd-sel"
+    "spd-sel"
+    "ext-high-temp-n"
+    "wd-disable-n"
+    "hpm-stby-rst-n"
+    "jtag-sel-s0"
+    "cpld-user-mode"
+    "jtag-srst-n"
+    "host0-shd-req-n"
+)
+
+export output_low_gpios_in_bmc_reboot=(
+    "rtc-battery-voltage-read-enable"
+    "s0-rtc-lock"
+    "hpm-fw-recovery"
+    "led-fault"
+    "spi-nor-access"
+    "host0-special-boot"
+)
+
+export input_gpios_in_bmc_reboot=(
+    "s0-vrd-fault-n"
+    "s1-vrd-fault-n"
+    "irq-n"
+    "presence-ps0"
+    "presence-ps1"
+    "hsc-12vmain-alt2-n"
+    "s0-pcp-oc-warn-n"
+    "s1-pcp-oc-warn-n"
+    "cpu-bios-recover"
+    "s0-heartbeat"
+    "hs-scout-proc-hot"
+    "s0-vr-hot-n"
+    "s1-vr-hot-n"
+    "hsc-12vmain-alt1-n"
+    "power-chassis-good"
+    "power-button"
+    "s0-ddr-save"
+    "soc-spi-nor-access"
+    "presence-cpu0"
+    "jtag-dbgr-prsnt-n"
+    "ps0-ac-loss-n"
+    "ps1-ac-loss-n"
+    "s1-ddr-save"
+    "sys-pgood"
+    "presence-cpu1"
+    "s0-fault-alert"
+    "s0-sys-auth-failure-n"
+    "host0-ready"
+    "ocp-pgood"
+    "s1-fault-alert"
+    "s1-fw-boot-ok"
+    "s0-spi-auth-fail-n"
+    "s1-sys-auth-failure-n"
+    "reset-button"
+    "ps0-pgood"
+    "ps1-pgood"
+    "s0-soc-pgood"
+)