1 /* 2 * Copyright (c) 2018-2019, STMicroelectronics - All Rights Reserved 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <limits.h> 8 9 #include <platform_def.h> 10 11 #include <common/bl_common.h> 12 #include <common/debug.h> 13 #include <drivers/delay_timer.h> 14 #include <drivers/st/stm32mp_reset.h> 15 #include <lib/mmio.h> 16 #include <lib/utils_def.h> 17 18 #define RESET_TIMEOUT_US_1MS U(1000) 19 id2reg_offset(unsigned int reset_id)20static uint32_t id2reg_offset(unsigned int reset_id) 21 { 22 return ((reset_id & GENMASK(31, 5)) >> 5) * sizeof(uint32_t); 23 } 24 id2reg_bit_pos(unsigned int reset_id)25static uint8_t id2reg_bit_pos(unsigned int reset_id) 26 { 27 return (uint8_t)(reset_id & GENMASK(4, 0)); 28 } 29 stm32mp_reset_assert(uint32_t id)30void stm32mp_reset_assert(uint32_t id) 31 { 32 uint32_t offset = id2reg_offset(id); 33 uint32_t bitmsk = BIT(id2reg_bit_pos(id)); 34 uint64_t timeout_ref; 35 uintptr_t rcc_base = stm32mp_rcc_base(); 36 37 mmio_write_32(rcc_base + offset, bitmsk); 38 39 timeout_ref = timeout_init_us(RESET_TIMEOUT_US_1MS); 40 while ((mmio_read_32(rcc_base + offset) & bitmsk) == 0U) { 41 if (timeout_elapsed(timeout_ref)) { 42 panic(); 43 } 44 } 45 } 46 stm32mp_reset_deassert(uint32_t id)47void stm32mp_reset_deassert(uint32_t id) 48 { 49 uint32_t offset = id2reg_offset(id) + RCC_RSTCLRR_OFFSET; 50 uint32_t bitmsk = BIT(id2reg_bit_pos(id)); 51 uint64_t timeout_ref; 52 uintptr_t rcc_base = stm32mp_rcc_base(); 53 54 mmio_write_32(rcc_base + offset, bitmsk); 55 56 timeout_ref = timeout_init_us(RESET_TIMEOUT_US_1MS); 57 while ((mmio_read_32(rcc_base + offset) & bitmsk) != 0U) { 58 if (timeout_elapsed(timeout_ref)) { 59 panic(); 60 } 61 } 62 } 63