summaryrefslogtreecommitdiff
path: root/zephyr/shim/include/zephyr_write_protect.h
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2022-02-07 14:50:09 +0100
committerCommit Bot <commit-bot@chromium.org>2022-02-11 00:38:24 +0000
commit74a02c2ff082d70608064f4b09f8ecf08a77e685 (patch)
tree1b59c3e9265f7a6fa0a39f76083f03aa2b419095 /zephyr/shim/include/zephyr_write_protect.h
parent4b10d2b2d093a43d9ef46ab4024cf38e13bb8f67 (diff)
downloadchrome-ec-74a02c2ff082d70608064f4b09f8ecf08a77e685.tar.gz
write protect: extract checking write protect
The write-protect state can be checked on 2 pins GPIO_WP or GPIO_WP_L. The CONFIG_WP_ACTIVE_HIGH config is used to distinguish these two cases. Move the checking the config and pin state to a separate header file. For Zephyr, start using the gpio_get_level function that takes into account the GPIO_ACTIVE_LOW flag. Also, use 'gpio-wp' alias to the WP pin instead of the legacy enum-name property and 'int-wp' alias to the WP GPIO interrupt. BUG=b:211779766 TEST=zmake testall & make sure WP works BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I70bfbcd5e539fcc8cd157f2feae1a6c8e25083a4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3447404 Reviewed-by: Andrew McRae <amcrae@google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/shim/include/zephyr_write_protect.h')
-rw-r--r--zephyr/shim/include/zephyr_write_protect.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/zephyr/shim/include/zephyr_write_protect.h b/zephyr/shim/include/zephyr_write_protect.h
new file mode 100644
index 0000000000..3d82b2ec93
--- /dev/null
+++ b/zephyr/shim/include/zephyr_write_protect.h
@@ -0,0 +1,43 @@
+/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_ZEPHYR_WRITE_PROTECT_H
+#define __CROS_EC_ZEPHYR_WRITE_PROTECT_H
+
+#include "gpio/gpio_int.h"
+#include "gpio_signal.h"
+#include <drivers/gpio.h>
+
+/**
+ * Check the WP state. The function depends on the alias 'gpio_wp'. It is used
+ * to replace the enum-name.
+ *
+ * @return true if the WP is active, false otherwise.
+ */
+static inline int write_protect_is_asserted(void)
+{
+#ifdef CONFIG_WP_ALWAYS
+ return true;
+#else
+ return gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_wp));
+#endif
+}
+
+/**
+ * Enable interrupt for WP pin. The interrupt itself has to be defined in a node
+ * with compatible = "cros-ec,gpio-interrupts" and pointed by the alias int_wp.
+ *
+ * @return 0 if success
+ */
+static inline int write_protect_enable_interrupt(void)
+{
+#if DT_NODE_EXISTS(DT_ALIAS(int_wp))
+ return gpio_enable_dt_interrupt(GPIO_INT_FROM_NODE(DT_ALIAS(int_wp)));
+#else
+ return -1;
+#endif
+}
+
+#endif /* __CROS_EC_ZEPHYR_WRITE_PROTECT_H */