blob: c7c2040a11ab414d7780e4588b9ad43b80210d91 [file] [log] [blame]
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +01001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2018 Microsemi Corporation
4 */
5
Simon Glass97589732020-05-10 11:40:02 -06006#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06007#include <asm/global_data.h>
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +01008
9#include <asm/io.h>
10#include <asm/types.h>
11
12#include <mach/tlb.h>
13#include <mach/ddr.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static inline int vcoreiii_train_bytelane(void)
18{
19 int ret;
20
21 ret = hal_vcoreiii_train_bytelane(0);
22
Horatiu Vulturc15620a2019-01-17 15:33:27 +010023#if defined(CONFIG_SOC_OCELOT) || defined(CONFIG_SOC_JR2) || \
Horatiu Vultur914e7872019-01-23 16:39:42 +010024 defined(CONFIG_SOC_SERVALT) || defined(CONFIG_SOC_SERVAL)
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010025 if (ret)
26 return ret;
27 ret = hal_vcoreiii_train_bytelane(1);
Gregory CLEMENT819b57212018-12-14 16:16:48 +010028#endif
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010029
30 return ret;
31}
32
33int vcoreiii_ddr_init(void)
34{
Lars Povlsen1470ce22020-02-06 10:45:40 +010035 register int res;
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010036
37 if (!(readl(BASE_CFG + ICPU_MEMCTRL_STAT)
38 & ICPU_MEMCTRL_STAT_INIT_DONE)) {
39 hal_vcoreiii_init_memctl();
40 hal_vcoreiii_wait_memctl();
41 if (hal_vcoreiii_init_dqs() || vcoreiii_train_bytelane())
42 hal_vcoreiii_ddr_failed();
43 }
Lars Povlsen1470ce22020-02-06 10:45:40 +010044
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010045 res = dram_check();
46 if (res == 0)
47 hal_vcoreiii_ddr_verified();
48 else
49 hal_vcoreiii_ddr_failed();
50
Lars Povlsen1470ce22020-02-06 10:45:40 +010051 /* Remap DDR to kuseg: Clear boot-mode */
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010052 clrbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
53 ICPU_GENERAL_CTRL_BOOT_MODE_ENA);
Lars Povlsen1470ce22020-02-06 10:45:40 +010054 /* - and read-back to activate/verify */
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010055 readl(BASE_CFG + ICPU_GENERAL_CTRL);
Lars Povlsen1470ce22020-02-06 10:45:40 +010056
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010057 return res;
58}
59
60int print_cpuinfo(void)
61{
62 printf("MSCC VCore-III MIPS 24Kec\n");
63
64 return 0;
65}
66
67int dram_init(void)
68{
Tom Rinibb4dd962022-11-16 13:10:37 -050069 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010070 return 0;
71}