1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 MediaTek Inc.
4 * Author: Wenzhen Yu <Wenzhen Yu@mediatek.com>
5 * Ryder Lee <ryder.lee@mediatek.com>
8 #include <linux/clk-provider.h>
10 #include <linux/platform_device.h>
15 #include <dt-bindings/clock/mt7629-clk.h>
17 #define GATE_ETH(_id, _name, _parent, _shift) \
18 GATE_MTK(_id, _name, _parent, ð_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
20 static const struct mtk_gate_regs eth_cg_regs
= {
26 static const struct mtk_gate eth_clks
[] = {
27 GATE_ETH(CLK_ETH_FE_EN
, "eth_fe_en", "eth2pll", 6),
28 GATE_ETH(CLK_ETH_GP2_EN
, "eth_gp2_en", "txclk_src_pre", 7),
29 GATE_ETH(CLK_ETH_GP1_EN
, "eth_gp1_en", "txclk_src_pre", 8),
30 GATE_ETH(CLK_ETH_GP0_EN
, "eth_gp0_en", "txclk_src_pre", 9),
31 GATE_ETH(CLK_ETH_ESW_EN
, "eth_esw_en", "eth_500m", 16),
34 static const struct mtk_gate_regs sgmii_cg_regs
= {
40 #define GATE_SGMII(_id, _name, _parent, _shift) \
41 GATE_MTK(_id, _name, _parent, &sgmii_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
43 static const struct mtk_gate sgmii_clks
[2][4] = {
45 GATE_SGMII(CLK_SGMII_TX_EN
, "sgmii_tx_en",
47 GATE_SGMII(CLK_SGMII_RX_EN
, "sgmii_rx_en",
48 "ssusb_eq_rx250m", 3),
49 GATE_SGMII(CLK_SGMII_CDR_REF
, "sgmii_cdr_ref",
51 GATE_SGMII(CLK_SGMII_CDR_FB
, "sgmii_cdr_fb",
54 GATE_SGMII(CLK_SGMII_TX_EN
, "sgmii_tx_en1",
56 GATE_SGMII(CLK_SGMII_RX_EN
, "sgmii_rx_en1",
57 "ssusb_eq_rx250m", 3),
58 GATE_SGMII(CLK_SGMII_CDR_REF
, "sgmii_cdr_ref1",
60 GATE_SGMII(CLK_SGMII_CDR_FB
, "sgmii_cdr_fb1",
65 static u16 rst_ofs
[] = { 0x34, };
67 static const struct mtk_clk_rst_desc clk_rst_desc
= {
68 .version
= MTK_RST_SIMPLE
,
69 .rst_bank_ofs
= rst_ofs
,
70 .rst_bank_nr
= ARRAY_SIZE(rst_ofs
),
73 static int clk_mt7629_ethsys_init(struct platform_device
*pdev
)
75 struct clk_hw_onecell_data
*clk_data
;
76 struct device_node
*node
= pdev
->dev
.of_node
;
79 clk_data
= mtk_alloc_clk_data(CLK_ETH_NR_CLK
);
83 mtk_clk_register_gates(&pdev
->dev
, node
, eth_clks
,
84 CLK_ETH_NR_CLK
, clk_data
);
86 r
= of_clk_add_hw_provider(node
, of_clk_hw_onecell_get
, clk_data
);
89 "could not register clock provider: %s: %d\n",
92 mtk_register_reset_controller_with_dev(&pdev
->dev
, &clk_rst_desc
);
97 static int clk_mt7629_sgmiisys_init(struct platform_device
*pdev
)
99 struct clk_hw_onecell_data
*clk_data
;
100 struct device_node
*node
= pdev
->dev
.of_node
;
104 clk_data
= mtk_alloc_clk_data(CLK_SGMII_NR_CLK
);
108 mtk_clk_register_gates(&pdev
->dev
, node
, sgmii_clks
[id
++],
109 CLK_SGMII_NR_CLK
, clk_data
);
111 r
= of_clk_add_hw_provider(node
, of_clk_hw_onecell_get
, clk_data
);
114 "could not register clock provider: %s: %d\n",
120 static const struct of_device_id of_match_clk_mt7629_eth
[] = {
122 .compatible
= "mediatek,mt7629-ethsys",
123 .data
= clk_mt7629_ethsys_init
,
125 .compatible
= "mediatek,mt7629-sgmiisys",
126 .data
= clk_mt7629_sgmiisys_init
,
131 MODULE_DEVICE_TABLE(of
, of_match_clk_mt7629_eth
);
133 static int clk_mt7629_eth_probe(struct platform_device
*pdev
)
135 int (*clk_init
)(struct platform_device
*);
138 clk_init
= of_device_get_match_data(&pdev
->dev
);
145 "could not register clock provider: %s: %d\n",
151 static struct platform_driver clk_mt7629_eth_drv
= {
152 .probe
= clk_mt7629_eth_probe
,
154 .name
= "clk-mt7629-eth",
155 .of_match_table
= of_match_clk_mt7629_eth
,
159 builtin_platform_driver(clk_mt7629_eth_drv
);
161 MODULE_DESCRIPTION("MediaTek MT7629 Ethernet clocks driver");
162 MODULE_LICENSE("GPL");