summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-01-28 11:53:53 +1100
committerCommit Bot <commit-bot@chromium.org>2022-02-01 02:27:44 +0000
commit3f8b0b1f248dce2caee7b9a0562511f05546ba62 (patch)
tree6c9110cba7037b29f8b65311d71b580436e65b1b
parent713d53c5c50be80e9c9765b30d2def8bcb676f7c (diff)
downloadchrome-ec-3f8b0b1f248dce2caee7b9a0562511f05546ba62.tar.gz
zephyr: Convert wake-pins to use interrupt config
Convert the hibernate wake-pins to use the new interrupt config. BUG=b:214608987,b:216869126 TEST=zmake testall BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Cq-Depend: chromium:3423294,chromium:3423295 Change-Id: Iaaf03da88ead8bce7b2b428c265434a5a17b4ab7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3422856 Reviewed-by: Wai-Hong Tam <waihong@google.com>
-rw-r--r--zephyr/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts4
-rw-r--r--zephyr/drivers/cros_system/cros_system_it8xxx2.c52
-rw-r--r--zephyr/drivers/cros_system/cros_system_npcx.c54
-rw-r--r--zephyr/dts/bindings/gpio/hibernate-wake-pins.yaml4
-rw-r--r--zephyr/include/drivers/cros_system.h28
-rw-r--r--zephyr/projects/asurada/hayato/gpio.dts6
-rw-r--r--zephyr/projects/brya/brya/gpio.dts8
-rw-r--r--zephyr/projects/corsola/gpio_krabby.dts6
-rw-r--r--zephyr/projects/herobrine/gpio.dts13
-rw-r--r--zephyr/projects/nissa/nereid_overlay.dts6
-rw-r--r--zephyr/projects/nissa/nivviks_overlay.dts6
-rw-r--r--zephyr/projects/npcx_evb/npcx7/gpio.dts8
-rw-r--r--zephyr/projects/npcx_evb/npcx9/gpio.dts8
-rw-r--r--zephyr/projects/trogdor/lazor/gpio.dts10
-rw-r--r--zephyr/projects/trogdor/lazor/interrupts.dts5
-rw-r--r--zephyr/projects/trogdor/trogdor/gpio.dts10
-rw-r--r--zephyr/projects/trogdor/trogdor/interrupts.dts5
17 files changed, 142 insertions, 91 deletions
diff --git a/zephyr/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts b/zephyr/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts
index 892bf883eb..33eae64d9b 100644
--- a/zephyr/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts
+++ b/zephyr/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts
@@ -88,8 +88,8 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <&power_button_l
- &lid_open>;
+ wakeup-irqs = <&int_power_button
+ &int_lid_open>;
};
named-adc-channels {
diff --git a/zephyr/drivers/cros_system/cros_system_it8xxx2.c b/zephyr/drivers/cros_system/cros_system_it8xxx2.c
index 5731dcf984..1feb2a84c2 100644
--- a/zephyr/drivers/cros_system/cros_system_it8xxx2.c
+++ b/zephyr/drivers/cros_system/cros_system_it8xxx2.c
@@ -12,6 +12,7 @@
#include <soc/ite_it8xxx2/reg_def_cros.h>
#include "gpio.h"
+#include "gpio/gpio_int.h"
#include "system.h"
#include "util.h"
@@ -153,6 +154,13 @@ static int cros_system_it8xxx2_soc_reset(const struct device *dev)
return 0;
}
+/*
+ * Fake wake ISR handler, needed for pins that do not have a handler.
+ */
+void wake_isr(enum gpio_signal signal)
+{
+}
+
static int cros_system_it8xxx2_hibernate(const struct device *dev,
uint32_t seconds,
uint32_t microseconds)
@@ -203,17 +211,43 @@ static int cros_system_it8xxx2_hibernate(const struct device *dev,
irq_enable(FREE_RUN_TIMER_IRQ);
}
- static const int wakeup_pin_list[] = {
#if DT_NODE_EXISTS(SYSTEM_DT_NODE_HIBERNATE_CONFIG)
- UTIL_LISTIFY(SYSTEM_DT_NODE_WAKEUP_PIN_LEN,
- SYSTEM_DT_WAKEUP_GPIO_ENUM_BY_IDX, _)
-#endif
- };
- /* Reconfigure wake-up GPIOs */
- for (int i = 0; i < ARRAY_SIZE(wakeup_pin_list); i++)
- /* Re-enable interrupt for wake-up inputs */
- gpio_enable_interrupt(wakeup_pin_list[i]);
+/*
+ * Get the interrupt DTS node for this wakeup pin
+ */
+#define WAKEUP_INT(id, prop, idx) DT_PHANDLE_BY_IDX(id, prop, idx)
+
+/*
+ * Get the named-gpio node for this wakeup pin by reading the
+ * irq-gpio property from the interrupt node.
+ */
+#define WAKEUP_NGPIO(id, prop, idx) \
+ DT_PHANDLE(WAKEUP_INT(id, prop, idx), irq_pin)
+
+/*
+ * Reset and re-enable interrupts on this wake pin.
+ */
+#define WAKEUP_SETUP(id, prop, idx) \
+do { \
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODE(WAKEUP_NGPIO(id, prop, idx)), \
+ GPIO_INPUT); \
+ gpio_enable_dt_interrupt( \
+ &GPIO_INT_FROM_NODE(WAKEUP_INT(id, prop, idx))); \
+ } while (0);
+
+/*
+ * For all the wake-pins, re-init the GPIO and re-enable the interrupt.
+ */
+ DT_FOREACH_PROP_ELEM(SYSTEM_DT_NODE_HIBERNATE_CONFIG,
+ wakeup_irqs,
+ WAKEUP_SETUP);
+
+#undef WAKEUP_INT
+#undef WAKEUP_NGPIO
+#undef WAKEUP_SETUP
+
+#endif
/* EC sleep mode */
chip_pll_ctrl(CHIP_PLL_SLEEP);
diff --git a/zephyr/drivers/cros_system/cros_system_npcx.c b/zephyr/drivers/cros_system/cros_system_npcx.c
index e3d3bc29b2..8f75eb47ee 100644
--- a/zephyr/drivers/cros_system/cros_system_npcx.c
+++ b/zephyr/drivers/cros_system/cros_system_npcx.c
@@ -13,6 +13,7 @@
#include <sys/util.h>
#include "gpio.h"
+#include "gpio/gpio_int.h"
#include "rom_chip.h"
#include "soc_gpio.h"
#include "soc_miwu.h"
@@ -141,6 +142,13 @@ static void system_npcx_disable_instant_wakeup(void)
inst_pmc->ENIDL_CTL &= ~BIT(NPCX_ENIDL_CTL_LP_WK_CTL);
}
+/*
+ * Fake wake ISR handler, needed for pins that do not have a handler.
+ */
+void wake_isr(enum gpio_signal signal)
+{
+}
+
static void system_npcx_set_wakeup_gpios_before_hibernate(void)
{
const uintptr_t miwu_base[] = {
@@ -164,19 +172,43 @@ static void system_npcx_set_wakeup_gpios_before_hibernate(void)
}
}
- static const int wakeup_pin_list[] = {
#if DT_NODE_EXISTS(SYSTEM_DT_NODE_HIBERNATE_CONFIG)
- UTIL_LISTIFY(SYSTEM_DT_NODE_WAKEUP_PIN_LEN,
- SYSTEM_DT_WAKEUP_GPIO_ENUM_BY_IDX, _)
-#endif
- };
- /* Reconfigure wake-up GPIOs */
- for (int i = 0; i < ARRAY_SIZE(wakeup_pin_list); i++) {
- gpio_reset(wakeup_pin_list[i]);
- /* Re-enable interrupt for wake-up inputs */
- gpio_enable_interrupt(wakeup_pin_list[i]);
- }
+/*
+ * Get the interrupt DTS node for this wakeup pin
+ */
+#define WAKEUP_INT(id, prop, idx) DT_PHANDLE_BY_IDX(id, prop, idx)
+
+/*
+ * Get the named-gpio node for this wakeup pin by reading the
+ * irq-gpio property from the interrupt node.
+ */
+#define WAKEUP_NGPIO(id, prop, idx) \
+ DT_PHANDLE(WAKEUP_INT(id, prop, idx), irq_pin)
+
+/*
+ * Reset and re-enable interrupts on this wake pin.
+ */
+#define WAKEUP_SETUP(id, prop, idx) \
+do { \
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODE(WAKEUP_NGPIO(id, prop, idx)), \
+ GPIO_INPUT); \
+ gpio_enable_dt_interrupt( \
+ &GPIO_INT_FROM_NODE(WAKEUP_INT(id, prop, idx))); \
+ } while (0);
+
+/*
+ * For all the wake-pins, re-init the GPIO and re-enable the interrupt.
+ */
+ DT_FOREACH_PROP_ELEM(SYSTEM_DT_NODE_HIBERNATE_CONFIG,
+ wakeup_irqs,
+ WAKEUP_SETUP);
+
+#undef WAKEUP_INT
+#undef WAKEUP_NGPIO
+#undef WAKEUP_SETUP
+
+#endif
}
/*
diff --git a/zephyr/dts/bindings/gpio/hibernate-wake-pins.yaml b/zephyr/dts/bindings/gpio/hibernate-wake-pins.yaml
index 64435f7b3b..0d79efa79d 100644
--- a/zephyr/dts/bindings/gpio/hibernate-wake-pins.yaml
+++ b/zephyr/dts/bindings/gpio/hibernate-wake-pins.yaml
@@ -7,7 +7,7 @@ description: Hibernate Wake-up Pins Configurations
compatible: "cros-ec,hibernate-wake-pins"
properties:
- wakeup-pins:
+ wakeup-irqs:
type: phandles
required: true
- description: GPIO list for hibernate wake-up
+ description: Interrupt list for hibernate wake-up
diff --git a/zephyr/include/drivers/cros_system.h b/zephyr/include/drivers/cros_system.h
index 0d2f2f69b2..99c6ba12a7 100644
--- a/zephyr/include/drivers/cros_system.h
+++ b/zephyr/include/drivers/cros_system.h
@@ -47,34 +47,6 @@ enum system_reset_cause {
#define SYSTEM_DT_NODE_HIBERNATE_CONFIG DT_INST(0, cros_ec_hibernate_wake_pins)
/**
- * @brief Get the length of 'wakeup-pins' property
- *
- * @return length of 'wakeup-pins' prop which type is 'phandles'
- */
-#define SYSTEM_DT_NODE_WAKEUP_PIN_LEN \
- DT_PROP_LEN(SYSTEM_DT_NODE_HIBERNATE_CONFIG, wakeup_pins)
-
-/**
- * @brief Get a node identifier from a phandle in property 'wakeup-pins' at
- * index i.
- *
- * @param i index of 'wakeup-pins' prop which type is 'phandles'
- * @return node identifier with that path.
- */
-#define SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i) \
- DT_PHANDLE_BY_IDX(SYSTEM_DT_NODE_HIBERNATE_CONFIG, wakeup_pins, i)
-
-/**
- * @brief Get the enum using in chromium system by index i in 'wakeup-pins'
- * list.
- *
- * @param i index of 'wakeup-pins' prop which type is 'phandles'
- * @return GPIO enumeration
- */
-#define SYSTEM_DT_WAKEUP_GPIO_ENUM_BY_IDX(i, _) \
- GPIO_SIGNAL(SYSTEM_DT_NODE_WAKEUP_PIN_BY_IDX(i)),
-
-/**
* @typedef cros_system_get_reset_cause_api
* @brief Callback API for getting reset cause instance.
* See cros_system_get_reset_cause() for argument descriptions
diff --git a/zephyr/projects/asurada/hayato/gpio.dts b/zephyr/projects/asurada/hayato/gpio.dts
index a39bebe4d7..865eefaec2 100644
--- a/zephyr/projects/asurada/hayato/gpio.dts
+++ b/zephyr/projects/asurada/hayato/gpio.dts
@@ -277,9 +277,9 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <&ac_present
- &power_button_l
- &lid_open>;
+ wakeup-irqs = <&int_ac_present
+ &int_power_button
+ &int_lid_open>;
};
power_signal_list: power-signal-list {
diff --git a/zephyr/projects/brya/brya/gpio.dts b/zephyr/projects/brya/brya/gpio.dts
index a9138cc623..31e17c518b 100644
--- a/zephyr/projects/brya/brya/gpio.dts
+++ b/zephyr/projects/brya/brya/gpio.dts
@@ -330,10 +330,10 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &acok_od
- &gsc_ec_pwr_btn_odl
- &lid_open
+ wakeup-irqs = <
+ &int_ac_present
+ &int_power_button
+ &int_lid_open
>;
};
diff --git a/zephyr/projects/corsola/gpio_krabby.dts b/zephyr/projects/corsola/gpio_krabby.dts
index b2df9bc453..705a08d753 100644
--- a/zephyr/projects/corsola/gpio_krabby.dts
+++ b/zephyr/projects/corsola/gpio_krabby.dts
@@ -241,9 +241,9 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <&ac_present
- &power_button_l
- &lid_open>;
+ wakeup-irqs = <&int_ac_present
+ &int_power_button
+ &int_lid_open>;
};
unused-pins {
diff --git a/zephyr/projects/herobrine/gpio.dts b/zephyr/projects/herobrine/gpio.dts
index cc6260b651..ff3340fdb0 100644
--- a/zephyr/projects/herobrine/gpio.dts
+++ b/zephyr/projects/herobrine/gpio.dts
@@ -275,11 +275,14 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_chg_acok_od
- &gpio_ec_pwr_btn_odl
- &gpio_lid_open_ec
- &gpio_rtc_ec_wake_odl
+ wakeup-irqs = <
+ /*
+ * TODO(b/216893756): Resolve how
+ * hibernation is done.
+ */
+ &int_ac_present
+ &int_power_button
+ &int_lid_open
>;
};
diff --git a/zephyr/projects/nissa/nereid_overlay.dts b/zephyr/projects/nissa/nereid_overlay.dts
index 058dbfdf42..f513594b38 100644
--- a/zephyr/projects/nissa/nereid_overlay.dts
+++ b/zephyr/projects/nissa/nereid_overlay.dts
@@ -14,9 +14,9 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_gsc_ec_pwr_btn_odl
- &gpio_lid_open
+ wakeup-irqs = <
+ &int_power_button
+ &int_lid_open
>;
};
diff --git a/zephyr/projects/nissa/nivviks_overlay.dts b/zephyr/projects/nissa/nivviks_overlay.dts
index 1359025d9a..24b0f6ee03 100644
--- a/zephyr/projects/nissa/nivviks_overlay.dts
+++ b/zephyr/projects/nissa/nivviks_overlay.dts
@@ -14,9 +14,9 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_gsc_ec_pwr_btn_odl
- &gpio_lid_open
+ wakeup-irqs = <
+ &int_power_button
+ &int_lid_open
>;
};
diff --git a/zephyr/projects/npcx_evb/npcx7/gpio.dts b/zephyr/projects/npcx_evb/npcx7/gpio.dts
index 3bfc4f386a..fd9a195673 100644
--- a/zephyr/projects/npcx_evb/npcx7/gpio.dts
+++ b/zephyr/projects/npcx_evb/npcx7/gpio.dts
@@ -60,10 +60,10 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_ac_present
- &gpio_power_button_l
- &gpio_lid_open
+ wakeup-irqs = <
+ &int_ac_present
+ &int_power_button
+ &int_lid_open
>;
};
};
diff --git a/zephyr/projects/npcx_evb/npcx9/gpio.dts b/zephyr/projects/npcx_evb/npcx9/gpio.dts
index 3bfc4f386a..fd9a195673 100644
--- a/zephyr/projects/npcx_evb/npcx9/gpio.dts
+++ b/zephyr/projects/npcx_evb/npcx9/gpio.dts
@@ -60,10 +60,10 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_ac_present
- &gpio_power_button_l
- &gpio_lid_open
+ wakeup-irqs = <
+ &int_ac_present
+ &int_power_button
+ &int_lid_open
>;
};
};
diff --git a/zephyr/projects/trogdor/lazor/gpio.dts b/zephyr/projects/trogdor/lazor/gpio.dts
index b38fea23a5..9e12c97267 100644
--- a/zephyr/projects/trogdor/lazor/gpio.dts
+++ b/zephyr/projects/trogdor/lazor/gpio.dts
@@ -331,11 +331,11 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_acok_od
- &gpio_ec_pwr_btn_odl
- &gpio_lid_open_ec
- &gpio_ec_rst_odl
+ wakeup-irqs = <
+ &int_ac_present
+ &int_power_button
+ &int_lid_open
+ &int_ec_rst
>;
};
diff --git a/zephyr/projects/trogdor/lazor/interrupts.dts b/zephyr/projects/trogdor/lazor/interrupts.dts
index 8ba8f71078..823433e3bb 100644
--- a/zephyr/projects/trogdor/lazor/interrupts.dts
+++ b/zephyr/projects/trogdor/lazor/interrupts.dts
@@ -122,5 +122,10 @@
flags = <GPIO_INT_EDGE_BOTH>;
handler = "gmr_tablet_switch_isr";
};
+ int_ec_rst: ec_rst {
+ irq-pin = <&gpio_ec_rst_odl>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "wake_isr";
+ };
};
};
diff --git a/zephyr/projects/trogdor/trogdor/gpio.dts b/zephyr/projects/trogdor/trogdor/gpio.dts
index 0245ed20c2..16102943a2 100644
--- a/zephyr/projects/trogdor/trogdor/gpio.dts
+++ b/zephyr/projects/trogdor/trogdor/gpio.dts
@@ -289,11 +289,11 @@
hibernate-wake-pins {
compatible = "cros-ec,hibernate-wake-pins";
- wakeup-pins = <
- &gpio_chg_acok_od
- &gpio_ec_pwr_btn_odl
- &gpio_lid_open_ec
- &gpio_ec_rst_odl
+ wakeup-irqs = <
+ &int_ac_present
+ &int_power_button
+ &int_lid_open
+ &int_ec_rst
>;
};
diff --git a/zephyr/projects/trogdor/trogdor/interrupts.dts b/zephyr/projects/trogdor/trogdor/interrupts.dts
index d3514770a3..06f293101f 100644
--- a/zephyr/projects/trogdor/trogdor/interrupts.dts
+++ b/zephyr/projects/trogdor/trogdor/interrupts.dts
@@ -112,5 +112,10 @@
flags = <GPIO_INT_EDGE_BOTH>;
handler = "gmr_tablet_switch_isr";
};
+ int_ec_rst: ec_rst {
+ irq-pin = <&gpio_ec_rst_odl>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "wake_isr";
+ };
};
};