1 // SPDX-License-Identifier: GPL-2.0
3 * Marvell Orion SoC clocks
5 * Copyright (C) 2014 Thomas Petazzoni
7 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
11 #include <linux/kernel.h>
12 #include <linux/clk-provider.h>
17 static const struct coreclk_ratio orion_coreclk_ratios
[] __initconst
= {
18 { .id
= 0, .name
= "ddrclk", }
25 #define SAR_MV88F5181_TCLK_FREQ 8
26 #define SAR_MV88F5181_TCLK_FREQ_MASK 0x3
28 static u32 __init
mv88f5181_get_tclk_freq(void __iomem
*sar
)
30 u32 opt
= (readl(sar
) >> SAR_MV88F5181_TCLK_FREQ
) &
31 SAR_MV88F5181_TCLK_FREQ_MASK
;
42 #define SAR_MV88F5181_CPU_FREQ 4
43 #define SAR_MV88F5181_CPU_FREQ_MASK 0xf
45 static u32 __init
mv88f5181_get_cpu_freq(void __iomem
*sar
)
47 u32 opt
= (readl(sar
) >> SAR_MV88F5181_CPU_FREQ
) &
48 SAR_MV88F5181_CPU_FREQ_MASK
;
51 else if (opt
== 1 || opt
== 2)
59 static void __init
mv88f5181_get_clk_ratio(void __iomem
*sar
, int id
,
62 u32 opt
= (readl(sar
) >> SAR_MV88F5181_CPU_FREQ
) &
63 SAR_MV88F5181_CPU_FREQ_MASK
;
64 if (opt
== 0 || opt
== 1) {
67 } else if (opt
== 2 || opt
== 3) {
76 static const struct coreclk_soc_desc mv88f5181_coreclks
= {
77 .get_tclk_freq
= mv88f5181_get_tclk_freq
,
78 .get_cpu_freq
= mv88f5181_get_cpu_freq
,
79 .get_clk_ratio
= mv88f5181_get_clk_ratio
,
80 .ratios
= orion_coreclk_ratios
,
81 .num_ratios
= ARRAY_SIZE(orion_coreclk_ratios
),
84 static void __init
mv88f5181_clk_init(struct device_node
*np
)
86 return mvebu_coreclk_setup(np
, &mv88f5181_coreclks
);
89 CLK_OF_DECLARE(mv88f5181_clk
, "marvell,mv88f5181-core-clock", mv88f5181_clk_init
);
95 #define SAR_MV88F5182_TCLK_FREQ 8
96 #define SAR_MV88F5182_TCLK_FREQ_MASK 0x3
98 static u32 __init
mv88f5182_get_tclk_freq(void __iomem
*sar
)
100 u32 opt
= (readl(sar
) >> SAR_MV88F5182_TCLK_FREQ
) &
101 SAR_MV88F5182_TCLK_FREQ_MASK
;
110 #define SAR_MV88F5182_CPU_FREQ 4
111 #define SAR_MV88F5182_CPU_FREQ_MASK 0xf
113 static u32 __init
mv88f5182_get_cpu_freq(void __iomem
*sar
)
115 u32 opt
= (readl(sar
) >> SAR_MV88F5182_CPU_FREQ
) &
116 SAR_MV88F5182_CPU_FREQ_MASK
;
119 else if (opt
== 1 || opt
== 2)
127 static void __init
mv88f5182_get_clk_ratio(void __iomem
*sar
, int id
,
130 u32 opt
= (readl(sar
) >> SAR_MV88F5182_CPU_FREQ
) &
131 SAR_MV88F5182_CPU_FREQ_MASK
;
132 if (opt
== 0 || opt
== 1) {
135 } else if (opt
== 2 || opt
== 3) {
144 static const struct coreclk_soc_desc mv88f5182_coreclks
= {
145 .get_tclk_freq
= mv88f5182_get_tclk_freq
,
146 .get_cpu_freq
= mv88f5182_get_cpu_freq
,
147 .get_clk_ratio
= mv88f5182_get_clk_ratio
,
148 .ratios
= orion_coreclk_ratios
,
149 .num_ratios
= ARRAY_SIZE(orion_coreclk_ratios
),
152 static void __init
mv88f5182_clk_init(struct device_node
*np
)
154 return mvebu_coreclk_setup(np
, &mv88f5182_coreclks
);
157 CLK_OF_DECLARE(mv88f5182_clk
, "marvell,mv88f5182-core-clock", mv88f5182_clk_init
);
163 static u32 __init
mv88f5281_get_tclk_freq(void __iomem
*sar
)
165 /* On 5281, tclk is always 166 Mhz */
169 #define SAR_MV88F5281_CPU_FREQ 4
170 #define SAR_MV88F5281_CPU_FREQ_MASK 0xf
172 static u32 __init
mv88f5281_get_cpu_freq(void __iomem
*sar
)
174 u32 opt
= (readl(sar
) >> SAR_MV88F5281_CPU_FREQ
) &
175 SAR_MV88F5281_CPU_FREQ_MASK
;
176 if (opt
== 1 || opt
== 2)
184 static void __init
mv88f5281_get_clk_ratio(void __iomem
*sar
, int id
,
187 u32 opt
= (readl(sar
) >> SAR_MV88F5281_CPU_FREQ
) &
188 SAR_MV88F5281_CPU_FREQ_MASK
;
192 } else if (opt
== 2 || opt
== 3) {
201 static const struct coreclk_soc_desc mv88f5281_coreclks
= {
202 .get_tclk_freq
= mv88f5281_get_tclk_freq
,
203 .get_cpu_freq
= mv88f5281_get_cpu_freq
,
204 .get_clk_ratio
= mv88f5281_get_clk_ratio
,
205 .ratios
= orion_coreclk_ratios
,
206 .num_ratios
= ARRAY_SIZE(orion_coreclk_ratios
),
209 static void __init
mv88f5281_clk_init(struct device_node
*np
)
211 return mvebu_coreclk_setup(np
, &mv88f5281_coreclks
);
214 CLK_OF_DECLARE(mv88f5281_clk
, "marvell,mv88f5281-core-clock", mv88f5281_clk_init
);
220 #define SAR_MV88F6183_TCLK_FREQ 9
221 #define SAR_MV88F6183_TCLK_FREQ_MASK 0x1
223 static u32 __init
mv88f6183_get_tclk_freq(void __iomem
*sar
)
225 u32 opt
= (readl(sar
) >> SAR_MV88F6183_TCLK_FREQ
) &
226 SAR_MV88F6183_TCLK_FREQ_MASK
;
235 #define SAR_MV88F6183_CPU_FREQ 1
236 #define SAR_MV88F6183_CPU_FREQ_MASK 0x3f
238 static u32 __init
mv88f6183_get_cpu_freq(void __iomem
*sar
)
240 u32 opt
= (readl(sar
) >> SAR_MV88F6183_CPU_FREQ
) &
241 SAR_MV88F6183_CPU_FREQ_MASK
;
250 static void __init
mv88f6183_get_clk_ratio(void __iomem
*sar
, int id
,
253 u32 opt
= (readl(sar
) >> SAR_MV88F6183_CPU_FREQ
) &
254 SAR_MV88F6183_CPU_FREQ_MASK
;
255 if (opt
== 9 || opt
== 17) {
264 static const struct coreclk_soc_desc mv88f6183_coreclks
= {
265 .get_tclk_freq
= mv88f6183_get_tclk_freq
,
266 .get_cpu_freq
= mv88f6183_get_cpu_freq
,
267 .get_clk_ratio
= mv88f6183_get_clk_ratio
,
268 .ratios
= orion_coreclk_ratios
,
269 .num_ratios
= ARRAY_SIZE(orion_coreclk_ratios
),
273 static void __init
mv88f6183_clk_init(struct device_node
*np
)
275 return mvebu_coreclk_setup(np
, &mv88f6183_coreclks
);
278 CLK_OF_DECLARE(mv88f6183_clk
, "marvell,mv88f6183-core-clock", mv88f6183_clk_init
);