162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2016 MediaTek Inc. 462306a36Sopenharmony_ci * Author: Kevin Chen <kevin-cw.chen@mediatek.com> 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#include <linux/of.h> 862306a36Sopenharmony_ci#include <linux/platform_device.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include "clk-gate.h" 1162306a36Sopenharmony_ci#include "clk-mtk.h" 1262306a36Sopenharmony_ci#include "clk-pll.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#include <dt-bindings/clock/mt6797-clk.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* 1762306a36Sopenharmony_ci * For some clocks, we don't care what their actual rates are. And these 1862306a36Sopenharmony_ci * clocks may change their rate on different products or different scenarios. 1962306a36Sopenharmony_ci * So we model these clocks' rate as 0, to denote it's not an actual rate. 2062306a36Sopenharmony_ci */ 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistatic DEFINE_SPINLOCK(mt6797_clk_lock); 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_cistatic const struct mtk_fixed_factor top_fixed_divs[] = { 2562306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1, 1), 2662306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2), 2762306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2), 2862306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4), 2962306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8), 3062306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16), 3162306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3), 3262306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL_D3_D3, "syspll_d3_d3", "syspll_d3", 1, 3), 3362306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2), 3462306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4), 3562306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "syspll_d3", 1, 8), 3662306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5), 3762306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2), 3862306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4), 3962306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7), 4062306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2), 4162306a36Sopenharmony_ci FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4), 4262306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1, 1), 4362306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7), 4462306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll", 1, 26), 4562306a36Sopenharmony_ci FACTOR(CLK_TOP_SSUSB_PHY_48M_CK, "ssusb_phy_48m_ck", "univpll", 1, 1), 4662306a36Sopenharmony_ci FACTOR(CLK_TOP_USB_PHY48M_CK, "usb_phy48m_ck", "univpll", 1, 1), 4762306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2), 4862306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2), 4962306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4), 5062306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1, 8), 5162306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3), 5262306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 2), 5362306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 4), 5462306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 8), 5562306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5), 5662306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2), 5762306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4), 5862306a36Sopenharmony_ci FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1, 8), 5962306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_CK_ORG, "ulposc_ck_org", "ulposc", 1, 1), 6062306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_CK, "ulposc_ck", "ulposc_ck_org", 1, 3), 6162306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_D2, "ulposc_d2", "ulposc_ck", 1, 2), 6262306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_D3, "ulposc_d3", "ulposc_ck", 1, 4), 6362306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_D4, "ulposc_d4", "ulposc_ck", 1, 8), 6462306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_D8, "ulposc_d8", "ulposc_ck", 1, 10), 6562306a36Sopenharmony_ci FACTOR(CLK_TOP_ULPOSC_D10, "ulposc_d10", "ulposc_ck_org", 1, 1), 6662306a36Sopenharmony_ci FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1, 1), 6762306a36Sopenharmony_ci FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1, 1), 6862306a36Sopenharmony_ci FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1, 1), 6962306a36Sopenharmony_ci FACTOR(CLK_TOP_MFGPLL_D2, "mfgpll_d2", "mfgpll_ck", 1, 2), 7062306a36Sopenharmony_ci FACTOR(CLK_TOP_IMGPLL_CK, "imgpll_ck", "imgpll", 1, 1), 7162306a36Sopenharmony_ci FACTOR(CLK_TOP_IMGPLL_D2, "imgpll_d2", "imgpll_ck", 1, 2), 7262306a36Sopenharmony_ci FACTOR(CLK_TOP_IMGPLL_D4, "imgpll_d4", "imgpll_ck", 1, 4), 7362306a36Sopenharmony_ci FACTOR(CLK_TOP_CODECPLL_CK, "codecpll_ck", "codecpll", 1, 1), 7462306a36Sopenharmony_ci FACTOR(CLK_TOP_CODECPLL_D2, "codecpll_d2", "codecpll_ck", 1, 2), 7562306a36Sopenharmony_ci FACTOR(CLK_TOP_VDECPLL_CK, "vdecpll_ck", "vdecpll", 1, 1), 7662306a36Sopenharmony_ci FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1, 1), 7762306a36Sopenharmony_ci FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2), 7862306a36Sopenharmony_ci FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1, 4), 7962306a36Sopenharmony_ci FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1, 8), 8062306a36Sopenharmony_ci FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll_ck", 1, 16), 8162306a36Sopenharmony_ci FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1, 1), 8262306a36Sopenharmony_ci FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1, 2), 8362306a36Sopenharmony_ci FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1, 4), 8462306a36Sopenharmony_ci FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll_ck", 1, 8), 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cistatic const char * const axi_parents[] = { 8862306a36Sopenharmony_ci "clk26m", 8962306a36Sopenharmony_ci "syspll_d7", 9062306a36Sopenharmony_ci "ulposc_axi_ck_mux", 9162306a36Sopenharmony_ci}; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_cistatic const char * const ulposc_axi_ck_mux_parents[] = { 9462306a36Sopenharmony_ci "syspll1_d4", 9562306a36Sopenharmony_ci "ulposc_axi_ck_mux_pre", 9662306a36Sopenharmony_ci}; 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_cistatic const char * const ulposc_axi_ck_mux_pre_parents[] = { 9962306a36Sopenharmony_ci "ulposc_d2", 10062306a36Sopenharmony_ci "ulposc_d3", 10162306a36Sopenharmony_ci}; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_cistatic const char * const ddrphycfg_parents[] = { 10462306a36Sopenharmony_ci "clk26m", 10562306a36Sopenharmony_ci "syspll3_d2", 10662306a36Sopenharmony_ci "syspll2_d4", 10762306a36Sopenharmony_ci "syspll1_d8", 10862306a36Sopenharmony_ci}; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistatic const char * const mm_parents[] = { 11162306a36Sopenharmony_ci "clk26m", 11262306a36Sopenharmony_ci "imgpll_ck", 11362306a36Sopenharmony_ci "univpll1_d2", 11462306a36Sopenharmony_ci "syspll1_d2", 11562306a36Sopenharmony_ci}; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_cistatic const char * const pwm_parents[] = { 11862306a36Sopenharmony_ci "clk26m", 11962306a36Sopenharmony_ci "univpll2_d4", 12062306a36Sopenharmony_ci "ulposc_d2", 12162306a36Sopenharmony_ci "ulposc_d3", 12262306a36Sopenharmony_ci "ulposc_d8", 12362306a36Sopenharmony_ci "ulposc_d10", 12462306a36Sopenharmony_ci "ulposc_d4", 12562306a36Sopenharmony_ci}; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_cistatic const char * const vdec_parents[] = { 12862306a36Sopenharmony_ci "clk26m", 12962306a36Sopenharmony_ci "vdecpll_ck", 13062306a36Sopenharmony_ci "imgpll_ck", 13162306a36Sopenharmony_ci "syspll_d3", 13262306a36Sopenharmony_ci "univpll_d5", 13362306a36Sopenharmony_ci "clk26m", 13462306a36Sopenharmony_ci "clk26m", 13562306a36Sopenharmony_ci}; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_cistatic const char * const venc_parents[] = { 13862306a36Sopenharmony_ci "clk26m", 13962306a36Sopenharmony_ci "codecpll_ck", 14062306a36Sopenharmony_ci "syspll_d3", 14162306a36Sopenharmony_ci}; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_cistatic const char * const mfg_parents[] = { 14462306a36Sopenharmony_ci "clk26m", 14562306a36Sopenharmony_ci "mfgpll_ck", 14662306a36Sopenharmony_ci "syspll_d3", 14762306a36Sopenharmony_ci "univpll_d3", 14862306a36Sopenharmony_ci}; 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cistatic const char * const camtg[] = { 15162306a36Sopenharmony_ci "clk26m", 15262306a36Sopenharmony_ci "univpll_d26", 15362306a36Sopenharmony_ci "univpll2_d2", 15462306a36Sopenharmony_ci}; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_cistatic const char * const uart_parents[] = { 15762306a36Sopenharmony_ci "clk26m", 15862306a36Sopenharmony_ci "univpll2_d8", 15962306a36Sopenharmony_ci}; 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_cistatic const char * const spi_parents[] = { 16262306a36Sopenharmony_ci "clk26m", 16362306a36Sopenharmony_ci "syspll3_d2", 16462306a36Sopenharmony_ci "syspll2_d4", 16562306a36Sopenharmony_ci "ulposc_spi_ck_mux", 16662306a36Sopenharmony_ci}; 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_cistatic const char * const ulposc_spi_ck_mux_parents[] = { 16962306a36Sopenharmony_ci "ulposc_d2", 17062306a36Sopenharmony_ci "ulposc_d3", 17162306a36Sopenharmony_ci}; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_cistatic const char * const usb20_parents[] = { 17462306a36Sopenharmony_ci "clk26m", 17562306a36Sopenharmony_ci "univpll1_d8", 17662306a36Sopenharmony_ci "syspll4_d2", 17762306a36Sopenharmony_ci}; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_cistatic const char * const msdc50_0_hclk_parents[] = { 18062306a36Sopenharmony_ci "clk26m", 18162306a36Sopenharmony_ci "syspll1_d2", 18262306a36Sopenharmony_ci "syspll2_d2", 18362306a36Sopenharmony_ci "syspll4_d2", 18462306a36Sopenharmony_ci}; 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cistatic const char * const msdc50_0_parents[] = { 18762306a36Sopenharmony_ci "clk26m", 18862306a36Sopenharmony_ci "msdcpll", 18962306a36Sopenharmony_ci "syspll_d3", 19062306a36Sopenharmony_ci "univpll1_d4", 19162306a36Sopenharmony_ci "syspll2_d2", 19262306a36Sopenharmony_ci "syspll_d7", 19362306a36Sopenharmony_ci "msdcpll_d2", 19462306a36Sopenharmony_ci "univpll1_d2", 19562306a36Sopenharmony_ci "univpll_d3", 19662306a36Sopenharmony_ci}; 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_cistatic const char * const msdc30_1_parents[] = { 19962306a36Sopenharmony_ci "clk26m", 20062306a36Sopenharmony_ci "univpll2_d2", 20162306a36Sopenharmony_ci "msdcpll_d2", 20262306a36Sopenharmony_ci "univpll1_d4", 20362306a36Sopenharmony_ci "syspll2_d2", 20462306a36Sopenharmony_ci "syspll_d7", 20562306a36Sopenharmony_ci "univpll_d7", 20662306a36Sopenharmony_ci}; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_cistatic const char * const msdc30_2_parents[] = { 20962306a36Sopenharmony_ci "clk26m", 21062306a36Sopenharmony_ci "univpll2_d8", 21162306a36Sopenharmony_ci "syspll2_d8", 21262306a36Sopenharmony_ci "syspll1_d8", 21362306a36Sopenharmony_ci "msdcpll_d8", 21462306a36Sopenharmony_ci "syspll3_d4", 21562306a36Sopenharmony_ci "univpll_d26", 21662306a36Sopenharmony_ci}; 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_cistatic const char * const audio_parents[] = { 21962306a36Sopenharmony_ci "clk26m", 22062306a36Sopenharmony_ci "syspll3_d4", 22162306a36Sopenharmony_ci "syspll4_d4", 22262306a36Sopenharmony_ci "syspll1_d16", 22362306a36Sopenharmony_ci}; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_cistatic const char * const aud_intbus_parents[] = { 22662306a36Sopenharmony_ci "clk26m", 22762306a36Sopenharmony_ci "syspll1_d4", 22862306a36Sopenharmony_ci "syspll4_d2", 22962306a36Sopenharmony_ci}; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cistatic const char * const pmicspi_parents[] = { 23262306a36Sopenharmony_ci "clk26m", 23362306a36Sopenharmony_ci "univpll_d26", 23462306a36Sopenharmony_ci "syspll3_d4", 23562306a36Sopenharmony_ci "syspll1_d8", 23662306a36Sopenharmony_ci "ulposc_d4", 23762306a36Sopenharmony_ci "ulposc_d8", 23862306a36Sopenharmony_ci "syspll2_d8", 23962306a36Sopenharmony_ci}; 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_cistatic const char * const scp_parents[] = { 24262306a36Sopenharmony_ci "clk26m", 24362306a36Sopenharmony_ci "syspll_d3", 24462306a36Sopenharmony_ci "ulposc_ck", 24562306a36Sopenharmony_ci "univpll_d5", 24662306a36Sopenharmony_ci}; 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_cistatic const char * const atb_parents[] = { 24962306a36Sopenharmony_ci "clk26m", 25062306a36Sopenharmony_ci "syspll1_d2", 25162306a36Sopenharmony_ci "syspll_d5", 25262306a36Sopenharmony_ci}; 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_cistatic const char * const mjc_parents[] = { 25562306a36Sopenharmony_ci "clk26m", 25662306a36Sopenharmony_ci "imgpll_ck", 25762306a36Sopenharmony_ci "univpll_d5", 25862306a36Sopenharmony_ci "syspll1_d2", 25962306a36Sopenharmony_ci}; 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_cistatic const char * const dpi0_parents[] = { 26262306a36Sopenharmony_ci "clk26m", 26362306a36Sopenharmony_ci "tvdpll_d2", 26462306a36Sopenharmony_ci "tvdpll_d4", 26562306a36Sopenharmony_ci "tvdpll_d8", 26662306a36Sopenharmony_ci "tvdpll_d16", 26762306a36Sopenharmony_ci "clk26m", 26862306a36Sopenharmony_ci "clk26m", 26962306a36Sopenharmony_ci}; 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_cistatic const char * const aud_1_parents[] = { 27262306a36Sopenharmony_ci "clk26m", 27362306a36Sopenharmony_ci "apll1_ck", 27462306a36Sopenharmony_ci}; 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_cistatic const char * const aud_2_parents[] = { 27762306a36Sopenharmony_ci "clk26m", 27862306a36Sopenharmony_ci "apll2_ck", 27962306a36Sopenharmony_ci}; 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_cistatic const char * const ssusb_top_sys_parents[] = { 28262306a36Sopenharmony_ci "clk26m", 28362306a36Sopenharmony_ci "univpll3_d2", 28462306a36Sopenharmony_ci}; 28562306a36Sopenharmony_ci 28662306a36Sopenharmony_cistatic const char * const spm_parents[] = { 28762306a36Sopenharmony_ci "clk26m", 28862306a36Sopenharmony_ci "syspll1_d8", 28962306a36Sopenharmony_ci}; 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_cistatic const char * const bsi_spi_parents[] = { 29262306a36Sopenharmony_ci "clk26m", 29362306a36Sopenharmony_ci "syspll_d3_d3", 29462306a36Sopenharmony_ci "syspll1_d4", 29562306a36Sopenharmony_ci "syspll_d7", 29662306a36Sopenharmony_ci}; 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_cistatic const char * const audio_h_parents[] = { 29962306a36Sopenharmony_ci "clk26m", 30062306a36Sopenharmony_ci "apll2_ck", 30162306a36Sopenharmony_ci "apll1_ck", 30262306a36Sopenharmony_ci "univpll_d7", 30362306a36Sopenharmony_ci}; 30462306a36Sopenharmony_ci 30562306a36Sopenharmony_cistatic const char * const mfg_52m_parents[] = { 30662306a36Sopenharmony_ci "clk26m", 30762306a36Sopenharmony_ci "univpll2_d8", 30862306a36Sopenharmony_ci "univpll2_d4", 30962306a36Sopenharmony_ci "univpll2_d4", 31062306a36Sopenharmony_ci}; 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_cistatic const char * const anc_md32_parents[] = { 31362306a36Sopenharmony_ci "clk26m", 31462306a36Sopenharmony_ci "syspll1_d2", 31562306a36Sopenharmony_ci "univpll_d5", 31662306a36Sopenharmony_ci}; 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci/* 31962306a36Sopenharmony_ci * Clock mux ddrphycfg is needed by the DRAM controller. We mark it as 32062306a36Sopenharmony_ci * critical as otherwise the system will hang after boot. 32162306a36Sopenharmony_ci */ 32262306a36Sopenharmony_cistatic const struct mtk_composite top_muxes[] = { 32362306a36Sopenharmony_ci MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX_PRE, "ulposc_axi_ck_mux_pre", 32462306a36Sopenharmony_ci ulposc_axi_ck_mux_pre_parents, 0x0040, 3, 1), 32562306a36Sopenharmony_ci MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX, "ulposc_axi_ck_mux", 32662306a36Sopenharmony_ci ulposc_axi_ck_mux_parents, 0x0040, 2, 1), 32762306a36Sopenharmony_ci MUX(CLK_TOP_MUX_AXI, "axi_sel", axi_parents, 32862306a36Sopenharmony_ci 0x0040, 0, 2), 32962306a36Sopenharmony_ci MUX_FLAGS(CLK_TOP_MUX_DDRPHYCFG, "ddrphycfg_sel", ddrphycfg_parents, 33062306a36Sopenharmony_ci 0x0040, 16, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT), 33162306a36Sopenharmony_ci MUX(CLK_TOP_MUX_MM, "mm_sel", mm_parents, 33262306a36Sopenharmony_ci 0x0040, 24, 2), 33362306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_PWM, "pwm_sel", pwm_parents, 0x0050, 0, 3, 7), 33462306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_VDEC, "vdec_sel", vdec_parents, 0x0050, 8, 3, 15), 33562306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_VENC, "venc_sel", venc_parents, 0x0050, 16, 2, 23), 33662306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_MFG, "mfg_sel", mfg_parents, 0x0050, 24, 2, 31), 33762306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_CAMTG, "camtg_sel", camtg, 0x0060, 0, 2, 7), 33862306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_UART, "uart_sel", uart_parents, 0x0060, 8, 1, 15), 33962306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_SPI, "spi_sel", spi_parents, 0x0060, 16, 2, 23), 34062306a36Sopenharmony_ci MUX(CLK_TOP_MUX_ULPOSC_SPI_CK_MUX, "ulposc_spi_ck_mux", 34162306a36Sopenharmony_ci ulposc_spi_ck_mux_parents, 0x0060, 18, 1), 34262306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_USB20, "usb20_sel", usb20_parents, 34362306a36Sopenharmony_ci 0x0060, 24, 2, 31), 34462306a36Sopenharmony_ci MUX(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_0_hclk_sel", 34562306a36Sopenharmony_ci msdc50_0_hclk_parents, 0x0070, 8, 2), 34662306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel", msdc50_0_parents, 34762306a36Sopenharmony_ci 0x0070, 16, 4, 23), 34862306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel", msdc30_1_parents, 34962306a36Sopenharmony_ci 0x0070, 24, 3, 31), 35062306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel", msdc30_2_parents, 35162306a36Sopenharmony_ci 0x0080, 0, 3, 7), 35262306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_AUDIO, "audio_sel", audio_parents, 35362306a36Sopenharmony_ci 0x0080, 16, 2, 23), 35462306a36Sopenharmony_ci MUX(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel", aud_intbus_parents, 35562306a36Sopenharmony_ci 0x0080, 24, 2), 35662306a36Sopenharmony_ci MUX(CLK_TOP_MUX_PMICSPI, "pmicspi_sel", pmicspi_parents, 35762306a36Sopenharmony_ci 0x0090, 0, 3), 35862306a36Sopenharmony_ci MUX(CLK_TOP_MUX_SCP, "scp_sel", scp_parents, 35962306a36Sopenharmony_ci 0x0090, 8, 2), 36062306a36Sopenharmony_ci MUX(CLK_TOP_MUX_ATB, "atb_sel", atb_parents, 36162306a36Sopenharmony_ci 0x0090, 16, 2), 36262306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_MJC, "mjc_sel", mjc_parents, 0x0090, 24, 2, 31), 36362306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_DPI0, "dpi0_sel", dpi0_parents, 0x00A0, 0, 3, 7), 36462306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_AUD_1, "aud_1_sel", aud_1_parents, 36562306a36Sopenharmony_ci 0x00A0, 16, 1, 23), 36662306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_AUD_2, "aud_2_sel", aud_2_parents, 36762306a36Sopenharmony_ci 0x00A0, 24, 1, 31), 36862306a36Sopenharmony_ci MUX(CLK_TOP_MUX_SSUSB_TOP_SYS, "ssusb_top_sys_sel", 36962306a36Sopenharmony_ci ssusb_top_sys_parents, 0x00B0, 8, 1), 37062306a36Sopenharmony_ci MUX(CLK_TOP_MUX_SPM, "spm_sel", spm_parents, 37162306a36Sopenharmony_ci 0x00C0, 0, 1), 37262306a36Sopenharmony_ci MUX(CLK_TOP_MUX_BSI_SPI, "bsi_spi_sel", bsi_spi_parents, 37362306a36Sopenharmony_ci 0x00C0, 8, 2), 37462306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_AUDIO_H, "audio_h_sel", audio_h_parents, 37562306a36Sopenharmony_ci 0x00C0, 16, 2, 23), 37662306a36Sopenharmony_ci MUX_GATE(CLK_TOP_MUX_ANC_MD32, "anc_md32_sel", anc_md32_parents, 37762306a36Sopenharmony_ci 0x00C0, 24, 2, 31), 37862306a36Sopenharmony_ci MUX(CLK_TOP_MUX_MFG_52M, "mfg_52m_sel", mfg_52m_parents, 37962306a36Sopenharmony_ci 0x0104, 1, 2), 38062306a36Sopenharmony_ci}; 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_cistatic int mtk_topckgen_init(struct platform_device *pdev) 38362306a36Sopenharmony_ci{ 38462306a36Sopenharmony_ci struct clk_hw_onecell_data *clk_data; 38562306a36Sopenharmony_ci void __iomem *base; 38662306a36Sopenharmony_ci struct device_node *node = pdev->dev.of_node; 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci base = devm_platform_ioremap_resource(pdev, 0); 38962306a36Sopenharmony_ci if (IS_ERR(base)) 39062306a36Sopenharmony_ci return PTR_ERR(base); 39162306a36Sopenharmony_ci 39262306a36Sopenharmony_ci clk_data = mtk_alloc_clk_data(CLK_TOP_NR); 39362306a36Sopenharmony_ci if (!clk_data) 39462306a36Sopenharmony_ci return -ENOMEM; 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs), 39762306a36Sopenharmony_ci clk_data); 39862306a36Sopenharmony_ci 39962306a36Sopenharmony_ci mtk_clk_register_composites(&pdev->dev, top_muxes, 40062306a36Sopenharmony_ci ARRAY_SIZE(top_muxes), base, 40162306a36Sopenharmony_ci &mt6797_clk_lock, clk_data); 40262306a36Sopenharmony_ci 40362306a36Sopenharmony_ci return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); 40462306a36Sopenharmony_ci} 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_cistatic const struct mtk_gate_regs infra0_cg_regs = { 40762306a36Sopenharmony_ci .set_ofs = 0x0080, 40862306a36Sopenharmony_ci .clr_ofs = 0x0084, 40962306a36Sopenharmony_ci .sta_ofs = 0x0090, 41062306a36Sopenharmony_ci}; 41162306a36Sopenharmony_ci 41262306a36Sopenharmony_cistatic const struct mtk_gate_regs infra1_cg_regs = { 41362306a36Sopenharmony_ci .set_ofs = 0x0088, 41462306a36Sopenharmony_ci .clr_ofs = 0x008c, 41562306a36Sopenharmony_ci .sta_ofs = 0x0094, 41662306a36Sopenharmony_ci}; 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_cistatic const struct mtk_gate_regs infra2_cg_regs = { 41962306a36Sopenharmony_ci .set_ofs = 0x00a8, 42062306a36Sopenharmony_ci .clr_ofs = 0x00ac, 42162306a36Sopenharmony_ci .sta_ofs = 0x00b0, 42262306a36Sopenharmony_ci}; 42362306a36Sopenharmony_ci 42462306a36Sopenharmony_ci#define GATE_ICG0(_id, _name, _parent, _shift) \ 42562306a36Sopenharmony_ci GATE_MTK(_id, _name, _parent, &infra0_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci#define GATE_ICG1(_id, _name, _parent, _shift) \ 42862306a36Sopenharmony_ci GATE_MTK(_id, _name, _parent, &infra1_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ci#define GATE_ICG1_FLAGS(_id, _name, _parent, _shift, _flags) \ 43162306a36Sopenharmony_ci GATE_MTK_FLAGS(_id, _name, _parent, &infra1_cg_regs, _shift, \ 43262306a36Sopenharmony_ci &mtk_clk_gate_ops_setclr, _flags) 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci#define GATE_ICG2(_id, _name, _parent, _shift) \ 43562306a36Sopenharmony_ci GATE_MTK(_id, _name, _parent, &infra2_cg_regs, _shift, &mtk_clk_gate_ops_setclr) 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci#define GATE_ICG2_FLAGS(_id, _name, _parent, _shift, _flags) \ 43862306a36Sopenharmony_ci GATE_MTK_FLAGS(_id, _name, _parent, &infra2_cg_regs, _shift, \ 43962306a36Sopenharmony_ci &mtk_clk_gate_ops_setclr, _flags) 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci/* 44262306a36Sopenharmony_ci * Clock gates dramc and dramc_b are needed by the DRAM controller. 44362306a36Sopenharmony_ci * We mark them as critical as otherwise the system will hang after boot. 44462306a36Sopenharmony_ci */ 44562306a36Sopenharmony_cistatic const struct mtk_gate infra_clks[] = { 44662306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr", "ulposc", 0), 44762306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PMIC_AP, "infra_pmic_ap", "pmicspi_sel", 1), 44862306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PMIC_MD, "infra_pmic_md", "pmicspi_sel", 2), 44962306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn", "pmicspi_sel", 3), 45062306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_SCP, "infra_scp", "scp_sel", 4), 45162306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_SEJ, "infra_sej", "axi_sel", 5), 45262306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_APXGPT, "infra_apxgpt", "axi_sel", 6), 45362306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_SEJ_13M, "infra_sej_13m", "clk26m", 7), 45462306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_ICUSB, "infra_icusb", "usb20_sel", 8), 45562306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_GCE, "infra_gce", "axi_sel", 9), 45662306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_THERM, "infra_therm", "axi_sel", 10), 45762306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_I2C0, "infra_i2c0", "axi_sel", 11), 45862306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_I2C1, "infra_i2c1", "axi_sel", 12), 45962306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_I2C2, "infra_i2c2", "axi_sel", 13), 46062306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_I2C3, "infra_i2c3", "axi_sel", 14), 46162306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk", "axi_sel", 15), 46262306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PWM1, "infra_pwm1", "axi_sel", 16), 46362306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PWM2, "infra_pwm2", "axi_sel", 17), 46462306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PWM3, "infra_pwm3", "axi_sel", 18), 46562306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PWM4, "infra_pwm4", "axi_sel", 19), 46662306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_PWM, "infra_pwm", "axi_sel", 21), 46762306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_UART0, "infra_uart0", "uart_sel", 22), 46862306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_UART1, "infra_uart1", "uart_sel", 23), 46962306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_UART2, "infra_uart2", "uart_sel", 24), 47062306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_UART3, "infra_uart3", "uart_sel", 25), 47162306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_MD2MD_CCIF_0, "infra_md2md_ccif_0", "axi_sel", 27), 47262306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_MD2MD_CCIF_1, "infra_md2md_ccif_1", "axi_sel", 28), 47362306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_MD2MD_CCIF_2, "infra_md2md_ccif_2", "axi_sel", 29), 47462306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_FHCTL, "infra_fhctl", "clk26m", 30), 47562306a36Sopenharmony_ci GATE_ICG0(CLK_INFRA_BTIF, "infra_btif", "axi_sel", 31), 47662306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MD2MD_CCIF_3, "infra_md2md_ccif_3", "axi_sel", 0), 47762306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_SPI, "infra_spi", "spi_sel", 1), 47862306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MSDC0, "infra_msdc0", "msdc50_0_sel", 2), 47962306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MD2MD_CCIF_4, "infra_md2md_ccif_4", "axi_sel", 3), 48062306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MSDC1, "infra_msdc1", "msdc30_1_sel", 4), 48162306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MSDC2, "infra_msdc2", "msdc30_2_sel", 5), 48262306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MD2MD_CCIF_5, "infra_md2md_ccif_5", "axi_sel", 7), 48362306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_GCPU, "infra_gcpu", "axi_sel", 8), 48462306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 9), 48562306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_AUXADC, "infra_auxadc", "clk26m", 10), 48662306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_CPUM, "infra_cpum", "axi_sel", 11), 48762306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_0, "infra_ap_c2k_ccif_0", 48862306a36Sopenharmony_ci "axi_sel", 12), 48962306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_1, "infra_ap_c2k_ccif_1", 49062306a36Sopenharmony_ci "axi_sel", 13), 49162306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_CLDMA, "infra_cldma", "axi_sel", 16), 49262306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_DISP_PWM, "infra_disp_pwm", "pwm_sel", 17), 49362306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_AP_DMA, "infra_ap_dma", "axi_sel", 18), 49462306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_DEVICE_APC, "infra_device_apc", "axi_sel", 20), 49562306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "mm_sel", 22), 49662306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_CCIF_AP, "infra_ccif_ap", "axi_sel", 23), 49762306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_AUDIO, "infra_audio", "axi_sel", 25), 49862306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_CCIF_MD, "infra_ccif_md", "axi_sel", 26), 49962306a36Sopenharmony_ci GATE_ICG1_FLAGS(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m", 50062306a36Sopenharmony_ci "clk26m", 31, CLK_IS_CRITICAL), 50162306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C4, "infra_i2c4", "axi_sel", 0), 50262306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C_APPM, "infra_i2c_appm", "axi_sel", 1), 50362306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C_GPUPM, "infra_i2c_gpupm", "axi_sel", 2), 50462306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm", "axi_sel", 3), 50562306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C2_ARB, "infra_i2c2_arb", "axi_sel", 4), 50662306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C3_IMM, "infra_i2c3_imm", "axi_sel", 5), 50762306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C3_ARB, "infra_i2c3_arb", "axi_sel", 6), 50862306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_I2C5, "infra_i2c5", "axi_sel", 7), 50962306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SYS_CIRQ, "infra_sys_cirq", "axi_sel", 8), 51062306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SPI1, "infra_spi1", "spi_sel", 10), 51162306a36Sopenharmony_ci GATE_ICG2_FLAGS(CLK_INFRA_DRAMC_B_F26M, "infra_dramc_b_f26m", 51262306a36Sopenharmony_ci "clk26m", 11, CLK_IS_CRITICAL), 51362306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_ANC_MD32, "infra_anc_md32", "anc_md32_sel", 12), 51462306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_ANC_MD32_32K, "infra_anc_md32_32k", "clk26m", 13), 51562306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_DVFS_SPM1, "infra_dvfs_spm1", "axi_sel", 15), 51662306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_AES_TOP0, "infra_aes_top0", "axi_sel", 16), 51762306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_AES_TOP1, "infra_aes_top1", "axi_sel", 17), 51862306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SSUSB_BUS, "infra_ssusb_bus", "axi_sel", 18), 51962306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SPI2, "infra_spi2", "spi_sel", 19), 52062306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SPI3, "infra_spi3", "spi_sel", 20), 52162306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SPI4, "infra_spi4", "spi_sel", 21), 52262306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SPI5, "infra_spi5", "spi_sel", 22), 52362306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_IRTX, "infra_irtx", "spi_sel", 23), 52462306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SSUSB_SYS, "infra_ssusb_sys", 52562306a36Sopenharmony_ci "ssusb_top_sys_sel", 24), 52662306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_SSUSB_REF, "infra_ssusb_ref", "clk26m", 9), 52762306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_AUDIO_26M, "infra_audio_26m", "clk26m", 26), 52862306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_AUDIO_26M_PAD_TOP, "infra_audio_26m_pad_top", 52962306a36Sopenharmony_ci "clk26m", 27), 53062306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_modem_temp_share", 53162306a36Sopenharmony_ci "axi_sel", 28), 53262306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_VAD_WRAP_SOC, "infra_vad_wrap_soc", "axi_sel", 29), 53362306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_DRAMC_CONF, "infra_dramc_conf", "axi_sel", 30), 53462306a36Sopenharmony_ci GATE_ICG2(CLK_INFRA_DRAMC_B_CONF, "infra_dramc_b_conf", "axi_sel", 31), 53562306a36Sopenharmony_ci GATE_ICG1(CLK_INFRA_MFG_VCG, "infra_mfg_vcg", "mfg_52m_sel", 14), 53662306a36Sopenharmony_ci}; 53762306a36Sopenharmony_ci 53862306a36Sopenharmony_cistatic const struct mtk_fixed_factor infra_fixed_divs[] = { 53962306a36Sopenharmony_ci FACTOR(CLK_INFRA_13M, "clk13m", "clk26m", 1, 2), 54062306a36Sopenharmony_ci}; 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_cistatic struct clk_hw_onecell_data *infra_clk_data; 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_cistatic void mtk_infrasys_init_early(struct device_node *node) 54562306a36Sopenharmony_ci{ 54662306a36Sopenharmony_ci int r, i; 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ci if (!infra_clk_data) { 54962306a36Sopenharmony_ci infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR); 55062306a36Sopenharmony_ci if (!infra_clk_data) 55162306a36Sopenharmony_ci return; 55262306a36Sopenharmony_ci 55362306a36Sopenharmony_ci for (i = 0; i < CLK_INFRA_NR; i++) 55462306a36Sopenharmony_ci infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER); 55562306a36Sopenharmony_ci } 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs), 55862306a36Sopenharmony_ci infra_clk_data); 55962306a36Sopenharmony_ci 56062306a36Sopenharmony_ci r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, 56162306a36Sopenharmony_ci infra_clk_data); 56262306a36Sopenharmony_ci if (r) 56362306a36Sopenharmony_ci pr_err("%s(): could not register clock provider: %d\n", 56462306a36Sopenharmony_ci __func__, r); 56562306a36Sopenharmony_ci} 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ciCLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt6797-infracfg", 56862306a36Sopenharmony_ci mtk_infrasys_init_early); 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_cistatic int mtk_infrasys_init(struct platform_device *pdev) 57162306a36Sopenharmony_ci{ 57262306a36Sopenharmony_ci int i; 57362306a36Sopenharmony_ci struct device_node *node = pdev->dev.of_node; 57462306a36Sopenharmony_ci 57562306a36Sopenharmony_ci if (!infra_clk_data) { 57662306a36Sopenharmony_ci infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR); 57762306a36Sopenharmony_ci if (!infra_clk_data) 57862306a36Sopenharmony_ci return -ENOMEM; 57962306a36Sopenharmony_ci } else { 58062306a36Sopenharmony_ci for (i = 0; i < CLK_INFRA_NR; i++) { 58162306a36Sopenharmony_ci if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER)) 58262306a36Sopenharmony_ci infra_clk_data->hws[i] = ERR_PTR(-ENOENT); 58362306a36Sopenharmony_ci } 58462306a36Sopenharmony_ci } 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci mtk_clk_register_gates(&pdev->dev, node, infra_clks, 58762306a36Sopenharmony_ci ARRAY_SIZE(infra_clks), infra_clk_data); 58862306a36Sopenharmony_ci mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs), 58962306a36Sopenharmony_ci infra_clk_data); 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ci return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, 59262306a36Sopenharmony_ci infra_clk_data); 59362306a36Sopenharmony_ci} 59462306a36Sopenharmony_ci 59562306a36Sopenharmony_ci#define MT6797_PLL_FMAX (3000UL * MHZ) 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_ci#define CON0_MT6797_RST_BAR BIT(24) 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ci#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \ 60062306a36Sopenharmony_ci _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \ 60162306a36Sopenharmony_ci _pcw_shift, _div_table) { \ 60262306a36Sopenharmony_ci .id = _id, \ 60362306a36Sopenharmony_ci .name = _name, \ 60462306a36Sopenharmony_ci .reg = _reg, \ 60562306a36Sopenharmony_ci .pwr_reg = _pwr_reg, \ 60662306a36Sopenharmony_ci .en_mask = _en_mask, \ 60762306a36Sopenharmony_ci .flags = _flags, \ 60862306a36Sopenharmony_ci .rst_bar_mask = CON0_MT6797_RST_BAR, \ 60962306a36Sopenharmony_ci .fmax = MT6797_PLL_FMAX, \ 61062306a36Sopenharmony_ci .pcwbits = _pcwbits, \ 61162306a36Sopenharmony_ci .pd_reg = _pd_reg, \ 61262306a36Sopenharmony_ci .pd_shift = _pd_shift, \ 61362306a36Sopenharmony_ci .tuner_reg = _tuner_reg, \ 61462306a36Sopenharmony_ci .pcw_reg = _pcw_reg, \ 61562306a36Sopenharmony_ci .pcw_shift = _pcw_shift, \ 61662306a36Sopenharmony_ci .div_table = _div_table, \ 61762306a36Sopenharmony_ci} 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \ 62062306a36Sopenharmony_ci _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \ 62162306a36Sopenharmony_ci _pcw_shift) \ 62262306a36Sopenharmony_ci PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \ 62362306a36Sopenharmony_ci _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \ 62462306a36Sopenharmony_ci NULL) 62562306a36Sopenharmony_ci 62662306a36Sopenharmony_cistatic const struct mtk_pll_data plls[] = { 62762306a36Sopenharmony_ci PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0220, 0x022C, 0xF0000100, PLL_AO, 62862306a36Sopenharmony_ci 21, 0x220, 4, 0x0, 0x224, 0), 62962306a36Sopenharmony_ci PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0230, 0x023C, 0xFE000010, 0, 7, 63062306a36Sopenharmony_ci 0x230, 4, 0x0, 0x234, 14), 63162306a36Sopenharmony_ci PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0240, 0x024C, 0x00000100, 0, 21, 63262306a36Sopenharmony_ci 0x244, 24, 0x0, 0x244, 0), 63362306a36Sopenharmony_ci PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0250, 0x025C, 0x00000120, 0, 21, 63462306a36Sopenharmony_ci 0x250, 4, 0x0, 0x254, 0), 63562306a36Sopenharmony_ci PLL(CLK_APMIXED_IMGPLL, "imgpll", 0x0260, 0x026C, 0x00000120, 0, 21, 63662306a36Sopenharmony_ci 0x260, 4, 0x0, 0x264, 0), 63762306a36Sopenharmony_ci PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0270, 0x027C, 0xC0000120, 0, 21, 63862306a36Sopenharmony_ci 0x270, 4, 0x0, 0x274, 0), 63962306a36Sopenharmony_ci PLL(CLK_APMIXED_CODECPLL, "codecpll", 0x0290, 0x029C, 0x00000120, 0, 21, 64062306a36Sopenharmony_ci 0x290, 4, 0x0, 0x294, 0), 64162306a36Sopenharmony_ci PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x02E4, 0x02F0, 0x00000120, 0, 21, 64262306a36Sopenharmony_ci 0x2E4, 4, 0x0, 0x2E8, 0), 64362306a36Sopenharmony_ci PLL(CLK_APMIXED_APLL1, "apll1", 0x02A0, 0x02B0, 0x00000130, 0, 31, 64462306a36Sopenharmony_ci 0x2A0, 4, 0x2A8, 0x2A4, 0), 64562306a36Sopenharmony_ci PLL(CLK_APMIXED_APLL2, "apll2", 0x02B4, 0x02C4, 0x00000130, 0, 31, 64662306a36Sopenharmony_ci 0x2B4, 4, 0x2BC, 0x2B8, 0), 64762306a36Sopenharmony_ci}; 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_cistatic int mtk_apmixedsys_init(struct platform_device *pdev) 65062306a36Sopenharmony_ci{ 65162306a36Sopenharmony_ci struct clk_hw_onecell_data *clk_data; 65262306a36Sopenharmony_ci struct device_node *node = pdev->dev.of_node; 65362306a36Sopenharmony_ci 65462306a36Sopenharmony_ci clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR); 65562306a36Sopenharmony_ci if (!clk_data) 65662306a36Sopenharmony_ci return -ENOMEM; 65762306a36Sopenharmony_ci 65862306a36Sopenharmony_ci mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data); 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data); 66162306a36Sopenharmony_ci} 66262306a36Sopenharmony_ci 66362306a36Sopenharmony_cistatic const struct of_device_id of_match_clk_mt6797[] = { 66462306a36Sopenharmony_ci { 66562306a36Sopenharmony_ci .compatible = "mediatek,mt6797-topckgen", 66662306a36Sopenharmony_ci .data = mtk_topckgen_init, 66762306a36Sopenharmony_ci }, { 66862306a36Sopenharmony_ci .compatible = "mediatek,mt6797-infracfg", 66962306a36Sopenharmony_ci .data = mtk_infrasys_init, 67062306a36Sopenharmony_ci }, { 67162306a36Sopenharmony_ci .compatible = "mediatek,mt6797-apmixedsys", 67262306a36Sopenharmony_ci .data = mtk_apmixedsys_init, 67362306a36Sopenharmony_ci }, { 67462306a36Sopenharmony_ci /* sentinel */ 67562306a36Sopenharmony_ci } 67662306a36Sopenharmony_ci}; 67762306a36Sopenharmony_ciMODULE_DEVICE_TABLE(of, of_match_clk_mt6797); 67862306a36Sopenharmony_ci 67962306a36Sopenharmony_cistatic int clk_mt6797_probe(struct platform_device *pdev) 68062306a36Sopenharmony_ci{ 68162306a36Sopenharmony_ci int (*clk_init)(struct platform_device *); 68262306a36Sopenharmony_ci int r; 68362306a36Sopenharmony_ci 68462306a36Sopenharmony_ci clk_init = of_device_get_match_data(&pdev->dev); 68562306a36Sopenharmony_ci if (!clk_init) 68662306a36Sopenharmony_ci return -EINVAL; 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci r = clk_init(pdev); 68962306a36Sopenharmony_ci if (r) 69062306a36Sopenharmony_ci dev_err(&pdev->dev, 69162306a36Sopenharmony_ci "could not register clock provider: %s: %d\n", 69262306a36Sopenharmony_ci pdev->name, r); 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_ci return r; 69562306a36Sopenharmony_ci} 69662306a36Sopenharmony_ci 69762306a36Sopenharmony_cistatic struct platform_driver clk_mt6797_drv = { 69862306a36Sopenharmony_ci .probe = clk_mt6797_probe, 69962306a36Sopenharmony_ci .driver = { 70062306a36Sopenharmony_ci .name = "clk-mt6797", 70162306a36Sopenharmony_ci .of_match_table = of_match_clk_mt6797, 70262306a36Sopenharmony_ci }, 70362306a36Sopenharmony_ci}; 70462306a36Sopenharmony_ci 70562306a36Sopenharmony_cistatic int __init clk_mt6797_init(void) 70662306a36Sopenharmony_ci{ 70762306a36Sopenharmony_ci return platform_driver_register(&clk_mt6797_drv); 70862306a36Sopenharmony_ci} 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ciarch_initcall(clk_mt6797_init); 71162306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 712