2 * Marvell Armada 380/385 SoC clocks
4 * Copyright (C) 2014 Marvell
6 * Gregory CLEMENT <gregory.clement@free-electrons.com>
7 * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
8 * Andrew Lunn <andrew@lunn.ch>
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
15 #include <linux/kernel.h>
16 #include <linux/clk-provider.h>
22 * SAR[14:10] : Ratios between PCLK0, NBCLK, HCLK and DRAM clocks
24 * SAR[15] : TCLK frequency
29 #define SAR_A380_TCLK_FREQ_OPT 15
30 #define SAR_A380_TCLK_FREQ_OPT_MASK 0x1
31 #define SAR_A380_CPU_DDR_L2_FREQ_OPT 10
32 #define SAR_A380_CPU_DDR_L2_FREQ_OPT_MASK 0x1F
34 static const u32 armada_38x_tclk_frequencies
[] __initconst
= {
39 static u32 __init
armada_38x_get_tclk_freq(void __iomem
*sar
)
43 tclk_freq_select
= ((readl(sar
) >> SAR_A380_TCLK_FREQ_OPT
) &
44 SAR_A380_TCLK_FREQ_OPT_MASK
);
45 return armada_38x_tclk_frequencies
[tclk_freq_select
];
48 static const u32 armada_38x_cpu_frequencies
[] __initconst
= {
50 1066 * 1000 * 1000, 0, 0, 0,
51 1332 * 1000 * 1000, 0, 0, 0,
55 static u32 __init
armada_38x_get_cpu_freq(void __iomem
*sar
)
59 cpu_freq_select
= ((readl(sar
) >> SAR_A380_CPU_DDR_L2_FREQ_OPT
) &
60 SAR_A380_CPU_DDR_L2_FREQ_OPT_MASK
);
61 if (cpu_freq_select
>= ARRAY_SIZE(armada_38x_cpu_frequencies
)) {
62 pr_err("Selected CPU frequency (%d) unsupported\n",
67 return armada_38x_cpu_frequencies
[cpu_freq_select
];
70 enum { A380_CPU_TO_DDR
, A380_CPU_TO_L2
};
72 static const struct coreclk_ratio armada_38x_coreclk_ratios
[] __initconst
= {
73 { .id
= A380_CPU_TO_L2
, .name
= "l2clk" },
74 { .id
= A380_CPU_TO_DDR
, .name
= "ddrclk" },
77 static const int armada_38x_cpu_l2_ratios
[32][2] __initconst
= {
78 {0, 1}, {0, 1}, {0, 1}, {0, 1},
79 {1, 2}, {0, 1}, {0, 1}, {0, 1},
80 {1, 2}, {0, 1}, {0, 1}, {0, 1},
81 {1, 2}, {0, 1}, {0, 1}, {0, 1},
82 {0, 1}, {0, 1}, {0, 1}, {0, 1},
83 {0, 1}, {0, 1}, {0, 1}, {0, 1},
84 {0, 1}, {0, 1}, {0, 1}, {0, 1},
85 {0, 1}, {0, 1}, {0, 1}, {0, 1},
88 static const int armada_38x_cpu_ddr_ratios
[32][2] __initconst
= {
89 {0, 1}, {0, 1}, {0, 1}, {0, 1},
90 {1, 2}, {0, 1}, {0, 1}, {0, 1},
91 {1, 2}, {0, 1}, {0, 1}, {0, 1},
92 {1, 2}, {0, 1}, {0, 1}, {0, 1},
93 {0, 1}, {0, 1}, {0, 1}, {0, 1},
94 {0, 1}, {0, 1}, {0, 1}, {0, 1},
95 {0, 1}, {0, 1}, {0, 1}, {0, 1},
96 {0, 1}, {0, 1}, {0, 1}, {0, 1},
99 static void __init
armada_38x_get_clk_ratio(
100 void __iomem
*sar
, int id
, int *mult
, int *div
)
102 u32 opt
= ((readl(sar
) >> SAR_A380_CPU_DDR_L2_FREQ_OPT
) &
103 SAR_A380_CPU_DDR_L2_FREQ_OPT_MASK
);
107 *mult
= armada_38x_cpu_l2_ratios
[opt
][0];
108 *div
= armada_38x_cpu_l2_ratios
[opt
][1];
110 case A380_CPU_TO_DDR
:
111 *mult
= armada_38x_cpu_ddr_ratios
[opt
][0];
112 *div
= armada_38x_cpu_ddr_ratios
[opt
][1];
117 static const struct coreclk_soc_desc armada_38x_coreclks
= {
118 .get_tclk_freq
= armada_38x_get_tclk_freq
,
119 .get_cpu_freq
= armada_38x_get_cpu_freq
,
120 .get_clk_ratio
= armada_38x_get_clk_ratio
,
121 .ratios
= armada_38x_coreclk_ratios
,
122 .num_ratios
= ARRAY_SIZE(armada_38x_coreclk_ratios
),
125 static void __init
armada_38x_coreclk_init(struct device_node
*np
)
127 mvebu_coreclk_setup(np
, &armada_38x_coreclks
);
129 CLK_OF_DECLARE(armada_38x_core_clk
, "marvell,armada-380-core-clock",
130 armada_38x_coreclk_init
);
133 * Clock Gating Control
135 static const struct clk_gating_soc_desc armada_38x_gating_desc
[] __initconst
= {
136 { "audio", NULL
, 0 },
144 { "usb3h0", NULL
, 9 },
145 { "usb3h1", NULL
, 10 },
146 { "usb3d", NULL
, 11 },
148 { "crypto0z", NULL
, 14 },
149 { "sata0", NULL
, 15 },
150 { "crypto1z", NULL
, 16 },
151 { "sdio", NULL
, 17 },
152 { "usb2", NULL
, 18 },
153 { "crypto1", NULL
, 21 },
154 { "xor0", NULL
, 22 },
155 { "crypto0", NULL
, 23 },
157 { "xor1", NULL
, 28 },
158 { "sata1", NULL
, 30 },
162 static void __init
armada_38x_clk_gating_init(struct device_node
*np
)
164 mvebu_clk_gating_setup(np
, armada_38x_gating_desc
);
166 CLK_OF_DECLARE(armada_38x_clk_gating
, "marvell,armada-380-gating-clock",
167 armada_38x_clk_gating_init
);