Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| 2 | /* |
| 3 | * Copyright (c) 2018 Microsemi Corporation |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 9 | |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/types.h> |
| 12 | |
| 13 | #include <mach/tlb.h> |
| 14 | #include <mach/ddr.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static inline int vcoreiii_train_bytelane(void) |
| 19 | { |
| 20 | int ret; |
| 21 | |
| 22 | ret = hal_vcoreiii_train_bytelane(0); |
| 23 | |
Horatiu Vultur | c15620a | 2019-01-17 15:33:27 +0100 | [diff] [blame] | 24 | #if defined(CONFIG_SOC_OCELOT) || defined(CONFIG_SOC_JR2) || \ |
Horatiu Vultur | 914e787 | 2019-01-23 16:39:42 +0100 | [diff] [blame] | 25 | defined(CONFIG_SOC_SERVALT) || defined(CONFIG_SOC_SERVAL) |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 26 | if (ret) |
| 27 | return ret; |
| 28 | ret = hal_vcoreiii_train_bytelane(1); |
Gregory CLEMENT | 819b5721 | 2018-12-14 16:16:48 +0100 | [diff] [blame] | 29 | #endif |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 30 | |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | int vcoreiii_ddr_init(void) |
| 35 | { |
Lars Povlsen | 1470ce2 | 2020-02-06 10:45:40 +0100 | [diff] [blame] | 36 | register int res; |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 37 | |
| 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 Povlsen | 1470ce2 | 2020-02-06 10:45:40 +0100 | [diff] [blame] | 45 | |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 46 | res = dram_check(); |
| 47 | if (res == 0) |
| 48 | hal_vcoreiii_ddr_verified(); |
| 49 | else |
| 50 | hal_vcoreiii_ddr_failed(); |
| 51 | |
Lars Povlsen | 1470ce2 | 2020-02-06 10:45:40 +0100 | [diff] [blame] | 52 | /* Remap DDR to kuseg: Clear boot-mode */ |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 53 | clrbits_le32(BASE_CFG + ICPU_GENERAL_CTRL, |
| 54 | ICPU_GENERAL_CTRL_BOOT_MODE_ENA); |
Lars Povlsen | 1470ce2 | 2020-02-06 10:45:40 +0100 | [diff] [blame] | 55 | /* - and read-back to activate/verify */ |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 56 | readl(BASE_CFG + ICPU_GENERAL_CTRL); |
Lars Povlsen | 1470ce2 | 2020-02-06 10:45:40 +0100 | [diff] [blame] | 57 | |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 58 | return res; |
| 59 | } |
| 60 | |
| 61 | int print_cpuinfo(void) |
| 62 | { |
| 63 | printf("MSCC VCore-III MIPS 24Kec\n"); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | int dram_init(void) |
| 69 | { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 70 | gd->ram_size = CFG_SYS_SDRAM_SIZE; |
Gregory CLEMENT | af05ee5 | 2018-12-14 16:16:47 +0100 | [diff] [blame] | 71 | return 0; |
| 72 | } |