xref: /openbmc/linux/drivers/clk/meson/axg-audio.c (revision 6355592e)
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 /*
3  * Copyright (c) 2018 BayLibre, SAS.
4  * Author: Jerome Brunet <jbrunet@baylibre.com>
5  */
6 
7 #include <linux/clk.h>
8 #include <linux/clk-provider.h>
9 #include <linux/init.h>
10 #include <linux/of_device.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/regmap.h>
14 #include <linux/reset.h>
15 #include <linux/slab.h>
16 
17 #include "axg-audio.h"
18 #include "clk-regmap.h"
19 #include "clk-phase.h"
20 #include "sclk-div.h"
21 
22 #define AUD_MST_IN_COUNT	8
23 #define AUD_SLV_SCLK_COUNT	10
24 #define AUD_SLV_LRCLK_COUNT	10
25 
26 #define AUD_GATE(_name, _reg, _bit, _phws, _iflags)			\
27 struct clk_regmap aud_##_name = {					\
28 	.data = &(struct clk_regmap_gate_data){				\
29 		.offset = (_reg),					\
30 		.bit_idx = (_bit),					\
31 	},								\
32 	.hw.init = &(struct clk_init_data) {				\
33 		.name = "aud_"#_name,					\
34 		.ops = &clk_regmap_gate_ops,				\
35 		.parent_hws = (const struct clk_hw *[]) { &_phws.hw },	\
36 		.num_parents = 1,					\
37 		.flags = CLK_DUTY_CYCLE_PARENT | (_iflags),		\
38 	},								\
39 }
40 
41 #define AUD_MUX(_name, _reg, _mask, _shift, _dflags, _pdata, _iflags)	\
42 struct clk_regmap aud_##_name = {					\
43 	.data = &(struct clk_regmap_mux_data){				\
44 		.offset = (_reg),					\
45 		.mask = (_mask),					\
46 		.shift = (_shift),					\
47 		.flags = (_dflags),					\
48 	},								\
49 	.hw.init = &(struct clk_init_data){				\
50 		.name = "aud_"#_name,					\
51 		.ops = &clk_regmap_mux_ops,				\
52 		.parent_data = _pdata,					\
53 		.num_parents = ARRAY_SIZE(_pdata),			\
54 		.flags = CLK_DUTY_CYCLE_PARENT | (_iflags),		\
55 	},								\
56 }
57 
58 #define AUD_DIV(_name, _reg, _shift, _width, _dflags, _phws, _iflags)	\
59 struct clk_regmap aud_##_name = {					\
60 	.data = &(struct clk_regmap_div_data){				\
61 		.offset = (_reg),					\
62 		.shift = (_shift),					\
63 		.width = (_width),					\
64 		.flags = (_dflags),					\
65 	},								\
66 	.hw.init = &(struct clk_init_data){				\
67 		.name = "aud_"#_name,					\
68 		.ops = &clk_regmap_divider_ops,				\
69 		.parent_hws = (const struct clk_hw *[]) { &_phws.hw },	\
70 		.num_parents = 1,					\
71 		.flags = (_iflags),					\
72 	},								\
73 }
74 
75 #define AUD_PCLK_GATE(_name, _bit)				\
76 struct clk_regmap aud_##_name = {					\
77 	.data = &(struct clk_regmap_gate_data){				\
78 		.offset = (AUDIO_CLK_GATE_EN),				\
79 		.bit_idx = (_bit),					\
80 	},								\
81 	.hw.init = &(struct clk_init_data) {				\
82 		.name = "aud_"#_name,					\
83 		.ops = &clk_regmap_gate_ops,				\
84 		.parent_data = &(const struct clk_parent_data) {	\
85 			.fw_name = "pclk",				\
86 		},							\
87 		.num_parents = 1,					\
88 	},								\
89 }
90 /* Audio peripheral clocks */
91 static AUD_PCLK_GATE(ddr_arb,	   0);
92 static AUD_PCLK_GATE(pdm,	   1);
93 static AUD_PCLK_GATE(tdmin_a,	   2);
94 static AUD_PCLK_GATE(tdmin_b,	   3);
95 static AUD_PCLK_GATE(tdmin_c,	   4);
96 static AUD_PCLK_GATE(tdmin_lb,	   5);
97 static AUD_PCLK_GATE(tdmout_a,	   6);
98 static AUD_PCLK_GATE(tdmout_b,	   7);
99 static AUD_PCLK_GATE(tdmout_c,	   8);
100 static AUD_PCLK_GATE(frddr_a,	   9);
101 static AUD_PCLK_GATE(frddr_b,	   10);
102 static AUD_PCLK_GATE(frddr_c,	   11);
103 static AUD_PCLK_GATE(toddr_a,	   12);
104 static AUD_PCLK_GATE(toddr_b,	   13);
105 static AUD_PCLK_GATE(toddr_c,	   14);
106 static AUD_PCLK_GATE(loopback,	   15);
107 static AUD_PCLK_GATE(spdifin,	   16);
108 static AUD_PCLK_GATE(spdifout,	   17);
109 static AUD_PCLK_GATE(resample,	   18);
110 static AUD_PCLK_GATE(power_detect, 19);
111 static AUD_PCLK_GATE(spdifout_b,   21);
112 
113 /* Audio Master Clocks */
114 static const struct clk_parent_data mst_mux_parent_data[] = {
115 	{ .fw_name = "mst_in0", },
116 	{ .fw_name = "mst_in1", },
117 	{ .fw_name = "mst_in2", },
118 	{ .fw_name = "mst_in3", },
119 	{ .fw_name = "mst_in4", },
120 	{ .fw_name = "mst_in5", },
121 	{ .fw_name = "mst_in6", },
122 	{ .fw_name = "mst_in7", },
123 };
124 
125 #define AUD_MST_MUX(_name, _reg, _flag)				\
126 	AUD_MUX(_name##_sel, _reg, 0x7, 24, _flag,		\
127 		mst_mux_parent_data, 0)
128 
129 #define AUD_MST_MCLK_MUX(_name, _reg)				\
130 	AUD_MST_MUX(_name, _reg, CLK_MUX_ROUND_CLOSEST)
131 
132 #define AUD_MST_SYS_MUX(_name, _reg)				\
133 	AUD_MST_MUX(_name, _reg, 0)
134 
135 static AUD_MST_MCLK_MUX(mst_a_mclk,   AUDIO_MCLK_A_CTRL);
136 static AUD_MST_MCLK_MUX(mst_b_mclk,   AUDIO_MCLK_B_CTRL);
137 static AUD_MST_MCLK_MUX(mst_c_mclk,   AUDIO_MCLK_C_CTRL);
138 static AUD_MST_MCLK_MUX(mst_d_mclk,   AUDIO_MCLK_D_CTRL);
139 static AUD_MST_MCLK_MUX(mst_e_mclk,   AUDIO_MCLK_E_CTRL);
140 static AUD_MST_MCLK_MUX(mst_f_mclk,   AUDIO_MCLK_F_CTRL);
141 static AUD_MST_MCLK_MUX(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL);
142 static AUD_MST_MCLK_MUX(pdm_dclk,     AUDIO_CLK_PDMIN_CTRL0);
143 static AUD_MST_SYS_MUX(spdifin_clk,   AUDIO_CLK_SPDIFIN_CTRL);
144 static AUD_MST_SYS_MUX(pdm_sysclk,    AUDIO_CLK_PDMIN_CTRL1);
145 static AUD_MST_MCLK_MUX(spdifout_b_clk, AUDIO_CLK_SPDIFOUT_B_CTRL);
146 
147 #define AUD_MST_DIV(_name, _reg, _flag)				\
148 	AUD_DIV(_name##_div, _reg, 0, 16, _flag,		\
149 		    aud_##_name##_sel, CLK_SET_RATE_PARENT)	\
150 
151 #define AUD_MST_MCLK_DIV(_name, _reg)				\
152 	AUD_MST_DIV(_name, _reg, CLK_DIVIDER_ROUND_CLOSEST)
153 
154 #define AUD_MST_SYS_DIV(_name, _reg)				\
155 	AUD_MST_DIV(_name, _reg, 0)
156 
157 static AUD_MST_MCLK_DIV(mst_a_mclk,   AUDIO_MCLK_A_CTRL);
158 static AUD_MST_MCLK_DIV(mst_b_mclk,   AUDIO_MCLK_B_CTRL);
159 static AUD_MST_MCLK_DIV(mst_c_mclk,   AUDIO_MCLK_C_CTRL);
160 static AUD_MST_MCLK_DIV(mst_d_mclk,   AUDIO_MCLK_D_CTRL);
161 static AUD_MST_MCLK_DIV(mst_e_mclk,   AUDIO_MCLK_E_CTRL);
162 static AUD_MST_MCLK_DIV(mst_f_mclk,   AUDIO_MCLK_F_CTRL);
163 static AUD_MST_MCLK_DIV(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL);
164 static AUD_MST_MCLK_DIV(pdm_dclk,     AUDIO_CLK_PDMIN_CTRL0);
165 static AUD_MST_SYS_DIV(spdifin_clk,   AUDIO_CLK_SPDIFIN_CTRL);
166 static AUD_MST_SYS_DIV(pdm_sysclk,    AUDIO_CLK_PDMIN_CTRL1);
167 static AUD_MST_MCLK_DIV(spdifout_b_clk, AUDIO_CLK_SPDIFOUT_B_CTRL);
168 
169 #define AUD_MST_MCLK_GATE(_name, _reg)				\
170 	AUD_GATE(_name, _reg, 31,  aud_##_name##_div,		\
171 		 CLK_SET_RATE_PARENT)
172 
173 static AUD_MST_MCLK_GATE(mst_a_mclk,   AUDIO_MCLK_A_CTRL);
174 static AUD_MST_MCLK_GATE(mst_b_mclk,   AUDIO_MCLK_B_CTRL);
175 static AUD_MST_MCLK_GATE(mst_c_mclk,   AUDIO_MCLK_C_CTRL);
176 static AUD_MST_MCLK_GATE(mst_d_mclk,   AUDIO_MCLK_D_CTRL);
177 static AUD_MST_MCLK_GATE(mst_e_mclk,   AUDIO_MCLK_E_CTRL);
178 static AUD_MST_MCLK_GATE(mst_f_mclk,   AUDIO_MCLK_F_CTRL);
179 static AUD_MST_MCLK_GATE(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL);
180 static AUD_MST_MCLK_GATE(spdifin_clk,  AUDIO_CLK_SPDIFIN_CTRL);
181 static AUD_MST_MCLK_GATE(pdm_dclk,     AUDIO_CLK_PDMIN_CTRL0);
182 static AUD_MST_MCLK_GATE(pdm_sysclk,   AUDIO_CLK_PDMIN_CTRL1);
183 static AUD_MST_MCLK_GATE(spdifout_b_clk, AUDIO_CLK_SPDIFOUT_B_CTRL);
184 
185 /* Sample Clocks */
186 #define AUD_MST_SCLK_PRE_EN(_name, _reg)			\
187 	AUD_GATE(mst_##_name##_sclk_pre_en, _reg, 31,		\
188 		 aud_mst_##_name##_mclk, 0)
189 
190 static AUD_MST_SCLK_PRE_EN(a, AUDIO_MST_A_SCLK_CTRL0);
191 static AUD_MST_SCLK_PRE_EN(b, AUDIO_MST_B_SCLK_CTRL0);
192 static AUD_MST_SCLK_PRE_EN(c, AUDIO_MST_C_SCLK_CTRL0);
193 static AUD_MST_SCLK_PRE_EN(d, AUDIO_MST_D_SCLK_CTRL0);
194 static AUD_MST_SCLK_PRE_EN(e, AUDIO_MST_E_SCLK_CTRL0);
195 static AUD_MST_SCLK_PRE_EN(f, AUDIO_MST_F_SCLK_CTRL0);
196 
197 #define AUD_SCLK_DIV(_name, _reg, _div_shift, _div_width,		\
198 			 _hi_shift, _hi_width, _phws, _iflags)		\
199 struct clk_regmap aud_##_name = {					\
200 	.data = &(struct meson_sclk_div_data) {				\
201 		.div = {						\
202 			.reg_off = (_reg),				\
203 			.shift   = (_div_shift),			\
204 			.width   = (_div_width),			\
205 		},							\
206 		.hi = {							\
207 			.reg_off = (_reg),				\
208 			.shift   = (_hi_shift),				\
209 			.width   = (_hi_width),				\
210 		},							\
211 	},								\
212 	.hw.init = &(struct clk_init_data) {				\
213 		.name = "aud_"#_name,					\
214 		.ops = &meson_sclk_div_ops,				\
215 		.parent_hws = (const struct clk_hw *[]) { &_phws.hw },	\
216 		.num_parents = 1,					\
217 		.flags = (_iflags),					\
218 	},								\
219 }
220 
221 #define AUD_MST_SCLK_DIV(_name, _reg)					\
222 	AUD_SCLK_DIV(mst_##_name##_sclk_div, _reg, 20, 10, 0, 0,	\
223 		     aud_mst_##_name##_sclk_pre_en,			\
224 		     CLK_SET_RATE_PARENT)
225 
226 static AUD_MST_SCLK_DIV(a, AUDIO_MST_A_SCLK_CTRL0);
227 static AUD_MST_SCLK_DIV(b, AUDIO_MST_B_SCLK_CTRL0);
228 static AUD_MST_SCLK_DIV(c, AUDIO_MST_C_SCLK_CTRL0);
229 static AUD_MST_SCLK_DIV(d, AUDIO_MST_D_SCLK_CTRL0);
230 static AUD_MST_SCLK_DIV(e, AUDIO_MST_E_SCLK_CTRL0);
231 static AUD_MST_SCLK_DIV(f, AUDIO_MST_F_SCLK_CTRL0);
232 
233 #define AUD_MST_SCLK_POST_EN(_name, _reg)				\
234 	AUD_GATE(mst_##_name##_sclk_post_en, _reg, 30,			\
235 		 aud_mst_##_name##_sclk_div, CLK_SET_RATE_PARENT)
236 
237 static AUD_MST_SCLK_POST_EN(a, AUDIO_MST_A_SCLK_CTRL0);
238 static AUD_MST_SCLK_POST_EN(b, AUDIO_MST_B_SCLK_CTRL0);
239 static AUD_MST_SCLK_POST_EN(c, AUDIO_MST_C_SCLK_CTRL0);
240 static AUD_MST_SCLK_POST_EN(d, AUDIO_MST_D_SCLK_CTRL0);
241 static AUD_MST_SCLK_POST_EN(e, AUDIO_MST_E_SCLK_CTRL0);
242 static AUD_MST_SCLK_POST_EN(f, AUDIO_MST_F_SCLK_CTRL0);
243 
244 #define AUD_TRIPHASE(_name, _reg, _width, _shift0, _shift1, _shift2,	\
245 			 _phws, _iflags)				\
246 struct clk_regmap aud_##_name = {					\
247 	.data = &(struct meson_clk_triphase_data) {			\
248 		.ph0 = {						\
249 			.reg_off = (_reg),				\
250 			.shift   = (_shift0),				\
251 			.width   = (_width),				\
252 		},							\
253 		.ph1 = {						\
254 			.reg_off = (_reg),				\
255 			.shift   = (_shift1),				\
256 			.width   = (_width),				\
257 		},							\
258 		.ph2 = {						\
259 			.reg_off = (_reg),				\
260 			.shift   = (_shift2),				\
261 			.width   = (_width),				\
262 		},							\
263 	},								\
264 	.hw.init = &(struct clk_init_data) {				\
265 		.name = "aud_"#_name,					\
266 		.ops = &meson_clk_triphase_ops,				\
267 		.parent_hws = (const struct clk_hw *[]) { &_phws.hw },	\
268 		.num_parents = 1,					\
269 		.flags = CLK_DUTY_CYCLE_PARENT | (_iflags),		\
270 	},								\
271 }
272 
273 #define AUD_MST_SCLK(_name, _reg)					\
274 	AUD_TRIPHASE(mst_##_name##_sclk, _reg, 1, 0, 2, 4,		\
275 		     aud_mst_##_name##_sclk_post_en, CLK_SET_RATE_PARENT)
276 
277 static AUD_MST_SCLK(a, AUDIO_MST_A_SCLK_CTRL1);
278 static AUD_MST_SCLK(b, AUDIO_MST_B_SCLK_CTRL1);
279 static AUD_MST_SCLK(c, AUDIO_MST_C_SCLK_CTRL1);
280 static AUD_MST_SCLK(d, AUDIO_MST_D_SCLK_CTRL1);
281 static AUD_MST_SCLK(e, AUDIO_MST_E_SCLK_CTRL1);
282 static AUD_MST_SCLK(f, AUDIO_MST_F_SCLK_CTRL1);
283 
284 #define AUD_MST_LRCLK_DIV(_name, _reg)					\
285 	AUD_SCLK_DIV(mst_##_name##_lrclk_div, _reg, 0, 10, 10, 10,	\
286 		     aud_mst_##_name##_sclk_post_en, 0)			\
287 
288 static AUD_MST_LRCLK_DIV(a, AUDIO_MST_A_SCLK_CTRL0);
289 static AUD_MST_LRCLK_DIV(b, AUDIO_MST_B_SCLK_CTRL0);
290 static AUD_MST_LRCLK_DIV(c, AUDIO_MST_C_SCLK_CTRL0);
291 static AUD_MST_LRCLK_DIV(d, AUDIO_MST_D_SCLK_CTRL0);
292 static AUD_MST_LRCLK_DIV(e, AUDIO_MST_E_SCLK_CTRL0);
293 static AUD_MST_LRCLK_DIV(f, AUDIO_MST_F_SCLK_CTRL0);
294 
295 #define AUD_MST_LRCLK(_name, _reg)					\
296 	AUD_TRIPHASE(mst_##_name##_lrclk, _reg, 1, 1, 3, 5,		\
297 		     aud_mst_##_name##_lrclk_div, CLK_SET_RATE_PARENT)
298 
299 static AUD_MST_LRCLK(a, AUDIO_MST_A_SCLK_CTRL1);
300 static AUD_MST_LRCLK(b, AUDIO_MST_B_SCLK_CTRL1);
301 static AUD_MST_LRCLK(c, AUDIO_MST_C_SCLK_CTRL1);
302 static AUD_MST_LRCLK(d, AUDIO_MST_D_SCLK_CTRL1);
303 static AUD_MST_LRCLK(e, AUDIO_MST_E_SCLK_CTRL1);
304 static AUD_MST_LRCLK(f, AUDIO_MST_F_SCLK_CTRL1);
305 
306 static const struct clk_parent_data tdm_sclk_parent_data[] = {
307 	{ .hw = &aud_mst_a_sclk.hw, },
308 	{ .hw = &aud_mst_b_sclk.hw, },
309 	{ .hw = &aud_mst_c_sclk.hw, },
310 	{ .hw = &aud_mst_d_sclk.hw, },
311 	{ .hw = &aud_mst_e_sclk.hw, },
312 	{ .hw = &aud_mst_f_sclk.hw, },
313 	{ .fw_name = "slv_sclk0", },
314 	{ .fw_name = "slv_sclk1", },
315 	{ .fw_name = "slv_sclk2", },
316 	{ .fw_name = "slv_sclk3", },
317 	{ .fw_name = "slv_sclk4", },
318 	{ .fw_name = "slv_sclk5", },
319 	{ .fw_name = "slv_sclk6", },
320 	{ .fw_name = "slv_sclk7", },
321 	{ .fw_name = "slv_sclk8", },
322 	{ .fw_name = "slv_sclk9", },
323 };
324 
325 #define AUD_TDM_SCLK_MUX(_name, _reg)				\
326 	AUD_MUX(tdm##_name##_sclk_sel, _reg, 0xf, 24,		\
327 		    CLK_MUX_ROUND_CLOSEST,			\
328 		    tdm_sclk_parent_data, 0)
329 
330 static AUD_TDM_SCLK_MUX(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
331 static AUD_TDM_SCLK_MUX(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
332 static AUD_TDM_SCLK_MUX(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
333 static AUD_TDM_SCLK_MUX(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
334 static AUD_TDM_SCLK_MUX(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
335 static AUD_TDM_SCLK_MUX(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
336 static AUD_TDM_SCLK_MUX(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
337 
338 #define AUD_TDM_SCLK_PRE_EN(_name, _reg)				\
339 	AUD_GATE(tdm##_name##_sclk_pre_en, _reg, 31,			\
340 		 aud_tdm##_name##_sclk_sel, CLK_SET_RATE_PARENT)
341 
342 static AUD_TDM_SCLK_PRE_EN(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
343 static AUD_TDM_SCLK_PRE_EN(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
344 static AUD_TDM_SCLK_PRE_EN(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
345 static AUD_TDM_SCLK_PRE_EN(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
346 static AUD_TDM_SCLK_PRE_EN(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
347 static AUD_TDM_SCLK_PRE_EN(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
348 static AUD_TDM_SCLK_PRE_EN(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
349 
350 #define AUD_TDM_SCLK_POST_EN(_name, _reg)				\
351 	AUD_GATE(tdm##_name##_sclk_post_en, _reg, 30,			\
352 		 aud_tdm##_name##_sclk_pre_en, CLK_SET_RATE_PARENT)
353 
354 static AUD_TDM_SCLK_POST_EN(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
355 static AUD_TDM_SCLK_POST_EN(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
356 static AUD_TDM_SCLK_POST_EN(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
357 static AUD_TDM_SCLK_POST_EN(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
358 static AUD_TDM_SCLK_POST_EN(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
359 static AUD_TDM_SCLK_POST_EN(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
360 static AUD_TDM_SCLK_POST_EN(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
361 
362 #define AUD_TDM_SCLK(_name, _reg)					\
363 	struct clk_regmap aud_tdm##_name##_sclk = {			\
364 	.data = &(struct meson_clk_phase_data) {			\
365 		.ph = {							\
366 			.reg_off = (_reg),				\
367 			.shift   = 29,					\
368 			.width   = 1,					\
369 		},							\
370 	},								\
371 	.hw.init = &(struct clk_init_data) {				\
372 		.name = "aud_tdm"#_name"_sclk",				\
373 		.ops = &meson_clk_phase_ops,				\
374 		.parent_hws = (const struct clk_hw *[]) {		\
375 			&aud_tdm##_name##_sclk_post_en.hw		\
376 		},							\
377 		.num_parents = 1,					\
378 		.flags = CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT,	\
379 	},								\
380 }
381 
382 static AUD_TDM_SCLK(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
383 static AUD_TDM_SCLK(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
384 static AUD_TDM_SCLK(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
385 static AUD_TDM_SCLK(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
386 static AUD_TDM_SCLK(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
387 static AUD_TDM_SCLK(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
388 static AUD_TDM_SCLK(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
389 
390 static const struct clk_parent_data tdm_lrclk_parent_data[] = {
391 	{ .hw = &aud_mst_a_lrclk.hw, },
392 	{ .hw = &aud_mst_b_lrclk.hw, },
393 	{ .hw = &aud_mst_c_lrclk.hw, },
394 	{ .hw = &aud_mst_d_lrclk.hw, },
395 	{ .hw = &aud_mst_e_lrclk.hw, },
396 	{ .hw = &aud_mst_f_lrclk.hw, },
397 	{ .fw_name = "slv_lrclk0", },
398 	{ .fw_name = "slv_lrclk1", },
399 	{ .fw_name = "slv_lrclk2", },
400 	{ .fw_name = "slv_lrclk3", },
401 	{ .fw_name = "slv_lrclk4", },
402 	{ .fw_name = "slv_lrclk5", },
403 	{ .fw_name = "slv_lrclk6", },
404 	{ .fw_name = "slv_lrclk7", },
405 	{ .fw_name = "slv_lrclk8", },
406 	{ .fw_name = "slv_lrclk9", },
407 };
408 
409 #define AUD_TDM_LRLCK(_name, _reg)			\
410 	AUD_MUX(tdm##_name##_lrclk, _reg, 0xf, 20,	\
411 		CLK_MUX_ROUND_CLOSEST,			\
412 		tdm_lrclk_parent_data, 0)
413 
414 static AUD_TDM_LRLCK(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
415 static AUD_TDM_LRLCK(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
416 static AUD_TDM_LRLCK(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
417 static AUD_TDM_LRLCK(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
418 static AUD_TDM_LRLCK(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
419 static AUD_TDM_LRLCK(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
420 static AUD_TDM_LRLCK(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
421 
422 /* G12a Pad control */
423 #define AUD_TDM_PAD_CTRL(_name, _reg, _shift, _parents)		\
424 	AUD_MUX(tdm_##_name, _reg, 0x7, _shift, 0, _parents,	\
425 		CLK_SET_RATE_NO_REPARENT)
426 
427 static const struct clk_parent_data mclk_pad_ctrl_parent_data[] = {
428 	{ .hw = &aud_mst_a_mclk.hw },
429 	{ .hw = &aud_mst_b_mclk.hw },
430 	{ .hw = &aud_mst_c_mclk.hw },
431 	{ .hw = &aud_mst_d_mclk.hw },
432 	{ .hw = &aud_mst_e_mclk.hw },
433 	{ .hw = &aud_mst_f_mclk.hw },
434 };
435 
436 static AUD_TDM_PAD_CTRL(mclk_pad_0, AUDIO_MST_PAD_CTRL0, 0,
437 			mclk_pad_ctrl_parent_data);
438 static AUD_TDM_PAD_CTRL(mclk_pad_1, AUDIO_MST_PAD_CTRL0, 4,
439 			mclk_pad_ctrl_parent_data);
440 
441 static const struct clk_parent_data lrclk_pad_ctrl_parent_data[] = {
442 	{ .hw = &aud_mst_a_lrclk.hw },
443 	{ .hw = &aud_mst_b_lrclk.hw },
444 	{ .hw = &aud_mst_c_lrclk.hw },
445 	{ .hw = &aud_mst_d_lrclk.hw },
446 	{ .hw = &aud_mst_e_lrclk.hw },
447 	{ .hw = &aud_mst_f_lrclk.hw },
448 };
449 
450 static AUD_TDM_PAD_CTRL(lrclk_pad_0, AUDIO_MST_PAD_CTRL1, 16,
451 			lrclk_pad_ctrl_parent_data);
452 static AUD_TDM_PAD_CTRL(lrclk_pad_1, AUDIO_MST_PAD_CTRL1, 20,
453 			lrclk_pad_ctrl_parent_data);
454 static AUD_TDM_PAD_CTRL(lrclk_pad_2, AUDIO_MST_PAD_CTRL1, 24,
455 			lrclk_pad_ctrl_parent_data);
456 
457 static const struct clk_parent_data sclk_pad_ctrl_parent_data[] = {
458 	{ .hw = &aud_mst_a_sclk.hw },
459 	{ .hw = &aud_mst_b_sclk.hw },
460 	{ .hw = &aud_mst_c_sclk.hw },
461 	{ .hw = &aud_mst_d_sclk.hw },
462 	{ .hw = &aud_mst_e_sclk.hw },
463 	{ .hw = &aud_mst_f_sclk.hw },
464 };
465 
466 static AUD_TDM_PAD_CTRL(sclk_pad_0, AUDIO_MST_PAD_CTRL1, 0,
467 			sclk_pad_ctrl_parent_data);
468 static AUD_TDM_PAD_CTRL(sclk_pad_1, AUDIO_MST_PAD_CTRL1, 4,
469 			sclk_pad_ctrl_parent_data);
470 static AUD_TDM_PAD_CTRL(sclk_pad_2, AUDIO_MST_PAD_CTRL1, 8,
471 			sclk_pad_ctrl_parent_data);
472 
473 /*
474  * Array of all clocks provided by this provider
475  * The input clocks of the controller will be populated at runtime
476  */
477 static struct clk_hw_onecell_data axg_audio_hw_onecell_data = {
478 	.hws = {
479 		[AUD_CLKID_DDR_ARB]		= &aud_ddr_arb.hw,
480 		[AUD_CLKID_PDM]			= &aud_pdm.hw,
481 		[AUD_CLKID_TDMIN_A]		= &aud_tdmin_a.hw,
482 		[AUD_CLKID_TDMIN_B]		= &aud_tdmin_b.hw,
483 		[AUD_CLKID_TDMIN_C]		= &aud_tdmin_c.hw,
484 		[AUD_CLKID_TDMIN_LB]		= &aud_tdmin_lb.hw,
485 		[AUD_CLKID_TDMOUT_A]		= &aud_tdmout_a.hw,
486 		[AUD_CLKID_TDMOUT_B]		= &aud_tdmout_b.hw,
487 		[AUD_CLKID_TDMOUT_C]		= &aud_tdmout_c.hw,
488 		[AUD_CLKID_FRDDR_A]		= &aud_frddr_a.hw,
489 		[AUD_CLKID_FRDDR_B]		= &aud_frddr_b.hw,
490 		[AUD_CLKID_FRDDR_C]		= &aud_frddr_c.hw,
491 		[AUD_CLKID_TODDR_A]		= &aud_toddr_a.hw,
492 		[AUD_CLKID_TODDR_B]		= &aud_toddr_b.hw,
493 		[AUD_CLKID_TODDR_C]		= &aud_toddr_c.hw,
494 		[AUD_CLKID_LOOPBACK]		= &aud_loopback.hw,
495 		[AUD_CLKID_SPDIFIN]		= &aud_spdifin.hw,
496 		[AUD_CLKID_SPDIFOUT]		= &aud_spdifout.hw,
497 		[AUD_CLKID_RESAMPLE]		= &aud_resample.hw,
498 		[AUD_CLKID_POWER_DETECT]	= &aud_power_detect.hw,
499 		[AUD_CLKID_MST_A_MCLK_SEL]	= &aud_mst_a_mclk_sel.hw,
500 		[AUD_CLKID_MST_B_MCLK_SEL]	= &aud_mst_b_mclk_sel.hw,
501 		[AUD_CLKID_MST_C_MCLK_SEL]	= &aud_mst_c_mclk_sel.hw,
502 		[AUD_CLKID_MST_D_MCLK_SEL]	= &aud_mst_d_mclk_sel.hw,
503 		[AUD_CLKID_MST_E_MCLK_SEL]	= &aud_mst_e_mclk_sel.hw,
504 		[AUD_CLKID_MST_F_MCLK_SEL]	= &aud_mst_f_mclk_sel.hw,
505 		[AUD_CLKID_MST_A_MCLK_DIV]	= &aud_mst_a_mclk_div.hw,
506 		[AUD_CLKID_MST_B_MCLK_DIV]	= &aud_mst_b_mclk_div.hw,
507 		[AUD_CLKID_MST_C_MCLK_DIV]	= &aud_mst_c_mclk_div.hw,
508 		[AUD_CLKID_MST_D_MCLK_DIV]	= &aud_mst_d_mclk_div.hw,
509 		[AUD_CLKID_MST_E_MCLK_DIV]	= &aud_mst_e_mclk_div.hw,
510 		[AUD_CLKID_MST_F_MCLK_DIV]	= &aud_mst_f_mclk_div.hw,
511 		[AUD_CLKID_MST_A_MCLK]		= &aud_mst_a_mclk.hw,
512 		[AUD_CLKID_MST_B_MCLK]		= &aud_mst_b_mclk.hw,
513 		[AUD_CLKID_MST_C_MCLK]		= &aud_mst_c_mclk.hw,
514 		[AUD_CLKID_MST_D_MCLK]		= &aud_mst_d_mclk.hw,
515 		[AUD_CLKID_MST_E_MCLK]		= &aud_mst_e_mclk.hw,
516 		[AUD_CLKID_MST_F_MCLK]		= &aud_mst_f_mclk.hw,
517 		[AUD_CLKID_SPDIFOUT_CLK_SEL]	= &aud_spdifout_clk_sel.hw,
518 		[AUD_CLKID_SPDIFOUT_CLK_DIV]	= &aud_spdifout_clk_div.hw,
519 		[AUD_CLKID_SPDIFOUT_CLK]	= &aud_spdifout_clk.hw,
520 		[AUD_CLKID_SPDIFIN_CLK_SEL]	= &aud_spdifin_clk_sel.hw,
521 		[AUD_CLKID_SPDIFIN_CLK_DIV]	= &aud_spdifin_clk_div.hw,
522 		[AUD_CLKID_SPDIFIN_CLK]		= &aud_spdifin_clk.hw,
523 		[AUD_CLKID_PDM_DCLK_SEL]	= &aud_pdm_dclk_sel.hw,
524 		[AUD_CLKID_PDM_DCLK_DIV]	= &aud_pdm_dclk_div.hw,
525 		[AUD_CLKID_PDM_DCLK]		= &aud_pdm_dclk.hw,
526 		[AUD_CLKID_PDM_SYSCLK_SEL]	= &aud_pdm_sysclk_sel.hw,
527 		[AUD_CLKID_PDM_SYSCLK_DIV]	= &aud_pdm_sysclk_div.hw,
528 		[AUD_CLKID_PDM_SYSCLK]		= &aud_pdm_sysclk.hw,
529 		[AUD_CLKID_MST_A_SCLK_PRE_EN]	= &aud_mst_a_sclk_pre_en.hw,
530 		[AUD_CLKID_MST_B_SCLK_PRE_EN]	= &aud_mst_b_sclk_pre_en.hw,
531 		[AUD_CLKID_MST_C_SCLK_PRE_EN]	= &aud_mst_c_sclk_pre_en.hw,
532 		[AUD_CLKID_MST_D_SCLK_PRE_EN]	= &aud_mst_d_sclk_pre_en.hw,
533 		[AUD_CLKID_MST_E_SCLK_PRE_EN]	= &aud_mst_e_sclk_pre_en.hw,
534 		[AUD_CLKID_MST_F_SCLK_PRE_EN]	= &aud_mst_f_sclk_pre_en.hw,
535 		[AUD_CLKID_MST_A_SCLK_DIV]	= &aud_mst_a_sclk_div.hw,
536 		[AUD_CLKID_MST_B_SCLK_DIV]	= &aud_mst_b_sclk_div.hw,
537 		[AUD_CLKID_MST_C_SCLK_DIV]	= &aud_mst_c_sclk_div.hw,
538 		[AUD_CLKID_MST_D_SCLK_DIV]	= &aud_mst_d_sclk_div.hw,
539 		[AUD_CLKID_MST_E_SCLK_DIV]	= &aud_mst_e_sclk_div.hw,
540 		[AUD_CLKID_MST_F_SCLK_DIV]	= &aud_mst_f_sclk_div.hw,
541 		[AUD_CLKID_MST_A_SCLK_POST_EN]	= &aud_mst_a_sclk_post_en.hw,
542 		[AUD_CLKID_MST_B_SCLK_POST_EN]	= &aud_mst_b_sclk_post_en.hw,
543 		[AUD_CLKID_MST_C_SCLK_POST_EN]	= &aud_mst_c_sclk_post_en.hw,
544 		[AUD_CLKID_MST_D_SCLK_POST_EN]	= &aud_mst_d_sclk_post_en.hw,
545 		[AUD_CLKID_MST_E_SCLK_POST_EN]	= &aud_mst_e_sclk_post_en.hw,
546 		[AUD_CLKID_MST_F_SCLK_POST_EN]	= &aud_mst_f_sclk_post_en.hw,
547 		[AUD_CLKID_MST_A_SCLK]		= &aud_mst_a_sclk.hw,
548 		[AUD_CLKID_MST_B_SCLK]		= &aud_mst_b_sclk.hw,
549 		[AUD_CLKID_MST_C_SCLK]		= &aud_mst_c_sclk.hw,
550 		[AUD_CLKID_MST_D_SCLK]		= &aud_mst_d_sclk.hw,
551 		[AUD_CLKID_MST_E_SCLK]		= &aud_mst_e_sclk.hw,
552 		[AUD_CLKID_MST_F_SCLK]		= &aud_mst_f_sclk.hw,
553 		[AUD_CLKID_MST_A_LRCLK_DIV]	= &aud_mst_a_lrclk_div.hw,
554 		[AUD_CLKID_MST_B_LRCLK_DIV]	= &aud_mst_b_lrclk_div.hw,
555 		[AUD_CLKID_MST_C_LRCLK_DIV]	= &aud_mst_c_lrclk_div.hw,
556 		[AUD_CLKID_MST_D_LRCLK_DIV]	= &aud_mst_d_lrclk_div.hw,
557 		[AUD_CLKID_MST_E_LRCLK_DIV]	= &aud_mst_e_lrclk_div.hw,
558 		[AUD_CLKID_MST_F_LRCLK_DIV]	= &aud_mst_f_lrclk_div.hw,
559 		[AUD_CLKID_MST_A_LRCLK]		= &aud_mst_a_lrclk.hw,
560 		[AUD_CLKID_MST_B_LRCLK]		= &aud_mst_b_lrclk.hw,
561 		[AUD_CLKID_MST_C_LRCLK]		= &aud_mst_c_lrclk.hw,
562 		[AUD_CLKID_MST_D_LRCLK]		= &aud_mst_d_lrclk.hw,
563 		[AUD_CLKID_MST_E_LRCLK]		= &aud_mst_e_lrclk.hw,
564 		[AUD_CLKID_MST_F_LRCLK]		= &aud_mst_f_lrclk.hw,
565 		[AUD_CLKID_TDMIN_A_SCLK_SEL]	= &aud_tdmin_a_sclk_sel.hw,
566 		[AUD_CLKID_TDMIN_B_SCLK_SEL]	= &aud_tdmin_b_sclk_sel.hw,
567 		[AUD_CLKID_TDMIN_C_SCLK_SEL]	= &aud_tdmin_c_sclk_sel.hw,
568 		[AUD_CLKID_TDMIN_LB_SCLK_SEL]	= &aud_tdmin_lb_sclk_sel.hw,
569 		[AUD_CLKID_TDMOUT_A_SCLK_SEL]	= &aud_tdmout_a_sclk_sel.hw,
570 		[AUD_CLKID_TDMOUT_B_SCLK_SEL]	= &aud_tdmout_b_sclk_sel.hw,
571 		[AUD_CLKID_TDMOUT_C_SCLK_SEL]	= &aud_tdmout_c_sclk_sel.hw,
572 		[AUD_CLKID_TDMIN_A_SCLK_PRE_EN]	= &aud_tdmin_a_sclk_pre_en.hw,
573 		[AUD_CLKID_TDMIN_B_SCLK_PRE_EN]	= &aud_tdmin_b_sclk_pre_en.hw,
574 		[AUD_CLKID_TDMIN_C_SCLK_PRE_EN]	= &aud_tdmin_c_sclk_pre_en.hw,
575 		[AUD_CLKID_TDMIN_LB_SCLK_PRE_EN] = &aud_tdmin_lb_sclk_pre_en.hw,
576 		[AUD_CLKID_TDMOUT_A_SCLK_PRE_EN] = &aud_tdmout_a_sclk_pre_en.hw,
577 		[AUD_CLKID_TDMOUT_B_SCLK_PRE_EN] = &aud_tdmout_b_sclk_pre_en.hw,
578 		[AUD_CLKID_TDMOUT_C_SCLK_PRE_EN] = &aud_tdmout_c_sclk_pre_en.hw,
579 		[AUD_CLKID_TDMIN_A_SCLK_POST_EN] = &aud_tdmin_a_sclk_post_en.hw,
580 		[AUD_CLKID_TDMIN_B_SCLK_POST_EN] = &aud_tdmin_b_sclk_post_en.hw,
581 		[AUD_CLKID_TDMIN_C_SCLK_POST_EN] = &aud_tdmin_c_sclk_post_en.hw,
582 		[AUD_CLKID_TDMIN_LB_SCLK_POST_EN] = &aud_tdmin_lb_sclk_post_en.hw,
583 		[AUD_CLKID_TDMOUT_A_SCLK_POST_EN] = &aud_tdmout_a_sclk_post_en.hw,
584 		[AUD_CLKID_TDMOUT_B_SCLK_POST_EN] = &aud_tdmout_b_sclk_post_en.hw,
585 		[AUD_CLKID_TDMOUT_C_SCLK_POST_EN] = &aud_tdmout_c_sclk_post_en.hw,
586 		[AUD_CLKID_TDMIN_A_SCLK]	= &aud_tdmin_a_sclk.hw,
587 		[AUD_CLKID_TDMIN_B_SCLK]	= &aud_tdmin_b_sclk.hw,
588 		[AUD_CLKID_TDMIN_C_SCLK]	= &aud_tdmin_c_sclk.hw,
589 		[AUD_CLKID_TDMIN_LB_SCLK]	= &aud_tdmin_lb_sclk.hw,
590 		[AUD_CLKID_TDMOUT_A_SCLK]	= &aud_tdmout_a_sclk.hw,
591 		[AUD_CLKID_TDMOUT_B_SCLK]	= &aud_tdmout_b_sclk.hw,
592 		[AUD_CLKID_TDMOUT_C_SCLK]	= &aud_tdmout_c_sclk.hw,
593 		[AUD_CLKID_TDMIN_A_LRCLK]	= &aud_tdmin_a_lrclk.hw,
594 		[AUD_CLKID_TDMIN_B_LRCLK]	= &aud_tdmin_b_lrclk.hw,
595 		[AUD_CLKID_TDMIN_C_LRCLK]	= &aud_tdmin_c_lrclk.hw,
596 		[AUD_CLKID_TDMIN_LB_LRCLK]	= &aud_tdmin_lb_lrclk.hw,
597 		[AUD_CLKID_TDMOUT_A_LRCLK]	= &aud_tdmout_a_lrclk.hw,
598 		[AUD_CLKID_TDMOUT_B_LRCLK]	= &aud_tdmout_b_lrclk.hw,
599 		[AUD_CLKID_TDMOUT_C_LRCLK]	= &aud_tdmout_c_lrclk.hw,
600 		[NR_CLKS] = NULL,
601 	},
602 	.num = NR_CLKS,
603 };
604 
605 /*
606  * Array of all G12A clocks provided by this provider
607  * The input clocks of the controller will be populated at runtime
608  */
609 static struct clk_hw_onecell_data g12a_audio_hw_onecell_data = {
610 	.hws = {
611 		[AUD_CLKID_DDR_ARB]		= &aud_ddr_arb.hw,
612 		[AUD_CLKID_PDM]			= &aud_pdm.hw,
613 		[AUD_CLKID_TDMIN_A]		= &aud_tdmin_a.hw,
614 		[AUD_CLKID_TDMIN_B]		= &aud_tdmin_b.hw,
615 		[AUD_CLKID_TDMIN_C]		= &aud_tdmin_c.hw,
616 		[AUD_CLKID_TDMIN_LB]		= &aud_tdmin_lb.hw,
617 		[AUD_CLKID_TDMOUT_A]		= &aud_tdmout_a.hw,
618 		[AUD_CLKID_TDMOUT_B]		= &aud_tdmout_b.hw,
619 		[AUD_CLKID_TDMOUT_C]		= &aud_tdmout_c.hw,
620 		[AUD_CLKID_FRDDR_A]		= &aud_frddr_a.hw,
621 		[AUD_CLKID_FRDDR_B]		= &aud_frddr_b.hw,
622 		[AUD_CLKID_FRDDR_C]		= &aud_frddr_c.hw,
623 		[AUD_CLKID_TODDR_A]		= &aud_toddr_a.hw,
624 		[AUD_CLKID_TODDR_B]		= &aud_toddr_b.hw,
625 		[AUD_CLKID_TODDR_C]		= &aud_toddr_c.hw,
626 		[AUD_CLKID_LOOPBACK]		= &aud_loopback.hw,
627 		[AUD_CLKID_SPDIFIN]		= &aud_spdifin.hw,
628 		[AUD_CLKID_SPDIFOUT]		= &aud_spdifout.hw,
629 		[AUD_CLKID_RESAMPLE]		= &aud_resample.hw,
630 		[AUD_CLKID_POWER_DETECT]	= &aud_power_detect.hw,
631 		[AUD_CLKID_SPDIFOUT_B]		= &aud_spdifout_b.hw,
632 		[AUD_CLKID_MST_A_MCLK_SEL]	= &aud_mst_a_mclk_sel.hw,
633 		[AUD_CLKID_MST_B_MCLK_SEL]	= &aud_mst_b_mclk_sel.hw,
634 		[AUD_CLKID_MST_C_MCLK_SEL]	= &aud_mst_c_mclk_sel.hw,
635 		[AUD_CLKID_MST_D_MCLK_SEL]	= &aud_mst_d_mclk_sel.hw,
636 		[AUD_CLKID_MST_E_MCLK_SEL]	= &aud_mst_e_mclk_sel.hw,
637 		[AUD_CLKID_MST_F_MCLK_SEL]	= &aud_mst_f_mclk_sel.hw,
638 		[AUD_CLKID_MST_A_MCLK_DIV]	= &aud_mst_a_mclk_div.hw,
639 		[AUD_CLKID_MST_B_MCLK_DIV]	= &aud_mst_b_mclk_div.hw,
640 		[AUD_CLKID_MST_C_MCLK_DIV]	= &aud_mst_c_mclk_div.hw,
641 		[AUD_CLKID_MST_D_MCLK_DIV]	= &aud_mst_d_mclk_div.hw,
642 		[AUD_CLKID_MST_E_MCLK_DIV]	= &aud_mst_e_mclk_div.hw,
643 		[AUD_CLKID_MST_F_MCLK_DIV]	= &aud_mst_f_mclk_div.hw,
644 		[AUD_CLKID_MST_A_MCLK]		= &aud_mst_a_mclk.hw,
645 		[AUD_CLKID_MST_B_MCLK]		= &aud_mst_b_mclk.hw,
646 		[AUD_CLKID_MST_C_MCLK]		= &aud_mst_c_mclk.hw,
647 		[AUD_CLKID_MST_D_MCLK]		= &aud_mst_d_mclk.hw,
648 		[AUD_CLKID_MST_E_MCLK]		= &aud_mst_e_mclk.hw,
649 		[AUD_CLKID_MST_F_MCLK]		= &aud_mst_f_mclk.hw,
650 		[AUD_CLKID_SPDIFOUT_CLK_SEL]	= &aud_spdifout_clk_sel.hw,
651 		[AUD_CLKID_SPDIFOUT_CLK_DIV]	= &aud_spdifout_clk_div.hw,
652 		[AUD_CLKID_SPDIFOUT_CLK]	= &aud_spdifout_clk.hw,
653 		[AUD_CLKID_SPDIFOUT_B_CLK_SEL]	= &aud_spdifout_b_clk_sel.hw,
654 		[AUD_CLKID_SPDIFOUT_B_CLK_DIV]	= &aud_spdifout_b_clk_div.hw,
655 		[AUD_CLKID_SPDIFOUT_B_CLK]	= &aud_spdifout_b_clk.hw,
656 		[AUD_CLKID_SPDIFIN_CLK_SEL]	= &aud_spdifin_clk_sel.hw,
657 		[AUD_CLKID_SPDIFIN_CLK_DIV]	= &aud_spdifin_clk_div.hw,
658 		[AUD_CLKID_SPDIFIN_CLK]		= &aud_spdifin_clk.hw,
659 		[AUD_CLKID_PDM_DCLK_SEL]	= &aud_pdm_dclk_sel.hw,
660 		[AUD_CLKID_PDM_DCLK_DIV]	= &aud_pdm_dclk_div.hw,
661 		[AUD_CLKID_PDM_DCLK]		= &aud_pdm_dclk.hw,
662 		[AUD_CLKID_PDM_SYSCLK_SEL]	= &aud_pdm_sysclk_sel.hw,
663 		[AUD_CLKID_PDM_SYSCLK_DIV]	= &aud_pdm_sysclk_div.hw,
664 		[AUD_CLKID_PDM_SYSCLK]		= &aud_pdm_sysclk.hw,
665 		[AUD_CLKID_MST_A_SCLK_PRE_EN]	= &aud_mst_a_sclk_pre_en.hw,
666 		[AUD_CLKID_MST_B_SCLK_PRE_EN]	= &aud_mst_b_sclk_pre_en.hw,
667 		[AUD_CLKID_MST_C_SCLK_PRE_EN]	= &aud_mst_c_sclk_pre_en.hw,
668 		[AUD_CLKID_MST_D_SCLK_PRE_EN]	= &aud_mst_d_sclk_pre_en.hw,
669 		[AUD_CLKID_MST_E_SCLK_PRE_EN]	= &aud_mst_e_sclk_pre_en.hw,
670 		[AUD_CLKID_MST_F_SCLK_PRE_EN]	= &aud_mst_f_sclk_pre_en.hw,
671 		[AUD_CLKID_MST_A_SCLK_DIV]	= &aud_mst_a_sclk_div.hw,
672 		[AUD_CLKID_MST_B_SCLK_DIV]	= &aud_mst_b_sclk_div.hw,
673 		[AUD_CLKID_MST_C_SCLK_DIV]	= &aud_mst_c_sclk_div.hw,
674 		[AUD_CLKID_MST_D_SCLK_DIV]	= &aud_mst_d_sclk_div.hw,
675 		[AUD_CLKID_MST_E_SCLK_DIV]	= &aud_mst_e_sclk_div.hw,
676 		[AUD_CLKID_MST_F_SCLK_DIV]	= &aud_mst_f_sclk_div.hw,
677 		[AUD_CLKID_MST_A_SCLK_POST_EN]	= &aud_mst_a_sclk_post_en.hw,
678 		[AUD_CLKID_MST_B_SCLK_POST_EN]	= &aud_mst_b_sclk_post_en.hw,
679 		[AUD_CLKID_MST_C_SCLK_POST_EN]	= &aud_mst_c_sclk_post_en.hw,
680 		[AUD_CLKID_MST_D_SCLK_POST_EN]	= &aud_mst_d_sclk_post_en.hw,
681 		[AUD_CLKID_MST_E_SCLK_POST_EN]	= &aud_mst_e_sclk_post_en.hw,
682 		[AUD_CLKID_MST_F_SCLK_POST_EN]	= &aud_mst_f_sclk_post_en.hw,
683 		[AUD_CLKID_MST_A_SCLK]		= &aud_mst_a_sclk.hw,
684 		[AUD_CLKID_MST_B_SCLK]		= &aud_mst_b_sclk.hw,
685 		[AUD_CLKID_MST_C_SCLK]		= &aud_mst_c_sclk.hw,
686 		[AUD_CLKID_MST_D_SCLK]		= &aud_mst_d_sclk.hw,
687 		[AUD_CLKID_MST_E_SCLK]		= &aud_mst_e_sclk.hw,
688 		[AUD_CLKID_MST_F_SCLK]		= &aud_mst_f_sclk.hw,
689 		[AUD_CLKID_MST_A_LRCLK_DIV]	= &aud_mst_a_lrclk_div.hw,
690 		[AUD_CLKID_MST_B_LRCLK_DIV]	= &aud_mst_b_lrclk_div.hw,
691 		[AUD_CLKID_MST_C_LRCLK_DIV]	= &aud_mst_c_lrclk_div.hw,
692 		[AUD_CLKID_MST_D_LRCLK_DIV]	= &aud_mst_d_lrclk_div.hw,
693 		[AUD_CLKID_MST_E_LRCLK_DIV]	= &aud_mst_e_lrclk_div.hw,
694 		[AUD_CLKID_MST_F_LRCLK_DIV]	= &aud_mst_f_lrclk_div.hw,
695 		[AUD_CLKID_MST_A_LRCLK]		= &aud_mst_a_lrclk.hw,
696 		[AUD_CLKID_MST_B_LRCLK]		= &aud_mst_b_lrclk.hw,
697 		[AUD_CLKID_MST_C_LRCLK]		= &aud_mst_c_lrclk.hw,
698 		[AUD_CLKID_MST_D_LRCLK]		= &aud_mst_d_lrclk.hw,
699 		[AUD_CLKID_MST_E_LRCLK]		= &aud_mst_e_lrclk.hw,
700 		[AUD_CLKID_MST_F_LRCLK]		= &aud_mst_f_lrclk.hw,
701 		[AUD_CLKID_TDMIN_A_SCLK_SEL]	= &aud_tdmin_a_sclk_sel.hw,
702 		[AUD_CLKID_TDMIN_B_SCLK_SEL]	= &aud_tdmin_b_sclk_sel.hw,
703 		[AUD_CLKID_TDMIN_C_SCLK_SEL]	= &aud_tdmin_c_sclk_sel.hw,
704 		[AUD_CLKID_TDMIN_LB_SCLK_SEL]	= &aud_tdmin_lb_sclk_sel.hw,
705 		[AUD_CLKID_TDMOUT_A_SCLK_SEL]	= &aud_tdmout_a_sclk_sel.hw,
706 		[AUD_CLKID_TDMOUT_B_SCLK_SEL]	= &aud_tdmout_b_sclk_sel.hw,
707 		[AUD_CLKID_TDMOUT_C_SCLK_SEL]	= &aud_tdmout_c_sclk_sel.hw,
708 		[AUD_CLKID_TDMIN_A_SCLK_PRE_EN]	= &aud_tdmin_a_sclk_pre_en.hw,
709 		[AUD_CLKID_TDMIN_B_SCLK_PRE_EN]	= &aud_tdmin_b_sclk_pre_en.hw,
710 		[AUD_CLKID_TDMIN_C_SCLK_PRE_EN]	= &aud_tdmin_c_sclk_pre_en.hw,
711 		[AUD_CLKID_TDMIN_LB_SCLK_PRE_EN] = &aud_tdmin_lb_sclk_pre_en.hw,
712 		[AUD_CLKID_TDMOUT_A_SCLK_PRE_EN] = &aud_tdmout_a_sclk_pre_en.hw,
713 		[AUD_CLKID_TDMOUT_B_SCLK_PRE_EN] = &aud_tdmout_b_sclk_pre_en.hw,
714 		[AUD_CLKID_TDMOUT_C_SCLK_PRE_EN] = &aud_tdmout_c_sclk_pre_en.hw,
715 		[AUD_CLKID_TDMIN_A_SCLK_POST_EN] = &aud_tdmin_a_sclk_post_en.hw,
716 		[AUD_CLKID_TDMIN_B_SCLK_POST_EN] = &aud_tdmin_b_sclk_post_en.hw,
717 		[AUD_CLKID_TDMIN_C_SCLK_POST_EN] = &aud_tdmin_c_sclk_post_en.hw,
718 		[AUD_CLKID_TDMIN_LB_SCLK_POST_EN] = &aud_tdmin_lb_sclk_post_en.hw,
719 		[AUD_CLKID_TDMOUT_A_SCLK_POST_EN] = &aud_tdmout_a_sclk_post_en.hw,
720 		[AUD_CLKID_TDMOUT_B_SCLK_POST_EN] = &aud_tdmout_b_sclk_post_en.hw,
721 		[AUD_CLKID_TDMOUT_C_SCLK_POST_EN] = &aud_tdmout_c_sclk_post_en.hw,
722 		[AUD_CLKID_TDMIN_A_SCLK]	= &aud_tdmin_a_sclk.hw,
723 		[AUD_CLKID_TDMIN_B_SCLK]	= &aud_tdmin_b_sclk.hw,
724 		[AUD_CLKID_TDMIN_C_SCLK]	= &aud_tdmin_c_sclk.hw,
725 		[AUD_CLKID_TDMIN_LB_SCLK]	= &aud_tdmin_lb_sclk.hw,
726 		[AUD_CLKID_TDMOUT_A_SCLK]	= &aud_tdmout_a_sclk.hw,
727 		[AUD_CLKID_TDMOUT_B_SCLK]	= &aud_tdmout_b_sclk.hw,
728 		[AUD_CLKID_TDMOUT_C_SCLK]	= &aud_tdmout_c_sclk.hw,
729 		[AUD_CLKID_TDMIN_A_LRCLK]	= &aud_tdmin_a_lrclk.hw,
730 		[AUD_CLKID_TDMIN_B_LRCLK]	= &aud_tdmin_b_lrclk.hw,
731 		[AUD_CLKID_TDMIN_C_LRCLK]	= &aud_tdmin_c_lrclk.hw,
732 		[AUD_CLKID_TDMIN_LB_LRCLK]	= &aud_tdmin_lb_lrclk.hw,
733 		[AUD_CLKID_TDMOUT_A_LRCLK]	= &aud_tdmout_a_lrclk.hw,
734 		[AUD_CLKID_TDMOUT_B_LRCLK]	= &aud_tdmout_b_lrclk.hw,
735 		[AUD_CLKID_TDMOUT_C_LRCLK]	= &aud_tdmout_c_lrclk.hw,
736 		[AUD_CLKID_TDM_MCLK_PAD0]	= &aud_tdm_mclk_pad_0.hw,
737 		[AUD_CLKID_TDM_MCLK_PAD1]	= &aud_tdm_mclk_pad_1.hw,
738 		[AUD_CLKID_TDM_LRCLK_PAD0]	= &aud_tdm_lrclk_pad_0.hw,
739 		[AUD_CLKID_TDM_LRCLK_PAD1]	= &aud_tdm_lrclk_pad_1.hw,
740 		[AUD_CLKID_TDM_LRCLK_PAD2]	= &aud_tdm_lrclk_pad_2.hw,
741 		[AUD_CLKID_TDM_SCLK_PAD0]	= &aud_tdm_sclk_pad_0.hw,
742 		[AUD_CLKID_TDM_SCLK_PAD1]	= &aud_tdm_sclk_pad_1.hw,
743 		[AUD_CLKID_TDM_SCLK_PAD2]	= &aud_tdm_sclk_pad_2.hw,
744 		[NR_CLKS] = NULL,
745 	},
746 	.num = NR_CLKS,
747 };
748 
749 /* Convenience table to populate regmap in .probe()
750  * Note that this table is shared between both AXG and G12A,
751  * with spdifout_b clocks being exclusive to G12A. Since those
752  * clocks are not declared within the AXG onecell table, we do not
753  * feel the need to have separate AXG/G12A regmap tables.
754  */
755 static struct clk_regmap *const aud_clk_regmaps[] = {
756 	&aud_ddr_arb,
757 	&aud_pdm,
758 	&aud_tdmin_a,
759 	&aud_tdmin_b,
760 	&aud_tdmin_c,
761 	&aud_tdmin_lb,
762 	&aud_tdmout_a,
763 	&aud_tdmout_b,
764 	&aud_tdmout_c,
765 	&aud_frddr_a,
766 	&aud_frddr_b,
767 	&aud_frddr_c,
768 	&aud_toddr_a,
769 	&aud_toddr_b,
770 	&aud_toddr_c,
771 	&aud_loopback,
772 	&aud_spdifin,
773 	&aud_spdifout,
774 	&aud_resample,
775 	&aud_power_detect,
776 	&aud_spdifout_b,
777 	&aud_mst_a_mclk_sel,
778 	&aud_mst_b_mclk_sel,
779 	&aud_mst_c_mclk_sel,
780 	&aud_mst_d_mclk_sel,
781 	&aud_mst_e_mclk_sel,
782 	&aud_mst_f_mclk_sel,
783 	&aud_mst_a_mclk_div,
784 	&aud_mst_b_mclk_div,
785 	&aud_mst_c_mclk_div,
786 	&aud_mst_d_mclk_div,
787 	&aud_mst_e_mclk_div,
788 	&aud_mst_f_mclk_div,
789 	&aud_mst_a_mclk,
790 	&aud_mst_b_mclk,
791 	&aud_mst_c_mclk,
792 	&aud_mst_d_mclk,
793 	&aud_mst_e_mclk,
794 	&aud_mst_f_mclk,
795 	&aud_spdifout_clk_sel,
796 	&aud_spdifout_clk_div,
797 	&aud_spdifout_clk,
798 	&aud_spdifin_clk_sel,
799 	&aud_spdifin_clk_div,
800 	&aud_spdifin_clk,
801 	&aud_pdm_dclk_sel,
802 	&aud_pdm_dclk_div,
803 	&aud_pdm_dclk,
804 	&aud_pdm_sysclk_sel,
805 	&aud_pdm_sysclk_div,
806 	&aud_pdm_sysclk,
807 	&aud_mst_a_sclk_pre_en,
808 	&aud_mst_b_sclk_pre_en,
809 	&aud_mst_c_sclk_pre_en,
810 	&aud_mst_d_sclk_pre_en,
811 	&aud_mst_e_sclk_pre_en,
812 	&aud_mst_f_sclk_pre_en,
813 	&aud_mst_a_sclk_div,
814 	&aud_mst_b_sclk_div,
815 	&aud_mst_c_sclk_div,
816 	&aud_mst_d_sclk_div,
817 	&aud_mst_e_sclk_div,
818 	&aud_mst_f_sclk_div,
819 	&aud_mst_a_sclk_post_en,
820 	&aud_mst_b_sclk_post_en,
821 	&aud_mst_c_sclk_post_en,
822 	&aud_mst_d_sclk_post_en,
823 	&aud_mst_e_sclk_post_en,
824 	&aud_mst_f_sclk_post_en,
825 	&aud_mst_a_sclk,
826 	&aud_mst_b_sclk,
827 	&aud_mst_c_sclk,
828 	&aud_mst_d_sclk,
829 	&aud_mst_e_sclk,
830 	&aud_mst_f_sclk,
831 	&aud_mst_a_lrclk_div,
832 	&aud_mst_b_lrclk_div,
833 	&aud_mst_c_lrclk_div,
834 	&aud_mst_d_lrclk_div,
835 	&aud_mst_e_lrclk_div,
836 	&aud_mst_f_lrclk_div,
837 	&aud_mst_a_lrclk,
838 	&aud_mst_b_lrclk,
839 	&aud_mst_c_lrclk,
840 	&aud_mst_d_lrclk,
841 	&aud_mst_e_lrclk,
842 	&aud_mst_f_lrclk,
843 	&aud_tdmin_a_sclk_sel,
844 	&aud_tdmin_b_sclk_sel,
845 	&aud_tdmin_c_sclk_sel,
846 	&aud_tdmin_lb_sclk_sel,
847 	&aud_tdmout_a_sclk_sel,
848 	&aud_tdmout_b_sclk_sel,
849 	&aud_tdmout_c_sclk_sel,
850 	&aud_tdmin_a_sclk_pre_en,
851 	&aud_tdmin_b_sclk_pre_en,
852 	&aud_tdmin_c_sclk_pre_en,
853 	&aud_tdmin_lb_sclk_pre_en,
854 	&aud_tdmout_a_sclk_pre_en,
855 	&aud_tdmout_b_sclk_pre_en,
856 	&aud_tdmout_c_sclk_pre_en,
857 	&aud_tdmin_a_sclk_post_en,
858 	&aud_tdmin_b_sclk_post_en,
859 	&aud_tdmin_c_sclk_post_en,
860 	&aud_tdmin_lb_sclk_post_en,
861 	&aud_tdmout_a_sclk_post_en,
862 	&aud_tdmout_b_sclk_post_en,
863 	&aud_tdmout_c_sclk_post_en,
864 	&aud_tdmin_a_sclk,
865 	&aud_tdmin_b_sclk,
866 	&aud_tdmin_c_sclk,
867 	&aud_tdmin_lb_sclk,
868 	&aud_tdmout_a_sclk,
869 	&aud_tdmout_b_sclk,
870 	&aud_tdmout_c_sclk,
871 	&aud_tdmin_a_lrclk,
872 	&aud_tdmin_b_lrclk,
873 	&aud_tdmin_c_lrclk,
874 	&aud_tdmin_lb_lrclk,
875 	&aud_tdmout_a_lrclk,
876 	&aud_tdmout_b_lrclk,
877 	&aud_tdmout_c_lrclk,
878 	&aud_spdifout_b_clk_sel,
879 	&aud_spdifout_b_clk_div,
880 	&aud_spdifout_b_clk,
881 	&aud_tdm_mclk_pad_0,
882 	&aud_tdm_mclk_pad_1,
883 	&aud_tdm_lrclk_pad_0,
884 	&aud_tdm_lrclk_pad_1,
885 	&aud_tdm_lrclk_pad_2,
886 	&aud_tdm_sclk_pad_0,
887 	&aud_tdm_sclk_pad_1,
888 	&aud_tdm_sclk_pad_2,
889 };
890 
891 static int devm_clk_get_enable(struct device *dev, char *id)
892 {
893 	struct clk *clk;
894 	int ret;
895 
896 	clk = devm_clk_get(dev, id);
897 	if (IS_ERR(clk)) {
898 		ret = PTR_ERR(clk);
899 		if (ret != -EPROBE_DEFER)
900 			dev_err(dev, "failed to get %s", id);
901 		return ret;
902 	}
903 
904 	ret = clk_prepare_enable(clk);
905 	if (ret) {
906 		dev_err(dev, "failed to enable %s", id);
907 		return ret;
908 	}
909 
910 	ret = devm_add_action_or_reset(dev,
911 				       (void(*)(void *))clk_disable_unprepare,
912 				       clk);
913 	if (ret) {
914 		dev_err(dev, "failed to add reset action on %s", id);
915 		return ret;
916 	}
917 
918 	return 0;
919 }
920 
921 static const struct regmap_config axg_audio_regmap_cfg = {
922 	.reg_bits	= 32,
923 	.val_bits	= 32,
924 	.reg_stride	= 4,
925 	.max_register	= AUDIO_CLK_PDMIN_CTRL1,
926 };
927 
928 struct audioclk_data {
929 	struct clk_hw_onecell_data *hw_onecell_data;
930 };
931 
932 static int axg_audio_clkc_probe(struct platform_device *pdev)
933 {
934 	struct device *dev = &pdev->dev;
935 	const struct audioclk_data *data;
936 	struct regmap *map;
937 	struct resource *res;
938 	void __iomem *regs;
939 	struct clk_hw *hw;
940 	int ret, i;
941 
942 	data = of_device_get_match_data(dev);
943 	if (!data)
944 		return -EINVAL;
945 
946 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
947 	regs = devm_ioremap_resource(dev, res);
948 	if (IS_ERR(regs))
949 		return PTR_ERR(regs);
950 
951 	map = devm_regmap_init_mmio(dev, regs, &axg_audio_regmap_cfg);
952 	if (IS_ERR(map)) {
953 		dev_err(dev, "failed to init regmap: %ld\n", PTR_ERR(map));
954 		return PTR_ERR(map);
955 	}
956 
957 	/* Get the mandatory peripheral clock */
958 	ret = devm_clk_get_enable(dev, "pclk");
959 	if (ret)
960 		return ret;
961 
962 	ret = device_reset(dev);
963 	if (ret) {
964 		dev_err(dev, "failed to reset device\n");
965 		return ret;
966 	}
967 
968 	/* Populate regmap for the regmap backed clocks */
969 	for (i = 0; i < ARRAY_SIZE(aud_clk_regmaps); i++)
970 		aud_clk_regmaps[i]->map = map;
971 
972 	/* Take care to skip the registered input clocks */
973 	for (i = AUD_CLKID_DDR_ARB; i < data->hw_onecell_data->num; i++) {
974 		hw = data->hw_onecell_data->hws[i];
975 		/* array might be sparse */
976 		if (!hw)
977 			continue;
978 
979 		ret = devm_clk_hw_register(dev, hw);
980 		if (ret) {
981 			dev_err(dev, "failed to register clock %s\n",
982 				hw->init->name);
983 			return ret;
984 		}
985 	}
986 
987 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
988 					   data->hw_onecell_data);
989 }
990 
991 static const struct audioclk_data axg_audioclk_data = {
992 	.hw_onecell_data = &axg_audio_hw_onecell_data,
993 };
994 
995 static const struct audioclk_data g12a_audioclk_data = {
996 	.hw_onecell_data = &g12a_audio_hw_onecell_data,
997 };
998 
999 static const struct of_device_id clkc_match_table[] = {
1000 	{
1001 		.compatible = "amlogic,axg-audio-clkc",
1002 		.data = &axg_audioclk_data
1003 	}, {
1004 		.compatible = "amlogic,g12a-audio-clkc",
1005 		.data = &g12a_audioclk_data
1006 	}, {}
1007 };
1008 MODULE_DEVICE_TABLE(of, clkc_match_table);
1009 
1010 static struct platform_driver axg_audio_driver = {
1011 	.probe		= axg_audio_clkc_probe,
1012 	.driver		= {
1013 		.name	= "axg-audio-clkc",
1014 		.of_match_table = clkc_match_table,
1015 	},
1016 };
1017 module_platform_driver(axg_audio_driver);
1018 
1019 MODULE_DESCRIPTION("Amlogic AXG/G12A Audio Clock driver");
1020 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
1021 MODULE_LICENSE("GPL v2");
1022