aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk/meson/meson8b-clkc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clk/meson/meson8b-clkc.c')
-rw-r--r--drivers/clk/meson/meson8b-clkc.c425
1 files changed, 338 insertions, 87 deletions
diff --git a/drivers/clk/meson/meson8b-clkc.c b/drivers/clk/meson/meson8b-clkc.c
index 4d057b3e21b2..4c9413cdf373 100644
--- a/drivers/clk/meson/meson8b-clkc.c
+++ b/drivers/clk/meson/meson8b-clkc.c
@@ -1,7 +1,12 @@
1/* 1/*
2 * AmLogic S805 / Meson8b Clock Controller Driver
3 *
2 * Copyright (c) 2015 Endless Mobile, Inc. 4 * Copyright (c) 2015 Endless Mobile, Inc.
3 * Author: Carlo Caione <carlo@endlessm.com> 5 * Author: Carlo Caione <carlo@endlessm.com>
4 * 6 *
7 * Copyright (c) 2016 BayLibre, Inc.
8 * Michael Turquette <mturquette@baylibre.com>
9 *
5 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License, 11 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation. 12 * version 2, as published by the Free Software Foundation.
@@ -15,23 +20,33 @@
15 * this program. If not, see <http://www.gnu.org/licenses/>. 20 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */ 21 */
17 22
23#include <linux/clk.h>
18#include <linux/clk-provider.h> 24#include <linux/clk-provider.h>
19#include <linux/kernel.h>
20#include <linux/of.h>
21#include <linux/of_address.h> 25#include <linux/of_address.h>
22#include <linux/slab.h>
23#include <dt-bindings/clock/meson8b-clkc.h> 26#include <dt-bindings/clock/meson8b-clkc.h>
27#include <linux/platform_device.h>
28#include <linux/init.h>
24 29
25#include "clkc.h" 30#include "clkc.h"
26 31
27#define MESON8B_REG_CTL0_ADDR 0x0000 32/*
28#define MESON8B_REG_SYS_CPU_CNTL1 0x015c 33 * Clock controller register offsets
29#define MESON8B_REG_HHI_MPEG 0x0174 34 *
30#define MESON8B_REG_MALI 0x01b0 35 * Register offsets from the HardKernel[0] data sheet are listed in comment
36 * blocks below. Those offsets must be multiplied by 4 before adding them to
37 * the base address to get the right value
38 *
39 * [0] http://dn.odroid.com/S805/Datasheet/S805_Datasheet%20V0.8%2020150126.pdf
40 */
41#define MESON8B_REG_SYS_CPU_CNTL1 0x015c /* 0x57 offset in data sheet */
42#define MESON8B_REG_HHI_MPEG 0x0174 /* 0x5d offset in data sheet */
43#define MESON8B_REG_MALI 0x01b0 /* 0x6c offset in data sheet */
31#define MESON8B_REG_PLL_FIXED 0x0280 44#define MESON8B_REG_PLL_FIXED 0x0280
32#define MESON8B_REG_PLL_SYS 0x0300 45#define MESON8B_REG_PLL_SYS 0x0300
33#define MESON8B_REG_PLL_VID 0x0320 46#define MESON8B_REG_PLL_VID 0x0320
34 47
48static DEFINE_SPINLOCK(clk_lock);
49
35static const struct pll_rate_table sys_pll_rate_table[] = { 50static const struct pll_rate_table sys_pll_rate_table[] = {
36 PLL_RATE(312000000, 52, 1, 2), 51 PLL_RATE(312000000, 52, 1, 2),
37 PLL_RATE(336000000, 56, 1, 2), 52 PLL_RATE(336000000, 56, 1, 2),
@@ -102,95 +117,331 @@ static const struct clk_div_table cpu_div_table[] = {
102 { /* sentinel */ }, 117 { /* sentinel */ },
103}; 118};
104 119
105PNAME(p_xtal) = { "xtal" }; 120static struct clk_fixed_rate meson8b_xtal = {
106PNAME(p_fclk_div) = { "fixed_pll" }; 121 .fixed_rate = 24000000,
107PNAME(p_cpu_clk) = { "sys_pll" }; 122 .hw.init = &(struct clk_init_data){
108PNAME(p_clk81) = { "fclk_div3", "fclk_div4", "fclk_div5" }; 123 .name = "xtal",
109PNAME(p_mali) = { "fclk_div3", "fclk_div4", "fclk_div5", 124 .num_parents = 0,
110 "fclk_div7", "zero" }; 125 .ops = &clk_fixed_rate_ops,
126 },
127};
128
129static struct meson_clk_pll meson8b_fixed_pll = {
130 .m = {
131 .reg_off = MESON8B_REG_PLL_FIXED,
132 .shift = 0,
133 .width = 9,
134 },
135 .n = {
136 .reg_off = MESON8B_REG_PLL_FIXED,
137 .shift = 9,
138 .width = 5,
139 },
140 .od = {
141 .reg_off = MESON8B_REG_PLL_FIXED,
142 .shift = 16,
143 .width = 2,
144 },
145 .lock = &clk_lock,
146 .hw.init = &(struct clk_init_data){
147 .name = "fixed_pll",
148 .ops = &meson_clk_pll_ro_ops,
149 .parent_names = (const char *[]){ "xtal" },
150 .num_parents = 1,
151 .flags = CLK_GET_RATE_NOCACHE,
152 },
153};
154
155static struct meson_clk_pll meson8b_vid_pll = {
156 .m = {
157 .reg_off = MESON8B_REG_PLL_VID,
158 .shift = 0,
159 .width = 9,
160 },
161 .n = {
162 .reg_off = MESON8B_REG_PLL_VID,
163 .shift = 9,
164 .width = 5,
165 },
166 .od = {
167 .reg_off = MESON8B_REG_PLL_VID,
168 .shift = 16,
169 .width = 2,
170 },
171 .lock = &clk_lock,
172 .hw.init = &(struct clk_init_data){
173 .name = "vid_pll",
174 .ops = &meson_clk_pll_ro_ops,
175 .parent_names = (const char *[]){ "xtal" },
176 .num_parents = 1,
177 .flags = CLK_GET_RATE_NOCACHE,
178 },
179};
180
181static struct meson_clk_pll meson8b_sys_pll = {
182 .m = {
183 .reg_off = MESON8B_REG_PLL_SYS,
184 .shift = 0,
185 .width = 9,
186 },
187 .n = {
188 .reg_off = MESON8B_REG_PLL_SYS,
189 .shift = 9,
190 .width = 5,
191 },
192 .od = {
193 .reg_off = MESON8B_REG_PLL_SYS,
194 .shift = 16,
195 .width = 2,
196 },
197 .rate_table = sys_pll_rate_table,
198 .rate_count = ARRAY_SIZE(sys_pll_rate_table),
199 .lock = &clk_lock,
200 .hw.init = &(struct clk_init_data){
201 .name = "sys_pll",
202 .ops = &meson_clk_pll_ops,
203 .parent_names = (const char *[]){ "xtal" },
204 .num_parents = 1,
205 .flags = CLK_GET_RATE_NOCACHE,
206 },
207};
208
209static struct clk_fixed_factor meson8b_fclk_div2 = {
210 .mult = 1,
211 .div = 2,
212 .hw.init = &(struct clk_init_data){
213 .name = "fclk_div2",
214 .ops = &clk_fixed_factor_ops,
215 .parent_names = (const char *[]){ "fixed_pll" },
216 .num_parents = 1,
217 },
218};
219
220static struct clk_fixed_factor meson8b_fclk_div3 = {
221 .mult = 1,
222 .div = 3,
223 .hw.init = &(struct clk_init_data){
224 .name = "fclk_div3",
225 .ops = &clk_fixed_factor_ops,
226 .parent_names = (const char *[]){ "fixed_pll" },
227 .num_parents = 1,
228 },
229};
230
231static struct clk_fixed_factor meson8b_fclk_div4 = {
232 .mult = 1,
233 .div = 4,
234 .hw.init = &(struct clk_init_data){
235 .name = "fclk_div4",
236 .ops = &clk_fixed_factor_ops,
237 .parent_names = (const char *[]){ "fixed_pll" },
238 .num_parents = 1,
239 },
240};
241
242static struct clk_fixed_factor meson8b_fclk_div5 = {
243 .mult = 1,
244 .div = 5,
245 .hw.init = &(struct clk_init_data){
246 .name = "fclk_div5",
247 .ops = &clk_fixed_factor_ops,
248 .parent_names = (const char *[]){ "fixed_pll" },
249 .num_parents = 1,
250 },
251};
252
253static struct clk_fixed_factor meson8b_fclk_div7 = {
254 .mult = 1,
255 .div = 7,
256 .hw.init = &(struct clk_init_data){
257 .name = "fclk_div7",
258 .ops = &clk_fixed_factor_ops,
259 .parent_names = (const char *[]){ "fixed_pll" },
260 .num_parents = 1,
261 },
262};
263
264/*
265 * FIXME cpu clocks and the legacy composite clocks (e.g. clk81) are both PLL
266 * post-dividers and should be modeled with their respective PLLs via the
267 * forthcoming coordinated clock rates feature
268 */
269static struct meson_clk_cpu meson8b_cpu_clk = {
270 .reg_off = MESON8B_REG_SYS_CPU_CNTL1,
271 .div_table = cpu_div_table,
272 .clk_nb.notifier_call = meson_clk_cpu_notifier_cb,
273 .hw.init = &(struct clk_init_data){
274 .name = "cpu_clk",
275 .ops = &meson_clk_cpu_ops,
276 .parent_names = (const char *[]){ "sys_pll" },
277 .num_parents = 1,
278 },
279};
111 280
112static u32 mux_table_clk81[] = { 6, 5, 7 }; 281static u32 mux_table_clk81[] = { 6, 5, 7 };
113static u32 mux_table_mali[] = { 6, 5, 7, 4, 0 };
114
115static struct pll_conf pll_confs = {
116 .m = PARM(0x00, 0, 9),
117 .n = PARM(0x00, 9, 5),
118 .od = PARM(0x00, 16, 2),
119};
120
121static struct pll_conf sys_pll_conf = {
122 .m = PARM(0x00, 0, 9),
123 .n = PARM(0x00, 9, 5),
124 .od = PARM(0x00, 16, 2),
125 .rate_table = sys_pll_rate_table,
126};
127
128static const struct composite_conf clk81_conf __initconst = {
129 .mux_table = mux_table_clk81,
130 .mux_flags = CLK_MUX_READ_ONLY,
131 .mux_parm = PARM(0x00, 12, 3),
132 .div_parm = PARM(0x00, 0, 7),
133 .gate_parm = PARM(0x00, 7, 1),
134};
135
136static const struct composite_conf mali_conf __initconst = {
137 .mux_table = mux_table_mali,
138 .mux_parm = PARM(0x00, 9, 3),
139 .div_parm = PARM(0x00, 0, 7),
140 .gate_parm = PARM(0x00, 8, 1),
141};
142
143static const struct clk_conf meson8b_xtal_conf __initconst =
144 FIXED_RATE_P(MESON8B_REG_CTL0_ADDR, CLKID_XTAL, "xtal", 0,
145 PARM(0x00, 4, 7));
146
147static const struct clk_conf meson8b_clk_confs[] __initconst = {
148 FIXED_RATE(CLKID_ZERO, "zero", 0, 0),
149 PLL(MESON8B_REG_PLL_FIXED, CLKID_PLL_FIXED, "fixed_pll",
150 p_xtal, 0, &pll_confs),
151 PLL(MESON8B_REG_PLL_VID, CLKID_PLL_VID, "vid_pll",
152 p_xtal, 0, &pll_confs),
153 PLL(MESON8B_REG_PLL_SYS, CLKID_PLL_SYS, "sys_pll",
154 p_xtal, 0, &sys_pll_conf),
155 FIXED_FACTOR_DIV(CLKID_FCLK_DIV2, "fclk_div2", p_fclk_div, 0, 2),
156 FIXED_FACTOR_DIV(CLKID_FCLK_DIV3, "fclk_div3", p_fclk_div, 0, 3),
157 FIXED_FACTOR_DIV(CLKID_FCLK_DIV4, "fclk_div4", p_fclk_div, 0, 4),
158 FIXED_FACTOR_DIV(CLKID_FCLK_DIV5, "fclk_div5", p_fclk_div, 0, 5),
159 FIXED_FACTOR_DIV(CLKID_FCLK_DIV7, "fclk_div7", p_fclk_div, 0, 7),
160 CPU(MESON8B_REG_SYS_CPU_CNTL1, CLKID_CPUCLK, "a5_clk", p_cpu_clk,
161 cpu_div_table),
162 COMPOSITE(MESON8B_REG_HHI_MPEG, CLKID_CLK81, "clk81", p_clk81,
163 CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED, &clk81_conf),
164 COMPOSITE(MESON8B_REG_MALI, CLKID_MALI, "mali", p_mali,
165 CLK_IGNORE_UNUSED, &mali_conf),
166};
167
168static void __init meson8b_clkc_init(struct device_node *np)
169{
170 void __iomem *clk_base;
171 282
172 if (!meson_clk_init(np, CLK_NR_CLKS)) 283struct clk_mux meson8b_mpeg_clk_sel = {
173 return; 284 .reg = (void *)MESON8B_REG_HHI_MPEG,
285 .mask = 0x7,
286 .shift = 12,
287 .flags = CLK_MUX_READ_ONLY,
288 .table = mux_table_clk81,
289 .lock = &clk_lock,
290 .hw.init = &(struct clk_init_data){
291 .name = "mpeg_clk_sel",
292 .ops = &clk_mux_ro_ops,
293 /*
294 * FIXME bits 14:12 selects from 8 possible parents:
295 * xtal, 1'b0 (wtf), fclk_div7, mpll_clkout1, mpll_clkout2,
296 * fclk_div4, fclk_div3, fclk_div5
297 */
298 .parent_names = (const char *[]){ "fclk_div3", "fclk_div4",
299 "fclk_div5" },
300 .num_parents = 3,
301 .flags = (CLK_SET_RATE_NO_REPARENT | CLK_IGNORE_UNUSED),
302 },
303};
174 304
175 /* XTAL */ 305struct clk_divider meson8b_mpeg_clk_div = {
176 clk_base = of_iomap(np, 0); 306 .reg = (void *)MESON8B_REG_HHI_MPEG,
177 if (!clk_base) { 307 .shift = 0,
178 pr_err("%s: Unable to map xtal base\n", __func__); 308 .width = 7,
179 return; 309 .lock = &clk_lock,
180 } 310 .hw.init = &(struct clk_init_data){
311 .name = "mpeg_clk_div",
312 .ops = &clk_divider_ops,
313 .parent_names = (const char *[]){ "mpeg_clk_sel" },
314 .num_parents = 1,
315 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
316 },
317};
181 318
182 meson_clk_register_clks(&meson8b_xtal_conf, 1, clk_base); 319struct clk_gate meson8b_clk81 = {
183 iounmap(clk_base); 320 .reg = (void *)MESON8B_REG_HHI_MPEG,
321 .bit_idx = 7,
322 .lock = &clk_lock,
323 .hw.init = &(struct clk_init_data){
324 .name = "clk81",
325 .ops = &clk_gate_ops,
326 .parent_names = (const char *[]){ "mpeg_clk_div" },
327 .num_parents = 1,
328 .flags = (CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED),
329 },
330};
331
332static struct clk_hw_onecell_data meson8b_hw_onecell_data = {
333 .hws = {
334 [CLKID_XTAL] = &meson8b_xtal.hw,
335 [CLKID_PLL_FIXED] = &meson8b_fixed_pll.hw,
336 [CLKID_PLL_VID] = &meson8b_vid_pll.hw,
337 [CLKID_PLL_SYS] = &meson8b_sys_pll.hw,
338 [CLKID_FCLK_DIV2] = &meson8b_fclk_div2.hw,
339 [CLKID_FCLK_DIV3] = &meson8b_fclk_div3.hw,
340 [CLKID_FCLK_DIV4] = &meson8b_fclk_div4.hw,
341 [CLKID_FCLK_DIV5] = &meson8b_fclk_div5.hw,
342 [CLKID_FCLK_DIV7] = &meson8b_fclk_div7.hw,
343 [CLKID_CPUCLK] = &meson8b_cpu_clk.hw,
344 [CLKID_MPEG_SEL] = &meson8b_mpeg_clk_sel.hw,
345 [CLKID_MPEG_DIV] = &meson8b_mpeg_clk_div.hw,
346 [CLKID_CLK81] = &meson8b_clk81.hw,
347 },
348 .num = CLK_NR_CLKS,
349};
350
351static struct meson_clk_pll *const meson8b_clk_plls[] = {
352 &meson8b_fixed_pll,
353 &meson8b_vid_pll,
354 &meson8b_sys_pll,
355};
356
357static int meson8b_clkc_probe(struct platform_device *pdev)
358{
359 void __iomem *clk_base;
360 int ret, clkid, i;
361 struct clk_hw *parent_hw;
362 struct clk *parent_clk;
363 struct device *dev = &pdev->dev;
184 364
185 /* Generic clocks and PLLs */ 365 /* Generic clocks and PLLs */
186 clk_base = of_iomap(np, 1); 366 clk_base = of_iomap(dev->of_node, 1);
187 if (!clk_base) { 367 if (!clk_base) {
188 pr_err("%s: Unable to map clk base\n", __func__); 368 pr_err("%s: Unable to map clk base\n", __func__);
189 return; 369 return -ENXIO;
370 }
371
372 /* Populate base address for PLLs */
373 for (i = 0; i < ARRAY_SIZE(meson8b_clk_plls); i++)
374 meson8b_clk_plls[i]->base = clk_base;
375
376 /* Populate the base address for CPU clk */
377 meson8b_cpu_clk.base = clk_base;
378
379 /* Populate the base address for the MPEG clks */
380 meson8b_mpeg_clk_sel.reg = clk_base + (u32)meson8b_mpeg_clk_sel.reg;
381 meson8b_mpeg_clk_div.reg = clk_base + (u32)meson8b_mpeg_clk_div.reg;
382 meson8b_clk81.reg = clk_base + (u32)meson8b_clk81.reg;
383
384 /*
385 * register all clks
386 * CLKID_UNUSED = 0, so skip it and start with CLKID_XTAL = 1
387 */
388 for (clkid = CLKID_XTAL; clkid < CLK_NR_CLKS; clkid++) {
389 /* array might be sparse */
390 if (!meson8b_hw_onecell_data.hws[clkid])
391 continue;
392
393 /* FIXME convert to devm_clk_register */
394 ret = devm_clk_hw_register(dev, meson8b_hw_onecell_data.hws[clkid]);
395 if (ret)
396 goto iounmap;
190 } 397 }
191 398
192 meson_clk_register_clks(meson8b_clk_confs, 399 /*
193 ARRAY_SIZE(meson8b_clk_confs), 400 * Register CPU clk notifier
194 clk_base); 401 *
402 * FIXME this is wrong for a lot of reasons. First, the muxes should be
403 * struct clk_hw objects. Second, we shouldn't program the muxes in
404 * notifier handlers. The tricky programming sequence will be handled
405 * by the forthcoming coordinated clock rates mechanism once that
406 * feature is released.
407 *
408 * Furthermore, looking up the parent this way is terrible. At some
409 * point we will stop allocating a default struct clk when registering
410 * a new clk_hw, and this hack will no longer work. Releasing the ccr
411 * feature before that time solves the problem :-)
412 */
413 parent_hw = clk_hw_get_parent(&meson8b_cpu_clk.hw);
414 parent_clk = parent_hw->clk;
415 ret = clk_notifier_register(parent_clk, &meson8b_cpu_clk.clk_nb);
416 if (ret) {
417 pr_err("%s: failed to register clock notifier for cpu_clk\n",
418 __func__);
419 goto iounmap;
420 }
421
422 return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
423 &meson8b_hw_onecell_data);
424
425iounmap:
426 iounmap(clk_base);
427 return ret;
428}
429
430static const struct of_device_id meson8b_clkc_match_table[] = {
431 { .compatible = "amlogic,meson8b-clkc" },
432 { }
433};
434
435static struct platform_driver meson8b_driver = {
436 .probe = meson8b_clkc_probe,
437 .driver = {
438 .name = "meson8b-clkc",
439 .of_match_table = meson8b_clkc_match_table,
440 },
441};
442
443static int __init meson8b_clkc_init(void)
444{
445 return platform_driver_register(&meson8b_driver);
195} 446}
196CLK_OF_DECLARE(meson8b_clock, "amlogic,meson8b-clkc", meson8b_clkc_init); 447device_initcall(meson8b_clkc_init);