xref: /optee_os/core/arch/arm/plat-sam/sam_sfr.c (revision bbbbab0e737faa12ac4c2e6e15d2903dd9c41167)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (C) 2017 Timesys Corporation.
4  * Copyright (C) 2021 Microchip
5  * All rights reserved.
6  */
7 
8 #include <kernel/dt.h>
9 #include <matrix.h>
10 #include <mm/core_memprot.h>
11 #include <mm/core_mmu.h>
12 #include <sam_sfr.h>
13 #include <sama5d2.h>
14 #include <types_ext.h>
15 
16 register_phys_mem_pgdir(MEM_AREA_IO_SEC, SFR_BASE, CORE_MMU_PGDIR_SIZE);
17 
18 vaddr_t sam_sfr_base(void)
19 {
20 	static void *va;
21 
22 	if (!cpu_mmu_enabled())
23 		return SFR_BASE;
24 
25 	if (!va)
26 		va = phys_to_virt(SFR_BASE, MEM_AREA_IO_SEC, 1);
27 
28 	return (vaddr_t)va;
29 }
30 
31 static TEE_Result atmel_sfr_probe(const void *fdt, int node,
32 				  const void *compat_data __unused)
33 {
34 	if (_fdt_get_status(fdt, node) == DT_STATUS_OK_SEC)
35 		matrix_configure_periph_secure(AT91C_ID_SFR);
36 
37 	return TEE_SUCCESS;
38 }
39 
40 static const struct dt_device_match atmel_sfr_match_table[] = {
41 	{ .compatible = "atmel,sama5d2-sfr" },
42 	{ }
43 };
44 
45 DEFINE_DT_DRIVER(atmel_sfr_dt_driver) = {
46 	.name = "atmel_sfr",
47 	.type = DT_DRIVER_NOTYPE,
48 	.match_table = atmel_sfr_match_table,
49 	.probe = atmel_sfr_probe,
50 };
51