1 // SPDX-License-Identifier: GPL-2.0
3 * Marvell Armada XP SoC clocks
5 * Copyright (C) 2012 Marvell
7 * Gregory CLEMENT <gregory.clement@free-electrons.com>
8 * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
9 * Andrew Lunn <andrew@lunn.ch>
13 #include <linux/kernel.h>
14 #include <linux/clk-provider.h>
22 * Armada XP Sample At Reset is a 64 bit bitfiled split in two
26 #define SARL 0 /* Low part [0:31] */
27 #define SARL_AXP_PCLK_FREQ_OPT 21
28 #define SARL_AXP_PCLK_FREQ_OPT_MASK 0x7
29 #define SARL_AXP_FAB_FREQ_OPT 24
30 #define SARL_AXP_FAB_FREQ_OPT_MASK 0xF
31 #define SARH 4 /* High part [32:63] */
32 #define SARH_AXP_PCLK_FREQ_OPT (52-32)
33 #define SARH_AXP_PCLK_FREQ_OPT_MASK 0x1
34 #define SARH_AXP_PCLK_FREQ_OPT_SHIFT 3
35 #define SARH_AXP_FAB_FREQ_OPT (51-32)
36 #define SARH_AXP_FAB_FREQ_OPT_MASK 0x1
37 #define SARH_AXP_FAB_FREQ_OPT_SHIFT 4
39 enum { AXP_CPU_TO_NBCLK, AXP_CPU_TO_HCLK, AXP_CPU_TO_DRAMCLK };
41 static const struct coreclk_ratio axp_coreclk_ratios[] __initconst = {
42 { .id = AXP_CPU_TO_NBCLK, .name = "nbclk" },
43 { .id = AXP_CPU_TO_HCLK, .name = "hclk" },
44 { .id = AXP_CPU_TO_DRAMCLK, .name = "dramclk" },
47 /* Armada XP TCLK frequency is fixed to 250MHz */
48 static u32 __init axp_get_tclk_freq(void __iomem *sar)
53 /* MV98DX3236 TCLK frequency is fixed to 200MHz */
54 static u32 __init mv98dx3236_get_tclk_freq(void __iomem *sar)
59 static const u32 axp_cpu_freqs[] __initconst = {
74 static u32 __init axp_get_cpu_freq(void __iomem *sar)
77 u8 cpu_freq_select = 0;
79 cpu_freq_select = ((readl(sar + SARL) >> SARL_AXP_PCLK_FREQ_OPT) &
80 SARL_AXP_PCLK_FREQ_OPT_MASK);
82 * The upper bit is not contiguous to the other ones and
83 * located in the high part of the SAR registers
85 cpu_freq_select |= (((readl(sar + SARH) >> SARH_AXP_PCLK_FREQ_OPT) &
86 SARH_AXP_PCLK_FREQ_OPT_MASK) << SARH_AXP_PCLK_FREQ_OPT_SHIFT);
87 if (cpu_freq_select >= ARRAY_SIZE(axp_cpu_freqs)) {
88 pr_err("CPU freq select unsupported: %d\n", cpu_freq_select);
91 cpu_freq = axp_cpu_freqs[cpu_freq_select];
96 /* MV98DX3236 CLK frequency is fixed to 800MHz */
97 static u32 __init mv98dx3236_get_cpu_freq(void __iomem *sar)
102 static const int axp_nbclk_ratios[32][2] __initconst = {
103 {0, 1}, {1, 2}, {2, 2}, {2, 2},
104 {1, 2}, {1, 2}, {1, 1}, {2, 3},
105 {0, 1}, {1, 2}, {2, 4}, {0, 1},
106 {1, 2}, {0, 1}, {0, 1}, {2, 2},
107 {0, 1}, {0, 1}, {0, 1}, {1, 1},
108 {2, 3}, {0, 1}, {0, 1}, {0, 1},
109 {0, 1}, {0, 1}, {0, 1}, {1, 1},
110 {0, 1}, {0, 1}, {0, 1}, {0, 1},
113 static const int axp_hclk_ratios[32][2] __initconst = {
114 {0, 1}, {1, 2}, {2, 6}, {2, 3},
115 {1, 3}, {1, 4}, {1, 2}, {2, 6},
116 {0, 1}, {1, 6}, {2, 10}, {0, 1},
117 {1, 4}, {0, 1}, {0, 1}, {2, 5},
118 {0, 1}, {0, 1}, {0, 1}, {1, 2},
119 {2, 6}, {0, 1}, {0, 1}, {0, 1},
120 {0, 1}, {0, 1}, {0, 1}, {1, 1},
121 {0, 1}, {0, 1}, {0, 1}, {0, 1},
124 static const int axp_dramclk_ratios[32][2] __initconst = {
125 {0, 1}, {1, 2}, {2, 3}, {2, 3},
126 {1, 3}, {1, 2}, {1, 2}, {2, 6},
127 {0, 1}, {1, 3}, {2, 5}, {0, 1},
128 {1, 4}, {0, 1}, {0, 1}, {2, 5},
129 {0, 1}, {0, 1}, {0, 1}, {1, 1},
130 {2, 3}, {0, 1}, {0, 1}, {0, 1},
131 {0, 1}, {0, 1}, {0, 1}, {1, 1},
132 {0, 1}, {0, 1}, {0, 1}, {0, 1},
135 static void __init axp_get_clk_ratio(
136 void __iomem *sar, int id, int *mult, int *div)
138 u32 opt = ((readl(sar + SARL) >> SARL_AXP_FAB_FREQ_OPT) &
139 SARL_AXP_FAB_FREQ_OPT_MASK);
141 * The upper bit is not contiguous to the other ones and
142 * located in the high part of the SAR registers
144 opt |= (((readl(sar + SARH) >> SARH_AXP_FAB_FREQ_OPT) &
145 SARH_AXP_FAB_FREQ_OPT_MASK) << SARH_AXP_FAB_FREQ_OPT_SHIFT);
148 case AXP_CPU_TO_NBCLK:
149 *mult = axp_nbclk_ratios[opt][0];
150 *div = axp_nbclk_ratios[opt][1];
152 case AXP_CPU_TO_HCLK:
153 *mult = axp_hclk_ratios[opt][0];
154 *div = axp_hclk_ratios[opt][1];
156 case AXP_CPU_TO_DRAMCLK:
157 *mult = axp_dramclk_ratios[opt][0];
158 *div = axp_dramclk_ratios[opt][1];
163 static const struct coreclk_soc_desc axp_coreclks = {
164 .get_tclk_freq = axp_get_tclk_freq,
165 .get_cpu_freq = axp_get_cpu_freq,
166 .get_clk_ratio = axp_get_clk_ratio,
167 .ratios = axp_coreclk_ratios,
168 .num_ratios = ARRAY_SIZE(axp_coreclk_ratios),
171 static const struct coreclk_soc_desc mv98dx3236_coreclks = {
172 .get_tclk_freq = mv98dx3236_get_tclk_freq,
173 .get_cpu_freq = mv98dx3236_get_cpu_freq,
177 * Clock Gating Control
180 static const struct clk_gating_soc_desc axp_gating_desc[] __initconst = {
181 { "audio", NULL, 0, 0 },
182 { "ge3", NULL, 1, 0 },
183 { "ge2", NULL, 2, 0 },
184 { "ge1", NULL, 3, 0 },
185 { "ge0", NULL, 4, 0 },
186 { "pex00", NULL, 5, 0 },
187 { "pex01", NULL, 6, 0 },
188 { "pex02", NULL, 7, 0 },
189 { "pex03", NULL, 8, 0 },
190 { "pex10", NULL, 9, 0 },
191 { "pex11", NULL, 10, 0 },
192 { "pex12", NULL, 11, 0 },
193 { "pex13", NULL, 12, 0 },
194 { "bp", NULL, 13, 0 },
195 { "sata0lnk", NULL, 14, 0 },
196 { "sata0", "sata0lnk", 15, 0 },
197 { "lcd", NULL, 16, 0 },
198 { "sdio", NULL, 17, 0 },
199 { "usb0", NULL, 18, 0 },
200 { "usb1", NULL, 19, 0 },
201 { "usb2", NULL, 20, 0 },
202 { "xor0", NULL, 22, 0 },
203 { "crypto", NULL, 23, 0 },
204 { "tdm", NULL, 25, 0 },
205 { "pex20", NULL, 26, 0 },
206 { "pex30", NULL, 27, 0 },
207 { "xor1", NULL, 28, 0 },
208 { "sata1lnk", NULL, 29, 0 },
209 { "sata1", "sata1lnk", 30, 0 },
213 static const struct clk_gating_soc_desc mv98dx3236_gating_desc[] __initconst = {
214 { "ge1", NULL, 3, 0 },
215 { "ge0", NULL, 4, 0 },
216 { "pex00", NULL, 5, 0 },
217 { "sdio", NULL, 17, 0 },
218 { "xor0", NULL, 22, 0 },
222 static void __init axp_clk_init(struct device_node *np)
224 struct device_node *cgnp =
225 of_find_compatible_node(NULL, NULL, "marvell,armada-xp-gating-clock");
227 mvebu_coreclk_setup(np, &axp_coreclks);
230 mvebu_clk_gating_setup(cgnp, axp_gating_desc);
234 CLK_OF_DECLARE(axp_clk, "marvell,armada-xp-core-clock", axp_clk_init);