xref: /openbmc/u-boot/drivers/ram/rockchip/sdram_rk3128.c (revision 7436f5e54d35bcad53befec90e2e67288071f74e)
1*c43acfdcSKever Yang // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2b7aef289SKever Yang /*
3b7aef289SKever Yang  * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
4b7aef289SKever Yang  */
5b7aef289SKever Yang 
6b7aef289SKever Yang #include <common.h>
7b7aef289SKever Yang #include <dm.h>
8b7aef289SKever Yang #include <ram.h>
9b7aef289SKever Yang #include <syscon.h>
10b7aef289SKever Yang #include <asm/arch/clock.h>
11b7aef289SKever Yang #include <asm/arch/grf_rk3128.h>
12b7aef289SKever Yang #include <asm/arch/sdram_common.h>
13b7aef289SKever Yang 
14b7aef289SKever Yang struct dram_info {
15b7aef289SKever Yang 	struct ram_info info;
16b7aef289SKever Yang 	struct rk3128_grf *grf;
17b7aef289SKever Yang };
18b7aef289SKever Yang 
rk3128_dmc_probe(struct udevice * dev)19b7aef289SKever Yang static int rk3128_dmc_probe(struct udevice *dev)
20b7aef289SKever Yang {
21b7aef289SKever Yang 	struct dram_info *priv = dev_get_priv(dev);
22b7aef289SKever Yang 
23b7aef289SKever Yang 	priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
24b7aef289SKever Yang 	debug("%s: grf=%p\n", __func__, priv->grf);
25b7aef289SKever Yang 	priv->info.base = CONFIG_SYS_SDRAM_BASE;
26b7aef289SKever Yang 	priv->info.size = rockchip_sdram_size(
27b7aef289SKever Yang 				(phys_addr_t)&priv->grf->os_reg[1]);
28b7aef289SKever Yang 
29b7aef289SKever Yang 	return 0;
30b7aef289SKever Yang }
31b7aef289SKever Yang 
rk3128_dmc_get_info(struct udevice * dev,struct ram_info * info)32b7aef289SKever Yang static int rk3128_dmc_get_info(struct udevice *dev, struct ram_info *info)
33b7aef289SKever Yang {
34b7aef289SKever Yang 	struct dram_info *priv = dev_get_priv(dev);
35b7aef289SKever Yang 
36b7aef289SKever Yang 	*info = priv->info;
37b7aef289SKever Yang 
38b7aef289SKever Yang 	return 0;
39b7aef289SKever Yang }
40b7aef289SKever Yang 
41b7aef289SKever Yang static struct ram_ops rk3128_dmc_ops = {
42b7aef289SKever Yang 	.get_info = rk3128_dmc_get_info,
43b7aef289SKever Yang };
44b7aef289SKever Yang 
45b7aef289SKever Yang static const struct udevice_id rk3128_dmc_ids[] = {
46b7aef289SKever Yang 	{ .compatible = "rockchip,rk3128-dmc" },
47b7aef289SKever Yang 	{ }
48b7aef289SKever Yang };
49b7aef289SKever Yang 
50b7aef289SKever Yang U_BOOT_DRIVER(dmc_rk3128) = {
51b7aef289SKever Yang 	.name = "rockchip_rk3128_dmc",
52b7aef289SKever Yang 	.id = UCLASS_RAM,
53b7aef289SKever Yang 	.of_match = rk3128_dmc_ids,
54b7aef289SKever Yang 	.ops = &rk3128_dmc_ops,
55b7aef289SKever Yang 	.probe = rk3128_dmc_probe,
56b7aef289SKever Yang 	.priv_auto_alloc_size = sizeof(struct dram_info),
57b7aef289SKever Yang };
58