stm32mp1_context.c 969 Bytes
Newer Older
1
/*
2
 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <errno.h>
8

9
#include <platform_def.h>
10
11
12
13
14

#include <drivers/st/stm32mp1_clk.h>
#include <dt-bindings/clock/stm32mp1-clks.h>
#include <lib/mmio.h>

15
16
17
18
19
20
21
22
23
24
25
#include <stm32mp1_context.h>

#define TAMP_BOOT_ITF_BACKUP_REG_ID	U(20)
#define TAMP_BOOT_ITF_MASK		U(0x0000FF00)
#define TAMP_BOOT_ITF_SHIFT		8

int stm32_save_boot_interface(uint32_t interface, uint32_t instance)
{
	uint32_t tamp_clk_off = 0;
	uint32_t bkpr_itf_idx = tamp_bkpr(TAMP_BOOT_ITF_BACKUP_REG_ID);

26
	if (!stm32mp_clk_is_enabled(RTCAPB)) {
27
		tamp_clk_off = 1;
28
		if (stm32mp_clk_enable(RTCAPB) != 0) {
29
30
31
32
33
34
35
36
37
38
			return -EINVAL;
		}
	}

	mmio_clrsetbits_32(bkpr_itf_idx,
			   TAMP_BOOT_ITF_MASK,
			   ((interface << 4) | (instance & 0xFU)) <<
			   TAMP_BOOT_ITF_SHIFT);

	if (tamp_clk_off != 0U) {
39
		if (stm32mp_clk_disable(RTCAPB) != 0) {
40
41
42
43
44
45
			return -EINVAL;
		}
	}

	return 0;
}