blob: 7c71cbdd55a91bf82d730ce44e27dce872fb5106 [file] [log] [blame]
Peng Fanbbcd2c42022-07-26 16:40:39 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2022 NXP
4 *
5 * Peng Fan <peng.fan@nxp.com>
6 */
7
8#include <common.h>
9#include <cpu_func.h>
10#include <init.h>
11#include <log.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/global_data.h>
14#include <asm/io.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/sys_proto.h>
Ye Li62185922022-07-26 16:40:54 +080017#include <asm/arch/trdc.h>
Peng Fanbbcd2c42022-07-26 16:40:39 +080018#include <asm/mach-imx/boot_mode.h>
19#include <asm/mach-imx/syscounter.h>
20#include <asm/armv8/mmu.h>
21#include <dm/uclass.h>
22#include <env.h>
23#include <env_internal.h>
24#include <errno.h>
25#include <fdt_support.h>
26#include <linux/bitops.h>
27#include <asm/setup.h>
28#include <asm/bootm.h>
29#include <asm/arch-imx/cpu.h>
30
31DECLARE_GLOBAL_DATA_PTR;
32
Peng Fan5de0fc02022-07-26 16:40:48 +080033struct rom_api *g_rom_api = (struct rom_api *)0x1980;
34
35#ifdef CONFIG_ENV_IS_IN_MMC
36__weak int board_mmc_get_env_dev(int devno)
37{
38 return devno; }
39
40int mmc_get_env_dev(void)
41{
42 volatile gd_t *pgd = gd;
43 int ret;
44 u32 boot;
45 u16 boot_type;
46 u8 boot_instance;
47
48 ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, &boot,
49 ((uintptr_t)&boot) ^ QUERY_BT_DEV);
50 set_gd(pgd);
51
52 if (ret != ROM_API_OKAY) {
53 puts("ROMAPI: failure at query_boot_info\n");
54 return CONFIG_SYS_MMC_ENV_DEV;
55 }
56
57 boot_type = boot >> 16;
58 boot_instance = (boot >> 8) & 0xff;
59
60 debug("boot_type %d, instance %d\n", boot_type, boot_instance);
61
62 /* If not boot from sd/mmc, use default value */
63 if (boot_type != BOOT_TYPE_SD && boot_type != BOOT_TYPE_MMC)
64 return env_get_ulong("mmcdev", 10, CONFIG_SYS_MMC_ENV_DEV);
65
66 return board_mmc_get_env_dev(boot_instance);
67}
68#endif
69
Peng Fanbbcd2c42022-07-26 16:40:39 +080070u32 get_cpu_rev(void)
71{
72 return (MXC_CPU_IMX93 << 12) | CHIP_REV_1_0;
73}
74
Ye Li9e19ff92022-07-26 16:40:47 +080075#define UNLOCK_WORD 0xD928C520 /* unlock word */
76#define REFRESH_WORD 0xB480A602 /* refresh word */
77
78static void disable_wdog(void __iomem *wdog_base)
79{
80 u32 val_cs = readl(wdog_base + 0x00);
81
82 if (!(val_cs & 0x80))
83 return;
84
85 /* default is 32bits cmd */
86 writel(REFRESH_WORD, (wdog_base + 0x04)); /* Refresh the CNT */
87
88 if (!(val_cs & 0x800)) {
89 writel(UNLOCK_WORD, (wdog_base + 0x04));
90 while (!(readl(wdog_base + 0x00) & 0x800))
91 ;
92 }
93 writel(0x0, (wdog_base + 0x0C)); /* Set WIN to 0 */
94 writel(0x400, (wdog_base + 0x08)); /* Set timeout to default 0x400 */
95 writel(0x2120, (wdog_base + 0x00)); /* Disable it and set update */
96
97 while (!(readl(wdog_base + 0x00) & 0x400))
98 ;
99}
100
101void init_wdog(void)
102{
103 u32 src_val;
104
105 disable_wdog((void __iomem *)WDG3_BASE_ADDR);
106 disable_wdog((void __iomem *)WDG4_BASE_ADDR);
107 disable_wdog((void __iomem *)WDG5_BASE_ADDR);
108
109 src_val = readl(0x54460018); /* reset mask */
110 src_val &= ~0x1c;
111 writel(src_val, 0x54460018);
112}
113
Peng Fanbbcd2c42022-07-26 16:40:39 +0800114static struct mm_region imx93_mem_map[] = {
115 {
116 /* ROM */
117 .virt = 0x0UL,
118 .phys = 0x0UL,
119 .size = 0x100000UL,
120 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
121 PTE_BLOCK_OUTER_SHARE
122 }, {
123 /* OCRAM */
124 .virt = 0x20480000UL,
125 .phys = 0x20480000UL,
126 .size = 0xA0000UL,
127 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
128 PTE_BLOCK_OUTER_SHARE
129 }, {
130 /* AIPS */
131 .virt = 0x40000000UL,
132 .phys = 0x40000000UL,
133 .size = 0x40000000UL,
134 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
135 PTE_BLOCK_NON_SHARE |
136 PTE_BLOCK_PXN | PTE_BLOCK_UXN
137 }, {
138 /* Flexible Serial Peripheral Interface */
139 .virt = 0x28000000UL,
140 .phys = 0x28000000UL,
141 .size = 0x30000000UL,
142 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
143 PTE_BLOCK_NON_SHARE |
144 PTE_BLOCK_PXN | PTE_BLOCK_UXN
145 }, {
146 /* DRAM1 */
147 .virt = 0x80000000UL,
148 .phys = 0x80000000UL,
149 .size = PHYS_SDRAM_SIZE,
150 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
151 PTE_BLOCK_OUTER_SHARE
152 }, {
153 /* empty entrie to split table entry 5 if needed when TEEs are used */
154 0,
155 }, {
156 /* List terminator */
157 0,
158 }
159};
160
161struct mm_region *mem_map = imx93_mem_map;
162
163int dram_init(void)
164{
165 gd->ram_size = PHYS_SDRAM_SIZE;
166
167 return 0;
168}
169
170void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
171{
172 mac[0] = 0x1;
173 mac[1] = 0x2;
174 mac[2] = 0x3;
175 mac[3] = 0x4;
176 mac[4] = 0x5;
177 mac[5] = 0x6;
178}
179
180int print_cpuinfo(void)
181{
182 u32 cpurev;
183
184 cpurev = get_cpu_rev();
185
186 printf("CPU: i.MX93 rev%d.%d\n", (cpurev & 0x000F0) >> 4, (cpurev & 0x0000F) >> 0);
187
188 return 0;
189}
190
191int arch_misc_init(void)
192{
193 return 0;
194}
195
196int ft_system_setup(void *blob, struct bd_info *bd)
197{
198 return 0;
199}
200
201int arch_cpu_init(void)
202{
Ye Li9e19ff92022-07-26 16:40:47 +0800203 if (IS_ENABLED(CONFIG_SPL_BUILD)) {
204 /* Disable wdog */
205 init_wdog();
206
Peng Fan28b5cb52022-07-26 16:40:43 +0800207 clock_init();
Ye Li62185922022-07-26 16:40:54 +0800208
209 trdc_early_init();
Ye Li9e19ff92022-07-26 16:40:47 +0800210 }
Peng Fan28b5cb52022-07-26 16:40:43 +0800211
Peng Fanbbcd2c42022-07-26 16:40:39 +0800212 return 0;
213}
Jian Liacf41a32022-07-26 16:40:46 +0800214
215int timer_init(void)
216{
217#ifdef CONFIG_SPL_BUILD
218 struct sctr_regs *sctr = (struct sctr_regs *)SYSCNT_CTRL_BASE_ADDR;
219 unsigned long freq = readl(&sctr->cntfid0);
220
221 /* Update with accurate clock frequency */
222 asm volatile("msr cntfrq_el0, %0" : : "r" (freq) : "memory");
223
224 clrsetbits_le32(&sctr->cntcr, SC_CNTCR_FREQ0 | SC_CNTCR_FREQ1,
225 SC_CNTCR_FREQ0 | SC_CNTCR_ENABLE | SC_CNTCR_HDBG);
226#endif
227
228 gd->arch.tbl = 0;
229 gd->arch.tbu = 0;
230
231 return 0;
232}