1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * (C) Copyright 2018 Rockchip Electronics Co., Ltd. 4 */ 5 6 #include <common.h> 7 #include <dm.h> 8 #include <ram.h> 9 #include <syscon.h> 10 #include <asm/arch/clock.h> 11 #include <asm/arch/grf_px30.h> 12 #include <asm/arch/grf_rk1808.h> 13 #include <asm/arch/grf_rk3036.h> 14 #include <asm/arch/grf_rk3308.h> 15 #include <asm/arch/sdram_common.h> 16 17 DECLARE_GLOBAL_DATA_PTR; 18 19 #ifndef CONFIG_TPL_BUILD 20 struct dram_info { 21 struct ram_info info; 22 }; 23 24 static int dmc_probe(struct udevice *dev) 25 { 26 struct dram_info *priv = dev_get_priv(dev); 27 28 #if defined(CONFIG_ROCKCHIP_RK3036) 29 struct rk3036_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); 30 31 priv->info.size = rockchip_sdram_size((phys_addr_t)&grf->os_reg[1]); 32 #elif defined(CONFIG_ROCKCHIP_RK3308) 33 struct rk3308_grf *grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); 34 35 priv->info.size = rockchip_sdram_size((phys_addr_t)&grf->os_reg2); 36 #elif defined(CONFIG_ROCKCHIP_PX30) 37 struct px30_pmugrf *pmugrf = 38 syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); 39 40 priv->info.size = 41 rockchip_sdram_size((phys_addr_t)&pmugrf->os_reg[2]); 42 #elif defined(CONFIG_ROCKCHIP_RK1808) 43 struct rk1808_pmugrf *pmugrf = 44 syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); 45 46 priv->info.size = 47 rockchip_sdram_size((phys_addr_t)&pmugrf->os_reg[2]); 48 #else 49 #error chip error 50 #endif 51 52 priv->info.base = CONFIG_SYS_SDRAM_BASE; 53 54 return 0; 55 } 56 57 static int dmc_get_info(struct udevice *dev, struct ram_info *info) 58 { 59 struct dram_info *priv = dev_get_priv(dev); 60 61 *info = priv->info; 62 63 return 0; 64 } 65 66 static struct ram_ops dmc_ops = { 67 .get_info = dmc_get_info, 68 }; 69 70 static const struct udevice_id dmc_ids[] = { 71 #if defined(CONFIG_ROCKCHIP_RK3036) 72 { .compatible = "rockchip,rk3036-dmc" }, 73 #elif defined(CONFIG_ROCKCHIP_RK3308) 74 { .compatible = "rockchip,rk3308-dmc" }, 75 #elif defined(CONFIG_ROCKCHIP_PX30) 76 { .compatible = "rockchip,px30-dmc" }, 77 #elif defined(CONFIG_ROCKCHIP_RK1808) 78 { .compatible = "rockchip,rk1808-dmc" }, 79 #endif 80 { } 81 }; 82 83 U_BOOT_DRIVER(dmc_tiny) = { 84 .name = "rockchip_dmc", 85 .id = UCLASS_RAM, 86 .of_match = dmc_ids, 87 .ops = &dmc_ops, 88 .probe = dmc_probe, 89 .priv_auto_alloc_size = sizeof(struct dram_info), 90 }; 91 #endif 92