18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (C) 2015 Broadcom Corporation
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
58c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License as
68c2ecf20Sopenharmony_ci * published by the Free Software Foundation version 2.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This program is distributed "as is" WITHOUT ANY WARRANTY of any
98c2ecf20Sopenharmony_ci * kind, whether express or implied; without even the implied warranty
108c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
118c2ecf20Sopenharmony_ci * GNU General Public License for more details.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/kernel.h>
158c2ecf20Sopenharmony_ci#include <linux/err.h>
168c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
178c2ecf20Sopenharmony_ci#include <linux/io.h>
188c2ecf20Sopenharmony_ci#include <linux/of.h>
198c2ecf20Sopenharmony_ci#include <linux/of_address.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <dt-bindings/clock/bcm-nsp.h>
228c2ecf20Sopenharmony_ci#include "clk-iproc.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define REG_VAL(o, s, w) { .offset = o, .shift = s, .width = w, }
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define AON_VAL(o, pw, ps, is) { .offset = o, .pwr_width = pw, \
278c2ecf20Sopenharmony_ci	.pwr_shift = ps, .iso_shift = is }
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define RESET_VAL(o, rs, prs) { .offset = o, .reset_shift = rs, \
308c2ecf20Sopenharmony_ci	.p_reset_shift = prs }
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define DF_VAL(o, kis, kiw, kps, kpw, kas, kaw) { .offset = o, .ki_shift = kis,\
338c2ecf20Sopenharmony_ci	.ki_width = kiw, .kp_shift = kps, .kp_width = kpw, .ka_shift = kas,    \
348c2ecf20Sopenharmony_ci	.ka_width = kaw }
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \
378c2ecf20Sopenharmony_ci	.hold_shift = hs, .bypass_shift = bs }
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistatic void __init nsp_armpll_init(struct device_node *node)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	iproc_armpll_setup(node);
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ciCLK_OF_DECLARE(nsp_armpll, "brcm,nsp-armpll", nsp_armpll_init);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic const struct iproc_pll_ctrl genpll = {
468c2ecf20Sopenharmony_ci	.flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL,
478c2ecf20Sopenharmony_ci	.aon = AON_VAL(0x0, 1, 12, 0),
488c2ecf20Sopenharmony_ci	.reset = RESET_VAL(0x0, 11, 10),
498c2ecf20Sopenharmony_ci	.dig_filter = DF_VAL(0x0, 4, 3, 0, 4, 7, 3),
508c2ecf20Sopenharmony_ci	.ndiv_int = REG_VAL(0x14, 20, 10),
518c2ecf20Sopenharmony_ci	.ndiv_frac = REG_VAL(0x14, 0, 20),
528c2ecf20Sopenharmony_ci	.pdiv = REG_VAL(0x18, 24, 3),
538c2ecf20Sopenharmony_ci	.status = REG_VAL(0x20, 12, 1),
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic const struct iproc_clk_ctrl genpll_clk[] = {
578c2ecf20Sopenharmony_ci	[BCM_NSP_GENPLL_PHY_CLK] = {
588c2ecf20Sopenharmony_ci		.channel = BCM_NSP_GENPLL_PHY_CLK,
598c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
608c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x4, 12, 6, 18),
618c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x18, 16, 8),
628c2ecf20Sopenharmony_ci	},
638c2ecf20Sopenharmony_ci	[BCM_NSP_GENPLL_ENET_SW_CLK] = {
648c2ecf20Sopenharmony_ci		.channel = BCM_NSP_GENPLL_ENET_SW_CLK,
658c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
668c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x4, 13, 7, 19),
678c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x18, 8, 8),
688c2ecf20Sopenharmony_ci	},
698c2ecf20Sopenharmony_ci	[BCM_NSP_GENPLL_USB_PHY_REF_CLK] = {
708c2ecf20Sopenharmony_ci		.channel = BCM_NSP_GENPLL_USB_PHY_REF_CLK,
718c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
728c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x4, 14, 8, 20),
738c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x18, 0, 8),
748c2ecf20Sopenharmony_ci	},
758c2ecf20Sopenharmony_ci	[BCM_NSP_GENPLL_IPROCFAST_CLK] = {
768c2ecf20Sopenharmony_ci		.channel = BCM_NSP_GENPLL_IPROCFAST_CLK,
778c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
788c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x4, 15, 9, 21),
798c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x1c, 16, 8),
808c2ecf20Sopenharmony_ci	},
818c2ecf20Sopenharmony_ci	[BCM_NSP_GENPLL_SATA1_CLK] = {
828c2ecf20Sopenharmony_ci		.channel = BCM_NSP_GENPLL_SATA1_CLK,
838c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
848c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x4, 16, 10, 22),
858c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x1c, 8, 8),
868c2ecf20Sopenharmony_ci	},
878c2ecf20Sopenharmony_ci	[BCM_NSP_GENPLL_SATA2_CLK] = {
888c2ecf20Sopenharmony_ci		.channel = BCM_NSP_GENPLL_SATA2_CLK,
898c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
908c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x4, 17, 11, 23),
918c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x1c, 0, 8),
928c2ecf20Sopenharmony_ci	},
938c2ecf20Sopenharmony_ci};
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic void __init nsp_genpll_clk_init(struct device_node *node)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	iproc_pll_clk_setup(node, &genpll, NULL, 0, genpll_clk,
988c2ecf20Sopenharmony_ci			    ARRAY_SIZE(genpll_clk));
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ciCLK_OF_DECLARE(nsp_genpll_clk, "brcm,nsp-genpll", nsp_genpll_clk_init);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistatic const struct iproc_pll_ctrl lcpll0 = {
1038c2ecf20Sopenharmony_ci	.flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL,
1048c2ecf20Sopenharmony_ci	.aon = AON_VAL(0x0, 1, 24, 0),
1058c2ecf20Sopenharmony_ci	.reset = RESET_VAL(0x0, 23, 22),
1068c2ecf20Sopenharmony_ci	.dig_filter = DF_VAL(0x0, 16, 3, 12, 4, 19, 4),
1078c2ecf20Sopenharmony_ci	.ndiv_int = REG_VAL(0x4, 20, 8),
1088c2ecf20Sopenharmony_ci	.ndiv_frac = REG_VAL(0x4, 0, 20),
1098c2ecf20Sopenharmony_ci	.pdiv = REG_VAL(0x4, 28, 3),
1108c2ecf20Sopenharmony_ci	.status = REG_VAL(0x10, 12, 1),
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic const struct iproc_clk_ctrl lcpll0_clk[] = {
1148c2ecf20Sopenharmony_ci	[BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK] = {
1158c2ecf20Sopenharmony_ci		.channel = BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK,
1168c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
1178c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x0, 6, 3, 9),
1188c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x8, 24, 8),
1198c2ecf20Sopenharmony_ci	},
1208c2ecf20Sopenharmony_ci	[BCM_NSP_LCPLL0_SDIO_CLK] = {
1218c2ecf20Sopenharmony_ci		.channel = BCM_NSP_LCPLL0_SDIO_CLK,
1228c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
1238c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x0, 7, 4, 10),
1248c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x8, 16, 8),
1258c2ecf20Sopenharmony_ci	},
1268c2ecf20Sopenharmony_ci	[BCM_NSP_LCPLL0_DDR_PHY_CLK] = {
1278c2ecf20Sopenharmony_ci		.channel = BCM_NSP_LCPLL0_DDR_PHY_CLK,
1288c2ecf20Sopenharmony_ci		.flags = IPROC_CLK_AON,
1298c2ecf20Sopenharmony_ci		.enable = ENABLE_VAL(0x0, 8, 5, 11),
1308c2ecf20Sopenharmony_ci		.mdiv = REG_VAL(0x8, 8, 8),
1318c2ecf20Sopenharmony_ci	},
1328c2ecf20Sopenharmony_ci};
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic void __init nsp_lcpll0_clk_init(struct device_node *node)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	iproc_pll_clk_setup(node, &lcpll0, NULL, 0, lcpll0_clk,
1378c2ecf20Sopenharmony_ci			    ARRAY_SIZE(lcpll0_clk));
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ciCLK_OF_DECLARE(nsp_lcpll0_clk, "brcm,nsp-lcpll0", nsp_lcpll0_clk_init);
140