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