xref: /linux/drivers/clk/meson/axg-audio.c (revision 1cd50181750f4bde1e4305812a8df5a5731ed28a)
1*1cd50181SJerome Brunet // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2*1cd50181SJerome Brunet /*
3*1cd50181SJerome Brunet  * Copyright (c) 2018 BayLibre, SAS.
4*1cd50181SJerome Brunet  * Author: Jerome Brunet <jbrunet@baylibre.com>
5*1cd50181SJerome Brunet  */
6*1cd50181SJerome Brunet 
7*1cd50181SJerome Brunet #include <linux/clk.h>
8*1cd50181SJerome Brunet #include <linux/clk-provider.h>
9*1cd50181SJerome Brunet #include <linux/init.h>
10*1cd50181SJerome Brunet #include <linux/of_device.h>
11*1cd50181SJerome Brunet #include <linux/module.h>
12*1cd50181SJerome Brunet #include <linux/platform_device.h>
13*1cd50181SJerome Brunet #include <linux/regmap.h>
14*1cd50181SJerome Brunet #include <linux/reset.h>
15*1cd50181SJerome Brunet #include <linux/slab.h>
16*1cd50181SJerome Brunet 
17*1cd50181SJerome Brunet #include "clkc-audio.h"
18*1cd50181SJerome Brunet #include "axg-audio.h"
19*1cd50181SJerome Brunet 
20*1cd50181SJerome Brunet #define AXG_MST_IN_COUNT	8
21*1cd50181SJerome Brunet #define AXG_SLV_SCLK_COUNT	10
22*1cd50181SJerome Brunet #define AXG_SLV_LRCLK_COUNT	10
23*1cd50181SJerome Brunet 
24*1cd50181SJerome Brunet #define AXG_AUD_GATE(_name, _reg, _bit, _pname, _iflags)		\
25*1cd50181SJerome Brunet struct clk_regmap axg_##_name = {					\
26*1cd50181SJerome Brunet 	.data = &(struct clk_regmap_gate_data){				\
27*1cd50181SJerome Brunet 		.offset = (_reg),					\
28*1cd50181SJerome Brunet 		.bit_idx = (_bit),					\
29*1cd50181SJerome Brunet 	},								\
30*1cd50181SJerome Brunet 	.hw.init = &(struct clk_init_data) {				\
31*1cd50181SJerome Brunet 		.name = "axg_"#_name,					\
32*1cd50181SJerome Brunet 		.ops = &clk_regmap_gate_ops,				\
33*1cd50181SJerome Brunet 		.parent_names = (const char *[]){ _pname },		\
34*1cd50181SJerome Brunet 		.num_parents = 1,					\
35*1cd50181SJerome Brunet 		.flags = CLK_DUTY_CYCLE_PARENT | (_iflags),		\
36*1cd50181SJerome Brunet 	},								\
37*1cd50181SJerome Brunet }
38*1cd50181SJerome Brunet 
39*1cd50181SJerome Brunet #define AXG_AUD_MUX(_name, _reg, _mask, _shift, _dflags, _pnames, _iflags) \
40*1cd50181SJerome Brunet struct clk_regmap axg_##_name = {					\
41*1cd50181SJerome Brunet 	.data = &(struct clk_regmap_mux_data){				\
42*1cd50181SJerome Brunet 		.offset = (_reg),					\
43*1cd50181SJerome Brunet 		.mask = (_mask),					\
44*1cd50181SJerome Brunet 		.shift = (_shift),					\
45*1cd50181SJerome Brunet 		.flags = (_dflags),					\
46*1cd50181SJerome Brunet 	},								\
47*1cd50181SJerome Brunet 	.hw.init = &(struct clk_init_data){				\
48*1cd50181SJerome Brunet 		.name = "axg_"#_name,					\
49*1cd50181SJerome Brunet 		.ops = &clk_regmap_mux_ops,				\
50*1cd50181SJerome Brunet 		.parent_names = (_pnames),				\
51*1cd50181SJerome Brunet 		.num_parents = ARRAY_SIZE(_pnames),			\
52*1cd50181SJerome Brunet 		.flags = CLK_DUTY_CYCLE_PARENT | (_iflags),		\
53*1cd50181SJerome Brunet 	},								\
54*1cd50181SJerome Brunet }
55*1cd50181SJerome Brunet 
56*1cd50181SJerome Brunet #define AXG_AUD_DIV(_name, _reg, _shift, _width, _dflags, _pname, _iflags) \
57*1cd50181SJerome Brunet struct clk_regmap axg_##_name = {					\
58*1cd50181SJerome Brunet 	.data = &(struct clk_regmap_div_data){				\
59*1cd50181SJerome Brunet 		.offset = (_reg),					\
60*1cd50181SJerome Brunet 		.shift = (_shift),					\
61*1cd50181SJerome Brunet 		.width = (_width),					\
62*1cd50181SJerome Brunet 		.flags = (_dflags),					\
63*1cd50181SJerome Brunet 	},								\
64*1cd50181SJerome Brunet 	.hw.init = &(struct clk_init_data){				\
65*1cd50181SJerome Brunet 		.name = "axg_"#_name,					\
66*1cd50181SJerome Brunet 		.ops = &clk_regmap_divider_ops,				\
67*1cd50181SJerome Brunet 		.parent_names = (const char *[]) { _pname },		\
68*1cd50181SJerome Brunet 		.num_parents = 1,					\
69*1cd50181SJerome Brunet 		.flags = (_iflags),					\
70*1cd50181SJerome Brunet 	},								\
71*1cd50181SJerome Brunet }
72*1cd50181SJerome Brunet 
73*1cd50181SJerome Brunet #define AXG_PCLK_GATE(_name, _bit)				\
74*1cd50181SJerome Brunet 	AXG_AUD_GATE(_name, AUDIO_CLK_GATE_EN, _bit, "axg_audio_pclk", 0)
75*1cd50181SJerome Brunet 
76*1cd50181SJerome Brunet /* Audio peripheral clocks */
77*1cd50181SJerome Brunet static AXG_PCLK_GATE(ddr_arb,	   0);
78*1cd50181SJerome Brunet static AXG_PCLK_GATE(pdm,	   1);
79*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmin_a,	   2);
80*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmin_b,	   3);
81*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmin_c,	   4);
82*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmin_lb,	   5);
83*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmout_a,	   6);
84*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmout_b,	   7);
85*1cd50181SJerome Brunet static AXG_PCLK_GATE(tdmout_c,	   8);
86*1cd50181SJerome Brunet static AXG_PCLK_GATE(frddr_a,	   9);
87*1cd50181SJerome Brunet static AXG_PCLK_GATE(frddr_b,	   10);
88*1cd50181SJerome Brunet static AXG_PCLK_GATE(frddr_c,	   11);
89*1cd50181SJerome Brunet static AXG_PCLK_GATE(toddr_a,	   12);
90*1cd50181SJerome Brunet static AXG_PCLK_GATE(toddr_b,	   13);
91*1cd50181SJerome Brunet static AXG_PCLK_GATE(toddr_c,	   14);
92*1cd50181SJerome Brunet static AXG_PCLK_GATE(loopback,	   15);
93*1cd50181SJerome Brunet static AXG_PCLK_GATE(spdifin,	   16);
94*1cd50181SJerome Brunet static AXG_PCLK_GATE(spdifout,	   17);
95*1cd50181SJerome Brunet static AXG_PCLK_GATE(resample,	   18);
96*1cd50181SJerome Brunet static AXG_PCLK_GATE(power_detect, 19);
97*1cd50181SJerome Brunet 
98*1cd50181SJerome Brunet /* Audio Master Clocks */
99*1cd50181SJerome Brunet static const char * const mst_mux_parent_names[] = {
100*1cd50181SJerome Brunet 	"axg_mst_in0", "axg_mst_in1", "axg_mst_in2", "axg_mst_in3",
101*1cd50181SJerome Brunet 	"axg_mst_in4", "axg_mst_in5", "axg_mst_in6", "axg_mst_in7",
102*1cd50181SJerome Brunet };
103*1cd50181SJerome Brunet 
104*1cd50181SJerome Brunet #define AXG_MST_MCLK_MUX(_name, _reg)					\
105*1cd50181SJerome Brunet 	AXG_AUD_MUX(_name##_sel, _reg, 0x7, 24, CLK_MUX_ROUND_CLOSEST, \
106*1cd50181SJerome Brunet 		    mst_mux_parent_names, CLK_SET_RATE_PARENT)
107*1cd50181SJerome Brunet 
108*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(mst_a_mclk,   AUDIO_MCLK_A_CTRL);
109*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(mst_b_mclk,   AUDIO_MCLK_B_CTRL);
110*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(mst_c_mclk,   AUDIO_MCLK_C_CTRL);
111*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(mst_d_mclk,   AUDIO_MCLK_D_CTRL);
112*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(mst_e_mclk,   AUDIO_MCLK_E_CTRL);
113*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(mst_f_mclk,   AUDIO_MCLK_F_CTRL);
114*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL);
115*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(spdifin_clk,  AUDIO_CLK_SPDIFIN_CTRL);
116*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(pdm_dclk,     AUDIO_CLK_PDMIN_CTRL0);
117*1cd50181SJerome Brunet static AXG_MST_MCLK_MUX(pdm_sysclk,   AUDIO_CLK_PDMIN_CTRL1);
118*1cd50181SJerome Brunet 
119*1cd50181SJerome Brunet #define AXG_MST_MCLK_DIV(_name, _reg)					\
120*1cd50181SJerome Brunet 	AXG_AUD_DIV(_name##_div, _reg, 0, 16, CLK_DIVIDER_ROUND_CLOSEST, \
121*1cd50181SJerome Brunet 		    "axg_"#_name"_sel", CLK_SET_RATE_PARENT)		\
122*1cd50181SJerome Brunet 
123*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(mst_a_mclk,   AUDIO_MCLK_A_CTRL);
124*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(mst_b_mclk,   AUDIO_MCLK_B_CTRL);
125*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(mst_c_mclk,   AUDIO_MCLK_C_CTRL);
126*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(mst_d_mclk,   AUDIO_MCLK_D_CTRL);
127*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(mst_e_mclk,   AUDIO_MCLK_E_CTRL);
128*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(mst_f_mclk,   AUDIO_MCLK_F_CTRL);
129*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL);
130*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(spdifin_clk,  AUDIO_CLK_SPDIFIN_CTRL);
131*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(pdm_dclk,     AUDIO_CLK_PDMIN_CTRL0);
132*1cd50181SJerome Brunet static AXG_MST_MCLK_DIV(pdm_sysclk,   AUDIO_CLK_PDMIN_CTRL1);
133*1cd50181SJerome Brunet 
134*1cd50181SJerome Brunet #define AXG_MST_MCLK_GATE(_name, _reg)					\
135*1cd50181SJerome Brunet 	AXG_AUD_GATE(_name, _reg, 31,  "axg_"#_name"_div",		\
136*1cd50181SJerome Brunet 		     CLK_SET_RATE_PARENT)
137*1cd50181SJerome Brunet 
138*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(mst_a_mclk,   AUDIO_MCLK_A_CTRL);
139*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(mst_b_mclk,   AUDIO_MCLK_B_CTRL);
140*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(mst_c_mclk,   AUDIO_MCLK_C_CTRL);
141*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(mst_d_mclk,   AUDIO_MCLK_D_CTRL);
142*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(mst_e_mclk,   AUDIO_MCLK_E_CTRL);
143*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(mst_f_mclk,   AUDIO_MCLK_F_CTRL);
144*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(spdifout_clk, AUDIO_CLK_SPDIFOUT_CTRL);
145*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(spdifin_clk,  AUDIO_CLK_SPDIFIN_CTRL);
146*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(pdm_dclk,     AUDIO_CLK_PDMIN_CTRL0);
147*1cd50181SJerome Brunet static AXG_MST_MCLK_GATE(pdm_sysclk,   AUDIO_CLK_PDMIN_CTRL1);
148*1cd50181SJerome Brunet 
149*1cd50181SJerome Brunet /* Sample Clocks */
150*1cd50181SJerome Brunet #define AXG_MST_SCLK_PRE_EN(_name, _reg)			\
151*1cd50181SJerome Brunet 	AXG_AUD_GATE(mst_##_name##_sclk_pre_en, _reg, 31,	\
152*1cd50181SJerome Brunet 		     "axg_mst_"#_name"_mclk", 0)
153*1cd50181SJerome Brunet 
154*1cd50181SJerome Brunet static AXG_MST_SCLK_PRE_EN(a, AUDIO_MST_A_SCLK_CTRL0);
155*1cd50181SJerome Brunet static AXG_MST_SCLK_PRE_EN(b, AUDIO_MST_B_SCLK_CTRL0);
156*1cd50181SJerome Brunet static AXG_MST_SCLK_PRE_EN(c, AUDIO_MST_C_SCLK_CTRL0);
157*1cd50181SJerome Brunet static AXG_MST_SCLK_PRE_EN(d, AUDIO_MST_D_SCLK_CTRL0);
158*1cd50181SJerome Brunet static AXG_MST_SCLK_PRE_EN(e, AUDIO_MST_E_SCLK_CTRL0);
159*1cd50181SJerome Brunet static AXG_MST_SCLK_PRE_EN(f, AUDIO_MST_F_SCLK_CTRL0);
160*1cd50181SJerome Brunet 
161*1cd50181SJerome Brunet #define AXG_AUD_SCLK_DIV(_name, _reg, _div_shift, _div_width,		\
162*1cd50181SJerome Brunet 			 _hi_shift, _hi_width, _pname, _iflags)		\
163*1cd50181SJerome Brunet struct clk_regmap axg_##_name = {					\
164*1cd50181SJerome Brunet 	.data = &(struct meson_sclk_div_data) {				\
165*1cd50181SJerome Brunet 		.div = {						\
166*1cd50181SJerome Brunet 			.reg_off = (_reg),				\
167*1cd50181SJerome Brunet 			.shift   = (_div_shift),			\
168*1cd50181SJerome Brunet 			.width   = (_div_width),			\
169*1cd50181SJerome Brunet 		},							\
170*1cd50181SJerome Brunet 		.hi = {							\
171*1cd50181SJerome Brunet 			.reg_off = (_reg),				\
172*1cd50181SJerome Brunet 			.shift   = (_hi_shift),				\
173*1cd50181SJerome Brunet 			.width   = (_hi_width),				\
174*1cd50181SJerome Brunet 		},							\
175*1cd50181SJerome Brunet 	},								\
176*1cd50181SJerome Brunet 	.hw.init = &(struct clk_init_data) {				\
177*1cd50181SJerome Brunet 		.name = "axg_"#_name,					\
178*1cd50181SJerome Brunet 		.ops = &meson_sclk_div_ops,				\
179*1cd50181SJerome Brunet 		.parent_names = (const char *[]) { _pname },		\
180*1cd50181SJerome Brunet 		.num_parents = 1,					\
181*1cd50181SJerome Brunet 		.flags = (_iflags),					\
182*1cd50181SJerome Brunet 	},								\
183*1cd50181SJerome Brunet }
184*1cd50181SJerome Brunet 
185*1cd50181SJerome Brunet #define AXG_MST_SCLK_DIV(_name, _reg)					\
186*1cd50181SJerome Brunet 	AXG_AUD_SCLK_DIV(mst_##_name##_sclk_div, _reg, 20, 10, 0, 0,	\
187*1cd50181SJerome Brunet 			 "axg_mst_"#_name"_sclk_pre_en",		\
188*1cd50181SJerome Brunet 			 CLK_SET_RATE_PARENT)
189*1cd50181SJerome Brunet 
190*1cd50181SJerome Brunet static AXG_MST_SCLK_DIV(a, AUDIO_MST_A_SCLK_CTRL0);
191*1cd50181SJerome Brunet static AXG_MST_SCLK_DIV(b, AUDIO_MST_B_SCLK_CTRL0);
192*1cd50181SJerome Brunet static AXG_MST_SCLK_DIV(c, AUDIO_MST_C_SCLK_CTRL0);
193*1cd50181SJerome Brunet static AXG_MST_SCLK_DIV(d, AUDIO_MST_D_SCLK_CTRL0);
194*1cd50181SJerome Brunet static AXG_MST_SCLK_DIV(e, AUDIO_MST_E_SCLK_CTRL0);
195*1cd50181SJerome Brunet static AXG_MST_SCLK_DIV(f, AUDIO_MST_F_SCLK_CTRL0);
196*1cd50181SJerome Brunet 
197*1cd50181SJerome Brunet #define AXG_MST_SCLK_POST_EN(_name, _reg)				\
198*1cd50181SJerome Brunet 	AXG_AUD_GATE(mst_##_name##_sclk_post_en, _reg, 30,		\
199*1cd50181SJerome Brunet 		     "axg_mst_"#_name"_sclk_div", CLK_SET_RATE_PARENT)
200*1cd50181SJerome Brunet 
201*1cd50181SJerome Brunet static AXG_MST_SCLK_POST_EN(a, AUDIO_MST_A_SCLK_CTRL0);
202*1cd50181SJerome Brunet static AXG_MST_SCLK_POST_EN(b, AUDIO_MST_B_SCLK_CTRL0);
203*1cd50181SJerome Brunet static AXG_MST_SCLK_POST_EN(c, AUDIO_MST_C_SCLK_CTRL0);
204*1cd50181SJerome Brunet static AXG_MST_SCLK_POST_EN(d, AUDIO_MST_D_SCLK_CTRL0);
205*1cd50181SJerome Brunet static AXG_MST_SCLK_POST_EN(e, AUDIO_MST_E_SCLK_CTRL0);
206*1cd50181SJerome Brunet static AXG_MST_SCLK_POST_EN(f, AUDIO_MST_F_SCLK_CTRL0);
207*1cd50181SJerome Brunet 
208*1cd50181SJerome Brunet #define AXG_AUD_TRIPHASE(_name, _reg, _width, _shift0, _shift1, _shift2, \
209*1cd50181SJerome Brunet 			 _pname, _iflags)				\
210*1cd50181SJerome Brunet struct clk_regmap axg_##_name = {					\
211*1cd50181SJerome Brunet 	.data = &(struct meson_clk_triphase_data) {			\
212*1cd50181SJerome Brunet 		.ph0 = {						\
213*1cd50181SJerome Brunet 			.reg_off = (_reg),				\
214*1cd50181SJerome Brunet 			.shift   = (_shift0),				\
215*1cd50181SJerome Brunet 			.width   = (_width),				\
216*1cd50181SJerome Brunet 		},							\
217*1cd50181SJerome Brunet 		.ph1 = {						\
218*1cd50181SJerome Brunet 			.reg_off = (_reg),				\
219*1cd50181SJerome Brunet 			.shift   = (_shift1),				\
220*1cd50181SJerome Brunet 			.width   = (_width),				\
221*1cd50181SJerome Brunet 		},							\
222*1cd50181SJerome Brunet 		.ph2 = {						\
223*1cd50181SJerome Brunet 			.reg_off = (_reg),				\
224*1cd50181SJerome Brunet 			.shift   = (_shift2),				\
225*1cd50181SJerome Brunet 			.width   = (_width),				\
226*1cd50181SJerome Brunet 		},							\
227*1cd50181SJerome Brunet 	},								\
228*1cd50181SJerome Brunet 	.hw.init = &(struct clk_init_data) {				\
229*1cd50181SJerome Brunet 		.name = "axg_"#_name,					\
230*1cd50181SJerome Brunet 		.ops = &meson_clk_triphase_ops,				\
231*1cd50181SJerome Brunet 		.parent_names = (const char *[]) { _pname },		\
232*1cd50181SJerome Brunet 		.num_parents = 1,					\
233*1cd50181SJerome Brunet 		.flags = CLK_DUTY_CYCLE_PARENT | (_iflags),		\
234*1cd50181SJerome Brunet 	},								\
235*1cd50181SJerome Brunet }
236*1cd50181SJerome Brunet 
237*1cd50181SJerome Brunet #define AXG_MST_SCLK(_name, _reg)					\
238*1cd50181SJerome Brunet 	AXG_AUD_TRIPHASE(mst_##_name##_sclk, _reg, 1, 0, 2, 4,		\
239*1cd50181SJerome Brunet 			 "axg_mst_"#_name"_sclk_post_en", CLK_SET_RATE_PARENT)
240*1cd50181SJerome Brunet 
241*1cd50181SJerome Brunet static AXG_MST_SCLK(a, AUDIO_MST_A_SCLK_CTRL1);
242*1cd50181SJerome Brunet static AXG_MST_SCLK(b, AUDIO_MST_B_SCLK_CTRL1);
243*1cd50181SJerome Brunet static AXG_MST_SCLK(c, AUDIO_MST_C_SCLK_CTRL1);
244*1cd50181SJerome Brunet static AXG_MST_SCLK(d, AUDIO_MST_D_SCLK_CTRL1);
245*1cd50181SJerome Brunet static AXG_MST_SCLK(e, AUDIO_MST_E_SCLK_CTRL1);
246*1cd50181SJerome Brunet static AXG_MST_SCLK(f, AUDIO_MST_F_SCLK_CTRL1);
247*1cd50181SJerome Brunet 
248*1cd50181SJerome Brunet #define AXG_MST_LRCLK_DIV(_name, _reg)					\
249*1cd50181SJerome Brunet 	AXG_AUD_SCLK_DIV(mst_##_name##_lrclk_div, _reg, 0, 10, 10, 10,	\
250*1cd50181SJerome Brunet 		    "axg_mst_"#_name"_sclk_post_en", 0)			\
251*1cd50181SJerome Brunet 
252*1cd50181SJerome Brunet static AXG_MST_LRCLK_DIV(a, AUDIO_MST_A_SCLK_CTRL0);
253*1cd50181SJerome Brunet static AXG_MST_LRCLK_DIV(b, AUDIO_MST_B_SCLK_CTRL0);
254*1cd50181SJerome Brunet static AXG_MST_LRCLK_DIV(c, AUDIO_MST_C_SCLK_CTRL0);
255*1cd50181SJerome Brunet static AXG_MST_LRCLK_DIV(d, AUDIO_MST_D_SCLK_CTRL0);
256*1cd50181SJerome Brunet static AXG_MST_LRCLK_DIV(e, AUDIO_MST_E_SCLK_CTRL0);
257*1cd50181SJerome Brunet static AXG_MST_LRCLK_DIV(f, AUDIO_MST_F_SCLK_CTRL0);
258*1cd50181SJerome Brunet 
259*1cd50181SJerome Brunet #define AXG_MST_LRCLK(_name, _reg)					\
260*1cd50181SJerome Brunet 	AXG_AUD_TRIPHASE(mst_##_name##_lrclk, _reg, 1, 1, 3, 5,		\
261*1cd50181SJerome Brunet 			 "axg_mst_"#_name"_lrclk_div", CLK_SET_RATE_PARENT)
262*1cd50181SJerome Brunet 
263*1cd50181SJerome Brunet static AXG_MST_LRCLK(a, AUDIO_MST_A_SCLK_CTRL1);
264*1cd50181SJerome Brunet static AXG_MST_LRCLK(b, AUDIO_MST_B_SCLK_CTRL1);
265*1cd50181SJerome Brunet static AXG_MST_LRCLK(c, AUDIO_MST_C_SCLK_CTRL1);
266*1cd50181SJerome Brunet static AXG_MST_LRCLK(d, AUDIO_MST_D_SCLK_CTRL1);
267*1cd50181SJerome Brunet static AXG_MST_LRCLK(e, AUDIO_MST_E_SCLK_CTRL1);
268*1cd50181SJerome Brunet static AXG_MST_LRCLK(f, AUDIO_MST_F_SCLK_CTRL1);
269*1cd50181SJerome Brunet 
270*1cd50181SJerome Brunet static const char * const tdm_sclk_parent_names[] = {
271*1cd50181SJerome Brunet 	"axg_mst_a_sclk", "axg_mst_b_sclk", "axg_mst_c_sclk",
272*1cd50181SJerome Brunet 	"axg_mst_d_sclk", "axg_mst_e_sclk", "axg_mst_f_sclk",
273*1cd50181SJerome Brunet 	"axg_slv_sclk0", "axg_slv_sclk1", "axg_slv_sclk2",
274*1cd50181SJerome Brunet 	"axg_slv_sclk3", "axg_slv_sclk4", "axg_slv_sclk5",
275*1cd50181SJerome Brunet 	"axg_slv_sclk6", "axg_slv_sclk7", "axg_slv_sclk8",
276*1cd50181SJerome Brunet 	"axg_slv_sclk9"
277*1cd50181SJerome Brunet };
278*1cd50181SJerome Brunet 
279*1cd50181SJerome Brunet #define AXG_TDM_SCLK_MUX(_name, _reg)				\
280*1cd50181SJerome Brunet 	AXG_AUD_MUX(tdm##_name##_sclk_sel, _reg, 0xf, 24,	\
281*1cd50181SJerome Brunet 		    CLK_MUX_ROUND_CLOSEST,			\
282*1cd50181SJerome Brunet 		    tdm_sclk_parent_names, 0)
283*1cd50181SJerome Brunet 
284*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
285*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
286*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
287*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
288*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
289*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
290*1cd50181SJerome Brunet static AXG_TDM_SCLK_MUX(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
291*1cd50181SJerome Brunet 
292*1cd50181SJerome Brunet #define AXG_TDM_SCLK_PRE_EN(_name, _reg)				\
293*1cd50181SJerome Brunet 	AXG_AUD_GATE(tdm##_name##_sclk_pre_en, _reg, 31,		\
294*1cd50181SJerome Brunet 		     "axg_tdm"#_name"_sclk_sel", CLK_SET_RATE_PARENT)
295*1cd50181SJerome Brunet 
296*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
297*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
298*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
299*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
300*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
301*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
302*1cd50181SJerome Brunet static AXG_TDM_SCLK_PRE_EN(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
303*1cd50181SJerome Brunet 
304*1cd50181SJerome Brunet #define AXG_TDM_SCLK_POST_EN(_name, _reg)				\
305*1cd50181SJerome Brunet 	AXG_AUD_GATE(tdm##_name##_sclk_post_en, _reg, 30,		\
306*1cd50181SJerome Brunet 		     "axg_tdm"#_name"_sclk_pre_en", CLK_SET_RATE_PARENT)
307*1cd50181SJerome Brunet 
308*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
309*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
310*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
311*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
312*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
313*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
314*1cd50181SJerome Brunet static AXG_TDM_SCLK_POST_EN(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
315*1cd50181SJerome Brunet 
316*1cd50181SJerome Brunet #define AXG_TDM_SCLK(_name, _reg)					\
317*1cd50181SJerome Brunet 	struct clk_regmap axg_tdm##_name##_sclk = {			\
318*1cd50181SJerome Brunet 	.data = &(struct meson_clk_phase_data) {			\
319*1cd50181SJerome Brunet 		.ph = {							\
320*1cd50181SJerome Brunet 			.reg_off = (_reg),				\
321*1cd50181SJerome Brunet 			.shift   = 29,					\
322*1cd50181SJerome Brunet 			.width   = 1,					\
323*1cd50181SJerome Brunet 		},							\
324*1cd50181SJerome Brunet 	},								\
325*1cd50181SJerome Brunet 	.hw.init = &(struct clk_init_data) {				\
326*1cd50181SJerome Brunet 		.name = "axg_tdm"#_name"_sclk",				\
327*1cd50181SJerome Brunet 		.ops = &meson_clk_phase_ops,				\
328*1cd50181SJerome Brunet 		.parent_names = (const char *[])			\
329*1cd50181SJerome Brunet 		{ "axg_tdm"#_name"_sclk_post_en" },			\
330*1cd50181SJerome Brunet 		.num_parents = 1,					\
331*1cd50181SJerome Brunet 		.flags = CLK_DUTY_CYCLE_PARENT | CLK_SET_RATE_PARENT,	\
332*1cd50181SJerome Brunet 	},								\
333*1cd50181SJerome Brunet }
334*1cd50181SJerome Brunet 
335*1cd50181SJerome Brunet static AXG_TDM_SCLK(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
336*1cd50181SJerome Brunet static AXG_TDM_SCLK(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
337*1cd50181SJerome Brunet static AXG_TDM_SCLK(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
338*1cd50181SJerome Brunet static AXG_TDM_SCLK(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
339*1cd50181SJerome Brunet static AXG_TDM_SCLK(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
340*1cd50181SJerome Brunet static AXG_TDM_SCLK(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
341*1cd50181SJerome Brunet static AXG_TDM_SCLK(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
342*1cd50181SJerome Brunet 
343*1cd50181SJerome Brunet static const char * const tdm_lrclk_parent_names[] = {
344*1cd50181SJerome Brunet 	"axg_mst_a_lrclk", "axg_mst_b_lrclk", "axg_mst_c_lrclk",
345*1cd50181SJerome Brunet 	"axg_mst_d_lrclk", "axg_mst_e_lrclk", "axg_mst_f_lrclk",
346*1cd50181SJerome Brunet 	"axg_slv_lrclk0", "axg_slv_lrclk1", "axg_slv_lrclk2",
347*1cd50181SJerome Brunet 	"axg_slv_lrclk3", "axg_slv_lrclk4", "axg_slv_lrclk5",
348*1cd50181SJerome Brunet 	"axg_slv_lrclk6", "axg_slv_lrclk7", "axg_slv_lrclk8",
349*1cd50181SJerome Brunet 	"axg_slv_lrclk9"
350*1cd50181SJerome Brunet };
351*1cd50181SJerome Brunet 
352*1cd50181SJerome Brunet #define AXG_TDM_LRLCK(_name, _reg)		       \
353*1cd50181SJerome Brunet 	AXG_AUD_MUX(tdm##_name##_lrclk, _reg, 0xf, 20, \
354*1cd50181SJerome Brunet 		    CLK_MUX_ROUND_CLOSEST,	       \
355*1cd50181SJerome Brunet 		    tdm_lrclk_parent_names, 0)
356*1cd50181SJerome Brunet 
357*1cd50181SJerome Brunet static AXG_TDM_LRLCK(in_a,  AUDIO_CLK_TDMIN_A_CTRL);
358*1cd50181SJerome Brunet static AXG_TDM_LRLCK(in_b,  AUDIO_CLK_TDMIN_B_CTRL);
359*1cd50181SJerome Brunet static AXG_TDM_LRLCK(in_c,  AUDIO_CLK_TDMIN_C_CTRL);
360*1cd50181SJerome Brunet static AXG_TDM_LRLCK(in_lb, AUDIO_CLK_TDMIN_LB_CTRL);
361*1cd50181SJerome Brunet static AXG_TDM_LRLCK(out_a, AUDIO_CLK_TDMOUT_A_CTRL);
362*1cd50181SJerome Brunet static AXG_TDM_LRLCK(out_b, AUDIO_CLK_TDMOUT_B_CTRL);
363*1cd50181SJerome Brunet static AXG_TDM_LRLCK(out_c, AUDIO_CLK_TDMOUT_C_CTRL);
364*1cd50181SJerome Brunet 
365*1cd50181SJerome Brunet /*
366*1cd50181SJerome Brunet  * Array of all clocks provided by this provider
367*1cd50181SJerome Brunet  * The input clocks of the controller will be populated at runtime
368*1cd50181SJerome Brunet  */
369*1cd50181SJerome Brunet static struct clk_hw_onecell_data axg_audio_hw_onecell_data = {
370*1cd50181SJerome Brunet 	.hws = {
371*1cd50181SJerome Brunet 		[AUD_CLKID_DDR_ARB]		= &axg_ddr_arb.hw,
372*1cd50181SJerome Brunet 		[AUD_CLKID_PDM]			= &axg_pdm.hw,
373*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_A]		= &axg_tdmin_a.hw,
374*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_B]		= &axg_tdmin_b.hw,
375*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_C]		= &axg_tdmin_c.hw,
376*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_LB]		= &axg_tdmin_lb.hw,
377*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_A]		= &axg_tdmout_a.hw,
378*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_B]		= &axg_tdmout_b.hw,
379*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_C]		= &axg_tdmout_c.hw,
380*1cd50181SJerome Brunet 		[AUD_CLKID_FRDDR_A]		= &axg_frddr_a.hw,
381*1cd50181SJerome Brunet 		[AUD_CLKID_FRDDR_B]		= &axg_frddr_b.hw,
382*1cd50181SJerome Brunet 		[AUD_CLKID_FRDDR_C]		= &axg_frddr_c.hw,
383*1cd50181SJerome Brunet 		[AUD_CLKID_TODDR_A]		= &axg_toddr_a.hw,
384*1cd50181SJerome Brunet 		[AUD_CLKID_TODDR_B]		= &axg_toddr_b.hw,
385*1cd50181SJerome Brunet 		[AUD_CLKID_TODDR_C]		= &axg_toddr_c.hw,
386*1cd50181SJerome Brunet 		[AUD_CLKID_LOOPBACK]		= &axg_loopback.hw,
387*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFIN]		= &axg_spdifin.hw,
388*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFOUT]		= &axg_spdifout.hw,
389*1cd50181SJerome Brunet 		[AUD_CLKID_RESAMPLE]		= &axg_resample.hw,
390*1cd50181SJerome Brunet 		[AUD_CLKID_POWER_DETECT]	= &axg_power_detect.hw,
391*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_MCLK_SEL]	= &axg_mst_a_mclk_sel.hw,
392*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_MCLK_SEL]	= &axg_mst_b_mclk_sel.hw,
393*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_MCLK_SEL]	= &axg_mst_c_mclk_sel.hw,
394*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_MCLK_SEL]	= &axg_mst_d_mclk_sel.hw,
395*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_MCLK_SEL]	= &axg_mst_e_mclk_sel.hw,
396*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_MCLK_SEL]	= &axg_mst_f_mclk_sel.hw,
397*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_MCLK_DIV]	= &axg_mst_a_mclk_div.hw,
398*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_MCLK_DIV]	= &axg_mst_b_mclk_div.hw,
399*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_MCLK_DIV]	= &axg_mst_c_mclk_div.hw,
400*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_MCLK_DIV]	= &axg_mst_d_mclk_div.hw,
401*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_MCLK_DIV]	= &axg_mst_e_mclk_div.hw,
402*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_MCLK_DIV]	= &axg_mst_f_mclk_div.hw,
403*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_MCLK]		= &axg_mst_a_mclk.hw,
404*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_MCLK]		= &axg_mst_b_mclk.hw,
405*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_MCLK]		= &axg_mst_c_mclk.hw,
406*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_MCLK]		= &axg_mst_d_mclk.hw,
407*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_MCLK]		= &axg_mst_e_mclk.hw,
408*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_MCLK]		= &axg_mst_f_mclk.hw,
409*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFOUT_CLK_SEL]	= &axg_spdifout_clk_sel.hw,
410*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFOUT_CLK_DIV]	= &axg_spdifout_clk_div.hw,
411*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFOUT_CLK]	= &axg_spdifout_clk.hw,
412*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFIN_CLK_SEL]	= &axg_spdifin_clk_sel.hw,
413*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFIN_CLK_DIV]	= &axg_spdifin_clk_div.hw,
414*1cd50181SJerome Brunet 		[AUD_CLKID_SPDIFIN_CLK]		= &axg_spdifin_clk.hw,
415*1cd50181SJerome Brunet 		[AUD_CLKID_PDM_DCLK_SEL]	= &axg_pdm_dclk_sel.hw,
416*1cd50181SJerome Brunet 		[AUD_CLKID_PDM_DCLK_DIV]	= &axg_pdm_dclk_div.hw,
417*1cd50181SJerome Brunet 		[AUD_CLKID_PDM_DCLK]		= &axg_pdm_dclk.hw,
418*1cd50181SJerome Brunet 		[AUD_CLKID_PDM_SYSCLK_SEL]	= &axg_pdm_sysclk_sel.hw,
419*1cd50181SJerome Brunet 		[AUD_CLKID_PDM_SYSCLK_DIV]	= &axg_pdm_sysclk_div.hw,
420*1cd50181SJerome Brunet 		[AUD_CLKID_PDM_SYSCLK]		= &axg_pdm_sysclk.hw,
421*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_SCLK_PRE_EN]	= &axg_mst_a_sclk_pre_en.hw,
422*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_SCLK_PRE_EN]	= &axg_mst_b_sclk_pre_en.hw,
423*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_SCLK_PRE_EN]	= &axg_mst_c_sclk_pre_en.hw,
424*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_SCLK_PRE_EN]	= &axg_mst_d_sclk_pre_en.hw,
425*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_SCLK_PRE_EN]	= &axg_mst_e_sclk_pre_en.hw,
426*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_SCLK_PRE_EN]	= &axg_mst_f_sclk_pre_en.hw,
427*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_SCLK_DIV]	= &axg_mst_a_sclk_div.hw,
428*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_SCLK_DIV]	= &axg_mst_b_sclk_div.hw,
429*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_SCLK_DIV]	= &axg_mst_c_sclk_div.hw,
430*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_SCLK_DIV]	= &axg_mst_d_sclk_div.hw,
431*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_SCLK_DIV]	= &axg_mst_e_sclk_div.hw,
432*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_SCLK_DIV]	= &axg_mst_f_sclk_div.hw,
433*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_SCLK_POST_EN]	= &axg_mst_a_sclk_post_en.hw,
434*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_SCLK_POST_EN]	= &axg_mst_b_sclk_post_en.hw,
435*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_SCLK_POST_EN]	= &axg_mst_c_sclk_post_en.hw,
436*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_SCLK_POST_EN]	= &axg_mst_d_sclk_post_en.hw,
437*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_SCLK_POST_EN]	= &axg_mst_e_sclk_post_en.hw,
438*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_SCLK_POST_EN]	= &axg_mst_f_sclk_post_en.hw,
439*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_SCLK]		= &axg_mst_a_sclk.hw,
440*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_SCLK]		= &axg_mst_b_sclk.hw,
441*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_SCLK]		= &axg_mst_c_sclk.hw,
442*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_SCLK]		= &axg_mst_d_sclk.hw,
443*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_SCLK]		= &axg_mst_e_sclk.hw,
444*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_SCLK]		= &axg_mst_f_sclk.hw,
445*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_LRCLK_DIV]	= &axg_mst_a_lrclk_div.hw,
446*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_LRCLK_DIV]	= &axg_mst_b_lrclk_div.hw,
447*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_LRCLK_DIV]	= &axg_mst_c_lrclk_div.hw,
448*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_LRCLK_DIV]	= &axg_mst_d_lrclk_div.hw,
449*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_LRCLK_DIV]	= &axg_mst_e_lrclk_div.hw,
450*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_LRCLK_DIV]	= &axg_mst_f_lrclk_div.hw,
451*1cd50181SJerome Brunet 		[AUD_CLKID_MST_A_LRCLK]		= &axg_mst_a_lrclk.hw,
452*1cd50181SJerome Brunet 		[AUD_CLKID_MST_B_LRCLK]		= &axg_mst_b_lrclk.hw,
453*1cd50181SJerome Brunet 		[AUD_CLKID_MST_C_LRCLK]		= &axg_mst_c_lrclk.hw,
454*1cd50181SJerome Brunet 		[AUD_CLKID_MST_D_LRCLK]		= &axg_mst_d_lrclk.hw,
455*1cd50181SJerome Brunet 		[AUD_CLKID_MST_E_LRCLK]		= &axg_mst_e_lrclk.hw,
456*1cd50181SJerome Brunet 		[AUD_CLKID_MST_F_LRCLK]		= &axg_mst_f_lrclk.hw,
457*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_A_SCLK_SEL]	= &axg_tdmin_a_sclk_sel.hw,
458*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_B_SCLK_SEL]	= &axg_tdmin_b_sclk_sel.hw,
459*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_C_SCLK_SEL]	= &axg_tdmin_c_sclk_sel.hw,
460*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_LB_SCLK_SEL]	= &axg_tdmin_lb_sclk_sel.hw,
461*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_A_SCLK_SEL]	= &axg_tdmout_a_sclk_sel.hw,
462*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_B_SCLK_SEL]	= &axg_tdmout_b_sclk_sel.hw,
463*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_C_SCLK_SEL]	= &axg_tdmout_c_sclk_sel.hw,
464*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_A_SCLK_PRE_EN]	= &axg_tdmin_a_sclk_pre_en.hw,
465*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_B_SCLK_PRE_EN]	= &axg_tdmin_b_sclk_pre_en.hw,
466*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_C_SCLK_PRE_EN]	= &axg_tdmin_c_sclk_pre_en.hw,
467*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_LB_SCLK_PRE_EN] = &axg_tdmin_lb_sclk_pre_en.hw,
468*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_A_SCLK_PRE_EN] = &axg_tdmout_a_sclk_pre_en.hw,
469*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_B_SCLK_PRE_EN] = &axg_tdmout_b_sclk_pre_en.hw,
470*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_C_SCLK_PRE_EN] = &axg_tdmout_c_sclk_pre_en.hw,
471*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_A_SCLK_POST_EN] = &axg_tdmin_a_sclk_post_en.hw,
472*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_B_SCLK_POST_EN] = &axg_tdmin_b_sclk_post_en.hw,
473*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_C_SCLK_POST_EN] = &axg_tdmin_c_sclk_post_en.hw,
474*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_LB_SCLK_POST_EN] = &axg_tdmin_lb_sclk_post_en.hw,
475*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_A_SCLK_POST_EN] = &axg_tdmout_a_sclk_post_en.hw,
476*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_B_SCLK_POST_EN] = &axg_tdmout_b_sclk_post_en.hw,
477*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_C_SCLK_POST_EN] = &axg_tdmout_c_sclk_post_en.hw,
478*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_A_SCLK]	= &axg_tdmin_a_sclk.hw,
479*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_B_SCLK]	= &axg_tdmin_b_sclk.hw,
480*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_C_SCLK]	= &axg_tdmin_c_sclk.hw,
481*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_LB_SCLK]	= &axg_tdmin_lb_sclk.hw,
482*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_A_SCLK]	= &axg_tdmout_a_sclk.hw,
483*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_B_SCLK]	= &axg_tdmout_b_sclk.hw,
484*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_C_SCLK]	= &axg_tdmout_c_sclk.hw,
485*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_A_LRCLK]	= &axg_tdmin_a_lrclk.hw,
486*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_B_LRCLK]	= &axg_tdmin_b_lrclk.hw,
487*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_C_LRCLK]	= &axg_tdmin_c_lrclk.hw,
488*1cd50181SJerome Brunet 		[AUD_CLKID_TDMIN_LB_LRCLK]	= &axg_tdmin_lb_lrclk.hw,
489*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_A_LRCLK]	= &axg_tdmout_a_lrclk.hw,
490*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_B_LRCLK]	= &axg_tdmout_b_lrclk.hw,
491*1cd50181SJerome Brunet 		[AUD_CLKID_TDMOUT_C_LRCLK]	= &axg_tdmout_c_lrclk.hw,
492*1cd50181SJerome Brunet 		[NR_CLKS] = NULL,
493*1cd50181SJerome Brunet 	},
494*1cd50181SJerome Brunet 	.num = NR_CLKS,
495*1cd50181SJerome Brunet };
496*1cd50181SJerome Brunet 
497*1cd50181SJerome Brunet /* Convenience table to populate regmap in .probe() */
498*1cd50181SJerome Brunet static struct clk_regmap *const axg_audio_clk_regmaps[] = {
499*1cd50181SJerome Brunet 	&axg_ddr_arb,
500*1cd50181SJerome Brunet 	&axg_pdm,
501*1cd50181SJerome Brunet 	&axg_tdmin_a,
502*1cd50181SJerome Brunet 	&axg_tdmin_b,
503*1cd50181SJerome Brunet 	&axg_tdmin_c,
504*1cd50181SJerome Brunet 	&axg_tdmin_lb,
505*1cd50181SJerome Brunet 	&axg_tdmout_a,
506*1cd50181SJerome Brunet 	&axg_tdmout_b,
507*1cd50181SJerome Brunet 	&axg_tdmout_c,
508*1cd50181SJerome Brunet 	&axg_frddr_a,
509*1cd50181SJerome Brunet 	&axg_frddr_b,
510*1cd50181SJerome Brunet 	&axg_frddr_c,
511*1cd50181SJerome Brunet 	&axg_toddr_a,
512*1cd50181SJerome Brunet 	&axg_toddr_b,
513*1cd50181SJerome Brunet 	&axg_toddr_c,
514*1cd50181SJerome Brunet 	&axg_loopback,
515*1cd50181SJerome Brunet 	&axg_spdifin,
516*1cd50181SJerome Brunet 	&axg_spdifout,
517*1cd50181SJerome Brunet 	&axg_resample,
518*1cd50181SJerome Brunet 	&axg_power_detect,
519*1cd50181SJerome Brunet 	&axg_mst_a_mclk_sel,
520*1cd50181SJerome Brunet 	&axg_mst_b_mclk_sel,
521*1cd50181SJerome Brunet 	&axg_mst_c_mclk_sel,
522*1cd50181SJerome Brunet 	&axg_mst_d_mclk_sel,
523*1cd50181SJerome Brunet 	&axg_mst_e_mclk_sel,
524*1cd50181SJerome Brunet 	&axg_mst_f_mclk_sel,
525*1cd50181SJerome Brunet 	&axg_mst_a_mclk_div,
526*1cd50181SJerome Brunet 	&axg_mst_b_mclk_div,
527*1cd50181SJerome Brunet 	&axg_mst_c_mclk_div,
528*1cd50181SJerome Brunet 	&axg_mst_d_mclk_div,
529*1cd50181SJerome Brunet 	&axg_mst_e_mclk_div,
530*1cd50181SJerome Brunet 	&axg_mst_f_mclk_div,
531*1cd50181SJerome Brunet 	&axg_mst_a_mclk,
532*1cd50181SJerome Brunet 	&axg_mst_b_mclk,
533*1cd50181SJerome Brunet 	&axg_mst_c_mclk,
534*1cd50181SJerome Brunet 	&axg_mst_d_mclk,
535*1cd50181SJerome Brunet 	&axg_mst_e_mclk,
536*1cd50181SJerome Brunet 	&axg_mst_f_mclk,
537*1cd50181SJerome Brunet 	&axg_spdifout_clk_sel,
538*1cd50181SJerome Brunet 	&axg_spdifout_clk_div,
539*1cd50181SJerome Brunet 	&axg_spdifout_clk,
540*1cd50181SJerome Brunet 	&axg_spdifin_clk_sel,
541*1cd50181SJerome Brunet 	&axg_spdifin_clk_div,
542*1cd50181SJerome Brunet 	&axg_spdifin_clk,
543*1cd50181SJerome Brunet 	&axg_pdm_dclk_sel,
544*1cd50181SJerome Brunet 	&axg_pdm_dclk_div,
545*1cd50181SJerome Brunet 	&axg_pdm_dclk,
546*1cd50181SJerome Brunet 	&axg_pdm_sysclk_sel,
547*1cd50181SJerome Brunet 	&axg_pdm_sysclk_div,
548*1cd50181SJerome Brunet 	&axg_pdm_sysclk,
549*1cd50181SJerome Brunet 	&axg_mst_a_sclk_pre_en,
550*1cd50181SJerome Brunet 	&axg_mst_b_sclk_pre_en,
551*1cd50181SJerome Brunet 	&axg_mst_c_sclk_pre_en,
552*1cd50181SJerome Brunet 	&axg_mst_d_sclk_pre_en,
553*1cd50181SJerome Brunet 	&axg_mst_e_sclk_pre_en,
554*1cd50181SJerome Brunet 	&axg_mst_f_sclk_pre_en,
555*1cd50181SJerome Brunet 	&axg_mst_a_sclk_div,
556*1cd50181SJerome Brunet 	&axg_mst_b_sclk_div,
557*1cd50181SJerome Brunet 	&axg_mst_c_sclk_div,
558*1cd50181SJerome Brunet 	&axg_mst_d_sclk_div,
559*1cd50181SJerome Brunet 	&axg_mst_e_sclk_div,
560*1cd50181SJerome Brunet 	&axg_mst_f_sclk_div,
561*1cd50181SJerome Brunet 	&axg_mst_a_sclk_post_en,
562*1cd50181SJerome Brunet 	&axg_mst_b_sclk_post_en,
563*1cd50181SJerome Brunet 	&axg_mst_c_sclk_post_en,
564*1cd50181SJerome Brunet 	&axg_mst_d_sclk_post_en,
565*1cd50181SJerome Brunet 	&axg_mst_e_sclk_post_en,
566*1cd50181SJerome Brunet 	&axg_mst_f_sclk_post_en,
567*1cd50181SJerome Brunet 	&axg_mst_a_sclk,
568*1cd50181SJerome Brunet 	&axg_mst_b_sclk,
569*1cd50181SJerome Brunet 	&axg_mst_c_sclk,
570*1cd50181SJerome Brunet 	&axg_mst_d_sclk,
571*1cd50181SJerome Brunet 	&axg_mst_e_sclk,
572*1cd50181SJerome Brunet 	&axg_mst_f_sclk,
573*1cd50181SJerome Brunet 	&axg_mst_a_lrclk_div,
574*1cd50181SJerome Brunet 	&axg_mst_b_lrclk_div,
575*1cd50181SJerome Brunet 	&axg_mst_c_lrclk_div,
576*1cd50181SJerome Brunet 	&axg_mst_d_lrclk_div,
577*1cd50181SJerome Brunet 	&axg_mst_e_lrclk_div,
578*1cd50181SJerome Brunet 	&axg_mst_f_lrclk_div,
579*1cd50181SJerome Brunet 	&axg_mst_a_lrclk,
580*1cd50181SJerome Brunet 	&axg_mst_b_lrclk,
581*1cd50181SJerome Brunet 	&axg_mst_c_lrclk,
582*1cd50181SJerome Brunet 	&axg_mst_d_lrclk,
583*1cd50181SJerome Brunet 	&axg_mst_e_lrclk,
584*1cd50181SJerome Brunet 	&axg_mst_f_lrclk,
585*1cd50181SJerome Brunet 	&axg_tdmin_a_sclk_sel,
586*1cd50181SJerome Brunet 	&axg_tdmin_b_sclk_sel,
587*1cd50181SJerome Brunet 	&axg_tdmin_c_sclk_sel,
588*1cd50181SJerome Brunet 	&axg_tdmin_lb_sclk_sel,
589*1cd50181SJerome Brunet 	&axg_tdmout_a_sclk_sel,
590*1cd50181SJerome Brunet 	&axg_tdmout_b_sclk_sel,
591*1cd50181SJerome Brunet 	&axg_tdmout_c_sclk_sel,
592*1cd50181SJerome Brunet 	&axg_tdmin_a_sclk_pre_en,
593*1cd50181SJerome Brunet 	&axg_tdmin_b_sclk_pre_en,
594*1cd50181SJerome Brunet 	&axg_tdmin_c_sclk_pre_en,
595*1cd50181SJerome Brunet 	&axg_tdmin_lb_sclk_pre_en,
596*1cd50181SJerome Brunet 	&axg_tdmout_a_sclk_pre_en,
597*1cd50181SJerome Brunet 	&axg_tdmout_b_sclk_pre_en,
598*1cd50181SJerome Brunet 	&axg_tdmout_c_sclk_pre_en,
599*1cd50181SJerome Brunet 	&axg_tdmin_a_sclk_post_en,
600*1cd50181SJerome Brunet 	&axg_tdmin_b_sclk_post_en,
601*1cd50181SJerome Brunet 	&axg_tdmin_c_sclk_post_en,
602*1cd50181SJerome Brunet 	&axg_tdmin_lb_sclk_post_en,
603*1cd50181SJerome Brunet 	&axg_tdmout_a_sclk_post_en,
604*1cd50181SJerome Brunet 	&axg_tdmout_b_sclk_post_en,
605*1cd50181SJerome Brunet 	&axg_tdmout_c_sclk_post_en,
606*1cd50181SJerome Brunet 	&axg_tdmin_a_sclk,
607*1cd50181SJerome Brunet 	&axg_tdmin_b_sclk,
608*1cd50181SJerome Brunet 	&axg_tdmin_c_sclk,
609*1cd50181SJerome Brunet 	&axg_tdmin_lb_sclk,
610*1cd50181SJerome Brunet 	&axg_tdmout_a_sclk,
611*1cd50181SJerome Brunet 	&axg_tdmout_b_sclk,
612*1cd50181SJerome Brunet 	&axg_tdmout_c_sclk,
613*1cd50181SJerome Brunet 	&axg_tdmin_a_lrclk,
614*1cd50181SJerome Brunet 	&axg_tdmin_b_lrclk,
615*1cd50181SJerome Brunet 	&axg_tdmin_c_lrclk,
616*1cd50181SJerome Brunet 	&axg_tdmin_lb_lrclk,
617*1cd50181SJerome Brunet 	&axg_tdmout_a_lrclk,
618*1cd50181SJerome Brunet 	&axg_tdmout_b_lrclk,
619*1cd50181SJerome Brunet 	&axg_tdmout_c_lrclk,
620*1cd50181SJerome Brunet };
621*1cd50181SJerome Brunet 
622*1cd50181SJerome Brunet static struct clk *devm_clk_get_enable(struct device *dev, char *id)
623*1cd50181SJerome Brunet {
624*1cd50181SJerome Brunet 	struct clk *clk;
625*1cd50181SJerome Brunet 	int ret;
626*1cd50181SJerome Brunet 
627*1cd50181SJerome Brunet 	clk = devm_clk_get(dev, id);
628*1cd50181SJerome Brunet 	if (IS_ERR(clk)) {
629*1cd50181SJerome Brunet 		if (PTR_ERR(clk) != -EPROBE_DEFER)
630*1cd50181SJerome Brunet 			dev_err(dev, "failed to get %s", id);
631*1cd50181SJerome Brunet 		return clk;
632*1cd50181SJerome Brunet 	}
633*1cd50181SJerome Brunet 
634*1cd50181SJerome Brunet 	ret = clk_prepare_enable(clk);
635*1cd50181SJerome Brunet 	if (ret) {
636*1cd50181SJerome Brunet 		dev_err(dev, "failed to enable %s", id);
637*1cd50181SJerome Brunet 		return ERR_PTR(ret);
638*1cd50181SJerome Brunet 	}
639*1cd50181SJerome Brunet 
640*1cd50181SJerome Brunet 	ret = devm_add_action_or_reset(dev,
641*1cd50181SJerome Brunet 				       (void(*)(void *))clk_disable_unprepare,
642*1cd50181SJerome Brunet 				       clk);
643*1cd50181SJerome Brunet 	if (ret) {
644*1cd50181SJerome Brunet 		dev_err(dev, "failed to add reset action on %s", id);
645*1cd50181SJerome Brunet 		return ERR_PTR(ret);
646*1cd50181SJerome Brunet 	}
647*1cd50181SJerome Brunet 
648*1cd50181SJerome Brunet 	return clk;
649*1cd50181SJerome Brunet }
650*1cd50181SJerome Brunet 
651*1cd50181SJerome Brunet static const struct clk_ops axg_clk_no_ops = {};
652*1cd50181SJerome Brunet 
653*1cd50181SJerome Brunet static struct clk_hw *axg_clk_hw_register_bypass(struct device *dev,
654*1cd50181SJerome Brunet 						 const char *name,
655*1cd50181SJerome Brunet 						 const char *parent_name)
656*1cd50181SJerome Brunet {
657*1cd50181SJerome Brunet 	struct clk_hw *hw;
658*1cd50181SJerome Brunet 	struct clk_init_data init;
659*1cd50181SJerome Brunet 	char *clk_name;
660*1cd50181SJerome Brunet 	int ret;
661*1cd50181SJerome Brunet 
662*1cd50181SJerome Brunet 	hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
663*1cd50181SJerome Brunet 	if (!hw)
664*1cd50181SJerome Brunet 		return ERR_PTR(-ENOMEM);
665*1cd50181SJerome Brunet 
666*1cd50181SJerome Brunet 	clk_name = kasprintf(GFP_KERNEL, "axg_%s", name);
667*1cd50181SJerome Brunet 	if (!clk_name)
668*1cd50181SJerome Brunet 		return ERR_PTR(-ENOMEM);
669*1cd50181SJerome Brunet 
670*1cd50181SJerome Brunet 	init.name = clk_name;
671*1cd50181SJerome Brunet 	init.ops = &axg_clk_no_ops;
672*1cd50181SJerome Brunet 	init.flags = 0;
673*1cd50181SJerome Brunet 	init.parent_names = parent_name ? &parent_name : NULL;
674*1cd50181SJerome Brunet 	init.num_parents = parent_name ? 1 : 0;
675*1cd50181SJerome Brunet 	hw->init = &init;
676*1cd50181SJerome Brunet 
677*1cd50181SJerome Brunet 	ret = devm_clk_hw_register(dev, hw);
678*1cd50181SJerome Brunet 	kfree(clk_name);
679*1cd50181SJerome Brunet 
680*1cd50181SJerome Brunet 	return ret ? ERR_PTR(ret) : hw;
681*1cd50181SJerome Brunet }
682*1cd50181SJerome Brunet 
683*1cd50181SJerome Brunet static int axg_register_clk_hw_input(struct device *dev,
684*1cd50181SJerome Brunet 				     const char *name,
685*1cd50181SJerome Brunet 				     unsigned int clkid)
686*1cd50181SJerome Brunet {
687*1cd50181SJerome Brunet 	struct clk *parent_clk = devm_clk_get(dev, name);
688*1cd50181SJerome Brunet 	struct clk_hw *hw = NULL;
689*1cd50181SJerome Brunet 
690*1cd50181SJerome Brunet 	if (IS_ERR(parent_clk)) {
691*1cd50181SJerome Brunet 		int err = PTR_ERR(parent_clk);
692*1cd50181SJerome Brunet 
693*1cd50181SJerome Brunet 		/* It is ok if an input clock is missing */
694*1cd50181SJerome Brunet 		if (err == -ENOENT) {
695*1cd50181SJerome Brunet 			dev_dbg(dev, "%s not provided", name);
696*1cd50181SJerome Brunet 		} else {
697*1cd50181SJerome Brunet 			if (err != -EPROBE_DEFER)
698*1cd50181SJerome Brunet 				dev_err(dev, "failed to get %s clock", name);
699*1cd50181SJerome Brunet 			return err;
700*1cd50181SJerome Brunet 		}
701*1cd50181SJerome Brunet 	} else {
702*1cd50181SJerome Brunet 		hw = axg_clk_hw_register_bypass(dev, name,
703*1cd50181SJerome Brunet 						__clk_get_name(parent_clk));
704*1cd50181SJerome Brunet 	}
705*1cd50181SJerome Brunet 
706*1cd50181SJerome Brunet 	if (IS_ERR(hw)) {
707*1cd50181SJerome Brunet 		dev_err(dev, "failed to register %s clock", name);
708*1cd50181SJerome Brunet 		return PTR_ERR(hw);
709*1cd50181SJerome Brunet 	}
710*1cd50181SJerome Brunet 
711*1cd50181SJerome Brunet 	axg_audio_hw_onecell_data.hws[clkid] = hw;
712*1cd50181SJerome Brunet 	return 0;
713*1cd50181SJerome Brunet }
714*1cd50181SJerome Brunet 
715*1cd50181SJerome Brunet static int axg_register_clk_hw_inputs(struct device *dev,
716*1cd50181SJerome Brunet 				      const char *basename,
717*1cd50181SJerome Brunet 				      unsigned int count,
718*1cd50181SJerome Brunet 				      unsigned int clkid)
719*1cd50181SJerome Brunet {
720*1cd50181SJerome Brunet 	char *name;
721*1cd50181SJerome Brunet 	int i, ret;
722*1cd50181SJerome Brunet 
723*1cd50181SJerome Brunet 	for (i = 0; i < count; i++) {
724*1cd50181SJerome Brunet 		name = kasprintf(GFP_KERNEL, "%s%d", basename, i);
725*1cd50181SJerome Brunet 		if (!name)
726*1cd50181SJerome Brunet 			return -ENOMEM;
727*1cd50181SJerome Brunet 
728*1cd50181SJerome Brunet 		ret = axg_register_clk_hw_input(dev, name, clkid + i);
729*1cd50181SJerome Brunet 		kfree(name);
730*1cd50181SJerome Brunet 		if (ret)
731*1cd50181SJerome Brunet 			return ret;
732*1cd50181SJerome Brunet 	}
733*1cd50181SJerome Brunet 
734*1cd50181SJerome Brunet 	return 0;
735*1cd50181SJerome Brunet }
736*1cd50181SJerome Brunet 
737*1cd50181SJerome Brunet static const struct regmap_config axg_audio_regmap_cfg = {
738*1cd50181SJerome Brunet 	.reg_bits	= 32,
739*1cd50181SJerome Brunet 	.val_bits	= 32,
740*1cd50181SJerome Brunet 	.reg_stride	= 4,
741*1cd50181SJerome Brunet 	.max_register	= AUDIO_CLK_PDMIN_CTRL1,
742*1cd50181SJerome Brunet };
743*1cd50181SJerome Brunet 
744*1cd50181SJerome Brunet static int axg_audio_clkc_probe(struct platform_device *pdev)
745*1cd50181SJerome Brunet {
746*1cd50181SJerome Brunet 	struct device *dev = &pdev->dev;
747*1cd50181SJerome Brunet 	struct regmap *map;
748*1cd50181SJerome Brunet 	struct resource *res;
749*1cd50181SJerome Brunet 	void __iomem *regs;
750*1cd50181SJerome Brunet 	struct clk *clk;
751*1cd50181SJerome Brunet 	struct clk_hw *hw;
752*1cd50181SJerome Brunet 	int ret, i;
753*1cd50181SJerome Brunet 
754*1cd50181SJerome Brunet 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
755*1cd50181SJerome Brunet 	regs = devm_ioremap_resource(dev, res);
756*1cd50181SJerome Brunet 	if (IS_ERR(regs))
757*1cd50181SJerome Brunet 		return PTR_ERR(regs);
758*1cd50181SJerome Brunet 
759*1cd50181SJerome Brunet 	map = devm_regmap_init_mmio(dev, regs, &axg_audio_regmap_cfg);
760*1cd50181SJerome Brunet 	if (IS_ERR(map)) {
761*1cd50181SJerome Brunet 		dev_err(dev, "failed to init regmap: %ld\n", PTR_ERR(map));
762*1cd50181SJerome Brunet 		return PTR_ERR(map);
763*1cd50181SJerome Brunet 	}
764*1cd50181SJerome Brunet 
765*1cd50181SJerome Brunet 	/* Get the mandatory peripheral clock */
766*1cd50181SJerome Brunet 	clk = devm_clk_get_enable(dev, "pclk");
767*1cd50181SJerome Brunet 	if (IS_ERR(clk))
768*1cd50181SJerome Brunet 		return PTR_ERR(clk);
769*1cd50181SJerome Brunet 
770*1cd50181SJerome Brunet 	ret = device_reset(dev);
771*1cd50181SJerome Brunet 	if (ret) {
772*1cd50181SJerome Brunet 		dev_err(dev, "failed to reset device\n");
773*1cd50181SJerome Brunet 		return ret;
774*1cd50181SJerome Brunet 	}
775*1cd50181SJerome Brunet 
776*1cd50181SJerome Brunet 	/* Register the peripheral input clock */
777*1cd50181SJerome Brunet 	hw = axg_clk_hw_register_bypass(dev, "audio_pclk",
778*1cd50181SJerome Brunet 					__clk_get_name(clk));
779*1cd50181SJerome Brunet 	if (IS_ERR(hw))
780*1cd50181SJerome Brunet 		return PTR_ERR(hw);
781*1cd50181SJerome Brunet 
782*1cd50181SJerome Brunet 	axg_audio_hw_onecell_data.hws[AUD_CLKID_PCLK] = hw;
783*1cd50181SJerome Brunet 
784*1cd50181SJerome Brunet 	/* Register optional input master clocks */
785*1cd50181SJerome Brunet 	ret = axg_register_clk_hw_inputs(dev, "mst_in",
786*1cd50181SJerome Brunet 					 AXG_MST_IN_COUNT,
787*1cd50181SJerome Brunet 					 AUD_CLKID_MST0);
788*1cd50181SJerome Brunet 	if (ret)
789*1cd50181SJerome Brunet 		return ret;
790*1cd50181SJerome Brunet 
791*1cd50181SJerome Brunet 	/* Register optional input slave sclks */
792*1cd50181SJerome Brunet 	ret = axg_register_clk_hw_inputs(dev, "slv_sclk",
793*1cd50181SJerome Brunet 					 AXG_SLV_SCLK_COUNT,
794*1cd50181SJerome Brunet 					 AUD_CLKID_SLV_SCLK0);
795*1cd50181SJerome Brunet 	if (ret)
796*1cd50181SJerome Brunet 		return ret;
797*1cd50181SJerome Brunet 
798*1cd50181SJerome Brunet 	/* Register optional input slave lrclks */
799*1cd50181SJerome Brunet 	ret = axg_register_clk_hw_inputs(dev, "slv_lrclk",
800*1cd50181SJerome Brunet 					 AXG_SLV_LRCLK_COUNT,
801*1cd50181SJerome Brunet 					 AUD_CLKID_SLV_LRCLK0);
802*1cd50181SJerome Brunet 	if (ret)
803*1cd50181SJerome Brunet 		return ret;
804*1cd50181SJerome Brunet 
805*1cd50181SJerome Brunet 	/* Populate regmap for the regmap backed clocks */
806*1cd50181SJerome Brunet 	for (i = 0; i < ARRAY_SIZE(axg_audio_clk_regmaps); i++)
807*1cd50181SJerome Brunet 		axg_audio_clk_regmaps[i]->map = map;
808*1cd50181SJerome Brunet 
809*1cd50181SJerome Brunet 	/* Take care to skip the registered input clocks */
810*1cd50181SJerome Brunet 	for (i = AUD_CLKID_DDR_ARB; i < axg_audio_hw_onecell_data.num; i++) {
811*1cd50181SJerome Brunet 		hw = axg_audio_hw_onecell_data.hws[i];
812*1cd50181SJerome Brunet 		/* array might be sparse */
813*1cd50181SJerome Brunet 		if (!hw)
814*1cd50181SJerome Brunet 			continue;
815*1cd50181SJerome Brunet 
816*1cd50181SJerome Brunet 		ret = devm_clk_hw_register(dev, hw);
817*1cd50181SJerome Brunet 		if (ret) {
818*1cd50181SJerome Brunet 			dev_err(dev, "failed to register clock %s\n",
819*1cd50181SJerome Brunet 				hw->init->name);
820*1cd50181SJerome Brunet 			return ret;
821*1cd50181SJerome Brunet 		}
822*1cd50181SJerome Brunet 	}
823*1cd50181SJerome Brunet 
824*1cd50181SJerome Brunet 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
825*1cd50181SJerome Brunet 					   &axg_audio_hw_onecell_data);
826*1cd50181SJerome Brunet }
827*1cd50181SJerome Brunet 
828*1cd50181SJerome Brunet static const struct of_device_id clkc_match_table[] = {
829*1cd50181SJerome Brunet 	{ .compatible = "amlogic,axg-audio-clkc" },
830*1cd50181SJerome Brunet 	{}
831*1cd50181SJerome Brunet };
832*1cd50181SJerome Brunet MODULE_DEVICE_TABLE(of, clkc_match_table);
833*1cd50181SJerome Brunet 
834*1cd50181SJerome Brunet static struct platform_driver axg_audio_driver = {
835*1cd50181SJerome Brunet 	.probe		= axg_audio_clkc_probe,
836*1cd50181SJerome Brunet 	.driver		= {
837*1cd50181SJerome Brunet 		.name	= "axg-audio-clkc",
838*1cd50181SJerome Brunet 		.of_match_table = clkc_match_table,
839*1cd50181SJerome Brunet 	},
840*1cd50181SJerome Brunet };
841*1cd50181SJerome Brunet module_platform_driver(axg_audio_driver);
842*1cd50181SJerome Brunet 
843*1cd50181SJerome Brunet MODULE_DESCRIPTION("Amlogic A113x Audio Clock driver");
844*1cd50181SJerome Brunet MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
845*1cd50181SJerome Brunet MODULE_LICENSE("GPL v2");
846