aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Gautier <yann.gautier@st.com>2019-02-14 09:17:55 +0100
committerYann Gautier <yann.gautier@st.com>2019-02-14 11:20:23 +0100
commit5202cb393da7f6f3a9cf48a49e2a12f3bdee2b16 (patch)
tree764737f2f4ad38e55410e4b74836e3dfa898cd85
parent7ae58c6ba79fee3cc032aae2105b073304409ebc (diff)
downloadtrusted-firmware-a-5202cb393da7f6f3a9cf48a49e2a12f3bdee2b16.tar.gz
stm32mp1: add timeout detection in reset driver
This change makes the platform to panic in case of peripheral reset resource malfunction. Change-Id: I17eb9cb045b78a4e5142a8c33b744e84992d732a Signed-off-by: Yann Gautier <yann.gautier@st.com> Signed-off-by: Etienne Carriere <etienne.carriere@st.com> Signed-off-by: Nicolas LE BAYON <nicolas.le.bayon@st.com>
-rw-r--r--drivers/st/reset/stm32mp1_reset.c44
-rw-r--r--include/drivers/st/stm32mp1_rcc.h3
2 files changed, 35 insertions, 12 deletions
diff --git a/drivers/st/reset/stm32mp1_reset.c b/drivers/st/reset/stm32mp1_reset.c
index b2de76085d..fd3f93e017 100644
--- a/drivers/st/reset/stm32mp1_reset.c
+++ b/drivers/st/reset/stm32mp1_reset.c
@@ -10,33 +10,53 @@
#include <common/bl_common.h>
#include <common/debug.h>
+#include <drivers/delay_timer.h>
#include <drivers/st/stm32mp_reset.h>
#include <lib/mmio.h>
#include <lib/utils_def.h>
-#define RST_CLR_OFFSET 4U
+#define RESET_TIMEOUT_US_1MS U(1000)
+
+static uint32_t id2reg_offset(unsigned int reset_id)
+{
+ return ((reset_id & GENMASK(31, 5)) >> 5) * sizeof(uint32_t);
+}
+
+static uint8_t id2reg_bit_pos(unsigned int reset_id)
+{
+ return (uint8_t)(reset_id & GENMASK(4, 0));
+}
void stm32mp_reset_assert(uint32_t id)
{
- uint32_t offset = (id / (uint32_t)__LONG_BIT) * sizeof(uintptr_t);
- uint32_t bit = id % (uint32_t)__LONG_BIT;
+ uint32_t offset = id2reg_offset(id);
+ uint32_t bitmsk = BIT(id2reg_bit_pos(id));
+ uint64_t timeout_ref;
uintptr_t rcc_base = stm32mp_rcc_base();
- mmio_write_32(rcc_base + offset, BIT(bit));
- while ((mmio_read_32(rcc_base + offset) & BIT(bit)) == 0U) {
- ;
+ mmio_write_32(rcc_base + offset, bitmsk);
+
+ timeout_ref = timeout_init_us(RESET_TIMEOUT_US_1MS);
+ while ((mmio_read_32(rcc_base + offset) & bitmsk) == 0U) {
+ if (timeout_elapsed(timeout_ref)) {
+ panic();
+ }
}
}
void stm32mp_reset_deassert(uint32_t id)
{
- uint32_t offset = ((id / (uint32_t)__LONG_BIT) * sizeof(uintptr_t)) +
- RST_CLR_OFFSET;
- uint32_t bit = id % (uint32_t)__LONG_BIT;
+ uint32_t offset = id2reg_offset(id) + RCC_RSTCLRR_OFFSET;
+ uint32_t bitmsk = BIT(id2reg_bit_pos(id));
+ uint64_t timeout_ref;
uintptr_t rcc_base = stm32mp_rcc_base();
- mmio_write_32(rcc_base + offset, BIT(bit));
- while ((mmio_read_32(rcc_base + offset) & BIT(bit)) != 0U) {
- ;
+ mmio_write_32(rcc_base + offset, bitmsk);
+
+ timeout_ref = timeout_init_us(RESET_TIMEOUT_US_1MS);
+ while ((mmio_read_32(rcc_base + offset) & bitmsk) != 0U) {
+ if (timeout_elapsed(timeout_ref)) {
+ panic();
+ }
}
}
diff --git a/include/drivers/st/stm32mp1_rcc.h b/include/drivers/st/stm32mp1_rcc.h
index 2f29e84d59..1922c48154 100644
--- a/include/drivers/st/stm32mp1_rcc.h
+++ b/include/drivers/st/stm32mp1_rcc.h
@@ -280,6 +280,9 @@
/* Offset between RCC_MP_xxxENSETR and RCC_MP_xxxENCLRR registers */
#define RCC_MP_ENCLRR_OFFSET U(4)
+/* Offset between RCC_xxxRSTSETR and RCC_xxxRSTCLRR registers */
+#define RCC_RSTCLRR_OFFSET U(4)
+
/* Fields of RCC_BDCR register */
#define RCC_BDCR_LSEON BIT(0)
#define RCC_BDCR_LSEBYP BIT(1)