Skip to content

Commit ec97d23

Browse files
SamShih33bebarino
authored andcommitted
clk: mediatek: add mt7986 clock support
Add MT7986 clock support, include topckgen, apmixedsys, infracfg, and ethernet subsystem clocks. Signed-off-by: Sam Shih <sam.shih@mediatek.com> Link: https://lore.kernel.org/r/20211217121148.6753-4-sam.shih@mediatek.com Reviewed-by: Ryder Lee <ryder.lee@kernel.org> [sboyd@kernel.org: Fix typos in Kconfig, there are more existing typos from where they were copied from of but whatever] Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 4470c83 commit ec97d23

File tree

6 files changed

+819
-0
lines changed

6 files changed

+819
-0
lines changed

drivers/clk/mediatek/Kconfig

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

347+
config COMMON_CLK_MT7986
348+
bool "Clock driver for MediaTek MT7986"
349+
depends on ARCH_MEDIATEK || COMPILE_TEST
350+
select COMMON_CLK_MEDIATEK
351+
default ARCH_MEDIATEK
352+
help
353+
This driver supports MediaTek MT7986 basic clocks and clocks
354+
required for various peripherals found on MediaTek.
355+
356+
config COMMON_CLK_MT7986_ETHSYS
357+
bool "Clock driver for MediaTek MT7986 ETHSYS"
358+
depends on COMMON_CLK_MT7986
359+
default COMMON_CLK_MT7986
360+
help
361+
This driver adds support for clocks for Ethernet and SGMII
362+
required on MediaTek MT7986 SoC.
363+
347364
config COMMON_CLK_MT8135
348365
bool "Clock driver for MediaTek MT8135"
349366
depends on (ARCH_MEDIATEK && ARM) || COMPILE_TEST

