xref: /openbmc/linux/sound/soc/sh/rcar/rsnd.h (revision bb7927c7)
1 /*
2  * Renesas R-Car
3  *
4  * Copyright (C) 2013 Renesas Solutions Corp.
5  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #ifndef RSND_H
12 #define RSND_H
13 
14 #include <linux/clk.h>
15 #include <linux/device.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/io.h>
18 #include <linux/list.h>
19 #include <linux/module.h>
20 #include <linux/of_device.h>
21 #include <linux/of_irq.h>
22 #include <linux/sh_dma.h>
23 #include <linux/workqueue.h>
24 #include <sound/soc.h>
25 #include <sound/pcm_params.h>
26 
27 #define RSND_GEN1_SRU	0
28 #define RSND_GEN1_ADG	1
29 #define RSND_GEN1_SSI	2
30 
31 #define RSND_GEN2_SCU	0
32 #define RSND_GEN2_ADG	1
33 #define RSND_GEN2_SSIU	2
34 #define RSND_GEN2_SSI	3
35 
36 #define RSND_BASE_MAX	4
37 
38 /*
39  *	pseudo register
40  *
41  * The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different.
42  * This driver uses pseudo register in order to hide it.
43  * see gen1/gen2 for detail
44  */
45 enum rsnd_reg {
46 	/* SCU (MIX/CTU/DVC) */
47 	RSND_REG_SRC_I_BUSIF_MODE,
48 	RSND_REG_SRC_O_BUSIF_MODE,
49 	RSND_REG_SRC_ROUTE_MODE0,
50 	RSND_REG_SRC_SWRSR,
51 	RSND_REG_SRC_SRCIR,
52 	RSND_REG_SRC_ADINR,
53 	RSND_REG_SRC_IFSCR,
54 	RSND_REG_SRC_IFSVR,
55 	RSND_REG_SRC_SRCCR,
56 	RSND_REG_SRC_CTRL,
57 	RSND_REG_SRC_BSDSR,
58 	RSND_REG_SRC_BSISR,
59 	RSND_REG_SRC_INT_ENABLE0,
60 	RSND_REG_SRC_BUSIF_DALIGN,
61 	RSND_REG_SRCIN_TIMSEL0,
62 	RSND_REG_SRCIN_TIMSEL1,
63 	RSND_REG_SRCIN_TIMSEL2,
64 	RSND_REG_SRCIN_TIMSEL3,
65 	RSND_REG_SRCIN_TIMSEL4,
66 	RSND_REG_SRCOUT_TIMSEL0,
67 	RSND_REG_SRCOUT_TIMSEL1,
68 	RSND_REG_SRCOUT_TIMSEL2,
69 	RSND_REG_SRCOUT_TIMSEL3,
70 	RSND_REG_SRCOUT_TIMSEL4,
71 	RSND_REG_SCU_SYS_STATUS0,
72 	RSND_REG_SCU_SYS_STATUS1,
73 	RSND_REG_SCU_SYS_INT_EN0,
74 	RSND_REG_SCU_SYS_INT_EN1,
75 	RSND_REG_CMD_CTRL,
76 	RSND_REG_CMD_BUSIF_DALIGN,
77 	RSND_REG_CMD_ROUTE_SLCT,
78 	RSND_REG_CMDOUT_TIMSEL,
79 	RSND_REG_CTU_SWRSR,
80 	RSND_REG_CTU_CTUIR,
81 	RSND_REG_CTU_ADINR,
82 	RSND_REG_CTU_CPMDR,
83 	RSND_REG_CTU_SCMDR,
84 	RSND_REG_CTU_SV00R,
85 	RSND_REG_CTU_SV01R,
86 	RSND_REG_CTU_SV02R,
87 	RSND_REG_CTU_SV03R,
88 	RSND_REG_CTU_SV04R,
89 	RSND_REG_CTU_SV05R,
90 	RSND_REG_CTU_SV06R,
91 	RSND_REG_CTU_SV07R,
92 	RSND_REG_CTU_SV10R,
93 	RSND_REG_CTU_SV11R,
94 	RSND_REG_CTU_SV12R,
95 	RSND_REG_CTU_SV13R,
96 	RSND_REG_CTU_SV14R,
97 	RSND_REG_CTU_SV15R,
98 	RSND_REG_CTU_SV16R,
99 	RSND_REG_CTU_SV17R,
100 	RSND_REG_CTU_SV20R,
101 	RSND_REG_CTU_SV21R,
102 	RSND_REG_CTU_SV22R,
103 	RSND_REG_CTU_SV23R,
104 	RSND_REG_CTU_SV24R,
105 	RSND_REG_CTU_SV25R,
106 	RSND_REG_CTU_SV26R,
107 	RSND_REG_CTU_SV27R,
108 	RSND_REG_CTU_SV30R,
109 	RSND_REG_CTU_SV31R,
110 	RSND_REG_CTU_SV32R,
111 	RSND_REG_CTU_SV33R,
112 	RSND_REG_CTU_SV34R,
113 	RSND_REG_CTU_SV35R,
114 	RSND_REG_CTU_SV36R,
115 	RSND_REG_CTU_SV37R,
116 	RSND_REG_MIX_SWRSR,
117 	RSND_REG_MIX_MIXIR,
118 	RSND_REG_MIX_ADINR,
119 	RSND_REG_MIX_MIXMR,
120 	RSND_REG_MIX_MVPDR,
121 	RSND_REG_MIX_MDBAR,
122 	RSND_REG_MIX_MDBBR,
123 	RSND_REG_MIX_MDBCR,
124 	RSND_REG_MIX_MDBDR,
125 	RSND_REG_MIX_MDBER,
126 	RSND_REG_DVC_SWRSR,
127 	RSND_REG_DVC_DVUIR,
128 	RSND_REG_DVC_ADINR,
129 	RSND_REG_DVC_DVUCR,
130 	RSND_REG_DVC_ZCMCR,
131 	RSND_REG_DVC_VOL0R,
132 	RSND_REG_DVC_VOL1R,
133 	RSND_REG_DVC_VOL2R,
134 	RSND_REG_DVC_VOL3R,
135 	RSND_REG_DVC_VOL4R,
136 	RSND_REG_DVC_VOL5R,
137 	RSND_REG_DVC_VOL6R,
138 	RSND_REG_DVC_VOL7R,
139 	RSND_REG_DVC_DVUER,
140 	RSND_REG_DVC_VRCTR,
141 	RSND_REG_DVC_VRPDR,
142 	RSND_REG_DVC_VRDBR,
143 
144 	/* ADG */
145 	RSND_REG_BRRA,
146 	RSND_REG_BRRB,
147 	RSND_REG_SSICKR,
148 	RSND_REG_DIV_EN,
149 	RSND_REG_AUDIO_CLK_SEL0,
150 	RSND_REG_AUDIO_CLK_SEL1,
151 	RSND_REG_AUDIO_CLK_SEL2,
152 
153 	/* SSIU */
154 	RSND_REG_SSI_MODE,
155 	RSND_REG_SSI_MODE0,
156 	RSND_REG_SSI_MODE1,
157 	RSND_REG_SSI_MODE2,
158 	RSND_REG_SSI_CONTROL,
159 	RSND_REG_SSI_CTRL,
160 	RSND_REG_SSI_BUSIF_MODE,
161 	RSND_REG_SSI_BUSIF_ADINR,
162 	RSND_REG_SSI_BUSIF_DALIGN,
163 	RSND_REG_SSI_INT_ENABLE,
164 
165 	/* SSI */
166 	RSND_REG_SSICR,
167 	RSND_REG_SSISR,
168 	RSND_REG_SSITDR,
169 	RSND_REG_SSIRDR,
170 	RSND_REG_SSIWSR,
171 
172 	RSND_REG_MAX,
173 };
174 
175 struct rsnd_priv;
176 struct rsnd_mod;
177 struct rsnd_dai;
178 struct rsnd_dai_stream;
179 
180 /*
181  *	R-Car basic functions
182  */
183 #define rsnd_mod_read(m, r) \
184 	rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
185 #define rsnd_mod_write(m, r, d) \
186 	rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
187 #define rsnd_mod_bset(m, r, s, d) \
188 	rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
189 
190 u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
191 void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
192 		enum rsnd_reg reg, u32 data);
193 void rsnd_force_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
194 		enum rsnd_reg reg, u32 data);
195 void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
196 		    u32 mask, u32 data);
197 u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
198 u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
199 
200 /*
201  *	R-Car DMA
202  */
203 int rsnd_dma_attach(struct rsnd_dai_stream *io,
204 		    struct rsnd_mod *mod, struct rsnd_mod **dma_mod);
205 int rsnd_dma_probe(struct rsnd_priv *priv);
206 struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
207 					  struct rsnd_mod *mod, char *name);
208 
209 /*
210  *	R-Car sound mod
211  */
212 enum rsnd_mod_type {
213 	RSND_MOD_AUDMAPP,
214 	RSND_MOD_AUDMA,
215 	RSND_MOD_DVC,
216 	RSND_MOD_MIX,
217 	RSND_MOD_CTU,
218 	RSND_MOD_CMD,
219 	RSND_MOD_SRC,
220 	RSND_MOD_SSIM3,		/* SSI multi 3 */
221 	RSND_MOD_SSIM2,		/* SSI multi 2 */
222 	RSND_MOD_SSIM1,		/* SSI multi 1 */
223 	RSND_MOD_SSIP,		/* SSI parent */
224 	RSND_MOD_SSI,
225 	RSND_MOD_SSIU,
226 	RSND_MOD_MAX,
227 };
228 
229 struct rsnd_mod_ops {
230 	char *name;
231 	struct dma_chan* (*dma_req)(struct rsnd_dai_stream *io,
232 				    struct rsnd_mod *mod);
233 	int (*probe)(struct rsnd_mod *mod,
234 		     struct rsnd_dai_stream *io,
235 		     struct rsnd_priv *priv);
236 	int (*remove)(struct rsnd_mod *mod,
237 		      struct rsnd_dai_stream *io,
238 		      struct rsnd_priv *priv);
239 	int (*init)(struct rsnd_mod *mod,
240 		    struct rsnd_dai_stream *io,
241 		    struct rsnd_priv *priv);
242 	int (*quit)(struct rsnd_mod *mod,
243 		    struct rsnd_dai_stream *io,
244 		    struct rsnd_priv *priv);
245 	int (*start)(struct rsnd_mod *mod,
246 		     struct rsnd_dai_stream *io,
247 		     struct rsnd_priv *priv);
248 	int (*stop)(struct rsnd_mod *mod,
249 		    struct rsnd_dai_stream *io,
250 		    struct rsnd_priv *priv);
251 	int (*irq)(struct rsnd_mod *mod,
252 		   struct rsnd_dai_stream *io,
253 		   struct rsnd_priv *priv, int enable);
254 	int (*pcm_new)(struct rsnd_mod *mod,
255 		       struct rsnd_dai_stream *io,
256 		       struct snd_soc_pcm_runtime *rtd);
257 	int (*hw_params)(struct rsnd_mod *mod,
258 			 struct rsnd_dai_stream *io,
259 			 struct snd_pcm_substream *substream,
260 			 struct snd_pcm_hw_params *hw_params);
261 	int (*fallback)(struct rsnd_mod *mod,
262 			struct rsnd_dai_stream *io,
263 			struct rsnd_priv *priv);
264 	int (*nolock_start)(struct rsnd_mod *mod,
265 		    struct rsnd_dai_stream *io,
266 		    struct rsnd_priv *priv);
267 	int (*nolock_stop)(struct rsnd_mod *mod,
268 		    struct rsnd_dai_stream *io,
269 		    struct rsnd_priv *priv);
270 };
271 
272 struct rsnd_dai_stream;
273 struct rsnd_mod {
274 	int id;
275 	enum rsnd_mod_type type;
276 	struct rsnd_mod_ops *ops;
277 	struct rsnd_priv *priv;
278 	struct clk *clk;
279 	u32 *(*get_status)(struct rsnd_dai_stream *io,
280 			   struct rsnd_mod *mod,
281 			   enum rsnd_mod_type type);
282 	u32 status;
283 };
284 /*
285  * status
286  *
287  * 0xH0000CBA
288  *
289  * A	0: nolock_start	1: nolock_stop
290  * B	0: init		1: quit
291  * C	0: start	1: stop
292  *
293  * H is always called (see __rsnd_mod_call)
294  * H	0: probe	1: remove
295  * H	0: pcm_new
296  * H	0: fallback
297  * H	0: hw_params
298  */
299 #define __rsnd_mod_shift_nolock_start	0
300 #define __rsnd_mod_shift_nolock_stop	0
301 #define __rsnd_mod_shift_init		4
302 #define __rsnd_mod_shift_quit		4
303 #define __rsnd_mod_shift_start		8
304 #define __rsnd_mod_shift_stop		8
305 #define __rsnd_mod_shift_probe		28 /* always called */
306 #define __rsnd_mod_shift_remove		28 /* always called */
307 #define __rsnd_mod_shift_irq		28 /* always called */
308 #define __rsnd_mod_shift_pcm_new	28 /* always called */
309 #define __rsnd_mod_shift_fallback	28 /* always called */
310 #define __rsnd_mod_shift_hw_params	28 /* always called */
311 
312 #define __rsnd_mod_add_probe		0
313 #define __rsnd_mod_add_remove		0
314 #define __rsnd_mod_add_nolock_start	 1
315 #define __rsnd_mod_add_nolock_stop	-1
316 #define __rsnd_mod_add_init		 1
317 #define __rsnd_mod_add_quit		-1
318 #define __rsnd_mod_add_start		 1
319 #define __rsnd_mod_add_stop		-1
320 #define __rsnd_mod_add_irq		0
321 #define __rsnd_mod_add_pcm_new		0
322 #define __rsnd_mod_add_fallback		0
323 #define __rsnd_mod_add_hw_params	0
324 
325 #define __rsnd_mod_call_probe		0
326 #define __rsnd_mod_call_remove		0
327 #define __rsnd_mod_call_init		0
328 #define __rsnd_mod_call_quit		1
329 #define __rsnd_mod_call_start		0
330 #define __rsnd_mod_call_stop		1
331 #define __rsnd_mod_call_irq		0
332 #define __rsnd_mod_call_pcm_new		0
333 #define __rsnd_mod_call_fallback	0
334 #define __rsnd_mod_call_hw_params	0
335 #define __rsnd_mod_call_nolock_start	0
336 #define __rsnd_mod_call_nolock_stop	1
337 
338 #define rsnd_mod_to_priv(mod) ((mod)->priv)
339 #define rsnd_mod_id(mod) ((mod) ? (mod)->id : -1)
340 #define rsnd_mod_power_on(mod)	clk_enable((mod)->clk)
341 #define rsnd_mod_power_off(mod)	clk_disable((mod)->clk)
342 #define rsnd_mod_get(ip)	(&(ip)->mod)
343 
344 int rsnd_mod_init(struct rsnd_priv *priv,
345 		  struct rsnd_mod *mod,
346 		  struct rsnd_mod_ops *ops,
347 		  struct clk *clk,
348 		  u32* (*get_status)(struct rsnd_dai_stream *io,
349 				     struct rsnd_mod *mod,
350 				     enum rsnd_mod_type type),
351 		  enum rsnd_mod_type type,
352 		  int id);
353 void rsnd_mod_quit(struct rsnd_mod *mod);
354 char *rsnd_mod_name(struct rsnd_mod *mod);
355 struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
356 				  struct rsnd_mod *mod);
357 void rsnd_mod_interrupt(struct rsnd_mod *mod,
358 			void (*callback)(struct rsnd_mod *mod,
359 					 struct rsnd_dai_stream *io));
360 u32 *rsnd_mod_get_status(struct rsnd_dai_stream *io,
361 			 struct rsnd_mod *mod,
362 			 enum rsnd_mod_type type);
363 struct rsnd_mod *rsnd_mod_next(int *iterator,
364 			       struct rsnd_dai_stream *io,
365 			       enum rsnd_mod_type *array,
366 			       int array_size);
367 #define for_each_rsnd_mod(iterator, pos, io)				\
368 	for (iterator = 0;						\
369 	     (pos = rsnd_mod_next(&iterator, io, NULL, 0));)
370 #define for_each_rsnd_mod_arrays(iterator, pos, io, array, size)	\
371 	for (iterator = 0;						\
372 	     (pos = rsnd_mod_next(&iterator, io, array, size));)
373 #define for_each_rsnd_mod_array(iterator, pos, io, array)		\
374 	for_each_rsnd_mod_arrays(iterator, pos, io, array, ARRAY_SIZE(array))
375 
376 void rsnd_parse_connect_common(struct rsnd_dai *rdai,
377 		struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id),
378 		struct device_node *node,
379 		struct device_node *playback,
380 		struct device_node *capture);
381 
382 void rsnd_set_slot(struct rsnd_dai *rdai,
383 		   int slots, int slots_total);
384 int rsnd_get_slot(struct rsnd_dai_stream *io);
385 int rsnd_get_slot_num(struct rsnd_dai_stream *io);
386 
387 int rsnd_runtime_channel_original(struct rsnd_dai_stream *io);
388 int rsnd_runtime_channel_after_ctu(struct rsnd_dai_stream *io);
389 int rsnd_runtime_channel_for_ssi(struct rsnd_dai_stream *io);
390 int rsnd_runtime_is_ssi_multi(struct rsnd_dai_stream *io);
391 int rsnd_runtime_is_ssi_tdm(struct rsnd_dai_stream *io);
392 
393 /*
394  * DT
395  */
396 #define rsnd_parse_of_node(priv, node)					\
397 	of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, node)
398 #define RSND_NODE_DAI	"rcar_sound,dai"
399 #define RSND_NODE_SSI	"rcar_sound,ssi"
400 #define RSND_NODE_SRC	"rcar_sound,src"
401 #define RSND_NODE_CTU	"rcar_sound,ctu"
402 #define RSND_NODE_MIX	"rcar_sound,mix"
403 #define RSND_NODE_DVC	"rcar_sound,dvc"
404 
405 /*
406  *	R-Car sound DAI
407  */
408 #define RSND_DAI_NAME_SIZE	16
409 struct rsnd_dai_stream {
410 	char name[RSND_DAI_NAME_SIZE];
411 	struct snd_pcm_substream *substream;
412 	struct rsnd_mod *mod[RSND_MOD_MAX];
413 	struct rsnd_dai_path_info *info; /* rcar_snd.h */
414 	struct rsnd_dai *rdai;
415 	u32 parent_ssi_status;
416 	int byte_pos;
417 	int period_pos;
418 	int byte_per_period;
419 	int next_period_byte;
420 };
421 #define rsnd_io_to_mod(io, i)	((i) < RSND_MOD_MAX ? (io)->mod[(i)] : NULL)
422 #define rsnd_io_to_mod_ssi(io)	rsnd_io_to_mod((io), RSND_MOD_SSI)
423 #define rsnd_io_to_mod_ssip(io)	rsnd_io_to_mod((io), RSND_MOD_SSIP)
424 #define rsnd_io_to_mod_src(io)	rsnd_io_to_mod((io), RSND_MOD_SRC)
425 #define rsnd_io_to_mod_ctu(io)	rsnd_io_to_mod((io), RSND_MOD_CTU)
426 #define rsnd_io_to_mod_mix(io)	rsnd_io_to_mod((io), RSND_MOD_MIX)
427 #define rsnd_io_to_mod_dvc(io)	rsnd_io_to_mod((io), RSND_MOD_DVC)
428 #define rsnd_io_to_mod_cmd(io)	rsnd_io_to_mod((io), RSND_MOD_CMD)
429 #define rsnd_io_to_rdai(io)	((io)->rdai)
430 #define rsnd_io_to_priv(io)	(rsnd_rdai_to_priv(rsnd_io_to_rdai(io)))
431 #define rsnd_io_is_play(io)	(&rsnd_io_to_rdai(io)->playback == io)
432 #define rsnd_io_to_runtime(io) ((io)->substream ? \
433 				(io)->substream->runtime : NULL)
434 int rsnd_io_is_working(struct rsnd_dai_stream *io);
435 
436 struct rsnd_dai {
437 	char name[RSND_DAI_NAME_SIZE];
438 	struct rsnd_dai_stream playback;
439 	struct rsnd_dai_stream capture;
440 	struct rsnd_priv *priv;
441 
442 	int slots;
443 	int slots_num;
444 
445 	unsigned int clk_master:1;
446 	unsigned int bit_clk_inv:1;
447 	unsigned int frm_clk_inv:1;
448 	unsigned int sys_delay:1;
449 	unsigned int data_alignment:1;
450 };
451 
452 #define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
453 #define rsnd_rdai_is_clk_master(rdai) ((rdai)->clk_master)
454 #define rsnd_rdai_to_priv(rdai) ((rdai)->priv)
455 #define for_each_rsnd_dai(rdai, priv, i)		\
456 	for (i = 0;					\
457 	     (i < rsnd_rdai_nr(priv)) &&		\
458 	     ((rdai) = rsnd_rdai_get(priv, i));		\
459 	     i++)
460 
461 struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id);
462 
463 bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
464 void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io);
465 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
466 int rsnd_dai_connect(struct rsnd_mod *mod,
467 		     struct rsnd_dai_stream *io,
468 		     enum rsnd_mod_type type);
469 #define rsnd_dai_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DAI)
470 
471 /*
472  *	R-Car Gen1/Gen2
473  */
474 int rsnd_gen_probe(struct rsnd_priv *priv);
475 void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
476 			       struct rsnd_mod *mod,
477 			       enum rsnd_reg reg);
478 phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id);
479 
480 /*
481  *	R-Car ADG
482  */
483 int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
484 int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
485 int rsnd_adg_probe(struct rsnd_priv *priv);
486 void rsnd_adg_remove(struct rsnd_priv *priv);
487 int rsnd_adg_set_src_timesel_gen2(struct rsnd_mod *src_mod,
488 				  struct rsnd_dai_stream *io,
489 				  unsigned int in_rate,
490 				  unsigned int out_rate);
491 int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *mod,
492 				 struct rsnd_dai_stream *io);
493 
494 /*
495  *	R-Car sound priv
496  */
497 struct rsnd_priv {
498 
499 	struct platform_device *pdev;
500 	spinlock_t lock;
501 	unsigned long flags;
502 #define RSND_GEN_MASK	(0xF << 0)
503 #define RSND_GEN1	(1 << 0)
504 #define RSND_GEN2	(2 << 0)
505 
506 	/*
507 	 * below value will be filled on rsnd_gen_probe()
508 	 */
509 	void *gen;
510 
511 	/*
512 	 * below value will be filled on rsnd_adg_probe()
513 	 */
514 	void *adg;
515 
516 	/*
517 	 * below value will be filled on rsnd_dma_probe()
518 	 */
519 	void *dma;
520 
521 	/*
522 	 * below value will be filled on rsnd_ssi_probe()
523 	 */
524 	void *ssi;
525 	int ssi_nr;
526 
527 	/*
528 	 * below value will be filled on rsnd_ssiu_probe()
529 	 */
530 	void *ssiu;
531 	int ssiu_nr;
532 
533 	/*
534 	 * below value will be filled on rsnd_src_probe()
535 	 */
536 	void *src;
537 	int src_nr;
538 
539 	/*
540 	 * below value will be filled on rsnd_ctu_probe()
541 	 */
542 	void *ctu;
543 	int ctu_nr;
544 
545 	/*
546 	 * below value will be filled on rsnd_mix_probe()
547 	 */
548 	void *mix;
549 	int mix_nr;
550 
551 	/*
552 	 * below value will be filled on rsnd_dvc_probe()
553 	 */
554 	void *dvc;
555 	int dvc_nr;
556 
557 	/*
558 	 * below value will be filled on rsnd_cmd_probe()
559 	 */
560 	void *cmd;
561 	int cmd_nr;
562 
563 	/*
564 	 * below value will be filled on rsnd_dai_probe()
565 	 */
566 	struct snd_soc_dai_driver *daidrv;
567 	struct rsnd_dai *rdai;
568 	int rdai_nr;
569 };
570 
571 #define rsnd_priv_to_pdev(priv)	((priv)->pdev)
572 #define rsnd_priv_to_dev(priv)	(&(rsnd_priv_to_pdev(priv)->dev))
573 
574 #define rsnd_is_gen1(priv)	(((priv)->flags & RSND_GEN_MASK) == RSND_GEN1)
575 #define rsnd_is_gen2(priv)	(((priv)->flags & RSND_GEN_MASK) == RSND_GEN2)
576 
577 /*
578  *	rsnd_kctrl
579  */
580 struct rsnd_kctrl_cfg {
581 	unsigned int max;
582 	unsigned int size;
583 	u32 *val;
584 	const char * const *texts;
585 	void (*update)(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
586 	struct rsnd_dai_stream *io;
587 	struct snd_card *card;
588 	struct snd_kcontrol *kctrl;
589 };
590 
591 #define RSND_MAX_CHANNELS	8
592 struct rsnd_kctrl_cfg_m {
593 	struct rsnd_kctrl_cfg cfg;
594 	u32 val[RSND_MAX_CHANNELS];
595 };
596 
597 struct rsnd_kctrl_cfg_s {
598 	struct rsnd_kctrl_cfg cfg;
599 	u32 val;
600 };
601 
602 void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg);
603 #define rsnd_kctrl_remove(_cfg)	_rsnd_kctrl_remove(&((_cfg).cfg))
604 
605 int rsnd_kctrl_new_m(struct rsnd_mod *mod,
606 		     struct rsnd_dai_stream *io,
607 		     struct snd_soc_pcm_runtime *rtd,
608 		     const unsigned char *name,
609 		     void (*update)(struct rsnd_dai_stream *io,
610 				    struct rsnd_mod *mod),
611 		     struct rsnd_kctrl_cfg_m *_cfg,
612 		     int ch_size,
613 		     u32 max);
614 int rsnd_kctrl_new_s(struct rsnd_mod *mod,
615 		     struct rsnd_dai_stream *io,
616 		     struct snd_soc_pcm_runtime *rtd,
617 		     const unsigned char *name,
618 		     void (*update)(struct rsnd_dai_stream *io,
619 				    struct rsnd_mod *mod),
620 		     struct rsnd_kctrl_cfg_s *_cfg,
621 		     u32 max);
622 int rsnd_kctrl_new_e(struct rsnd_mod *mod,
623 		     struct rsnd_dai_stream *io,
624 		     struct snd_soc_pcm_runtime *rtd,
625 		     const unsigned char *name,
626 		     struct rsnd_kctrl_cfg_s *_cfg,
627 		     void (*update)(struct rsnd_dai_stream *io,
628 				    struct rsnd_mod *mod),
629 		     const char * const *texts,
630 		     u32 max);
631 
632 /*
633  *	R-Car SSI
634  */
635 int rsnd_ssi_probe(struct rsnd_priv *priv);
636 void rsnd_ssi_remove(struct rsnd_priv *priv);
637 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
638 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
639 int rsnd_ssi_use_busif(struct rsnd_dai_stream *io);
640 u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io);
641 
642 #define rsnd_ssi_is_pin_sharing(io)	\
643 	__rsnd_ssi_is_pin_sharing(rsnd_io_to_mod_ssi(io))
644 int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
645 
646 #define rsnd_ssi_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSI)
647 void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
648 			    struct device_node *playback,
649 			    struct device_node *capture);
650 
651 /*
652  *	R-Car SSIU
653  */
654 int rsnd_ssiu_attach(struct rsnd_dai_stream *io,
655 		     struct rsnd_mod *mod);
656 int rsnd_ssiu_probe(struct rsnd_priv *priv);
657 void rsnd_ssiu_remove(struct rsnd_priv *priv);
658 
659 /*
660  *	R-Car SRC
661  */
662 int rsnd_src_probe(struct rsnd_priv *priv);
663 void rsnd_src_remove(struct rsnd_priv *priv);
664 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id);
665 
666 #define rsnd_src_get_in_rate(priv, io) rsnd_src_get_rate(priv, io, 1)
667 #define rsnd_src_get_out_rate(priv, io) rsnd_src_get_rate(priv, io, 0)
668 unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
669 			       struct rsnd_dai_stream *io,
670 			       int is_in);
671 
672 #define rsnd_src_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SRC)
673 #define rsnd_parse_connect_src(rdai, playback, capture)			\
674 	rsnd_parse_connect_common(rdai, rsnd_src_mod_get,		\
675 				  rsnd_src_of_node(rsnd_rdai_to_priv(rdai)), \
676 						   playback, capture)
677 
678 /*
679  *	R-Car CTU
680  */
681 int rsnd_ctu_probe(struct rsnd_priv *priv);
682 void rsnd_ctu_remove(struct rsnd_priv *priv);
683 int rsnd_ctu_converted_channel(struct rsnd_mod *mod);
684 struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id);
685 #define rsnd_ctu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_CTU)
686 #define rsnd_parse_connect_ctu(rdai, playback, capture)			\
687 	rsnd_parse_connect_common(rdai, rsnd_ctu_mod_get,		\
688 				  rsnd_ctu_of_node(rsnd_rdai_to_priv(rdai)), \
689 						   playback, capture)
690 
691 /*
692  *	R-Car MIX
693  */
694 int rsnd_mix_probe(struct rsnd_priv *priv);
695 void rsnd_mix_remove(struct rsnd_priv *priv);
696 struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id);
697 #define rsnd_mix_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_MIX)
698 #define rsnd_parse_connect_mix(rdai, playback, capture)			\
699 	rsnd_parse_connect_common(rdai, rsnd_mix_mod_get,		\
700 				  rsnd_mix_of_node(rsnd_rdai_to_priv(rdai)), \
701 						   playback, capture)
702 
703 /*
704  *	R-Car DVC
705  */
706 int rsnd_dvc_probe(struct rsnd_priv *priv);
707 void rsnd_dvc_remove(struct rsnd_priv *priv);
708 struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id);
709 #define rsnd_dvc_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DVC)
710 #define rsnd_parse_connect_dvc(rdai, playback, capture)			\
711 	rsnd_parse_connect_common(rdai, rsnd_dvc_mod_get,		\
712 				  rsnd_dvc_of_node(rsnd_rdai_to_priv(rdai)), \
713 						   playback, capture)
714 
715 /*
716  *	R-Car CMD
717  */
718 int rsnd_cmd_probe(struct rsnd_priv *priv);
719 void rsnd_cmd_remove(struct rsnd_priv *priv);
720 int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id);
721 struct rsnd_mod *rsnd_cmd_mod_get(struct rsnd_priv *priv, int id);
722 
723 #ifdef DEBUG
724 void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type);
725 #define rsnd_mod_confirm_ssi(mssi)	rsnd_mod_make_sure(mssi, RSND_MOD_SSI)
726 #define rsnd_mod_confirm_src(msrc)	rsnd_mod_make_sure(msrc, RSND_MOD_SRC)
727 #define rsnd_mod_confirm_dvc(mdvc)	rsnd_mod_make_sure(mdvc, RSND_MOD_DVC)
728 #else
729 #define rsnd_mod_confirm_ssi(mssi)
730 #define rsnd_mod_confirm_src(msrc)
731 #define rsnd_mod_confirm_dvc(mdvc)
732 #endif
733 
734 #endif
735