xref: /linux/drivers/clk/mediatek/clk-mt7988-eth.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
14b471943SSam Shih // SPDX-License-Identifier: GPL-2.0
24b471943SSam Shih /*
34b471943SSam Shih  * Copyright (c) 2023 MediaTek Inc.
44b471943SSam Shih  * Author: Sam Shih <sam.shih@mediatek.com>
54b471943SSam Shih  * Author: Xiufeng Li <Xiufeng.Li@mediatek.com>
64b471943SSam Shih  */
74b471943SSam Shih 
84b471943SSam Shih #include <linux/clk-provider.h>
94b471943SSam Shih #include <linux/of.h>
104b471943SSam Shih #include <linux/of_address.h>
114b471943SSam Shih #include <linux/of_device.h>
124b471943SSam Shih #include <linux/platform_device.h>
134b471943SSam Shih #include "clk-mtk.h"
144b471943SSam Shih #include "clk-gate.h"
154b471943SSam Shih #include "reset.h"
164b471943SSam Shih #include <dt-bindings/clock/mediatek,mt7988-clk.h>
174b471943SSam Shih #include <dt-bindings/reset/mediatek,mt7988-resets.h>
184b471943SSam Shih 
194b471943SSam Shih static const struct mtk_gate_regs ethdma_cg_regs = {
204b471943SSam Shih 	.set_ofs = 0x30,
214b471943SSam Shih 	.clr_ofs = 0x30,
224b471943SSam Shih 	.sta_ofs = 0x30,
234b471943SSam Shih };
244b471943SSam Shih 
254b471943SSam Shih #define GATE_ETHDMA(_id, _name, _parent, _shift)		\
264b471943SSam Shih 	{							\
274b471943SSam Shih 		.id = _id,					\
284b471943SSam Shih 		.name = _name,					\
294b471943SSam Shih 		.parent_name = _parent,				\
304b471943SSam Shih 		.regs = &ethdma_cg_regs,			\
314b471943SSam Shih 		.shift = _shift,				\
324b471943SSam Shih 		.ops = &mtk_clk_gate_ops_no_setclr_inv,		\
334b471943SSam Shih 	}
344b471943SSam Shih 
354b471943SSam Shih static const struct mtk_gate ethdma_clks[] = {
364b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_XGP1_EN, "ethdma_xgp1_en", "top_xtal", 0),
374b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_XGP2_EN, "ethdma_xgp2_en", "top_xtal", 1),
384b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_XGP3_EN, "ethdma_xgp3_en", "top_xtal", 2),
394b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_FE_EN, "ethdma_fe_en", "netsys_2x_sel", 6),
404b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_GP2_EN, "ethdma_gp2_en", "top_xtal", 7),
414b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_GP1_EN, "ethdma_gp1_en", "top_xtal", 8),
424b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_GP3_EN, "ethdma_gp3_en", "top_xtal", 10),
434b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_ESW_EN, "ethdma_esw_en", "netsys_gsw_sel", 16),
444b471943SSam Shih 	GATE_ETHDMA(CLK_ETHDMA_CRYPT0_EN, "ethdma_crypt0_en", "eip197_sel", 29),
454b471943SSam Shih };
464b471943SSam Shih 
474b471943SSam Shih static const struct mtk_clk_desc ethdma_desc = {
484b471943SSam Shih 	.clks = ethdma_clks,
494b471943SSam Shih 	.num_clks = ARRAY_SIZE(ethdma_clks),
504b471943SSam Shih };
514b471943SSam Shih 
524b471943SSam Shih static const struct mtk_gate_regs sgmii_cg_regs = {
534b471943SSam Shih 	.set_ofs = 0xe4,
544b471943SSam Shih 	.clr_ofs = 0xe4,
554b471943SSam Shih 	.sta_ofs = 0xe4,
564b471943SSam Shih };
574b471943SSam Shih 
584b471943SSam Shih #define GATE_SGMII(_id, _name, _parent, _shift)			\
594b471943SSam Shih 	{							\
604b471943SSam Shih 		.id = _id,					\
614b471943SSam Shih 		.name = _name,					\
624b471943SSam Shih 		.parent_name = _parent,				\
634b471943SSam Shih 		.regs = &sgmii_cg_regs,				\
644b471943SSam Shih 		.shift = _shift,				\
654b471943SSam Shih 		.ops = &mtk_clk_gate_ops_no_setclr_inv,		\
664b471943SSam Shih 	}
674b471943SSam Shih 
684b471943SSam Shih static const struct mtk_gate sgmii0_clks[] = {
694b471943SSam Shih 	GATE_SGMII(CLK_SGM0_TX_EN, "sgm0_tx_en", "top_xtal", 2),
704b471943SSam Shih 	GATE_SGMII(CLK_SGM0_RX_EN, "sgm0_rx_en", "top_xtal", 3),
714b471943SSam Shih };
724b471943SSam Shih 
734b471943SSam Shih static const struct mtk_clk_desc sgmii0_desc = {
744b471943SSam Shih 	.clks = sgmii0_clks,
754b471943SSam Shih 	.num_clks = ARRAY_SIZE(sgmii0_clks),
764b471943SSam Shih };
774b471943SSam Shih 
784b471943SSam Shih static const struct mtk_gate sgmii1_clks[] = {
794b471943SSam Shih 	GATE_SGMII(CLK_SGM1_TX_EN, "sgm1_tx_en", "top_xtal", 2),
804b471943SSam Shih 	GATE_SGMII(CLK_SGM1_RX_EN, "sgm1_rx_en", "top_xtal", 3),
814b471943SSam Shih };
824b471943SSam Shih 
834b471943SSam Shih static const struct mtk_clk_desc sgmii1_desc = {
844b471943SSam Shih 	.clks = sgmii1_clks,
854b471943SSam Shih 	.num_clks = ARRAY_SIZE(sgmii1_clks),
864b471943SSam Shih };
874b471943SSam Shih 
884b471943SSam Shih static const struct mtk_gate_regs ethwarp_cg_regs = {
894b471943SSam Shih 	.set_ofs = 0x14,
904b471943SSam Shih 	.clr_ofs = 0x14,
914b471943SSam Shih 	.sta_ofs = 0x14,
924b471943SSam Shih };
934b471943SSam Shih 
944b471943SSam Shih #define GATE_ETHWARP(_id, _name, _parent, _shift)		\
954b471943SSam Shih 	{							\
964b471943SSam Shih 		.id = _id,					\
974b471943SSam Shih 		.name = _name,					\
984b471943SSam Shih 		.parent_name = _parent,				\
994b471943SSam Shih 		.regs = &ethwarp_cg_regs,			\
1004b471943SSam Shih 		.shift = _shift,				\
1014b471943SSam Shih 		.ops = &mtk_clk_gate_ops_no_setclr_inv,		\
1024b471943SSam Shih 	}
1034b471943SSam Shih 
1044b471943SSam Shih static const struct mtk_gate ethwarp_clks[] = {
1054b471943SSam Shih 	GATE_ETHWARP(CLK_ETHWARP_WOCPU2_EN, "ethwarp_wocpu2_en", "netsys_mcu_sel", 13),
1064b471943SSam Shih 	GATE_ETHWARP(CLK_ETHWARP_WOCPU1_EN, "ethwarp_wocpu1_en", "netsys_mcu_sel", 14),
1074b471943SSam Shih 	GATE_ETHWARP(CLK_ETHWARP_WOCPU0_EN, "ethwarp_wocpu0_en", "netsys_mcu_sel", 15),
1084b471943SSam Shih };
1094b471943SSam Shih 
1104b471943SSam Shih static u16 ethwarp_rst_ofs[] = { 0x8 };
1114b471943SSam Shih 
1124b471943SSam Shih static u16 ethwarp_idx_map[] = {
1134b471943SSam Shih 	[MT7988_ETHWARP_RST_SWITCH] = 9,
1144b471943SSam Shih };
1154b471943SSam Shih 
1164b471943SSam Shih static const struct mtk_clk_rst_desc ethwarp_rst_desc = {
1174b471943SSam Shih 	.version = MTK_RST_SIMPLE,
1184b471943SSam Shih 	.rst_bank_ofs = ethwarp_rst_ofs,
1194b471943SSam Shih 	.rst_bank_nr = ARRAY_SIZE(ethwarp_rst_ofs),
1204b471943SSam Shih 	.rst_idx_map = ethwarp_idx_map,
1214b471943SSam Shih 	.rst_idx_map_nr = ARRAY_SIZE(ethwarp_idx_map),
1224b471943SSam Shih };
1234b471943SSam Shih 
1244b471943SSam Shih static const struct mtk_clk_desc ethwarp_desc = {
1254b471943SSam Shih 	.clks = ethwarp_clks,
1264b471943SSam Shih 	.num_clks = ARRAY_SIZE(ethwarp_clks),
1274b471943SSam Shih 	.rst_desc = &ethwarp_rst_desc,
1284b471943SSam Shih };
1294b471943SSam Shih 
1304b471943SSam Shih static const struct of_device_id of_match_clk_mt7988_eth[] = {
1314b471943SSam Shih 	{ .compatible = "mediatek,mt7988-ethsys", .data = &ethdma_desc },
1324b471943SSam Shih 	{ .compatible = "mediatek,mt7988-sgmiisys0", .data = &sgmii0_desc },
1334b471943SSam Shih 	{ .compatible = "mediatek,mt7988-sgmiisys1", .data = &sgmii1_desc },
1344b471943SSam Shih 	{ .compatible = "mediatek,mt7988-ethwarp", .data = &ethwarp_desc },
1354b471943SSam Shih 	{ /* sentinel */ }
1364b471943SSam Shih };
1374b471943SSam Shih MODULE_DEVICE_TABLE(of, of_match_clk_mt7988_eth);
1384b471943SSam Shih 
1394b471943SSam Shih static struct platform_driver clk_mt7988_eth_drv = {
1404b471943SSam Shih 	.driver = {
1414b471943SSam Shih 		.name = "clk-mt7988-eth",
1424b471943SSam Shih 		.of_match_table = of_match_clk_mt7988_eth,
1434b471943SSam Shih 	},
1444b471943SSam Shih 	.probe = mtk_clk_simple_probe,
145*f00b45dbSUwe Kleine-König 	.remove = mtk_clk_simple_remove,
1464b471943SSam Shih };
1474b471943SSam Shih module_platform_driver(clk_mt7988_eth_drv);
1484b471943SSam Shih 
1494b471943SSam Shih MODULE_DESCRIPTION("MediaTek MT7988 Ethernet clocks driver");
1504b471943SSam Shih MODULE_LICENSE("GPL");
151