blob: d2aea8d7d1ccf2046b978e3e65a2b9e2ece824ff [file] [log] [blame]
Yanhong Wang5a85d052023-03-29 11:42:13 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2022-23 StarFive Technology Co., Ltd.
4 *
5 * Author: Yanhong Wang <yanhong.wang@starfivetech.com>
Xingyu Wu751e4402023-07-07 18:50:07 +08006 * Xingyu Wu <xingyu.wu@starfivetech.com>
Yanhong Wang5a85d052023-03-29 11:42:13 +08007 */
8
9#include <common.h>
10#include <clk.h>
11#include <clk-uclass.h>
12#include <dm.h>
13#include <dm/device.h>
14#include <dm/devres.h>
15#include <dm/lists.h>
16#include <dt-bindings/clock/starfive,jh7110-crg.h>
17#include <log.h>
18#include <linux/clk-provider.h>
19
Yanhong Wang5a85d052023-03-29 11:42:13 +080020#define STARFIVE_CLK_ENABLE_SHIFT 31 /* [31] */
21#define STARFIVE_CLK_INVERT_SHIFT 30 /* [30] */
22#define STARFIVE_CLK_MUX_SHIFT 24 /* [29:24] */
23#define STARFIVE_CLK_DIV_SHIFT 0 /* [23:0] */
24
25#define OFFSET(id) ((id) * 4)
26#define AONOFFSET(id) (((id) - JH7110_SYSCLK_END) * 4)
27#define STGOFFSET(id) (((id) - JH7110_AONCLK_END) * 4)
28
29typedef int (*jh1710_init_fn)(struct udevice *dev);
30
31struct jh7110_clk_priv {
32 void __iomem *reg;
33 jh1710_init_fn init;
34};
35
36static const char *cpu_root_sels[2] = {
37 [0] = "oscillator",
38 [1] = "pll0_out",
39};
40
41static const char *perh_root_sels[2] = {
42 [0] = "pll0_out",
43 [1] = "pll2_out",
44};
45
46static const char *bus_root_sels[2] = {
47 [0] = "oscillator",
48 [1] = "pll2_out",
49};
50
51static const char *qspi_ref_sels[2] = {
52 [0] = "oscillator",
53 [1] = "qspi_ref_src",
54};
55
56static const char *gmac1_tx_sels[2] = {
57 [0] = "gmac1_gtxclk",
58 [1] = "gmac1_rmii_rtx",
59};
60
61static const char *gmac0_tx_sels[2] = {
62 [0] = "gmac0_gtxclk",
63 [1] = "gmac0_rmii_rtx",
64};
65
66static const char *apb_func_sels[2] = {
67 [0] = "osc_div4",
68 [1] = "oscillator",
69};
70
71static const char *gmac1_rx_sels[2] = {
72 [0] = "gmac1-rgmii-rxin-clock",
73 [1] = "gmac1_rmii_rtx",
74};
75
76static struct clk *starfive_clk_mux(void __iomem *reg,
77 const char *name,
78 unsigned int offset,
79 u8 width,
80 const char * const *parent_names,
81 u8 num_parents)
82{
83 return clk_register_mux(NULL, name, parent_names, num_parents, 0,
84 reg + offset, STARFIVE_CLK_MUX_SHIFT,
85 width, 0);
86}
87
88static struct clk *starfive_clk_gate(void __iomem *reg,
89 const char *name,
90 const char *parent_name,
91 unsigned int offset)
92{
93 return clk_register_gate(NULL, name, parent_name, 0, reg + offset,
94 STARFIVE_CLK_ENABLE_SHIFT, 0, NULL);
95}
96
97static struct clk *starfive_clk_inv(void __iomem *reg,
98 const char *name,
99 const char *parent_name,
100 unsigned int offset)
101{
102 return clk_register_gate(NULL, name, parent_name, 0, reg + offset,
103 STARFIVE_CLK_INVERT_SHIFT, 0, NULL);
104}
105
106static struct clk *starfive_clk_divider(void __iomem *reg,
107 const char *name,
108 const char *parent_name,
109 unsigned int offset,
110 u8 width)
111{
112 return clk_register_divider(NULL, name, parent_name, 0, reg + offset,
113 0, width, CLK_DIVIDER_ONE_BASED);
114}
115
116static struct clk *starfive_clk_composite(void __iomem *reg,
117 const char *name,
118 const char * const *parent_names,
119 unsigned int num_parents,
120 unsigned int offset,
121 unsigned int mux_width,
122 unsigned int gate_width,
123 unsigned int div_width)
124{
125 struct clk *clk = ERR_PTR(-ENOMEM);
126 struct clk_divider *div = NULL;
127 struct clk_gate *gate = NULL;
128 struct clk_mux *mux = NULL;
129 int mask_arry[4] = {0x1, 0x3, 0x7, 0xF};
130 int mask;
131
132 if (mux_width) {
133 if (mux_width > 4)
134 goto fail;
135 else
136 mask = mask_arry[mux_width - 1];
137
138 mux = kzalloc(sizeof(*mux), GFP_KERNEL);
139 if (!mux)
140 goto fail;
141
142 mux->reg = reg + offset;
143 mux->mask = mask;
144 mux->shift = STARFIVE_CLK_MUX_SHIFT;
145 mux->num_parents = num_parents;
146 mux->flags = 0;
147 mux->parent_names = parent_names;
148 }
149
150 if (gate_width) {
151 gate = kzalloc(sizeof(*gate), GFP_KERNEL);
152
153 if (!gate)
154 goto fail;
155
156 gate->reg = reg + offset;
157 gate->bit_idx = STARFIVE_CLK_ENABLE_SHIFT;
158 gate->flags = 0;
159 }
160
161 if (div_width) {
162 div = kzalloc(sizeof(*div), GFP_KERNEL);
163 if (!div)
164 goto fail;
165
166 div->reg = reg + offset;
167
168 if (offset == OFFSET(JH7110_SYSCLK_UART3_CORE) ||
169 offset == OFFSET(JH7110_SYSCLK_UART4_CORE) ||
170 offset == OFFSET(JH7110_SYSCLK_UART5_CORE)) {
171 div->shift = 8;
172 div->width = 8;
173 } else {
174 div->shift = STARFIVE_CLK_DIV_SHIFT;
175 div->width = div_width;
176 }
177 div->flags = CLK_DIVIDER_ONE_BASED;
178 div->table = NULL;
179 }
180
181 clk = clk_register_composite(NULL, name,
182 parent_names, num_parents,
183 &mux->clk, &clk_mux_ops,
184 &div->clk, &clk_divider_ops,
185 &gate->clk, &clk_gate_ops, 0);
186
187 if (IS_ERR(clk))
188 goto fail;
189
190 return clk;
191
192fail:
193 kfree(gate);
194 kfree(div);
195 kfree(mux);
196 return ERR_CAST(clk);
197}
198
199static struct clk *starfive_clk_fix_parent_composite(void __iomem *reg,
200 const char *name,
201 const char *parent_names,
202 unsigned int offset,
203 unsigned int mux_width,
204 unsigned int gate_width,
205 unsigned int div_width)
206{
207 const char * const *parents;
208
209 parents = &parent_names;
210
211 return starfive_clk_composite(reg, name, parents, 1, offset,
212 mux_width, gate_width, div_width);
213}
214
215static struct clk *starfive_clk_gate_divider(void __iomem *reg,
216 const char *name,
217 const char *parent,
218 unsigned int offset,
219 unsigned int width)
220{
221 const char * const *parent_names;
222
223 parent_names = &parent;
224
225 return starfive_clk_composite(reg, name, parent_names, 1,
226 offset, 0, 1, width);
227}
228
229static int jh7110_syscrg_init(struct udevice *dev)
230{
231 struct jh7110_clk_priv *priv = dev_get_priv(dev);
Yanhong Wang5a85d052023-03-29 11:42:13 +0800232 struct clk *pclk;
Yanhong Wang5a85d052023-03-29 11:42:13 +0800233
Yanhong Wang5a85d052023-03-29 11:42:13 +0800234 clk_dm(JH7110_SYSCLK_CPU_ROOT,
235 starfive_clk_mux(priv->reg, "cpu_root",
236 OFFSET(JH7110_SYSCLK_CPU_ROOT), 1,
237 cpu_root_sels, ARRAY_SIZE(cpu_root_sels)));
238 clk_dm(JH7110_SYSCLK_CPU_CORE,
239 starfive_clk_divider(priv->reg,
240 "cpu_core", "cpu_root",
241 OFFSET(JH7110_SYSCLK_CPU_CORE), 3));
242 clk_dm(JH7110_SYSCLK_CPU_BUS,
243 starfive_clk_divider(priv->reg,
244 "cpu_bus", "cpu_core",
245 OFFSET(JH7110_SYSCLK_CPU_BUS), 2));
246 clk_dm(JH7110_SYSCLK_PERH_ROOT,
247 starfive_clk_composite(priv->reg,
248 "perh_root",
249 perh_root_sels, ARRAY_SIZE(perh_root_sels),
250 OFFSET(JH7110_SYSCLK_PERH_ROOT), 1, 0, 2));
251 clk_dm(JH7110_SYSCLK_BUS_ROOT,
252 starfive_clk_mux(priv->reg, "bus_root",
253 OFFSET(JH7110_SYSCLK_BUS_ROOT), 1,
254 bus_root_sels, ARRAY_SIZE(bus_root_sels)));
255 clk_dm(JH7110_SYSCLK_NOCSTG_BUS,
256 starfive_clk_divider(priv->reg,
257 "nocstg_bus", "bus_root",
258 OFFSET(JH7110_SYSCLK_NOCSTG_BUS), 3));
259 clk_dm(JH7110_SYSCLK_AXI_CFG0,
260 starfive_clk_divider(priv->reg,
261 "axi_cfg0", "bus_root",
262 OFFSET(JH7110_SYSCLK_AXI_CFG0), 2));
263 clk_dm(JH7110_SYSCLK_STG_AXIAHB,
264 starfive_clk_divider(priv->reg,
265 "stg_axiahb", "axi_cfg0",
266 OFFSET(JH7110_SYSCLK_STG_AXIAHB), 2));
267 clk_dm(JH7110_SYSCLK_AHB0,
268 starfive_clk_gate(priv->reg,
269 "ahb0", "stg_axiahb",
270 OFFSET(JH7110_SYSCLK_AHB0)));
271 clk_dm(JH7110_SYSCLK_AHB1,
272 starfive_clk_gate(priv->reg,
273 "ahb1", "stg_axiahb",
274 OFFSET(JH7110_SYSCLK_AHB1)));
275 clk_dm(JH7110_SYSCLK_APB_BUS,
276 starfive_clk_divider(priv->reg,
277 "apb_bus", "stg_axiahb",
278 OFFSET(JH7110_SYSCLK_APB_BUS), 4));
279 clk_dm(JH7110_SYSCLK_APB0,
280 starfive_clk_gate(priv->reg,
281 "apb0", "apb_bus",
282 OFFSET(JH7110_SYSCLK_APB0)));
283 clk_dm(JH7110_SYSCLK_QSPI_AHB,
284 starfive_clk_gate(priv->reg,
285 "qspi_ahb", "ahb1",
286 OFFSET(JH7110_SYSCLK_QSPI_AHB)));
287 clk_dm(JH7110_SYSCLK_QSPI_APB,
288 starfive_clk_gate(priv->reg,
289 "qspi_apb", "apb_bus",
290 OFFSET(JH7110_SYSCLK_QSPI_APB)));
291 clk_dm(JH7110_SYSCLK_QSPI_REF_SRC,
292 starfive_clk_divider(priv->reg,
293 "qspi_ref_src", "pll0_out",
294 OFFSET(JH7110_SYSCLK_QSPI_REF_SRC), 5));
295 clk_dm(JH7110_SYSCLK_QSPI_REF,
296 starfive_clk_composite(priv->reg,
297 "qspi_ref",
298 qspi_ref_sels, ARRAY_SIZE(qspi_ref_sels),
299 OFFSET(JH7110_SYSCLK_QSPI_REF), 1, 1, 0));
300 clk_dm(JH7110_SYSCLK_SDIO0_AHB,
301 starfive_clk_gate(priv->reg,
302 "sdio0_ahb", "ahb0",
303 OFFSET(JH7110_SYSCLK_SDIO0_AHB)));
304 clk_dm(JH7110_SYSCLK_SDIO1_AHB,
305 starfive_clk_gate(priv->reg,
306 "sdio1_ahb", "ahb0",
307 OFFSET(JH7110_SYSCLK_SDIO1_AHB)));
308 clk_dm(JH7110_SYSCLK_SDIO0_SDCARD,
309 starfive_clk_fix_parent_composite(priv->reg,
310 "sdio0_sdcard", "axi_cfg0",
311 OFFSET(JH7110_SYSCLK_SDIO0_SDCARD), 0, 1, 4));
312 clk_dm(JH7110_SYSCLK_SDIO1_SDCARD,
313 starfive_clk_fix_parent_composite(priv->reg,
314 "sdio1_sdcard", "axi_cfg0",
315 OFFSET(JH7110_SYSCLK_SDIO1_SDCARD), 0, 1, 4));
316 clk_dm(JH7110_SYSCLK_USB_125M,
317 starfive_clk_divider(priv->reg,
318 "usb_125m", "pll0_out",
319 OFFSET(JH7110_SYSCLK_USB_125M), 4));
320 clk_dm(JH7110_SYSCLK_NOC_BUS_STG_AXI,
321 starfive_clk_gate(priv->reg,
322 "noc_bus_stg_axi", "nocstg_bus",
323 OFFSET(JH7110_SYSCLK_NOC_BUS_STG_AXI)));
324 clk_dm(JH7110_SYSCLK_GMAC1_AHB,
325 starfive_clk_gate(priv->reg,
326 "gmac1_ahb", "ahb0",
327 OFFSET(JH7110_SYSCLK_GMAC1_AHB)));
328 clk_dm(JH7110_SYSCLK_GMAC1_AXI,
329 starfive_clk_gate(priv->reg,
330 "gmac1_axi", "stg_axiahb",
331 OFFSET(JH7110_SYSCLK_GMAC1_AXI)));
332 clk_dm(JH7110_SYSCLK_GMAC_SRC,
333 starfive_clk_divider(priv->reg,
334 "gmac_src", "pll0_out",
335 OFFSET(JH7110_SYSCLK_GMAC_SRC), 3));
336 clk_dm(JH7110_SYSCLK_GMAC1_GTXCLK,
337 starfive_clk_divider(priv->reg,
338 "gmac1_gtxclk", "pll0_out",
339 OFFSET(JH7110_SYSCLK_GMAC1_GTXCLK), 4));
340 clk_dm(JH7110_SYSCLK_GMAC1_GTXC,
341 starfive_clk_gate(priv->reg,
342 "gmac1_gtxc", "gmac1_gtxclk",
343 OFFSET(JH7110_SYSCLK_GMAC1_GTXC)));
344 clk_dm(JH7110_SYSCLK_GMAC1_RMII_RTX,
345 starfive_clk_divider(priv->reg,
346 "gmac1_rmii_rtx", "gmac1-rmii-refin-clock",
347 OFFSET(JH7110_SYSCLK_GMAC1_RMII_RTX), 5));
348 clk_dm(JH7110_SYSCLK_GMAC1_PTP,
349 starfive_clk_gate_divider(priv->reg,
350 "gmac1_ptp", "gmac_src",
351 OFFSET(JH7110_SYSCLK_GMAC1_PTP), 5));
352 clk_dm(JH7110_SYSCLK_GMAC1_RX,
353 starfive_clk_mux(priv->reg, "gmac1_rx",
354 OFFSET(JH7110_SYSCLK_GMAC1_RX), 1,
355 gmac1_rx_sels, ARRAY_SIZE(gmac1_rx_sels)));
356 clk_dm(JH7110_SYSCLK_GMAC1_TX,
357 starfive_clk_composite(priv->reg,
358 "gmac1_tx",
359 gmac1_tx_sels, ARRAY_SIZE(gmac1_tx_sels),
360 OFFSET(JH7110_SYSCLK_GMAC1_TX), 1, 1, 0));
361 clk_dm(JH7110_SYSCLK_GMAC1_TX_INV,
362 starfive_clk_inv(priv->reg,
363 "gmac1_tx_inv", "gmac1_tx",
364 OFFSET(JH7110_SYSCLK_GMAC1_TX_INV)));
365 clk_dm(JH7110_SYSCLK_GMAC0_GTXCLK,
366 starfive_clk_gate_divider(priv->reg,
367 "gmac0_gtxclk", "pll0_out",
368 OFFSET(JH7110_SYSCLK_GMAC0_GTXCLK), 4));
369 clk_dm(JH7110_SYSCLK_GMAC0_PTP,
370 starfive_clk_gate_divider(priv->reg,
371 "gmac0_ptp", "gmac_src",
372 OFFSET(JH7110_SYSCLK_GMAC0_PTP), 5));
373 clk_dm(JH7110_SYSCLK_GMAC0_GTXC,
374 starfive_clk_gate(priv->reg,
375 "gmac0_gtxc", "gmac0_gtxclk",
376 OFFSET(JH7110_SYSCLK_GMAC0_GTXC)));
377 clk_dm(JH7110_SYSCLK_UART0_APB,
378 starfive_clk_gate(priv->reg,
379 "uart0_apb", "apb0",
380 OFFSET(JH7110_SYSCLK_UART0_APB)));
381 clk_dm(JH7110_SYSCLK_UART0_CORE,
382 starfive_clk_gate(priv->reg,
383 "uart0_core", "oscillator",
384 OFFSET(JH7110_SYSCLK_UART0_CORE)));
385 clk_dm(JH7110_SYSCLK_UART1_APB,
386 starfive_clk_gate(priv->reg,
387 "uart1_apb", "apb0",
388 OFFSET(JH7110_SYSCLK_UART1_APB)));
389 clk_dm(JH7110_SYSCLK_UART1_CORE,
390 starfive_clk_gate(priv->reg,
391 "uart1_core", "oscillator",
392 OFFSET(JH7110_SYSCLK_UART1_CORE)));
393 clk_dm(JH7110_SYSCLK_UART2_APB,
394 starfive_clk_gate(priv->reg,
395 "uart2_apb", "apb0",
396 OFFSET(JH7110_SYSCLK_UART2_APB)));
397 clk_dm(JH7110_SYSCLK_UART2_CORE,
398 starfive_clk_gate(priv->reg,
399 "uart2_core", "oscillator",
400 OFFSET(JH7110_SYSCLK_UART2_CORE)));
401 clk_dm(JH7110_SYSCLK_UART3_APB,
402 starfive_clk_gate(priv->reg,
403 "uart3_apb", "apb0",
404 OFFSET(JH7110_SYSCLK_UART3_APB)));
405 clk_dm(JH7110_SYSCLK_UART3_CORE,
406 starfive_clk_gate_divider(priv->reg,
407 "uart3_core", "perh_root",
408 OFFSET(JH7110_SYSCLK_UART3_CORE), 8));
409 clk_dm(JH7110_SYSCLK_UART4_APB,
410 starfive_clk_gate(priv->reg,
411 "uart4_apb", "apb0",
412 OFFSET(JH7110_SYSCLK_UART4_APB)));
413 clk_dm(JH7110_SYSCLK_UART4_CORE,
414 starfive_clk_gate_divider(priv->reg,
415 "uart4_core", "perh_root",
416 OFFSET(JH7110_SYSCLK_UART4_CORE), 8));
417 clk_dm(JH7110_SYSCLK_UART5_APB,
418 starfive_clk_gate(priv->reg,
419 "uart5_apb", "apb0",
420 OFFSET(JH7110_SYSCLK_UART5_APB)));
421 clk_dm(JH7110_SYSCLK_UART5_CORE,
422 starfive_clk_gate_divider(priv->reg,
423 "uart5_core", "perh_root",
424 OFFSET(JH7110_SYSCLK_UART5_CORE), 8));
425 clk_dm(JH7110_SYSCLK_I2C2_APB,
426 starfive_clk_gate(priv->reg,
427 "i2c2_apb", "apb0",
428 OFFSET(JH7110_SYSCLK_I2C2_APB)));
429 clk_dm(JH7110_SYSCLK_I2C5_APB,
430 starfive_clk_gate(priv->reg,
431 "i2c5_apb", "apb0",
432 OFFSET(JH7110_SYSCLK_I2C5_APB)));
433
434 /* enable noc_bus_stg_axi clock */
435 if (!clk_get_by_id(JH7110_SYSCLK_NOC_BUS_STG_AXI, &pclk))
436 clk_enable(pclk);
437
438 return 0;
439}
440
441static int jh7110_aoncrg_init(struct udevice *dev)
442{
443 struct jh7110_clk_priv *priv = dev_get_priv(dev);
444
445 clk_dm(JH7110_AONCLK_OSC_DIV4,
446 starfive_clk_divider(priv->reg,
447 "osc_div4", "oscillator",
448 AONOFFSET(JH7110_AONCLK_OSC_DIV4), 5));
449 clk_dm(JH7110_AONCLK_APB_FUNC,
450 starfive_clk_mux(priv->reg, "apb_func",
451 AONOFFSET(JH7110_AONCLK_APB_FUNC), 1,
452 apb_func_sels, ARRAY_SIZE(apb_func_sels)));
453 clk_dm(JH7110_AONCLK_GMAC0_AHB,
454 starfive_clk_gate(priv->reg,
455 "gmac0_ahb", "stg_axiahb",
456 AONOFFSET(JH7110_AONCLK_GMAC0_AHB)));
457 clk_dm(JH7110_AONCLK_GMAC0_AXI,
458 starfive_clk_gate(priv->reg,
459 "gmac0_axi", "stg_axiahb",
460 AONOFFSET(JH7110_AONCLK_GMAC0_AXI)));
461 clk_dm(JH7110_AONCLK_GMAC0_RMII_RTX,
462 starfive_clk_divider(priv->reg,
463 "gmac0_rmii_rtx", "gmac0-rmii-refin-clock",
464 AONOFFSET(JH7110_AONCLK_GMAC0_RMII_RTX), 5));
465 clk_dm(JH7110_AONCLK_GMAC0_TX,
466 starfive_clk_composite(priv->reg,
467 "gmac0_tx", gmac0_tx_sels,
468 ARRAY_SIZE(gmac0_tx_sels),
469 AONOFFSET(JH7110_AONCLK_GMAC0_TX), 1, 1, 0));
470 clk_dm(JH7110_AONCLK_GMAC0_TX_INV,
471 starfive_clk_inv(priv->reg,
472 "gmac0_tx_inv", "gmac0_tx",
473 AONOFFSET(JH7110_AONCLK_GMAC0_TX_INV)));
474 clk_dm(JH7110_AONCLK_OTPC_APB,
475 starfive_clk_gate(priv->reg,
476 "otpc_apb", "apb_bus",
477 AONOFFSET(JH7110_AONCLK_OTPC_APB)));
478
479 return 0;
480}
481
482static int jh7110_stgcrg_init(struct udevice *dev)
483{
484 struct jh7110_clk_priv *priv = dev_get_priv(dev);
485
486 clk_dm(JH7110_STGCLK_USB_APB,
487 starfive_clk_gate(priv->reg,
488 "usb_apb", "apb_bus",
489 STGOFFSET(JH7110_STGCLK_USB_APB)));
490 clk_dm(JH7110_STGCLK_USB_UTMI_APB,
491 starfive_clk_gate(priv->reg,
492 "usb_utmi_apb", "apb_bus",
493 STGOFFSET(JH7110_STGCLK_USB_UTMI_APB)));
494 clk_dm(JH7110_STGCLK_USB_AXI,
495 starfive_clk_gate(priv->reg,
496 "usb_axi", "stg_axiahb",
497 STGOFFSET(JH7110_STGCLK_USB_AXI)));
498 clk_dm(JH7110_STGCLK_USB_LPM,
499 starfive_clk_gate_divider(priv->reg,
500 "usb_lpm", "oscillator",
501 STGOFFSET(JH7110_STGCLK_USB_LPM), 2));
502 clk_dm(JH7110_STGCLK_USB_STB,
503 starfive_clk_gate_divider(priv->reg,
504 "usb_stb", "oscillator",
505 STGOFFSET(JH7110_STGCLK_USB_STB), 3));
506 clk_dm(JH7110_STGCLK_USB_APP_125,
507 starfive_clk_gate(priv->reg,
508 "usb_app_125", "usb_125m",
509 STGOFFSET(JH7110_STGCLK_USB_APP_125)));
510 clk_dm(JH7110_STGCLK_USB_REFCLK,
511 starfive_clk_divider(priv->reg, "usb_refclk", "oscillator",
512 STGOFFSET(JH7110_STGCLK_USB_REFCLK), 2));
513 clk_dm(JH7110_STGCLK_PCIE0_AXI,
514 starfive_clk_gate(priv->reg,
515 "pcie0_axi", "stg_axiahb",
516 STGOFFSET(JH7110_STGCLK_PCIE0_AXI)));
517 clk_dm(JH7110_STGCLK_PCIE0_APB,
518 starfive_clk_gate(priv->reg,
519 "pcie0_apb", "apb_bus",
520 STGOFFSET(JH7110_STGCLK_PCIE0_APB)));
521 clk_dm(JH7110_STGCLK_PCIE0_TL,
522 starfive_clk_gate(priv->reg,
523 "pcie0_tl", "stg_axiahb",
524 STGOFFSET(JH7110_STGCLK_PCIE0_TL)));
525 clk_dm(JH7110_STGCLK_PCIE1_AXI,
526 starfive_clk_gate(priv->reg,
527 "pcie1_axi", "stg_axiahb",
528 STGOFFSET(JH7110_STGCLK_PCIE1_AXI)));
529 clk_dm(JH7110_STGCLK_PCIE1_APB,
530 starfive_clk_gate(priv->reg,
531 "pcie1_apb", "apb_bus",
532 STGOFFSET(JH7110_STGCLK_PCIE1_APB)));
533 clk_dm(JH7110_STGCLK_PCIE1_TL,
534 starfive_clk_gate(priv->reg,
535 "pcie1_tl", "stg_axiahb",
536 STGOFFSET(JH7110_STGCLK_PCIE1_TL)));
537
538 return 0;
539}
540
541static int jh7110_clk_probe(struct udevice *dev)
542{
543 struct jh7110_clk_priv *priv = dev_get_priv(dev);
544
545 priv->init = (jh1710_init_fn)dev_get_driver_data(dev);
546 priv->reg = (void __iomem *)dev_read_addr_ptr(dev);
547
548 if (priv->init)
549 return priv->init(dev);
550
551 return 0;
552}
553
554static int jh7110_clk_bind(struct udevice *dev)
555{
556 /* The reset driver does not have a device node, so bind it here */
557 return device_bind_driver_to_node(dev, "jh7110_reset", dev->name,
558 dev_ofnode(dev), NULL);
559}
560
561static const struct udevice_id jh7110_clk_of_match[] = {
562 { .compatible = "starfive,jh7110-syscrg",
563 .data = (ulong)&jh7110_syscrg_init
564 },
565 { .compatible = "starfive,jh7110-stgcrg",
566 .data = (ulong)&jh7110_stgcrg_init
567 },
568 { .compatible = "starfive,jh7110-aoncrg",
569 .data = (ulong)&jh7110_aoncrg_init
570 },
571 { }
572};
573
574U_BOOT_DRIVER(jh7110_clk) = {
575 .name = "jh7110_clk",
576 .id = UCLASS_CLK,
577 .of_match = jh7110_clk_of_match,
578 .probe = jh7110_clk_probe,
579 .ops = &ccf_clk_ops,
580 .priv_auto = sizeof(struct jh7110_clk_priv),
581 .bind = jh7110_clk_bind,
582};