11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22fc0a509SSean Wang /*
32fc0a509SSean Wang  * Copyright (c) 2017 MediaTek Inc.
42fc0a509SSean Wang  * Author: Chen Zhong <chen.zhong@mediatek.com>
52fc0a509SSean Wang  *	   Sean Wang <sean.wang@mediatek.com>
62fc0a509SSean Wang  */
72fc0a509SSean Wang 
82fc0a509SSean Wang #include <linux/clk-provider.h>
9*a96cbb14SRob Herring #include <linux/mod_devicetable.h>
102fc0a509SSean Wang #include <linux/platform_device.h>
112fc0a509SSean Wang 
122fc0a509SSean Wang #include "clk-mtk.h"
132fc0a509SSean Wang #include "clk-gate.h"
142fc0a509SSean Wang 
152fc0a509SSean Wang #include <dt-bindings/clock/mt7622-clk.h>
162fc0a509SSean Wang 
174c85e20bSAngeloGioacchino Del Regno #define GATE_PCIE(_id, _name, _parent, _shift)				\
184c85e20bSAngeloGioacchino Del Regno 	GATE_MTK(_id, _name, _parent, &pcie_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
192fc0a509SSean Wang 
204c85e20bSAngeloGioacchino Del Regno #define GATE_SSUSB(_id, _name, _parent, _shift)				\
214c85e20bSAngeloGioacchino Del Regno 	GATE_MTK(_id, _name, _parent, &ssusb_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
222fc0a509SSean Wang 
232fc0a509SSean Wang static const struct mtk_gate_regs pcie_cg_regs = {
242fc0a509SSean Wang 	.set_ofs = 0x30,
252fc0a509SSean Wang 	.clr_ofs = 0x30,
262fc0a509SSean Wang 	.sta_ofs = 0x30,
272fc0a509SSean Wang };
282fc0a509SSean Wang 
292fc0a509SSean Wang static const struct mtk_gate_regs ssusb_cg_regs = {
302fc0a509SSean Wang 	.set_ofs = 0x30,
312fc0a509SSean Wang 	.clr_ofs = 0x30,
322fc0a509SSean Wang 	.sta_ofs = 0x30,
332fc0a509SSean Wang };
342fc0a509SSean Wang 
352fc0a509SSean Wang static const struct mtk_gate ssusb_clks[] = {
362fc0a509SSean Wang 	GATE_SSUSB(CLK_SSUSB_U2_PHY_1P_EN, "ssusb_u2_phy_1p",
372fc0a509SSean Wang 		   "to_u2_phy_1p", 0),
382fc0a509SSean Wang 	GATE_SSUSB(CLK_SSUSB_U2_PHY_EN, "ssusb_u2_phy_en", "to_u2_phy", 1),
392fc0a509SSean Wang 	GATE_SSUSB(CLK_SSUSB_REF_EN, "ssusb_ref_en", "to_usb3_ref", 5),
402fc0a509SSean Wang 	GATE_SSUSB(CLK_SSUSB_SYS_EN, "ssusb_sys_en", "to_usb3_sys", 6),
412fc0a509SSean Wang 	GATE_SSUSB(CLK_SSUSB_MCU_EN, "ssusb_mcu_en", "axi_sel", 7),
422fc0a509SSean Wang 	GATE_SSUSB(CLK_SSUSB_DMA_EN, "ssusb_dma_en", "hif_sel", 8),
432fc0a509SSean Wang };
442fc0a509SSean Wang 
452fc0a509SSean Wang static const struct mtk_gate pcie_clks[] = {
462fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P1_AUX_EN, "pcie_p1_aux_en", "p1_1mhz", 12),
472fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P1_OBFF_EN, "pcie_p1_obff_en", "free_run_4mhz", 13),
482fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P1_AHB_EN, "pcie_p1_ahb_en", "axi_sel", 14),
492fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P1_AXI_EN, "pcie_p1_axi_en", "hif_sel", 15),
502fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P1_MAC_EN, "pcie_p1_mac_en", "pcie1_mac_en", 16),
512fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P1_PIPE_EN, "pcie_p1_pipe_en", "pcie1_pipe_en", 17),
522fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P0_AUX_EN, "pcie_p0_aux_en", "p0_1mhz", 18),
532fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P0_OBFF_EN, "pcie_p0_obff_en", "free_run_4mhz", 19),
542fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P0_AHB_EN, "pcie_p0_ahb_en", "axi_sel", 20),
552fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P0_AXI_EN, "pcie_p0_axi_en", "hif_sel", 21),
562fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P0_MAC_EN, "pcie_p0_mac_en", "pcie0_mac_en", 22),
572fc0a509SSean Wang 	GATE_PCIE(CLK_PCIE_P0_PIPE_EN, "pcie_p0_pipe_en", "pcie0_pipe_en", 23),
582fc0a509SSean Wang 	GATE_PCIE(CLK_SATA_AHB_EN, "sata_ahb_en", "axi_sel", 26),
592fc0a509SSean Wang 	GATE_PCIE(CLK_SATA_AXI_EN, "sata_axi_en", "hif_sel", 27),
602fc0a509SSean Wang 	GATE_PCIE(CLK_SATA_ASIC_EN, "sata_asic_en", "sata_asic", 28),
612fc0a509SSean Wang 	GATE_PCIE(CLK_SATA_RBC_EN, "sata_rbc_en", "sata_rbc", 29),
622fc0a509SSean Wang 	GATE_PCIE(CLK_SATA_PM_EN, "sata_pm_en", "univpll2_d4", 30),
632fc0a509SSean Wang };
642fc0a509SSean Wang 
65723e3671SRex-BC Chen static u16 rst_ofs[] = { 0x34, };
66723e3671SRex-BC Chen 
672d2a2900SRex-BC Chen static const struct mtk_clk_rst_desc clk_rst_desc = {
682d2a2900SRex-BC Chen 	.version = MTK_RST_SIMPLE,
69723e3671SRex-BC Chen 	.rst_bank_ofs = rst_ofs,
70723e3671SRex-BC Chen 	.rst_bank_nr = ARRAY_SIZE(rst_ofs),
712d2a2900SRex-BC Chen };
722d2a2900SRex-BC Chen 
730f69a423SAngeloGioacchino Del Regno static const struct mtk_clk_desc ssusb_desc = {
740f69a423SAngeloGioacchino Del Regno 	.clks = ssusb_clks,
750f69a423SAngeloGioacchino Del Regno 	.num_clks = ARRAY_SIZE(ssusb_clks),
760f69a423SAngeloGioacchino Del Regno 	.rst_desc = &clk_rst_desc,
772fc0a509SSean Wang };
782fc0a509SSean Wang 
790f69a423SAngeloGioacchino Del Regno static const struct mtk_clk_desc pcie_desc = {
800f69a423SAngeloGioacchino Del Regno 	.clks = pcie_clks,
810f69a423SAngeloGioacchino Del Regno 	.num_clks = ARRAY_SIZE(pcie_clks),
820f69a423SAngeloGioacchino Del Regno 	.rst_desc = &clk_rst_desc,
830f69a423SAngeloGioacchino Del Regno };
842fc0a509SSean Wang 
850f69a423SAngeloGioacchino Del Regno static const struct of_device_id of_match_clk_mt7622_hif[] = {
860f69a423SAngeloGioacchino Del Regno 	{ .compatible = "mediatek,mt7622-pciesys", .data = &pcie_desc },
870f69a423SAngeloGioacchino Del Regno 	{ .compatible = "mediatek,mt7622-ssusbsys", .data = &ssusb_desc },
880f69a423SAngeloGioacchino Del Regno 	{ /* sentinel */ }
890f69a423SAngeloGioacchino Del Regno };
9065c9ad77SAngeloGioacchino Del Regno MODULE_DEVICE_TABLE(of, of_match_clk_mt7622_hif);
912fc0a509SSean Wang 
922fc0a509SSean Wang static struct platform_driver clk_mt7622_hif_drv = {
930f69a423SAngeloGioacchino Del Regno 	.probe = mtk_clk_simple_probe,
9461ca6ee7SUwe Kleine-König 	.remove_new = mtk_clk_simple_remove,
952fc0a509SSean Wang 	.driver = {
962fc0a509SSean Wang 		.name = "clk-mt7622-hif",
972fc0a509SSean Wang 		.of_match_table = of_match_clk_mt7622_hif,
982fc0a509SSean Wang 	},
992fc0a509SSean Wang };
100164d240dSAngeloGioacchino Del Regno module_platform_driver(clk_mt7622_hif_drv);
101a451da86SAngeloGioacchino Del Regno MODULE_LICENSE("GPL");
102