Skip to content

Commit 43c04ed

Browse files
Tooniisbebarino
authored andcommitted
clk: mediatek: Add drivers for MediaTek MT6735 main clock and reset drivers
Add drivers for MT6735 apmixedsys, topckgen, infracfg and pericfg clock and reset controllers. These provide the base clocks and resets on the platform, enough to bring up all essential blocks including PWRAP, MSDC and peripherals (UART, I2C, SPI). Signed-off-by: Yassine Oudjana <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Stephen Boyd <[email protected]>
1 parent ea1cca0 commit 43c04ed

File tree

7 files changed

+777
-0
lines changed

7 files changed

+777
-0
lines changed

MAINTAINERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14533,6 +14533,10 @@ M: Yassine Oudjana <[email protected]>
1453314533
1453414534
L: [email protected] (moderated for non-subscribers)
1453514535
S: Maintained
14536+
F: drivers/clk/mediatek/clk-mt6735-apmixedsys.c
14537+
F: drivers/clk/mediatek/clk-mt6735-infracfg.c
14538+
F: drivers/clk/mediatek/clk-mt6735-pericfg.c
14539+
F: drivers/clk/mediatek/clk-mt6735-topckgen.c
1453614540
F: include/dt-bindings/clock/mediatek,mt6735-apmixedsys.h
1453714541
F: include/dt-bindings/clock/mediatek,mt6735-infracfg.h
1453814542
F: include/dt-bindings/clock/mediatek,mt6735-pericfg.h

drivers/clk/mediatek/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ config COMMON_CLK_MT2712_VENCSYS
124124
help
125125
This driver supports MediaTek MT2712 vencsys clocks.
126126

127+
config COMMON_CLK_MT6735
128+
tristate "Main clock drivers for MediaTek MT6735"
129+
depends on ARCH_MEDIATEK || COMPILE_TEST
130+
select COMMON_CLK_MEDIATEK
131+
help
132+
This enables drivers for clocks and resets provided
133+
by apmixedsys, topckgen, infracfg and pericfg on the
134+
MediaTek MT6735 SoC.
135+
127136
config COMMON_CLK_MT6765
128137
bool "Clock driver for MediaTek MT6765"
129138
depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST

drivers/clk/mediatek/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
obj-$(CONFIG_COMMON_CLK_MEDIATEK) += clk-mtk.o clk-pll.o clk-gate.o clk-apmixed.o clk-cpumux.o reset.o clk-mux.o
33
obj-$(CONFIG_COMMON_CLK_MEDIATEK_FHCTL) += clk-fhctl.o clk-pllfh.o
44

