blob: c43f7a585bf8a51f9bb7870919f88fd401891c5f [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
6#include <common.h>
7
8#include <asm/io.h>
9#include <asm/types.h>
10
11#include <mach/tlb.h>
12#include <mach/ddr.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16static inline int vcoreiii_train_bytelane(void)
17{
18 int ret;
19
20 ret = hal_vcoreiii_train_bytelane(0);
21
Horatiu Vulturc15620a2019-01-17 15:33:27 +010022#if defined(CONFIG_SOC_OCELOT) || defined(CONFIG_SOC_JR2) || \
Horatiu Vultur914e7872019-01-23 16:39:42 +010023 defined(CONFIG_SOC_SERVALT) || defined(CONFIG_SOC_SERVAL)
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010024 if (ret)
25 return ret;
26 ret = hal_vcoreiii_train_bytelane(1);
Gregory CLEMENT819b57212018-12-14 16:16:48 +010027#endif
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010028
29 return ret;
30}
31
32int vcoreiii_ddr_init(void)
33{
34 int res;
35
36 if (!(readl(BASE_CFG + ICPU_MEMCTRL_STAT)
37 & ICPU_MEMCTRL_STAT_INIT_DONE)) {
38 hal_vcoreiii_init_memctl();
39 hal_vcoreiii_wait_memctl();
40 if (hal_vcoreiii_init_dqs() || vcoreiii_train_bytelane())
41 hal_vcoreiii_ddr_failed();
42 }
43#if (CONFIG_SYS_TEXT_BASE != 0x20000000)
44 res = dram_check();
45 if (res == 0)
46 hal_vcoreiii_ddr_verified();
47 else
48 hal_vcoreiii_ddr_failed();
49
50 /* Clear boot-mode and read-back to activate/verify */
51 clrbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
52 ICPU_GENERAL_CTRL_BOOT_MODE_ENA);
53 readl(BASE_CFG + ICPU_GENERAL_CTRL);
54#else
55 res = 0;
56#endif
57 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{
69 while (vcoreiii_ddr_init())
70 ;
71
72 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
73 return 0;
74}