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 static const u32 axp_cpu_freqs
[] __initconst
= {
68 static u32 __init
axp_get_cpu_freq(void __iomem
*sar
)
71 u8 cpu_freq_select
= 0;
73 cpu_freq_select
= ((readl(sar
+ SARL
) >> SARL_AXP_PCLK_FREQ_OPT
) &
74 SARL_AXP_PCLK_FREQ_OPT_MASK
);
76 * The upper bit is not contiguous to the other ones and
77 * located in the high part of the SAR registers
79 cpu_freq_select
|= (((readl(sar
+ SARH
) >> SARH_AXP_PCLK_FREQ_OPT
) &
80 SARH_AXP_PCLK_FREQ_OPT_MASK
) << SARH_AXP_PCLK_FREQ_OPT_SHIFT
);
81 if (cpu_freq_select
>= ARRAY_SIZE(axp_cpu_freqs
)) {
82 pr_err("CPU freq select unsupported: %d\n", cpu_freq_select
);
85 cpu_freq
= axp_cpu_freqs
[cpu_freq_select
];
90 static const int axp_nbclk_ratios
[32][2] __initconst
= {
91 {0, 1}, {1, 2}, {2, 2}, {2, 2},
92 {1, 2}, {1, 2}, {1, 1}, {2, 3},
93 {0, 1}, {1, 2}, {2, 4}, {0, 1},
94 {1, 2}, {0, 1}, {0, 1}, {2, 2},
95 {0, 1}, {0, 1}, {0, 1}, {1, 1},
96 {2, 3}, {0, 1}, {0, 1}, {0, 1},
97 {0, 1}, {0, 1}, {0, 1}, {1, 1},
98 {0, 1}, {0, 1}, {0, 1}, {0, 1},
101 static const int axp_hclk_ratios
[32][2] __initconst
= {
102 {0, 1}, {1, 2}, {2, 6}, {2, 3},
103 {1, 3}, {1, 4}, {1, 2}, {2, 6},
104 {0, 1}, {1, 6}, {2, 10}, {0, 1},
105 {1, 4}, {0, 1}, {0, 1}, {2, 5},
106 {0, 1}, {0, 1}, {0, 1}, {1, 2},
107 {2, 6}, {0, 1}, {0, 1}, {0, 1},
108 {0, 1}, {0, 1}, {0, 1}, {1, 1},
109 {0, 1}, {0, 1}, {0, 1}, {0, 1},
112 static const int axp_dramclk_ratios
[32][2] __initconst
= {
113 {0, 1}, {1, 2}, {2, 3}, {2, 3},
114 {1, 3}, {1, 2}, {1, 2}, {2, 6},
115 {0, 1}, {1, 3}, {2, 5}, {0, 1},
116 {1, 4}, {0, 1}, {0, 1}, {2, 5},
117 {0, 1}, {0, 1}, {0, 1}, {1, 1},
118 {2, 3}, {0, 1}, {0, 1}, {0, 1},
119 {0, 1}, {0, 1}, {0, 1}, {1, 1},
120 {0, 1}, {0, 1}, {0, 1}, {0, 1},
123 static void __init
axp_get_clk_ratio(
124 void __iomem
*sar
, int id
, int *mult
, int *div
)
126 u32 opt
= ((readl(sar
+ SARL
) >> SARL_AXP_FAB_FREQ_OPT
) &
127 SARL_AXP_FAB_FREQ_OPT_MASK
);
129 * The upper bit is not contiguous to the other ones and
130 * located in the high part of the SAR registers
132 opt
|= (((readl(sar
+ SARH
) >> SARH_AXP_FAB_FREQ_OPT
) &
133 SARH_AXP_FAB_FREQ_OPT_MASK
) << SARH_AXP_FAB_FREQ_OPT_SHIFT
);
136 case AXP_CPU_TO_NBCLK
:
137 *mult
= axp_nbclk_ratios
[opt
][0];
138 *div
= axp_nbclk_ratios
[opt
][1];
140 case AXP_CPU_TO_HCLK
:
141 *mult
= axp_hclk_ratios
[opt
][0];
142 *div
= axp_hclk_ratios
[opt
][1];
144 case AXP_CPU_TO_DRAMCLK
:
145 *mult
= axp_dramclk_ratios
[opt
][0];
146 *div
= axp_dramclk_ratios
[opt
][1];
151 static const struct coreclk_soc_desc axp_coreclks
= {
152 .get_tclk_freq
= axp_get_tclk_freq
,
153 .get_cpu_freq
= axp_get_cpu_freq
,
154 .get_clk_ratio
= axp_get_clk_ratio
,
155 .ratios
= axp_coreclk_ratios
,
156 .num_ratios
= ARRAY_SIZE(axp_coreclk_ratios
),
160 * Clock Gating Control
163 static const struct clk_gating_soc_desc axp_gating_desc
[] __initconst
= {
164 { "audio", NULL
, 0, 0 },
165 { "ge3", NULL
, 1, 0 },
166 { "ge2", NULL
, 2, 0 },
167 { "ge1", NULL
, 3, 0 },
168 { "ge0", NULL
, 4, 0 },
169 { "pex00", NULL
, 5, 0 },
170 { "pex01", NULL
, 6, 0 },
171 { "pex02", NULL
, 7, 0 },
172 { "pex03", NULL
, 8, 0 },
173 { "pex10", NULL
, 9, 0 },
174 { "pex11", NULL
, 10, 0 },
175 { "pex12", NULL
, 11, 0 },
176 { "pex13", NULL
, 12, 0 },
177 { "bp", NULL
, 13, 0 },
178 { "sata0lnk", NULL
, 14, 0 },
179 { "sata0", "sata0lnk", 15, 0 },
180 { "lcd", NULL
, 16, 0 },
181 { "sdio", NULL
, 17, 0 },
182 { "usb0", NULL
, 18, 0 },
183 { "usb1", NULL
, 19, 0 },
184 { "usb2", NULL
, 20, 0 },
185 { "xor0", NULL
, 22, 0 },
186 { "crypto", NULL
, 23, 0 },
187 { "tdm", NULL
, 25, 0 },
188 { "pex20", NULL
, 26, 0 },
189 { "pex30", NULL
, 27, 0 },
190 { "xor1", NULL
, 28, 0 },
191 { "sata1lnk", NULL
, 29, 0 },
192 { "sata1", "sata1lnk", 30, 0 },
196 static void __init
axp_clk_init(struct device_node
*np
)
198 struct device_node
*cgnp
=
199 of_find_compatible_node(NULL
, NULL
, "marvell,armada-xp-gating-clock");
201 mvebu_coreclk_setup(np
, &axp_coreclks
);
204 mvebu_clk_gating_setup(cgnp
, axp_gating_desc
);
208 CLK_OF_DECLARE(axp_clk
, "marvell,armada-xp-core-clock", axp_clk_init
);