blob: f7fbd33cc4b99af1cce437c2c2006836d7d951ef [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>
Simon Glass97589732020-05-10 11:40:02 -06007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Gregory CLEMENTaf05ee52018-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 Vulturc15620a2019-01-17 15:33:27 +010024#if defined(CONFIG_SOC_OCELOT) || defined(CONFIG_SOC_JR2) || \
Horatiu Vultur914e7872019-01-23 16:39:42 +010025 defined(CONFIG_SOC_SERVALT) || defined(CONFIG_SOC_SERVAL)
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010026 if (ret)
27 return ret;
28 ret = hal_vcoreiii_train_bytelane(1);
Gregory CLEMENT819b57212018-12-14 16:16:48 +010029#endif
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010030
31 return ret;
32}
33
34int vcoreiii_ddr_init(void)
35{
Lars Povlsen1470ce22020-02-06 10:45:40 +010036 register int res;
Gregory CLEMENTaf05ee52018-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 Povlsen1470ce22020-02-06 10:45:40 +010045
Gregory CLEMENTaf05ee52018-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 Povlsen1470ce22020-02-06 10:45:40 +010052 /* Remap DDR to kuseg: Clear boot-mode */
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010053 clrbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
54 ICPU_GENERAL_CTRL_BOOT_MODE_ENA);
Lars Povlsen1470ce22020-02-06 10:45:40 +010055 /* - and read-back to activate/verify */
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010056 readl(BASE_CFG + ICPU_GENERAL_CTRL);
Lars Povlsen1470ce22020-02-06 10:45:40 +010057
Gregory CLEMENTaf05ee52018-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 Rinibb4dd962022-11-16 13:10:37 -050070 gd->ram_size = CFG_SYS_SDRAM_SIZE;
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010071 return 0;
72}