Skip to content

Commit 813c3b5

Browse files
dangowrtbebarino
authored andcommitted
clk: mediatek: add MT7981 clock support
Add MT7981 clock support, include topckgen, apmixedsys, infracfg and ethernet subsystem clocks. The drivers are based on clk-mt7981.c which can be found in MediaTek's SDK sources. To be fit for upstream inclusion the driver has been split into clock domains and the infracfg part has been significantly de-bloated by removing all the 1:1 factors (aliases). Signed-off-by: Jianhui Zhao <[email protected]> Signed-off-by: Daniel Golle <[email protected]> Link: https://lore.kernel.org/r/8136eb5b2049177bc2f6d3e0f2aefecc342d626f.1674703830.git.daniel@makrotopia.org Reviewed-by: AngeloGioacchino Del Regno <[email protected]> [[email protected]: Add module license] Signed-off-by: Stephen Boyd <[email protected]>
1 parent a6473d0 commit 813c3b5

File tree

6 files changed

+870
-0
lines changed

6 files changed

+870
-0
lines changed

drivers/clk/mediatek/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,23 @@ config COMMON_CLK_MT7629_HIFSYS
388388
This driver supports MediaTek MT7629 HIFSYS clocks providing
389389
to PCI-E and USB.
390390

391+
config COMMON_CLK_MT7981
392+
bool "Clock driver for MediaTek MT7981"
393+
depends on ARCH_MEDIATEK || COMPILE_TEST
394+
select COMMON_CLK_MEDIATEK
395+
default ARCH_MEDIATEK
396+
help
397+
This driver supports MediaTek MT7981 basic clocks and clocks
398+
required for various peripherals found on this SoC.
399+
400+
config COMMON_CLK_MT7981_ETHSYS
401+
tristate "Clock driver for MediaTek MT7981 ETHSYS"
402+
depends on COMMON_CLK_MT7981
403+
default COMMON_CLK_MT7981
404+
help
405+
This driver adds support for clocks for Ethernet and SGMII
406+
required on MediaTek MT7981 SoC.
407+
391408
config COMMON_CLK_MT7986
392409
bool "Clock driver for MediaTek MT7986"
393410
depends on ARCH_MEDIATEK || COMPILE_TEST

