1 // SPDX-License-Identifier: GPL-2.0
3 * Marvell Armada AP806 System Controller
5 * Copyright (C) 2016 Marvell
7 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
11 #define pr_fmt(fmt) "ap806-system-controller: " fmt
13 #include "armada_ap_cp_helper.h"
14 #include <linux/clk-provider.h>
15 #include <linux/mfd/syscon.h>
16 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/regmap.h>
21 #define AP806_SAR_REG 0x400
22 #define AP806_SAR_CLKFREQ_MODE_MASK 0x1f
24 #define AP806_CLK_NUM 6
26 static struct clk
*ap806_clks
[AP806_CLK_NUM
];
28 static struct clk_onecell_data ap806_clk_data
= {
30 .clk_num
= AP806_CLK_NUM
,
33 static int ap806_get_sar_clocks(unsigned int freq_mode
,
34 unsigned int *cpuclk_freq
,
35 unsigned int *dclk_freq
)
105 static int ap807_get_sar_clocks(unsigned int freq_mode
,
106 unsigned int *cpuclk_freq
,
107 unsigned int *dclk_freq
)
129 static int ap806_syscon_common_probe(struct platform_device
*pdev
,
130 struct device_node
*syscon_node
)
132 unsigned int freq_mode
, cpuclk_freq
, dclk_freq
;
133 const char *name
, *fixedclk_name
;
134 struct device
*dev
= &pdev
->dev
;
135 struct device_node
*np
= dev
->of_node
;
136 struct regmap
*regmap
;
140 regmap
= syscon_node_to_regmap(syscon_node
);
141 if (IS_ERR(regmap
)) {
142 dev_err(dev
, "cannot get regmap\n");
143 return PTR_ERR(regmap
);
146 ret
= regmap_read(regmap
, AP806_SAR_REG
, ®
);
148 dev_err(dev
, "cannot read from regmap\n");
152 freq_mode
= reg
& AP806_SAR_CLKFREQ_MODE_MASK
;
154 if (of_device_is_compatible(pdev
->dev
.of_node
,
155 "marvell,ap806-clock")) {
156 ret
= ap806_get_sar_clocks(freq_mode
, &cpuclk_freq
, &dclk_freq
);
157 } else if (of_device_is_compatible(pdev
->dev
.of_node
,
158 "marvell,ap807-clock")) {
159 ret
= ap807_get_sar_clocks(freq_mode
, &cpuclk_freq
, &dclk_freq
);
161 dev_err(dev
, "compatible not supported\n");
166 dev_err(dev
, "invalid Sample at Reset value\n");
170 /* Convert to hertz */
171 cpuclk_freq
*= 1000 * 1000;
172 dclk_freq
*= 1000 * 1000;
174 /* CPU clocks depend on the Sample At Reset configuration */
175 name
= ap_cp_unique_name(dev
, syscon_node
, "pll-cluster-0");
176 ap806_clks
[0] = clk_register_fixed_rate(dev
, name
, NULL
,
178 if (IS_ERR(ap806_clks
[0])) {
179 ret
= PTR_ERR(ap806_clks
[0]);
183 name
= ap_cp_unique_name(dev
, syscon_node
, "pll-cluster-1");
184 ap806_clks
[1] = clk_register_fixed_rate(dev
, name
, NULL
, 0,
186 if (IS_ERR(ap806_clks
[1])) {
187 ret
= PTR_ERR(ap806_clks
[1]);
191 /* Fixed clock is always 1200 Mhz */
192 fixedclk_name
= ap_cp_unique_name(dev
, syscon_node
, "fixed");
193 ap806_clks
[2] = clk_register_fixed_rate(dev
, fixedclk_name
, NULL
,
194 0, 1200 * 1000 * 1000);
195 if (IS_ERR(ap806_clks
[2])) {
196 ret
= PTR_ERR(ap806_clks
[2]);
200 /* MSS Clock is fixed clock divided by 6 */
201 name
= ap_cp_unique_name(dev
, syscon_node
, "mss");
202 ap806_clks
[3] = clk_register_fixed_factor(NULL
, name
, fixedclk_name
,
204 if (IS_ERR(ap806_clks
[3])) {
205 ret
= PTR_ERR(ap806_clks
[3]);
209 /* SDIO(/eMMC) Clock is fixed clock divided by 3 */
210 name
= ap_cp_unique_name(dev
, syscon_node
, "sdio");
211 ap806_clks
[4] = clk_register_fixed_factor(NULL
, name
,
214 if (IS_ERR(ap806_clks
[4])) {
215 ret
= PTR_ERR(ap806_clks
[4]);
219 /* AP-DCLK(HCLK) Clock is DDR clock divided by 2 */
220 name
= ap_cp_unique_name(dev
, syscon_node
, "ap-dclk");
221 ap806_clks
[5] = clk_register_fixed_rate(dev
, name
, NULL
, 0, dclk_freq
);
222 if (IS_ERR(ap806_clks
[5])) {
223 ret
= PTR_ERR(ap806_clks
[5]);
227 ret
= of_clk_add_provider(np
, of_clk_src_onecell_get
, &ap806_clk_data
);
234 clk_unregister_fixed_factor(ap806_clks
[5]);
236 clk_unregister_fixed_factor(ap806_clks
[4]);
238 clk_unregister_fixed_factor(ap806_clks
[3]);
240 clk_unregister_fixed_rate(ap806_clks
[2]);
242 clk_unregister_fixed_rate(ap806_clks
[1]);
244 clk_unregister_fixed_rate(ap806_clks
[0]);
249 static int ap806_syscon_legacy_probe(struct platform_device
*pdev
)
251 dev_warn(&pdev
->dev
, FW_WARN
"Using legacy device tree binding\n");
252 dev_warn(&pdev
->dev
, FW_WARN
"Update your device tree:\n");
253 dev_warn(&pdev
->dev
, FW_WARN
254 "This binding won't be supported in future kernel\n");
256 return ap806_syscon_common_probe(pdev
, pdev
->dev
.of_node
);
260 static int ap806_clock_probe(struct platform_device
*pdev
)
262 return ap806_syscon_common_probe(pdev
, pdev
->dev
.of_node
->parent
);
265 static const struct of_device_id ap806_syscon_legacy_of_match
[] = {
266 { .compatible
= "marvell,ap806-system-controller", },
270 static struct platform_driver ap806_syscon_legacy_driver
= {
271 .probe
= ap806_syscon_legacy_probe
,
273 .name
= "marvell-ap806-system-controller",
274 .of_match_table
= ap806_syscon_legacy_of_match
,
275 .suppress_bind_attrs
= true,
278 builtin_platform_driver(ap806_syscon_legacy_driver
);
280 static const struct of_device_id ap806_clock_of_match
[] = {
281 { .compatible
= "marvell,ap806-clock", },
282 { .compatible
= "marvell,ap807-clock", },
286 static struct platform_driver ap806_clock_driver
= {
287 .probe
= ap806_clock_probe
,
289 .name
= "marvell-ap806-clock",
290 .of_match_table
= ap806_clock_of_match
,
291 .suppress_bind_attrs
= true,
294 builtin_platform_driver(ap806_clock_driver
);