Lines Matching +full:pd +full:- +full:disable

1 // SPDX-License-Identifier: GPL-2.0
11 #include "sifive-prci.h"
12 #include "fu540-prci.h"
13 #include "fu740-prci.h"
20 * __prci_readl() - read from a PRCI register
21 * @pd: PRCI context
25 * address of the PRCI register target described by @pd, and return
30 * Return: the contents of the register described by @pd and @offs.
32 static u32 __prci_readl(struct __prci_data *pd, u32 offs) in __prci_readl() argument
34 return readl_relaxed(pd->va + offs); in __prci_readl()
37 static void __prci_writel(u32 v, u32 offs, struct __prci_data *pd) in __prci_writel() argument
39 writel_relaxed(v, pd->va + offs); in __prci_writel()
42 /* WRPLL-related private functions */
45 * __prci_wrpll_unpack() - unpack WRPLL configuration registers into parameters
64 c->divr = v; in __prci_wrpll_unpack()
68 c->divf = v; in __prci_wrpll_unpack()
72 c->divq = v; in __prci_wrpll_unpack()
76 c->range = v; in __prci_wrpll_unpack()
78 c->flags &= in __prci_wrpll_unpack()
82 c->flags |= WRPLL_FLAGS_INT_FEEDBACK_MASK; in __prci_wrpll_unpack()
86 * __prci_wrpll_pack() - pack PLL configuration parameters into a register value
104 r |= c->divr << PRCI_COREPLLCFG0_DIVR_SHIFT; in __prci_wrpll_pack()
105 r |= c->divf << PRCI_COREPLLCFG0_DIVF_SHIFT; in __prci_wrpll_pack()
106 r |= c->divq << PRCI_COREPLLCFG0_DIVQ_SHIFT; in __prci_wrpll_pack()
107 r |= c->range << PRCI_COREPLLCFG0_RANGE_SHIFT; in __prci_wrpll_pack()
116 * __prci_wrpll_read_cfg0() - read the WRPLL configuration from the PRCI
117 * @pd: PRCI context
121 * the PRCI identified by @pd, and store it into the local configuration
125 * @pd and @pwd from changing during execution.
127 static void __prci_wrpll_read_cfg0(struct __prci_data *pd, in __prci_wrpll_read_cfg0() argument
130 __prci_wrpll_unpack(&pwd->c, __prci_readl(pd, pwd->cfg0_offs)); in __prci_wrpll_read_cfg0()
134 * __prci_wrpll_write_cfg0() - write WRPLL configuration into the PRCI
135 * @pd: PRCI context
145 * @pd and @pwd from changing during execution.
147 static void __prci_wrpll_write_cfg0(struct __prci_data *pd, in __prci_wrpll_write_cfg0() argument
151 __prci_writel(__prci_wrpll_pack(c), pwd->cfg0_offs, pd); in __prci_wrpll_write_cfg0()
153 memcpy(&pwd->c, c, sizeof(*c)); in __prci_wrpll_write_cfg0()
157 * __prci_wrpll_write_cfg1() - write Clock enable/disable configuration
159 * @pd: PRCI context
161 * @enable: Clock enable or disable value
163 static void __prci_wrpll_write_cfg1(struct __prci_data *pd, in __prci_wrpll_write_cfg1() argument
167 __prci_writel(enable, pwd->cfg1_offs, pd); in __prci_wrpll_write_cfg1()
181 struct __prci_wrpll_data *pwd = pc->pwd; in sifive_prci_wrpll_recalc_rate()
183 return wrpll_calc_output_rate(&pwd->c, parent_rate); in sifive_prci_wrpll_recalc_rate()
191 struct __prci_wrpll_data *pwd = pc->pwd; in sifive_prci_wrpll_round_rate()
194 memcpy(&c, &pwd->c, sizeof(c)); in sifive_prci_wrpll_round_rate()
205 struct __prci_wrpll_data *pwd = pc->pwd; in sifive_prci_wrpll_set_rate()
206 struct __prci_data *pd = pc->pd; in sifive_prci_wrpll_set_rate() local
209 r = wrpll_configure_for_rate(&pwd->c, rate, parent_rate); in sifive_prci_wrpll_set_rate()
213 if (pwd->enable_bypass) in sifive_prci_wrpll_set_rate()
214 pwd->enable_bypass(pd); in sifive_prci_wrpll_set_rate()
216 __prci_wrpll_write_cfg0(pd, pwd, &pwd->c); in sifive_prci_wrpll_set_rate()
218 udelay(wrpll_calc_max_lock_us(&pwd->c)); in sifive_prci_wrpll_set_rate()
226 struct __prci_wrpll_data *pwd = pc->pwd; in sifive_clk_is_enabled()
227 struct __prci_data *pd = pc->pd; in sifive_clk_is_enabled() local
230 r = __prci_readl(pd, pwd->cfg1_offs); in sifive_clk_is_enabled()
241 struct __prci_wrpll_data *pwd = pc->pwd; in sifive_prci_clock_enable()
242 struct __prci_data *pd = pc->pd; in sifive_prci_clock_enable() local
247 __prci_wrpll_write_cfg1(pd, pwd, PRCI_COREPLLCFG1_CKE_MASK); in sifive_prci_clock_enable()
249 if (pwd->disable_bypass) in sifive_prci_clock_enable()
250 pwd->disable_bypass(pd); in sifive_prci_clock_enable()
258 struct __prci_wrpll_data *pwd = pc->pwd; in sifive_prci_clock_disable()
259 struct __prci_data *pd = pc->pd; in sifive_prci_clock_disable() local
262 if (pwd->enable_bypass) in sifive_prci_clock_disable()
263 pwd->enable_bypass(pd); in sifive_prci_clock_disable()
265 r = __prci_readl(pd, pwd->cfg1_offs); in sifive_prci_clock_disable()
268 __prci_wrpll_write_cfg1(pd, pwd, r); in sifive_prci_clock_disable()
277 struct __prci_data *pd = pc->pd; in sifive_prci_tlclksel_recalc_rate() local
281 v = __prci_readl(pd, PRCI_CLKMUXSTATUSREG_OFFSET); in sifive_prci_tlclksel_recalc_rate()
294 struct __prci_data *pd = pc->pd; in sifive_prci_hfpclkplldiv_recalc_rate() local
295 u32 div = __prci_readl(pd, PRCI_HFPCLKPLLDIV_OFFSET); in sifive_prci_hfpclkplldiv_recalc_rate()
305 * sifive_prci_coreclksel_use_hfclk() - switch the CORECLK mux to output HFCLK
306 * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
313 void sifive_prci_coreclksel_use_hfclk(struct __prci_data *pd) in sifive_prci_coreclksel_use_hfclk() argument
317 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); in sifive_prci_coreclksel_use_hfclk()
319 __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd); in sifive_prci_coreclksel_use_hfclk()
321 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */ in sifive_prci_coreclksel_use_hfclk()
325 * sifive_prci_coreclksel_use_corepll() - switch the CORECLK mux to output
327 * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
334 void sifive_prci_coreclksel_use_corepll(struct __prci_data *pd) in sifive_prci_coreclksel_use_corepll() argument
338 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); in sifive_prci_coreclksel_use_corepll()
340 __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd); in sifive_prci_coreclksel_use_corepll()
342 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */ in sifive_prci_coreclksel_use_corepll()
346 * sifive_prci_coreclksel_use_final_corepll() - switch the CORECLK mux to output
348 * @pd: struct __prci_data * for the PRCI containing the CORECLK mux reg
356 void sifive_prci_coreclksel_use_final_corepll(struct __prci_data *pd) in sifive_prci_coreclksel_use_final_corepll() argument
360 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); in sifive_prci_coreclksel_use_final_corepll()
362 __prci_writel(r, PRCI_CORECLKSEL_OFFSET, pd); in sifive_prci_coreclksel_use_final_corepll()
364 r = __prci_readl(pd, PRCI_CORECLKSEL_OFFSET); /* barrier */ in sifive_prci_coreclksel_use_final_corepll()
368 * sifive_prci_corepllsel_use_dvfscorepll() - switch the COREPLL mux to
370 * @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg
377 void sifive_prci_corepllsel_use_dvfscorepll(struct __prci_data *pd) in sifive_prci_corepllsel_use_dvfscorepll() argument
381 r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET); in sifive_prci_corepllsel_use_dvfscorepll()
383 __prci_writel(r, PRCI_COREPLLSEL_OFFSET, pd); in sifive_prci_corepllsel_use_dvfscorepll()
385 r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET); /* barrier */ in sifive_prci_corepllsel_use_dvfscorepll()
389 * sifive_prci_corepllsel_use_corepll() - switch the COREPLL mux to
391 * @pd: struct __prci_data * for the PRCI containing the COREPLL mux reg
398 void sifive_prci_corepllsel_use_corepll(struct __prci_data *pd) in sifive_prci_corepllsel_use_corepll() argument
402 r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET); in sifive_prci_corepllsel_use_corepll()
404 __prci_writel(r, PRCI_COREPLLSEL_OFFSET, pd); in sifive_prci_corepllsel_use_corepll()
406 r = __prci_readl(pd, PRCI_COREPLLSEL_OFFSET); /* barrier */ in sifive_prci_corepllsel_use_corepll()
410 * sifive_prci_hfpclkpllsel_use_hfclk() - switch the HFPCLKPLL mux to
412 * @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg
419 void sifive_prci_hfpclkpllsel_use_hfclk(struct __prci_data *pd) in sifive_prci_hfpclkpllsel_use_hfclk() argument
423 r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET); in sifive_prci_hfpclkpllsel_use_hfclk()
425 __prci_writel(r, PRCI_HFPCLKPLLSEL_OFFSET, pd); in sifive_prci_hfpclkpllsel_use_hfclk()
427 r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET); /* barrier */ in sifive_prci_hfpclkpllsel_use_hfclk()
431 * sifive_prci_hfpclkpllsel_use_hfpclkpll() - switch the HFPCLKPLL mux to
433 * @pd: struct __prci_data * for the PRCI containing the HFPCLKPLL mux reg
440 void sifive_prci_hfpclkpllsel_use_hfpclkpll(struct __prci_data *pd) in sifive_prci_hfpclkpllsel_use_hfpclkpll() argument
444 r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET); in sifive_prci_hfpclkpllsel_use_hfpclkpll()
446 __prci_writel(r, PRCI_HFPCLKPLLSEL_OFFSET, pd); in sifive_prci_hfpclkpllsel_use_hfpclkpll()
448 r = __prci_readl(pd, PRCI_HFPCLKPLLSEL_OFFSET); /* barrier */ in sifive_prci_hfpclkpllsel_use_hfpclkpll()
451 /* PCIE AUX clock APIs for enable, disable. */
455 struct __prci_data *pd = pc->pd; in sifive_prci_pcie_aux_clock_is_enabled() local
458 r = __prci_readl(pd, PRCI_PCIE_AUX_OFFSET); in sifive_prci_pcie_aux_clock_is_enabled()
469 struct __prci_data *pd = pc->pd; in sifive_prci_pcie_aux_clock_enable() local
475 __prci_writel(1, PRCI_PCIE_AUX_OFFSET, pd); in sifive_prci_pcie_aux_clock_enable()
476 r = __prci_readl(pd, PRCI_PCIE_AUX_OFFSET); /* barrier */ in sifive_prci_pcie_aux_clock_enable()
484 struct __prci_data *pd = pc->pd; in sifive_prci_pcie_aux_clock_disable() local
487 __prci_writel(0, PRCI_PCIE_AUX_OFFSET, pd); in sifive_prci_pcie_aux_clock_disable()
488 r = __prci_readl(pd, PRCI_PCIE_AUX_OFFSET); /* barrier */ in sifive_prci_pcie_aux_clock_disable()
493 * __prci_register_clocks() - register clock controls in the PRCI
495 * @pd: The pointer for PRCI per-device instance data
503 static int __prci_register_clocks(struct device *dev, struct __prci_data *pd, in __prci_register_clocks() argument
510 parent_count = of_clk_get_parent_count(dev->of_node); in __prci_register_clocks()
514 return -EINVAL; in __prci_register_clocks()
518 for (i = 0; i < desc->num_clks; ++i) { in __prci_register_clocks()
519 pic = &(desc->clks[i]); in __prci_register_clocks()
521 init.name = pic->name; in __prci_register_clocks()
522 init.parent_names = &pic->parent_name; in __prci_register_clocks()
524 init.ops = pic->ops; in __prci_register_clocks()
525 pic->hw.init = &init; in __prci_register_clocks()
527 pic->pd = pd; in __prci_register_clocks()
529 if (pic->pwd) in __prci_register_clocks()
530 __prci_wrpll_read_cfg0(pd, pic->pwd); in __prci_register_clocks()
532 r = devm_clk_hw_register(dev, &pic->hw); in __prci_register_clocks()
539 pd->hw_clks.hws[i] = &pic->hw; in __prci_register_clocks()
542 pd->hw_clks.num = i; in __prci_register_clocks()
545 &pd->hw_clks); in __prci_register_clocks()
555 * sifive_prci_probe() - initialize prci data and check parent count
562 struct device *dev = &pdev->dev; in sifive_prci_probe()
563 struct __prci_data *pd; in sifive_prci_probe() local
567 desc = of_device_get_match_data(&pdev->dev); in sifive_prci_probe()
569 pd = devm_kzalloc(dev, struct_size(pd, hw_clks.hws, desc->num_clks), GFP_KERNEL); in sifive_prci_probe()
570 if (!pd) in sifive_prci_probe()
571 return -ENOMEM; in sifive_prci_probe()
573 pd->va = devm_platform_ioremap_resource(pdev, 0); in sifive_prci_probe()
574 if (IS_ERR(pd->va)) in sifive_prci_probe()
575 return PTR_ERR(pd->va); in sifive_prci_probe()
577 pd->reset.rcdev.owner = THIS_MODULE; in sifive_prci_probe()
578 pd->reset.rcdev.nr_resets = PRCI_RST_NR; in sifive_prci_probe()
579 pd->reset.rcdev.ops = &reset_simple_ops; in sifive_prci_probe()
580 pd->reset.rcdev.of_node = pdev->dev.of_node; in sifive_prci_probe()
581 pd->reset.active_low = true; in sifive_prci_probe()
582 pd->reset.membase = pd->va + PRCI_DEVICESRESETREG_OFFSET; in sifive_prci_probe()
583 spin_lock_init(&pd->reset.lock); in sifive_prci_probe()
585 r = devm_reset_controller_register(&pdev->dev, &pd->reset.rcdev); in sifive_prci_probe()
590 r = __prci_register_clocks(dev, pd, desc); in sifive_prci_probe()
602 {.compatible = "sifive,fu540-c000-prci", .data = &prci_clk_fu540},
603 {.compatible = "sifive,fu740-c000-prci", .data = &prci_clk_fu740},
610 .name = "sifive-clk-prci",