blob: 8b2c2f323a71d1bbb9bc78cc14efa1f9572e5ffd [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
Tom Riniabb9a042024-05-18 20:20:43 -06007#include <common.h>
Simon Glass19c58cf2015-08-30 16:55:34 -06008#include <dm.h>
Johan Jonker6ba857d2023-03-13 01:30:57 +01009#include <dt-structs.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Johan Jonker6ba857d2023-03-13 01:30:57 +010011#include <malloc.h>
12#include <regmap.h>
Simon Glass19c58cf2015-08-30 16:55:34 -060013#include <syscon.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080014#include <asm/arch-rockchip/clock.h>
Simon Glass19c58cf2015-08-30 16:55:34 -060015
16static const struct udevice_id rk3288_syscon_ids[] = {
17 { .compatible = "rockchip,rk3288-noc", .data = ROCKCHIP_SYSCON_NOC },
18 { .compatible = "rockchip,rk3288-grf", .data = ROCKCHIP_SYSCON_GRF },
19 { .compatible = "rockchip,rk3288-sgrf", .data = ROCKCHIP_SYSCON_SGRF },
20 { .compatible = "rockchip,rk3288-pmu", .data = ROCKCHIP_SYSCON_PMU },
21 { }
22};
23
24U_BOOT_DRIVER(syscon_rk3288) = {
25 .name = "rk3288_syscon",
26 .id = UCLASS_SYSCON,
27 .of_match = rk3288_syscon_ids,
28};
Simon Glassd63ea432016-07-04 11:58:33 -060029
30#if CONFIG_IS_ENABLED(OF_PLATDATA)
Johan Jonker6ba857d2023-03-13 01:30:57 +010031#if IS_ENABLED(CONFIG_FDT_64BIT)
32struct rockchip_rk3288_noc_plat {
33 struct dtd_rockchip_rk3288_noc dtplat;
34};
35
36struct rockchip_rk3288_grf_plat {
37 struct dtd_rockchip_rk3288_grf dtplat;
38};
39
40struct rockchip_rk3288_sgrf_plat {
41 struct dtd_rockchip_rk3288_sgrf dtplat;
42};
43
44struct rockchip_rk3288_pmu_plat {
45 struct dtd_rockchip_rk3288_pmu dtplat;
46};
47
48static int rk3288_noc_bind_of_plat(struct udevice *dev)
49{
50 struct rockchip_rk3288_noc_plat *plat = dev_get_plat(dev);
51 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
52 int size = dev->uclass->uc_drv->per_device_auto;
53
54 if (size && !priv) {
55 priv = calloc(1, size);
56 if (!priv)
57 return -ENOMEM;
58 dev_set_uclass_priv(dev, priv);
59 }
60
61 dev->driver_data = dev->driver->of_match->data;
62 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
63
64 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
65 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
66}
67
68static int rk3288_grf_bind_of_plat(struct udevice *dev)
69{
70 struct rockchip_rk3288_grf_plat *plat = dev_get_plat(dev);
71 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
72 int size = dev->uclass->uc_drv->per_device_auto;
73
74 if (size && !priv) {
75 priv = calloc(1, size);
76 if (!priv)
77 return -ENOMEM;
78 dev_set_uclass_priv(dev, priv);
79 }
80
81 dev->driver_data = dev->driver->of_match->data;
82 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
83
84 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
85 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
86}
87
88static int rk3288_sgrf_bind_of_plat(struct udevice *dev)
89{
90 struct rockchip_rk3288_sgrf_plat *plat = dev_get_plat(dev);
91 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
92 int size = dev->uclass->uc_drv->per_device_auto;
93
94 if (size && !priv) {
95 priv = calloc(1, size);
96 if (!priv)
97 return -ENOMEM;
98 dev_set_uclass_priv(dev, priv);
99 }
100
101 dev->driver_data = dev->driver->of_match->data;
102 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
103
104 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
105 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
106}
107
108static int rk3288_pmu_bind_of_plat(struct udevice *dev)
109{
110 struct rockchip_rk3288_pmu_plat *plat = dev_get_plat(dev);
111 struct syscon_uc_info *priv = dev_get_uclass_priv(dev);
112 int size = dev->uclass->uc_drv->per_device_auto;
113
114 if (size && !priv) {
115 priv = calloc(1, size);
116 if (!priv)
117 return -ENOMEM;
118 dev_set_uclass_priv(dev, priv);
119 }
120
121 dev->driver_data = dev->driver->of_match->data;
122 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
123
124 return regmap_init_mem_plat(dev, plat->dtplat.reg, sizeof(plat->dtplat.reg[0]),
125 ARRAY_SIZE(plat->dtplat.reg) / 2, &priv->regmap);
126}
127#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700128static int rk3288_syscon_bind_of_plat(struct udevice *dev)
Simon Glassd63ea432016-07-04 11:58:33 -0600129{
130 dev->driver_data = dev->driver->of_match->data;
131 debug("syscon: %s %d\n", dev->name, (uint)dev->driver_data);
132
133 return 0;
134}
Johan Jonker6ba857d2023-03-13 01:30:57 +0100135#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600136
137U_BOOT_DRIVER(rockchip_rk3288_noc) = {
138 .name = "rockchip_rk3288_noc",
139 .id = UCLASS_SYSCON,
140 .of_match = rk3288_syscon_ids,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100141#if IS_ENABLED(CONFIG_FDT_64BIT)
142 .bind = rk3288_noc_bind_of_plat,
143 .plat_auto = sizeof(struct rockchip_rk3288_noc_plat),
144#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700145 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100146#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600147};
148
149U_BOOT_DRIVER(rockchip_rk3288_grf) = {
150 .name = "rockchip_rk3288_grf",
151 .id = UCLASS_SYSCON,
152 .of_match = rk3288_syscon_ids + 1,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100153#if IS_ENABLED(CONFIG_FDT_64BIT)
154 .bind = rk3288_grf_bind_of_plat,
155 .plat_auto = sizeof(struct rockchip_rk3288_grf_plat),
156#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700157 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100158#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600159};
160
161U_BOOT_DRIVER(rockchip_rk3288_sgrf) = {
162 .name = "rockchip_rk3288_sgrf",
163 .id = UCLASS_SYSCON,
164 .of_match = rk3288_syscon_ids + 2,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100165#if IS_ENABLED(CONFIG_FDT_64BIT)
166 .bind = rk3288_sgrf_bind_of_plat,
167 .plat_auto = sizeof(struct rockchip_rk3288_sgrf_plat),
168#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700169 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100170#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600171};
172
173U_BOOT_DRIVER(rockchip_rk3288_pmu) = {
174 .name = "rockchip_rk3288_pmu",
175 .id = UCLASS_SYSCON,
176 .of_match = rk3288_syscon_ids + 3,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100177#if IS_ENABLED(CONFIG_FDT_64BIT)
178 .bind = rk3288_pmu_bind_of_plat,
179 .plat_auto = sizeof(struct rockchip_rk3288_pmu_plat),
180#else
Simon Glassb75b15b2020-12-03 16:55:23 -0700181 .bind = rk3288_syscon_bind_of_plat,
Johan Jonker6ba857d2023-03-13 01:30:57 +0100182#endif
Simon Glassd63ea432016-07-04 11:58:33 -0600183};
184#endif