drivers/clk/mediatek/Makefile

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

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2021 MediaTek Inc.
4+
* Author: Sam Shih <sam.shih@mediatek.com>
5+
* Author: Wenzhen Yu <wenzhen.yu@mediatek.com>
6+
*/
7+
8+
#include <linux/clk-provider.h>
9+
#include <linux/of.h>
10+
#include <linux/of_address.h>
11+
#include <linux/of_device.h>
12+
#include <linux/platform_device.h>
13+
14+
#include "clk-mtk.h"
15+
#include "clk-gate.h"
16+
17+
#include <dt-bindings/clock/mt7986-clk.h>
18+
19+
static const struct mtk_gate_regs sgmii0_cg_regs = {
20+
.set_ofs = 0xe4,
21+
.clr_ofs = 0xe4,
22+
.sta_ofs = 0xe4,
23+
};
24+
25+
#define GATE_SGMII0(_id, _name, _parent, _shift) \
26+
{ \
27+
.id = _id, .name = _name, .parent_name = _parent, \
28+
.regs = &sgmii0_cg_regs, .shift = _shift, \
29+
.ops = &mtk_clk_gate_ops_no_setclr_inv, \
30+
}
31+
32+
static const struct mtk_gate sgmii0_clks[] __initconst = {
33+
GATE_SGMII0(CLK_SGMII0_TX250M_EN, "sgmii0_tx250m_en", "top_xtal", 2),
34+
GATE_SGMII0(CLK_SGMII0_RX250M_EN, "sgmii0_rx250m_en", "top_xtal", 3),
35+
GATE_SGMII0(CLK_SGMII0_CDR_REF, "sgmii0_cdr_ref", "top_xtal", 4),
36+
GATE_SGMII0(CLK_SGMII0_CDR_FB, "sgmii0_cdr_fb", "top_xtal", 5),
37+
};
38+
39+
static const struct mtk_gate_regs sgmii1_cg_regs = {
40+
.set_ofs = 0xe4,
41+
.clr_ofs = 0xe4,
42+
.sta_ofs = 0xe4,
43+
};
44+
45+
#define GATE_SGMII1(_id, _name, _parent, _shift) \
46+
{ \
47+
.id = _id, .name = _name, .parent_name = _parent, \
48+
.regs = &sgmii1_cg_regs, .shift = _shift, \
49+
.ops = &mtk_clk_gate_ops_no_setclr_inv, \
50+
}
51+
52+
static const struct mtk_gate sgmii1_clks[] __initconst = {
53+
GATE_SGMII1(CLK_SGMII1_TX250M_EN, "sgmii1_tx250m_en", "top_xtal", 2),
54+
GATE_SGMII1(CLK_SGMII1_RX250M_EN, "sgmii1_rx250m_en", "top_xtal", 3),
55+
GATE_SGMII1(CLK_SGMII1_CDR_REF, "sgmii1_cdr_ref", "top_xtal", 4),
56+
GATE_SGMII1(CLK_SGMII1_CDR_FB, "sgmii1_cdr_fb", "top_xtal", 5),
57+
};
58+
59+
static const struct mtk_gate_regs eth_cg_regs = {
60+
.set_ofs = 0x30,
61+
.clr_ofs = 0x30,
62+
.sta_ofs = 0x30,
63+
};
64+
65+
#define GATE_ETH(_id, _name, _parent, _shift) \
66+
{ \
67+
.id = _id, .name = _name, .parent_name = _parent, \
68+
.regs = &eth_cg_regs, .shift = _shift, \
69+
.ops = &mtk_clk_gate_ops_no_setclr_inv, \
70+
}
71+
72+
static const struct mtk_gate eth_clks[] __initconst = {
73+
GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", "netsys_2x_sel", 6),
74+
GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", "sgm_325m_sel", 7),
75+
GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", "sgm_325m_sel", 8),
76+
GATE_ETH(CLK_ETH_WOCPU1_EN, "eth_wocpu1_en", "netsys_mcu_sel", 14),
77+
GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", "netsys_mcu_sel", 15),
78+
};
79+
80+
static void __init mtk_sgmiisys_0_init(struct device_node *node)
81+
{
82+
struct clk_onecell_data *clk_data;
83+
int r;
84+
85+
clk_data = mtk_alloc_clk_data(ARRAY_SIZE(sgmii0_clks));
86+
87+
mtk_clk_register_gates(node, sgmii0_clks, ARRAY_SIZE(sgmii0_clks),
88+
clk_data);
89+
90+
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
91+
if (r)
92+
pr_err("%s(): could not register clock provider: %d\n",
93+
__func__, r);
94+
}
95+
CLK_OF_DECLARE(mtk_sgmiisys_0, "mediatek,mt7986-sgmiisys_0",
96+
mtk_sgmiisys_0_init);
97+
98+
static void __init mtk_sgmiisys_1_init(struct device_node *node)
99+
{
100+
struct clk_onecell_data *clk_data;
101+
int r;
102+
103+
clk_data = mtk_alloc_clk_data(ARRAY_SIZE(sgmii1_clks));
104+
105+
mtk_clk_register_gates(node, sgmii1_clks, ARRAY_SIZE(sgmii1_clks),
106+
clk_data);
107+
108+
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
109+
110+
if (r)
111+
pr_err("%s(): could not register clock provider: %d\n",
112+
__func__, r);
113+
}
114+
CLK_OF_DECLARE(mtk_sgmiisys_1, "mediatek,mt7986-sgmiisys_1",
115+
mtk_sgmiisys_1_init);
116+
117+
static void __init mtk_ethsys_init(struct device_node *node)
118+
{
119+
struct clk_onecell_data *clk_data;
120+
int r;
121+
122+
clk_data = mtk_alloc_clk_data(ARRAY_SIZE(eth_clks));
123+
124+
mtk_clk_register_gates(node, eth_clks, ARRAY_SIZE(eth_clks), clk_data);
125+
126+
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
127+
128+
if (r)
129+
pr_err("%s(): could not register clock provider: %d\n",
130+
__func__, r);
131+
}
132+
CLK_OF_DECLARE(mtk_ethsys, "mediatek,mt7986-ethsys_ck", mtk_ethsys_init);

0 commit comments

Comments
 (0)