xref: /rk3399_rockchip-uboot/drivers/ram/rockchip/sdram_px30.c (revision d5f538dc02e53c7267fcd4a914104071fca889b5)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
3  *
4  * SPDX-License-Identifier:     GPL-2.0
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <ram.h>
10 #include <syscon.h>
11 #include <asm/arch/clock.h>
12 #include <asm/arch/grf_px30.h>
13 #include <asm/arch/sdram_common.h>
14 
15 DECLARE_GLOBAL_DATA_PTR;
16 struct dram_info {
17 	struct ram_info info;
18 	struct px30_pmugrf *pmugrf;
19 };
20 
21 static int px30_dmc_probe(struct udevice *dev)
22 {
23 	struct dram_info *priv = dev_get_priv(dev);
24 
25 	priv->pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF);
26 	debug("%s: pmugrf=%p\n", __func__, priv->pmugrf);
27 	priv->info.base = CONFIG_SYS_SDRAM_BASE;
28 	priv->info.size = rockchip_sdram_size(
29 				(phys_addr_t)&priv->pmugrf->os_reg[2]);
30 
31 	return 0;
32 }
33 
34 static int px30_dmc_get_info(struct udevice *dev, struct ram_info *info)
35 {
36 	struct dram_info *priv = dev_get_priv(dev);
37 
38 	*info = priv->info;
39 
40 	return 0;
41 }
42 
43 static struct ram_ops px30_dmc_ops = {
44 	.get_info = px30_dmc_get_info,
45 };
46 
47 
48 static const struct udevice_id px30_dmc_ids[] = {
49 	{ .compatible = "rockchip,px30-dmc" },
50 	{ }
51 };
52 
53 U_BOOT_DRIVER(dmc_px30) = {
54 	.name = "rockchip_px30_dmc",
55 	.id = UCLASS_RAM,
56 	.of_match = px30_dmc_ids,
57 	.ops = &px30_dmc_ops,
58 	.probe = px30_dmc_probe,
59 	.priv_auto_alloc_size = sizeof(struct dram_info),
60 };
61