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 <io.h>
9 #include <kernel/dt.h>
10 #include <matrix.h>
11 #include <mm/core_memprot.h>
12 #include <mm/core_mmu.h>
13 #include <sam_sfr.h>
14 #include <sama5d2.h>
15 #include <types_ext.h>
16
17 register_phys_mem_pgdir(MEM_AREA_IO_SEC, SFR_BASE, CORE_MMU_PGDIR_SIZE);
18
sam_sfr_base(void)19 vaddr_t sam_sfr_base(void)
20 {
21 static void *va;
22
23 if (!cpu_mmu_enabled())
24 return SFR_BASE;
25
26 if (!va)
27 va = phys_to_virt(SFR_BASE, MEM_AREA_IO_SEC, 1);
28
29 return (vaddr_t)va;
30 }
31
atmel_sfr_set_usb_suspend(bool set)32 void atmel_sfr_set_usb_suspend(bool set)
33 {
34 if (set)
35 io_setbits32(sam_sfr_base() + AT91_SFR_OHCIICR,
36 AT91_OHCIICR_USB_SUSPEND);
37 else
38 io_clrbits32(sam_sfr_base() + AT91_SFR_OHCIICR,
39 AT91_OHCIICR_USB_SUSPEND);
40 }
41
atmel_sfr_probe(const void * fdt,int node,const void * compat_data __unused)42 static TEE_Result atmel_sfr_probe(const void *fdt, int node,
43 const void *compat_data __unused)
44 {
45 if (_fdt_get_status(fdt, node) == DT_STATUS_OK_SEC)
46 matrix_configure_periph_secure(AT91C_ID_SFR);
47
48 return TEE_SUCCESS;
49 }
50
51 static const struct dt_device_match atmel_sfr_match_table[] = {
52 { .compatible = "atmel,sama5d2-sfr" },
53 { }
54 };
55
56 DEFINE_DT_DRIVER(atmel_sfr_dt_driver) = {
57 .name = "atmel_sfr",
58 .type = DT_DRIVER_NOTYPE,
59 .match_table = atmel_sfr_match_table,
60 .probe = atmel_sfr_probe,
61 };
62