4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
14 #include <linux/clk.h>
15 #include <linux/device.h>
16 #include <linux/dma-mapping.h>
18 #include <linux/list.h>
19 #include <linux/module.h>
20 #include <linux/sh_dma.h>
21 #include <linux/workqueue.h>
22 #include <sound/rcar_snd.h>
23 #include <sound/soc.h>
24 #include <sound/pcm_params.h>
29 * The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different.
30 * This driver uses pseudo register in order to hide it.
31 * see gen1/gen2 for detail
35 RSND_REG_SRC_ROUTE_SEL, /* for Gen1 */
36 RSND_REG_SRC_TMG_SEL0, /* for Gen1 */
37 RSND_REG_SRC_TMG_SEL1, /* for Gen1 */
38 RSND_REG_SRC_TMG_SEL2, /* for Gen1 */
39 RSND_REG_SRC_ROUTE_CTRL, /* for Gen1 */
40 RSND_REG_SRC_CTRL, /* for Gen2 */
41 RSND_REG_SSI_CTRL, /* for Gen2 */
43 RSND_REG_SSI_BUSIF_MODE, /* for Gen2 */
44 RSND_REG_SSI_BUSIF_ADINR, /* for Gen2 */
47 RSND_REG_INT_ENABLE, /* for Gen2 */
48 RSND_REG_SRC_BUSIF_MODE,
49 RSND_REG_SRC_ROUTE_MODE0,
56 RSND_REG_SRC_MNFSR, /* for Gen1 */
57 RSND_REG_SRC_BSDSR, /* for Gen2 */
58 RSND_REG_SRC_BSISR, /* for Gen2 */
64 RSND_REG_AUDIO_CLK_SEL0,
65 RSND_REG_AUDIO_CLK_SEL1,
66 RSND_REG_AUDIO_CLK_SEL2,
67 RSND_REG_AUDIO_CLK_SEL3, /* for Gen1 */
68 RSND_REG_AUDIO_CLK_SEL4, /* for Gen1 */
69 RSND_REG_AUDIO_CLK_SEL5, /* for Gen1 */
70 RSND_REG_DIV_EN, /* for Gen2 */
71 RSND_REG_SRCIN_TIMSEL0, /* for Gen2 */
72 RSND_REG_SRCIN_TIMSEL1, /* for Gen2 */
73 RSND_REG_SRCIN_TIMSEL2, /* for Gen2 */
74 RSND_REG_SRCIN_TIMSEL3, /* for Gen2 */
75 RSND_REG_SRCIN_TIMSEL4, /* for Gen2 */
76 RSND_REG_SRCOUT_TIMSEL0, /* for Gen2 */
77 RSND_REG_SRCOUT_TIMSEL1, /* for Gen2 */
78 RSND_REG_SRCOUT_TIMSEL2, /* for Gen2 */
79 RSND_REG_SRCOUT_TIMSEL3, /* for Gen2 */
80 RSND_REG_SRCOUT_TIMSEL4, /* for Gen2 */
95 struct rsnd_dai_stream;
98 * R-Car basic functions
100 #define rsnd_mod_read(m, r) \
101 rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
102 #define rsnd_mod_write(m, r, d) \
103 rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
104 #define rsnd_mod_bset(m, r, s, d) \
105 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
107 u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
108 void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
109 enum rsnd_reg reg, u32 data);
110 void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
117 struct sh_dmae_slave slave;
118 struct work_struct work;
119 struct dma_chan *chan;
120 enum dma_data_direction dir;
123 int offset; /* it cares A/B plane */
126 void rsnd_dma_start(struct rsnd_dma *dma);
127 void rsnd_dma_stop(struct rsnd_dma *dma);
128 int rsnd_dma_available(struct rsnd_dma *dma);
129 int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
130 int is_play, int id);
131 void rsnd_dma_quit(struct rsnd_priv *priv,
132 struct rsnd_dma *dma);
144 struct rsnd_mod_ops {
146 int (*init)(struct rsnd_mod *mod,
147 struct rsnd_dai *rdai,
148 struct rsnd_dai_stream *io);
149 int (*quit)(struct rsnd_mod *mod,
150 struct rsnd_dai *rdai,
151 struct rsnd_dai_stream *io);
152 int (*start)(struct rsnd_mod *mod,
153 struct rsnd_dai *rdai,
154 struct rsnd_dai_stream *io);
155 int (*stop)(struct rsnd_mod *mod,
156 struct rsnd_dai *rdai,
157 struct rsnd_dai_stream *io);
160 struct rsnd_dai_stream;
163 enum rsnd_mod_type type;
164 struct rsnd_priv *priv;
165 struct rsnd_mod_ops *ops;
167 struct rsnd_dai_stream *io;
170 #define rsnd_mod_to_priv(mod) ((mod)->priv)
171 #define rsnd_mod_to_dma(mod) (&(mod)->dma)
172 #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
173 #define rsnd_mod_to_io(mod) ((mod)->io)
174 #define rsnd_mod_id(mod) ((mod)->id)
176 void rsnd_mod_init(struct rsnd_priv *priv,
177 struct rsnd_mod *mod,
178 struct rsnd_mod_ops *ops,
179 enum rsnd_mod_type type,
181 char *rsnd_mod_name(struct rsnd_mod *mod);
186 #define RSND_DAI_NAME_SIZE 16
187 struct rsnd_dai_stream {
188 struct snd_pcm_substream *substream;
189 struct rsnd_mod *mod[RSND_MOD_MAX];
193 int next_period_byte;
195 #define rsnd_io_to_mod_ssi(io) ((io)->mod[RSND_MOD_SSI])
196 #define rsnd_io_to_mod_scu(io) ((io)->mod[RSND_MOD_SCU])
199 char name[RSND_DAI_NAME_SIZE];
200 struct rsnd_dai_platform_info *info; /* rcar_snd.h */
201 struct rsnd_dai_stream playback;
202 struct rsnd_dai_stream capture;
204 unsigned int clk_master:1;
205 unsigned int bit_clk_inv:1;
206 unsigned int frm_clk_inv:1;
207 unsigned int sys_delay:1;
208 unsigned int data_alignment:1;
211 #define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
212 #define for_each_rsnd_dai(rdai, priv, i) \
214 (i < rsnd_rdai_nr(priv)) && \
215 ((rdai) = rsnd_dai_get(priv, i)); \
218 struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
219 int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
220 int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
221 #define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
222 #define rsnd_io_to_runtime(io) ((io)->substream->runtime)
224 void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
225 int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
226 #define rsnd_dai_is_clk_master(rdai) ((rdai)->clk_master)
231 int rsnd_gen_probe(struct platform_device *pdev,
232 struct rsnd_priv *priv);
233 void rsnd_gen_remove(struct platform_device *pdev,
234 struct rsnd_priv *priv);
235 void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
236 struct rsnd_mod *mod,
238 #define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
239 #define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2)
244 int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
245 int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
246 int rsnd_adg_probe(struct platform_device *pdev,
247 struct rsnd_priv *priv);
248 void rsnd_adg_remove(struct platform_device *pdev,
249 struct rsnd_priv *priv);
250 int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
251 struct rsnd_mod *mod,
252 unsigned int src_rate,
253 unsigned int dst_rate);
254 int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
255 struct rsnd_dai *rdai,
256 struct rsnd_dai_stream *io,
257 unsigned int src_rate,
258 unsigned int dst_rate);
259 int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
260 struct rsnd_dai *rdai,
261 struct rsnd_dai_stream *io);
269 struct rcar_snd_info *info;
273 * below value will be filled on rsnd_gen_probe()
278 * below value will be filled on rsnd_scu_probe()
284 * below value will be filled on rsnd_adg_probe()
289 * below value will be filled on rsnd_ssi_probe()
295 * below value will be filled on rsnd_dai_probe()
297 struct snd_soc_dai_driver *daidrv;
298 struct rsnd_dai *rdai;
302 #define rsnd_priv_to_dev(priv) ((priv)->dev)
303 #define rsnd_priv_to_info(priv) ((priv)->info)
304 #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
305 #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
310 int rsnd_scu_probe(struct platform_device *pdev,
311 struct rsnd_priv *priv);
312 void rsnd_scu_remove(struct platform_device *pdev,
313 struct rsnd_priv *priv);
314 struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
315 unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv,
316 struct rsnd_dai_stream *io,
317 struct snd_pcm_runtime *runtime);
319 #define rsnd_scu_nr(priv) ((priv)->scu_nr)
324 int rsnd_ssi_probe(struct platform_device *pdev,
325 struct rsnd_priv *priv);
326 void rsnd_ssi_remove(struct platform_device *pdev,
327 struct rsnd_priv *priv);
328 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
329 struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
330 int dai_id, int is_play);
331 int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
332 int rsnd_ssi_is_play(struct rsnd_mod *mod);