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 4
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 int ap806_syscon_clk_probe(struct platform_device
*pdev
)
37 unsigned int freq_mode
, cpuclk_freq
;
38 const char *name
, *fixedclk_name
;
39 struct device_node
*np
= pdev
->dev
.of_node
;
40 struct regmap
*regmap
;
44 regmap
= syscon_node_to_regmap(np
);
46 dev_err(&pdev
->dev
, "cannot get regmap\n");
47 return PTR_ERR(regmap
);
50 ret
= regmap_read(regmap
, AP806_SAR_REG
, ®
);
52 dev_err(&pdev
->dev
, "cannot read from regmap\n");
56 freq_mode
= reg
& AP806_SAR_CLKFREQ_MODE_MASK
;
74 dev_err(&pdev
->dev
, "invalid SAR value\n");
78 /* Convert to hertz */
79 cpuclk_freq
*= 1000 * 1000;
81 /* CPU clocks depend on the Sample At Reset configuration */
82 of_property_read_string_index(np
, "clock-output-names",
84 ap806_clks
[0] = clk_register_fixed_rate(&pdev
->dev
, name
, NULL
,
86 if (IS_ERR(ap806_clks
[0])) {
87 ret
= PTR_ERR(ap806_clks
[0]);
91 of_property_read_string_index(np
, "clock-output-names",
93 ap806_clks
[1] = clk_register_fixed_rate(&pdev
->dev
, name
, NULL
, 0,
95 if (IS_ERR(ap806_clks
[1])) {
96 ret
= PTR_ERR(ap806_clks
[1]);
100 /* Fixed clock is always 1200 Mhz */
101 of_property_read_string_index(np
, "clock-output-names",
103 ap806_clks
[2] = clk_register_fixed_rate(&pdev
->dev
, fixedclk_name
, NULL
,
104 0, 1200 * 1000 * 1000);
105 if (IS_ERR(ap806_clks
[2])) {
106 ret
= PTR_ERR(ap806_clks
[2]);
110 /* MSS Clock is fixed clock divided by 6 */
111 of_property_read_string_index(np
, "clock-output-names",
113 ap806_clks
[3] = clk_register_fixed_factor(NULL
, name
, fixedclk_name
,
115 if (IS_ERR(ap806_clks
[3])) {
116 ret
= PTR_ERR(ap806_clks
[3]);
120 ret
= of_clk_add_provider(np
, of_clk_src_onecell_get
, &ap806_clk_data
);
127 clk_unregister_fixed_factor(ap806_clks
[3]);
129 clk_unregister_fixed_rate(ap806_clks
[2]);
131 clk_unregister_fixed_rate(ap806_clks
[1]);
133 clk_unregister_fixed_rate(ap806_clks
[0]);
138 static const struct of_device_id ap806_syscon_of_match
[] = {
139 { .compatible
= "marvell,ap806-system-controller", },
143 static struct platform_driver ap806_syscon_driver
= {
144 .probe
= ap806_syscon_clk_probe
,
146 .name
= "marvell-ap806-system-controller",
147 .of_match_table
= ap806_syscon_of_match
,
148 .suppress_bind_attrs
= true,
151 builtin_platform_driver(ap806_syscon_driver
);