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 ap806_syscon_common_probe(struct platform_device *pdev,
106 struct device_node *syscon_node)
108 unsigned int freq_mode, cpuclk_freq, dclk_freq;
109 const char *name, *fixedclk_name;
110 struct device *dev = &pdev->dev;
111 struct device_node *np = dev->of_node;
112 struct regmap *regmap;
116 regmap = syscon_node_to_regmap(syscon_node);
117 if (IS_ERR(regmap)) {
118 dev_err(dev, "cannot get regmap\n");
119 return PTR_ERR(regmap);
122 ret = regmap_read(regmap, AP806_SAR_REG, ®);
124 dev_err(dev, "cannot read from regmap\n");
128 freq_mode = reg & AP806_SAR_CLKFREQ_MODE_MASK;
130 if (of_device_is_compatible(pdev->dev.of_node,
131 "marvell,ap806-clock")) {
132 ret = ap806_get_sar_clocks(freq_mode, &cpuclk_freq, &dclk_freq);
134 dev_err(dev, "compatible not supported\n");
139 dev_err(dev, "invalid Sample at Reset value\n");
143 /* Convert to hertz */
144 cpuclk_freq *= 1000 * 1000;
145 dclk_freq *= 1000 * 1000;
147 /* CPU clocks depend on the Sample At Reset configuration */
148 name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-0");
149 ap806_clks[0] = clk_register_fixed_rate(dev, name, NULL,
151 if (IS_ERR(ap806_clks[0])) {
152 ret = PTR_ERR(ap806_clks[0]);
156 name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-1");
157 ap806_clks[1] = clk_register_fixed_rate(dev, name, NULL, 0,
159 if (IS_ERR(ap806_clks[1])) {
160 ret = PTR_ERR(ap806_clks[1]);
164 /* Fixed clock is always 1200 Mhz */
165 fixedclk_name = ap_cp_unique_name(dev, syscon_node, "fixed");
166 ap806_clks[2] = clk_register_fixed_rate(dev, fixedclk_name, NULL,
167 0, 1200 * 1000 * 1000);
168 if (IS_ERR(ap806_clks[2])) {
169 ret = PTR_ERR(ap806_clks[2]);
173 /* MSS Clock is fixed clock divided by 6 */
174 name = ap_cp_unique_name(dev, syscon_node, "mss");
175 ap806_clks[3] = clk_register_fixed_factor(NULL, name, fixedclk_name,
177 if (IS_ERR(ap806_clks[3])) {
178 ret = PTR_ERR(ap806_clks[3]);
182 /* SDIO(/eMMC) Clock is fixed clock divided by 3 */
183 name = ap_cp_unique_name(dev, syscon_node, "sdio");
184 ap806_clks[4] = clk_register_fixed_factor(NULL, name,
187 if (IS_ERR(ap806_clks[4])) {
188 ret = PTR_ERR(ap806_clks[4]);
192 /* AP-DCLK(HCLK) Clock is DDR clock divided by 2 */
193 name = ap_cp_unique_name(dev, syscon_node, "ap-dclk");
194 ap806_clks[5] = clk_register_fixed_rate(dev, name, NULL, 0, dclk_freq);
195 if (IS_ERR(ap806_clks[5])) {
196 ret = PTR_ERR(ap806_clks[5]);
200 ret = of_clk_add_provider(np, of_clk_src_onecell_get, &ap806_clk_data);
207 clk_unregister_fixed_factor(ap806_clks[5]);
209 clk_unregister_fixed_factor(ap806_clks[4]);
211 clk_unregister_fixed_factor(ap806_clks[3]);
213 clk_unregister_fixed_rate(ap806_clks[2]);
215 clk_unregister_fixed_rate(ap806_clks[1]);
217 clk_unregister_fixed_rate(ap806_clks[0]);
222 static int ap806_syscon_legacy_probe(struct platform_device *pdev)
224 dev_warn(&pdev->dev, FW_WARN "Using legacy device tree binding\n");
225 dev_warn(&pdev->dev, FW_WARN "Update your device tree:\n");
226 dev_warn(&pdev->dev, FW_WARN
227 "This binding won't be supported in future kernel\n");
229 return ap806_syscon_common_probe(pdev, pdev->dev.of_node);
233 static int ap806_clock_probe(struct platform_device *pdev)
235 return ap806_syscon_common_probe(pdev, pdev->dev.of_node->parent);
238 static const struct of_device_id ap806_syscon_legacy_of_match[] = {
239 { .compatible = "marvell,ap806-system-controller", },
243 static struct platform_driver ap806_syscon_legacy_driver = {
244 .probe = ap806_syscon_legacy_probe,
246 .name = "marvell-ap806-system-controller",
247 .of_match_table = ap806_syscon_legacy_of_match,
248 .suppress_bind_attrs = true,
251 builtin_platform_driver(ap806_syscon_legacy_driver);
253 static const struct of_device_id ap806_clock_of_match[] = {
254 { .compatible = "marvell,ap806-clock", },
258 static struct platform_driver ap806_clock_driver = {
259 .probe = ap806_clock_probe,
261 .name = "marvell-ap806-clock",
262 .of_match_table = ap806_clock_of_match,
263 .suppress_bind_attrs = true,
266 builtin_platform_driver(ap806_clock_driver);