drivers/clk/mediatek/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ obj-$(CONFIG_COMMON_CLK_MT7622_AUDSYS) += clk-mt7622-aud.o
5353
obj-$(CONFIG_COMMON_CLK_MT7629) += clk-mt7629.o
5454
obj-$(CONFIG_COMMON_CLK_MT7629_ETHSYS) += clk-mt7629-eth.o
5555
obj-$(CONFIG_COMMON_CLK_MT7629_HIFSYS) += clk-mt7629-hif.o
56+
obj-$(CONFIG_COMMON_CLK_MT7981) += clk-mt7981-apmixed.o
57+
obj-$(CONFIG_COMMON_CLK_MT7981) += clk-mt7981-topckgen.o
58+
obj-$(CONFIG_COMMON_CLK_MT7981) += clk-mt7981-infracfg.o
59+
obj-$(CONFIG_COMMON_CLK_MT7981_ETHSYS) += clk-mt7981-eth.o
5660
obj-$(CONFIG_COMMON_CLK_MT7986) += clk-mt7986-apmixed.o
5761
obj-$(CONFIG_COMMON_CLK_MT7986) += clk-mt7986-topckgen.o
5862
obj-$(CONFIG_COMMON_CLK_MT7986) += clk-mt7986-infracfg.o
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2021 MediaTek Inc.
4+
* Author: Sam Shih <[email protected]>
5+
* Author: Wenzhen Yu <[email protected]>
6+
* Author: Jianhui Zhao <[email protected]>
7+
* Author: Daniel Golle <[email protected]>
8+
*/
9+
10+
#include <linux/clk-provider.h>
11+
#include <linux/of.h>
12+
#include <linux/of_address.h>
13+
#include <linux/of_device.h>
14+
#include <linux/platform_device.h>
15+
16+
#include "clk-gate.h"
17+
#include "clk-mtk.h"
18+
#include "clk-mux.h"
19+
#include "clk-pll.h"
20+
21+
#include <dt-bindings/clock/mediatek,mt7981-clk.h>
22+
#include <linux/clk.h>
23+
24+
#define MT7981_PLL_FMAX (2500UL * MHZ)
25+
#define CON0_MT7981_RST_BAR BIT(27)
26+
27+
#define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
28+
_pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
29+
_div_table, _parent_name) \
30+
{ \
31+
.id = _id, .name = _name, .reg = _reg, .pwr_reg = _pwr_reg, \
32+
.en_mask = _en_mask, .flags = _flags, \
33+
.rst_bar_mask = CON0_MT7981_RST_BAR, .fmax = MT7981_PLL_FMAX, \
34+
.pcwbits = _pcwbits, .pd_reg = _pd_reg, .pd_shift = _pd_shift, \
35+
.tuner_reg = _tuner_reg, .pcw_reg = _pcw_reg, \
36+
.pcw_shift = _pcw_shift, .div_table = _div_table, \
37+
.parent_name = _parent_name, \
38+
}
39+
40+
#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
41+
_pd_shift, _tuner_reg, _pcw_reg, _pcw_shift) \
42+
PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
43+
_pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, NULL, \
44+
"clkxtal")
45+
46+
static const struct mtk_pll_data plls[] = {
47+
PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0x00000001, PLL_AO,
48+
32, 0x0200, 4, 0, 0x0204, 0),
49+
PLL(CLK_APMIXED_NET2PLL, "net2pll", 0x0210, 0x021C, 0x00000001, 0, 32,
50+
0x0210, 4, 0, 0x0214, 0),
51+
PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0220, 0x022C, 0x00000001, 0, 32,
52+
0x0220, 4, 0, 0x0224, 0),
53+
PLL(CLK_APMIXED_SGMPLL, "sgmpll", 0x0230, 0x023C, 0x00000001, 0, 32,
54+
0x0230, 4, 0, 0x0234, 0),
55+
PLL(CLK_APMIXED_WEDMCUPLL, "wedmcupll", 0x0240, 0x024C, 0x00000001, 0, 32,
56+
0x0240, 4, 0, 0x0244, 0),
57+
PLL(CLK_APMIXED_NET1PLL, "net1pll", 0x0250, 0x025C, 0x00000001, 0, 32,
58+
0x0250, 4, 0, 0x0254, 0),
59+
PLL(CLK_APMIXED_MPLL, "mpll", 0x0260, 0x0270, 0x00000001, 0, 32,
60+
0x0260, 4, 0, 0x0264, 0),
61+
PLL(CLK_APMIXED_APLL2, "apll2", 0x0278, 0x0288, 0x00000001, 0, 32,
62+
0x0278, 4, 0, 0x027C, 0),
63+
};
64+
65+
static const struct of_device_id of_match_clk_mt7981_apmixed[] = {
66+
{ .compatible = "mediatek,mt7981-apmixedsys", },
67+
{ /* sentinel */ }
68+
};
69+
70+
static int clk_mt7981_apmixed_probe(struct platform_device *pdev)
71+
{
72+
struct clk_hw_onecell_data *clk_data;
73+
struct device_node *node = pdev->dev.of_node;
74+
int r;
75+
76+
clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
77+
if (!clk_data)
78+
return -ENOMEM;
79+
80+
mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
81+
82+
r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
83+
if (r) {
84+
pr_err("%s(): could not register clock provider: %d\n",
85+
__func__, r);
86+
goto free_apmixed_data;
87+
}
88+
return r;
89+
90+
free_apmixed_data:
91+
mtk_free_clk_data(clk_data);
92+
return r;
93+
}
94+
95+
static struct platform_driver clk_mt7981_apmixed_drv = {
96+
.probe = clk_mt7981_apmixed_probe,
97+
.driver = {
98+
.name = "clk-mt7981-apmixed",
99+
.of_match_table = of_match_clk_mt7981_apmixed,
100+
},
101+
};
102+
builtin_platform_driver(clk_mt7981_apmixed_drv);

