summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWai-Hong Tam <waihong@google.com>2022-03-15 16:56:44 -0700
committerCommit Bot <commit-bot@chromium.org>2022-03-16 18:07:09 +0000
commit6e5d4978a9f31b62d5a8d2356b7e06ecea0bdb56 (patch)
treec4ab8dd9c9735b061b54eea281e80c325c17e008
parenta17c70ef114aa087ac36860ec4cd40fd62d536db (diff)
downloadchrome-ec-6e5d4978a9f31b62d5a8d2356b7e06ecea0bdb56.tar.gz
zephyr: gpio: Do not change the output state for open-drain outputs
In the GPIO init, for each OUTPUT GPIO, it changes its output state according to its current state. It works for a push-pull OUTPUT. But for an open drain output, its current value doesn't imply the previous output state. The current low state is either 1) the EC previously drove the pin low; 2) the EC previously high-Z'ed the pin. These 2 cases can't be differentiated, so skip overriding the output state. BRANCH=None BUG=b:224616711 TEST=Verified the EC RW can boot the AP into the logic prompt. Change-Id: Ifdd1c6bac74b80edd95e9075744e1e583d553a0e Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3530149 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/shim/src/gpio.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c
index 59d59d78f7..6eb9a142ad 100644
--- a/zephyr/shim/src/gpio.c
+++ b/zephyr/shim/src/gpio.c
@@ -286,8 +286,22 @@ static int init_gpios(const struct device *unused)
flags &=
~(GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH);
- flags |= current ? GPIO_OUTPUT_INIT_HIGH
- : GPIO_OUTPUT_INIT_LOW;
+
+ /*
+ * For an open drain output, its current value
+ * doesn't imply the previous output state.
+ *
+ * The current low state is either
+ * 1) the EC previously drove the pin low;
+ * 2) the EC previously high-Z'ed the pin.
+ *
+ * These 2 cases can't be differentiated, so
+ * skip overriding the output state.
+ */
+ if ((flags & GPIO_OPEN_DRAIN) != GPIO_OPEN_DRAIN) {
+ flags |= current ? GPIO_OUTPUT_INIT_HIGH
+ : GPIO_OUTPUT_INIT_LOW;
+ }
}
rv = gpio_pin_configure_dt(&configs[i].spec, flags);