1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019 Western Digital Corporation or its affiliates.
5 * Copyright (C) 2018 SiFive, Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * The FU540 PRCI implements clock and reset control for the SiFive
19 * FU540-C000 chip. This driver assumes that it has sole control
20 * over all PRCI resources.
22 * This driver is based on the PRCI driver written by Wesley Terpstra.
24 * Refer, commit 999529edf517ed75b56659d456d221b2ee56bb60 of:
25 * https://github.com/riscv/riscv-linux
28 * - SiFive FU540-C000 manual v1p0, Chapter 7 "Clocking and Reset"
33 #include <clk-uclass.h>
38 #include <linux/delay.h>
39 #include <linux/err.h>
41 #include <linux/math64.h>
42 #include <linux/clk/analogbits-wrpll-cln28hpc.h>
43 #include <dt-bindings/clock/sifive-fu540-prci.h>
46 * EXPECTED_CLK_PARENT_COUNT: how many parent clocks this driver expects:
49 #define EXPECTED_CLK_PARENT_COUNT 2
52 * Register offsets and bitmasks
56 #define PRCI_COREPLLCFG0_OFFSET 0x4
57 #define PRCI_COREPLLCFG0_DIVR_SHIFT 0
58 #define PRCI_COREPLLCFG0_DIVR_MASK (0x3f << PRCI_COREPLLCFG0_DIVR_SHIFT)
59 #define PRCI_COREPLLCFG0_DIVF_SHIFT 6
60 #define PRCI_COREPLLCFG0_DIVF_MASK (0x1ff << PRCI_COREPLLCFG0_DIVF_SHIFT)
61 #define PRCI_COREPLLCFG0_DIVQ_SHIFT 15
62 #define PRCI_COREPLLCFG0_DIVQ_MASK (0x7 << PRCI_COREPLLCFG0_DIVQ_SHIFT)
63 #define PRCI_COREPLLCFG0_RANGE_SHIFT 18
64 #define PRCI_COREPLLCFG0_RANGE_MASK (0x7 << PRCI_COREPLLCFG0_RANGE_SHIFT)
65 #define PRCI_COREPLLCFG0_BYPASS_SHIFT 24
66 #define PRCI_COREPLLCFG0_BYPASS_MASK (0x1 << PRCI_COREPLLCFG0_BYPASS_SHIFT)
67 #define PRCI_COREPLLCFG0_FSE_SHIFT 25
68 #define PRCI_COREPLLCFG0_FSE_MASK (0x1 << PRCI_COREPLLCFG0_FSE_SHIFT)
69 #define PRCI_COREPLLCFG0_LOCK_SHIFT 31
70 #define PRCI_COREPLLCFG0_LOCK_MASK (0x1 << PRCI_COREPLLCFG0_LOCK_SHIFT)
73 #define PRCI_COREPLLCFG1_OFFSET 0x8
74 #define PRCI_COREPLLCFG1_CKE_SHIFT 31
75 #define PRCI_COREPLLCFG1_CKE_MASK (0x1 << PRCI_COREPLLCFG1_CKE_SHIFT)
78 #define PRCI_DDRPLLCFG0_OFFSET 0xc
79 #define PRCI_DDRPLLCFG0_DIVR_SHIFT 0
80 #define PRCI_DDRPLLCFG0_DIVR_MASK (0x3f << PRCI_DDRPLLCFG0_DIVR_SHIFT)
81 #define PRCI_DDRPLLCFG0_DIVF_SHIFT 6
82 #define PRCI_DDRPLLCFG0_DIVF_MASK (0x1ff << PRCI_DDRPLLCFG0_DIVF_SHIFT)
83 #define PRCI_DDRPLLCFG0_DIVQ_SHIFT 15
84 #define PRCI_DDRPLLCFG0_DIVQ_MASK (0x7 << PRCI_DDRPLLCFG0_DIVQ_SHIFT)
85 #define PRCI_DDRPLLCFG0_RANGE_SHIFT 18
86 #define PRCI_DDRPLLCFG0_RANGE_MASK (0x7 << PRCI_DDRPLLCFG0_RANGE_SHIFT)
87 #define PRCI_DDRPLLCFG0_BYPASS_SHIFT 24
88 #define PRCI_DDRPLLCFG0_BYPASS_MASK (0x1 << PRCI_DDRPLLCFG0_BYPASS_SHIFT)
89 #define PRCI_DDRPLLCFG0_FSE_SHIFT 25
90 #define PRCI_DDRPLLCFG0_FSE_MASK (0x1 << PRCI_DDRPLLCFG0_FSE_SHIFT)
91 #define PRCI_DDRPLLCFG0_LOCK_SHIFT 31
92 #define PRCI_DDRPLLCFG0_LOCK_MASK (0x1 << PRCI_DDRPLLCFG0_LOCK_SHIFT)
95 #define PRCI_DDRPLLCFG1_OFFSET 0x10
96 #define PRCI_DDRPLLCFG1_CKE_SHIFT 31
97 #define PRCI_DDRPLLCFG1_CKE_MASK (0x1 << PRCI_DDRPLLCFG1_CKE_SHIFT)
100 #define PRCI_GEMGXLPLLCFG0_OFFSET 0x1c
101 #define PRCI_GEMGXLPLLCFG0_DIVR_SHIFT 0
102 #define PRCI_GEMGXLPLLCFG0_DIVR_MASK \
103 (0x3f << PRCI_GEMGXLPLLCFG0_DIVR_SHIFT)
104 #define PRCI_GEMGXLPLLCFG0_DIVF_SHIFT 6
105 #define PRCI_GEMGXLPLLCFG0_DIVF_MASK \
106 (0x1ff << PRCI_GEMGXLPLLCFG0_DIVF_SHIFT)
107 #define PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT 15
108 #define PRCI_GEMGXLPLLCFG0_DIVQ_MASK (0x7 << PRCI_GEMGXLPLLCFG0_DIVQ_SHIFT)
109 #define PRCI_GEMGXLPLLCFG0_RANGE_SHIFT 18
110 #define PRCI_GEMGXLPLLCFG0_RANGE_MASK \
111 (0x7 << PRCI_GEMGXLPLLCFG0_RANGE_SHIFT)
112 #define PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT 24
113 #define PRCI_GEMGXLPLLCFG0_BYPASS_MASK \
114 (0x1 << PRCI_GEMGXLPLLCFG0_BYPASS_SHIFT)
115 #define PRCI_GEMGXLPLLCFG0_FSE_SHIFT 25
116 #define PRCI_GEMGXLPLLCFG0_FSE_MASK \
117 (0x1 << PRCI_GEMGXLPLLCFG0_FSE_SHIFT)
118 #define PRCI_GEMGXLPLLCFG0_LOCK_SHIFT 31
119 #define PRCI_GEMGXLPLLCFG0_LOCK_MASK (0x1 << PRCI_GEMGXLPLLCFG0_LOCK_SHIFT)
122 #define PRCI_GEMGXLPLLCFG1_OFFSET 0x20
123 #define PRCI_GEMGXLPLLCFG1_CKE_SHIFT 31
124 #define PRCI_GEMGXLPLLCFG1_CKE_MASK (0x1 << PRCI_GEMGXLPLLCFG1_CKE_SHIFT)
127 #define PRCI_CORECLKSEL_OFFSET 0x24
128 #define PRCI_CORECLKSEL_CORECLKSEL_SHIFT 0
129 #define PRCI_CORECLKSEL_CORECLKSEL_MASK \
130 (0x1 << PRCI_CORECLKSEL_CORECLKSEL_SHIFT)
132 /* DEVICESRESETREG */
133 #define PRCI_DEVICESRESETREG_OFFSET 0x28
134 #define PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_SHIFT 0
135 #define PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_MASK \
136 (0x1 << PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_SHIFT)
137 #define PRCI_DEVICESRESETREG_DDR_AXI_RST_N_SHIFT 1
138 #define PRCI_DEVICESRESETREG_DDR_AXI_RST_N_MASK \
139 (0x1 << PRCI_DEVICESRESETREG_DDR_AXI_RST_N_SHIFT)
140 #define PRCI_DEVICESRESETREG_DDR_AHB_RST_N_SHIFT 2
141 #define PRCI_DEVICESRESETREG_DDR_AHB_RST_N_MASK \
142 (0x1 << PRCI_DEVICESRESETREG_DDR_AHB_RST_N_SHIFT)
143 #define PRCI_DEVICESRESETREG_DDR_PHY_RST_N_SHIFT 3
144 #define PRCI_DEVICESRESETREG_DDR_PHY_RST_N_MASK \
145 (0x1 << PRCI_DEVICESRESETREG_DDR_PHY_RST_N_SHIFT)
146 #define PRCI_DEVICESRESETREG_GEMGXL_RST_N_SHIFT 5
147 #define PRCI_DEVICESRESETREG_GEMGXL_RST_N_MASK \
148 (0x1 << PRCI_DEVICESRESETREG_GEMGXL_RST_N_SHIFT)
150 /* CLKMUXSTATUSREG */
151 #define PRCI_CLKMUXSTATUSREG_OFFSET 0x2c
152 #define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT 1
153 #define PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK \
154 (0x1 << PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_SHIFT)
157 #define PRCI_PROCMONCFG_OFFSET 0xF0
158 #define PRCI_PROCMONCFG_CORE_CLOCK_SHIFT 24
159 #define PRCI_PROCMONCFG_CORE_CLOCK_MASK \
160 (0x1 << PRCI_PROCMONCFG_CORE_CLOCK_SHIFT)
167 * struct __prci_data - per-device-instance data
168 * @va: base virtual address of the PRCI IP block
169 * @parent: parent clk instance
171 * PRCI per-device instance data
175 struct clk parent_hfclk;
176 struct clk parent_rtcclk;
180 * struct __prci_wrpll_data - WRPLL configuration and integration data
181 * @c: WRPLL current configuration record
182 * @enable_bypass: fn ptr to code to bypass the WRPLL (if applicable; else NULL)
183 * @disable_bypass: fn ptr to code to not bypass the WRPLL (or NULL)
184 * @cfg0_offs: WRPLL CFG0 register offset (in bytes) from the PRCI base address
185 * @cfg1_offs: WRPLL CFG1 register offset (in bytes) from the PRCI base address
186 * @release_reset: fn ptr to code to release clock reset
188 * @enable_bypass and @disable_bypass are used for WRPLL instances
189 * that contain a separate external glitchless clock mux downstream
190 * from the PLL. The WRPLL internal bypass mux is not glitchless.
192 struct __prci_wrpll_data {
194 void (*enable_bypass)(struct __prci_data *pd);
195 void (*disable_bypass)(struct __prci_data *pd);
198 void (*release_reset)(struct __prci_data *pd);
203 /* struct __prci_clock_ops - clock operations */
204 struct __prci_clock_ops {
205 int (*set_rate)(struct __prci_clock *pc,
207 unsigned long parent_rate);
208 unsigned long (*round_rate)(struct __prci_clock *pc,
210 unsigned long *parent_rate);
211 unsigned long (*recalc_rate)(struct __prci_clock *pc,
212 unsigned long parent_rate);
213 int (*enable_clk)(struct __prci_clock *pc, bool enable);
217 * struct __prci_clock - describes a clock device managed by PRCI
218 * @name: user-readable clock name string - should match the manual
219 * @parent_name: parent name for this clock
220 * @ops: struct __prci_clock_ops for control
221 * @pwd: WRPLL-specific data, associated with this clock (if not NULL)
222 * @pd: PRCI-specific data associated with this clock (if not NULL)
224 * PRCI clock data. Used by the PRCI driver to register PRCI-provided
225 * clocks to the Linux clock infrastructure.
227 struct __prci_clock {
229 const char *parent_name;
230 const struct __prci_clock_ops *ops;
231 struct __prci_wrpll_data *pwd;
232 struct __prci_data *pd;
240 * __prci_readl() - read from a PRCI register
242 * @offs: register offset to read from (in bytes, from PRCI base address)
244 * Read the register located at offset @offs from the base virtual
245 * address of the PRCI register target described by @pd, and return
246 * the value to the caller.
248 * Context: Any context.
250 * Return: the contents of the register described by @pd and @offs.
252 static u32 __prci_readl(struct __prci_data *pd, u32 offs)
254 return readl(pd->va + offs);
257 static void __prci_writel(u32 v, u32 offs, struct __prci_data *pd)
259 writel(v, pd->va + offs);
262 /* WRPLL-related private functions */
265 * __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters
266 * @c: ptr to a struct wrpll_cfg record to write config into
267 * @r: value read from the PRCI PLL configuration register
269 * Given a value @r read from an FU540 PRCI PLL configuration register,
270 * split it into fields and populate it into the WRPLL configuration record
273 * The COREPLLCFG0 macros are used below, but the other *PLLCFG0 macros
274 * have the same register layout.
276 * Context: Any context.
278 static void __prci_wrpll_unpack(struct wrpll_cfg *c, u32 r)
282 v = r & PRCI_COREPLLCFG0_DIVR_MASK;
283 v >>= PRCI_COREPLLCFG0_DIVR_SHIFT;
286 v = r & PRCI_COREPLLCFG0_DIVF_MASK;
287 v >>= PRCI_COREPLLCFG0_DIVF_SHIFT;
290 v = r & PRCI_COREPLLCFG0_DIVQ_MASK;
291 v >>= PRCI_COREPLLCFG0_DIVQ_SHIFT;
294 v = r & PRCI_COREPLLCFG0_RANGE_MASK;
295 v >>= PRCI_COREPLLCFG0_RANGE_SHIFT;
298 c->flags &= (WRPLL_FLAGS_INT_FEEDBACK_MASK |
299 WRPLL_FLAGS_EXT_FEEDBACK_MASK);
301 /* external feedback mode not supported */
302 c->flags |= WRPLL_FLAGS_INT_FEEDBACK_MASK;
306 * __prci_wrpll_pack() - pack PLL configuration parameters into a register value
307 * @c: pointer to a struct wrpll_cfg record containing the PLL's cfg
309 * Using a set of WRPLL configuration values pointed to by @c,
310 * assemble a PRCI PLL configuration register value, and return it to
313 * Context: Any context. Caller must ensure that the contents of the
314 * record pointed to by @c do not change during the execution
317 * Returns: a value suitable for writing into a PRCI PLL configuration
320 static u32 __prci_wrpll_pack(const struct wrpll_cfg *c)
324 r |= c->divr << PRCI_COREPLLCFG0_DIVR_SHIFT;
325 r |= c->divf << PRCI_COREPLLCFG0_DIVF_SHIFT;
326 r |= c->divq << PRCI_COREPLLCFG0_DIVQ_SHIFT;
327 r |= c->range << PRCI_COREPLLCFG0_RANGE_SHIFT;
329 /* external feedback mode not supported */
330 r |= PRCI_COREPLLCFG0_FSE_MASK;
336 * __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI
338 * @pwd: PRCI WRPLL metadata
340 * Read the current configuration of the PLL identified by @pwd from
341 * the PRCI identified by @pd, and store it into the local configuration
344 * Context: Any context. Caller must prevent the records pointed to by
345 * @pd and @pwd from changing during execution.
347 static void __prci_wrpll_read_cfg0(struct __prci_data *pd,
348 struct __prci_wrpll_data *pwd)
350 __prci_wrpll_unpack(&pwd->c, __prci_readl(pd, pwd->cfg0_offs));
354 * __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI
356 * @pwd: PRCI WRPLL metadata
357 * @c: WRPLL configuration record to write
359 * Write the WRPLL configuration described by @c into the WRPLL
360 * configuration register identified by @pwd in the PRCI instance
361 * described by @c. Make a cached copy of the WRPLL's current
362 * configuration so it can be used by other code.
364 * Context: Any context. Caller must prevent the records pointed to by
365 * @pd and @pwd from changing during execution.
367 static void __prci_wrpll_write_cfg0(struct __prci_data *pd,
368 struct __prci_wrpll_data *pwd,
371 __prci_writel(__prci_wrpll_pack(c), pwd->cfg0_offs, pd);
373 memcpy(&pwd->c, c, sizeof(*c));
377 * __prci_wrpll_write_cfg1() - write Clock enable/disable configuration
380 * @pwd: PRCI WRPLL metadata
381 * @enable: Clock enable or disable value
383 static void __prci_wrpll_write_cfg1(struct __prci_data *pd,
384 struct __prci_wrpll_data *pwd,
387 __prci_writel(enable, pwd->cfg1_offs, pd);
390 /* Core clock mux control */
393 * __prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK
394 * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
396 * Switch the CORECLK mux to the HFCLK input source; return once complete.
398 * Context: Any context. Caller must prevent concurrent changes to the
399 * PRCI_CORECLKSEL_OFFSET register.
401 static void __prci_coreclksel_use_hfclk(struct __prci_data *pd)
405 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET);
406 r |= PRCI_CORECLKSEL_CORECLKSEL_MASK;
407 __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd);
409 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */
413 * __prci_coreclksel_use_corepll() - switch the CORECLK mux to output COREPLL
414 * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
416 * Switch the CORECLK mux to the PLL output clock; return once complete.
418 * Context: Any context. Caller must prevent concurrent changes to the
419 * PRCI_CORECLKSEL_OFFSET register.
421 static void __prci_coreclksel_use_corepll(struct __prci_data *pd)
425 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET);
426 r &= ~PRCI_CORECLKSEL_CORECLKSEL_MASK;
427 __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd);
429 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */
432 static unsigned long sifive_fu540_prci_wrpll_recalc_rate(
433 struct __prci_clock *pc,
434 unsigned long parent_rate)
436 struct __prci_wrpll_data *pwd = pc->pwd;
438 return wrpll_calc_output_rate(&pwd->c, parent_rate);
441 static unsigned long sifive_fu540_prci_wrpll_round_rate(
442 struct __prci_clock *pc,
444 unsigned long *parent_rate)
446 struct __prci_wrpll_data *pwd = pc->pwd;
449 memcpy(&c, &pwd->c, sizeof(c));
451 wrpll_configure_for_rate(&c, rate, *parent_rate);
453 return wrpll_calc_output_rate(&c, *parent_rate);
456 static int sifive_fu540_prci_wrpll_set_rate(struct __prci_clock *pc,
458 unsigned long parent_rate)
460 struct __prci_wrpll_data *pwd = pc->pwd;
461 struct __prci_data *pd = pc->pd;
464 r = wrpll_configure_for_rate(&pwd->c, rate, parent_rate);
468 if (pwd->enable_bypass)
469 pwd->enable_bypass(pd);
471 __prci_wrpll_write_cfg0(pd, pwd, &pwd->c);
473 udelay(wrpll_calc_max_lock_us(&pwd->c));
475 if (pwd->disable_bypass)
476 pwd->disable_bypass(pd);
481 static int sifive_fu540_prci_clock_enable(struct __prci_clock *pc, bool enable)
483 struct __prci_wrpll_data *pwd = pc->pwd;
484 struct __prci_data *pd = pc->pd;
487 __prci_wrpll_write_cfg1(pd, pwd, PRCI_COREPLLCFG1_CKE_MASK);
489 if (pwd->release_reset)
490 pwd->release_reset(pd);
494 r = __prci_readl(pd, pwd->cfg1_offs);
495 r &= ~PRCI_COREPLLCFG1_CKE_MASK;
497 __prci_wrpll_write_cfg1(pd, pwd, r);
503 static const struct __prci_clock_ops sifive_fu540_prci_wrpll_clk_ops = {
504 .set_rate = sifive_fu540_prci_wrpll_set_rate,
505 .round_rate = sifive_fu540_prci_wrpll_round_rate,
506 .recalc_rate = sifive_fu540_prci_wrpll_recalc_rate,
507 .enable_clk = sifive_fu540_prci_clock_enable,
510 /* TLCLKSEL clock integration */
512 static unsigned long sifive_fu540_prci_tlclksel_recalc_rate(
513 struct __prci_clock *pc,
514 unsigned long parent_rate)
516 struct __prci_data *pd = pc->pd;
520 v = __prci_readl(pd, PRCI_CLKMUXSTATUSREG_OFFSET);
521 v &= PRCI_CLKMUXSTATUSREG_TLCLKSEL_STATUS_MASK;
524 return div_u64(parent_rate, div);
527 static const struct __prci_clock_ops sifive_fu540_prci_tlclksel_clk_ops = {
528 .recalc_rate = sifive_fu540_prci_tlclksel_recalc_rate,
532 * __prci_ddr_release_reset() - Release DDR reset
533 * @pd: struct __prci_data * for the PRCI containing the DDRCLK mux reg
536 static void __prci_ddr_release_reset(struct __prci_data *pd)
540 v = __prci_readl(pd, PRCI_DEVICESRESETREG_OFFSET);
541 v |= PRCI_DEVICESRESETREG_DDR_CTRL_RST_N_MASK;
542 __prci_writel(v, PRCI_DEVICESRESETREG_OFFSET, pd);
544 /* HACK to get the '1 full controller clock cycle'. */
545 asm volatile ("fence");
546 v = __prci_readl(pd, PRCI_DEVICESRESETREG_OFFSET);
547 v |= (PRCI_DEVICESRESETREG_DDR_AXI_RST_N_MASK |
548 PRCI_DEVICESRESETREG_DDR_AHB_RST_N_MASK |
549 PRCI_DEVICESRESETREG_DDR_PHY_RST_N_MASK);
550 __prci_writel(v, PRCI_DEVICESRESETREG_OFFSET, pd);
552 /* HACK to get the '1 full controller clock cycle'. */
553 asm volatile ("fence");
556 * These take like 16 cycles to actually propagate. We can't go sending
557 * stuff before they come out of reset. So wait.
559 for (int i = 0; i < 256; i++)
560 asm volatile ("nop");
564 * __prci_ethernet_release_reset() - Release ethernet reset
565 * @pd: struct __prci_data * for the PRCI containing the Ethernet CLK mux reg
568 static void __prci_ethernet_release_reset(struct __prci_data *pd)
572 /* Release GEMGXL reset */
573 v = __prci_readl(pd, PRCI_DEVICESRESETREG_OFFSET);
574 v |= PRCI_DEVICESRESETREG_GEMGXL_RST_N_MASK;
575 __prci_writel(v, PRCI_DEVICESRESETREG_OFFSET, pd);
577 /* Procmon => core clock */
578 __prci_writel(PRCI_PROCMONCFG_CORE_CLOCK_MASK, PRCI_PROCMONCFG_OFFSET,
583 * PRCI integration data for each WRPLL instance
586 static struct __prci_wrpll_data __prci_corepll_data = {
587 .cfg0_offs = PRCI_COREPLLCFG0_OFFSET,
588 .cfg1_offs = PRCI_COREPLLCFG1_OFFSET,
589 .enable_bypass = __prci_coreclksel_use_hfclk,
590 .disable_bypass = __prci_coreclksel_use_corepll,
593 static struct __prci_wrpll_data __prci_ddrpll_data = {
594 .cfg0_offs = PRCI_DDRPLLCFG0_OFFSET,
595 .cfg1_offs = PRCI_DDRPLLCFG1_OFFSET,
596 .release_reset = __prci_ddr_release_reset,
599 static struct __prci_wrpll_data __prci_gemgxlpll_data = {
600 .cfg0_offs = PRCI_GEMGXLPLLCFG0_OFFSET,
601 .cfg1_offs = PRCI_GEMGXLPLLCFG1_OFFSET,
602 .release_reset = __prci_ethernet_release_reset,
606 * List of clock controls provided by the PRCI
609 static struct __prci_clock __prci_init_clocks[] = {
610 [PRCI_CLK_COREPLL] = {
612 .parent_name = "hfclk",
613 .ops = &sifive_fu540_prci_wrpll_clk_ops,
614 .pwd = &__prci_corepll_data,
616 [PRCI_CLK_DDRPLL] = {
618 .parent_name = "hfclk",
619 .ops = &sifive_fu540_prci_wrpll_clk_ops,
620 .pwd = &__prci_ddrpll_data,
622 [PRCI_CLK_GEMGXLPLL] = {
624 .parent_name = "hfclk",
625 .ops = &sifive_fu540_prci_wrpll_clk_ops,
626 .pwd = &__prci_gemgxlpll_data,
630 .parent_name = "corepll",
631 .ops = &sifive_fu540_prci_tlclksel_clk_ops,
635 static ulong sifive_fu540_prci_parent_rate(struct __prci_clock *pc)
638 struct __prci_clock *p;
640 if (strcmp(pc->parent_name, "corepll") == 0) {
641 p = &__prci_init_clocks[PRCI_CLK_COREPLL];
642 if (!p->pd || !p->ops->recalc_rate)
645 return p->ops->recalc_rate(p, sifive_fu540_prci_parent_rate(p));
648 if (strcmp(pc->parent_name, "rtcclk") == 0)
649 parent_rate = clk_get_rate(&pc->pd->parent_rtcclk);
651 parent_rate = clk_get_rate(&pc->pd->parent_hfclk);
656 static ulong sifive_fu540_prci_get_rate(struct clk *clk)
658 struct __prci_clock *pc;
660 if (ARRAY_SIZE(__prci_init_clocks) <= clk->id)
663 pc = &__prci_init_clocks[clk->id];
664 if (!pc->pd || !pc->ops->recalc_rate)
667 return pc->ops->recalc_rate(pc, sifive_fu540_prci_parent_rate(pc));
670 static ulong sifive_fu540_prci_set_rate(struct clk *clk, ulong rate)
673 struct __prci_clock *pc;
675 if (ARRAY_SIZE(__prci_init_clocks) <= clk->id)
678 pc = &__prci_init_clocks[clk->id];
679 if (!pc->pd || !pc->ops->set_rate)
682 err = pc->ops->set_rate(pc, rate, sifive_fu540_prci_parent_rate(pc));
689 static int sifive_fu540_prci_enable(struct clk *clk)
691 struct __prci_clock *pc;
694 if (ARRAY_SIZE(__prci_init_clocks) <= clk->id)
697 pc = &__prci_init_clocks[clk->id];
701 if (pc->ops->enable_clk)
702 ret = pc->ops->enable_clk(pc, 1);
707 static int sifive_fu540_prci_disable(struct clk *clk)
709 struct __prci_clock *pc;
712 if (ARRAY_SIZE(__prci_init_clocks) <= clk->id)
715 pc = &__prci_init_clocks[clk->id];
719 if (pc->ops->enable_clk)
720 ret = pc->ops->enable_clk(pc, 0);
725 static int sifive_fu540_prci_probe(struct udevice *dev)
728 struct __prci_clock *pc;
729 struct __prci_data *pd = dev_get_priv(dev);
731 pd->va = (void *)dev_read_addr(dev);
733 return PTR_ERR(pd->va);
735 err = clk_get_by_index(dev, 0, &pd->parent_hfclk);
739 err = clk_get_by_index(dev, 1, &pd->parent_rtcclk);
743 for (i = 0; i < ARRAY_SIZE(__prci_init_clocks); ++i) {
744 pc = &__prci_init_clocks[i];
747 __prci_wrpll_read_cfg0(pd, pc->pwd);
753 static struct clk_ops sifive_fu540_prci_ops = {
754 .set_rate = sifive_fu540_prci_set_rate,
755 .get_rate = sifive_fu540_prci_get_rate,
756 .enable = sifive_fu540_prci_enable,
757 .disable = sifive_fu540_prci_disable,
760 static const struct udevice_id sifive_fu540_prci_ids[] = {
761 { .compatible = "sifive,fu540-c000-prci" },
765 U_BOOT_DRIVER(sifive_fu540_prci) = {
766 .name = "sifive-fu540-prci",
768 .of_match = sifive_fu540_prci_ids,
769 .probe = sifive_fu540_prci_probe,
770 .ops = &sifive_fu540_prci_ops,
771 .priv_auto_alloc_size = sizeof(struct __prci_data),