2 * Copyright (c) 2016 Maxime Ripard. All rights reserved.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/clk-provider.h>
15 #include <linux/of_address.h>
17 #include "ccu_common.h"
18 #include "ccu_reset.h"
28 #include "ccu_phase.h"
30 #include "ccu-sun5i.h"
32 static struct ccu_nkmp pll_core_clk = {
34 .n = _SUNXI_CCU_MULT_OFFSET(8, 5, 0),
35 .k = _SUNXI_CCU_MULT(4, 2),
36 .m = _SUNXI_CCU_DIV(0, 2),
37 .p = _SUNXI_CCU_DIV(16, 2),
40 .hw.init = CLK_HW_INIT("pll-core",
48 * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
49 * the base (2x, 4x and 8x), and one variable divider (the one true
52 * We don't have any need for the variable divider for now, so we just
53 * hardcode it to match with the clock names
55 #define SUN5I_PLL_AUDIO_REG 0x008
57 static struct ccu_nm pll_audio_base_clk = {
59 .n = _SUNXI_CCU_MULT_OFFSET(8, 7, 0),
62 * The datasheet is wrong here, this doesn't have any
65 .m = _SUNXI_CCU_DIV_OFFSET(0, 5, 0),
68 .hw.init = CLK_HW_INIT("pll-audio-base",
75 static struct ccu_mult pll_video0_clk = {
77 .mult = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(0, 7, 0, 9, 127),
78 .frac = _SUNXI_CCU_FRAC(BIT(15), BIT(14),
79 270000000, 297000000),
82 .features = (CCU_FEATURE_FRACTIONAL |
83 CCU_FEATURE_ALL_PREDIV),
85 .hw.init = CLK_HW_INIT("pll-video0",
92 static struct ccu_nkmp pll_ve_clk = {
94 .n = _SUNXI_CCU_MULT_OFFSET(8, 5, 0),
95 .k = _SUNXI_CCU_MULT(4, 2),
96 .m = _SUNXI_CCU_DIV(0, 2),
97 .p = _SUNXI_CCU_DIV(16, 2),
100 .hw.init = CLK_HW_INIT("pll-ve",
107 static struct ccu_nk pll_ddr_base_clk = {
109 .n = _SUNXI_CCU_MULT_OFFSET(8, 5, 0),
110 .k = _SUNXI_CCU_MULT(4, 2),
113 .hw.init = CLK_HW_INIT("pll-ddr-base",
120 static SUNXI_CCU_M(pll_ddr_clk, "pll-ddr", "pll-ddr-base", 0x020, 0, 2,
123 static struct ccu_div pll_ddr_other_clk = {
124 .div = _SUNXI_CCU_DIV_FLAGS(16, 2, CLK_DIVIDER_POWER_OF_TWO),
128 .hw.init = CLK_HW_INIT("pll-ddr-other", "pll-ddr-base",
134 static struct ccu_nk pll_periph_clk = {
136 .n = _SUNXI_CCU_MULT_OFFSET(8, 5, 0),
137 .k = _SUNXI_CCU_MULT(4, 2),
141 .features = CCU_FEATURE_FIXED_POSTDIV,
142 .hw.init = CLK_HW_INIT("pll-periph",
149 static struct ccu_mult pll_video1_clk = {
151 .mult = _SUNXI_CCU_MULT_OFFSET_MIN_MAX(0, 7, 0, 9, 127),
152 .frac = _SUNXI_CCU_FRAC(BIT(15), BIT(14),
153 270000000, 297000000),
156 .features = (CCU_FEATURE_FRACTIONAL |
157 CCU_FEATURE_ALL_PREDIV),
159 .hw.init = CLK_HW_INIT("pll-video1",
166 static SUNXI_CCU_GATE(hosc_clk, "hosc", "osc24M", 0x050, BIT(0), 0);
168 #define SUN5I_AHB_REG 0x054
169 static const char * const cpu_parents[] = { "osc32k", "hosc",
170 "pll-core" , "pll-periph" };
171 static const struct ccu_mux_fixed_prediv cpu_predivs[] = {
172 { .index = 3, .div = 3, },
174 static struct ccu_mux cpu_clk = {
178 .fixed_predivs = cpu_predivs,
179 .n_predivs = ARRAY_SIZE(cpu_predivs),
183 .features = CCU_FEATURE_FIXED_PREDIV,
184 .hw.init = CLK_HW_INIT_PARENTS("cpu",
191 static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x054, 0, 2, 0);
193 static const char * const ahb_parents[] = { "axi" , "cpu", "pll-periph" };
194 static const struct ccu_mux_fixed_prediv ahb_predivs[] = {
195 { .index = 2, .div = 2, },
197 static struct ccu_div ahb_clk = {
198 .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
202 .fixed_predivs = ahb_predivs,
203 .n_predivs = ARRAY_SIZE(ahb_predivs),
208 .hw.init = CLK_HW_INIT_PARENTS("ahb",
215 static struct clk_div_table apb0_div_table[] = {
216 { .val = 0, .div = 2 },
217 { .val = 1, .div = 2 },
218 { .val = 2, .div = 4 },
219 { .val = 3, .div = 8 },
222 static SUNXI_CCU_DIV_TABLE(apb0_clk, "apb0", "ahb",
223 0x054, 8, 2, apb0_div_table, 0);
225 static const char * const apb1_parents[] = { "hosc", "pll-periph", "osc32k" };
226 static SUNXI_CCU_MP_WITH_MUX(apb1_clk, "apb1", apb1_parents, 0x058,
232 static SUNXI_CCU_GATE(axi_dram_clk, "axi-dram", "axi",
235 static SUNXI_CCU_GATE(ahb_otg_clk, "ahb-otg", "ahb",
237 static SUNXI_CCU_GATE(ahb_ehci_clk, "ahb-ehci", "ahb",
239 static SUNXI_CCU_GATE(ahb_ohci_clk, "ahb-ohci", "ahb",
241 static SUNXI_CCU_GATE(ahb_ss_clk, "ahb-ss", "ahb",
243 static SUNXI_CCU_GATE(ahb_dma_clk, "ahb-dma", "ahb",
245 static SUNXI_CCU_GATE(ahb_bist_clk, "ahb-bist", "ahb",
247 static SUNXI_CCU_GATE(ahb_mmc0_clk, "ahb-mmc0", "ahb",
249 static SUNXI_CCU_GATE(ahb_mmc1_clk, "ahb-mmc1", "ahb",
251 static SUNXI_CCU_GATE(ahb_mmc2_clk, "ahb-mmc2", "ahb",
253 static SUNXI_CCU_GATE(ahb_nand_clk, "ahb-nand", "ahb",
255 static SUNXI_CCU_GATE(ahb_sdram_clk, "ahb-sdram", "ahb",
256 0x060, BIT(14), CLK_IS_CRITICAL);
257 static SUNXI_CCU_GATE(ahb_emac_clk, "ahb-emac", "ahb",
259 static SUNXI_CCU_GATE(ahb_ts_clk, "ahb-ts", "ahb",
261 static SUNXI_CCU_GATE(ahb_spi0_clk, "ahb-spi0", "ahb",
263 static SUNXI_CCU_GATE(ahb_spi1_clk, "ahb-spi1", "ahb",
265 static SUNXI_CCU_GATE(ahb_spi2_clk, "ahb-spi2", "ahb",
267 static SUNXI_CCU_GATE(ahb_gps_clk, "ahb-gps", "ahb",
269 static SUNXI_CCU_GATE(ahb_hstimer_clk, "ahb-hstimer", "ahb",
272 static SUNXI_CCU_GATE(ahb_ve_clk, "ahb-ve", "ahb",
274 static SUNXI_CCU_GATE(ahb_tve_clk, "ahb-tve", "ahb",
276 static SUNXI_CCU_GATE(ahb_lcd_clk, "ahb-lcd", "ahb",
278 static SUNXI_CCU_GATE(ahb_csi_clk, "ahb-csi", "ahb",
280 static SUNXI_CCU_GATE(ahb_hdmi_clk, "ahb-hdmi", "ahb",
282 static SUNXI_CCU_GATE(ahb_de_be_clk, "ahb-de-be", "ahb",
284 static SUNXI_CCU_GATE(ahb_de_fe_clk, "ahb-de-fe", "ahb",
286 static SUNXI_CCU_GATE(ahb_iep_clk, "ahb-iep", "ahb",
288 static SUNXI_CCU_GATE(ahb_gpu_clk, "ahb-gpu", "ahb",
291 static SUNXI_CCU_GATE(apb0_codec_clk, "apb0-codec", "apb0",
293 static SUNXI_CCU_GATE(apb0_spdif_clk, "apb0-spdif", "apb0",
295 static SUNXI_CCU_GATE(apb0_i2s_clk, "apb0-i2s", "apb0",
297 static SUNXI_CCU_GATE(apb0_pio_clk, "apb0-pio", "apb0",
299 static SUNXI_CCU_GATE(apb0_ir_clk, "apb0-ir", "apb0",
301 static SUNXI_CCU_GATE(apb0_keypad_clk, "apb0-keypad", "apb0",
304 static SUNXI_CCU_GATE(apb1_i2c0_clk, "apb1-i2c0", "apb1",
306 static SUNXI_CCU_GATE(apb1_i2c1_clk, "apb1-i2c1", "apb1",
308 static SUNXI_CCU_GATE(apb1_i2c2_clk, "apb1-i2c2", "apb1",
310 static SUNXI_CCU_GATE(apb1_uart0_clk, "apb1-uart0", "apb1",
312 static SUNXI_CCU_GATE(apb1_uart1_clk, "apb1-uart1", "apb1",
314 static SUNXI_CCU_GATE(apb1_uart2_clk, "apb1-uart2", "apb1",
316 static SUNXI_CCU_GATE(apb1_uart3_clk, "apb1-uart3", "apb1",
319 static const char * const mod0_default_parents[] = { "hosc", "pll-periph",
321 static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
328 static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
335 static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
342 static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
349 static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", mod0_default_parents, 0x098,
356 static SUNXI_CCU_MP_WITH_MUX_GATE(ss_clk, "ss", mod0_default_parents, 0x09c,
363 static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
370 static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
377 static SUNXI_CCU_MP_WITH_MUX_GATE(spi2_clk, "spi2", mod0_default_parents, 0x0a8,
384 static SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir", mod0_default_parents, 0x0b0,
391 static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
392 "pll-audio-2x", "pll-audio" };
393 static SUNXI_CCU_MUX_WITH_GATE(i2s_clk, "i2s", i2s_parents,
394 0x0b8, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
396 static const char * const spdif_parents[] = { "pll-audio-8x", "pll-audio-4x",
397 "pll-audio-2x", "pll-audio" };
398 static SUNXI_CCU_MUX_WITH_GATE(spdif_clk, "spdif", spdif_parents,
399 0x0c0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
401 static const char * const keypad_parents[] = { "hosc", "losc"};
402 static const u8 keypad_table[] = { 0, 2 };
403 static struct ccu_mp keypad_clk = {
405 .m = _SUNXI_CCU_DIV(8, 5),
406 .p = _SUNXI_CCU_DIV(20, 2),
407 .mux = _SUNXI_CCU_MUX_TABLE(24, 2, keypad_table),
411 .hw.init = CLK_HW_INIT_PARENTS("keypad",
418 static SUNXI_CCU_GATE(usb_ohci_clk, "usb-ohci", "pll-periph",
420 static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "pll-periph",
422 static SUNXI_CCU_GATE(usb_phy1_clk, "usb-phy1", "pll-periph",
425 static const char * const gps_parents[] = { "hosc", "pll-periph",
426 "pll-video1", "pll-ve" };
427 static SUNXI_CCU_M_WITH_MUX_GATE(gps_clk, "gps", gps_parents,
428 0x0d0, 0, 3, 24, 2, BIT(31), 0);
430 static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "pll-ddr",
432 static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "pll-ddr",
434 static SUNXI_CCU_GATE(dram_ts_clk, "dram-ts", "pll-ddr",
436 static SUNXI_CCU_GATE(dram_tve_clk, "dram-tve", "pll-ddr",
438 static SUNXI_CCU_GATE(dram_de_fe_clk, "dram-de-fe", "pll-ddr",
440 static SUNXI_CCU_GATE(dram_de_be_clk, "dram-de-be", "pll-ddr",
442 static SUNXI_CCU_GATE(dram_ace_clk, "dram-ace", "pll-ddr",
444 static SUNXI_CCU_GATE(dram_iep_clk, "dram-iep", "pll-ddr",
447 static const char * const de_parents[] = { "pll-video0", "pll-video1",
449 static SUNXI_CCU_M_WITH_MUX_GATE(de_be_clk, "de-be", de_parents,
450 0x104, 0, 4, 24, 2, BIT(31), 0);
452 static SUNXI_CCU_M_WITH_MUX_GATE(de_fe_clk, "de-fe", de_parents,
453 0x10c, 0, 4, 24, 2, BIT(31), 0);
455 static const char * const tcon_parents[] = { "pll-video0", "pll-video1",
456 "pll-video0-2x", "pll-video1-2x" };
457 static SUNXI_CCU_MUX_WITH_GATE(tcon_ch0_clk, "tcon-ch0-sclk", tcon_parents,
458 0x118, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
460 static SUNXI_CCU_M_WITH_MUX_GATE(tcon_ch1_sclk2_clk, "tcon-ch1-sclk2",
462 0x12c, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
464 static SUNXI_CCU_M_WITH_GATE(tcon_ch1_sclk1_clk, "tcon-ch1-sclk1", "tcon-ch1-sclk2",
465 0x12c, 11, 1, BIT(15), CLK_SET_RATE_PARENT);
467 static const char * const csi_parents[] = { "hosc", "pll-video0", "pll-video1",
468 "pll-video0-2x", "pll-video1-2x" };
469 static const u8 csi_table[] = { 0, 1, 2, 5, 6 };
470 static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_clk, "csi",
471 csi_parents, csi_table,
472 0x134, 0, 5, 24, 3, BIT(31), 0);
474 static SUNXI_CCU_GATE(ve_clk, "ve", "pll-ve",
475 0x13c, BIT(31), CLK_SET_RATE_PARENT);
477 static SUNXI_CCU_GATE(codec_clk, "codec", "pll-audio",
478 0x140, BIT(31), CLK_SET_RATE_PARENT);
480 static SUNXI_CCU_GATE(avs_clk, "avs", "hosc",
483 static const char * const hdmi_parents[] = { "pll-video0", "pll-video0-2x" };
484 static const u8 hdmi_table[] = { 0, 2 };
485 static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(hdmi_clk, "hdmi",
486 hdmi_parents, hdmi_table,
487 0x150, 0, 4, 24, 2, BIT(31),
488 CLK_SET_RATE_PARENT);
490 static const char * const gpu_parents[] = { "pll-video0", "pll-ve",
491 "pll-ddr-other", "pll-video1",
493 static SUNXI_CCU_M_WITH_MUX_GATE(gpu_clk, "gpu", gpu_parents,
494 0x154, 0, 4, 24, 3, BIT(31), 0);
496 static const char * const mbus_parents[] = { "hosc", "pll-periph", "pll-ddr" };
497 static SUNXI_CCU_MP_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
498 0x15c, 0, 4, 16, 2, 24, 2, BIT(31), CLK_IS_CRITICAL);
500 static SUNXI_CCU_GATE(iep_clk, "iep", "de-be",
503 static struct ccu_common *sun5i_a10s_ccu_clks[] = {
505 &pll_core_clk.common,
506 &pll_audio_base_clk.common,
507 &pll_video0_clk.common,
509 &pll_ddr_base_clk.common,
511 &pll_ddr_other_clk.common,
512 &pll_periph_clk.common,
513 &pll_video1_clk.common,
519 &axi_dram_clk.common,
521 &ahb_ehci_clk.common,
522 &ahb_ohci_clk.common,
525 &ahb_bist_clk.common,
526 &ahb_mmc0_clk.common,
527 &ahb_mmc1_clk.common,
528 &ahb_mmc2_clk.common,
529 &ahb_nand_clk.common,
530 &ahb_sdram_clk.common,
531 &ahb_emac_clk.common,
533 &ahb_spi0_clk.common,
534 &ahb_spi1_clk.common,
535 &ahb_spi2_clk.common,
537 &ahb_hstimer_clk.common,
542 &ahb_hdmi_clk.common,
543 &ahb_de_be_clk.common,
544 &ahb_de_fe_clk.common,
547 &apb0_codec_clk.common,
548 &apb0_spdif_clk.common,
549 &apb0_i2s_clk.common,
550 &apb0_pio_clk.common,
552 &apb0_keypad_clk.common,
553 &apb1_i2c0_clk.common,
554 &apb1_i2c1_clk.common,
555 &apb1_i2c2_clk.common,
556 &apb1_uart0_clk.common,
557 &apb1_uart1_clk.common,
558 &apb1_uart2_clk.common,
559 &apb1_uart3_clk.common,
573 &usb_ohci_clk.common,
574 &usb_phy0_clk.common,
575 &usb_phy1_clk.common,
578 &dram_csi_clk.common,
580 &dram_tve_clk.common,
581 &dram_de_fe_clk.common,
582 &dram_de_be_clk.common,
583 &dram_ace_clk.common,
584 &dram_iep_clk.common,
587 &tcon_ch0_clk.common,
588 &tcon_ch1_sclk2_clk.common,
589 &tcon_ch1_sclk1_clk.common,
600 /* We hardcode the divider to 4 for now */
601 static CLK_FIXED_FACTOR(pll_audio_clk, "pll-audio",
602 "pll-audio-base", 4, 1, CLK_SET_RATE_PARENT);
603 static CLK_FIXED_FACTOR(pll_audio_2x_clk, "pll-audio-2x",
604 "pll-audio-base", 2, 1, CLK_SET_RATE_PARENT);
605 static CLK_FIXED_FACTOR(pll_audio_4x_clk, "pll-audio-4x",
606 "pll-audio-base", 1, 1, CLK_SET_RATE_PARENT);
607 static CLK_FIXED_FACTOR(pll_audio_8x_clk, "pll-audio-8x",
608 "pll-audio-base", 1, 2, CLK_SET_RATE_PARENT);
609 static CLK_FIXED_FACTOR(pll_video0_2x_clk, "pll-video0-2x",
610 "pll-video0", 1, 2, CLK_SET_RATE_PARENT);
611 static CLK_FIXED_FACTOR(pll_video1_2x_clk, "pll-video1-2x",
612 "pll-video1", 1, 2, CLK_SET_RATE_PARENT);
614 static struct clk_hw_onecell_data sun5i_a10s_hw_clks = {
616 [CLK_HOSC] = &hosc_clk.common.hw,
617 [CLK_PLL_CORE] = &pll_core_clk.common.hw,
618 [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
619 [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
620 [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
621 [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
622 [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
623 [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
624 [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
625 [CLK_PLL_VE] = &pll_ve_clk.common.hw,
626 [CLK_PLL_DDR_BASE] = &pll_ddr_base_clk.common.hw,
627 [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
628 [CLK_PLL_DDR_OTHER] = &pll_ddr_other_clk.common.hw,
629 [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw,
630 [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
631 [CLK_PLL_VIDEO1_2X] = &pll_video1_2x_clk.hw,
632 [CLK_CPU] = &cpu_clk.common.hw,
633 [CLK_AXI] = &axi_clk.common.hw,
634 [CLK_AHB] = &ahb_clk.common.hw,
635 [CLK_APB0] = &apb0_clk.common.hw,
636 [CLK_APB1] = &apb1_clk.common.hw,
637 [CLK_DRAM_AXI] = &axi_dram_clk.common.hw,
638 [CLK_AHB_OTG] = &ahb_otg_clk.common.hw,
639 [CLK_AHB_EHCI] = &ahb_ehci_clk.common.hw,
640 [CLK_AHB_OHCI] = &ahb_ohci_clk.common.hw,
641 [CLK_AHB_SS] = &ahb_ss_clk.common.hw,
642 [CLK_AHB_DMA] = &ahb_dma_clk.common.hw,
643 [CLK_AHB_BIST] = &ahb_bist_clk.common.hw,
644 [CLK_AHB_MMC0] = &ahb_mmc0_clk.common.hw,
645 [CLK_AHB_MMC1] = &ahb_mmc1_clk.common.hw,
646 [CLK_AHB_MMC2] = &ahb_mmc2_clk.common.hw,
647 [CLK_AHB_NAND] = &ahb_nand_clk.common.hw,
648 [CLK_AHB_SDRAM] = &ahb_sdram_clk.common.hw,
649 [CLK_AHB_EMAC] = &ahb_emac_clk.common.hw,
650 [CLK_AHB_TS] = &ahb_ts_clk.common.hw,
651 [CLK_AHB_SPI0] = &ahb_spi0_clk.common.hw,
652 [CLK_AHB_SPI1] = &ahb_spi1_clk.common.hw,
653 [CLK_AHB_SPI2] = &ahb_spi2_clk.common.hw,
654 [CLK_AHB_GPS] = &ahb_gps_clk.common.hw,
655 [CLK_AHB_HSTIMER] = &ahb_hstimer_clk.common.hw,
656 [CLK_AHB_VE] = &ahb_ve_clk.common.hw,
657 [CLK_AHB_TVE] = &ahb_tve_clk.common.hw,
658 [CLK_AHB_LCD] = &ahb_lcd_clk.common.hw,
659 [CLK_AHB_CSI] = &ahb_csi_clk.common.hw,
660 [CLK_AHB_HDMI] = &ahb_hdmi_clk.common.hw,
661 [CLK_AHB_DE_BE] = &ahb_de_be_clk.common.hw,
662 [CLK_AHB_DE_FE] = &ahb_de_fe_clk.common.hw,
663 [CLK_AHB_IEP] = &ahb_iep_clk.common.hw,
664 [CLK_AHB_GPU] = &ahb_gpu_clk.common.hw,
665 [CLK_APB0_CODEC] = &apb0_codec_clk.common.hw,
666 [CLK_APB0_I2S] = &apb0_i2s_clk.common.hw,
667 [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
668 [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
669 [CLK_APB0_KEYPAD] = &apb0_keypad_clk.common.hw,
670 [CLK_APB1_I2C0] = &apb1_i2c0_clk.common.hw,
671 [CLK_APB1_I2C1] = &apb1_i2c1_clk.common.hw,
672 [CLK_APB1_I2C2] = &apb1_i2c2_clk.common.hw,
673 [CLK_APB1_UART0] = &apb1_uart0_clk.common.hw,
674 [CLK_APB1_UART1] = &apb1_uart1_clk.common.hw,
675 [CLK_APB1_UART2] = &apb1_uart2_clk.common.hw,
676 [CLK_APB1_UART3] = &apb1_uart3_clk.common.hw,
677 [CLK_NAND] = &nand_clk.common.hw,
678 [CLK_MMC0] = &mmc0_clk.common.hw,
679 [CLK_MMC1] = &mmc1_clk.common.hw,
680 [CLK_MMC2] = &mmc2_clk.common.hw,
681 [CLK_TS] = &ts_clk.common.hw,
682 [CLK_SS] = &ss_clk.common.hw,
683 [CLK_SPI0] = &spi0_clk.common.hw,
684 [CLK_SPI1] = &spi1_clk.common.hw,
685 [CLK_SPI2] = &spi2_clk.common.hw,
686 [CLK_IR] = &ir_clk.common.hw,
687 [CLK_I2S] = &i2s_clk.common.hw,
688 [CLK_KEYPAD] = &keypad_clk.common.hw,
689 [CLK_USB_OHCI] = &usb_ohci_clk.common.hw,
690 [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
691 [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
692 [CLK_GPS] = &gps_clk.common.hw,
693 [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
694 [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
695 [CLK_DRAM_TS] = &dram_ts_clk.common.hw,
696 [CLK_DRAM_TVE] = &dram_tve_clk.common.hw,
697 [CLK_DRAM_DE_FE] = &dram_de_fe_clk.common.hw,
698 [CLK_DRAM_DE_BE] = &dram_de_be_clk.common.hw,
699 [CLK_DRAM_ACE] = &dram_ace_clk.common.hw,
700 [CLK_DRAM_IEP] = &dram_iep_clk.common.hw,
701 [CLK_DE_BE] = &de_be_clk.common.hw,
702 [CLK_DE_FE] = &de_fe_clk.common.hw,
703 [CLK_TCON_CH0] = &tcon_ch0_clk.common.hw,
704 [CLK_TCON_CH1_SCLK] = &tcon_ch1_sclk2_clk.common.hw,
705 [CLK_TCON_CH1] = &tcon_ch1_sclk1_clk.common.hw,
706 [CLK_CSI] = &csi_clk.common.hw,
707 [CLK_VE] = &ve_clk.common.hw,
708 [CLK_CODEC] = &codec_clk.common.hw,
709 [CLK_AVS] = &avs_clk.common.hw,
710 [CLK_HDMI] = &hdmi_clk.common.hw,
711 [CLK_GPU] = &gpu_clk.common.hw,
712 [CLK_MBUS] = &mbus_clk.common.hw,
713 [CLK_IEP] = &iep_clk.common.hw,
718 static struct ccu_reset_map sun5i_a10s_ccu_resets[] = {
719 [RST_USB_PHY0] = { 0x0cc, BIT(0) },
720 [RST_USB_PHY1] = { 0x0cc, BIT(1) },
722 [RST_GPS] = { 0x0d0, BIT(30) },
724 [RST_DE_BE] = { 0x104, BIT(30) },
726 [RST_DE_FE] = { 0x10c, BIT(30) },
728 [RST_TVE] = { 0x118, BIT(29) },
729 [RST_LCD] = { 0x118, BIT(30) },
731 [RST_CSI] = { 0x134, BIT(30) },
733 [RST_VE] = { 0x13c, BIT(0) },
735 [RST_GPU] = { 0x154, BIT(30) },
737 [RST_IEP] = { 0x160, BIT(30) },
740 static const struct sunxi_ccu_desc sun5i_a10s_ccu_desc = {
741 .ccu_clks = sun5i_a10s_ccu_clks,
742 .num_ccu_clks = ARRAY_SIZE(sun5i_a10s_ccu_clks),
744 .hw_clks = &sun5i_a10s_hw_clks,
746 .resets = sun5i_a10s_ccu_resets,
747 .num_resets = ARRAY_SIZE(sun5i_a10s_ccu_resets),
751 * The A13 is the A10s minus the TS, GPS, HDMI, I2S and the keypad
753 static struct clk_hw_onecell_data sun5i_a13_hw_clks = {
755 [CLK_HOSC] = &hosc_clk.common.hw,
756 [CLK_PLL_CORE] = &pll_core_clk.common.hw,
757 [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
758 [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
759 [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
760 [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
761 [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
762 [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
763 [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
764 [CLK_PLL_VE] = &pll_ve_clk.common.hw,
765 [CLK_PLL_DDR_BASE] = &pll_ddr_base_clk.common.hw,
766 [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
767 [CLK_PLL_DDR_OTHER] = &pll_ddr_other_clk.common.hw,
768 [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw,
769 [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
770 [CLK_PLL_VIDEO1_2X] = &pll_video1_2x_clk.hw,
771 [CLK_CPU] = &cpu_clk.common.hw,
772 [CLK_AXI] = &axi_clk.common.hw,
773 [CLK_AHB] = &ahb_clk.common.hw,
774 [CLK_APB0] = &apb0_clk.common.hw,
775 [CLK_APB1] = &apb1_clk.common.hw,
776 [CLK_DRAM_AXI] = &axi_dram_clk.common.hw,
777 [CLK_AHB_OTG] = &ahb_otg_clk.common.hw,
778 [CLK_AHB_EHCI] = &ahb_ehci_clk.common.hw,
779 [CLK_AHB_OHCI] = &ahb_ohci_clk.common.hw,
780 [CLK_AHB_SS] = &ahb_ss_clk.common.hw,
781 [CLK_AHB_DMA] = &ahb_dma_clk.common.hw,
782 [CLK_AHB_BIST] = &ahb_bist_clk.common.hw,
783 [CLK_AHB_MMC0] = &ahb_mmc0_clk.common.hw,
784 [CLK_AHB_MMC1] = &ahb_mmc1_clk.common.hw,
785 [CLK_AHB_MMC2] = &ahb_mmc2_clk.common.hw,
786 [CLK_AHB_NAND] = &ahb_nand_clk.common.hw,
787 [CLK_AHB_SDRAM] = &ahb_sdram_clk.common.hw,
788 [CLK_AHB_EMAC] = &ahb_emac_clk.common.hw,
789 [CLK_AHB_SPI0] = &ahb_spi0_clk.common.hw,
790 [CLK_AHB_SPI1] = &ahb_spi1_clk.common.hw,
791 [CLK_AHB_SPI2] = &ahb_spi2_clk.common.hw,
792 [CLK_AHB_HSTIMER] = &ahb_hstimer_clk.common.hw,
793 [CLK_AHB_VE] = &ahb_ve_clk.common.hw,
794 [CLK_AHB_TVE] = &ahb_tve_clk.common.hw,
795 [CLK_AHB_LCD] = &ahb_lcd_clk.common.hw,
796 [CLK_AHB_CSI] = &ahb_csi_clk.common.hw,
797 [CLK_AHB_DE_BE] = &ahb_de_be_clk.common.hw,
798 [CLK_AHB_DE_FE] = &ahb_de_fe_clk.common.hw,
799 [CLK_AHB_IEP] = &ahb_iep_clk.common.hw,
800 [CLK_AHB_GPU] = &ahb_gpu_clk.common.hw,
801 [CLK_APB0_CODEC] = &apb0_codec_clk.common.hw,
802 [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
803 [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
804 [CLK_APB1_I2C0] = &apb1_i2c0_clk.common.hw,
805 [CLK_APB1_I2C1] = &apb1_i2c1_clk.common.hw,
806 [CLK_APB1_I2C2] = &apb1_i2c2_clk.common.hw,
807 [CLK_APB1_UART0] = &apb1_uart0_clk.common.hw,
808 [CLK_APB1_UART1] = &apb1_uart1_clk.common.hw,
809 [CLK_APB1_UART2] = &apb1_uart2_clk.common.hw,
810 [CLK_APB1_UART3] = &apb1_uart3_clk.common.hw,
811 [CLK_NAND] = &nand_clk.common.hw,
812 [CLK_MMC0] = &mmc0_clk.common.hw,
813 [CLK_MMC1] = &mmc1_clk.common.hw,
814 [CLK_MMC2] = &mmc2_clk.common.hw,
815 [CLK_SS] = &ss_clk.common.hw,
816 [CLK_SPI0] = &spi0_clk.common.hw,
817 [CLK_SPI1] = &spi1_clk.common.hw,
818 [CLK_SPI2] = &spi2_clk.common.hw,
819 [CLK_IR] = &ir_clk.common.hw,
820 [CLK_USB_OHCI] = &usb_ohci_clk.common.hw,
821 [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
822 [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
823 [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
824 [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
825 [CLK_DRAM_TVE] = &dram_tve_clk.common.hw,
826 [CLK_DRAM_DE_FE] = &dram_de_fe_clk.common.hw,
827 [CLK_DRAM_DE_BE] = &dram_de_be_clk.common.hw,
828 [CLK_DRAM_ACE] = &dram_ace_clk.common.hw,
829 [CLK_DRAM_IEP] = &dram_iep_clk.common.hw,
830 [CLK_DE_BE] = &de_be_clk.common.hw,
831 [CLK_DE_FE] = &de_fe_clk.common.hw,
832 [CLK_TCON_CH0] = &tcon_ch0_clk.common.hw,
833 [CLK_TCON_CH1_SCLK] = &tcon_ch1_sclk2_clk.common.hw,
834 [CLK_TCON_CH1] = &tcon_ch1_sclk1_clk.common.hw,
835 [CLK_CSI] = &csi_clk.common.hw,
836 [CLK_VE] = &ve_clk.common.hw,
837 [CLK_CODEC] = &codec_clk.common.hw,
838 [CLK_AVS] = &avs_clk.common.hw,
839 [CLK_GPU] = &gpu_clk.common.hw,
840 [CLK_MBUS] = &mbus_clk.common.hw,
841 [CLK_IEP] = &iep_clk.common.hw,
846 static const struct sunxi_ccu_desc sun5i_a13_ccu_desc = {
847 .ccu_clks = sun5i_a10s_ccu_clks,
848 .num_ccu_clks = ARRAY_SIZE(sun5i_a10s_ccu_clks),
850 .hw_clks = &sun5i_a13_hw_clks,
852 .resets = sun5i_a10s_ccu_resets,
853 .num_resets = ARRAY_SIZE(sun5i_a10s_ccu_resets),
857 * The GR8 is the A10s CCU minus the HDMI and keypad, plus SPDIF
859 static struct clk_hw_onecell_data sun5i_gr8_hw_clks = {
861 [CLK_HOSC] = &hosc_clk.common.hw,
862 [CLK_PLL_CORE] = &pll_core_clk.common.hw,
863 [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw,
864 [CLK_PLL_AUDIO] = &pll_audio_clk.hw,
865 [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw,
866 [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw,
867 [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw,
868 [CLK_PLL_VIDEO0] = &pll_video0_clk.common.hw,
869 [CLK_PLL_VIDEO0_2X] = &pll_video0_2x_clk.hw,
870 [CLK_PLL_VE] = &pll_ve_clk.common.hw,
871 [CLK_PLL_DDR_BASE] = &pll_ddr_base_clk.common.hw,
872 [CLK_PLL_DDR] = &pll_ddr_clk.common.hw,
873 [CLK_PLL_DDR_OTHER] = &pll_ddr_other_clk.common.hw,
874 [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw,
875 [CLK_PLL_VIDEO1] = &pll_video1_clk.common.hw,
876 [CLK_PLL_VIDEO1_2X] = &pll_video1_2x_clk.hw,
877 [CLK_CPU] = &cpu_clk.common.hw,
878 [CLK_AXI] = &axi_clk.common.hw,
879 [CLK_AHB] = &ahb_clk.common.hw,
880 [CLK_APB0] = &apb0_clk.common.hw,
881 [CLK_APB1] = &apb1_clk.common.hw,
882 [CLK_DRAM_AXI] = &axi_dram_clk.common.hw,
883 [CLK_AHB_OTG] = &ahb_otg_clk.common.hw,
884 [CLK_AHB_EHCI] = &ahb_ehci_clk.common.hw,
885 [CLK_AHB_OHCI] = &ahb_ohci_clk.common.hw,
886 [CLK_AHB_SS] = &ahb_ss_clk.common.hw,
887 [CLK_AHB_DMA] = &ahb_dma_clk.common.hw,
888 [CLK_AHB_BIST] = &ahb_bist_clk.common.hw,
889 [CLK_AHB_MMC0] = &ahb_mmc0_clk.common.hw,
890 [CLK_AHB_MMC1] = &ahb_mmc1_clk.common.hw,
891 [CLK_AHB_MMC2] = &ahb_mmc2_clk.common.hw,
892 [CLK_AHB_NAND] = &ahb_nand_clk.common.hw,
893 [CLK_AHB_SDRAM] = &ahb_sdram_clk.common.hw,
894 [CLK_AHB_EMAC] = &ahb_emac_clk.common.hw,
895 [CLK_AHB_TS] = &ahb_ts_clk.common.hw,
896 [CLK_AHB_SPI0] = &ahb_spi0_clk.common.hw,
897 [CLK_AHB_SPI1] = &ahb_spi1_clk.common.hw,
898 [CLK_AHB_SPI2] = &ahb_spi2_clk.common.hw,
899 [CLK_AHB_GPS] = &ahb_gps_clk.common.hw,
900 [CLK_AHB_HSTIMER] = &ahb_hstimer_clk.common.hw,
901 [CLK_AHB_VE] = &ahb_ve_clk.common.hw,
902 [CLK_AHB_TVE] = &ahb_tve_clk.common.hw,
903 [CLK_AHB_LCD] = &ahb_lcd_clk.common.hw,
904 [CLK_AHB_CSI] = &ahb_csi_clk.common.hw,
905 [CLK_AHB_DE_BE] = &ahb_de_be_clk.common.hw,
906 [CLK_AHB_DE_FE] = &ahb_de_fe_clk.common.hw,
907 [CLK_AHB_IEP] = &ahb_iep_clk.common.hw,
908 [CLK_AHB_GPU] = &ahb_gpu_clk.common.hw,
909 [CLK_APB0_CODEC] = &apb0_codec_clk.common.hw,
910 [CLK_APB0_SPDIF] = &apb0_spdif_clk.common.hw,
911 [CLK_APB0_I2S] = &apb0_i2s_clk.common.hw,
912 [CLK_APB0_PIO] = &apb0_pio_clk.common.hw,
913 [CLK_APB0_IR] = &apb0_ir_clk.common.hw,
914 [CLK_APB1_I2C0] = &apb1_i2c0_clk.common.hw,
915 [CLK_APB1_I2C1] = &apb1_i2c1_clk.common.hw,
916 [CLK_APB1_I2C2] = &apb1_i2c2_clk.common.hw,
917 [CLK_APB1_UART0] = &apb1_uart0_clk.common.hw,
918 [CLK_APB1_UART1] = &apb1_uart1_clk.common.hw,
919 [CLK_APB1_UART2] = &apb1_uart2_clk.common.hw,
920 [CLK_APB1_UART3] = &apb1_uart3_clk.common.hw,
921 [CLK_NAND] = &nand_clk.common.hw,
922 [CLK_MMC0] = &mmc0_clk.common.hw,
923 [CLK_MMC1] = &mmc1_clk.common.hw,
924 [CLK_MMC2] = &mmc2_clk.common.hw,
925 [CLK_TS] = &ts_clk.common.hw,
926 [CLK_SS] = &ss_clk.common.hw,
927 [CLK_SPI0] = &spi0_clk.common.hw,
928 [CLK_SPI1] = &spi1_clk.common.hw,
929 [CLK_SPI2] = &spi2_clk.common.hw,
930 [CLK_IR] = &ir_clk.common.hw,
931 [CLK_I2S] = &i2s_clk.common.hw,
932 [CLK_SPDIF] = &spdif_clk.common.hw,
933 [CLK_USB_OHCI] = &usb_ohci_clk.common.hw,
934 [CLK_USB_PHY0] = &usb_phy0_clk.common.hw,
935 [CLK_USB_PHY1] = &usb_phy1_clk.common.hw,
936 [CLK_GPS] = &gps_clk.common.hw,
937 [CLK_DRAM_VE] = &dram_ve_clk.common.hw,
938 [CLK_DRAM_CSI] = &dram_csi_clk.common.hw,
939 [CLK_DRAM_TS] = &dram_ts_clk.common.hw,
940 [CLK_DRAM_TVE] = &dram_tve_clk.common.hw,
941 [CLK_DRAM_DE_FE] = &dram_de_fe_clk.common.hw,
942 [CLK_DRAM_DE_BE] = &dram_de_be_clk.common.hw,
943 [CLK_DRAM_ACE] = &dram_ace_clk.common.hw,
944 [CLK_DRAM_IEP] = &dram_iep_clk.common.hw,
945 [CLK_DE_BE] = &de_be_clk.common.hw,
946 [CLK_DE_FE] = &de_fe_clk.common.hw,
947 [CLK_TCON_CH0] = &tcon_ch0_clk.common.hw,
948 [CLK_TCON_CH1_SCLK] = &tcon_ch1_sclk2_clk.common.hw,
949 [CLK_TCON_CH1] = &tcon_ch1_sclk1_clk.common.hw,
950 [CLK_CSI] = &csi_clk.common.hw,
951 [CLK_VE] = &ve_clk.common.hw,
952 [CLK_CODEC] = &codec_clk.common.hw,
953 [CLK_AVS] = &avs_clk.common.hw,
954 [CLK_GPU] = &gpu_clk.common.hw,
955 [CLK_MBUS] = &mbus_clk.common.hw,
956 [CLK_IEP] = &iep_clk.common.hw,
961 static const struct sunxi_ccu_desc sun5i_gr8_ccu_desc = {
962 .ccu_clks = sun5i_a10s_ccu_clks,
963 .num_ccu_clks = ARRAY_SIZE(sun5i_a10s_ccu_clks),
965 .hw_clks = &sun5i_gr8_hw_clks,
967 .resets = sun5i_a10s_ccu_resets,
968 .num_resets = ARRAY_SIZE(sun5i_a10s_ccu_resets),
971 static void __init sun5i_ccu_init(struct device_node *node,
972 const struct sunxi_ccu_desc *desc)
977 reg = of_io_request_and_map(node, 0, of_node_full_name(node));
979 pr_err("%s: Could not map the clock registers\n",
980 of_node_full_name(node));
984 /* Force the PLL-Audio-1x divider to 4 */
985 val = readl(reg + SUN5I_PLL_AUDIO_REG);
986 val &= ~GENMASK(19, 16);
987 writel(val | (3 << 16), reg + SUN5I_PLL_AUDIO_REG);
990 * Use the peripheral PLL as the AHB parent, instead of CPU /
991 * AXI which have rate changes due to cpufreq.
993 * This is especially a big deal for the HS timer whose parent
996 val = readl(reg + SUN5I_AHB_REG);
997 val &= ~GENMASK(7, 6);
998 writel(val | (2 << 6), reg + SUN5I_AHB_REG);
1000 sunxi_ccu_probe(node, reg, desc);
1003 static void __init sun5i_a10s_ccu_setup(struct device_node *node)
1005 sun5i_ccu_init(node, &sun5i_a10s_ccu_desc);
1007 CLK_OF_DECLARE(sun5i_a10s_ccu, "allwinner,sun5i-a10s-ccu",
1008 sun5i_a10s_ccu_setup);
1010 static void __init sun5i_a13_ccu_setup(struct device_node *node)
1012 sun5i_ccu_init(node, &sun5i_a13_ccu_desc);
1014 CLK_OF_DECLARE(sun5i_a13_ccu, "allwinner,sun5i-a13-ccu",
1015 sun5i_a13_ccu_setup);
1017 static void __init sun5i_gr8_ccu_setup(struct device_node *node)
1019 sun5i_ccu_init(node, &sun5i_gr8_ccu_desc);
1021 CLK_OF_DECLARE(sun5i_gr8_ccu, "nextthing,gr8-ccu",
1022 sun5i_gr8_ccu_setup);