blob: 6413d0a88a16a90817b615886d3d51fb175884d6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass19c58cf2015-08-30 16:55:34 -06002/*
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass19c58cf2015-08-30 16:55:34 -06005 */
6
Simon Glass19c58cf2015-08-30 16:55:34 -06007#include <dm.h>
Johan Jonker6ba857d2023-03-13 01:30:57 +01008#include <dt-structs.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Johan Jonker6ba857d2023-03-13 01:30:57 +010010#include <malloc.h>
11#include <regmap.h>
Simon Glass19c58cf2015-08-30 16:55:34 -060012#include <syscon.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080013#include <asm/arch-rockchip/clock.h>
Simon Glass19c58cf2015-08-30 16:55:34 -060014
15static const struct udevice_id rk3288_syscon_ids[] = {
16 { .compatible = "rockchip,rk3288-noc", .data = ROCKCHIP_SYSCON_NOC },
17 { .compatible = "rockchip,rk3288-grf", .data = ROCKCHIP_SYSCON_GRF },
18 { .compatible = "rockchip,rk3288-sgrf", .data = ROCKCHIP_SYSCON_SGRF },
19 { .compatible = "rockchip,rk3288-pmu", .data = ROCKCHIP_SYSCON_PMU },
20 { }
21};
22
23U_BOOT_DRIVER(syscon_rk3288) = {
24 .name = "rk3288_syscon",
25 .id = UCLASS_SYSCON,
26 .of_match = rk3288_syscon_ids,
27};
Simon Glassd63ea432016-07-04 11:58:33 -060028
29#if CONFIG_IS_ENABLED(OF_PLATDATA)
Johan Jonker6ba857d2023-03-13 01:30:57 +010030#if IS_ENABLED(CONFIG_FDT_64BIT)
31struct rockchip_rk3288_noc_plat {
32 struct dtd_rockchip_rk3288_noc dtplat;
33};
34
35struct rockchip_rk3288_grf_plat {
36 struct dtd_rockchip_rk3288_grf dtplat;
37};
38
39struct rockchip_rk3288_sgrf_plat {
40 struct dtd_rockchip_rk3288_sgrf dtplat;
41};
42
43struct rockchip_rk3288_pmu_plat {
44 struct dtd_rockchip_rk3288_pmu dtplat;
45};
46
47static int rk3288_noc_bind_of_plat(struct udevice *dev)
48{
49 struct rockchip_rk3288_noc_plat *plat = dev_get_plat(dev);
50 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
51 int size = dev->uclass->uc_drv->per_device_auto;
52
53 if (size && !priv) {
54 priv = calloc(1, size);
55 if (!priv)
56 return -ENOMEM;
57 dev_set_uclass_priv(dev, priv);
58 }
59
60 dev->driver_data = dev->driver->of_match->data;
61 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
62
63 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
64 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
65}
66
67static int rk3288_grf_bind_of_plat(struct udevice *dev)
68{
69 struct rockchip_rk3288_grf_plat *plat = dev_get_plat(dev);
70 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
71 int size = dev->uclass->uc_drv->per_device_auto;
72
73 if (size && !priv) {
74 priv = calloc(1, size);
75 if (!priv)
76 return -ENOMEM;
77 dev_set_uclass_priv(dev, priv);
78 }
79
80 dev->driver_data = dev->driver->of_match->data;
81 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
82
83 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
84 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
85}
86
87static int rk3288_sgrf_bind_of_plat(struct udevice *dev)
88{
89 struct rockchip_rk3288_sgrf_plat *plat = dev_get_plat(dev);
90 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
91 int size = dev->uclass->uc_drv->per_device_auto;
92
93 if (size && !priv) {
94 priv = calloc(1, size);
95 if (!priv)
96 return -ENOMEM;
97 dev_set_uclass_priv(dev, priv);
98 }
99
100 dev->driver_data = dev->driver->of_match->data;
101 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
102
103 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
104 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
105}
106
107static int rk3288_pmu_bind_of_plat(struct udevice *dev)
108{
109 struct rockchip_rk3288_pmu_plat *plat = dev_get_plat(dev);
110 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
111 int size = dev->uclass->uc_drv->per_device_auto;
112
113 if (size && !priv) {
114 priv = calloc(1, size);
115 if (!priv)
116 return -ENOMEM;
117 dev_set_uclass_priv(dev, priv);
118 }
119
120 dev->driver_data = dev->driver->of_match->data;
121 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
122
123 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
124 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
125}
126#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700127static int rk3288_syscon_bind_of_plat(struct udevice *dev)
Simon Glassd63ea432016-07-04 11:58:33 -0600128{
129 dev->driver_data = dev->driver->of_match->data;
130 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
131
132 return 0;
133}
Johan Jonker6ba857d2023-03-13 01:30:57 +0100134#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600135
136U_BOOT_DRIVER(rockchip_rk3288_noc) = {
137 .name = "rockchip_rk3288_noc",
138 .id = UCLASS_SYSCON,
139 .of_match = rk3288_syscon_ids,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100140#if IS_ENABLED(CONFIG_FDT_64BIT)
141 .bind = rk3288_noc_bind_of_plat,
142 .plat_auto = sizeof(struct rockchip_rk3288_noc_plat),
143#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700144 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100145#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600146};
147
148U_BOOT_DRIVER(rockchip_rk3288_grf) = {
149 .name = "rockchip_rk3288_grf",
150 .id = UCLASS_SYSCON,
151 .of_match = rk3288_syscon_ids + 1,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100152#if IS_ENABLED(CONFIG_FDT_64BIT)
153 .bind = rk3288_grf_bind_of_plat,
154 .plat_auto = sizeof(struct rockchip_rk3288_grf_plat),
155#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700156 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100157#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600158};
159
160U_BOOT_DRIVER(rockchip_rk3288_sgrf) = {
161 .name = "rockchip_rk3288_sgrf",
162 .id = UCLASS_SYSCON,
163 .of_match = rk3288_syscon_ids + 2,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100164#if IS_ENABLED(CONFIG_FDT_64BIT)
165 .bind = rk3288_sgrf_bind_of_plat,
166 .plat_auto = sizeof(struct rockchip_rk3288_sgrf_plat),
167#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700168 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100169#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600170};
171
172U_BOOT_DRIVER(rockchip_rk3288_pmu) = {
173 .name = "rockchip_rk3288_pmu",
174 .id = UCLASS_SYSCON,
175 .of_match = rk3288_syscon_ids + 3,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100176#if IS_ENABLED(CONFIG_FDT_64BIT)
177 .bind = rk3288_pmu_bind_of_plat,
178 .plat_auto = sizeof(struct rockchip_rk3288_pmu_plat),
179#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700180 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100181#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600182};
183#endif