Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 7 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 9 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <drivers/st/stm32mp1_clk.h> |
| 12 | #include <dt-bindings/clock/stm32mp1-clks.h> |
| 13 | #include <lib/mmio.h> |
| 14 | |
Yann Gautier | 4193466 | 2018-07-20 11:36:05 +0200 | [diff] [blame] | 15 | #include <stm32mp1_context.h> |
| 16 | |
| 17 | #define TAMP_BOOT_ITF_BACKUP_REG_ID U(20) |
| 18 | #define TAMP_BOOT_ITF_MASK U(0x0000FF00) |
| 19 | #define TAMP_BOOT_ITF_SHIFT 8 |
| 20 | |
| 21 | int stm32_save_boot_interface(uint32_t interface, uint32_t instance) |
| 22 | { |
| 23 | uint32_t tamp_clk_off = 0; |
| 24 | uint32_t bkpr_itf_idx = tamp_bkpr(TAMP_BOOT_ITF_BACKUP_REG_ID); |
| 25 | |
| 26 | if (!stm32mp1_clk_is_enabled(RTCAPB)) { |
| 27 | tamp_clk_off = 1; |
| 28 | if (stm32mp1_clk_enable(RTCAPB) != 0) { |
| 29 | return -EINVAL; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | mmio_clrsetbits_32(bkpr_itf_idx, |
| 34 | TAMP_BOOT_ITF_MASK, |
| 35 | ((interface << 4) | (instance & 0xFU)) << |
| 36 | TAMP_BOOT_ITF_SHIFT); |
| 37 | |
| 38 | if (tamp_clk_off != 0U) { |
| 39 | if (stm32mp1_clk_disable(RTCAPB) != 0) { |
| 40 | return -EINVAL; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |