staging: rtl8188eu: rename HalSetBrateCfg() - style
[linux/fpc-iii.git] / drivers / clk / mvebu / orion.c
bloba6e5bee233855fcdc230480027ab071bec2f1275
1 /*
2 * Marvell Orion SoC clocks
4 * Copyright (C) 2014 Thomas Petazzoni
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 #include <linux/kernel.h>
14 #include <linux/clk-provider.h>
15 #include <linux/io.h>
16 #include <linux/of.h>
17 #include "common.h"
19 static const struct coreclk_ratio orion_coreclk_ratios[] __initconst = {
20 { .id = 0, .name = "ddrclk", }
24 * Orion 5181
27 #define SAR_MV88F5181_TCLK_FREQ 8
28 #define SAR_MV88F5181_TCLK_FREQ_MASK 0x3
30 static u32 __init mv88f5181_get_tclk_freq(void __iomem *sar)
32 u32 opt = (readl(sar) >> SAR_MV88F5181_TCLK_FREQ) &
33 SAR_MV88F5181_TCLK_FREQ_MASK;
34 if (opt == 0)
35 return 133333333;
36 else if (opt == 1)
37 return 150000000;
38 else if (opt == 2)
39 return 166666667;
40 else
41 return 0;
44 #define SAR_MV88F5181_CPU_FREQ 4
45 #define SAR_MV88F5181_CPU_FREQ_MASK 0xf
47 static u32 __init mv88f5181_get_cpu_freq(void __iomem *sar)
49 u32 opt = (readl(sar) >> SAR_MV88F5181_CPU_FREQ) &
50 SAR_MV88F5181_CPU_FREQ_MASK;
51 if (opt == 0)
52 return 333333333;
53 else if (opt == 1 || opt == 2)
54 return 400000000;
55 else if (opt == 3)
56 return 500000000;
57 else
58 return 0;
61 static void __init mv88f5181_get_clk_ratio(void __iomem *sar, int id,
62 int *mult, int *div)
64 u32 opt = (readl(sar) >> SAR_MV88F5181_CPU_FREQ) &
65 SAR_MV88F5181_CPU_FREQ_MASK;
66 if (opt == 0 || opt == 1) {
67 *mult = 1;
68 *div = 2;
69 } else if (opt == 2 || opt == 3) {
70 *mult = 1;
71 *div = 3;
72 } else {
73 *mult = 0;
74 *div = 1;
78 static const struct coreclk_soc_desc mv88f5181_coreclks = {
79 .get_tclk_freq = mv88f5181_get_tclk_freq,
80 .get_cpu_freq = mv88f5181_get_cpu_freq,
81 .get_clk_ratio = mv88f5181_get_clk_ratio,
82 .ratios = orion_coreclk_ratios,
83 .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
86 static void __init mv88f5181_clk_init(struct device_node *np)
88 return mvebu_coreclk_setup(np, &mv88f5181_coreclks);
91 CLK_OF_DECLARE(mv88f5181_clk, "marvell,mv88f5181-core-clock", mv88f5181_clk_init);
94 * Orion 5182
97 #define SAR_MV88F5182_TCLK_FREQ 8
98 #define SAR_MV88F5182_TCLK_FREQ_MASK 0x3
100 static u32 __init mv88f5182_get_tclk_freq(void __iomem *sar)
102 u32 opt = (readl(sar) >> SAR_MV88F5182_TCLK_FREQ) &
103 SAR_MV88F5182_TCLK_FREQ_MASK;
104 if (opt == 1)
105 return 150000000;
106 else if (opt == 2)
107 return 166666667;
108 else
109 return 0;
112 #define SAR_MV88F5182_CPU_FREQ 4
113 #define SAR_MV88F5182_CPU_FREQ_MASK 0xf
115 static u32 __init mv88f5182_get_cpu_freq(void __iomem *sar)
117 u32 opt = (readl(sar) >> SAR_MV88F5182_CPU_FREQ) &
118 SAR_MV88F5182_CPU_FREQ_MASK;
119 if (opt == 0)
120 return 333333333;
121 else if (opt == 1 || opt == 2)
122 return 400000000;
123 else if (opt == 3)
124 return 500000000;
125 else
126 return 0;
129 static void __init mv88f5182_get_clk_ratio(void __iomem *sar, int id,
130 int *mult, int *div)
132 u32 opt = (readl(sar) >> SAR_MV88F5182_CPU_FREQ) &
133 SAR_MV88F5182_CPU_FREQ_MASK;
134 if (opt == 0 || opt == 1) {
135 *mult = 1;
136 *div = 2;
137 } else if (opt == 2 || opt == 3) {
138 *mult = 1;
139 *div = 3;
140 } else {
141 *mult = 0;
142 *div = 1;
146 static const struct coreclk_soc_desc mv88f5182_coreclks = {
147 .get_tclk_freq = mv88f5182_get_tclk_freq,
148 .get_cpu_freq = mv88f5182_get_cpu_freq,
149 .get_clk_ratio = mv88f5182_get_clk_ratio,
150 .ratios = orion_coreclk_ratios,
151 .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
154 static void __init mv88f5182_clk_init(struct device_node *np)
156 return mvebu_coreclk_setup(np, &mv88f5182_coreclks);
159 CLK_OF_DECLARE(mv88f5182_clk, "marvell,mv88f5182-core-clock", mv88f5182_clk_init);
162 * Orion 5281
165 static u32 __init mv88f5281_get_tclk_freq(void __iomem *sar)
167 /* On 5281, tclk is always 166 Mhz */
168 return 166666667;
171 #define SAR_MV88F5281_CPU_FREQ 4
172 #define SAR_MV88F5281_CPU_FREQ_MASK 0xf
174 static u32 __init mv88f5281_get_cpu_freq(void __iomem *sar)
176 u32 opt = (readl(sar) >> SAR_MV88F5281_CPU_FREQ) &
177 SAR_MV88F5281_CPU_FREQ_MASK;
178 if (opt == 1 || opt == 2)
179 return 400000000;
180 else if (opt == 3)
181 return 500000000;
182 else
183 return 0;
186 static void __init mv88f5281_get_clk_ratio(void __iomem *sar, int id,
187 int *mult, int *div)
189 u32 opt = (readl(sar) >> SAR_MV88F5281_CPU_FREQ) &
190 SAR_MV88F5281_CPU_FREQ_MASK;
191 if (opt == 1) {
192 *mult = 1;
193 *div = 2;
194 } else if (opt == 2 || opt == 3) {
195 *mult = 1;
196 *div = 3;
197 } else {
198 *mult = 0;
199 *div = 1;
203 static const struct coreclk_soc_desc mv88f5281_coreclks = {
204 .get_tclk_freq = mv88f5281_get_tclk_freq,
205 .get_cpu_freq = mv88f5281_get_cpu_freq,
206 .get_clk_ratio = mv88f5281_get_clk_ratio,
207 .ratios = orion_coreclk_ratios,
208 .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
211 static void __init mv88f5281_clk_init(struct device_node *np)
213 return mvebu_coreclk_setup(np, &mv88f5281_coreclks);
216 CLK_OF_DECLARE(mv88f5281_clk, "marvell,mv88f5281-core-clock", mv88f5281_clk_init);
219 * Orion 6183
222 #define SAR_MV88F6183_TCLK_FREQ 9
223 #define SAR_MV88F6183_TCLK_FREQ_MASK 0x1
225 static u32 __init mv88f6183_get_tclk_freq(void __iomem *sar)
227 u32 opt = (readl(sar) >> SAR_MV88F6183_TCLK_FREQ) &
228 SAR_MV88F6183_TCLK_FREQ_MASK;
229 if (opt == 0)
230 return 133333333;
231 else if (opt == 1)
232 return 166666667;
233 else
234 return 0;
237 #define SAR_MV88F6183_CPU_FREQ 1
238 #define SAR_MV88F6183_CPU_FREQ_MASK 0x3f
240 static u32 __init mv88f6183_get_cpu_freq(void __iomem *sar)
242 u32 opt = (readl(sar) >> SAR_MV88F6183_CPU_FREQ) &
243 SAR_MV88F6183_CPU_FREQ_MASK;
244 if (opt == 9)
245 return 333333333;
246 else if (opt == 17)
247 return 400000000;
248 else
249 return 0;
252 static void __init mv88f6183_get_clk_ratio(void __iomem *sar, int id,
253 int *mult, int *div)
255 u32 opt = (readl(sar) >> SAR_MV88F6183_CPU_FREQ) &
256 SAR_MV88F6183_CPU_FREQ_MASK;
257 if (opt == 9 || opt == 17) {
258 *mult = 1;
259 *div = 2;
260 } else {
261 *mult = 0;
262 *div = 1;
266 static const struct coreclk_soc_desc mv88f6183_coreclks = {
267 .get_tclk_freq = mv88f6183_get_tclk_freq,
268 .get_cpu_freq = mv88f6183_get_cpu_freq,
269 .get_clk_ratio = mv88f6183_get_clk_ratio,
270 .ratios = orion_coreclk_ratios,
271 .num_ratios = ARRAY_SIZE(orion_coreclk_ratios),
275 static void __init mv88f6183_clk_init(struct device_node *np)
277 return mvebu_coreclk_setup(np, &mv88f6183_coreclks);
280 CLK_OF_DECLARE(mv88f6183_clk, "marvell,mv88f6183-core-clock", mv88f6183_clk_init);