2 * Marvell Armada 370 SoC clocks
4 * Copyright (C) 2012 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>
25 #define SARL 0 /* Low part [0:31] */
26 #define SARL_A370_PCLK_FREQ_OPT 11
27 #define SARL_A370_PCLK_FREQ_OPT_MASK 0xF
28 #define SARL_A370_FAB_FREQ_OPT 15
29 #define SARL_A370_FAB_FREQ_OPT_MASK 0x1F
30 #define SARL_A370_TCLK_FREQ_OPT 20
31 #define SARL_A370_TCLK_FREQ_OPT_MASK 0x1
33 enum { A370_CPU_TO_NBCLK
, A370_CPU_TO_HCLK
, A370_CPU_TO_DRAMCLK
};
35 static const struct coreclk_ratio a370_coreclk_ratios
[] __initconst
= {
36 { .id
= A370_CPU_TO_NBCLK
, .name
= "nbclk" },
37 { .id
= A370_CPU_TO_HCLK
, .name
= "hclk" },
38 { .id
= A370_CPU_TO_DRAMCLK
, .name
= "dramclk" },
41 static const u32 a370_tclk_freqs
[] __initconst
= {
46 static u32 __init
a370_get_tclk_freq(void __iomem
*sar
)
48 u8 tclk_freq_select
= 0;
50 tclk_freq_select
= ((readl(sar
) >> SARL_A370_TCLK_FREQ_OPT
) &
51 SARL_A370_TCLK_FREQ_OPT_MASK
);
52 return a370_tclk_freqs
[tclk_freq_select
];
55 static const u32 a370_cpu_freqs
[] __initconst
= {
65 static u32 __init
a370_get_cpu_freq(void __iomem
*sar
)
68 u8 cpu_freq_select
= 0;
70 cpu_freq_select
= ((readl(sar
) >> SARL_A370_PCLK_FREQ_OPT
) &
71 SARL_A370_PCLK_FREQ_OPT_MASK
);
72 if (cpu_freq_select
>= ARRAY_SIZE(a370_cpu_freqs
)) {
73 pr_err("CPU freq select unsupported %d\n", cpu_freq_select
);
76 cpu_freq
= a370_cpu_freqs
[cpu_freq_select
];
81 static const int a370_nbclk_ratios
[32][2] __initconst
= {
82 {0, 1}, {1, 2}, {2, 2}, {2, 2},
83 {1, 2}, {1, 2}, {1, 1}, {2, 3},
84 {0, 1}, {1, 2}, {2, 4}, {0, 1},
85 {1, 2}, {0, 1}, {0, 1}, {2, 2},
86 {0, 1}, {0, 1}, {0, 1}, {1, 1},
87 {2, 3}, {0, 1}, {0, 1}, {0, 1},
88 {0, 1}, {0, 1}, {0, 1}, {1, 1},
89 {0, 1}, {0, 1}, {0, 1}, {0, 1},
92 static const int a370_hclk_ratios
[32][2] __initconst
= {
93 {0, 1}, {1, 2}, {2, 6}, {2, 3},
94 {1, 3}, {1, 4}, {1, 2}, {2, 6},
95 {0, 1}, {1, 6}, {2, 10}, {0, 1},
96 {1, 4}, {0, 1}, {0, 1}, {2, 5},
97 {0, 1}, {0, 1}, {0, 1}, {1, 2},
98 {2, 6}, {0, 1}, {0, 1}, {0, 1},
99 {0, 1}, {0, 1}, {0, 1}, {1, 1},
100 {0, 1}, {0, 1}, {0, 1}, {0, 1},
103 static const int a370_dramclk_ratios
[32][2] __initconst
= {
104 {0, 1}, {1, 2}, {2, 3}, {2, 3},
105 {1, 3}, {1, 2}, {1, 2}, {2, 6},
106 {0, 1}, {1, 3}, {2, 5}, {0, 1},
107 {1, 4}, {0, 1}, {0, 1}, {2, 5},
108 {0, 1}, {0, 1}, {0, 1}, {1, 1},
109 {2, 3}, {0, 1}, {0, 1}, {0, 1},
110 {0, 1}, {0, 1}, {0, 1}, {1, 1},
111 {0, 1}, {0, 1}, {0, 1}, {0, 1},
114 static void __init
a370_get_clk_ratio(
115 void __iomem
*sar
, int id
, int *mult
, int *div
)
117 u32 opt
= ((readl(sar
) >> SARL_A370_FAB_FREQ_OPT
) &
118 SARL_A370_FAB_FREQ_OPT_MASK
);
121 case A370_CPU_TO_NBCLK
:
122 *mult
= a370_nbclk_ratios
[opt
][0];
123 *div
= a370_nbclk_ratios
[opt
][1];
125 case A370_CPU_TO_HCLK
:
126 *mult
= a370_hclk_ratios
[opt
][0];
127 *div
= a370_hclk_ratios
[opt
][1];
129 case A370_CPU_TO_DRAMCLK
:
130 *mult
= a370_dramclk_ratios
[opt
][0];
131 *div
= a370_dramclk_ratios
[opt
][1];
136 static const struct coreclk_soc_desc a370_coreclks
= {
137 .get_tclk_freq
= a370_get_tclk_freq
,
138 .get_cpu_freq
= a370_get_cpu_freq
,
139 .get_clk_ratio
= a370_get_clk_ratio
,
140 .ratios
= a370_coreclk_ratios
,
141 .num_ratios
= ARRAY_SIZE(a370_coreclk_ratios
),
144 static void __init
a370_coreclk_init(struct device_node
*np
)
146 mvebu_coreclk_setup(np
, &a370_coreclks
);
148 CLK_OF_DECLARE(a370_core_clk
, "marvell,armada-370-core-clock",
152 * Clock Gating Control
155 static const struct clk_gating_soc_desc a370_gating_desc
[] __initconst
= {
156 { "audio", NULL
, 0, 0 },
157 { "pex0_en", NULL
, 1, 0 },
158 { "pex1_en", NULL
, 2, 0 },
159 { "ge1", NULL
, 3, 0 },
160 { "ge0", NULL
, 4, 0 },
161 { "pex0", "pex0_en", 5, 0 },
162 { "pex1", "pex1_en", 9, 0 },
163 { "sata0", NULL
, 15, 0 },
164 { "sdio", NULL
, 17, 0 },
165 { "tdm", NULL
, 25, 0 },
166 { "ddr", NULL
, 28, CLK_IGNORE_UNUSED
},
167 { "sata1", NULL
, 30, 0 },
171 static void __init
a370_clk_gating_init(struct device_node
*np
)
173 mvebu_clk_gating_setup(np
, a370_gating_desc
);
175 CLK_OF_DECLARE(a370_clk_gating
, "marvell,armada-370-gating-clock",
176 a370_clk_gating_init
);