blob: f7fbd33cc4b99af1cce437c2c2006836d7d951ef [file] [log] [blame]
Gregory CLEMENTdd1033e2018-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>
Simon Glass691d7192020-05-10 11:40:02 -06007#include <init.h>
Simon Glass401d1c42020-10-30 21:38:53 -06008#include <asm/global_data.h>
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +01009
10#include <asm/io.h>
11#include <asm/types.h>
12
13#include <mach/tlb.h>
14#include <mach/ddr.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18static inline int vcoreiii_train_bytelane(void)
19{
20 int ret;
21
22 ret = hal_vcoreiii_train_bytelane(0);
23
Horatiu Vultur05512512019-01-17 15:33:27 +010024#if defined(CONFIG_SOC_OCELOT) || defined(CONFIG_SOC_JR2) || \
Horatiu Vultur1895b872019-01-23 16:39:42 +010025 defined(CONFIG_SOC_SERVALT) || defined(CONFIG_SOC_SERVAL)
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010026 if (ret)
27 return ret;
28 ret = hal_vcoreiii_train_bytelane(1);
Gregory CLEMENT6bd82312018-12-14 16:16:48 +010029#endif
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010030
31 return ret;
32}
33
34int vcoreiii_ddr_init(void)
35{
Lars Povlsen7048bb12020-02-06 10:45:40 +010036 register int res;
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010037
38 if (!(readl(BASE_CFG + ICPU_MEMCTRL_STAT)
39 & ICPU_MEMCTRL_STAT_INIT_DONE)) {
40 hal_vcoreiii_init_memctl();
41 hal_vcoreiii_wait_memctl();
42 if (hal_vcoreiii_init_dqs() || vcoreiii_train_bytelane())
43 hal_vcoreiii_ddr_failed();
44 }
Lars Povlsen7048bb12020-02-06 10:45:40 +010045
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010046 res = dram_check();
47 if (res == 0)
48 hal_vcoreiii_ddr_verified();
49 else
50 hal_vcoreiii_ddr_failed();
51
Lars Povlsen7048bb12020-02-06 10:45:40 +010052 /* Remap DDR to kuseg: Clear boot-mode */
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010053 clrbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
54 ICPU_GENERAL_CTRL_BOOT_MODE_ENA);
Lars Povlsen7048bb12020-02-06 10:45:40 +010055 /* - and read-back to activate/verify */
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010056 readl(BASE_CFG + ICPU_GENERAL_CTRL);
Lars Povlsen7048bb12020-02-06 10:45:40 +010057
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010058 return res;
59}
60
61int print_cpuinfo(void)
62{
63 printf("MSCC VCore-III MIPS 24Kec\n");
64
65 return 0;
66}
67
68int dram_init(void)
69{
Tom Riniaa6e94d2022-11-16 13:10:37 -050070 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Gregory CLEMENTdd1033e2018-12-14 16:16:47 +010071 return 0;
72}