2 * Marvell Armada AP806 System Controller
4 * Copyright (C) 2016 Marvell
6 * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
13 #define pr_fmt(fmt) "ap806-system-controller: " fmt
15 #include <linux/clk-provider.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/init.h>
19 #include <linux/of_address.h>
20 #include <linux/platform_device.h>
21 #include <linux/regmap.h>
23 #define AP806_SAR_REG 0x400
24 #define AP806_SAR_CLKFREQ_MODE_MASK 0x1f
26 #define AP806_CLK_NUM 5
28 static struct clk
*ap806_clks
[AP806_CLK_NUM
];
30 static struct clk_onecell_data ap806_clk_data
= {
32 .clk_num
= AP806_CLK_NUM
,
35 static char *ap806_unique_name(struct device
*dev
, struct device_node
*np
,
41 reg
= of_get_property(np
, "reg", NULL
);
42 addr
= of_translate_address(np
, reg
);
43 return devm_kasprintf(dev
, GFP_KERNEL
, "%llx-%s",
44 (unsigned long long)addr
, name
);
47 static int ap806_syscon_common_probe(struct platform_device
*pdev
,
48 struct device_node
*syscon_node
)
50 unsigned int freq_mode
, cpuclk_freq
;
51 const char *name
, *fixedclk_name
;
52 struct device
*dev
= &pdev
->dev
;
53 struct device_node
*np
= dev
->of_node
;
54 struct regmap
*regmap
;
58 regmap
= syscon_node_to_regmap(syscon_node
);
60 dev_err(dev
, "cannot get regmap\n");
61 return PTR_ERR(regmap
);
64 ret
= regmap_read(regmap
, AP806_SAR_REG
, ®
);
66 dev_err(dev
, "cannot read from regmap\n");
70 freq_mode
= reg
& AP806_SAR_CLKFREQ_MODE_MASK
;
106 dev_err(dev
, "invalid SAR value\n");
110 /* Convert to hertz */
111 cpuclk_freq
*= 1000 * 1000;
113 /* CPU clocks depend on the Sample At Reset configuration */
114 name
= ap806_unique_name(dev
, syscon_node
, "cpu-cluster-0");
115 ap806_clks
[0] = clk_register_fixed_rate(dev
, name
, NULL
,
117 if (IS_ERR(ap806_clks
[0])) {
118 ret
= PTR_ERR(ap806_clks
[0]);
122 name
= ap806_unique_name(dev
, syscon_node
, "cpu-cluster-1");
123 ap806_clks
[1] = clk_register_fixed_rate(dev
, name
, NULL
, 0,
125 if (IS_ERR(ap806_clks
[1])) {
126 ret
= PTR_ERR(ap806_clks
[1]);
130 /* Fixed clock is always 1200 Mhz */
131 fixedclk_name
= ap806_unique_name(dev
, syscon_node
, "fixed");
132 ap806_clks
[2] = clk_register_fixed_rate(dev
, fixedclk_name
, NULL
,
133 0, 1200 * 1000 * 1000);
134 if (IS_ERR(ap806_clks
[2])) {
135 ret
= PTR_ERR(ap806_clks
[2]);
139 /* MSS Clock is fixed clock divided by 6 */
140 name
= ap806_unique_name(dev
, syscon_node
, "mss");
141 ap806_clks
[3] = clk_register_fixed_factor(NULL
, name
, fixedclk_name
,
143 if (IS_ERR(ap806_clks
[3])) {
144 ret
= PTR_ERR(ap806_clks
[3]);
148 /* SDIO(/eMMC) Clock is fixed clock divided by 3 */
149 name
= ap806_unique_name(dev
, syscon_node
, "sdio");
150 ap806_clks
[4] = clk_register_fixed_factor(NULL
, name
,
153 if (IS_ERR(ap806_clks
[4])) {
154 ret
= PTR_ERR(ap806_clks
[4]);
158 of_clk_add_provider(np
, of_clk_src_onecell_get
, &ap806_clk_data
);
159 ret
= of_clk_add_provider(np
, of_clk_src_onecell_get
, &ap806_clk_data
);
166 clk_unregister_fixed_factor(ap806_clks
[4]);
168 clk_unregister_fixed_factor(ap806_clks
[3]);
170 clk_unregister_fixed_rate(ap806_clks
[2]);
172 clk_unregister_fixed_rate(ap806_clks
[1]);
174 clk_unregister_fixed_rate(ap806_clks
[0]);
179 static int ap806_syscon_legacy_probe(struct platform_device
*pdev
)
181 dev_warn(&pdev
->dev
, FW_WARN
"Using legacy device tree binding\n");
182 dev_warn(&pdev
->dev
, FW_WARN
"Update your device tree:\n");
183 dev_warn(&pdev
->dev
, FW_WARN
184 "This binding won't be supported in future kernel\n");
186 return ap806_syscon_common_probe(pdev
, pdev
->dev
.of_node
);
190 static int ap806_clock_probe(struct platform_device
*pdev
)
192 return ap806_syscon_common_probe(pdev
, pdev
->dev
.of_node
->parent
);
195 static const struct of_device_id ap806_syscon_legacy_of_match
[] = {
196 { .compatible
= "marvell,ap806-system-controller", },
200 static struct platform_driver ap806_syscon_legacy_driver
= {
201 .probe
= ap806_syscon_legacy_probe
,
203 .name
= "marvell-ap806-system-controller",
204 .of_match_table
= ap806_syscon_legacy_of_match
,
205 .suppress_bind_attrs
= true,
208 builtin_platform_driver(ap806_syscon_legacy_driver
);
210 static const struct of_device_id ap806_clock_of_match
[] = {
211 { .compatible
= "marvell,ap806-clock", },
215 static struct platform_driver ap806_clock_driver
= {
216 .probe
= ap806_clock_probe
,
218 .name
= "marvell-ap806-clock",
219 .of_match_table
= ap806_clock_of_match
,
220 .suppress_bind_attrs
= true,
223 builtin_platform_driver(ap806_clock_driver
);