162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci// Copyright (C) 2015 Broadcom Corporation 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include <linux/kernel.h> 562306a36Sopenharmony_ci#include <linux/err.h> 662306a36Sopenharmony_ci#include <linux/clk-provider.h> 762306a36Sopenharmony_ci#include <linux/io.h> 862306a36Sopenharmony_ci#include <linux/of.h> 962306a36Sopenharmony_ci#include <linux/of_address.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <dt-bindings/clock/bcm-ns2.h> 1262306a36Sopenharmony_ci#include "clk-iproc.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define REG_VAL(o, s, w) { .offset = o, .shift = s, .width = w, } 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define AON_VAL(o, pw, ps, is) { .offset = o, .pwr_width = pw, \ 1762306a36Sopenharmony_ci .pwr_shift = ps, .iso_shift = is } 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define RESET_VAL(o, rs, prs) { .offset = o, .reset_shift = rs, \ 2062306a36Sopenharmony_ci .p_reset_shift = prs } 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#define DF_VAL(o, kis, kiw, kps, kpw, kas, kaw) { .offset = o, .ki_shift = kis,\ 2362306a36Sopenharmony_ci .ki_width = kiw, .kp_shift = kps, .kp_width = kpw, .ka_shift = kas, \ 2462306a36Sopenharmony_ci .ka_width = kaw } 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define VCO_CTRL_VAL(uo, lo) { .u_offset = uo, .l_offset = lo } 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#define ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \ 2962306a36Sopenharmony_ci .hold_shift = hs, .bypass_shift = bs } 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistatic const struct iproc_pll_ctrl genpll_scr = { 3262306a36Sopenharmony_ci .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL, 3362306a36Sopenharmony_ci .aon = AON_VAL(0x0, 1, 15, 12), 3462306a36Sopenharmony_ci .reset = RESET_VAL(0x4, 2, 1), 3562306a36Sopenharmony_ci .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 2, 3), 3662306a36Sopenharmony_ci .ndiv_int = REG_VAL(0x8, 4, 10), 3762306a36Sopenharmony_ci .pdiv = REG_VAL(0x8, 0, 4), 3862306a36Sopenharmony_ci .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc), 3962306a36Sopenharmony_ci .status = REG_VAL(0x0, 27, 1), 4062306a36Sopenharmony_ci}; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_cistatic const struct iproc_clk_ctrl genpll_scr_clk[] = { 4462306a36Sopenharmony_ci /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined 4562306a36Sopenharmony_ci * in NS2. However, it doesn't appear to be used anywhere, so setting 4662306a36Sopenharmony_ci * it to 0. 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_ci [BCM_NS2_GENPLL_SCR_SCR_CLK] = { 4962306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SCR_SCR_CLK, 5062306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 5162306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 18, 12, 0), 5262306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 0, 8), 5362306a36Sopenharmony_ci }, 5462306a36Sopenharmony_ci [BCM_NS2_GENPLL_SCR_FS_CLK] = { 5562306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SCR_FS_CLK, 5662306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 5762306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 19, 13, 0), 5862306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 8, 8), 5962306a36Sopenharmony_ci }, 6062306a36Sopenharmony_ci [BCM_NS2_GENPLL_SCR_AUDIO_CLK] = { 6162306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SCR_AUDIO_CLK, 6262306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 6362306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 20, 14, 0), 6462306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 0, 8), 6562306a36Sopenharmony_ci }, 6662306a36Sopenharmony_ci [BCM_NS2_GENPLL_SCR_CH3_UNUSED] = { 6762306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SCR_CH3_UNUSED, 6862306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 6962306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 21, 15, 0), 7062306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 8, 8), 7162306a36Sopenharmony_ci }, 7262306a36Sopenharmony_ci [BCM_NS2_GENPLL_SCR_CH4_UNUSED] = { 7362306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SCR_CH4_UNUSED, 7462306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 7562306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 22, 16, 0), 7662306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 16, 8), 7762306a36Sopenharmony_ci }, 7862306a36Sopenharmony_ci [BCM_NS2_GENPLL_SCR_CH5_UNUSED] = { 7962306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SCR_CH5_UNUSED, 8062306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 8162306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 23, 17, 0), 8262306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 24, 8), 8362306a36Sopenharmony_ci }, 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistatic void __init ns2_genpll_scr_clk_init(struct device_node *node) 8762306a36Sopenharmony_ci{ 8862306a36Sopenharmony_ci iproc_pll_clk_setup(node, &genpll_scr, NULL, 0, genpll_scr_clk, 8962306a36Sopenharmony_ci ARRAY_SIZE(genpll_scr_clk)); 9062306a36Sopenharmony_ci} 9162306a36Sopenharmony_ciCLK_OF_DECLARE(ns2_genpll_src_clk, "brcm,ns2-genpll-scr", 9262306a36Sopenharmony_ci ns2_genpll_scr_clk_init); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_cistatic const struct iproc_pll_ctrl genpll_sw = { 9562306a36Sopenharmony_ci .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL, 9662306a36Sopenharmony_ci .aon = AON_VAL(0x0, 1, 11, 10), 9762306a36Sopenharmony_ci .reset = RESET_VAL(0x4, 2, 1), 9862306a36Sopenharmony_ci .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 2, 3), 9962306a36Sopenharmony_ci .ndiv_int = REG_VAL(0x8, 4, 10), 10062306a36Sopenharmony_ci .pdiv = REG_VAL(0x8, 0, 4), 10162306a36Sopenharmony_ci .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc), 10262306a36Sopenharmony_ci .status = REG_VAL(0x0, 13, 1), 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_cistatic const struct iproc_clk_ctrl genpll_sw_clk[] = { 10662306a36Sopenharmony_ci /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined 10762306a36Sopenharmony_ci * in NS2. However, it doesn't appear to be used anywhere, so setting 10862306a36Sopenharmony_ci * it to 0. 10962306a36Sopenharmony_ci */ 11062306a36Sopenharmony_ci [BCM_NS2_GENPLL_SW_RPE_CLK] = { 11162306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SW_RPE_CLK, 11262306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 11362306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 18, 12, 0), 11462306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 0, 8), 11562306a36Sopenharmony_ci }, 11662306a36Sopenharmony_ci [BCM_NS2_GENPLL_SW_250_CLK] = { 11762306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SW_250_CLK, 11862306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 11962306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 19, 13, 0), 12062306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 8, 8), 12162306a36Sopenharmony_ci }, 12262306a36Sopenharmony_ci [BCM_NS2_GENPLL_SW_NIC_CLK] = { 12362306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SW_NIC_CLK, 12462306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 12562306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 20, 14, 0), 12662306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 0, 8), 12762306a36Sopenharmony_ci }, 12862306a36Sopenharmony_ci [BCM_NS2_GENPLL_SW_CHIMP_CLK] = { 12962306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SW_CHIMP_CLK, 13062306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 13162306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 21, 15, 0), 13262306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 8, 8), 13362306a36Sopenharmony_ci }, 13462306a36Sopenharmony_ci [BCM_NS2_GENPLL_SW_PORT_CLK] = { 13562306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SW_PORT_CLK, 13662306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 13762306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 22, 16, 0), 13862306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 16, 8), 13962306a36Sopenharmony_ci }, 14062306a36Sopenharmony_ci [BCM_NS2_GENPLL_SW_SDIO_CLK] = { 14162306a36Sopenharmony_ci .channel = BCM_NS2_GENPLL_SW_SDIO_CLK, 14262306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 14362306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 23, 17, 0), 14462306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 24, 8), 14562306a36Sopenharmony_ci }, 14662306a36Sopenharmony_ci}; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_cistatic void __init ns2_genpll_sw_clk_init(struct device_node *node) 14962306a36Sopenharmony_ci{ 15062306a36Sopenharmony_ci iproc_pll_clk_setup(node, &genpll_sw, NULL, 0, genpll_sw_clk, 15162306a36Sopenharmony_ci ARRAY_SIZE(genpll_sw_clk)); 15262306a36Sopenharmony_ci} 15362306a36Sopenharmony_ciCLK_OF_DECLARE(ns2_genpll_sw_clk, "brcm,ns2-genpll-sw", 15462306a36Sopenharmony_ci ns2_genpll_sw_clk_init); 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_cistatic const struct iproc_pll_ctrl lcpll_ddr = { 15762306a36Sopenharmony_ci .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL, 15862306a36Sopenharmony_ci .aon = AON_VAL(0x0, 2, 1, 0), 15962306a36Sopenharmony_ci .reset = RESET_VAL(0x4, 2, 1), 16062306a36Sopenharmony_ci .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 1, 4), 16162306a36Sopenharmony_ci .ndiv_int = REG_VAL(0x8, 4, 10), 16262306a36Sopenharmony_ci .pdiv = REG_VAL(0x8, 0, 4), 16362306a36Sopenharmony_ci .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc), 16462306a36Sopenharmony_ci .status = REG_VAL(0x0, 0, 1), 16562306a36Sopenharmony_ci}; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_cistatic const struct iproc_clk_ctrl lcpll_ddr_clk[] = { 16862306a36Sopenharmony_ci /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined 16962306a36Sopenharmony_ci * in NS2. However, it doesn't appear to be used anywhere, so setting 17062306a36Sopenharmony_ci * it to 0. 17162306a36Sopenharmony_ci */ 17262306a36Sopenharmony_ci [BCM_NS2_LCPLL_DDR_PCIE_SATA_USB_CLK] = { 17362306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_DDR_PCIE_SATA_USB_CLK, 17462306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 17562306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 18, 12, 0), 17662306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 0, 8), 17762306a36Sopenharmony_ci }, 17862306a36Sopenharmony_ci [BCM_NS2_LCPLL_DDR_DDR_CLK] = { 17962306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_DDR_DDR_CLK, 18062306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 18162306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 19, 13, 0), 18262306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 8, 8), 18362306a36Sopenharmony_ci }, 18462306a36Sopenharmony_ci [BCM_NS2_LCPLL_DDR_CH2_UNUSED] = { 18562306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_DDR_CH2_UNUSED, 18662306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 18762306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 20, 14, 0), 18862306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 0, 8), 18962306a36Sopenharmony_ci }, 19062306a36Sopenharmony_ci [BCM_NS2_LCPLL_DDR_CH3_UNUSED] = { 19162306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_DDR_CH3_UNUSED, 19262306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 19362306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 21, 15, 0), 19462306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 8, 8), 19562306a36Sopenharmony_ci }, 19662306a36Sopenharmony_ci [BCM_NS2_LCPLL_DDR_CH4_UNUSED] = { 19762306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_DDR_CH4_UNUSED, 19862306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 19962306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 22, 16, 0), 20062306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 16, 8), 20162306a36Sopenharmony_ci }, 20262306a36Sopenharmony_ci [BCM_NS2_LCPLL_DDR_CH5_UNUSED] = { 20362306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_DDR_CH5_UNUSED, 20462306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 20562306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 23, 17, 0), 20662306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 24, 8), 20762306a36Sopenharmony_ci }, 20862306a36Sopenharmony_ci}; 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_cistatic void __init ns2_lcpll_ddr_clk_init(struct device_node *node) 21162306a36Sopenharmony_ci{ 21262306a36Sopenharmony_ci iproc_pll_clk_setup(node, &lcpll_ddr, NULL, 0, lcpll_ddr_clk, 21362306a36Sopenharmony_ci ARRAY_SIZE(lcpll_ddr_clk)); 21462306a36Sopenharmony_ci} 21562306a36Sopenharmony_ciCLK_OF_DECLARE(ns2_lcpll_ddr_clk, "brcm,ns2-lcpll-ddr", 21662306a36Sopenharmony_ci ns2_lcpll_ddr_clk_init); 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_cistatic const struct iproc_pll_ctrl lcpll_ports = { 21962306a36Sopenharmony_ci .flags = IPROC_CLK_AON | IPROC_CLK_PLL_SPLIT_STAT_CTRL, 22062306a36Sopenharmony_ci .aon = AON_VAL(0x0, 2, 5, 4), 22162306a36Sopenharmony_ci .reset = RESET_VAL(0x4, 2, 1), 22262306a36Sopenharmony_ci .dig_filter = DF_VAL(0x0, 9, 3, 5, 4, 1, 4), 22362306a36Sopenharmony_ci .ndiv_int = REG_VAL(0x8, 4, 10), 22462306a36Sopenharmony_ci .pdiv = REG_VAL(0x8, 0, 4), 22562306a36Sopenharmony_ci .vco_ctrl = VCO_CTRL_VAL(0x10, 0xc), 22662306a36Sopenharmony_ci .status = REG_VAL(0x0, 0, 1), 22762306a36Sopenharmony_ci}; 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_cistatic const struct iproc_clk_ctrl lcpll_ports_clk[] = { 23062306a36Sopenharmony_ci /* bypass_shift, the last value passed into ENABLE_VAL(), is not defined 23162306a36Sopenharmony_ci * in NS2. However, it doesn't appear to be used anywhere, so setting 23262306a36Sopenharmony_ci * it to 0. 23362306a36Sopenharmony_ci */ 23462306a36Sopenharmony_ci [BCM_NS2_LCPLL_PORTS_WAN_CLK] = { 23562306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_PORTS_WAN_CLK, 23662306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 23762306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 18, 12, 0), 23862306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 0, 8), 23962306a36Sopenharmony_ci }, 24062306a36Sopenharmony_ci [BCM_NS2_LCPLL_PORTS_RGMII_CLK] = { 24162306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_PORTS_RGMII_CLK, 24262306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 24362306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 19, 13, 0), 24462306a36Sopenharmony_ci .mdiv = REG_VAL(0x14, 8, 8), 24562306a36Sopenharmony_ci }, 24662306a36Sopenharmony_ci [BCM_NS2_LCPLL_PORTS_CH2_UNUSED] = { 24762306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_PORTS_CH2_UNUSED, 24862306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 24962306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 20, 14, 0), 25062306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 0, 8), 25162306a36Sopenharmony_ci }, 25262306a36Sopenharmony_ci [BCM_NS2_LCPLL_PORTS_CH3_UNUSED] = { 25362306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_PORTS_CH3_UNUSED, 25462306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 25562306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 21, 15, 0), 25662306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 8, 8), 25762306a36Sopenharmony_ci }, 25862306a36Sopenharmony_ci [BCM_NS2_LCPLL_PORTS_CH4_UNUSED] = { 25962306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_PORTS_CH4_UNUSED, 26062306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 26162306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 22, 16, 0), 26262306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 16, 8), 26362306a36Sopenharmony_ci }, 26462306a36Sopenharmony_ci [BCM_NS2_LCPLL_PORTS_CH5_UNUSED] = { 26562306a36Sopenharmony_ci .channel = BCM_NS2_LCPLL_PORTS_CH5_UNUSED, 26662306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 26762306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 23, 17, 0), 26862306a36Sopenharmony_ci .mdiv = REG_VAL(0x10, 24, 8), 26962306a36Sopenharmony_ci }, 27062306a36Sopenharmony_ci}; 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_cistatic void __init ns2_lcpll_ports_clk_init(struct device_node *node) 27362306a36Sopenharmony_ci{ 27462306a36Sopenharmony_ci iproc_pll_clk_setup(node, &lcpll_ports, NULL, 0, lcpll_ports_clk, 27562306a36Sopenharmony_ci ARRAY_SIZE(lcpll_ports_clk)); 27662306a36Sopenharmony_ci} 27762306a36Sopenharmony_ciCLK_OF_DECLARE(ns2_lcpll_ports_clk, "brcm,ns2-lcpll-ports", 27862306a36Sopenharmony_ci ns2_lcpll_ports_clk_init); 279