162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.io> 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/clk-provider.h> 862306a36Sopenharmony_ci#include <linux/io.h> 962306a36Sopenharmony_ci#include <linux/module.h> 1062306a36Sopenharmony_ci#include <linux/platform_device.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include "ccu_common.h" 1362306a36Sopenharmony_ci#include "ccu_reset.h" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include "ccu_div.h" 1662306a36Sopenharmony_ci#include "ccu_gate.h" 1762306a36Sopenharmony_ci#include "ccu_mp.h" 1862306a36Sopenharmony_ci#include "ccu_mult.h" 1962306a36Sopenharmony_ci#include "ccu_nk.h" 2062306a36Sopenharmony_ci#include "ccu_nkm.h" 2162306a36Sopenharmony_ci#include "ccu_nkmp.h" 2262306a36Sopenharmony_ci#include "ccu_nm.h" 2362306a36Sopenharmony_ci#include "ccu_phase.h" 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#include "ccu-suniv-f1c100s.h" 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_cistatic struct ccu_nkmp pll_cpu_clk = { 2862306a36Sopenharmony_ci .enable = BIT(31), 2962306a36Sopenharmony_ci .lock = BIT(28), 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci .n = _SUNXI_CCU_MULT(8, 5), 3262306a36Sopenharmony_ci .k = _SUNXI_CCU_MULT(4, 2), 3362306a36Sopenharmony_ci .m = _SUNXI_CCU_DIV(0, 2), 3462306a36Sopenharmony_ci /* MAX is guessed by the BSP table */ 3562306a36Sopenharmony_ci .p = _SUNXI_CCU_DIV_MAX(16, 2, 4), 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci .common = { 3862306a36Sopenharmony_ci .reg = 0x000, 3962306a36Sopenharmony_ci .hw.init = CLK_HW_INIT("pll-cpu", "osc24M", 4062306a36Sopenharmony_ci &ccu_nkmp_ops, 4162306a36Sopenharmony_ci CLK_SET_RATE_UNGATE), 4262306a36Sopenharmony_ci }, 4362306a36Sopenharmony_ci}; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/* 4662306a36Sopenharmony_ci * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from 4762306a36Sopenharmony_ci * the base (2x, 4x and 8x), and one variable divider (the one true 4862306a36Sopenharmony_ci * pll audio). 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * We don't have any need for the variable divider for now, so we just 5162306a36Sopenharmony_ci * hardcode it to match with the clock names 5262306a36Sopenharmony_ci */ 5362306a36Sopenharmony_ci#define SUNIV_PLL_AUDIO_REG 0x008 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_cistatic SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", 5662306a36Sopenharmony_ci "osc24M", 0x008, 5762306a36Sopenharmony_ci 8, 7, /* N */ 5862306a36Sopenharmony_ci 0, 5, /* M */ 5962306a36Sopenharmony_ci BIT(31), /* gate */ 6062306a36Sopenharmony_ci BIT(28), /* lock */ 6162306a36Sopenharmony_ci CLK_SET_RATE_UNGATE); 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video", 6462306a36Sopenharmony_ci "osc24M", 0x010, 6562306a36Sopenharmony_ci 8, 7, /* N */ 6662306a36Sopenharmony_ci 0, 4, /* M */ 6762306a36Sopenharmony_ci BIT(24), /* frac enable */ 6862306a36Sopenharmony_ci BIT(25), /* frac select */ 6962306a36Sopenharmony_ci 270000000, /* frac rate 0 */ 7062306a36Sopenharmony_ci 297000000, /* frac rate 1 */ 7162306a36Sopenharmony_ci BIT(31), /* gate */ 7262306a36Sopenharmony_ci BIT(28), /* lock */ 7362306a36Sopenharmony_ci CLK_SET_RATE_UNGATE); 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", 7662306a36Sopenharmony_ci "osc24M", 0x018, 7762306a36Sopenharmony_ci 8, 7, /* N */ 7862306a36Sopenharmony_ci 0, 4, /* M */ 7962306a36Sopenharmony_ci BIT(24), /* frac enable */ 8062306a36Sopenharmony_ci BIT(25), /* frac select */ 8162306a36Sopenharmony_ci 270000000, /* frac rate 0 */ 8262306a36Sopenharmony_ci 297000000, /* frac rate 1 */ 8362306a36Sopenharmony_ci BIT(31), /* gate */ 8462306a36Sopenharmony_ci BIT(28), /* lock */ 8562306a36Sopenharmony_ci CLK_SET_RATE_UNGATE); 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cistatic SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr", 8862306a36Sopenharmony_ci "osc24M", 0x020, 8962306a36Sopenharmony_ci 8, 5, /* N */ 9062306a36Sopenharmony_ci 4, 2, /* K */ 9162306a36Sopenharmony_ci 0, 2, /* M */ 9262306a36Sopenharmony_ci BIT(31), /* gate */ 9362306a36Sopenharmony_ci BIT(28), /* lock */ 9462306a36Sopenharmony_ci CLK_IS_CRITICAL); 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_cistatic struct ccu_nk pll_periph_clk = { 9762306a36Sopenharmony_ci .enable = BIT(31), 9862306a36Sopenharmony_ci .lock = BIT(28), 9962306a36Sopenharmony_ci .k = _SUNXI_CCU_MULT(4, 2), 10062306a36Sopenharmony_ci .n = _SUNXI_CCU_MULT(8, 5), 10162306a36Sopenharmony_ci .common = { 10262306a36Sopenharmony_ci .reg = 0x028, 10362306a36Sopenharmony_ci .hw.init = CLK_HW_INIT("pll-periph", "osc24M", 10462306a36Sopenharmony_ci &ccu_nk_ops, 0), 10562306a36Sopenharmony_ci }, 10662306a36Sopenharmony_ci}; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_cistatic const char * const cpu_parents[] = { "osc32k", "osc24M", 10962306a36Sopenharmony_ci "pll-cpu", "pll-cpu" }; 11062306a36Sopenharmony_cistatic SUNXI_CCU_MUX(cpu_clk, "cpu", cpu_parents, 11162306a36Sopenharmony_ci 0x050, 16, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT); 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistatic const char * const ahb_parents[] = { "osc32k", "osc24M", 11462306a36Sopenharmony_ci "cpu", "pll-periph" }; 11562306a36Sopenharmony_cistatic const struct ccu_mux_var_prediv ahb_predivs[] = { 11662306a36Sopenharmony_ci { .index = 3, .shift = 6, .width = 2 }, 11762306a36Sopenharmony_ci}; 11862306a36Sopenharmony_cistatic struct ccu_div ahb_clk = { 11962306a36Sopenharmony_ci .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO), 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci .mux = { 12262306a36Sopenharmony_ci .shift = 12, 12362306a36Sopenharmony_ci .width = 2, 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci .var_predivs = ahb_predivs, 12662306a36Sopenharmony_ci .n_var_predivs = ARRAY_SIZE(ahb_predivs), 12762306a36Sopenharmony_ci }, 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci .common = { 13062306a36Sopenharmony_ci .reg = 0x054, 13162306a36Sopenharmony_ci .features = CCU_FEATURE_VARIABLE_PREDIV, 13262306a36Sopenharmony_ci .hw.init = CLK_HW_INIT_PARENTS("ahb", 13362306a36Sopenharmony_ci ahb_parents, 13462306a36Sopenharmony_ci &ccu_div_ops, 13562306a36Sopenharmony_ci 0), 13662306a36Sopenharmony_ci }, 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_cistatic struct clk_div_table apb_div_table[] = { 14062306a36Sopenharmony_ci { .val = 0, .div = 2 }, 14162306a36Sopenharmony_ci { .val = 1, .div = 2 }, 14262306a36Sopenharmony_ci { .val = 2, .div = 4 }, 14362306a36Sopenharmony_ci { .val = 3, .div = 8 }, 14462306a36Sopenharmony_ci { /* Sentinel */ }, 14562306a36Sopenharmony_ci}; 14662306a36Sopenharmony_cistatic SUNXI_CCU_DIV_TABLE(apb_clk, "apb", "ahb", 14762306a36Sopenharmony_ci 0x054, 8, 2, apb_div_table, 0); 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb", 15062306a36Sopenharmony_ci 0x060, BIT(6), 0); 15162306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb", 15262306a36Sopenharmony_ci 0x060, BIT(8), 0); 15362306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb", 15462306a36Sopenharmony_ci 0x060, BIT(9), 0); 15562306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb", 15662306a36Sopenharmony_ci 0x060, BIT(14), 0); 15762306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb", 15862306a36Sopenharmony_ci 0x060, BIT(20), 0); 15962306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_spi1_clk, "bus-spi1", "ahb", 16062306a36Sopenharmony_ci 0x060, BIT(21), 0); 16162306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb", 16262306a36Sopenharmony_ci 0x060, BIT(24), 0); 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb", 16562306a36Sopenharmony_ci 0x064, BIT(0), 0); 16662306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_lcd_clk, "bus-lcd", "ahb", 16762306a36Sopenharmony_ci 0x064, BIT(4), 0); 16862306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_deinterlace_clk, "bus-deinterlace", "ahb", 16962306a36Sopenharmony_ci 0x064, BIT(5), 0); 17062306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb", 17162306a36Sopenharmony_ci 0x064, BIT(8), 0); 17262306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_tvd_clk, "bus-tvd", "ahb", 17362306a36Sopenharmony_ci 0x064, BIT(9), 0); 17462306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_tve_clk, "bus-tve", "ahb", 17562306a36Sopenharmony_ci 0x064, BIT(10), 0); 17662306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_de_be_clk, "bus-de-be", "ahb", 17762306a36Sopenharmony_ci 0x064, BIT(12), 0); 17862306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_de_fe_clk, "bus-de-fe", "ahb", 17962306a36Sopenharmony_ci 0x064, BIT(14), 0); 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb", 18262306a36Sopenharmony_ci 0x068, BIT(0), 0); 18362306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_spdif_clk, "bus-spdif", "apb", 18462306a36Sopenharmony_ci 0x068, BIT(1), 0); 18562306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_ir_clk, "bus-ir", "apb", 18662306a36Sopenharmony_ci 0x068, BIT(2), 0); 18762306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_rsb_clk, "bus-rsb", "apb", 18862306a36Sopenharmony_ci 0x068, BIT(3), 0); 18962306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb", 19062306a36Sopenharmony_ci 0x068, BIT(12), 0); 19162306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb", 19262306a36Sopenharmony_ci 0x068, BIT(16), 0); 19362306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb", 19462306a36Sopenharmony_ci 0x068, BIT(17), 0); 19562306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2c2_clk, "bus-i2c2", "apb", 19662306a36Sopenharmony_ci 0x068, BIT(18), 0); 19762306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb", 19862306a36Sopenharmony_ci 0x068, BIT(19), 0); 19962306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb", 20062306a36Sopenharmony_ci 0x068, BIT(20), 0); 20162306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb", 20262306a36Sopenharmony_ci 0x068, BIT(21), 0); 20362306a36Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb", 20462306a36Sopenharmony_ci 0x068, BIT(22), 0); 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_cistatic const char * const mod0_default_parents[] = { "osc24M", "pll-periph" }; 20762306a36Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088, 20862306a36Sopenharmony_ci 0, 4, /* M */ 20962306a36Sopenharmony_ci 16, 2, /* P */ 21062306a36Sopenharmony_ci 24, 2, /* mux */ 21162306a36Sopenharmony_ci BIT(31), /* gate */ 21262306a36Sopenharmony_ci 0); 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0", 21562306a36Sopenharmony_ci 0x088, 20, 3, 0); 21662306a36Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0", 21762306a36Sopenharmony_ci 0x088, 8, 3, 0); 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c, 22062306a36Sopenharmony_ci 0, 4, /* M */ 22162306a36Sopenharmony_ci 16, 2, /* P */ 22262306a36Sopenharmony_ci 24, 2, /* mux */ 22362306a36Sopenharmony_ci BIT(31), /* gate */ 22462306a36Sopenharmony_ci 0); 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1", 22762306a36Sopenharmony_ci 0x08c, 20, 3, 0); 22862306a36Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1", 22962306a36Sopenharmony_ci 0x08c, 8, 3, 0); 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cistatic const char * const i2s_spdif_parents[] = { "pll-audio-8x", 23262306a36Sopenharmony_ci "pll-audio-4x", 23362306a36Sopenharmony_ci "pll-audio-2x", 23462306a36Sopenharmony_ci "pll-audio" }; 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_cistatic SUNXI_CCU_MUX_WITH_GATE(i2s_clk, "i2s", i2s_spdif_parents, 23762306a36Sopenharmony_ci 0x0b0, 16, 2, BIT(31), 0); 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_cistatic SUNXI_CCU_MUX_WITH_GATE(spdif_clk, "spdif", i2s_spdif_parents, 24062306a36Sopenharmony_ci 0x0b4, 16, 2, BIT(31), 0); 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_cistatic const char * const ir_parents[] = { "osc32k", "osc24M" }; 24362306a36Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(ir_clk, "ir", 24462306a36Sopenharmony_ci ir_parents, 0x0b8, 24562306a36Sopenharmony_ci 0, 4, /* M */ 24662306a36Sopenharmony_ci 16, 2, /* P */ 24762306a36Sopenharmony_ci 24, 2, /* mux */ 24862306a36Sopenharmony_ci BIT(31), /* gate */ 24962306a36Sopenharmony_ci 0); 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_cistatic SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M", 25262306a36Sopenharmony_ci 0x0cc, BIT(1), 0); 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_cistatic SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "pll-ddr", 25562306a36Sopenharmony_ci 0x100, BIT(0), 0); 25662306a36Sopenharmony_cistatic SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "pll-ddr", 25762306a36Sopenharmony_ci 0x100, BIT(1), 0); 25862306a36Sopenharmony_cistatic SUNXI_CCU_GATE(dram_deinterlace_clk, "dram-deinterlace", 25962306a36Sopenharmony_ci "pll-ddr", 0x100, BIT(2), 0); 26062306a36Sopenharmony_cistatic SUNXI_CCU_GATE(dram_tvd_clk, "dram-tvd", "pll-ddr", 26162306a36Sopenharmony_ci 0x100, BIT(3), 0); 26262306a36Sopenharmony_cistatic SUNXI_CCU_GATE(dram_de_fe_clk, "dram-de-fe", "pll-ddr", 26362306a36Sopenharmony_ci 0x100, BIT(24), 0); 26462306a36Sopenharmony_cistatic SUNXI_CCU_GATE(dram_de_be_clk, "dram-de-be", "pll-ddr", 26562306a36Sopenharmony_ci 0x100, BIT(26), 0); 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_cistatic const char * const de_parents[] = { "pll-video", "pll-periph" }; 26862306a36Sopenharmony_cistatic const u8 de_table[] = { 0, 2, }; 26962306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(de_be_clk, "de-be", 27062306a36Sopenharmony_ci de_parents, de_table, 27162306a36Sopenharmony_ci 0x104, 0, 4, 24, 3, BIT(31), 0); 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(de_fe_clk, "de-fe", 27462306a36Sopenharmony_ci de_parents, de_table, 27562306a36Sopenharmony_ci 0x10c, 0, 4, 24, 3, BIT(31), 0); 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_cistatic const char * const tcon_parents[] = { "pll-video", "pll-video-2x" }; 27862306a36Sopenharmony_cistatic const u8 tcon_table[] = { 0, 2, }; 27962306a36Sopenharmony_cistatic SUNXI_CCU_MUX_TABLE_WITH_GATE(tcon_clk, "tcon", 28062306a36Sopenharmony_ci tcon_parents, tcon_table, 28162306a36Sopenharmony_ci 0x118, 24, 3, BIT(31), 28262306a36Sopenharmony_ci CLK_SET_RATE_PARENT); 28362306a36Sopenharmony_ci 28462306a36Sopenharmony_cistatic const char * const deinterlace_parents[] = { "pll-video", 28562306a36Sopenharmony_ci "pll-video-2x" }; 28662306a36Sopenharmony_cistatic const u8 deinterlace_table[] = { 0, 2, }; 28762306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(deinterlace_clk, "deinterlace", 28862306a36Sopenharmony_ci deinterlace_parents, deinterlace_table, 28962306a36Sopenharmony_ci 0x11c, 0, 4, 24, 3, BIT(31), 0); 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_cistatic const char * const tve_clk2_parents[] = { "pll-video", 29262306a36Sopenharmony_ci "pll-video-2x" }; 29362306a36Sopenharmony_cistatic const u8 tve_clk2_table[] = { 0, 2, }; 29462306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(tve_clk2_clk, "tve-clk2", 29562306a36Sopenharmony_ci tve_clk2_parents, tve_clk2_table, 29662306a36Sopenharmony_ci 0x120, 0, 4, 24, 3, BIT(31), 0); 29762306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_GATE(tve_clk1_clk, "tve-clk1", "tve-clk2", 29862306a36Sopenharmony_ci 0x120, 8, 1, BIT(15), 0); 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_cistatic const char * const tvd_parents[] = { "pll-video", "osc24M", 30162306a36Sopenharmony_ci "pll-video-2x" }; 30262306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_GATE(tvd_clk, "tvd", tvd_parents, 30362306a36Sopenharmony_ci 0x124, 0, 4, 24, 3, BIT(31), 0); 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_cistatic const char * const csi_parents[] = { "pll-video", "osc24M" }; 30662306a36Sopenharmony_cistatic const u8 csi_table[] = { 0, 5, }; 30762306a36Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_clk, "csi", csi_parents, csi_table, 30862306a36Sopenharmony_ci 0x120, 0, 4, 8, 3, BIT(15), 0); 30962306a36Sopenharmony_ci 31062306a36Sopenharmony_ci/* 31162306a36Sopenharmony_ci * TODO: BSP says the parent is pll-audio, however common sense and experience 31262306a36Sopenharmony_ci * told us it should be pll-ve. pll-ve is totally not used in BSP code. 31362306a36Sopenharmony_ci */ 31462306a36Sopenharmony_cistatic SUNXI_CCU_GATE(ve_clk, "ve", "pll-audio", 0x13c, BIT(31), 0); 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_cistatic SUNXI_CCU_GATE(codec_clk, "codec", "pll-audio", 0x140, BIT(31), 0); 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_cistatic SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x144, BIT(31), 0); 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_cistatic struct ccu_common *suniv_ccu_clks[] = { 32162306a36Sopenharmony_ci &pll_cpu_clk.common, 32262306a36Sopenharmony_ci &pll_audio_base_clk.common, 32362306a36Sopenharmony_ci &pll_video_clk.common, 32462306a36Sopenharmony_ci &pll_ve_clk.common, 32562306a36Sopenharmony_ci &pll_ddr0_clk.common, 32662306a36Sopenharmony_ci &pll_periph_clk.common, 32762306a36Sopenharmony_ci &cpu_clk.common, 32862306a36Sopenharmony_ci &ahb_clk.common, 32962306a36Sopenharmony_ci &apb_clk.common, 33062306a36Sopenharmony_ci &bus_dma_clk.common, 33162306a36Sopenharmony_ci &bus_mmc0_clk.common, 33262306a36Sopenharmony_ci &bus_mmc1_clk.common, 33362306a36Sopenharmony_ci &bus_dram_clk.common, 33462306a36Sopenharmony_ci &bus_spi0_clk.common, 33562306a36Sopenharmony_ci &bus_spi1_clk.common, 33662306a36Sopenharmony_ci &bus_otg_clk.common, 33762306a36Sopenharmony_ci &bus_ve_clk.common, 33862306a36Sopenharmony_ci &bus_lcd_clk.common, 33962306a36Sopenharmony_ci &bus_deinterlace_clk.common, 34062306a36Sopenharmony_ci &bus_csi_clk.common, 34162306a36Sopenharmony_ci &bus_tve_clk.common, 34262306a36Sopenharmony_ci &bus_tvd_clk.common, 34362306a36Sopenharmony_ci &bus_de_be_clk.common, 34462306a36Sopenharmony_ci &bus_de_fe_clk.common, 34562306a36Sopenharmony_ci &bus_codec_clk.common, 34662306a36Sopenharmony_ci &bus_spdif_clk.common, 34762306a36Sopenharmony_ci &bus_ir_clk.common, 34862306a36Sopenharmony_ci &bus_rsb_clk.common, 34962306a36Sopenharmony_ci &bus_i2s0_clk.common, 35062306a36Sopenharmony_ci &bus_i2c0_clk.common, 35162306a36Sopenharmony_ci &bus_i2c1_clk.common, 35262306a36Sopenharmony_ci &bus_i2c2_clk.common, 35362306a36Sopenharmony_ci &bus_pio_clk.common, 35462306a36Sopenharmony_ci &bus_uart0_clk.common, 35562306a36Sopenharmony_ci &bus_uart1_clk.common, 35662306a36Sopenharmony_ci &bus_uart2_clk.common, 35762306a36Sopenharmony_ci &mmc0_clk.common, 35862306a36Sopenharmony_ci &mmc0_sample_clk.common, 35962306a36Sopenharmony_ci &mmc0_output_clk.common, 36062306a36Sopenharmony_ci &mmc1_clk.common, 36162306a36Sopenharmony_ci &mmc1_sample_clk.common, 36262306a36Sopenharmony_ci &mmc1_output_clk.common, 36362306a36Sopenharmony_ci &i2s_clk.common, 36462306a36Sopenharmony_ci &spdif_clk.common, 36562306a36Sopenharmony_ci &ir_clk.common, 36662306a36Sopenharmony_ci &usb_phy0_clk.common, 36762306a36Sopenharmony_ci &dram_ve_clk.common, 36862306a36Sopenharmony_ci &dram_csi_clk.common, 36962306a36Sopenharmony_ci &dram_deinterlace_clk.common, 37062306a36Sopenharmony_ci &dram_tvd_clk.common, 37162306a36Sopenharmony_ci &dram_de_fe_clk.common, 37262306a36Sopenharmony_ci &dram_de_be_clk.common, 37362306a36Sopenharmony_ci &de_be_clk.common, 37462306a36Sopenharmony_ci &de_fe_clk.common, 37562306a36Sopenharmony_ci &tcon_clk.common, 37662306a36Sopenharmony_ci &deinterlace_clk.common, 37762306a36Sopenharmony_ci &tve_clk2_clk.common, 37862306a36Sopenharmony_ci &tve_clk1_clk.common, 37962306a36Sopenharmony_ci &tvd_clk.common, 38062306a36Sopenharmony_ci &csi_clk.common, 38162306a36Sopenharmony_ci &ve_clk.common, 38262306a36Sopenharmony_ci &codec_clk.common, 38362306a36Sopenharmony_ci &avs_clk.common, 38462306a36Sopenharmony_ci}; 38562306a36Sopenharmony_ci 38662306a36Sopenharmony_cistatic const struct clk_hw *clk_parent_pll_audio[] = { 38762306a36Sopenharmony_ci &pll_audio_base_clk.common.hw 38862306a36Sopenharmony_ci}; 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio", 39162306a36Sopenharmony_ci clk_parent_pll_audio, 39262306a36Sopenharmony_ci 4, 1, CLK_SET_RATE_PARENT); 39362306a36Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x", 39462306a36Sopenharmony_ci clk_parent_pll_audio, 39562306a36Sopenharmony_ci 2, 1, CLK_SET_RATE_PARENT); 39662306a36Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x", 39762306a36Sopenharmony_ci clk_parent_pll_audio, 39862306a36Sopenharmony_ci 1, 1, CLK_SET_RATE_PARENT); 39962306a36Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x", 40062306a36Sopenharmony_ci clk_parent_pll_audio, 40162306a36Sopenharmony_ci 1, 2, CLK_SET_RATE_PARENT); 40262306a36Sopenharmony_cistatic CLK_FIXED_FACTOR_HW(pll_video_2x_clk, "pll-video-2x", 40362306a36Sopenharmony_ci &pll_video_clk.common.hw, 40462306a36Sopenharmony_ci 1, 2, 0); 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_cistatic struct clk_hw_onecell_data suniv_hw_clks = { 40762306a36Sopenharmony_ci .hws = { 40862306a36Sopenharmony_ci [CLK_PLL_CPU] = &pll_cpu_clk.common.hw, 40962306a36Sopenharmony_ci [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw, 41062306a36Sopenharmony_ci [CLK_PLL_AUDIO] = &pll_audio_clk.hw, 41162306a36Sopenharmony_ci [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw, 41262306a36Sopenharmony_ci [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw, 41362306a36Sopenharmony_ci [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw, 41462306a36Sopenharmony_ci [CLK_PLL_VIDEO] = &pll_video_clk.common.hw, 41562306a36Sopenharmony_ci [CLK_PLL_VIDEO_2X] = &pll_video_2x_clk.hw, 41662306a36Sopenharmony_ci [CLK_PLL_VE] = &pll_ve_clk.common.hw, 41762306a36Sopenharmony_ci [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw, 41862306a36Sopenharmony_ci [CLK_PLL_PERIPH] = &pll_periph_clk.common.hw, 41962306a36Sopenharmony_ci [CLK_CPU] = &cpu_clk.common.hw, 42062306a36Sopenharmony_ci [CLK_AHB] = &ahb_clk.common.hw, 42162306a36Sopenharmony_ci [CLK_APB] = &apb_clk.common.hw, 42262306a36Sopenharmony_ci [CLK_BUS_DMA] = &bus_dma_clk.common.hw, 42362306a36Sopenharmony_ci [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw, 42462306a36Sopenharmony_ci [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw, 42562306a36Sopenharmony_ci [CLK_BUS_DRAM] = &bus_dram_clk.common.hw, 42662306a36Sopenharmony_ci [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw, 42762306a36Sopenharmony_ci [CLK_BUS_SPI1] = &bus_spi1_clk.common.hw, 42862306a36Sopenharmony_ci [CLK_BUS_OTG] = &bus_otg_clk.common.hw, 42962306a36Sopenharmony_ci [CLK_BUS_VE] = &bus_ve_clk.common.hw, 43062306a36Sopenharmony_ci [CLK_BUS_LCD] = &bus_lcd_clk.common.hw, 43162306a36Sopenharmony_ci [CLK_BUS_DEINTERLACE] = &bus_deinterlace_clk.common.hw, 43262306a36Sopenharmony_ci [CLK_BUS_CSI] = &bus_csi_clk.common.hw, 43362306a36Sopenharmony_ci [CLK_BUS_TVD] = &bus_tvd_clk.common.hw, 43462306a36Sopenharmony_ci [CLK_BUS_TVE] = &bus_tve_clk.common.hw, 43562306a36Sopenharmony_ci [CLK_BUS_DE_BE] = &bus_de_be_clk.common.hw, 43662306a36Sopenharmony_ci [CLK_BUS_DE_FE] = &bus_de_fe_clk.common.hw, 43762306a36Sopenharmony_ci [CLK_BUS_CODEC] = &bus_codec_clk.common.hw, 43862306a36Sopenharmony_ci [CLK_BUS_SPDIF] = &bus_spdif_clk.common.hw, 43962306a36Sopenharmony_ci [CLK_BUS_IR] = &bus_ir_clk.common.hw, 44062306a36Sopenharmony_ci [CLK_BUS_RSB] = &bus_rsb_clk.common.hw, 44162306a36Sopenharmony_ci [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw, 44262306a36Sopenharmony_ci [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw, 44362306a36Sopenharmony_ci [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw, 44462306a36Sopenharmony_ci [CLK_BUS_I2C2] = &bus_i2c2_clk.common.hw, 44562306a36Sopenharmony_ci [CLK_BUS_PIO] = &bus_pio_clk.common.hw, 44662306a36Sopenharmony_ci [CLK_BUS_UART0] = &bus_uart0_clk.common.hw, 44762306a36Sopenharmony_ci [CLK_BUS_UART1] = &bus_uart1_clk.common.hw, 44862306a36Sopenharmony_ci [CLK_BUS_UART2] = &bus_uart2_clk.common.hw, 44962306a36Sopenharmony_ci [CLK_MMC0] = &mmc0_clk.common.hw, 45062306a36Sopenharmony_ci [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw, 45162306a36Sopenharmony_ci [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw, 45262306a36Sopenharmony_ci [CLK_MMC1] = &mmc1_clk.common.hw, 45362306a36Sopenharmony_ci [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw, 45462306a36Sopenharmony_ci [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw, 45562306a36Sopenharmony_ci [CLK_I2S] = &i2s_clk.common.hw, 45662306a36Sopenharmony_ci [CLK_SPDIF] = &spdif_clk.common.hw, 45762306a36Sopenharmony_ci [CLK_IR] = &ir_clk.common.hw, 45862306a36Sopenharmony_ci [CLK_USB_PHY0] = &usb_phy0_clk.common.hw, 45962306a36Sopenharmony_ci [CLK_DRAM_VE] = &dram_ve_clk.common.hw, 46062306a36Sopenharmony_ci [CLK_DRAM_CSI] = &dram_csi_clk.common.hw, 46162306a36Sopenharmony_ci [CLK_DRAM_DEINTERLACE] = &dram_deinterlace_clk.common.hw, 46262306a36Sopenharmony_ci [CLK_DRAM_TVD] = &dram_tvd_clk.common.hw, 46362306a36Sopenharmony_ci [CLK_DRAM_DE_FE] = &dram_de_fe_clk.common.hw, 46462306a36Sopenharmony_ci [CLK_DRAM_DE_BE] = &dram_de_be_clk.common.hw, 46562306a36Sopenharmony_ci [CLK_DE_BE] = &de_be_clk.common.hw, 46662306a36Sopenharmony_ci [CLK_DE_FE] = &de_fe_clk.common.hw, 46762306a36Sopenharmony_ci [CLK_TCON] = &tcon_clk.common.hw, 46862306a36Sopenharmony_ci [CLK_DEINTERLACE] = &deinterlace_clk.common.hw, 46962306a36Sopenharmony_ci [CLK_TVE2_CLK] = &tve_clk2_clk.common.hw, 47062306a36Sopenharmony_ci [CLK_TVE1_CLK] = &tve_clk1_clk.common.hw, 47162306a36Sopenharmony_ci [CLK_TVD] = &tvd_clk.common.hw, 47262306a36Sopenharmony_ci [CLK_CSI] = &csi_clk.common.hw, 47362306a36Sopenharmony_ci [CLK_VE] = &ve_clk.common.hw, 47462306a36Sopenharmony_ci [CLK_CODEC] = &codec_clk.common.hw, 47562306a36Sopenharmony_ci [CLK_AVS] = &avs_clk.common.hw, 47662306a36Sopenharmony_ci }, 47762306a36Sopenharmony_ci .num = CLK_NUMBER, 47862306a36Sopenharmony_ci}; 47962306a36Sopenharmony_ci 48062306a36Sopenharmony_cistatic struct ccu_reset_map suniv_ccu_resets[] = { 48162306a36Sopenharmony_ci [RST_USB_PHY0] = { 0x0cc, BIT(0) }, 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_ci [RST_BUS_DMA] = { 0x2c0, BIT(6) }, 48462306a36Sopenharmony_ci [RST_BUS_MMC0] = { 0x2c0, BIT(8) }, 48562306a36Sopenharmony_ci [RST_BUS_MMC1] = { 0x2c0, BIT(9) }, 48662306a36Sopenharmony_ci [RST_BUS_DRAM] = { 0x2c0, BIT(14) }, 48762306a36Sopenharmony_ci [RST_BUS_SPI0] = { 0x2c0, BIT(20) }, 48862306a36Sopenharmony_ci [RST_BUS_SPI1] = { 0x2c0, BIT(21) }, 48962306a36Sopenharmony_ci [RST_BUS_OTG] = { 0x2c0, BIT(24) }, 49062306a36Sopenharmony_ci [RST_BUS_VE] = { 0x2c4, BIT(0) }, 49162306a36Sopenharmony_ci [RST_BUS_LCD] = { 0x2c4, BIT(4) }, 49262306a36Sopenharmony_ci [RST_BUS_DEINTERLACE] = { 0x2c4, BIT(5) }, 49362306a36Sopenharmony_ci [RST_BUS_CSI] = { 0x2c4, BIT(8) }, 49462306a36Sopenharmony_ci [RST_BUS_TVD] = { 0x2c4, BIT(9) }, 49562306a36Sopenharmony_ci [RST_BUS_TVE] = { 0x2c4, BIT(10) }, 49662306a36Sopenharmony_ci [RST_BUS_DE_BE] = { 0x2c4, BIT(12) }, 49762306a36Sopenharmony_ci [RST_BUS_DE_FE] = { 0x2c4, BIT(14) }, 49862306a36Sopenharmony_ci [RST_BUS_CODEC] = { 0x2d0, BIT(0) }, 49962306a36Sopenharmony_ci [RST_BUS_SPDIF] = { 0x2d0, BIT(1) }, 50062306a36Sopenharmony_ci [RST_BUS_IR] = { 0x2d0, BIT(2) }, 50162306a36Sopenharmony_ci [RST_BUS_RSB] = { 0x2d0, BIT(3) }, 50262306a36Sopenharmony_ci [RST_BUS_I2S0] = { 0x2d0, BIT(12) }, 50362306a36Sopenharmony_ci [RST_BUS_I2C0] = { 0x2d0, BIT(16) }, 50462306a36Sopenharmony_ci [RST_BUS_I2C1] = { 0x2d0, BIT(17) }, 50562306a36Sopenharmony_ci [RST_BUS_I2C2] = { 0x2d0, BIT(18) }, 50662306a36Sopenharmony_ci [RST_BUS_UART0] = { 0x2d0, BIT(20) }, 50762306a36Sopenharmony_ci [RST_BUS_UART1] = { 0x2d0, BIT(21) }, 50862306a36Sopenharmony_ci [RST_BUS_UART2] = { 0x2d0, BIT(22) }, 50962306a36Sopenharmony_ci}; 51062306a36Sopenharmony_ci 51162306a36Sopenharmony_cistatic const struct sunxi_ccu_desc suniv_ccu_desc = { 51262306a36Sopenharmony_ci .ccu_clks = suniv_ccu_clks, 51362306a36Sopenharmony_ci .num_ccu_clks = ARRAY_SIZE(suniv_ccu_clks), 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci .hw_clks = &suniv_hw_clks, 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ci .resets = suniv_ccu_resets, 51862306a36Sopenharmony_ci .num_resets = ARRAY_SIZE(suniv_ccu_resets), 51962306a36Sopenharmony_ci}; 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_cistatic struct ccu_pll_nb suniv_pll_cpu_nb = { 52262306a36Sopenharmony_ci .common = &pll_cpu_clk.common, 52362306a36Sopenharmony_ci /* copy from pll_cpu_clk */ 52462306a36Sopenharmony_ci .enable = BIT(31), 52562306a36Sopenharmony_ci .lock = BIT(28), 52662306a36Sopenharmony_ci}; 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_cistatic struct ccu_mux_nb suniv_cpu_nb = { 52962306a36Sopenharmony_ci .common = &cpu_clk.common, 53062306a36Sopenharmony_ci .cm = &cpu_clk.mux, 53162306a36Sopenharmony_ci .delay_us = 1, /* > 8 clock cycles at 24 MHz */ 53262306a36Sopenharmony_ci .bypass_index = 1, /* index of 24 MHz oscillator */ 53362306a36Sopenharmony_ci}; 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_cistatic int suniv_f1c100s_ccu_probe(struct platform_device *pdev) 53662306a36Sopenharmony_ci{ 53762306a36Sopenharmony_ci void __iomem *reg; 53862306a36Sopenharmony_ci int ret; 53962306a36Sopenharmony_ci u32 val; 54062306a36Sopenharmony_ci 54162306a36Sopenharmony_ci reg = devm_platform_ioremap_resource(pdev, 0); 54262306a36Sopenharmony_ci if (IS_ERR(reg)) 54362306a36Sopenharmony_ci return PTR_ERR(reg); 54462306a36Sopenharmony_ci 54562306a36Sopenharmony_ci /* Force the PLL-Audio-1x divider to 4 */ 54662306a36Sopenharmony_ci val = readl(reg + SUNIV_PLL_AUDIO_REG); 54762306a36Sopenharmony_ci val &= ~GENMASK(19, 16); 54862306a36Sopenharmony_ci writel(val | (3 << 16), reg + SUNIV_PLL_AUDIO_REG); 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &suniv_ccu_desc); 55162306a36Sopenharmony_ci if (ret) 55262306a36Sopenharmony_ci return ret; 55362306a36Sopenharmony_ci 55462306a36Sopenharmony_ci /* Gate then ungate PLL CPU after any rate changes */ 55562306a36Sopenharmony_ci ccu_pll_notifier_register(&suniv_pll_cpu_nb); 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci /* Reparent CPU during PLL CPU rate changes */ 55862306a36Sopenharmony_ci ccu_mux_notifier_register(pll_cpu_clk.common.hw.clk, 55962306a36Sopenharmony_ci &suniv_cpu_nb); 56062306a36Sopenharmony_ci 56162306a36Sopenharmony_ci return 0; 56262306a36Sopenharmony_ci} 56362306a36Sopenharmony_ci 56462306a36Sopenharmony_cistatic const struct of_device_id suniv_f1c100s_ccu_ids[] = { 56562306a36Sopenharmony_ci { .compatible = "allwinner,suniv-f1c100s-ccu" }, 56662306a36Sopenharmony_ci { } 56762306a36Sopenharmony_ci}; 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_cistatic struct platform_driver suniv_f1c100s_ccu_driver = { 57062306a36Sopenharmony_ci .probe = suniv_f1c100s_ccu_probe, 57162306a36Sopenharmony_ci .driver = { 57262306a36Sopenharmony_ci .name = "suniv-f1c100s-ccu", 57362306a36Sopenharmony_ci .suppress_bind_attrs = true, 57462306a36Sopenharmony_ci .of_match_table = suniv_f1c100s_ccu_ids, 57562306a36Sopenharmony_ci }, 57662306a36Sopenharmony_ci}; 57762306a36Sopenharmony_cimodule_platform_driver(suniv_f1c100s_ccu_driver); 57862306a36Sopenharmony_ci 57962306a36Sopenharmony_ciMODULE_IMPORT_NS(SUNXI_CCU); 58062306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 581