meta-facebook: yosemite4: Add initial GPIO setting
Summary:
To initial GPIO setting by following yosemite4 hardware setting
Tested:
Check GPIO using devmem
Change-Id: I706ecfc8a41dcc12e4bd0f293c5ae38f5943d377
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc b/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc
index a1b0ca5..117118d 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc
@@ -12,4 +12,9 @@
# is finished.
OBMC_IMAGE_EXTRA_INSTALL:append = " \
libusb1 \
-"
\ No newline at end of file
+"
+# Temporarily add plat-svc for gpio initialization
+OBMC_IMAGE_EXTRA_INSTALL:append = " \
+ plat-svc \
+"
+
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
new file mode 100644
index 0000000..bc1e54f
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
@@ -0,0 +1,39 @@
+#!/bin/bash -e
+# shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
+source /usr/libexec/yosemite4-common-functions
+
+# set initial value for GPIO output pins
+set_gpio EN_P5V_USB_CPLD_R 1
+set_gpio EN_NIC0_POWER_BMC_R 1
+set_gpio EN_NIC1_POWER_BMC_R 1
+set_gpio EN_NIC2_POWER_BMC_R 1
+set_gpio EN_NIC3_POWER_BMC_R 1
+set_gpio FM_BMC_RTCRST_R 0
+set_gpio RST_USB_HUB_R_N 1
+set_gpio FM_BMC_READY_R2 1
+set_gpio SPI_LOCK_REQ_BMC_N 1
+set_gpio EN_P3V_BAT_SCALED_R 0
+
+set_gpio P48V_OCP_GPIO1 0
+set_gpio P48V_OCP_GPIO2 0
+set_gpio P48V_OCP_GPIO3 0
+set_gpio RST_MUX_R_N 1
+set_gpio RST_LED_CONTROL_FAN_BOARD_0_N 1
+set_gpio RST_LED_CONTROL_FAN_BOARD_1_N 1
+set_gpio RST_IOEXP_FAN_BOARD_0_N 1
+set_gpio RST_IOEXP_FAN_BOARD_1_N 1
+set_gpio EN_P48V_AUX_0 1
+set_gpio EN_P48V_AUX_1 1
+set_gpio HSC_OCP_SLOT_ODD_GPIO1 0
+set_gpio HSC_OCP_SLOT_ODD_GPIO2 0
+set_gpio HSC_OCP_SLOT_ODD_GPIO3 0
+set_gpio HSC_OCP_SLOT_EVEN_GPIO1 0
+set_gpio HSC_OCP_SLOT_EVEN_GPIO2 0
+set_gpio HSC_OCP_SLOT_EVEN_GPIO3 0
+
+set_gpio NIC0_MAIN_PWR_EN 1
+set_gpio NIC1_MAIN_PWR_EN 1
+set_gpio NIC2_MAIN_PWR_EN 1
+set_gpio NIC3_MAIN_PWR_EN 1
+
+exit 0
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-sys-init.service b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-sys-init.service
new file mode 100644
index 0000000..d2377f4
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-sys-init.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Yosemite4 Early System Init
+Before=phosphor-pid-control.service
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/yosemite4-early-sys-init
+SyslogIdentifier=Yosemite4 Early Init
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/plat-svc_0.1.bb b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/plat-svc_0.1.bb
new file mode 100644
index 0000000..65a3824
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/plat-svc_0.1.bb
@@ -0,0 +1,24 @@
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit allarch systemd obmc-phosphor-systemd
+
+RDEPENDS:${PN} += "bash"
+RDEPENDS:${PN} += "libgpiod-tools"
+RDEPENDS:${PN} += "yosemite4-common-functions"
+
+SRC_URI += " \
+ file://yosemite4-sys-init.service \
+ file://yosemite4-early-sys-init \
+ "
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE:${PN}:append = " \
+ yosemite4-sys-init.service \
+ "
+
+do_install() {
+ install -d ${D}${libexecdir}
+ install -m 0755 ${WORKDIR}/yosemite4-early-sys-init ${D}${libexecdir}
+}
+
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
new file mode 100644
index 0000000..0614ff0
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+set_gpio()
+{
+ local NET_NAME=$1
+ local OUT_VAL=$2
+ mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME")
+ if [ "${#GPIO_INFO[@]}" -ne 2 ]; then
+ echo "set_gpio: can not find gpio, $NET_NAME"
+ return 1
+ fi
+
+ echo -n "set_gpio: set $NET_NAME = $OUT_VAL"
+ if ! gpioset "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}"="$OUT_VAL"; then
+ echo " failed"
+ return 1
+ fi
+
+ echo " success"
+ return 0
+}
+
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/yosemite4-common-functions_0.1.bb b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/yosemite4-common-functions_0.1.bb
new file mode 100644
index 0000000..d087524
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/yosemite4-common-functions_0.1.bb
@@ -0,0 +1,13 @@
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+RDEPENDS:${PN} += " bash libgpiod-tools"
+
+SRC_URI += " \
+ file://yosemite4-common-functions \
+ "
+
+do_install() {
+ install -d ${D}${libexecdir}
+ install -m 0755 ${WORKDIR}/yosemite4-common-functions ${D}${libexecdir}
+}