xref: /openbmc/linux/drivers/clk/bcm/clk-nsp.c (revision 52e6676e)
1*52e6676eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2*52e6676eSThomas Gleixner // Copyright (C) 2015 Broadcom Corporation
35f024b06SJon Mason 
45f024b06SJon Mason #include <linux/kernel.h>
55f024b06SJon Mason #include <linux/err.h>
65f024b06SJon Mason #include <linux/clk-provider.h>
75f024b06SJon Mason #include <linux/io.h>
85f024b06SJon Mason #include <linux/of.h>
95f024b06SJon Mason #include <linux/of_address.h>
105f024b06SJon Mason 
115f024b06SJon Mason #include <dt-bindings/clock/bcm-nsp.h>
125f024b06SJon Mason #include "clk-iproc.h"
135f024b06SJon Mason 
145f024b06SJon Mason #define REG_VAL(o, s, w) { .offset = o, .shift = s, .width = w, }
155f024b06SJon Mason 
165f024b06SJon Mason #define AON_VAL(o, pw, ps, is) { .offset = o, .pwr_width = pw, \
175f024b06SJon Mason 	.pwr_shift = ps, .iso_shift = is }
185f024b06SJon Mason 
19f713c6bfSJon Mason #define RESET_VAL(o, rs, prs) { .offset = o, .reset_shift = rs, \
20f713c6bfSJon Mason 	.p_reset_shift = prs }
21f713c6bfSJon Mason 
22f713c6bfSJon Mason #define DF_VAL(o, kis, kiw, kps, kpw, kas, kaw) { .offset = o, .ki_shift = kis,\
235f024b06SJon Mason 	.ki_width = kiw, .kp_shift = kps, .kp_width = kpw, .ka_shift = kas,    \
245f024b06SJon Mason 	.ka_width = kaw }
255f024b06SJon Mason 
265f024b06SJon Mason #define ENABLE_VAL(o, es, hs, bs) { .offset = o, .enable_shift = es, \
275f024b06SJon Mason 	.hold_shift = hs, .bypass_shift = bs }
285f024b06SJon Mason 
nsp_armpll_init(struct device_node * node)295f024b06SJon Mason static void __init nsp_armpll_init(struct device_node *node)
305f024b06SJon Mason {
315f024b06SJon Mason 	iproc_armpll_setup(node);
325f024b06SJon Mason }
335f024b06SJon Mason CLK_OF_DECLARE(nsp_armpll, "brcm,nsp-armpll", nsp_armpll_init);
345f024b06SJon Mason 
355f024b06SJon Mason static const struct iproc_pll_ctrl genpll = {
365f024b06SJon Mason 	.flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL,
375f024b06SJon Mason 	.aon = AON_VAL(0x0, 1, 12, 0),
38f713c6bfSJon Mason 	.reset = RESET_VAL(0x0, 11, 10),
39f713c6bfSJon Mason 	.dig_filter = DF_VAL(0x0, 4, 3, 0, 4, 7, 3),
405f024b06SJon Mason 	.ndiv_int = REG_VAL(0x14, 20, 10),
415f024b06SJon Mason 	.ndiv_frac = REG_VAL(0x14, 0, 20),
425f024b06SJon Mason 	.pdiv = REG_VAL(0x18, 24, 3),
435f024b06SJon Mason 	.status = REG_VAL(0x20, 12, 1),
445f024b06SJon Mason };
455f024b06SJon Mason 
465f024b06SJon Mason static const struct iproc_clk_ctrl genpll_clk[] = {
475f024b06SJon Mason 	[BCM_NSP_GENPLL_PHY_CLK] = {
485f024b06SJon Mason 		.channel = BCM_NSP_GENPLL_PHY_CLK,
495f024b06SJon Mason 		.flags = IPROC_CLK_AON,
505f024b06SJon Mason 		.enable = ENABLE_VAL(0x4, 12, 6, 18),
515f024b06SJon Mason 		.mdiv = REG_VAL(0x18, 16, 8),
525f024b06SJon Mason 	},
535f024b06SJon Mason 	[BCM_NSP_GENPLL_ENET_SW_CLK] = {
545f024b06SJon Mason 		.channel = BCM_NSP_GENPLL_ENET_SW_CLK,
555f024b06SJon Mason 		.flags = IPROC_CLK_AON,
565f024b06SJon Mason 		.enable = ENABLE_VAL(0x4, 13, 7, 19),
575f024b06SJon Mason 		.mdiv = REG_VAL(0x18, 8, 8),
585f024b06SJon Mason 	},
595f024b06SJon Mason 	[BCM_NSP_GENPLL_USB_PHY_REF_CLK] = {
605f024b06SJon Mason 		.channel = BCM_NSP_GENPLL_USB_PHY_REF_CLK,
615f024b06SJon Mason 		.flags = IPROC_CLK_AON,
625f024b06SJon Mason 		.enable = ENABLE_VAL(0x4, 14, 8, 20),
635f024b06SJon Mason 		.mdiv = REG_VAL(0x18, 0, 8),
645f024b06SJon Mason 	},
655f024b06SJon Mason 	[BCM_NSP_GENPLL_IPROCFAST_CLK] = {
665f024b06SJon Mason 		.channel = BCM_NSP_GENPLL_IPROCFAST_CLK,
675f024b06SJon Mason 		.flags = IPROC_CLK_AON,
685f024b06SJon Mason 		.enable = ENABLE_VAL(0x4, 15, 9, 21),
695f024b06SJon Mason 		.mdiv = REG_VAL(0x1c, 16, 8),
705f024b06SJon Mason 	},
715f024b06SJon Mason 	[BCM_NSP_GENPLL_SATA1_CLK] = {
725f024b06SJon Mason 		.channel = BCM_NSP_GENPLL_SATA1_CLK,
735f024b06SJon Mason 		.flags = IPROC_CLK_AON,
745f024b06SJon Mason 		.enable = ENABLE_VAL(0x4, 16, 10, 22),
755f024b06SJon Mason 		.mdiv = REG_VAL(0x1c, 8, 8),
765f024b06SJon Mason 	},
775f024b06SJon Mason 	[BCM_NSP_GENPLL_SATA2_CLK] = {
785f024b06SJon Mason 		.channel = BCM_NSP_GENPLL_SATA2_CLK,
795f024b06SJon Mason 		.flags = IPROC_CLK_AON,
805f024b06SJon Mason 		.enable = ENABLE_VAL(0x4, 17, 11, 23),
815f024b06SJon Mason 		.mdiv = REG_VAL(0x1c, 0, 8),
825f024b06SJon Mason 	},
835f024b06SJon Mason };
845f024b06SJon Mason 
nsp_genpll_clk_init(struct device_node * node)855f024b06SJon Mason static void __init nsp_genpll_clk_init(struct device_node *node)
865f024b06SJon Mason {
875f024b06SJon Mason 	iproc_pll_clk_setup(node, &genpll, NULL, 0, genpll_clk,
885f024b06SJon Mason 			    ARRAY_SIZE(genpll_clk));
895f024b06SJon Mason }
905f024b06SJon Mason CLK_OF_DECLARE(nsp_genpll_clk, "brcm,nsp-genpll", nsp_genpll_clk_init);
915f024b06SJon Mason 
925f024b06SJon Mason static const struct iproc_pll_ctrl lcpll0 = {
935f024b06SJon Mason 	.flags = IPROC_CLK_PLL_HAS_NDIV_FRAC | IPROC_CLK_EMBED_PWRCTRL,
945f024b06SJon Mason 	.aon = AON_VAL(0x0, 1, 24, 0),
95f713c6bfSJon Mason 	.reset = RESET_VAL(0x0, 23, 22),
96f713c6bfSJon Mason 	.dig_filter = DF_VAL(0x0, 16, 3, 12, 4, 19, 4),
975f024b06SJon Mason 	.ndiv_int = REG_VAL(0x4, 20, 8),
985f024b06SJon Mason 	.ndiv_frac = REG_VAL(0x4, 0, 20),
995f024b06SJon Mason 	.pdiv = REG_VAL(0x4, 28, 3),
1005f024b06SJon Mason 	.status = REG_VAL(0x10, 12, 1),
1015f024b06SJon Mason };
1025f024b06SJon Mason 
1035f024b06SJon Mason static const struct iproc_clk_ctrl lcpll0_clk[] = {
1045f024b06SJon Mason 	[BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK] = {
1055f024b06SJon Mason 		.channel = BCM_NSP_LCPLL0_PCIE_PHY_REF_CLK,
1065f024b06SJon Mason 		.flags = IPROC_CLK_AON,
1075f024b06SJon Mason 		.enable = ENABLE_VAL(0x0, 6, 3, 9),
1085f024b06SJon Mason 		.mdiv = REG_VAL(0x8, 24, 8),
1095f024b06SJon Mason 	},
1105f024b06SJon Mason 	[BCM_NSP_LCPLL0_SDIO_CLK] = {
1115f024b06SJon Mason 		.channel = BCM_NSP_LCPLL0_SDIO_CLK,
1125f024b06SJon Mason 		.flags = IPROC_CLK_AON,
1135f024b06SJon Mason 		.enable = ENABLE_VAL(0x0, 7, 4, 10),
1145f024b06SJon Mason 		.mdiv = REG_VAL(0x8, 16, 8),
1155f024b06SJon Mason 	},
1165f024b06SJon Mason 	[BCM_NSP_LCPLL0_DDR_PHY_CLK] = {
1175f024b06SJon Mason 		.channel = BCM_NSP_LCPLL0_DDR_PHY_CLK,
1185f024b06SJon Mason 		.flags = IPROC_CLK_AON,
1195f024b06SJon Mason 		.enable = ENABLE_VAL(0x0, 8, 5, 11),
1205f024b06SJon Mason 		.mdiv = REG_VAL(0x8, 8, 8),
1215f024b06SJon Mason 	},
1225f024b06SJon Mason };
1235f024b06SJon Mason 
nsp_lcpll0_clk_init(struct device_node * node)1245f024b06SJon Mason static void __init nsp_lcpll0_clk_init(struct device_node *node)
1255f024b06SJon Mason {
1265f024b06SJon Mason 	iproc_pll_clk_setup(node, &lcpll0, NULL, 0, lcpll0_clk,
1275f024b06SJon Mason 			    ARRAY_SIZE(lcpll0_clk));
1285f024b06SJon Mason }
1295f024b06SJon Mason CLK_OF_DECLARE(nsp_lcpll0_clk, "brcm,nsp-lcpll0", nsp_lcpll0_clk_init);
130