5+
obj-$(CONFIG_COMMON_CLK_MT6735) += clk-mt6735-apmixedsys.o clk-mt6735-infracfg.o clk-mt6735-pericfg.o clk-mt6735-topckgen.o
56
obj-$(CONFIG_COMMON_CLK_MT6765) += clk-mt6765.o
67
obj-$(CONFIG_COMMON_CLK_MT6765_AUDIOSYS) += clk-mt6765-audio.o
78
obj-$(CONFIG_COMMON_CLK_MT6765_CAMSYS) += clk-mt6765-cam.o
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2022 Yassine Oudjana <[email protected]>
4+
*/
5+
6+
#include <linux/clk-provider.h>
7+
#include <linux/platform_device.h>
8+
9+
#include "clk-mtk.h"
10+
#include "clk-pll.h"
11+
12+
#include <dt-bindings/clock/mediatek,mt6735-apmixedsys.h>
13+
14+
#define AP_PLL_CON_5 0x014
15+
#define ARMPLL_CON0 0x200
16+
#define ARMPLL_CON1 0x204
17+
#define ARMPLL_PWR_CON0 0x20c
18+
#define MAINPLL_CON0 0x210
19+
#define MAINPLL_CON1 0x214
20+
#define MAINPLL_PWR_CON0 0x21c
21+
#define UNIVPLL_CON0 0x220
22+
#define UNIVPLL_CON1 0x224
23+
#define UNIVPLL_PWR_CON0 0x22c
24+
#define MMPLL_CON0 0x230
25+
#define MMPLL_CON1 0x234
26+
#define MMPLL_PWR_CON0 0x23c
27+
#define MSDCPLL_CON0 0x240
28+
#define MSDCPLL_CON1 0x244
29+
#define MSDCPLL_PWR_CON0 0x24c
30+
#define VENCPLL_CON0 0x250
31+
#define VENCPLL_CON1 0x254
32+
#define VENCPLL_PWR_CON0 0x25c
33+
#define TVDPLL_CON0 0x260
34+
#define TVDPLL_CON1 0x264
35+
#define TVDPLL_PWR_CON0 0x26c
36+
#define APLL1_CON0 0x270
37+
#define APLL1_CON1 0x274
38+
#define APLL1_CON2 0x278
39+
#define APLL1_PWR_CON0 0x280
40+
#define APLL2_CON0 0x284
41+
#define APLL2_CON1 0x288
42+
#define APLL2_CON2 0x28c
43+
#define APLL2_PWR_CON0 0x294
44+
45+
#define CON0_RST_BAR BIT(24)
46+
47+
#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _rst_bar_mask, \
48+
_pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
49+
_tuner_en_bit, _pcw_reg, _pcwbits, _flags) { \
50+
.id = _id, \
51+
.name = _name, \
52+
.parent_name = "clk26m", \
53+
.reg = _reg, \
54+
.pwr_reg = _pwr_reg, \
55+
.en_mask = _en_mask, \
56+
.rst_bar_mask = _rst_bar_mask, \
57+
.pd_reg = _pd_reg, \
58+
.pd_shift = _pd_shift, \
59+
.tuner_reg = _tuner_reg, \
60+
.tuner_en_reg = _tuner_en_reg, \
61+
.tuner_en_bit = _tuner_en_bit, \
62+
.pcw_reg = _pcw_reg, \
63+
.pcw_chg_reg = _pcw_reg, \
64+
.pcwbits = _pcwbits, \
65+
.flags = _flags, \
66+
}
67+
68+
static const struct mtk_pll_data apmixedsys_plls[] = {
69+
PLL(CLK_APMIXED_ARMPLL, "armpll", ARMPLL_CON0, ARMPLL_PWR_CON0, 0x00000001, 0, ARMPLL_CON1, 24, 0, 0, 0, ARMPLL_CON1, 21, PLL_AO),
70+
PLL(CLK_APMIXED_MAINPLL, "mainpll", MAINPLL_CON0, MAINPLL_PWR_CON0, 0xf0000101, CON0_RST_BAR, MAINPLL_CON1, 24, 0, 0, 0, MAINPLL_CON1, 21, HAVE_RST_BAR),
71+
PLL(CLK_APMIXED_UNIVPLL, "univpll", UNIVPLL_CON0, UNIVPLL_PWR_CON0, 0xfc000001, CON0_RST_BAR, UNIVPLL_CON1, 24, 0, 0, 0, UNIVPLL_CON1, 21, HAVE_RST_BAR),
72+
PLL(CLK_APMIXED_MMPLL, "mmpll", MMPLL_CON0, MMPLL_PWR_CON0, 0x00000001, 0, MMPLL_CON1, 24, 0, 0, 0, MMPLL_CON1, 21, 0),
73+
PLL(CLK_APMIXED_MSDCPLL, "msdcpll", MSDCPLL_CON0, MSDCPLL_PWR_CON0, 0x00000001, 0, MSDCPLL_CON1, 24, 0, 0, 0, MSDCPLL_CON1, 21, 0),
74+
PLL(CLK_APMIXED_VENCPLL, "vencpll", VENCPLL_CON0, VENCPLL_PWR_CON0, 0x00000001, CON0_RST_BAR, VENCPLL_CON1, 24, 0, 0, 0, VENCPLL_CON1, 21, HAVE_RST_BAR),
75+
PLL(CLK_APMIXED_TVDPLL, "tvdpll", TVDPLL_CON0, TVDPLL_PWR_CON0, 0x00000001, 0, TVDPLL_CON1, 24, 0, 0, 0, TVDPLL_CON1, 21, 0),
76+
PLL(CLK_APMIXED_APLL1, "apll1", APLL1_CON0, APLL1_PWR_CON0, 0x00000001, 0, APLL1_CON0, 4, APLL1_CON2, AP_PLL_CON_5, 0, APLL1_CON1, 31, 0),
77+
PLL(CLK_APMIXED_APLL2, "apll2", APLL2_CON0, APLL2_PWR_CON0, 0x00000001, 0, APLL2_CON0, 4, APLL2_CON2, AP_PLL_CON_5, 1, APLL2_CON1, 31, 0)
78+
};
79+
80+
static int clk_mt6735_apmixed_probe(struct platform_device *pdev)
81+
{
82+
void __iomem *base;
83+
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
84+
struct clk_hw_onecell_data *clk_data;
85+
int ret;
86+
87+
base = devm_ioremap_resource(&pdev->dev, res);
88+
if (IS_ERR(base))
89+
return PTR_ERR(base);
90+
91+
clk_data = mtk_alloc_clk_data(ARRAY_SIZE(apmixedsys_plls));
92+
if (!clk_data)
93+
return -ENOMEM;
94+
platform_set_drvdata(pdev, clk_data);
95+
96+
ret = mtk_clk_register_plls(pdev->dev.of_node, apmixedsys_plls,
97+
ARRAY_SIZE(apmixedsys_plls), clk_data);
98+
if (ret) {
99+
dev_err(&pdev->dev, "Failed to register PLLs: %d\n", ret);
100+
return ret;
101+
}
102+
103+
ret = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get,
104+
clk_data);
105+
if (ret)
106+
dev_err(&pdev->dev,
107+
"Failed to register clock provider: %d\n", ret);
108+
109+
return ret;
110+
}
111+
112+
static void clk_mt6735_apmixed_remove(struct platform_device *pdev)
113+
{
114+
struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
115+
116+
mtk_clk_unregister_plls(apmixedsys_plls, ARRAY_SIZE(apmixedsys_plls), clk_data);
117+
mtk_free_clk_data(clk_data);
118+
}
119+
120+
static const struct of_device_id of_match_mt6735_apmixedsys[] = {
121+
{ .compatible = "mediatek,mt6735-apmixedsys" },
122+
{ /* sentinel */ }
123+
};
124+
MODULE_DEVICE_TABLE(of, of_match_mt6735_apmixedsys);
125+
126+
static struct platform_driver clk_mt6735_apmixedsys = {
127+
.probe = clk_mt6735_apmixed_probe,
128+
.remove = clk_mt6735_apmixed_remove,
129+
.driver = {
130+
.name = "clk-mt6735-apmixedsys",
131+
.of_match_table = of_match_mt6735_apmixedsys,
132+
},
133+
};
134+
module_platform_driver(clk_mt6735_apmixedsys);
135+
136+
MODULE_AUTHOR("Yassine Oudjana <[email protected]>");
137+
MODULE_DESCRIPTION("MediaTek MT6735 apmixedsys clock driver");
138+
MODULE_LICENSE("GPL");
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2022 Yassine Oudjana <[email protected]>
4+
*/
5+
6+
#include <linux/clk-provider.h>
7+
#include <linux/platform_device.h>
8+
9+
#include "clk-gate.h"
10+
#include "clk-mtk.h"
11+
12+
#include <dt-bindings/clock/mediatek,mt6735-infracfg.h>
13+
#include <dt-bindings/reset/mediatek,mt6735-infracfg.h>
14+
15+
#define INFRA_RST0 0x30
16+
#define INFRA_GLOBALCON_PDN0 0x40
17+
#define INFRA_PDN1 0x44
18+
#define INFRA_PDN_STA 0x48
19+
20+
#define RST_NR_PER_BANK 32
21+
22+
static struct mtk_gate_regs infra_cg_regs = {
23+
.set_ofs = INFRA_GLOBALCON_PDN0,
24+
.clr_ofs = INFRA_PDN1,
25+
.sta_ofs = INFRA_PDN_STA,
26+
};
27+
28+
static const struct mtk_gate infracfg_gates[] = {
29+
GATE_MTK(CLK_INFRA_DBG, "dbg", "axi_sel", &infra_cg_regs, 0, &mtk_clk_gate_ops_setclr),
30+
GATE_MTK(CLK_INFRA_GCE, "gce", "axi_sel", &infra_cg_regs, 1, &mtk_clk_gate_ops_setclr),
31+
GATE_MTK(CLK_INFRA_TRBG, "trbg", "axi_sel", &infra_cg_regs, 2, &mtk_clk_gate_ops_setclr),
32+
GATE_MTK(CLK_INFRA_CPUM, "cpum", "axi_sel", &infra_cg_regs, 3, &mtk_clk_gate_ops_setclr),
33+
GATE_MTK(CLK_INFRA_DEVAPC, "devapc", "axi_sel", &infra_cg_regs, 4, &mtk_clk_gate_ops_setclr),
34+
GATE_MTK(CLK_INFRA_AUDIO, "audio", "aud_intbus_sel", &infra_cg_regs, 5, &mtk_clk_gate_ops_setclr),
35+
GATE_MTK(CLK_INFRA_GCPU, "gcpu", "axi_sel", &infra_cg_regs, 6, &mtk_clk_gate_ops_setclr),
36+
GATE_MTK(CLK_INFRA_L2C_SRAM, "l2csram", "axi_sel", &infra_cg_regs, 7, &mtk_clk_gate_ops_setclr),
37+
GATE_MTK(CLK_INFRA_M4U, "m4u", "axi_sel", &infra_cg_regs, 8, &mtk_clk_gate_ops_setclr),
38+
GATE_MTK(CLK_INFRA_CLDMA, "cldma", "axi_sel", &infra_cg_regs, 12, &mtk_clk_gate_ops_setclr),
39+
GATE_MTK(CLK_INFRA_CONNMCU_BUS, "connmcu_bus", "axi_sel", &infra_cg_regs, 15, &mtk_clk_gate_ops_setclr),
40+
GATE_MTK(CLK_INFRA_KP, "kp", "axi_sel", &infra_cg_regs, 16, &mtk_clk_gate_ops_setclr),
41+
GATE_MTK_FLAGS(CLK_INFRA_APXGPT, "apxgpt", "axi_sel", &infra_cg_regs, 18, &mtk_clk_gate_ops_setclr, CLK_IS_CRITICAL),
42+
GATE_MTK(CLK_INFRA_SEJ, "sej", "axi_sel", &infra_cg_regs, 19, &mtk_clk_gate_ops_setclr),
43+
GATE_MTK(CLK_INFRA_CCIF0_AP, "ccif0ap", "axi_sel", &infra_cg_regs, 20, &mtk_clk_gate_ops_setclr),
44+
GATE_MTK(CLK_INFRA_CCIF1_AP, "ccif1ap", "axi_sel", &infra_cg_regs, 21, &mtk_clk_gate_ops_setclr),
45+
GATE_MTK(CLK_INFRA_PMIC_SPI, "pmicspi", "pmicspi_sel", &infra_cg_regs, 22, &mtk_clk_gate_ops_setclr),
46+
GATE_MTK(CLK_INFRA_PMIC_WRAP, "pmicwrap", "axi_sel", &infra_cg_regs, 23, &mtk_clk_gate_ops_setclr)
47+
};
48+
49+
static u16 infracfg_rst_bank_ofs[] = { INFRA_RST0 };
50+
51+
static u16 infracfg_rst_idx_map[] = {
52+
[MT6735_INFRA_RST0_EMI_REG] = 0 * RST_NR_PER_BANK + 0,
53+
[MT6735_INFRA_RST0_DRAMC0_AO] = 0 * RST_NR_PER_BANK + 1,
54+
[MT6735_INFRA_RST0_AP_CIRQ_EINT] = 0 * RST_NR_PER_BANK + 3,
55+
[MT6735_INFRA_RST0_APXGPT] = 0 * RST_NR_PER_BANK + 4,
56+
[MT6735_INFRA_RST0_SCPSYS] = 0 * RST_NR_PER_BANK + 5,
57+
[MT6735_INFRA_RST0_KP] = 0 * RST_NR_PER_BANK + 6,
58+
[MT6735_INFRA_RST0_PMIC_WRAP] = 0 * RST_NR_PER_BANK + 7,
59+
[MT6735_INFRA_RST0_CLDMA_AO_TOP] = 0 * RST_NR_PER_BANK + 8,
60+
[MT6735_INFRA_RST0_USBSIF_TOP] = 0 * RST_NR_PER_BANK + 9,
61+
[MT6735_INFRA_RST0_EMI] = 0 * RST_NR_PER_BANK + 16,
62+
[MT6735_INFRA_RST0_CCIF] = 0 * RST_NR_PER_BANK + 17,
63+
[MT6735_INFRA_RST0_DRAMC0] = 0 * RST_NR_PER_BANK + 18,
64+
[MT6735_INFRA_RST0_EMI_AO_REG] = 0 * RST_NR_PER_BANK + 19,
65+
[MT6735_INFRA_RST0_CCIF_AO] = 0 * RST_NR_PER_BANK + 20,
66+
[MT6735_INFRA_RST0_TRNG] = 0 * RST_NR_PER_BANK + 21,
67+
[MT6735_INFRA_RST0_SYS_CIRQ] = 0 * RST_NR_PER_BANK + 22,
68+
[MT6735_INFRA_RST0_GCE] = 0 * RST_NR_PER_BANK + 23,
69+
[MT6735_INFRA_RST0_M4U] = 0 * RST_NR_PER_BANK + 24,
70+
[MT6735_INFRA_RST0_CCIF1] = 0 * RST_NR_PER_BANK + 25,
71+
[MT6735_INFRA_RST0_CLDMA_TOP_PD] = 0 * RST_NR_PER_BANK + 26
72+
};
73+
74+
static const struct mtk_clk_rst_desc infracfg_resets = {
75+
.version = MTK_RST_SIMPLE,
76+
.rst_bank_ofs = infracfg_rst_bank_ofs,
77+
.rst_bank_nr = ARRAY_SIZE(infracfg_rst_bank_ofs),
78+
.rst_idx_map = infracfg_rst_idx_map,
79+
.rst_idx_map_nr = ARRAY_SIZE(infracfg_rst_idx_map)
80+
};
81+
82+
static const struct mtk_clk_desc infracfg_clks = {
83+
.clks = infracfg_gates,
84+
.num_clks = ARRAY_SIZE(infracfg_gates),
85+
86+
.rst_desc = &infracfg_resets
87+
};
88+
89+
static const struct of_device_id of_match_mt6735_infracfg[] = {
90+
{ .compatible = "mediatek,mt6735-infracfg", .data = &infracfg_clks },
91+
{ /* sentinel */ }
92+
};
93+
MODULE_DEVICE_TABLE(of, of_match_mt6735_infracfg);
94+
95+
static struct platform_driver clk_mt6735_infracfg = {
96+
.probe = mtk_clk_simple_probe,
97+
.remove = mtk_clk_simple_remove,
98+
.driver = {
99+
.name = "clk-mt6735-infracfg",
100+
.of_match_table = of_match_mt6735_infracfg,
101+
},
102+
};
103+
module_platform_driver(clk_mt6735_infracfg);
104+
105+
MODULE_AUTHOR("Yassine Oudjana <[email protected]>");
106+
MODULE_DESCRIPTION("MediaTek MT6735 infracfg clock and reset driver");
107+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)