1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021 MediaTek Inc.
4 * Chun-Jie Chen <chun-jie.chen@mediatek.com>
5 * Copyright (c) 2023 Collabora Ltd.
6 * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
9 #include <dt-bindings/clock/mt8192-clk.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include "clk-fhctl.h"
16 #include "clk-pllfh.h"
18 static const struct mtk_gate_regs apmixed_cg_regs
= {
24 #define GATE_APMIXED(_id, _name, _parent, _shift) \
25 GATE_MTK(_id, _name, _parent, &apmixed_cg_regs, _shift, &mtk_clk_gate_ops_no_setclr_inv)
27 static const struct mtk_gate apmixed_clks
[] = {
28 GATE_APMIXED(CLK_APMIXED_MIPID26M
, "mipid26m", "clk26m", 16),
31 #define MT8192_PLL_FMAX (3800UL * MHZ)
32 #define MT8192_PLL_FMIN (1500UL * MHZ)
33 #define MT8192_INTEGER_BITS 8
35 #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
36 _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
37 _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
38 _pcw_reg, _pcw_shift, _pcw_chg_reg, \
39 _en_reg, _pll_en_bit) { \
43 .pwr_reg = _pwr_reg, \
44 .en_mask = _en_mask, \
46 .rst_bar_mask = _rst_bar_mask, \
47 .fmax = MT8192_PLL_FMAX, \
48 .fmin = MT8192_PLL_FMIN, \
49 .pcwbits = _pcwbits, \
50 .pcwibits = MT8192_INTEGER_BITS, \
52 .pd_shift = _pd_shift, \
53 .tuner_reg = _tuner_reg, \
54 .tuner_en_reg = _tuner_en_reg, \
55 .tuner_en_bit = _tuner_en_bit, \
56 .pcw_reg = _pcw_reg, \
57 .pcw_shift = _pcw_shift, \
58 .pcw_chg_reg = _pcw_chg_reg, \
60 .pll_en_bit = _pll_en_bit, \
63 #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
64 _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
65 _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
66 _pcw_reg, _pcw_shift) \
67 PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
68 _rst_bar_mask, _pcwbits, _pd_reg, _pd_shift, \
69 _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
70 _pcw_reg, _pcw_shift, 0, 0, 0)
72 static const struct mtk_pll_data plls
[] = {
73 PLL_B(CLK_APMIXED_MAINPLL
, "mainpll", 0x0340, 0x034c, 0xff000000,
74 HAVE_RST_BAR
, BIT(23), 22, 0x0344, 24, 0, 0, 0, 0x0344, 0),
75 PLL_B(CLK_APMIXED_UNIVPLL
, "univpll", 0x0308, 0x0314, 0xff000000,
76 HAVE_RST_BAR
, BIT(23), 22, 0x030c, 24, 0, 0, 0, 0x030c, 0),
77 PLL(CLK_APMIXED_USBPLL
, "usbpll", 0x03c4, 0x03cc, 0x00000000,
78 0, 0, 22, 0x03c4, 24, 0, 0, 0, 0x03c4, 0, 0x03c4, 0x03cc, 2),
79 PLL_B(CLK_APMIXED_MSDCPLL
, "msdcpll", 0x0350, 0x035c, 0x00000000,
80 0, 0, 22, 0x0354, 24, 0, 0, 0, 0x0354, 0),
81 PLL_B(CLK_APMIXED_MMPLL
, "mmpll", 0x0360, 0x036c, 0xff000000,
82 HAVE_RST_BAR
, BIT(23), 22, 0x0364, 24, 0, 0, 0, 0x0364, 0),
83 PLL_B(CLK_APMIXED_ADSPPLL
, "adsppll", 0x0370, 0x037c, 0xff000000,
84 HAVE_RST_BAR
, BIT(23), 22, 0x0374, 24, 0, 0, 0, 0x0374, 0),
85 PLL_B(CLK_APMIXED_MFGPLL
, "mfgpll", 0x0268, 0x0274, 0x00000000,
86 0, 0, 22, 0x026c, 24, 0, 0, 0, 0x026c, 0),
87 PLL_B(CLK_APMIXED_TVDPLL
, "tvdpll", 0x0380, 0x038c, 0x00000000,
88 0, 0, 22, 0x0384, 24, 0, 0, 0, 0x0384, 0),
89 PLL_B(CLK_APMIXED_APLL1
, "apll1", 0x0318, 0x0328, 0x00000000,
90 0, 0, 32, 0x031c, 24, 0x0040, 0x000c, 0, 0x0320, 0),
91 PLL_B(CLK_APMIXED_APLL2
, "apll2", 0x032c, 0x033c, 0x00000000,
92 0, 0, 32, 0x0330, 24, 0, 0, 0, 0x0334, 0),
114 #define FH(_pllid, _fhid, _offset) { \
118 .fh_ver = FHCTL_PLLFH_V2, \
119 .fhx_offset = _offset, \
120 .dds_mask = GENMASK(21, 0), \
121 .slope0_value = 0x6003c97, \
122 .slope1_value = 0x6003c97, \
123 .sfstrx_en = BIT(2), \
124 .frddsx_en = BIT(1), \
125 .fhctlx_en = BIT(0), \
126 .tgl_org = BIT(31), \
127 .dvfs_tri = BIT(31), \
131 .updnlmt_shft = 16, \
132 .msk_frddsx_dys = GENMASK(23, 20), \
133 .msk_frddsx_dts = GENMASK(19, 16), \
137 static struct mtk_pllfh_data pllfhs
[] = {
138 FH(CLK_APMIXED_MFGPLL
, FH_MFGPLL
, 0xb4),
139 FH(CLK_APMIXED_MMPLL
, FH_MMPLL
, 0xf0),
140 FH(CLK_APMIXED_MAINPLL
, FH_MAINPLL
, 0x104),
141 FH(CLK_APMIXED_MSDCPLL
, FH_MSDCPLL
, 0x118),
142 FH(CLK_APMIXED_ADSPPLL
, FH_ADSPPLL
, 0x12c),
143 FH(CLK_APMIXED_TVDPLL
, FH_TVDPLL
, 0x154),
146 static const struct of_device_id of_match_clk_mt8192_apmixed
[] = {
147 { .compatible
= "mediatek,mt8192-apmixedsys" },
150 MODULE_DEVICE_TABLE(of
, of_match_clk_mt8192_apmixed
);
152 static int clk_mt8192_apmixed_probe(struct platform_device
*pdev
)
154 struct clk_hw_onecell_data
*clk_data
;
155 struct device_node
*node
= pdev
->dev
.of_node
;
156 const u8
*fhctl_node
= "mediatek,mt8192-fhctl";
159 clk_data
= mtk_alloc_clk_data(CLK_APMIXED_NR_CLK
);
163 fhctl_parse_dt(fhctl_node
, pllfhs
, ARRAY_SIZE(pllfhs
));
165 r
= mtk_clk_register_pllfhs(node
, plls
, ARRAY_SIZE(plls
),
166 pllfhs
, ARRAY_SIZE(pllfhs
), clk_data
);
170 r
= mtk_clk_register_gates(&pdev
->dev
, node
, apmixed_clks
,
171 ARRAY_SIZE(apmixed_clks
), clk_data
);
173 goto unregister_plls
;
175 r
= of_clk_add_hw_provider(node
, of_clk_hw_onecell_get
, clk_data
);
177 goto unregister_gates
;
182 mtk_clk_unregister_gates(apmixed_clks
, ARRAY_SIZE(apmixed_clks
), clk_data
);
184 mtk_clk_unregister_pllfhs(plls
, ARRAY_SIZE(plls
), pllfhs
,
185 ARRAY_SIZE(pllfhs
), clk_data
);
187 mtk_free_clk_data(clk_data
);
191 static void clk_mt8192_apmixed_remove(struct platform_device
*pdev
)
193 struct device_node
*node
= pdev
->dev
.of_node
;
194 struct clk_hw_onecell_data
*clk_data
= platform_get_drvdata(pdev
);
196 of_clk_del_provider(node
);
197 mtk_clk_unregister_gates(apmixed_clks
, ARRAY_SIZE(apmixed_clks
), clk_data
);
198 mtk_clk_unregister_pllfhs(plls
, ARRAY_SIZE(plls
), pllfhs
,
199 ARRAY_SIZE(pllfhs
), clk_data
);
200 mtk_free_clk_data(clk_data
);
203 static struct platform_driver clk_mt8192_apmixed_drv
= {
205 .name
= "clk-mt8192-apmixed",
206 .of_match_table
= of_match_clk_mt8192_apmixed
,
208 .probe
= clk_mt8192_apmixed_probe
,
209 .remove
= clk_mt8192_apmixed_remove
,
211 module_platform_driver(clk_mt8192_apmixed_drv
);
212 MODULE_DESCRIPTION("MediaTek MT8192 apmixed clocks driver");
213 MODULE_LICENSE("GPL");