drivers/clk/mediatek/clk-mt7981-eth.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2021 MediaTek Inc.
4+
* Author: Sam Shih <[email protected]>
5+
* Author: Wenzhen Yu <[email protected]>
6+
* Author: Jianhui Zhao <[email protected]>
7+
* Author: Daniel Golle <[email protected]>
8+
*/
9+
10+
#include <linux/clk-provider.h>
11+
#include <linux/of.h>
12+
#include <linux/of_address.h>
13+
#include <linux/of_device.h>
14+
#include <linux/platform_device.h>
15+
16+
#include "clk-mtk.h"
17+
#include "clk-gate.h"
18+
19+
#include <dt-bindings/clock/mediatek,mt7981-clk.h>
20+
21+
static const struct mtk_gate_regs sgmii0_cg_regs = {
22+
.set_ofs = 0xE4,
23+
.clr_ofs = 0xE4,
24+
.sta_ofs = 0xE4,
25+
};
26+
27+
#define GATE_SGMII0(_id, _name, _parent, _shift) { \
28+
.id = _id, \
29+
.name = _name, \
30+
.parent_name = _parent, \
31+
.regs = &sgmii0_cg_regs, \
32+
.shift = _shift, \
33+
.ops = &mtk_clk_gate_ops_no_setclr_inv, \
34+
}
35+
36+
static const struct mtk_gate sgmii0_clks[] __initconst = {
37+
GATE_SGMII0(CLK_SGM0_TX_EN, "sgm0_tx_en", "usb_tx250m", 2),
38+
GATE_SGMII0(CLK_SGM0_RX_EN, "sgm0_rx_en", "usb_eq_rx250m", 3),
39+
GATE_SGMII0(CLK_SGM0_CK0_EN, "sgm0_ck0_en", "usb_ln0", 4),
40+
GATE_SGMII0(CLK_SGM0_CDR_CK0_EN, "sgm0_cdr_ck0_en", "usb_cdr", 5),
41+
};
42+
43+
static const struct mtk_gate_regs sgmii1_cg_regs = {
44+
.set_ofs = 0xE4,
45+
.clr_ofs = 0xE4,
46+
.sta_ofs = 0xE4,
47+
};
48+
49+
#define GATE_SGMII1(_id, _name, _parent, _shift) { \
50+
.id = _id, \
51+
.name = _name, \
52+
.parent_name = _parent, \
53+
.regs = &sgmii1_cg_regs, \
54+
.shift = _shift, \
55+
.ops = &mtk_clk_gate_ops_no_setclr_inv, \
56+
}
57+
58+
static const struct mtk_gate sgmii1_clks[] __initconst = {
59+
GATE_SGMII1(CLK_SGM1_TX_EN, "sgm1_tx_en", "usb_tx250m", 2),
60+
GATE_SGMII1(CLK_SGM1_RX_EN, "sgm1_rx_en", "usb_eq_rx250m", 3),
61+
GATE_SGMII1(CLK_SGM1_CK1_EN, "sgm1_ck1_en", "usb_ln0", 4),
62+
GATE_SGMII1(CLK_SGM1_CDR_CK1_EN, "sgm1_cdr_ck1_en", "usb_cdr", 5),
63+
};
64+
65+
static const struct mtk_gate_regs eth_cg_regs = {
66+
.set_ofs = 0x30,
67+
.clr_ofs = 0x30,
68+
.sta_ofs = 0x30,
69+
};
70+
71+
#define GATE_ETH(_id, _name, _parent, _shift) { \
72+
.id = _id, \
73+
.name = _name, \
74+
.parent_name = _parent, \
75+
.regs = &eth_cg_regs, \
76+
.shift = _shift, \
77+
.ops = &mtk_clk_gate_ops_no_setclr_inv, \
78+
}
79+
80+
static const struct mtk_gate eth_clks[] __initconst = {
81+
GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "netsys_2x", 6),
82+
GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "sgm_325m", 7),
83+
GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "sgm_325m", 8),
84+
GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", "netsys_wed_mcu", 15),
85+
};
86+
87+
static const struct mtk_clk_desc eth_desc = {
88+
.clks = eth_clks,
89+
.num_clks = ARRAY_SIZE(eth_clks),
90+
};
91+
92+
static const struct mtk_clk_desc sgmii0_desc = {
93+
.clks = sgmii0_clks,
94+
.num_clks = ARRAY_SIZE(sgmii0_clks),
95+
};
96+
97+
static const struct mtk_clk_desc sgmii1_desc = {
98+
.clks = sgmii1_clks,
99+
.num_clks = ARRAY_SIZE(sgmii1_clks),
100+
};
101+
102+
static const struct of_device_id of_match_clk_mt7981_eth[] = {
103+
{ .compatible = "mediatek,mt7981-ethsys", .data = &eth_desc },
104+
{ .compatible = "mediatek,mt7981-sgmiisys_0", .data = &sgmii0_desc },
105+
{ .compatible = "mediatek,mt7981-sgmiisys_1", .data = &sgmii1_desc },
106+
{ /* sentinel */ }
107+
};
108+
109+
static struct platform_driver clk_mt7981_eth_drv = {
110+
.probe = mtk_clk_simple_probe,
111+
.remove = mtk_clk_simple_remove,
112+
.driver = {
113+
.name = "clk-mt7981-eth",
114+
.of_match_table = of_match_clk_mt7981_eth,
115+
},
116+
};
117+
module_platform_driver(clk_mt7981_eth_drv);
118+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)