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