1 // SPDX-License-Identifier: GPL-2.0
3 * Marvell Armada 39x SoC clocks
5 * Copyright (C) 2015 Marvell
14 #include <linux/kernel.h>
15 #include <linux/clk-provider.h>
21 * SARL[14:10] : Ratios between CPU, NBCLK, HCLK and DCLK.
23 * SARL[15] : TCLK frequency
27 * SARH[0] : Reference clock frequency
33 #define SARL_A390_TCLK_FREQ_OPT 15
34 #define SARL_A390_TCLK_FREQ_OPT_MASK 0x1
35 #define SARL_A390_CPU_DDR_L2_FREQ_OPT 10
36 #define SARL_A390_CPU_DDR_L2_FREQ_OPT_MASK 0x1F
38 #define SARH_A390_REFCLK_FREQ BIT(0)
40 static const u32 armada_39x_tclk_frequencies[] __initconst = {
45 static u32 __init armada_39x_get_tclk_freq(void __iomem *sar)
49 tclk_freq_select = ((readl(sar + SARL) >> SARL_A390_TCLK_FREQ_OPT) &
50 SARL_A390_TCLK_FREQ_OPT_MASK);
51 return armada_39x_tclk_frequencies[tclk_freq_select];
54 static const u32 armada_39x_cpu_frequencies[] __initconst = {
55 [0x0] = 666 * 1000 * 1000,
56 [0x2] = 800 * 1000 * 1000,
57 [0x3] = 800 * 1000 * 1000,
58 [0x4] = 1066 * 1000 * 1000,
59 [0x5] = 1066 * 1000 * 1000,
60 [0x6] = 1200 * 1000 * 1000,
61 [0x8] = 1332 * 1000 * 1000,
62 [0xB] = 1600 * 1000 * 1000,
63 [0xC] = 1600 * 1000 * 1000,
64 [0x12] = 1800 * 1000 * 1000,
65 [0x1E] = 1800 * 1000 * 1000,
68 static u32 __init armada_39x_get_cpu_freq(void __iomem *sar)
72 cpu_freq_select = ((readl(sar + SARL) >> SARL_A390_CPU_DDR_L2_FREQ_OPT) &
73 SARL_A390_CPU_DDR_L2_FREQ_OPT_MASK);
74 if (cpu_freq_select >= ARRAY_SIZE(armada_39x_cpu_frequencies)) {
75 pr_err("Selected CPU frequency (%d) unsupported\n",
80 return armada_39x_cpu_frequencies[cpu_freq_select];
83 enum { A390_CPU_TO_NBCLK, A390_CPU_TO_HCLK, A390_CPU_TO_DCLK };
85 static const struct coreclk_ratio armada_39x_coreclk_ratios[] __initconst = {
86 { .id = A390_CPU_TO_NBCLK, .name = "nbclk" },
87 { .id = A390_CPU_TO_HCLK, .name = "hclk" },
88 { .id = A390_CPU_TO_DCLK, .name = "dclk" },
91 static void __init armada_39x_get_clk_ratio(
92 void __iomem *sar, int id, int *mult, int *div)
95 case A390_CPU_TO_NBCLK:
99 case A390_CPU_TO_HCLK:
103 case A390_CPU_TO_DCLK:
110 static u32 __init armada_39x_refclk_ratio(void __iomem *sar)
112 if (readl(sar + SARH) & SARH_A390_REFCLK_FREQ)
113 return 40 * 1000 * 1000;
115 return 25 * 1000 * 1000;
118 static const struct coreclk_soc_desc armada_39x_coreclks = {
119 .get_tclk_freq = armada_39x_get_tclk_freq,
120 .get_cpu_freq = armada_39x_get_cpu_freq,
121 .get_clk_ratio = armada_39x_get_clk_ratio,
122 .get_refclk_freq = armada_39x_refclk_ratio,
123 .ratios = armada_39x_coreclk_ratios,
124 .num_ratios = ARRAY_SIZE(armada_39x_coreclk_ratios),
127 static void __init armada_39x_coreclk_init(struct device_node *np)
129 mvebu_coreclk_setup(np, &armada_39x_coreclks);
131 CLK_OF_DECLARE(armada_39x_core_clk, "marvell,armada-390-core-clock",
132 armada_39x_coreclk_init);
135 * Clock Gating Control
137 static const struct clk_gating_soc_desc armada_39x_gating_desc[] __initconst = {
142 { "usb3h0", NULL, 9 },
143 { "usb3h1", NULL, 10 },
144 { "sata0", NULL, 15 },
145 { "sdio", NULL, 17 },
146 { "xor0", NULL, 22 },
147 { "xor1", NULL, 28 },
151 static void __init armada_39x_clk_gating_init(struct device_node *np)
153 mvebu_clk_gating_setup(np, armada_39x_gating_desc);
155 CLK_OF_DECLARE(armada_39x_clk_gating, "marvell,armada-390-gating-clock",
156 armada_39x_clk_gating_init);