pwrctl: Add latch output to power control

On the Zaius machine, the BMC signals that power up the CPU are gated by
a latch to protect against GPIO blips during BMC reset/power loss.

This adds an optional power GPIO configuration that controls the latch's
enable pin. Its behavior is to assert high when the op-pwrctl runs,
allowing power_up lines to propagate past their latches.

Signed-off-by: Xo Wang <xow@google.com>
Change-Id: Ibf0d1db771033cb9bba82575cca1bd21cfb3ad3d
diff --git a/op-pwrctl/power_control_obj.c b/op-pwrctl/power_control_obj.c
index cd13c68..679493c 100644
--- a/op-pwrctl/power_control_obj.c
+++ b/op-pwrctl/power_control_obj.c
@@ -208,6 +208,12 @@
 	uint8_t pgood_state;
 
 	// get gpio device paths
+	if(power_gpio->latch_out.name != NULL) {  /* latch is optional */
+		rc = gpio_init(connection, &power_gpio->latch_out);
+		if(rc != GPIO_OK) {
+			error = rc;
+		}
+	}
 	rc = gpio_init(connection, &power_gpio->power_good_in);
 	if(rc != GPIO_OK) {
 		error = rc;
@@ -225,6 +231,26 @@
 		}
 	}
 
+	/* If there's a latch, it only needs to be set once. */
+	if(power_gpio->latch_out.name != NULL) {
+		do {
+			rc = gpio_open(&power_gpio->latch_out);
+			if(rc != GPIO_OK) {
+				/* Failures are non-fatal. */
+				break;
+			}
+			rc = gpio_write(&power_gpio->latch_out, 1);
+			gpio_close(&power_gpio->latch_out);
+		} while(0);
+		if (rc != GPIO_OK) {
+			error = rc;
+			g_print("PowerControl ERROR failed to assert latch %s rc=%d\n",
+					power_gpio->latch_out.name, rc);
+		} else {
+			g_print("PowerControl asserted latch %s\n", power_gpio->latch_out.name);
+		}
+	}
+
 	rc = gpio_open(&power_gpio->power_good_in);
 	if(rc != GPIO_OK) {
 		return rc;