blob: 87aaf86524661e9f690ad20f29151bffdbc0944e [file] [log] [blame]
Yanhong Wange28ec342023-03-29 11:42:08 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2022 StarFive Technology Co., Ltd.
4 * Author: Yanhong Wang<yanhong.wang@starfivetech.com>
5 */
Yanhong Wangf69a5122023-06-15 17:36:51 +08006#include <asm/arch/eeprom.h>
Yanhong Wange28ec342023-03-29 11:42:08 +08007#include <asm/csr.h>
8#include <asm/sections.h>
9#include <dm.h>
Yanhong Wangf69a5122023-06-15 17:36:51 +080010#include <linux/sizes.h>
Yanhong Wange28ec342023-03-29 11:42:08 +080011#include <log.h>
Yanhong Wangf69a5122023-06-15 17:36:51 +080012#include <init.h>
Yanhong Wange28ec342023-03-29 11:42:08 +080013
14#define CSR_U74_FEATURE_DISABLE 0x7c1
Yanhong Wange28ec342023-03-29 11:42:08 +080015
Yanhong Wangf69a5122023-06-15 17:36:51 +080016DECLARE_GLOBAL_DATA_PTR;
17
18static bool check_ddr_size(phys_size_t size)
19{
20 switch (size) {
21 case SZ_2:
22 case SZ_4:
23 case SZ_8:
24 case SZ_16:
25 return true;
26 default:
27 return false;
28 }
29}
30
Lukas Funke2b62dd62024-04-24 09:43:39 +020031int spl_dram_init(void)
Yanhong Wange28ec342023-03-29 11:42:08 +080032{
33 int ret;
34 struct udevice *dev;
Yanhong Wangf69a5122023-06-15 17:36:51 +080035 phys_size_t size;
36
37 ret = fdtdec_setup_mem_size_base();
38 if (ret)
39 return ret;
40
41 /* Read the definition of the DDR size from eeprom, and if not,
42 * use the definition in DT
43 */
44 size = (get_ddr_size_from_eeprom() >> 16) & 0xFF;
45 if (check_ddr_size(size))
46 gd->ram_size = size << 30;
Yanhong Wange28ec342023-03-29 11:42:08 +080047
48 /* DDR init */
49 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
50 if (ret) {
51 debug("DRAM init failed: %d\n", ret);
52 return ret;
53 }
54
55 return 0;
56}
57
58void harts_early_init(void)
59{
Yanhong Wange28ec342023-03-29 11:42:08 +080060 /*
61 * Feature Disable CSR
62 *
63 * Clear feature disable CSR to '0' to turn on all features for
64 * each core. This operation must be in M-mode.
65 */
66 if (CONFIG_IS_ENABLED(RISCV_MMODE))
67 csr_write(CSR_U74_FEATURE_DISABLE, 0);
Yanhong Wange28ec342023-03-29 11:42:08 +080068}