blob: fd3f93e017c17d307bdf875f4284b8737032dcac [file] [log] [blame]
Yann Gautier9aea69e2018-07-24 17:13:36 +02001/*
Yann Gautiera2e2a302019-02-14 11:13:39 +01002 * Copyright (c) 2018-2019, STMicroelectronics - All Rights Reserved
Yann Gautier9aea69e2018-07-24 17:13:36 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautier9aea69e2018-07-24 17:13:36 +02007#include <limits.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Yann Gautier9aea69e2018-07-24 17:13:36 +02009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <common/bl_common.h>
12#include <common/debug.h>
Yann Gautier33b1be42019-02-14 09:17:55 +010013#include <drivers/delay_timer.h>
Yann Gautiera2e2a302019-02-14 11:13:39 +010014#include <drivers/st/stm32mp_reset.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <lib/mmio.h>
16#include <lib/utils_def.h>
Yann Gautier9aea69e2018-07-24 17:13:36 +020017
Yann Gautier33b1be42019-02-14 09:17:55 +010018#define RESET_TIMEOUT_US_1MS U(1000)
19
20static uint32_t id2reg_offset(unsigned int reset_id)
21{
22 return ((reset_id & GENMASK(31, 5)) >> 5) * sizeof(uint32_t);
23}
24
25static uint8_t id2reg_bit_pos(unsigned int reset_id)
26{
27 return (uint8_t)(reset_id & GENMASK(4, 0));
28}
Yann Gautier9aea69e2018-07-24 17:13:36 +020029
Yann Gautiera2e2a302019-02-14 11:13:39 +010030void stm32mp_reset_assert(uint32_t id)
Yann Gautier9aea69e2018-07-24 17:13:36 +020031{
Yann Gautier33b1be42019-02-14 09:17:55 +010032 uint32_t offset = id2reg_offset(id);
33 uint32_t bitmsk = BIT(id2reg_bit_pos(id));
34 uint64_t timeout_ref;
Yann Gautier3d78a2e2019-02-14 11:01:20 +010035 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +020036
Yann Gautier33b1be42019-02-14 09:17:55 +010037 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 }
Yann Gautier9aea69e2018-07-24 17:13:36 +020044 }
45}
46
Yann Gautiera2e2a302019-02-14 11:13:39 +010047void stm32mp_reset_deassert(uint32_t id)
Yann Gautier9aea69e2018-07-24 17:13:36 +020048{
Yann Gautier33b1be42019-02-14 09:17:55 +010049 uint32_t offset = id2reg_offset(id) + RCC_RSTCLRR_OFFSET;
50 uint32_t bitmsk = BIT(id2reg_bit_pos(id));
51 uint64_t timeout_ref;
Yann Gautier3d78a2e2019-02-14 11:01:20 +010052 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +020053
Yann Gautier33b1be42019-02-14 09:17:55 +010054 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 }
Yann Gautier9aea69e2018-07-24 17:13:36 +020061 }
62}