blob: f7464eac9d9019d6b59d78ddbf1cb0a13b0238cb [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2
3/*
4
5 * Copyright (c) 2019 MediaTek Inc.
6
7 */
8
9#include <linux/clk-provider.h>
10#include <linux/platform_device.h>
11
12#include "clk-mtk.h"
13#include "clk-gate.h"
14
15#include <dt-bindings/clock/mt6880-clk.h>
16
17#define MT_CLKMGR_MODULE_INIT 0
18
19#define MT_CCF_BRINGUP 1
20
21#define INV_OFS -1
22
23/* get spm power status struct to register inside clk_data */
24static struct pwr_status pwr_stat = GATE_PWR_STAT(0x16C,
25 0x170, INV_OFS, BIT(21), BIT(21));
26
27static const struct mtk_gate_regs audsys0_cg_regs = {
28 .set_ofs = 0x0,
29 .clr_ofs = 0x0,
30 .sta_ofs = 0x0,
31};
32
33static const struct mtk_gate_regs audsys1_cg_regs = {
34 .set_ofs = 0x4,
35 .clr_ofs = 0x4,
36 .sta_ofs = 0x4,
37};
38
39static const struct mtk_gate_regs audsys2_cg_regs = {
40 .set_ofs = 0x8,
41 .clr_ofs = 0x8,
42 .sta_ofs = 0x8,
43};
44
45#define GATE_AUDSYS0(_id, _name, _parent, _shift) { \
46 .id = _id, \
47 .name = _name, \
48 .parent_name = _parent, \
49 .regs = &audsys0_cg_regs, \
50 .shift = _shift, \
51 .ops = &mtk_clk_gate_ops_no_setclr, \
52 .pwr_stat = &pwr_stat, \
53 }
54
55#define GATE_AUDSYS1(_id, _name, _parent, _shift) { \
56 .id = _id, \
57 .name = _name, \
58 .parent_name = _parent, \
59 .regs = &audsys1_cg_regs, \
60 .shift = _shift, \
61 .ops = &mtk_clk_gate_ops_no_setclr, \
62 .pwr_stat = &pwr_stat, \
63 }
64
65#define GATE_AUDSYS2(_id, _name, _parent, _shift) { \
66 .id = _id, \
67 .name = _name, \
68 .parent_name = _parent, \
69 .regs = &audsys2_cg_regs, \
70 .shift = _shift, \
71 .ops = &mtk_clk_gate_ops_no_setclr, \
72 .pwr_stat = &pwr_stat, \
73 }
74
75static const struct mtk_gate audsys_clks[] = {
76 /* AUDSYS0 */
77 GATE_AUDSYS0(CLK_AUDSYS_AFE, "aud_afe",
78 "audio_ck"/* parent */, 2),
79 GATE_AUDSYS0(CLK_AUDSYS_22M, "aud_22m",
80 "aud_engen1_ck"/* parent */, 8),
81 GATE_AUDSYS0(CLK_AUDSYS_24M, "aud_24m",
82 "aud_engen2_ck"/* parent */, 9),
83 GATE_AUDSYS0(CLK_AUDSYS_APLL2_TUNER, "aud_apll2_tuner",
84 "aud_engen2_ck"/* parent */, 18),
85 GATE_AUDSYS0(CLK_AUDSYS_APLL_TUNER, "aud_apll_tuner",
86 "aud_engen1_ck"/* parent */, 19),
87 GATE_AUDSYS0(CLK_AUDSYS_TDM, "aud_tdm_ck",
88 "aud_engen1_ck"/* parent */, 20),
89 GATE_AUDSYS0(CLK_AUDSYS_ADC, "aud_adc",
90 "audio_ck"/* parent */, 24),
91 GATE_AUDSYS0(CLK_AUDSYS_DAC, "aud_dac",
92 "audio_ck"/* parent */, 25),
93 GATE_AUDSYS0(CLK_AUDSYS_DAC_PREDIS, "aud_dac_predis",
94 "audio_ck"/* parent */, 26),
95 GATE_AUDSYS0(CLK_AUDSYS_TML, "aud_tml",
96 "audio_ck"/* parent */, 27),
97 /* AUDSYS1 */
98 GATE_AUDSYS1(CLK_AUDSYS_I2S0_BCLK, "aud_i2s0_bclk",
99 "audio_ck"/* parent */, 4),
100 GATE_AUDSYS1(CLK_AUDSYS_I2S1_BCLK, "aud_i2s1_bclk",
101 "audio_ck"/* parent */, 5),
102 GATE_AUDSYS1(CLK_AUDSYS_I2S2_BCLK, "aud_i2s2_bclk",
103 "audio_ck"/* parent */, 6),
104 GATE_AUDSYS1(CLK_AUDSYS_I2S4_BCLK, "aud_i2s4_bclk",
105 "audio_ck"/* parent */, 7),
106 GATE_AUDSYS1(CLK_AUDSYS_I2S5_BCLK, "aud_i2s5_bclk",
107 "audio_ck"/* parent */, 8),
108 GATE_AUDSYS1(CLK_AUDSYS_I2S6_BCLK, "aud_i2s6_bclk",
109 "audio_ck"/* parent */, 9),
110 GATE_AUDSYS1(CLK_AUDSYS_GENERAL1_ASRC, "aud_general1_asrc",
111 "audio_ck"/* parent */, 13),
112 GATE_AUDSYS1(CLK_AUDSYS_GENERAL2_ASRC, "aud_general2_asrc",
113 "audio_ck"/* parent */, 14),
114 GATE_AUDSYS1(CLK_AUDSYS_ADDA6_ADC, "aud_adda6_adc",
115 "audio_ck"/* parent */, 20),
116 /* AUDSYS2 */
117 GATE_AUDSYS2(CLK_AUDSYS_CONNSYS_I2S_ASRC, "aud_connsys_i2s_asrc",
118 "audio_ck"/* parent */, 12),
119 GATE_AUDSYS2(CLK_AUDSYS_AFE_SRC_PCM_TX, "aud_afe_src_pcm_tx",
120 "audio_ck"/* parent */, 16),
121 GATE_AUDSYS2(CLK_AUDSYS_AFE_SRC_PCM_TX2, "aud_afe_src_pcm_tx2",
122 "audio_ck"/* parent */, 17),
123 GATE_AUDSYS2(CLK_AUDSYS_AFE_SRC_PCM_TX3, "aud_afe_src_pcm_tx3",
124 "audio_ck"/* parent */, 18),
125 GATE_AUDSYS2(CLK_AUDSYS_AFE_SRC_PCM_RX, "aud_afe_src_pcm_rx",
126 "audio_ck"/* parent */, 19),
127 GATE_AUDSYS2(CLK_AUDSYS_AFE_SRC_I2SIN, "aud_afe_src_i2sin",
128 "audio_ck"/* parent */, 20),
129 GATE_AUDSYS2(CLK_AUDSYS_AFE_SRC_I2SOUT, "aud_afe_src_i2sout",
130 "audio_ck"/* parent */, 21),
131};
132
133static int clk_mt6880_audsys_probe(struct platform_device *pdev)
134{
135 struct clk_onecell_data *clk_data;
136 int r;
137 struct device_node *node = pdev->dev.of_node;
138
139#if MT_CCF_BRINGUP
140 pr_notice("%s init begin\n", __func__);
141#endif
142
143 clk_data = mtk_alloc_clk_data(CLK_AUDSYS_NR_CLK);
144
145 mtk_clk_register_gates(node, audsys_clks, ARRAY_SIZE(audsys_clks),
146 clk_data);
147
148 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
149
150 if (r)
151 pr_err("%s(): could not register clock provider: %d\n",
152 __func__, r);
153
154#if MT_CCF_BRINGUP
155 pr_notice("%s init end\n", __func__);
156#endif
157
158 return r;
159}
160
161static const struct of_device_id of_match_clk_mt6880_audsys[] = {
162 { .compatible = "mediatek,mt6880-audsys", },
163 {}
164};
165
166#if MT_CLKMGR_MODULE_INIT
167
168static struct platform_driver clk_mt6880_audsys_drv = {
169 .probe = clk_mt6880_audsys_probe,
170 .driver = {
171 .name = "clk-mt6880-audsys",
172 .of_match_table = of_match_clk_mt6880_audsys,
173 },
174};
175
176builtin_platform_driver(clk_mt6880_audsys_drv);
177
178#else
179
180static struct platform_driver clk_mt6880_audsys_drv = {
181 .probe = clk_mt6880_audsys_probe,
182 .driver = {
183 .name = "clk-mt6880-audsys",
184 .of_match_table = of_match_clk_mt6880_audsys,
185 },
186};
187static int __init clk_mt6880_audsys_platform_init(void)
188{
189 return platform_driver_register(&clk_mt6880_audsys_drv);
190}
191arch_initcall(clk_mt6880_audsys_platform_init);
192
193#endif /* MT_CLKMGR_MODULE_INIT */