18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2020-2022 MaxLinear, Inc. 48c2ecf20Sopenharmony_ci * Copyright (C) 2020 Intel Corporation. 58c2ecf20Sopenharmony_ci * Zhu Yixin <yzhu@maxlinear.com> 68c2ecf20Sopenharmony_ci * Rahul Tanwar <rtanwar@maxlinear.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#include <linux/clk-provider.h> 98c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h> 108c2ecf20Sopenharmony_ci#include <linux/of.h> 118c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 128c2ecf20Sopenharmony_ci#include <dt-bindings/clock/intel,lgm-clk.h> 138c2ecf20Sopenharmony_ci#include "clk-cgu.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define PLL_DIV_WIDTH 4 168c2ecf20Sopenharmony_ci#define PLL_DDIV_WIDTH 3 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* Gate0 clock shift */ 198c2ecf20Sopenharmony_ci#define G_C55_SHIFT 7 208c2ecf20Sopenharmony_ci#define G_QSPI_SHIFT 9 218c2ecf20Sopenharmony_ci#define G_EIP197_SHIFT 11 228c2ecf20Sopenharmony_ci#define G_VAULT130_SHIFT 12 238c2ecf20Sopenharmony_ci#define G_TOE_SHIFT 13 248c2ecf20Sopenharmony_ci#define G_SDXC_SHIFT 14 258c2ecf20Sopenharmony_ci#define G_EMMC_SHIFT 15 268c2ecf20Sopenharmony_ci#define G_SPIDBG_SHIFT 17 278c2ecf20Sopenharmony_ci#define G_DMA3_SHIFT 28 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* Gate1 clock shift */ 308c2ecf20Sopenharmony_ci#define G_DMA0_SHIFT 0 318c2ecf20Sopenharmony_ci#define G_LEDC0_SHIFT 1 328c2ecf20Sopenharmony_ci#define G_LEDC1_SHIFT 2 338c2ecf20Sopenharmony_ci#define G_I2S0_SHIFT 3 348c2ecf20Sopenharmony_ci#define G_I2S1_SHIFT 4 358c2ecf20Sopenharmony_ci#define G_EBU_SHIFT 5 368c2ecf20Sopenharmony_ci#define G_PWM_SHIFT 6 378c2ecf20Sopenharmony_ci#define G_I2C0_SHIFT 7 388c2ecf20Sopenharmony_ci#define G_I2C1_SHIFT 8 398c2ecf20Sopenharmony_ci#define G_I2C2_SHIFT 9 408c2ecf20Sopenharmony_ci#define G_I2C3_SHIFT 10 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define G_SSC0_SHIFT 12 438c2ecf20Sopenharmony_ci#define G_SSC1_SHIFT 13 448c2ecf20Sopenharmony_ci#define G_SSC2_SHIFT 14 458c2ecf20Sopenharmony_ci#define G_SSC3_SHIFT 15 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define G_GPTC0_SHIFT 17 488c2ecf20Sopenharmony_ci#define G_GPTC1_SHIFT 18 498c2ecf20Sopenharmony_ci#define G_GPTC2_SHIFT 19 508c2ecf20Sopenharmony_ci#define G_GPTC3_SHIFT 20 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define G_ASC0_SHIFT 22 538c2ecf20Sopenharmony_ci#define G_ASC1_SHIFT 23 548c2ecf20Sopenharmony_ci#define G_ASC2_SHIFT 24 558c2ecf20Sopenharmony_ci#define G_ASC3_SHIFT 25 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define G_PCM0_SHIFT 27 588c2ecf20Sopenharmony_ci#define G_PCM1_SHIFT 28 598c2ecf20Sopenharmony_ci#define G_PCM2_SHIFT 29 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* Gate2 clock shift */ 628c2ecf20Sopenharmony_ci#define G_PCIE10_SHIFT 1 638c2ecf20Sopenharmony_ci#define G_PCIE11_SHIFT 2 648c2ecf20Sopenharmony_ci#define G_PCIE30_SHIFT 3 658c2ecf20Sopenharmony_ci#define G_PCIE31_SHIFT 4 668c2ecf20Sopenharmony_ci#define G_PCIE20_SHIFT 5 678c2ecf20Sopenharmony_ci#define G_PCIE21_SHIFT 6 688c2ecf20Sopenharmony_ci#define G_PCIE40_SHIFT 7 698c2ecf20Sopenharmony_ci#define G_PCIE41_SHIFT 8 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define G_XPCS0_SHIFT 10 728c2ecf20Sopenharmony_ci#define G_XPCS1_SHIFT 11 738c2ecf20Sopenharmony_ci#define G_XPCS2_SHIFT 12 748c2ecf20Sopenharmony_ci#define G_XPCS3_SHIFT 13 758c2ecf20Sopenharmony_ci#define G_SATA0_SHIFT 14 768c2ecf20Sopenharmony_ci#define G_SATA1_SHIFT 15 778c2ecf20Sopenharmony_ci#define G_SATA2_SHIFT 16 788c2ecf20Sopenharmony_ci#define G_SATA3_SHIFT 17 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Gate3 clock shift */ 818c2ecf20Sopenharmony_ci#define G_ARCEM4_SHIFT 0 828c2ecf20Sopenharmony_ci#define G_IDMAR1_SHIFT 2 838c2ecf20Sopenharmony_ci#define G_IDMAT0_SHIFT 3 848c2ecf20Sopenharmony_ci#define G_IDMAT1_SHIFT 4 858c2ecf20Sopenharmony_ci#define G_IDMAT2_SHIFT 5 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define G_PPV4_SHIFT 8 888c2ecf20Sopenharmony_ci#define G_GSWIPO_SHIFT 9 898c2ecf20Sopenharmony_ci#define G_CQEM_SHIFT 10 908c2ecf20Sopenharmony_ci#define G_XPCS5_SHIFT 14 918c2ecf20Sopenharmony_ci#define G_USB1_SHIFT 25 928c2ecf20Sopenharmony_ci#define G_USB2_SHIFT 26 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/* Register definition */ 968c2ecf20Sopenharmony_ci#define CGU_PLL0CZ_CFG0 0x000 978c2ecf20Sopenharmony_ci#define CGU_PLL0CM0_CFG0 0x020 988c2ecf20Sopenharmony_ci#define CGU_PLL0CM1_CFG0 0x040 998c2ecf20Sopenharmony_ci#define CGU_PLL0B_CFG0 0x060 1008c2ecf20Sopenharmony_ci#define CGU_PLL1_CFG0 0x080 1018c2ecf20Sopenharmony_ci#define CGU_PLL2_CFG0 0x0A0 1028c2ecf20Sopenharmony_ci#define CGU_PLLPP_CFG0 0x0C0 1038c2ecf20Sopenharmony_ci#define CGU_LJPLL3_CFG0 0x0E0 1048c2ecf20Sopenharmony_ci#define CGU_LJPLL4_CFG0 0x100 1058c2ecf20Sopenharmony_ci#define CGU_C55_PCMCR 0x18C 1068c2ecf20Sopenharmony_ci#define CGU_PCMCR 0x190 1078c2ecf20Sopenharmony_ci#define CGU_IF_CLK1 0x1A0 1088c2ecf20Sopenharmony_ci#define CGU_IF_CLK2 0x1A4 1098c2ecf20Sopenharmony_ci#define CGU_GATE0 0x300 1108c2ecf20Sopenharmony_ci#define CGU_GATE1 0x310 1118c2ecf20Sopenharmony_ci#define CGU_GATE2 0x320 1128c2ecf20Sopenharmony_ci#define CGU_GATE3 0x310 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#define PLL_DIV(x) ((x) + 0x04) 1158c2ecf20Sopenharmony_ci#define PLL_SSC(x) ((x) + 0x10) 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define CLK_NR_CLKS (LGM_GCLK_USB2 + 1) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/* 1208c2ecf20Sopenharmony_ci * Below table defines the pair's of regval & effective dividers. 1218c2ecf20Sopenharmony_ci * It's more efficient to provide an explicit table due to non-linear 1228c2ecf20Sopenharmony_ci * relation between values. 1238c2ecf20Sopenharmony_ci */ 1248c2ecf20Sopenharmony_cistatic const struct clk_div_table pll_div[] = { 1258c2ecf20Sopenharmony_ci { .val = 0, .div = 1 }, 1268c2ecf20Sopenharmony_ci { .val = 1, .div = 2 }, 1278c2ecf20Sopenharmony_ci { .val = 2, .div = 3 }, 1288c2ecf20Sopenharmony_ci { .val = 3, .div = 4 }, 1298c2ecf20Sopenharmony_ci { .val = 4, .div = 5 }, 1308c2ecf20Sopenharmony_ci { .val = 5, .div = 6 }, 1318c2ecf20Sopenharmony_ci { .val = 6, .div = 8 }, 1328c2ecf20Sopenharmony_ci { .val = 7, .div = 10 }, 1338c2ecf20Sopenharmony_ci { .val = 8, .div = 12 }, 1348c2ecf20Sopenharmony_ci { .val = 9, .div = 16 }, 1358c2ecf20Sopenharmony_ci { .val = 10, .div = 20 }, 1368c2ecf20Sopenharmony_ci { .val = 11, .div = 24 }, 1378c2ecf20Sopenharmony_ci { .val = 12, .div = 32 }, 1388c2ecf20Sopenharmony_ci { .val = 13, .div = 40 }, 1398c2ecf20Sopenharmony_ci { .val = 14, .div = 48 }, 1408c2ecf20Sopenharmony_ci { .val = 15, .div = 64 }, 1418c2ecf20Sopenharmony_ci {} 1428c2ecf20Sopenharmony_ci}; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_cistatic const struct clk_div_table dcl_div[] = { 1458c2ecf20Sopenharmony_ci { .val = 0, .div = 6 }, 1468c2ecf20Sopenharmony_ci { .val = 1, .div = 12 }, 1478c2ecf20Sopenharmony_ci { .val = 2, .div = 24 }, 1488c2ecf20Sopenharmony_ci { .val = 3, .div = 32 }, 1498c2ecf20Sopenharmony_ci { .val = 4, .div = 48 }, 1508c2ecf20Sopenharmony_ci { .val = 5, .div = 96 }, 1518c2ecf20Sopenharmony_ci {} 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistatic const struct clk_parent_data pll_p[] = { 1558c2ecf20Sopenharmony_ci { .fw_name = "osc", .name = "osc" }, 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_cistatic const struct clk_parent_data pllcm_p[] = { 1588c2ecf20Sopenharmony_ci { .fw_name = "cpu_cm", .name = "cpu_cm" }, 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_cistatic const struct clk_parent_data emmc_p[] = { 1618c2ecf20Sopenharmony_ci { .fw_name = "emmc4", .name = "emmc4" }, 1628c2ecf20Sopenharmony_ci { .fw_name = "noc4", .name = "noc4" }, 1638c2ecf20Sopenharmony_ci}; 1648c2ecf20Sopenharmony_cistatic const struct clk_parent_data sdxc_p[] = { 1658c2ecf20Sopenharmony_ci { .fw_name = "sdxc3", .name = "sdxc3" }, 1668c2ecf20Sopenharmony_ci { .fw_name = "sdxc2", .name = "sdxc2" }, 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_cistatic const struct clk_parent_data pcm_p[] = { 1698c2ecf20Sopenharmony_ci { .fw_name = "v_docsis", .name = "v_docsis" }, 1708c2ecf20Sopenharmony_ci { .fw_name = "dcl", .name = "dcl" }, 1718c2ecf20Sopenharmony_ci}; 1728c2ecf20Sopenharmony_cistatic const struct clk_parent_data cbphy_p[] = { 1738c2ecf20Sopenharmony_ci { .fw_name = "dd_serdes", .name = "dd_serdes" }, 1748c2ecf20Sopenharmony_ci { .fw_name = "dd_pcie", .name = "dd_pcie" }, 1758c2ecf20Sopenharmony_ci}; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_cistatic const struct lgm_pll_clk_data lgm_pll_clks[] = { 1788c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLL0CZ, "pll0cz", pll_p, CLK_IGNORE_UNUSED, 1798c2ecf20Sopenharmony_ci CGU_PLL0CZ_CFG0, TYPE_ROPLL), 1808c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLL0CM0, "pll0cm0", pllcm_p, CLK_IGNORE_UNUSED, 1818c2ecf20Sopenharmony_ci CGU_PLL0CM0_CFG0, TYPE_ROPLL), 1828c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLL0CM1, "pll0cm1", pllcm_p, CLK_IGNORE_UNUSED, 1838c2ecf20Sopenharmony_ci CGU_PLL0CM1_CFG0, TYPE_ROPLL), 1848c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLL0B, "pll0b", pll_p, CLK_IGNORE_UNUSED, 1858c2ecf20Sopenharmony_ci CGU_PLL0B_CFG0, TYPE_ROPLL), 1868c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLL1, "pll1", pll_p, 0, CGU_PLL1_CFG0, TYPE_ROPLL), 1878c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLL2, "pll2", pll_p, CLK_IGNORE_UNUSED, 1888c2ecf20Sopenharmony_ci CGU_PLL2_CFG0, TYPE_ROPLL), 1898c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_PLLPP, "pllpp", pll_p, 0, CGU_PLLPP_CFG0, TYPE_ROPLL), 1908c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_LJPLL3, "ljpll3", pll_p, 0, CGU_LJPLL3_CFG0, TYPE_LJPLL), 1918c2ecf20Sopenharmony_ci LGM_PLL(LGM_CLK_LJPLL4, "ljpll4", pll_p, 0, CGU_LJPLL4_CFG0, TYPE_LJPLL), 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic const struct lgm_clk_branch lgm_branch_clks[] = { 1958c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_PP_HW, "pp_hw", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0), 1968c2ecf20Sopenharmony_ci 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div), 1978c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_PP_UC, "pp_uc", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0), 1988c2ecf20Sopenharmony_ci 4, PLL_DIV_WIDTH, 25, 1, 0, 0, pll_div), 1998c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_PP_FXD, "pp_fxd", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0), 2008c2ecf20Sopenharmony_ci 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div), 2018c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_PP_TBM, "pp_tbm", "pllpp", 0, PLL_DIV(CGU_PLLPP_CFG0), 2028c2ecf20Sopenharmony_ci 12, PLL_DIV_WIDTH, 27, 1, 0, 0, pll_div), 2038c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_DDR, "ddr", "pll2", CLK_IGNORE_UNUSED, 2048c2ecf20Sopenharmony_ci PLL_DIV(CGU_PLL2_CFG0), 0, PLL_DIV_WIDTH, 24, 1, 0, 0, 2058c2ecf20Sopenharmony_ci pll_div), 2068c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_CM, "cpu_cm", "pll0cz", 0, PLL_DIV(CGU_PLL0CZ_CFG0), 2078c2ecf20Sopenharmony_ci 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div), 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_IC, "cpu_ic", "pll0cz", CLK_IGNORE_UNUSED, 2108c2ecf20Sopenharmony_ci PLL_DIV(CGU_PLL0CZ_CFG0), 4, PLL_DIV_WIDTH, 25, 2118c2ecf20Sopenharmony_ci 1, 0, 0, pll_div), 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_SDXC3, "sdxc3", "pll0cz", 0, PLL_DIV(CGU_PLL0CZ_CFG0), 2148c2ecf20Sopenharmony_ci 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div), 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_CPU0, "cm0", "pll0cm0", 2178c2ecf20Sopenharmony_ci CLK_IGNORE_UNUSED, PLL_DIV(CGU_PLL0CM0_CFG0), 2188c2ecf20Sopenharmony_ci 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div), 2198c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_CPU1, "cm1", "pll0cm1", 2208c2ecf20Sopenharmony_ci CLK_IGNORE_UNUSED, PLL_DIV(CGU_PLL0CM1_CFG0), 2218c2ecf20Sopenharmony_ci 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div), 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci /* 2248c2ecf20Sopenharmony_ci * Marking ngi_clk (next generation interconnect) and noc_clk 2258c2ecf20Sopenharmony_ci * (network on chip peripheral clk) as critical clocks because 2268c2ecf20Sopenharmony_ci * these are shared parent clock sources for many different 2278c2ecf20Sopenharmony_ci * peripherals. 2288c2ecf20Sopenharmony_ci */ 2298c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_NGI, "ngi", "pll0b", 2308c2ecf20Sopenharmony_ci (CLK_IGNORE_UNUSED|CLK_IS_CRITICAL), PLL_DIV(CGU_PLL0B_CFG0), 2318c2ecf20Sopenharmony_ci 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div), 2328c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_NOC4, "noc4", "pll0b", 2338c2ecf20Sopenharmony_ci (CLK_IGNORE_UNUSED|CLK_IS_CRITICAL), PLL_DIV(CGU_PLL0B_CFG0), 2348c2ecf20Sopenharmony_ci 4, PLL_DIV_WIDTH, 25, 1, 0, 0, pll_div), 2358c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_SW, "switch", "pll0b", 0, PLL_DIV(CGU_PLL0B_CFG0), 2368c2ecf20Sopenharmony_ci 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div), 2378c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_QSPI, "qspi", "pll0b", 0, PLL_DIV(CGU_PLL0B_CFG0), 2388c2ecf20Sopenharmony_ci 12, PLL_DIV_WIDTH, 27, 1, 0, 0, pll_div), 2398c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_CT, "v_ct", "pll1", 0, PLL_DIV(CGU_PLL1_CFG0), 2408c2ecf20Sopenharmony_ci 0, PLL_DIV_WIDTH, 24, 1, 0, 0, pll_div), 2418c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_DSP, "v_dsp", "pll1", 0, PLL_DIV(CGU_PLL1_CFG0), 2428c2ecf20Sopenharmony_ci 8, PLL_DIV_WIDTH, 26, 1, 0, 0, pll_div), 2438c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_VIF, "v_ifclk", "pll1", 0, PLL_DIV(CGU_PLL1_CFG0), 2448c2ecf20Sopenharmony_ci 12, PLL_DIV_WIDTH, 27, 1, 0, 0, pll_div), 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci LGM_FIXED_FACTOR(LGM_CLK_EMMC4, "emmc4", "sdxc3", 0, 0, 2478c2ecf20Sopenharmony_ci 0, 0, 0, 0, 1, 4), 2488c2ecf20Sopenharmony_ci LGM_FIXED_FACTOR(LGM_CLK_SDXC2, "sdxc2", "noc4", 0, 0, 2498c2ecf20Sopenharmony_ci 0, 0, 0, 0, 1, 4), 2508c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_EMMC, "emmc", emmc_p, 0, CGU_IF_CLK1, 2518c2ecf20Sopenharmony_ci 0, 1, CLK_MUX_ROUND_CLOSEST, 0), 2528c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_SDXC, "sdxc", sdxc_p, 0, CGU_IF_CLK1, 2538c2ecf20Sopenharmony_ci 1, 1, CLK_MUX_ROUND_CLOSEST, 0), 2548c2ecf20Sopenharmony_ci LGM_FIXED(LGM_CLK_OSC, "osc", NULL, 0, 0, 0, 0, 0, 40000000, 0), 2558c2ecf20Sopenharmony_ci LGM_FIXED(LGM_CLK_SLIC, "slic", NULL, 0, CGU_IF_CLK1, 2568c2ecf20Sopenharmony_ci 8, 2, CLOCK_FLAG_VAL_INIT, 8192000, 2), 2578c2ecf20Sopenharmony_ci LGM_FIXED(LGM_CLK_DOCSIS, "v_docsis", NULL, 0, 0, 0, 0, 0, 16000000, 0), 2588c2ecf20Sopenharmony_ci LGM_DIV(LGM_CLK_DCL, "dcl", "v_ifclk", CLK_SET_RATE_PARENT, CGU_PCMCR, 2598c2ecf20Sopenharmony_ci 25, 3, 0, 0, DIV_CLK_NO_MASK, 0, dcl_div), 2608c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_PCM, "pcm", pcm_p, 0, CGU_C55_PCMCR, 2618c2ecf20Sopenharmony_ci 0, 1, CLK_MUX_ROUND_CLOSEST, 0), 2628c2ecf20Sopenharmony_ci LGM_FIXED_FACTOR(LGM_CLK_DDR_PHY, "ddr_phy", "ddr", 2638c2ecf20Sopenharmony_ci CLK_IGNORE_UNUSED, 0, 2648c2ecf20Sopenharmony_ci 0, 0, 0, 0, 2, 1), 2658c2ecf20Sopenharmony_ci LGM_FIXED_FACTOR(LGM_CLK_PONDEF, "pondef", "dd_pool", 2668c2ecf20Sopenharmony_ci CLK_SET_RATE_PARENT, 0, 0, 0, 0, 0, 1, 2), 2678c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_CBPHY0, "cbphy0", cbphy_p, 0, 0, 2688c2ecf20Sopenharmony_ci 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0), 2698c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_CBPHY1, "cbphy1", cbphy_p, 0, 0, 2708c2ecf20Sopenharmony_ci 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0), 2718c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_CBPHY2, "cbphy2", cbphy_p, 0, 0, 2728c2ecf20Sopenharmony_ci 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0), 2738c2ecf20Sopenharmony_ci LGM_MUX(LGM_CLK_CBPHY3, "cbphy3", cbphy_p, 0, 0, 2748c2ecf20Sopenharmony_ci 0, 0, MUX_CLK_SW | CLK_MUX_ROUND_CLOSEST, 0), 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_C55, "g_c55", NULL, 0, CGU_GATE0, 2778c2ecf20Sopenharmony_ci G_C55_SHIFT, 0, 0), 2788c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_QSPI, "g_qspi", "qspi", 0, CGU_GATE0, 2798c2ecf20Sopenharmony_ci G_QSPI_SHIFT, 0, 0), 2808c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_EIP197, "g_eip197", NULL, 0, CGU_GATE0, 2818c2ecf20Sopenharmony_ci G_EIP197_SHIFT, 0, 0), 2828c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_VAULT, "g_vault130", NULL, 0, CGU_GATE0, 2838c2ecf20Sopenharmony_ci G_VAULT130_SHIFT, 0, 0), 2848c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_TOE, "g_toe", NULL, 0, CGU_GATE0, 2858c2ecf20Sopenharmony_ci G_TOE_SHIFT, 0, 0), 2868c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SDXC, "g_sdxc", "sdxc", 0, CGU_GATE0, 2878c2ecf20Sopenharmony_ci G_SDXC_SHIFT, 0, 0), 2888c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_EMMC, "g_emmc", "emmc", 0, CGU_GATE0, 2898c2ecf20Sopenharmony_ci G_EMMC_SHIFT, 0, 0), 2908c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SPI_DBG, "g_spidbg", NULL, 0, CGU_GATE0, 2918c2ecf20Sopenharmony_ci G_SPIDBG_SHIFT, 0, 0), 2928c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_DMA3, "g_dma3", NULL, 0, CGU_GATE0, 2938c2ecf20Sopenharmony_ci G_DMA3_SHIFT, 0, 0), 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_DMA0, "g_dma0", NULL, 0, CGU_GATE1, 2968c2ecf20Sopenharmony_ci G_DMA0_SHIFT, 0, 0), 2978c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_LEDC0, "g_ledc0", NULL, 0, CGU_GATE1, 2988c2ecf20Sopenharmony_ci G_LEDC0_SHIFT, 0, 0), 2998c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_LEDC1, "g_ledc1", NULL, 0, CGU_GATE1, 3008c2ecf20Sopenharmony_ci G_LEDC1_SHIFT, 0, 0), 3018c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_I2S0, "g_i2s0", NULL, 0, CGU_GATE1, 3028c2ecf20Sopenharmony_ci G_I2S0_SHIFT, 0, 0), 3038c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_I2S1, "g_i2s1", NULL, 0, CGU_GATE1, 3048c2ecf20Sopenharmony_ci G_I2S1_SHIFT, 0, 0), 3058c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_EBU, "g_ebu", NULL, 0, CGU_GATE1, 3068c2ecf20Sopenharmony_ci G_EBU_SHIFT, 0, 0), 3078c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PWM, "g_pwm", NULL, 0, CGU_GATE1, 3088c2ecf20Sopenharmony_ci G_PWM_SHIFT, 0, 0), 3098c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_I2C0, "g_i2c0", NULL, 0, CGU_GATE1, 3108c2ecf20Sopenharmony_ci G_I2C0_SHIFT, 0, 0), 3118c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_I2C1, "g_i2c1", NULL, 0, CGU_GATE1, 3128c2ecf20Sopenharmony_ci G_I2C1_SHIFT, 0, 0), 3138c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_I2C2, "g_i2c2", NULL, 0, CGU_GATE1, 3148c2ecf20Sopenharmony_ci G_I2C2_SHIFT, 0, 0), 3158c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_I2C3, "g_i2c3", NULL, 0, CGU_GATE1, 3168c2ecf20Sopenharmony_ci G_I2C3_SHIFT, 0, 0), 3178c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SSC0, "g_ssc0", "noc4", 0, CGU_GATE1, 3188c2ecf20Sopenharmony_ci G_SSC0_SHIFT, 0, 0), 3198c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SSC1, "g_ssc1", "noc4", 0, CGU_GATE1, 3208c2ecf20Sopenharmony_ci G_SSC1_SHIFT, 0, 0), 3218c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SSC2, "g_ssc2", "noc4", 0, CGU_GATE1, 3228c2ecf20Sopenharmony_ci G_SSC2_SHIFT, 0, 0), 3238c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SSC3, "g_ssc3", "noc4", 0, CGU_GATE1, 3248c2ecf20Sopenharmony_ci G_SSC3_SHIFT, 0, 0), 3258c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_GPTC0, "g_gptc0", "noc4", 0, CGU_GATE1, 3268c2ecf20Sopenharmony_ci G_GPTC0_SHIFT, 0, 0), 3278c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_GPTC1, "g_gptc1", "noc4", 0, CGU_GATE1, 3288c2ecf20Sopenharmony_ci G_GPTC1_SHIFT, 0, 0), 3298c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_GPTC2, "g_gptc2", "noc4", 0, CGU_GATE1, 3308c2ecf20Sopenharmony_ci G_GPTC2_SHIFT, 0, 0), 3318c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_GPTC3, "g_gptc3", "osc", 0, CGU_GATE1, 3328c2ecf20Sopenharmony_ci G_GPTC3_SHIFT, 0, 0), 3338c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_ASC0, "g_asc0", "noc4", 0, CGU_GATE1, 3348c2ecf20Sopenharmony_ci G_ASC0_SHIFT, 0, 0), 3358c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_ASC1, "g_asc1", "noc4", 0, CGU_GATE1, 3368c2ecf20Sopenharmony_ci G_ASC1_SHIFT, 0, 0), 3378c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_ASC2, "g_asc2", "noc4", 0, CGU_GATE1, 3388c2ecf20Sopenharmony_ci G_ASC2_SHIFT, 0, 0), 3398c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_ASC3, "g_asc3", "osc", 0, CGU_GATE1, 3408c2ecf20Sopenharmony_ci G_ASC3_SHIFT, 0, 0), 3418c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCM0, "g_pcm0", NULL, 0, CGU_GATE1, 3428c2ecf20Sopenharmony_ci G_PCM0_SHIFT, 0, 0), 3438c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCM1, "g_pcm1", NULL, 0, CGU_GATE1, 3448c2ecf20Sopenharmony_ci G_PCM1_SHIFT, 0, 0), 3458c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCM2, "g_pcm2", NULL, 0, CGU_GATE1, 3468c2ecf20Sopenharmony_ci G_PCM2_SHIFT, 0, 0), 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE10, "g_pcie10", NULL, 0, CGU_GATE2, 3498c2ecf20Sopenharmony_ci G_PCIE10_SHIFT, 0, 0), 3508c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE11, "g_pcie11", NULL, 0, CGU_GATE2, 3518c2ecf20Sopenharmony_ci G_PCIE11_SHIFT, 0, 0), 3528c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE30, "g_pcie30", NULL, 0, CGU_GATE2, 3538c2ecf20Sopenharmony_ci G_PCIE30_SHIFT, 0, 0), 3548c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE31, "g_pcie31", NULL, 0, CGU_GATE2, 3558c2ecf20Sopenharmony_ci G_PCIE31_SHIFT, 0, 0), 3568c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE20, "g_pcie20", NULL, 0, CGU_GATE2, 3578c2ecf20Sopenharmony_ci G_PCIE20_SHIFT, 0, 0), 3588c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE21, "g_pcie21", NULL, 0, CGU_GATE2, 3598c2ecf20Sopenharmony_ci G_PCIE21_SHIFT, 0, 0), 3608c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE40, "g_pcie40", NULL, 0, CGU_GATE2, 3618c2ecf20Sopenharmony_ci G_PCIE40_SHIFT, 0, 0), 3628c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PCIE41, "g_pcie41", NULL, 0, CGU_GATE2, 3638c2ecf20Sopenharmony_ci G_PCIE41_SHIFT, 0, 0), 3648c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_XPCS0, "g_xpcs0", NULL, 0, CGU_GATE2, 3658c2ecf20Sopenharmony_ci G_XPCS0_SHIFT, 0, 0), 3668c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_XPCS1, "g_xpcs1", NULL, 0, CGU_GATE2, 3678c2ecf20Sopenharmony_ci G_XPCS1_SHIFT, 0, 0), 3688c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_XPCS2, "g_xpcs2", NULL, 0, CGU_GATE2, 3698c2ecf20Sopenharmony_ci G_XPCS2_SHIFT, 0, 0), 3708c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_XPCS3, "g_xpcs3", NULL, 0, CGU_GATE2, 3718c2ecf20Sopenharmony_ci G_XPCS3_SHIFT, 0, 0), 3728c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SATA0, "g_sata0", NULL, 0, CGU_GATE2, 3738c2ecf20Sopenharmony_ci G_SATA0_SHIFT, 0, 0), 3748c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SATA1, "g_sata1", NULL, 0, CGU_GATE2, 3758c2ecf20Sopenharmony_ci G_SATA1_SHIFT, 0, 0), 3768c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SATA2, "g_sata2", NULL, 0, CGU_GATE2, 3778c2ecf20Sopenharmony_ci G_SATA2_SHIFT, 0, 0), 3788c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_SATA3, "g_sata3", NULL, 0, CGU_GATE2, 3798c2ecf20Sopenharmony_ci G_SATA3_SHIFT, 0, 0), 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_ARCEM4, "g_arcem4", NULL, 0, CGU_GATE3, 3828c2ecf20Sopenharmony_ci G_ARCEM4_SHIFT, 0, 0), 3838c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_IDMAR1, "g_idmar1", NULL, 0, CGU_GATE3, 3848c2ecf20Sopenharmony_ci G_IDMAR1_SHIFT, 0, 0), 3858c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_IDMAT0, "g_idmat0", NULL, 0, CGU_GATE3, 3868c2ecf20Sopenharmony_ci G_IDMAT0_SHIFT, 0, 0), 3878c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_IDMAT1, "g_idmat1", NULL, 0, CGU_GATE3, 3888c2ecf20Sopenharmony_ci G_IDMAT1_SHIFT, 0, 0), 3898c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_IDMAT2, "g_idmat2", NULL, 0, CGU_GATE3, 3908c2ecf20Sopenharmony_ci G_IDMAT2_SHIFT, 0, 0), 3918c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_PPV4, "g_ppv4", NULL, 0, CGU_GATE3, 3928c2ecf20Sopenharmony_ci G_PPV4_SHIFT, 0, 0), 3938c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_GSWIPO, "g_gswipo", "switch", 0, CGU_GATE3, 3948c2ecf20Sopenharmony_ci G_GSWIPO_SHIFT, 0, 0), 3958c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_CQEM, "g_cqem", "switch", 0, CGU_GATE3, 3968c2ecf20Sopenharmony_ci G_CQEM_SHIFT, 0, 0), 3978c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_XPCS5, "g_xpcs5", NULL, 0, CGU_GATE3, 3988c2ecf20Sopenharmony_ci G_XPCS5_SHIFT, 0, 0), 3998c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_USB1, "g_usb1", NULL, 0, CGU_GATE3, 4008c2ecf20Sopenharmony_ci G_USB1_SHIFT, 0, 0), 4018c2ecf20Sopenharmony_ci LGM_GATE(LGM_GCLK_USB2, "g_usb2", NULL, 0, CGU_GATE3, 4028c2ecf20Sopenharmony_ci G_USB2_SHIFT, 0, 0), 4038c2ecf20Sopenharmony_ci}; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_cistatic const struct lgm_clk_ddiv_data lgm_ddiv_clks[] = { 4078c2ecf20Sopenharmony_ci LGM_DDIV(LGM_CLK_CML, "dd_cml", "ljpll3", 0, 4088c2ecf20Sopenharmony_ci PLL_DIV(CGU_LJPLL3_CFG0), 0, PLL_DDIV_WIDTH, 4098c2ecf20Sopenharmony_ci 3, PLL_DDIV_WIDTH, 24, 1, 29, 0), 4108c2ecf20Sopenharmony_ci LGM_DDIV(LGM_CLK_SERDES, "dd_serdes", "ljpll3", 0, 4118c2ecf20Sopenharmony_ci PLL_DIV(CGU_LJPLL3_CFG0), 6, PLL_DDIV_WIDTH, 4128c2ecf20Sopenharmony_ci 9, PLL_DDIV_WIDTH, 25, 1, 28, 0), 4138c2ecf20Sopenharmony_ci LGM_DDIV(LGM_CLK_POOL, "dd_pool", "ljpll3", 0, 4148c2ecf20Sopenharmony_ci PLL_DIV(CGU_LJPLL3_CFG0), 12, PLL_DDIV_WIDTH, 4158c2ecf20Sopenharmony_ci 15, PLL_DDIV_WIDTH, 26, 1, 28, 0), 4168c2ecf20Sopenharmony_ci LGM_DDIV(LGM_CLK_PTP, "dd_ptp", "ljpll3", 0, 4178c2ecf20Sopenharmony_ci PLL_DIV(CGU_LJPLL3_CFG0), 18, PLL_DDIV_WIDTH, 4188c2ecf20Sopenharmony_ci 21, PLL_DDIV_WIDTH, 27, 1, 28, 0), 4198c2ecf20Sopenharmony_ci LGM_DDIV(LGM_CLK_PCIE, "dd_pcie", "ljpll4", 0, 4208c2ecf20Sopenharmony_ci PLL_DIV(CGU_LJPLL4_CFG0), 0, PLL_DDIV_WIDTH, 4218c2ecf20Sopenharmony_ci 3, PLL_DDIV_WIDTH, 24, 1, 29, 0), 4228c2ecf20Sopenharmony_ci}; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_cistatic int lgm_cgu_probe(struct platform_device *pdev) 4258c2ecf20Sopenharmony_ci{ 4268c2ecf20Sopenharmony_ci struct lgm_clk_provider *ctx; 4278c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 4288c2ecf20Sopenharmony_ci struct device_node *np = dev->of_node; 4298c2ecf20Sopenharmony_ci int ret; 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci ctx = devm_kzalloc(dev, struct_size(ctx, clk_data.hws, CLK_NR_CLKS), 4328c2ecf20Sopenharmony_ci GFP_KERNEL); 4338c2ecf20Sopenharmony_ci if (!ctx) 4348c2ecf20Sopenharmony_ci return -ENOMEM; 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci ctx->clk_data.num = CLK_NR_CLKS; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci ctx->membase = syscon_node_to_regmap(np); 4398c2ecf20Sopenharmony_ci if (IS_ERR(ctx->membase)) { 4408c2ecf20Sopenharmony_ci dev_err(dev, "Failed to get clk CGU iomem\n"); 4418c2ecf20Sopenharmony_ci return PTR_ERR(ctx->membase); 4428c2ecf20Sopenharmony_ci } 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci ctx->np = np; 4468c2ecf20Sopenharmony_ci ctx->dev = dev; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci ret = lgm_clk_register_plls(ctx, lgm_pll_clks, 4498c2ecf20Sopenharmony_ci ARRAY_SIZE(lgm_pll_clks)); 4508c2ecf20Sopenharmony_ci if (ret) 4518c2ecf20Sopenharmony_ci return ret; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci ret = lgm_clk_register_branches(ctx, lgm_branch_clks, 4548c2ecf20Sopenharmony_ci ARRAY_SIZE(lgm_branch_clks)); 4558c2ecf20Sopenharmony_ci if (ret) 4568c2ecf20Sopenharmony_ci return ret; 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci ret = lgm_clk_register_ddiv(ctx, lgm_ddiv_clks, 4598c2ecf20Sopenharmony_ci ARRAY_SIZE(lgm_ddiv_clks)); 4608c2ecf20Sopenharmony_ci if (ret) 4618c2ecf20Sopenharmony_ci return ret; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, 4648c2ecf20Sopenharmony_ci &ctx->clk_data); 4658c2ecf20Sopenharmony_ci} 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_cistatic const struct of_device_id of_lgm_cgu_match[] = { 4688c2ecf20Sopenharmony_ci { .compatible = "intel,cgu-lgm" }, 4698c2ecf20Sopenharmony_ci {} 4708c2ecf20Sopenharmony_ci}; 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_cistatic struct platform_driver lgm_cgu_driver = { 4738c2ecf20Sopenharmony_ci .probe = lgm_cgu_probe, 4748c2ecf20Sopenharmony_ci .driver = { 4758c2ecf20Sopenharmony_ci .name = "cgu-lgm", 4768c2ecf20Sopenharmony_ci .of_match_table = of_lgm_cgu_match, 4778c2ecf20Sopenharmony_ci }, 4788c2ecf20Sopenharmony_ci}; 4798c2ecf20Sopenharmony_cibuiltin_platform_driver(lgm_cgu_driver); 480