xref: /linux/sound/soc/renesas/rcar/rsnd.h (revision 79a1d390f879563119bf2848b621bc7eed228c7d)
1c087a94bSLad Prabhakar // SPDX-License-Identifier: GPL-2.0
2c087a94bSLad Prabhakar //
3c087a94bSLad Prabhakar // Renesas R-Car
4c087a94bSLad Prabhakar //
5c087a94bSLad Prabhakar // Copyright (C) 2013 Renesas Solutions Corp.
6c087a94bSLad Prabhakar // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7c087a94bSLad Prabhakar 
8c087a94bSLad Prabhakar #ifndef RSND_H
9c087a94bSLad Prabhakar #define RSND_H
10c087a94bSLad Prabhakar 
11c087a94bSLad Prabhakar #include <linux/clk.h>
12c087a94bSLad Prabhakar #include <linux/device.h>
13c087a94bSLad Prabhakar #include <linux/dma-mapping.h>
14c087a94bSLad Prabhakar #include <linux/io.h>
15c087a94bSLad Prabhakar #include <linux/list.h>
16c087a94bSLad Prabhakar #include <linux/module.h>
17c087a94bSLad Prabhakar #include <linux/of.h>
18c087a94bSLad Prabhakar #include <linux/sh_dma.h>
19c087a94bSLad Prabhakar #include <linux/workqueue.h>
20c087a94bSLad Prabhakar #include <sound/soc.h>
21c087a94bSLad Prabhakar #include <sound/pcm_params.h>
22c087a94bSLad Prabhakar 
23c087a94bSLad Prabhakar #define RSND_BASE_ADG	0
24c087a94bSLad Prabhakar #define RSND_BASE_SSI	1
25c087a94bSLad Prabhakar #define RSND_BASE_SSIU	2
26c087a94bSLad Prabhakar #define RSND_BASE_SCU	3	// for Gen2/Gen3
27c087a94bSLad Prabhakar #define RSND_BASE_SDMC	3	// for Gen4	reuse
28c087a94bSLad Prabhakar #define RSND_BASE_MAX	4
29c087a94bSLad Prabhakar 
30c087a94bSLad Prabhakar /*
31c087a94bSLad Prabhakar  *	pseudo register
32c087a94bSLad Prabhakar  *
33c087a94bSLad Prabhakar  * The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different.
34c087a94bSLad Prabhakar  * This driver uses pseudo register in order to hide it.
35c087a94bSLad Prabhakar  * see gen1/gen2 for detail
36c087a94bSLad Prabhakar  */
37c087a94bSLad Prabhakar enum rsnd_reg {
38c087a94bSLad Prabhakar 	/* SCU (MIX/CTU/DVC) */
39c087a94bSLad Prabhakar 	SRC_I_BUSIF_MODE,
40c087a94bSLad Prabhakar 	SRC_O_BUSIF_MODE,
41c087a94bSLad Prabhakar 	SRC_ROUTE_MODE0,
42c087a94bSLad Prabhakar 	SRC_SWRSR,
43c087a94bSLad Prabhakar 	SRC_SRCIR,
44c087a94bSLad Prabhakar 	SRC_ADINR,
45c087a94bSLad Prabhakar 	SRC_IFSCR,
46c087a94bSLad Prabhakar 	SRC_IFSVR,
47c087a94bSLad Prabhakar 	SRC_SRCCR,
48c087a94bSLad Prabhakar 	SRC_CTRL,
49c087a94bSLad Prabhakar 	SRC_BSDSR,
50c087a94bSLad Prabhakar 	SRC_BSISR,
51c087a94bSLad Prabhakar 	SRC_INT_ENABLE0,
52c087a94bSLad Prabhakar 	SRC_BUSIF_DALIGN,
53c087a94bSLad Prabhakar 	SRCIN_TIMSEL0,
54c087a94bSLad Prabhakar 	SRCIN_TIMSEL1,
55c087a94bSLad Prabhakar 	SRCIN_TIMSEL2,
56c087a94bSLad Prabhakar 	SRCIN_TIMSEL3,
57c087a94bSLad Prabhakar 	SRCIN_TIMSEL4,
58c087a94bSLad Prabhakar 	SRCOUT_TIMSEL0,
59c087a94bSLad Prabhakar 	SRCOUT_TIMSEL1,
60c087a94bSLad Prabhakar 	SRCOUT_TIMSEL2,
61c087a94bSLad Prabhakar 	SRCOUT_TIMSEL3,
62c087a94bSLad Prabhakar 	SRCOUT_TIMSEL4,
63c087a94bSLad Prabhakar 	SCU_SYS_STATUS0,
64c087a94bSLad Prabhakar 	SCU_SYS_STATUS1,
65c087a94bSLad Prabhakar 	SCU_SYS_INT_EN0,
66c087a94bSLad Prabhakar 	SCU_SYS_INT_EN1,
67c087a94bSLad Prabhakar 	CMD_CTRL,
68c087a94bSLad Prabhakar 	CMD_BUSIF_MODE,
69c087a94bSLad Prabhakar 	CMD_BUSIF_DALIGN,
70c087a94bSLad Prabhakar 	CMD_ROUTE_SLCT,
71c087a94bSLad Prabhakar 	CMDOUT_TIMSEL,
72c087a94bSLad Prabhakar 	CTU_SWRSR,
73c087a94bSLad Prabhakar 	CTU_CTUIR,
74c087a94bSLad Prabhakar 	CTU_ADINR,
75c087a94bSLad Prabhakar 	CTU_CPMDR,
76c087a94bSLad Prabhakar 	CTU_SCMDR,
77c087a94bSLad Prabhakar 	CTU_SV00R,
78c087a94bSLad Prabhakar 	CTU_SV01R,
79c087a94bSLad Prabhakar 	CTU_SV02R,
80c087a94bSLad Prabhakar 	CTU_SV03R,
81c087a94bSLad Prabhakar 	CTU_SV04R,
82c087a94bSLad Prabhakar 	CTU_SV05R,
83c087a94bSLad Prabhakar 	CTU_SV06R,
84c087a94bSLad Prabhakar 	CTU_SV07R,
85c087a94bSLad Prabhakar 	CTU_SV10R,
86c087a94bSLad Prabhakar 	CTU_SV11R,
87c087a94bSLad Prabhakar 	CTU_SV12R,
88c087a94bSLad Prabhakar 	CTU_SV13R,
89c087a94bSLad Prabhakar 	CTU_SV14R,
90c087a94bSLad Prabhakar 	CTU_SV15R,
91c087a94bSLad Prabhakar 	CTU_SV16R,
92c087a94bSLad Prabhakar 	CTU_SV17R,
93c087a94bSLad Prabhakar 	CTU_SV20R,
94c087a94bSLad Prabhakar 	CTU_SV21R,
95c087a94bSLad Prabhakar 	CTU_SV22R,
96c087a94bSLad Prabhakar 	CTU_SV23R,
97c087a94bSLad Prabhakar 	CTU_SV24R,
98c087a94bSLad Prabhakar 	CTU_SV25R,
99c087a94bSLad Prabhakar 	CTU_SV26R,
100c087a94bSLad Prabhakar 	CTU_SV27R,
101c087a94bSLad Prabhakar 	CTU_SV30R,
102c087a94bSLad Prabhakar 	CTU_SV31R,
103c087a94bSLad Prabhakar 	CTU_SV32R,
104c087a94bSLad Prabhakar 	CTU_SV33R,
105c087a94bSLad Prabhakar 	CTU_SV34R,
106c087a94bSLad Prabhakar 	CTU_SV35R,
107c087a94bSLad Prabhakar 	CTU_SV36R,
108c087a94bSLad Prabhakar 	CTU_SV37R,
109c087a94bSLad Prabhakar 	MIX_SWRSR,
110c087a94bSLad Prabhakar 	MIX_MIXIR,
111c087a94bSLad Prabhakar 	MIX_ADINR,
112c087a94bSLad Prabhakar 	MIX_MIXMR,
113c087a94bSLad Prabhakar 	MIX_MVPDR,
114c087a94bSLad Prabhakar 	MIX_MDBAR,
115c087a94bSLad Prabhakar 	MIX_MDBBR,
116c087a94bSLad Prabhakar 	MIX_MDBCR,
117c087a94bSLad Prabhakar 	MIX_MDBDR,
118c087a94bSLad Prabhakar 	MIX_MDBER,
119c087a94bSLad Prabhakar 	DVC_SWRSR,
120c087a94bSLad Prabhakar 	DVC_DVUIR,
121c087a94bSLad Prabhakar 	DVC_ADINR,
122c087a94bSLad Prabhakar 	DVC_DVUCR,
123c087a94bSLad Prabhakar 	DVC_ZCMCR,
124c087a94bSLad Prabhakar 	DVC_VOL0R,
125c087a94bSLad Prabhakar 	DVC_VOL1R,
126c087a94bSLad Prabhakar 	DVC_VOL2R,
127c087a94bSLad Prabhakar 	DVC_VOL3R,
128c087a94bSLad Prabhakar 	DVC_VOL4R,
129c087a94bSLad Prabhakar 	DVC_VOL5R,
130c087a94bSLad Prabhakar 	DVC_VOL6R,
131c087a94bSLad Prabhakar 	DVC_VOL7R,
132c087a94bSLad Prabhakar 	DVC_DVUER,
133c087a94bSLad Prabhakar 	DVC_VRCTR,
134c087a94bSLad Prabhakar 	DVC_VRPDR,
135c087a94bSLad Prabhakar 	DVC_VRDBR,
136c087a94bSLad Prabhakar 
137c087a94bSLad Prabhakar 	/* ADG */
138c087a94bSLad Prabhakar 	BRRA,
139c087a94bSLad Prabhakar 	BRRB,
140c087a94bSLad Prabhakar 	BRGCKR,
141c087a94bSLad Prabhakar 	DIV_EN,
142c087a94bSLad Prabhakar 	AUDIO_CLK_SEL0,
143c087a94bSLad Prabhakar 	AUDIO_CLK_SEL1,
144c087a94bSLad Prabhakar 	AUDIO_CLK_SEL2,
145c087a94bSLad Prabhakar 
146c087a94bSLad Prabhakar 	/* SSIU */
147c087a94bSLad Prabhakar 	SSI_MODE,
148c087a94bSLad Prabhakar 	SSI_MODE0,
149c087a94bSLad Prabhakar 	SSI_MODE1,
150c087a94bSLad Prabhakar 	SSI_MODE2,
151c087a94bSLad Prabhakar 	SSI_CONTROL,
152c087a94bSLad Prabhakar 	SSI_CTRL,
153c087a94bSLad Prabhakar 	SSI_BUSIF0_MODE,
154c087a94bSLad Prabhakar 	SSI_BUSIF1_MODE,
155c087a94bSLad Prabhakar 	SSI_BUSIF2_MODE,
156c087a94bSLad Prabhakar 	SSI_BUSIF3_MODE,
157c087a94bSLad Prabhakar 	SSI_BUSIF4_MODE,
158c087a94bSLad Prabhakar 	SSI_BUSIF5_MODE,
159c087a94bSLad Prabhakar 	SSI_BUSIF6_MODE,
160c087a94bSLad Prabhakar 	SSI_BUSIF7_MODE,
161c087a94bSLad Prabhakar 	SSI_BUSIF0_ADINR,
162c087a94bSLad Prabhakar 	SSI_BUSIF1_ADINR,
163c087a94bSLad Prabhakar 	SSI_BUSIF2_ADINR,
164c087a94bSLad Prabhakar 	SSI_BUSIF3_ADINR,
165c087a94bSLad Prabhakar 	SSI_BUSIF4_ADINR,
166c087a94bSLad Prabhakar 	SSI_BUSIF5_ADINR,
167c087a94bSLad Prabhakar 	SSI_BUSIF6_ADINR,
168c087a94bSLad Prabhakar 	SSI_BUSIF7_ADINR,
169c087a94bSLad Prabhakar 	SSI_BUSIF0_DALIGN,
170c087a94bSLad Prabhakar 	SSI_BUSIF1_DALIGN,
171c087a94bSLad Prabhakar 	SSI_BUSIF2_DALIGN,
172c087a94bSLad Prabhakar 	SSI_BUSIF3_DALIGN,
173c087a94bSLad Prabhakar 	SSI_BUSIF4_DALIGN,
174c087a94bSLad Prabhakar 	SSI_BUSIF5_DALIGN,
175c087a94bSLad Prabhakar 	SSI_BUSIF6_DALIGN,
176c087a94bSLad Prabhakar 	SSI_BUSIF7_DALIGN,
177c087a94bSLad Prabhakar 	SSI_INT_ENABLE,
178c087a94bSLad Prabhakar 	SSI_SYS_STATUS0,
179c087a94bSLad Prabhakar 	SSI_SYS_STATUS1,
180c087a94bSLad Prabhakar 	SSI_SYS_STATUS2,
181c087a94bSLad Prabhakar 	SSI_SYS_STATUS3,
182c087a94bSLad Prabhakar 	SSI_SYS_STATUS4,
183c087a94bSLad Prabhakar 	SSI_SYS_STATUS5,
184c087a94bSLad Prabhakar 	SSI_SYS_STATUS6,
185c087a94bSLad Prabhakar 	SSI_SYS_STATUS7,
186c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE0,
187c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE1,
188c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE2,
189c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE3,
190c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE4,
191c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE5,
192c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE6,
193c087a94bSLad Prabhakar 	SSI_SYS_INT_ENABLE7,
194c087a94bSLad Prabhakar 	HDMI0_SEL,
195c087a94bSLad Prabhakar 	HDMI1_SEL,
196c087a94bSLad Prabhakar 	SSI9_BUSIF0_MODE,
197c087a94bSLad Prabhakar 	SSI9_BUSIF1_MODE,
198c087a94bSLad Prabhakar 	SSI9_BUSIF2_MODE,
199c087a94bSLad Prabhakar 	SSI9_BUSIF3_MODE,
200c087a94bSLad Prabhakar 	SSI9_BUSIF4_MODE,
201c087a94bSLad Prabhakar 	SSI9_BUSIF5_MODE,
202c087a94bSLad Prabhakar 	SSI9_BUSIF6_MODE,
203c087a94bSLad Prabhakar 	SSI9_BUSIF7_MODE,
204c087a94bSLad Prabhakar 	SSI9_BUSIF0_ADINR,
205c087a94bSLad Prabhakar 	SSI9_BUSIF1_ADINR,
206c087a94bSLad Prabhakar 	SSI9_BUSIF2_ADINR,
207c087a94bSLad Prabhakar 	SSI9_BUSIF3_ADINR,
208c087a94bSLad Prabhakar 	SSI9_BUSIF4_ADINR,
209c087a94bSLad Prabhakar 	SSI9_BUSIF5_ADINR,
210c087a94bSLad Prabhakar 	SSI9_BUSIF6_ADINR,
211c087a94bSLad Prabhakar 	SSI9_BUSIF7_ADINR,
212c087a94bSLad Prabhakar 	SSI9_BUSIF0_DALIGN,
213c087a94bSLad Prabhakar 	SSI9_BUSIF1_DALIGN,
214c087a94bSLad Prabhakar 	SSI9_BUSIF2_DALIGN,
215c087a94bSLad Prabhakar 	SSI9_BUSIF3_DALIGN,
216c087a94bSLad Prabhakar 	SSI9_BUSIF4_DALIGN,
217c087a94bSLad Prabhakar 	SSI9_BUSIF5_DALIGN,
218c087a94bSLad Prabhakar 	SSI9_BUSIF6_DALIGN,
219c087a94bSLad Prabhakar 	SSI9_BUSIF7_DALIGN,
220c087a94bSLad Prabhakar 
221c087a94bSLad Prabhakar 	/* SSI */
222c087a94bSLad Prabhakar 	SSICR,
223c087a94bSLad Prabhakar 	SSISR,
224c087a94bSLad Prabhakar 	SSITDR,
225c087a94bSLad Prabhakar 	SSIRDR,
226c087a94bSLad Prabhakar 	SSIWSR,
227c087a94bSLad Prabhakar 
228c087a94bSLad Prabhakar 	REG_MAX,
229c087a94bSLad Prabhakar };
230c087a94bSLad Prabhakar #define SRCIN_TIMSEL(i)		(SRCIN_TIMSEL0 + (i))
231c087a94bSLad Prabhakar #define SRCOUT_TIMSEL(i)	(SRCOUT_TIMSEL0 + (i))
232c087a94bSLad Prabhakar #define CTU_SVxxR(i, j)		(CTU_SV00R + (i * 8) + (j))
233c087a94bSLad Prabhakar #define DVC_VOLxR(i)		(DVC_VOL0R + (i))
234c087a94bSLad Prabhakar #define AUDIO_CLK_SEL(i)	(AUDIO_CLK_SEL0 + (i))
235c087a94bSLad Prabhakar #define SSI_BUSIF_MODE(i)	(SSI_BUSIF0_MODE + (i))
236c087a94bSLad Prabhakar #define SSI_BUSIF_ADINR(i)	(SSI_BUSIF0_ADINR + (i))
237c087a94bSLad Prabhakar #define SSI_BUSIF_DALIGN(i)	(SSI_BUSIF0_DALIGN + (i))
238c087a94bSLad Prabhakar #define SSI9_BUSIF_MODE(i)	(SSI9_BUSIF0_MODE + (i))
239c087a94bSLad Prabhakar #define SSI9_BUSIF_ADINR(i)	(SSI9_BUSIF0_ADINR + (i))
240c087a94bSLad Prabhakar #define SSI9_BUSIF_DALIGN(i)	(SSI9_BUSIF0_DALIGN + (i))
241c087a94bSLad Prabhakar #define SSI_SYS_STATUS(i)	(SSI_SYS_STATUS0 + (i))
242c087a94bSLad Prabhakar #define SSI_SYS_INT_ENABLE(i) (SSI_SYS_INT_ENABLE0 + (i))
243c087a94bSLad Prabhakar 
244c087a94bSLad Prabhakar 
245c087a94bSLad Prabhakar struct rsnd_priv;
246c087a94bSLad Prabhakar struct rsnd_mod;
247c087a94bSLad Prabhakar struct rsnd_dai;
248c087a94bSLad Prabhakar struct rsnd_dai_stream;
249c087a94bSLad Prabhakar 
250c087a94bSLad Prabhakar /*
251c087a94bSLad Prabhakar  *	R-Car basic functions
252c087a94bSLad Prabhakar  */
253c087a94bSLad Prabhakar u32 rsnd_mod_read(struct rsnd_mod *mod, enum rsnd_reg reg);
254c087a94bSLad Prabhakar void rsnd_mod_write(struct rsnd_mod *mod, enum rsnd_reg reg, u32 data);
255c087a94bSLad Prabhakar void rsnd_mod_bset(struct rsnd_mod *mod, enum rsnd_reg reg, u32 mask, u32 data);
256c087a94bSLad Prabhakar u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
257c087a94bSLad Prabhakar u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
258c087a94bSLad Prabhakar u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
259c087a94bSLad Prabhakar 
260c087a94bSLad Prabhakar /*
261c087a94bSLad Prabhakar  *	R-Car DMA
262c087a94bSLad Prabhakar  */
263c087a94bSLad Prabhakar int rsnd_dma_attach(struct rsnd_dai_stream *io,
264c087a94bSLad Prabhakar 		    struct rsnd_mod *mod, struct rsnd_mod **dma_mod);
265c087a94bSLad Prabhakar int rsnd_dma_probe(struct rsnd_priv *priv);
266c087a94bSLad Prabhakar struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node, char *name,
267c087a94bSLad Prabhakar 					  struct rsnd_mod *mod, char *x);
268c087a94bSLad Prabhakar 
269c087a94bSLad Prabhakar /*
270c087a94bSLad Prabhakar  *	R-Car sound mod
271c087a94bSLad Prabhakar  */
272c087a94bSLad Prabhakar enum rsnd_mod_type {
273c087a94bSLad Prabhakar 	RSND_MOD_AUDMAPP,
274c087a94bSLad Prabhakar 	RSND_MOD_AUDMA,
275c087a94bSLad Prabhakar 	RSND_MOD_DVC,
276c087a94bSLad Prabhakar 	RSND_MOD_MIX,
277c087a94bSLad Prabhakar 	RSND_MOD_CTU,
278c087a94bSLad Prabhakar 	RSND_MOD_CMD,
279c087a94bSLad Prabhakar 	RSND_MOD_SRC,
280c087a94bSLad Prabhakar 	RSND_MOD_SSIM3,		/* SSI multi 3 */
281c087a94bSLad Prabhakar 	RSND_MOD_SSIM2,		/* SSI multi 2 */
282c087a94bSLad Prabhakar 	RSND_MOD_SSIM1,		/* SSI multi 1 */
283c087a94bSLad Prabhakar 	RSND_MOD_SSIP,		/* SSI parent */
284c087a94bSLad Prabhakar 	RSND_MOD_SSI,
285c087a94bSLad Prabhakar 	RSND_MOD_SSIU,
286c087a94bSLad Prabhakar 	RSND_MOD_MAX,
287c087a94bSLad Prabhakar };
288c087a94bSLad Prabhakar 
289c087a94bSLad Prabhakar struct rsnd_mod_ops {
290c087a94bSLad Prabhakar 	char *name;
291c087a94bSLad Prabhakar 	struct dma_chan* (*dma_req)(struct rsnd_dai_stream *io,
292c087a94bSLad Prabhakar 				    struct rsnd_mod *mod);
293c087a94bSLad Prabhakar 	int (*probe)(struct rsnd_mod *mod,
294c087a94bSLad Prabhakar 		     struct rsnd_dai_stream *io,
295c087a94bSLad Prabhakar 		     struct rsnd_priv *priv);
296c087a94bSLad Prabhakar 	int (*remove)(struct rsnd_mod *mod,
297c087a94bSLad Prabhakar 		      struct rsnd_dai_stream *io,
298c087a94bSLad Prabhakar 		      struct rsnd_priv *priv);
299c087a94bSLad Prabhakar 	int (*init)(struct rsnd_mod *mod,
300c087a94bSLad Prabhakar 		    struct rsnd_dai_stream *io,
301c087a94bSLad Prabhakar 		    struct rsnd_priv *priv);
302c087a94bSLad Prabhakar 	int (*quit)(struct rsnd_mod *mod,
303c087a94bSLad Prabhakar 		    struct rsnd_dai_stream *io,
304c087a94bSLad Prabhakar 		    struct rsnd_priv *priv);
305c087a94bSLad Prabhakar 	int (*start)(struct rsnd_mod *mod,
306c087a94bSLad Prabhakar 		     struct rsnd_dai_stream *io,
307c087a94bSLad Prabhakar 		     struct rsnd_priv *priv);
308c087a94bSLad Prabhakar 	int (*stop)(struct rsnd_mod *mod,
309c087a94bSLad Prabhakar 		    struct rsnd_dai_stream *io,
310c087a94bSLad Prabhakar 		    struct rsnd_priv *priv);
311c087a94bSLad Prabhakar 	int (*irq)(struct rsnd_mod *mod,
312c087a94bSLad Prabhakar 		   struct rsnd_dai_stream *io,
313c087a94bSLad Prabhakar 		   struct rsnd_priv *priv, int enable);
314c087a94bSLad Prabhakar 	int (*pcm_new)(struct rsnd_mod *mod,
315c087a94bSLad Prabhakar 		       struct rsnd_dai_stream *io,
316c087a94bSLad Prabhakar 		       struct snd_soc_pcm_runtime *rtd);
317c087a94bSLad Prabhakar 	int (*hw_params)(struct rsnd_mod *mod,
318c087a94bSLad Prabhakar 			 struct rsnd_dai_stream *io,
319c087a94bSLad Prabhakar 			 struct snd_pcm_substream *substream,
320c087a94bSLad Prabhakar 			 struct snd_pcm_hw_params *hw_params);
321c087a94bSLad Prabhakar 	int (*pointer)(struct rsnd_mod *mod,
322c087a94bSLad Prabhakar 		       struct rsnd_dai_stream *io,
323c087a94bSLad Prabhakar 		       snd_pcm_uframes_t *pointer);
324c087a94bSLad Prabhakar 	int (*fallback)(struct rsnd_mod *mod,
325c087a94bSLad Prabhakar 			struct rsnd_dai_stream *io,
326c087a94bSLad Prabhakar 			struct rsnd_priv *priv);
327c087a94bSLad Prabhakar 	int (*prepare)(struct rsnd_mod *mod,
328c087a94bSLad Prabhakar 		       struct rsnd_dai_stream *io,
329c087a94bSLad Prabhakar 		       struct rsnd_priv *priv);
330c087a94bSLad Prabhakar 	int (*cleanup)(struct rsnd_mod *mod,
331c087a94bSLad Prabhakar 		       struct rsnd_dai_stream *io,
332c087a94bSLad Prabhakar 		       struct rsnd_priv *priv);
333c087a94bSLad Prabhakar 	int (*hw_free)(struct rsnd_mod *mod,
334c087a94bSLad Prabhakar 		       struct rsnd_dai_stream *io,
335c087a94bSLad Prabhakar 		       struct snd_pcm_substream *substream);
336c087a94bSLad Prabhakar 	u32 *(*get_status)(struct rsnd_mod *mod,
337c087a94bSLad Prabhakar 			   struct rsnd_dai_stream *io,
338c087a94bSLad Prabhakar 			   enum rsnd_mod_type type);
339c087a94bSLad Prabhakar 	int (*id)(struct rsnd_mod *mod);
340c087a94bSLad Prabhakar 	int (*id_sub)(struct rsnd_mod *mod);
341c087a94bSLad Prabhakar 	int (*id_cmd)(struct rsnd_mod *mod);
342c087a94bSLad Prabhakar 
343c087a94bSLad Prabhakar #ifdef CONFIG_DEBUG_FS
344c087a94bSLad Prabhakar 	void (*debug_info)(struct seq_file *m,
345c087a94bSLad Prabhakar 			   struct rsnd_dai_stream *io, struct rsnd_mod *mod);
346c087a94bSLad Prabhakar #endif
347c087a94bSLad Prabhakar };
348c087a94bSLad Prabhakar 
349c087a94bSLad Prabhakar struct rsnd_dai_stream;
350c087a94bSLad Prabhakar struct rsnd_mod {
351c087a94bSLad Prabhakar 	int id;
352c087a94bSLad Prabhakar 	enum rsnd_mod_type type;
353c087a94bSLad Prabhakar 	struct rsnd_mod_ops *ops;
354c087a94bSLad Prabhakar 	struct rsnd_priv *priv;
355c087a94bSLad Prabhakar 	struct clk *clk;
356c087a94bSLad Prabhakar 	u32 status;
357c087a94bSLad Prabhakar };
358c087a94bSLad Prabhakar /*
359c087a94bSLad Prabhakar  * status
360c087a94bSLad Prabhakar  *
361c087a94bSLad Prabhakar  * 0xH000DCB0
362c087a94bSLad Prabhakar  *
363c087a94bSLad Prabhakar  * B	0: init		1: quit
364c087a94bSLad Prabhakar  * C	0: start	1: stop
365c087a94bSLad Prabhakar  * D	0: hw_params	1: hw_free
366c087a94bSLad Prabhakar  *
367c087a94bSLad Prabhakar  * H is always called (see __rsnd_mod_call)
368c087a94bSLad Prabhakar  */
369c087a94bSLad Prabhakar #define __rsnd_mod_shift_init		4
370c087a94bSLad Prabhakar #define __rsnd_mod_shift_quit		4
371c087a94bSLad Prabhakar #define __rsnd_mod_shift_start		8
372c087a94bSLad Prabhakar #define __rsnd_mod_shift_stop		8
373c087a94bSLad Prabhakar #define __rsnd_mod_shift_hw_params	12
374c087a94bSLad Prabhakar #define __rsnd_mod_shift_hw_free	12
375c087a94bSLad Prabhakar #define __rsnd_mod_shift_probe		28 /* always called */
376c087a94bSLad Prabhakar #define __rsnd_mod_shift_remove		28 /* always called */
377c087a94bSLad Prabhakar #define __rsnd_mod_shift_irq		28 /* always called */
378c087a94bSLad Prabhakar #define __rsnd_mod_shift_pcm_new	28 /* always called */
379c087a94bSLad Prabhakar #define __rsnd_mod_shift_fallback	28 /* always called */
380c087a94bSLad Prabhakar #define __rsnd_mod_shift_pointer	28 /* always called */
381c087a94bSLad Prabhakar #define __rsnd_mod_shift_prepare	28 /* always called */
382c087a94bSLad Prabhakar #define __rsnd_mod_shift_cleanup	28 /* always called */
383c087a94bSLad Prabhakar 
384c087a94bSLad Prabhakar #define __rsnd_mod_add_probe		0
385c087a94bSLad Prabhakar #define __rsnd_mod_add_remove		0
386c087a94bSLad Prabhakar #define __rsnd_mod_add_prepare		0
387c087a94bSLad Prabhakar #define __rsnd_mod_add_cleanup		0
388c087a94bSLad Prabhakar #define __rsnd_mod_add_init		 1 /* needs protect */
389c087a94bSLad Prabhakar #define __rsnd_mod_add_quit		-1 /* needs protect */
390c087a94bSLad Prabhakar #define __rsnd_mod_add_start		 1 /* needs protect */
391c087a94bSLad Prabhakar #define __rsnd_mod_add_stop		-1 /* needs protect */
392c087a94bSLad Prabhakar #define __rsnd_mod_add_hw_params	 1 /* needs protect */
393c087a94bSLad Prabhakar #define __rsnd_mod_add_hw_free		-1 /* needs protect */
394c087a94bSLad Prabhakar #define __rsnd_mod_add_irq		0
395c087a94bSLad Prabhakar #define __rsnd_mod_add_pcm_new		0
396c087a94bSLad Prabhakar #define __rsnd_mod_add_fallback		0
397c087a94bSLad Prabhakar #define __rsnd_mod_add_pointer		0
398c087a94bSLad Prabhakar 
399c087a94bSLad Prabhakar #define __rsnd_mod_call_probe		0
400c087a94bSLad Prabhakar #define __rsnd_mod_call_remove		0
401c087a94bSLad Prabhakar #define __rsnd_mod_call_prepare		0
402c087a94bSLad Prabhakar #define __rsnd_mod_call_cleanup		0
403c087a94bSLad Prabhakar #define __rsnd_mod_call_init		0 /* needs protect */
404c087a94bSLad Prabhakar #define __rsnd_mod_call_quit		1 /* needs protect */
405c087a94bSLad Prabhakar #define __rsnd_mod_call_start		0 /* needs protect */
406c087a94bSLad Prabhakar #define __rsnd_mod_call_stop		1 /* needs protect */
407c087a94bSLad Prabhakar #define __rsnd_mod_call_hw_params	0 /* needs protect */
408c087a94bSLad Prabhakar #define __rsnd_mod_call_hw_free		1 /* needs protect */
409c087a94bSLad Prabhakar #define __rsnd_mod_call_irq		0
410c087a94bSLad Prabhakar #define __rsnd_mod_call_pcm_new		0
411c087a94bSLad Prabhakar #define __rsnd_mod_call_fallback	0
412c087a94bSLad Prabhakar #define __rsnd_mod_call_pointer		0
413c087a94bSLad Prabhakar 
414c087a94bSLad Prabhakar #define rsnd_mod_to_priv(mod)	((mod)->priv)
415c087a94bSLad Prabhakar #define rsnd_mod_power_on(mod)	clk_enable((mod)->clk)
416c087a94bSLad Prabhakar #define rsnd_mod_power_off(mod)	clk_disable((mod)->clk)
417c087a94bSLad Prabhakar #define rsnd_mod_get(ip)	(&(ip)->mod)
418c087a94bSLad Prabhakar 
419c087a94bSLad Prabhakar int rsnd_mod_init(struct rsnd_priv *priv,
420c087a94bSLad Prabhakar 		  struct rsnd_mod *mod,
421c087a94bSLad Prabhakar 		  struct rsnd_mod_ops *ops,
422c087a94bSLad Prabhakar 		  struct clk *clk,
423c087a94bSLad Prabhakar 		  enum rsnd_mod_type type,
424c087a94bSLad Prabhakar 		  int id);
425c087a94bSLad Prabhakar void rsnd_mod_quit(struct rsnd_mod *mod);
426c087a94bSLad Prabhakar struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
427c087a94bSLad Prabhakar 				  struct rsnd_mod *mod);
428c087a94bSLad Prabhakar void rsnd_mod_interrupt(struct rsnd_mod *mod,
429c087a94bSLad Prabhakar 			void (*callback)(struct rsnd_mod *mod,
430c087a94bSLad Prabhakar 					 struct rsnd_dai_stream *io));
431c087a94bSLad Prabhakar u32 *rsnd_mod_get_status(struct rsnd_mod *mod,
432c087a94bSLad Prabhakar 			 struct rsnd_dai_stream *io,
433c087a94bSLad Prabhakar 			 enum rsnd_mod_type type);
434c087a94bSLad Prabhakar int rsnd_mod_id(struct rsnd_mod *mod);
435c087a94bSLad Prabhakar int rsnd_mod_id_raw(struct rsnd_mod *mod);
436c087a94bSLad Prabhakar int rsnd_mod_id_sub(struct rsnd_mod *mod);
437c087a94bSLad Prabhakar char *rsnd_mod_name(struct rsnd_mod *mod);
438c087a94bSLad Prabhakar struct rsnd_mod *rsnd_mod_next(int *iterator,
439c087a94bSLad Prabhakar 			       struct rsnd_dai_stream *io,
440c087a94bSLad Prabhakar 			       enum rsnd_mod_type *array,
441c087a94bSLad Prabhakar 			       int array_size);
442c087a94bSLad Prabhakar #define for_each_rsnd_mod(iterator, pos, io)				\
443c087a94bSLad Prabhakar 	for (iterator = 0;						\
444c087a94bSLad Prabhakar 	     (pos = rsnd_mod_next(&iterator, io, NULL, 0)); iterator++)
445c087a94bSLad Prabhakar #define for_each_rsnd_mod_arrays(iterator, pos, io, array, size)	\
446c087a94bSLad Prabhakar 	for (iterator = 0;						\
447c087a94bSLad Prabhakar 	     (pos = rsnd_mod_next(&iterator, io, array, size)); iterator++)
448c087a94bSLad Prabhakar #define for_each_rsnd_mod_array(iterator, pos, io, array)		\
449c087a94bSLad Prabhakar 	for_each_rsnd_mod_arrays(iterator, pos, io, array, ARRAY_SIZE(array))
450c087a94bSLad Prabhakar 
451c087a94bSLad Prabhakar void rsnd_parse_connect_common(struct rsnd_dai *rdai, char *name,
452c087a94bSLad Prabhakar 		struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id),
453c087a94bSLad Prabhakar 		struct device_node *node,
454c087a94bSLad Prabhakar 		struct device_node *playback,
455c087a94bSLad Prabhakar 		struct device_node *capture);
456c087a94bSLad Prabhakar int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name);
457c087a94bSLad Prabhakar int rsnd_node_fixed_index(struct device *dev, struct device_node *node, char *name, int idx);
458c087a94bSLad Prabhakar 
459c087a94bSLad Prabhakar int rsnd_channel_normalization(int chan);
460c087a94bSLad Prabhakar #define rsnd_runtime_channel_original(io) \
461c087a94bSLad Prabhakar 	rsnd_runtime_channel_original_with_params(io, NULL)
462c087a94bSLad Prabhakar int rsnd_runtime_channel_original_with_params(struct rsnd_dai_stream *io,
463c087a94bSLad Prabhakar 				struct snd_pcm_hw_params *params);
464c087a94bSLad Prabhakar #define rsnd_runtime_channel_after_ctu(io)			\
465c087a94bSLad Prabhakar 	rsnd_runtime_channel_after_ctu_with_params(io, NULL)
466c087a94bSLad Prabhakar int rsnd_runtime_channel_after_ctu_with_params(struct rsnd_dai_stream *io,
467c087a94bSLad Prabhakar 				struct snd_pcm_hw_params *params);
468c087a94bSLad Prabhakar #define rsnd_runtime_channel_for_ssi(io) \
469c087a94bSLad Prabhakar 	rsnd_runtime_channel_for_ssi_with_params(io, NULL)
470c087a94bSLad Prabhakar int rsnd_runtime_channel_for_ssi_with_params(struct rsnd_dai_stream *io,
471c087a94bSLad Prabhakar 				 struct snd_pcm_hw_params *params);
472c087a94bSLad Prabhakar int rsnd_runtime_is_multi_ssi(struct rsnd_dai_stream *io);
473c087a94bSLad Prabhakar int rsnd_runtime_is_tdm(struct rsnd_dai_stream *io);
474c087a94bSLad Prabhakar int rsnd_runtime_is_tdm_split(struct rsnd_dai_stream *io);
475c087a94bSLad Prabhakar 
476c087a94bSLad Prabhakar /*
477c087a94bSLad Prabhakar  * DT
478c087a94bSLad Prabhakar  */
479c087a94bSLad Prabhakar #define rsnd_parse_of_node(priv, node)					\
480c087a94bSLad Prabhakar 	of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, node)
481c087a94bSLad Prabhakar #define RSND_NODE_DAI	"rcar_sound,dai"
482c087a94bSLad Prabhakar #define RSND_NODE_SSI	"rcar_sound,ssi"
483c087a94bSLad Prabhakar #define RSND_NODE_SSIU	"rcar_sound,ssiu"
484c087a94bSLad Prabhakar #define RSND_NODE_SRC	"rcar_sound,src"
485c087a94bSLad Prabhakar #define RSND_NODE_CTU	"rcar_sound,ctu"
486c087a94bSLad Prabhakar #define RSND_NODE_MIX	"rcar_sound,mix"
487c087a94bSLad Prabhakar #define RSND_NODE_DVC	"rcar_sound,dvc"
488c087a94bSLad Prabhakar 
489c087a94bSLad Prabhakar /*
490c087a94bSLad Prabhakar  *	R-Car sound DAI
491c087a94bSLad Prabhakar  */
492c087a94bSLad Prabhakar #define RSND_DAI_NAME_SIZE	16
493c087a94bSLad Prabhakar struct rsnd_dai_stream {
494c087a94bSLad Prabhakar 	char name[RSND_DAI_NAME_SIZE];
495c087a94bSLad Prabhakar 	struct snd_pcm_substream *substream;
496c087a94bSLad Prabhakar 	struct rsnd_mod *mod[RSND_MOD_MAX];
497c087a94bSLad Prabhakar 	struct rsnd_mod *dma;
498c087a94bSLad Prabhakar 	struct rsnd_dai *rdai;
499c087a94bSLad Prabhakar 	struct device *dmac_dev; /* for IPMMU */
500c087a94bSLad Prabhakar 	u32 converted_rate;      /* converted sampling rate */
501c087a94bSLad Prabhakar 	int converted_chan;      /* converted channels */
502c087a94bSLad Prabhakar 	u32 parent_ssi_status;
503c087a94bSLad Prabhakar 	u32 flags;
504c087a94bSLad Prabhakar };
505c087a94bSLad Prabhakar 
506c087a94bSLad Prabhakar /* flags */
507c087a94bSLad Prabhakar #define RSND_STREAM_HDMI0	(1 << 0) /* for HDMI0 */
508c087a94bSLad Prabhakar #define RSND_STREAM_HDMI1	(1 << 1) /* for HDMI1 */
509c087a94bSLad Prabhakar #define RSND_STREAM_TDM_SPLIT	(1 << 2) /* for TDM split mode */
510c087a94bSLad Prabhakar #define RSND_HW_RULE_ERR	(1 << 3) /* hw_rule error */
511c087a94bSLad Prabhakar 
512c087a94bSLad Prabhakar #define rsnd_io_to_mod(io, i)	((i) < RSND_MOD_MAX ? (io)->mod[(i)] : NULL)
513c087a94bSLad Prabhakar #define rsnd_io_to_mod_ssi(io)	rsnd_io_to_mod((io), RSND_MOD_SSI)
514c087a94bSLad Prabhakar #define rsnd_io_to_mod_ssiu(io)	rsnd_io_to_mod((io), RSND_MOD_SSIU)
515c087a94bSLad Prabhakar #define rsnd_io_to_mod_ssip(io)	rsnd_io_to_mod((io), RSND_MOD_SSIP)
516c087a94bSLad Prabhakar #define rsnd_io_to_mod_src(io)	rsnd_io_to_mod((io), RSND_MOD_SRC)
517c087a94bSLad Prabhakar #define rsnd_io_to_mod_ctu(io)	rsnd_io_to_mod((io), RSND_MOD_CTU)
518c087a94bSLad Prabhakar #define rsnd_io_to_mod_mix(io)	rsnd_io_to_mod((io), RSND_MOD_MIX)
519c087a94bSLad Prabhakar #define rsnd_io_to_mod_dvc(io)	rsnd_io_to_mod((io), RSND_MOD_DVC)
520c087a94bSLad Prabhakar #define rsnd_io_to_mod_cmd(io)	rsnd_io_to_mod((io), RSND_MOD_CMD)
521c087a94bSLad Prabhakar #define rsnd_io_to_rdai(io)	((io)->rdai)
522c087a94bSLad Prabhakar #define rsnd_io_to_priv(io)	(rsnd_rdai_to_priv(rsnd_io_to_rdai(io)))
523c087a94bSLad Prabhakar #define rsnd_io_is_play(io)	(&rsnd_io_to_rdai(io)->playback == io)
524c087a94bSLad Prabhakar #define rsnd_io_to_runtime(io) ((io)->substream ? \
525c087a94bSLad Prabhakar 				(io)->substream->runtime : NULL)
526c087a94bSLad Prabhakar #define rsnd_io_converted_rate(io)	((io)->converted_rate)
527c087a94bSLad Prabhakar #define rsnd_io_converted_chan(io)	((io)->converted_chan)
528c087a94bSLad Prabhakar int rsnd_io_is_working(struct rsnd_dai_stream *io);
529c087a94bSLad Prabhakar 
530c087a94bSLad Prabhakar struct rsnd_dai {
531c087a94bSLad Prabhakar 	char name[RSND_DAI_NAME_SIZE];
532c087a94bSLad Prabhakar 	struct rsnd_dai_stream playback;
533c087a94bSLad Prabhakar 	struct rsnd_dai_stream capture;
534c087a94bSLad Prabhakar 	struct rsnd_priv *priv;
535c087a94bSLad Prabhakar 	struct snd_pcm_hw_constraint_list constraint;
536c087a94bSLad Prabhakar 	struct of_phandle_args dai_args;
537c087a94bSLad Prabhakar 
538c087a94bSLad Prabhakar 	int max_channels;	/* 2ch - 16ch */
539c087a94bSLad Prabhakar 	int ssi_lane;		/* 1lane - 4lane */
540c087a94bSLad Prabhakar 	int chan_width;		/* 16/24/32 bit width */
541c087a94bSLad Prabhakar 
542c087a94bSLad Prabhakar 	unsigned int clk_master:1;
543c087a94bSLad Prabhakar 	unsigned int bit_clk_inv:1;
544c087a94bSLad Prabhakar 	unsigned int frm_clk_inv:1;
545c087a94bSLad Prabhakar 	unsigned int sys_delay:1;
546c087a94bSLad Prabhakar 	unsigned int data_alignment:1;
547c087a94bSLad Prabhakar };
548c087a94bSLad Prabhakar 
549c087a94bSLad Prabhakar #define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
550c087a94bSLad Prabhakar #define rsnd_rdai_is_clk_master(rdai) ((rdai)->clk_master)
551c087a94bSLad Prabhakar #define rsnd_rdai_to_priv(rdai) ((rdai)->priv)
552c087a94bSLad Prabhakar #define for_each_rsnd_dai(rdai, priv, i)		\
553c087a94bSLad Prabhakar 	for (i = 0;					\
554c087a94bSLad Prabhakar 	     (i < rsnd_rdai_nr(priv)) &&		\
555c087a94bSLad Prabhakar 	     ((rdai) = rsnd_rdai_get(priv, i));		\
556c087a94bSLad Prabhakar 	     i++)
557c087a94bSLad Prabhakar 
558c087a94bSLad Prabhakar struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id);
559c087a94bSLad Prabhakar 
560c087a94bSLad Prabhakar #define rsnd_rdai_channels_set(rdai, max_channels) \
561c087a94bSLad Prabhakar 	rsnd_rdai_channels_ctrl(rdai, max_channels)
562c087a94bSLad Prabhakar #define rsnd_rdai_channels_get(rdai) \
563c087a94bSLad Prabhakar 	rsnd_rdai_channels_ctrl(rdai, 0)
564c087a94bSLad Prabhakar int rsnd_rdai_channels_ctrl(struct rsnd_dai *rdai,
565c087a94bSLad Prabhakar 			    int max_channels);
566c087a94bSLad Prabhakar 
567c087a94bSLad Prabhakar #define rsnd_rdai_ssi_lane_set(rdai, ssi_lane) \
568c087a94bSLad Prabhakar 	rsnd_rdai_ssi_lane_ctrl(rdai, ssi_lane)
569c087a94bSLad Prabhakar #define rsnd_rdai_ssi_lane_get(rdai) \
570c087a94bSLad Prabhakar 	rsnd_rdai_ssi_lane_ctrl(rdai, 0)
571c087a94bSLad Prabhakar int rsnd_rdai_ssi_lane_ctrl(struct rsnd_dai *rdai,
572c087a94bSLad Prabhakar 			    int ssi_lane);
573c087a94bSLad Prabhakar 
574c087a94bSLad Prabhakar #define rsnd_rdai_width_set(rdai, width) \
575c087a94bSLad Prabhakar 	rsnd_rdai_width_ctrl(rdai, width)
576c087a94bSLad Prabhakar #define rsnd_rdai_width_get(rdai) \
577c087a94bSLad Prabhakar 	rsnd_rdai_width_ctrl(rdai, 0)
578c087a94bSLad Prabhakar int rsnd_rdai_width_ctrl(struct rsnd_dai *rdai, int width);
579c087a94bSLad Prabhakar int rsnd_dai_connect(struct rsnd_mod *mod,
580c087a94bSLad Prabhakar 		     struct rsnd_dai_stream *io,
581c087a94bSLad Prabhakar 		     enum rsnd_mod_type type);
582c087a94bSLad Prabhakar 
583c087a94bSLad Prabhakar /*
584c087a94bSLad Prabhakar  *	R-Car Gen1/Gen2
585c087a94bSLad Prabhakar  */
586c087a94bSLad Prabhakar int rsnd_gen_probe(struct rsnd_priv *priv);
587c087a94bSLad Prabhakar void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
588c087a94bSLad Prabhakar 			       struct rsnd_mod *mod,
589c087a94bSLad Prabhakar 			       enum rsnd_reg reg);
590c087a94bSLad Prabhakar phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id);
591c087a94bSLad Prabhakar #ifdef CONFIG_DEBUG_FS
592c087a94bSLad Prabhakar void __iomem *rsnd_gen_get_base_addr(struct rsnd_priv *priv, int reg_id);
593c087a94bSLad Prabhakar #endif
594c087a94bSLad Prabhakar 
595c087a94bSLad Prabhakar /*
596c087a94bSLad Prabhakar  *	R-Car ADG
597c087a94bSLad Prabhakar  */
598c087a94bSLad Prabhakar int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate);
599c087a94bSLad Prabhakar int rsnd_adg_ssi_clk_stop(struct rsnd_mod *ssi_mod);
600c087a94bSLad Prabhakar int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate);
601c087a94bSLad Prabhakar int rsnd_adg_probe(struct rsnd_priv *priv);
602c087a94bSLad Prabhakar void rsnd_adg_remove(struct rsnd_priv *priv);
603c087a94bSLad Prabhakar int rsnd_adg_set_src_timesel_gen2(struct rsnd_mod *src_mod,
604c087a94bSLad Prabhakar 				  struct rsnd_dai_stream *io,
605c087a94bSLad Prabhakar 				  unsigned int in_rate,
606c087a94bSLad Prabhakar 				  unsigned int out_rate);
607c087a94bSLad Prabhakar int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *cmd_mod,
608c087a94bSLad Prabhakar 				 struct rsnd_dai_stream *io);
609c087a94bSLad Prabhakar #define rsnd_adg_clk_enable(priv)	rsnd_adg_clk_control(priv, 1)
610c087a94bSLad Prabhakar #define rsnd_adg_clk_disable(priv)	rsnd_adg_clk_control(priv, 0)
611*139fa599SKuninori Morimoto int rsnd_adg_clk_control(struct rsnd_priv *priv, int enable);
612c087a94bSLad Prabhakar void rsnd_adg_clk_dbg_info(struct rsnd_priv *priv, struct seq_file *m);
613c087a94bSLad Prabhakar 
614c087a94bSLad Prabhakar /*
615c087a94bSLad Prabhakar  *	R-Car sound priv
616c087a94bSLad Prabhakar  */
617c087a94bSLad Prabhakar struct rsnd_priv {
618c087a94bSLad Prabhakar 
619c087a94bSLad Prabhakar 	struct platform_device *pdev;
620c087a94bSLad Prabhakar 	spinlock_t lock;
621c087a94bSLad Prabhakar 	unsigned long flags;
622c087a94bSLad Prabhakar #define RSND_GEN_MASK	(0xF << 0)
623c087a94bSLad Prabhakar #define RSND_GEN1	(1 << 0)
624c087a94bSLad Prabhakar #define RSND_GEN2	(2 << 0)
625c087a94bSLad Prabhakar #define RSND_GEN3	(3 << 0)
626c087a94bSLad Prabhakar #define RSND_GEN4	(4 << 0)
627c087a94bSLad Prabhakar #define RSND_SOC_MASK	(0xFF << 4)
628c087a94bSLad Prabhakar #define RSND_SOC_E	(1 << 4) /* E1/E2/E3 */
629c087a94bSLad Prabhakar 
630c087a94bSLad Prabhakar 	/*
631c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_gen_probe()
632c087a94bSLad Prabhakar 	 */
633c087a94bSLad Prabhakar 	void *gen;
634c087a94bSLad Prabhakar 
635c087a94bSLad Prabhakar 	/*
636c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_adg_probe()
637c087a94bSLad Prabhakar 	 */
638c087a94bSLad Prabhakar 	void *adg;
639c087a94bSLad Prabhakar 
640c087a94bSLad Prabhakar 	/*
641c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_dma_probe()
642c087a94bSLad Prabhakar 	 */
643c087a94bSLad Prabhakar 	void *dma;
644c087a94bSLad Prabhakar 
645c087a94bSLad Prabhakar 	/*
646c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_ssi_probe()
647c087a94bSLad Prabhakar 	 */
648c087a94bSLad Prabhakar 	void *ssi;
649c087a94bSLad Prabhakar 	int ssi_nr;
650c087a94bSLad Prabhakar 
651c087a94bSLad Prabhakar 	/*
652c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_ssiu_probe()
653c087a94bSLad Prabhakar 	 */
654c087a94bSLad Prabhakar 	void *ssiu;
655c087a94bSLad Prabhakar 	int ssiu_nr;
656c087a94bSLad Prabhakar 
657c087a94bSLad Prabhakar 	/*
658c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_src_probe()
659c087a94bSLad Prabhakar 	 */
660c087a94bSLad Prabhakar 	void *src;
661c087a94bSLad Prabhakar 	int src_nr;
662c087a94bSLad Prabhakar 
663c087a94bSLad Prabhakar 	/*
664c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_ctu_probe()
665c087a94bSLad Prabhakar 	 */
666c087a94bSLad Prabhakar 	void *ctu;
667c087a94bSLad Prabhakar 	int ctu_nr;
668c087a94bSLad Prabhakar 
669c087a94bSLad Prabhakar 	/*
670c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_mix_probe()
671c087a94bSLad Prabhakar 	 */
672c087a94bSLad Prabhakar 	void *mix;
673c087a94bSLad Prabhakar 	int mix_nr;
674c087a94bSLad Prabhakar 
675c087a94bSLad Prabhakar 	/*
676c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_dvc_probe()
677c087a94bSLad Prabhakar 	 */
678c087a94bSLad Prabhakar 	void *dvc;
679c087a94bSLad Prabhakar 	int dvc_nr;
680c087a94bSLad Prabhakar 
681c087a94bSLad Prabhakar 	/*
682c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_cmd_probe()
683c087a94bSLad Prabhakar 	 */
684c087a94bSLad Prabhakar 	void *cmd;
685c087a94bSLad Prabhakar 	int cmd_nr;
686c087a94bSLad Prabhakar 
687c087a94bSLad Prabhakar 	/*
688c087a94bSLad Prabhakar 	 * below value will be filled on rsnd_dai_probe()
689c087a94bSLad Prabhakar 	 */
690c087a94bSLad Prabhakar 	struct snd_soc_dai_driver *daidrv;
691c087a94bSLad Prabhakar 	struct rsnd_dai *rdai;
692c087a94bSLad Prabhakar 	int rdai_nr;
693c087a94bSLad Prabhakar 
694c087a94bSLad Prabhakar #define RSND_MAX_COMPONENT 3
695c087a94bSLad Prabhakar 	int component_dais[RSND_MAX_COMPONENT];
696c087a94bSLad Prabhakar };
697c087a94bSLad Prabhakar 
698c087a94bSLad Prabhakar #define rsnd_priv_to_pdev(priv)	((priv)->pdev)
699c087a94bSLad Prabhakar #define rsnd_priv_to_dev(priv)	(&(rsnd_priv_to_pdev(priv)->dev))
700c087a94bSLad Prabhakar 
701c087a94bSLad Prabhakar #define rsnd_is_gen1(priv)	(((priv)->flags & RSND_GEN_MASK) == RSND_GEN1)
702c087a94bSLad Prabhakar #define rsnd_is_gen2(priv)	(((priv)->flags & RSND_GEN_MASK) == RSND_GEN2)
703c087a94bSLad Prabhakar #define rsnd_is_gen3(priv)	(((priv)->flags & RSND_GEN_MASK) == RSND_GEN3)
704c087a94bSLad Prabhakar #define rsnd_is_gen4(priv)	(((priv)->flags & RSND_GEN_MASK) == RSND_GEN4)
705c087a94bSLad Prabhakar #define rsnd_is_gen3_e3(priv)	(((priv)->flags & \
706c087a94bSLad Prabhakar 					(RSND_GEN_MASK | RSND_SOC_MASK)) == \
707c087a94bSLad Prabhakar 					(RSND_GEN3 | RSND_SOC_E))
708c087a94bSLad Prabhakar 
709c087a94bSLad Prabhakar #define rsnd_flags_has(p, f) ((p)->flags & (f))
710c087a94bSLad Prabhakar #define rsnd_flags_set(p, f) ((p)->flags |= (f))
711c087a94bSLad Prabhakar #define rsnd_flags_del(p, f) ((p)->flags &= ~(f))
712c087a94bSLad Prabhakar 
713c087a94bSLad Prabhakar /*
714c087a94bSLad Prabhakar  *	rsnd_kctrl
715c087a94bSLad Prabhakar  */
716c087a94bSLad Prabhakar struct rsnd_kctrl_cfg {
717c087a94bSLad Prabhakar 	unsigned int max;
718c087a94bSLad Prabhakar 	unsigned int size;
719c087a94bSLad Prabhakar 	u32 *val;
720c087a94bSLad Prabhakar 	const char * const *texts;
721c087a94bSLad Prabhakar 	int (*accept)(struct rsnd_dai_stream *io);
722c087a94bSLad Prabhakar 	void (*update)(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
723c087a94bSLad Prabhakar 	struct rsnd_dai_stream *io;
724c087a94bSLad Prabhakar 	struct snd_card *card;
725c087a94bSLad Prabhakar 	struct snd_kcontrol *kctrl;
726c087a94bSLad Prabhakar 	struct rsnd_mod *mod;
727c087a94bSLad Prabhakar };
728c087a94bSLad Prabhakar 
729c087a94bSLad Prabhakar #define RSND_MAX_CHANNELS	8
730c087a94bSLad Prabhakar struct rsnd_kctrl_cfg_m {
731c087a94bSLad Prabhakar 	struct rsnd_kctrl_cfg cfg;
732c087a94bSLad Prabhakar 	u32 val[RSND_MAX_CHANNELS];
733c087a94bSLad Prabhakar };
734c087a94bSLad Prabhakar 
735c087a94bSLad Prabhakar struct rsnd_kctrl_cfg_s {
736c087a94bSLad Prabhakar 	struct rsnd_kctrl_cfg cfg;
737c087a94bSLad Prabhakar 	u32 val;
738c087a94bSLad Prabhakar };
739c087a94bSLad Prabhakar #define rsnd_kctrl_size(x)	((x).cfg.size)
740c087a94bSLad Prabhakar #define rsnd_kctrl_max(x)	((x).cfg.max)
741c087a94bSLad Prabhakar #define rsnd_kctrl_valm(x, i)	((x).val[i])	/* = (x).cfg.val[i] */
742c087a94bSLad Prabhakar #define rsnd_kctrl_vals(x)	((x).val)	/* = (x).cfg.val[0] */
743c087a94bSLad Prabhakar 
744c087a94bSLad Prabhakar int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream *io);
745c087a94bSLad Prabhakar int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream *io);
746c087a94bSLad Prabhakar struct rsnd_kctrl_cfg *rsnd_kctrl_init_m(struct rsnd_kctrl_cfg_m *cfg);
747c087a94bSLad Prabhakar struct rsnd_kctrl_cfg *rsnd_kctrl_init_s(struct rsnd_kctrl_cfg_s *cfg);
748c087a94bSLad Prabhakar int rsnd_kctrl_new(struct rsnd_mod *mod,
749c087a94bSLad Prabhakar 		   struct rsnd_dai_stream *io,
750c087a94bSLad Prabhakar 		   struct snd_soc_pcm_runtime *rtd,
751c087a94bSLad Prabhakar 		   const unsigned char *name,
752c087a94bSLad Prabhakar 		   int (*accept)(struct rsnd_dai_stream *io),
753c087a94bSLad Prabhakar 		   void (*update)(struct rsnd_dai_stream *io,
754c087a94bSLad Prabhakar 				  struct rsnd_mod *mod),
755c087a94bSLad Prabhakar 		   struct rsnd_kctrl_cfg *cfg,
756c087a94bSLad Prabhakar 		   const char * const *texts,
757c087a94bSLad Prabhakar 		   int size,
758c087a94bSLad Prabhakar 		   u32 max);
759c087a94bSLad Prabhakar 
760c087a94bSLad Prabhakar #define rsnd_kctrl_new_m(mod, io, rtd, name, accept, update, cfg, size, max) \
761c087a94bSLad Prabhakar 	rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_m(cfg), \
762c087a94bSLad Prabhakar 		       NULL, size, max)
763c087a94bSLad Prabhakar 
764c087a94bSLad Prabhakar #define rsnd_kctrl_new_s(mod, io, rtd, name, accept, update, cfg, max)	\
765c087a94bSLad Prabhakar 	rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
766c087a94bSLad Prabhakar 		       NULL, 1, max)
767c087a94bSLad Prabhakar 
768c087a94bSLad Prabhakar #define rsnd_kctrl_new_e(mod, io, rtd, name, accept, update, cfg, texts, size) \
769c087a94bSLad Prabhakar 	rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
770c087a94bSLad Prabhakar 		       texts, 1, size)
771c087a94bSLad Prabhakar 
772c087a94bSLad Prabhakar extern const char * const volume_ramp_rate[];
773c087a94bSLad Prabhakar #define VOLUME_RAMP_MAX_DVC	(0x17 + 1)
774c087a94bSLad Prabhakar #define VOLUME_RAMP_MAX_MIX	(0x0a + 1)
775c087a94bSLad Prabhakar 
776c087a94bSLad Prabhakar /*
777c087a94bSLad Prabhakar  *	R-Car SSI
778c087a94bSLad Prabhakar  */
779c087a94bSLad Prabhakar int rsnd_ssi_probe(struct rsnd_priv *priv);
780c087a94bSLad Prabhakar void rsnd_ssi_remove(struct rsnd_priv *priv);
781c087a94bSLad Prabhakar struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
782c087a94bSLad Prabhakar int rsnd_ssi_use_busif(struct rsnd_dai_stream *io);
783c087a94bSLad Prabhakar u32 rsnd_ssi_multi_secondaries_runtime(struct rsnd_dai_stream *io);
784c087a94bSLad Prabhakar int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
785c087a94bSLad Prabhakar 
786c087a94bSLad Prabhakar #define rsnd_ssi_is_pin_sharing(io)	\
787c087a94bSLad Prabhakar 	__rsnd_ssi_is_pin_sharing(rsnd_io_to_mod_ssi(io))
788c087a94bSLad Prabhakar int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
789c087a94bSLad Prabhakar 
790c087a94bSLad Prabhakar #define rsnd_ssi_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSI)
791c087a94bSLad Prabhakar void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
792c087a94bSLad Prabhakar 			    struct device_node *playback,
793c087a94bSLad Prabhakar 			    struct device_node *capture);
794c087a94bSLad Prabhakar unsigned int rsnd_ssi_clk_query(struct rsnd_dai *rdai,
795c087a94bSLad Prabhakar 		       int param1, int param2, int *idx);
796c087a94bSLad Prabhakar 
797c087a94bSLad Prabhakar /*
798c087a94bSLad Prabhakar  *	R-Car SSIU
799c087a94bSLad Prabhakar  */
800c087a94bSLad Prabhakar int rsnd_ssiu_attach(struct rsnd_dai_stream *io,
801c087a94bSLad Prabhakar 		     struct rsnd_mod *mod);
802c087a94bSLad Prabhakar int rsnd_ssiu_probe(struct rsnd_priv *priv);
803c087a94bSLad Prabhakar void rsnd_ssiu_remove(struct rsnd_priv *priv);
804c087a94bSLad Prabhakar void rsnd_parse_connect_ssiu(struct rsnd_dai *rdai,
805c087a94bSLad Prabhakar 			     struct device_node *playback,
806c087a94bSLad Prabhakar 			     struct device_node *capture);
807c087a94bSLad Prabhakar #define rsnd_ssiu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSIU)
808c087a94bSLad Prabhakar bool rsnd_ssiu_busif_err_status_clear(struct rsnd_mod *mod);
809c087a94bSLad Prabhakar 
810c087a94bSLad Prabhakar /*
811c087a94bSLad Prabhakar  *	R-Car SRC
812c087a94bSLad Prabhakar  */
813c087a94bSLad Prabhakar int rsnd_src_probe(struct rsnd_priv *priv);
814c087a94bSLad Prabhakar void rsnd_src_remove(struct rsnd_priv *priv);
815c087a94bSLad Prabhakar struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id);
816c087a94bSLad Prabhakar 
817c087a94bSLad Prabhakar #define rsnd_src_get_in_rate(priv, io) rsnd_src_get_rate(priv, io, 1)
818c087a94bSLad Prabhakar #define rsnd_src_get_out_rate(priv, io) rsnd_src_get_rate(priv, io, 0)
819c087a94bSLad Prabhakar unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
820c087a94bSLad Prabhakar 			       struct rsnd_dai_stream *io,
821c087a94bSLad Prabhakar 			       int is_in);
822c087a94bSLad Prabhakar 
823c087a94bSLad Prabhakar #define rsnd_src_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SRC)
824c087a94bSLad Prabhakar #define rsnd_parse_connect_src(rdai, playback, capture)			\
825c087a94bSLad Prabhakar 	rsnd_parse_connect_common(rdai, "src", rsnd_src_mod_get,	\
826c087a94bSLad Prabhakar 				  rsnd_src_of_node(rsnd_rdai_to_priv(rdai)), \
827c087a94bSLad Prabhakar 						   playback, capture)
828c087a94bSLad Prabhakar 
829c087a94bSLad Prabhakar /*
830c087a94bSLad Prabhakar  *	R-Car CTU
831c087a94bSLad Prabhakar  */
832c087a94bSLad Prabhakar int rsnd_ctu_probe(struct rsnd_priv *priv);
833c087a94bSLad Prabhakar void rsnd_ctu_remove(struct rsnd_priv *priv);
834c087a94bSLad Prabhakar struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id);
835c087a94bSLad Prabhakar #define rsnd_ctu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_CTU)
836c087a94bSLad Prabhakar #define rsnd_parse_connect_ctu(rdai, playback, capture)			\
837c087a94bSLad Prabhakar 	rsnd_parse_connect_common(rdai, "ctu", rsnd_ctu_mod_get,	\
838c087a94bSLad Prabhakar 				  rsnd_ctu_of_node(rsnd_rdai_to_priv(rdai)), \
839c087a94bSLad Prabhakar 						   playback, capture)
840c087a94bSLad Prabhakar 
841c087a94bSLad Prabhakar /*
842c087a94bSLad Prabhakar  *	R-Car MIX
843c087a94bSLad Prabhakar  */
844c087a94bSLad Prabhakar int rsnd_mix_probe(struct rsnd_priv *priv);
845c087a94bSLad Prabhakar void rsnd_mix_remove(struct rsnd_priv *priv);
846c087a94bSLad Prabhakar struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id);
847c087a94bSLad Prabhakar #define rsnd_mix_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_MIX)
848c087a94bSLad Prabhakar #define rsnd_parse_connect_mix(rdai, playback, capture)			\
849c087a94bSLad Prabhakar 	rsnd_parse_connect_common(rdai, "mix", rsnd_mix_mod_get,	\
850c087a94bSLad Prabhakar 				  rsnd_mix_of_node(rsnd_rdai_to_priv(rdai)), \
851c087a94bSLad Prabhakar 						   playback, capture)
852c087a94bSLad Prabhakar 
853c087a94bSLad Prabhakar /*
854c087a94bSLad Prabhakar  *	R-Car DVC
855c087a94bSLad Prabhakar  */
856c087a94bSLad Prabhakar int rsnd_dvc_probe(struct rsnd_priv *priv);
857c087a94bSLad Prabhakar void rsnd_dvc_remove(struct rsnd_priv *priv);
858c087a94bSLad Prabhakar struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id);
859c087a94bSLad Prabhakar #define rsnd_dvc_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DVC)
860c087a94bSLad Prabhakar #define rsnd_parse_connect_dvc(rdai, playback, capture)			\
861c087a94bSLad Prabhakar 	rsnd_parse_connect_common(rdai, "dvc", rsnd_dvc_mod_get,	\
862c087a94bSLad Prabhakar 				  rsnd_dvc_of_node(rsnd_rdai_to_priv(rdai)), \
863c087a94bSLad Prabhakar 						   playback, capture)
864c087a94bSLad Prabhakar 
865c087a94bSLad Prabhakar /*
866c087a94bSLad Prabhakar  *	R-Car CMD
867c087a94bSLad Prabhakar  */
868c087a94bSLad Prabhakar int rsnd_cmd_probe(struct rsnd_priv *priv);
869c087a94bSLad Prabhakar void rsnd_cmd_remove(struct rsnd_priv *priv);
870c087a94bSLad Prabhakar int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id);
871c087a94bSLad Prabhakar 
872c087a94bSLad Prabhakar void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type);
873c087a94bSLad Prabhakar 
874c087a94bSLad Prabhakar /*
875c087a94bSLad Prabhakar  * If you don't need interrupt status debug message,
876c087a94bSLad Prabhakar  * define RSND_DEBUG_NO_IRQ_STATUS as 1 on top of src.c/ssi.c
877c087a94bSLad Prabhakar  *
878c087a94bSLad Prabhakar  * #define RSND_DEBUG_NO_IRQ_STATUS 1
879c087a94bSLad Prabhakar  */
880c087a94bSLad Prabhakar #define rsnd_print_irq_status(dev, param...) do {	\
881c087a94bSLad Prabhakar 	if (!IS_BUILTIN(RSND_DEBUG_NO_IRQ_STATUS))	\
882c087a94bSLad Prabhakar 		dev_info(dev, param);			\
883c087a94bSLad Prabhakar } while (0)
884c087a94bSLad Prabhakar 
885c087a94bSLad Prabhakar #ifdef CONFIG_DEBUG_FS
886c087a94bSLad Prabhakar int rsnd_debugfs_probe(struct snd_soc_component *component);
887c087a94bSLad Prabhakar void rsnd_debugfs_reg_show(struct seq_file *m, phys_addr_t _addr,
888c087a94bSLad Prabhakar 			   void __iomem *base, int offset, int size);
889c087a94bSLad Prabhakar void rsnd_debugfs_mod_reg_show(struct seq_file *m, struct rsnd_mod *mod,
890c087a94bSLad Prabhakar 			       int reg_id, int offset, int size);
891c087a94bSLad Prabhakar 
892c087a94bSLad Prabhakar #else
893c087a94bSLad Prabhakar #define rsnd_debugfs_probe  NULL
894c087a94bSLad Prabhakar #endif
895c087a94bSLad Prabhakar 
896c087a94bSLad Prabhakar #endif /* RSND_H */
897