blob: 001747f223dd6b90e8f208e38cae10363226127c [file] [log] [blame]
Tom Rinidec7ea02024-05-20 13:35:03 -06001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * (C) Copyright 2024 - Analog Devices, Inc.
4 *
5 * Written and/or maintained by Timesys Corporation
6 *
7 * Contact: Nathan Barrett-Morrison <nathan.morrison@timesys.com>
8 * Contact: Greg Malysa <greg.malysa@timesys.com>
9 */
10
11#include <asm/io.h>
Oliver Gaskelld4f7cb52024-09-12 16:50:54 +010012#include <asm/armv8/mmu.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060013#include <asm/arch-adi/sc5xx/sc5xx.h>
14#include <asm/arch-adi/sc5xx/spl.h>
15
16#define REG_TSGENWR0_CNTCR 0x310AE000
17#define REG_PADS0_PCFG0 0x31004604
18#define REG_RCU0_BCODE 0x3108C028
19
20#define REG_SPU0_SECUREP_START 0x3108BA00
21#define REG_SPU0_WP_START 0x3108B400
22#define REG_SPU0_SECUREC0 0x3108B980
23
24#define REG_SCB5_SPI2_OSPI_REMAP 0x30400000
25#define BITM_SCB5_SPI2_OSPI_REMAP_REMAP 0x00000003
26#define ENUM_SCB5_SPI2_OSPI_REMAP_OSPI0 0x00000001
27
Oliver Gaskelld4f7cb52024-09-12 16:50:54 +010028static struct mm_region sc598_mem_map[] = {
29 {
30 /* Peripherals */
31 .virt = 0x0UL,
32 .phys = 0x0UL,
33 .size = 0x80000000UL,
34 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
35 PTE_BLOCK_NON_SHARE |
36 PTE_BLOCK_PXN | PTE_BLOCK_UXN
37 }, {
38 /* DDR */
39 .virt = 0x80000000UL,
40 .phys = 0x80000000UL,
41 .size = 0x40000000UL,
42 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
43 PTE_BLOCK_INNER_SHARE
44 }, {
45 /* List terminator */
46 0,
47 }
48};
49
50struct mm_region *mem_map = sc598_mem_map;
51
Tom Rinidec7ea02024-05-20 13:35:03 -060052adi_rom_boot_fn adi_rom_boot = (adi_rom_boot_fn)0x000000e4;
53
54void sc5xx_enable_rgmii(void)
55{
56 writel((readl(REG_PADS0_PCFG0) | 0xc), REG_PADS0_PCFG0);
57
58 // Set dw for little endian operation as well
59 writel(readl(REG_PADS0_PCFG0) & ~(1 << 19), REG_PADS0_PCFG0);
60 writel(readl(REG_PADS0_PCFG0) & ~(1 << 20), REG_PADS0_PCFG0);
61}
62
63void sc59x_remap_ospi(void)
64{
65 clrsetbits_le32(REG_SCB5_SPI2_OSPI_REMAP,
66 BITM_SCB5_SPI2_OSPI_REMAP_REMAP,
67 ENUM_SCB5_SPI2_OSPI_REMAP_OSPI0);
68}
69
70/**
71 * SPU/SMPU configuration is the default for permissive access from non-secure
72 * EL1. If TFA and OPTEE are configured, they run *after* this code, as the
73 * current boot flow is SPL -> TFA -> OPTEE -> Proper -> Linux, and will
74 * be expected to configure peripheral security correctly. If they are not
75 * configured, then this permissive setting will allow Linux (which always
76 * runs in NS EL1) to control all access to these peripherals. Without it,
77 * the peripherals would simply be unavailable in a non-security build,
78 * which is not OK.
79 */
80void sc5xx_soc_init(void)
81{
82 phys_addr_t smpus[] = {
83 0x31007800, //SMPU0
84 0x31083800, //SMPU2
85 0x31084800, //SMPU3
86 0x31085800, //SMPU4
87 0x31086800, //SMPU5
88 0x31087800, //SMPU6
89 0x310A0800, //SMPU9
90 0x310A1800, //SMPU11
91 0x31012800, //SMPU12
92 };
93 size_t i;
94
95 // Enable coresight timer
96 writel(1, REG_TSGENWR0_CNTCR);
97
98 //Do not rerun preboot routine --
99 // Without this, hardware resets triggered by RCU0_CTL:SYSRST
100 // lead to a deadlock somewhere in the boot ROM
101 writel(0x200, REG_RCU0_BCODE);
102
103 /* Alter outstanding transactions property of A55*/
104 writel(0x1, 0x30643108); /* SCB6 A55 M0 Ib.fn Mod */
105 isb();
106
107 /* configure DDR prefetch behavior, per ADI */
108 writel(0x1, 0x31076000);
109
110 /* configure smart mode, per ADI */
111 writel(0x1307, 0x31076004);
112
113 // Disable SPU and SPU WP registers
114 sc5xx_disable_spu0(REG_SPU0_SECUREP_START, REG_SPU0_SECUREP_START + 4*213);
115 sc5xx_disable_spu0(REG_SPU0_WP_START, REG_SPU0_WP_START + 4*213);
116
117 /* configure smpus permissively */
118 for (i = 0; i < ARRAY_SIZE(smpus); ++i)
119 writel(0x500, smpus[i]);
120
121 sc5xx_enable_ns_sharc_access(REG_SPU0_SECUREC0);
122}