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-nsp.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 ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \ 2762306a36Sopenharmony_ci .hold_shift = hs, .bypass_shift = bs } 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cistatic void __init nsp_armpll_init(struct device_node *node) 3062306a36Sopenharmony_ci{ 3162306a36Sopenharmony_ci iproc_armpll_setup(node); 3262306a36Sopenharmony_ci} 3362306a36Sopenharmony_ciCLK_OF_DECLARE(nsp_armpll, "brcm,nsp-armpll", nsp_armpll_init); 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cistatic const struct iproc_pll_ctrl genpll = { 3662306a36Sopenharmony_ci .flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL, 3762306a36Sopenharmony_ci .aon = AON_VAL(0x0, 1, 12, 0), 3862306a36Sopenharmony_ci .reset = RESET_VAL(0x0, 11, 10), 3962306a36Sopenharmony_ci .dig_filter = DF_VAL(0x0, 4, 3, 0, 4, 7, 3), 4062306a36Sopenharmony_ci .ndiv_int = REG_VAL(0x14, 20, 10), 4162306a36Sopenharmony_ci .ndiv_frac = REG_VAL(0x14, 0, 20), 4262306a36Sopenharmony_ci .pdiv = REG_VAL(0x18, 24, 3), 4362306a36Sopenharmony_ci .status = REG_VAL(0x20, 12, 1), 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cistatic const struct iproc_clk_ctrl genpll_clk[] = { 4762306a36Sopenharmony_ci [BCM_NSP_GENPLL_PHY_CLK] = { 4862306a36Sopenharmony_ci .channel = BCM_NSP_GENPLL_PHY_CLK, 4962306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 5062306a36Sopenharmony_ci .enable = ENABLE_VAL(0x4, 12, 6, 18), 5162306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 16, 8), 5262306a36Sopenharmony_ci }, 5362306a36Sopenharmony_ci [BCM_NSP_GENPLL_ENET_SW_CLK] = { 5462306a36Sopenharmony_ci .channel = BCM_NSP_GENPLL_ENET_SW_CLK, 5562306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 5662306a36Sopenharmony_ci .enable = ENABLE_VAL(0x4, 13, 7, 19), 5762306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 8, 8), 5862306a36Sopenharmony_ci }, 5962306a36Sopenharmony_ci [BCM_NSP_GENPLL_USB_PHY_REF_CLK] = { 6062306a36Sopenharmony_ci .channel = BCM_NSP_GENPLL_USB_PHY_REF_CLK, 6162306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 6262306a36Sopenharmony_ci .enable = ENABLE_VAL(0x4, 14, 8, 20), 6362306a36Sopenharmony_ci .mdiv = REG_VAL(0x18, 0, 8), 6462306a36Sopenharmony_ci }, 6562306a36Sopenharmony_ci [BCM_NSP_GENPLL_IPROCFAST_CLK] = { 6662306a36Sopenharmony_ci .channel = BCM_NSP_GENPLL_IPROCFAST_CLK, 6762306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 6862306a36Sopenharmony_ci .enable = ENABLE_VAL(0x4, 15, 9, 21), 6962306a36Sopenharmony_ci .mdiv = REG_VAL(0x1c, 16, 8), 7062306a36Sopenharmony_ci }, 7162306a36Sopenharmony_ci [BCM_NSP_GENPLL_SATA1_CLK] = { 7262306a36Sopenharmony_ci .channel = BCM_NSP_GENPLL_SATA1_CLK, 7362306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 7462306a36Sopenharmony_ci .enable = ENABLE_VAL(0x4, 16, 10, 22), 7562306a36Sopenharmony_ci .mdiv = REG_VAL(0x1c, 8, 8), 7662306a36Sopenharmony_ci }, 7762306a36Sopenharmony_ci [BCM_NSP_GENPLL_SATA2_CLK] = { 7862306a36Sopenharmony_ci .channel = BCM_NSP_GENPLL_SATA2_CLK, 7962306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 8062306a36Sopenharmony_ci .enable = ENABLE_VAL(0x4, 17, 11, 23), 8162306a36Sopenharmony_ci .mdiv = REG_VAL(0x1c, 0, 8), 8262306a36Sopenharmony_ci }, 8362306a36Sopenharmony_ci}; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_cistatic void __init nsp_genpll_clk_init(struct device_node *node) 8662306a36Sopenharmony_ci{ 8762306a36Sopenharmony_ci iproc_pll_clk_setup(node, &genpll, NULL, 0, genpll_clk, 8862306a36Sopenharmony_ci ARRAY_SIZE(genpll_clk)); 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ciCLK_OF_DECLARE(nsp_genpll_clk, "brcm,nsp-genpll", nsp_genpll_clk_init); 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistatic const struct iproc_pll_ctrl lcpll0 = { 9362306a36Sopenharmony_ci .flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL, 9462306a36Sopenharmony_ci .aon = AON_VAL(0x0, 1, 24, 0), 9562306a36Sopenharmony_ci .reset = RESET_VAL(0x0, 23, 22), 9662306a36Sopenharmony_ci .dig_filter = DF_VAL(0x0, 16, 3, 12, 4, 19, 4), 9762306a36Sopenharmony_ci .ndiv_int = REG_VAL(0x4, 20, 8), 9862306a36Sopenharmony_ci .ndiv_frac = REG_VAL(0x4, 0, 20), 9962306a36Sopenharmony_ci .pdiv = REG_VAL(0x4, 28, 3), 10062306a36Sopenharmony_ci .status = REG_VAL(0x10, 12, 1), 10162306a36Sopenharmony_ci}; 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_cistatic const struct iproc_clk_ctrl lcpll0_clk[] = { 10462306a36Sopenharmony_ci [BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK] = { 10562306a36Sopenharmony_ci .channel = BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK, 10662306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 10762306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 6, 3, 9), 10862306a36Sopenharmony_ci .mdiv = REG_VAL(0x8, 24, 8), 10962306a36Sopenharmony_ci }, 11062306a36Sopenharmony_ci [BCM_NSP_LCPLL0_SDIO_CLK] = { 11162306a36Sopenharmony_ci .channel = BCM_NSP_LCPLL0_SDIO_CLK, 11262306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 11362306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 7, 4, 10), 11462306a36Sopenharmony_ci .mdiv = REG_VAL(0x8, 16, 8), 11562306a36Sopenharmony_ci }, 11662306a36Sopenharmony_ci [BCM_NSP_LCPLL0_DDR_PHY_CLK] = { 11762306a36Sopenharmony_ci .channel = BCM_NSP_LCPLL0_DDR_PHY_CLK, 11862306a36Sopenharmony_ci .flags = IPROC_CLK_AON, 11962306a36Sopenharmony_ci .enable = ENABLE_VAL(0x0, 8, 5, 11), 12062306a36Sopenharmony_ci .mdiv = REG_VAL(0x8, 8, 8), 12162306a36Sopenharmony_ci }, 12262306a36Sopenharmony_ci}; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_cistatic void __init nsp_lcpll0_clk_init(struct device_node *node) 12562306a36Sopenharmony_ci{ 12662306a36Sopenharmony_ci iproc_pll_clk_setup(node, &lcpll0, NULL, 0, lcpll0_clk, 12762306a36Sopenharmony_ci ARRAY_SIZE(lcpll0_clk)); 12862306a36Sopenharmony_ci} 12962306a36Sopenharmony_ciCLK_OF_DECLARE(nsp_lcpll0_clk, "brcm,nsp-lcpll0", nsp_lcpll0_clk_init); 130