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 */
42 RSND_REG_INT_ENABLE
, /* for Gen2 */
43 RSND_REG_SRC_BUSIF_MODE
,
44 RSND_REG_SRC_ROUTE_MODE0
,
51 RSND_REG_SRC_MNFSR
, /* for Gen1 */
57 RSND_REG_AUDIO_CLK_SEL0
,
58 RSND_REG_AUDIO_CLK_SEL1
,
59 RSND_REG_AUDIO_CLK_SEL2
,
60 RSND_REG_AUDIO_CLK_SEL3
, /* for Gen1 */
61 RSND_REG_AUDIO_CLK_SEL4
, /* for Gen1 */
62 RSND_REG_AUDIO_CLK_SEL5
, /* for Gen1 */
77 struct rsnd_dai_stream
;
80 * R-Car basic functions
82 #define rsnd_mod_read(m, r) \
83 rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
84 #define rsnd_mod_write(m, r, d) \
85 rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
86 #define rsnd_mod_bset(m, r, s, d) \
87 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
89 u32
rsnd_read(struct rsnd_priv
*priv
, struct rsnd_mod
*mod
, enum rsnd_reg reg
);
90 void rsnd_write(struct rsnd_priv
*priv
, struct rsnd_mod
*mod
,
91 enum rsnd_reg reg
, u32 data
);
92 void rsnd_bset(struct rsnd_priv
*priv
, struct rsnd_mod
*mod
, enum rsnd_reg reg
,
99 struct sh_dmae_slave slave
;
100 struct work_struct work
;
101 struct dma_chan
*chan
;
102 enum dma_data_direction dir
;
105 int offset
; /* it cares A/B plane */
108 void rsnd_dma_start(struct rsnd_dma
*dma
);
109 void rsnd_dma_stop(struct rsnd_dma
*dma
);
110 int rsnd_dma_available(struct rsnd_dma
*dma
);
111 int rsnd_dma_init(struct rsnd_priv
*priv
, struct rsnd_dma
*dma
,
112 int is_play
, int id
);
113 void rsnd_dma_quit(struct rsnd_priv
*priv
,
114 struct rsnd_dma
*dma
);
121 struct rsnd_mod_ops
{
123 int (*init
)(struct rsnd_mod
*mod
,
124 struct rsnd_dai
*rdai
,
125 struct rsnd_dai_stream
*io
);
126 int (*quit
)(struct rsnd_mod
*mod
,
127 struct rsnd_dai
*rdai
,
128 struct rsnd_dai_stream
*io
);
129 int (*start
)(struct rsnd_mod
*mod
,
130 struct rsnd_dai
*rdai
,
131 struct rsnd_dai_stream
*io
);
132 int (*stop
)(struct rsnd_mod
*mod
,
133 struct rsnd_dai
*rdai
,
134 struct rsnd_dai_stream
*io
);
137 struct rsnd_dai_stream
;
140 struct rsnd_priv
*priv
;
141 struct rsnd_mod_ops
*ops
;
142 struct list_head list
; /* connect to rsnd_dai playback/capture */
144 struct rsnd_dai_stream
*io
;
147 #define rsnd_mod_to_priv(mod) ((mod)->priv)
148 #define rsnd_mod_to_dma(mod) (&(mod)->dma)
149 #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
150 #define rsnd_mod_to_io(mod) ((mod)->io)
151 #define rsnd_mod_id(mod) ((mod)->id)
152 #define for_each_rsnd_mod(pos, n, io) \
153 list_for_each_entry_safe(pos, n, &(io)->head, list)
154 #define __rsnd_mod_call(mod, func, rdai, io) \
156 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
157 struct device *dev = rsnd_priv_to_dev(priv); \
158 dev_dbg(dev, "%s-%d-%s\n", \
159 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \
160 (mod)->ops->func(mod, rdai, io); \
163 #define rsnd_mod_call(mod, func, rdai, io) \
164 (!(mod) ? -ENODEV : \
165 !((mod)->ops->func) ? 0 : \
166 __rsnd_mod_call(mod, func, rdai, io))
168 void rsnd_mod_init(struct rsnd_priv
*priv
,
169 struct rsnd_mod
*mod
,
170 struct rsnd_mod_ops
*ops
,
172 char *rsnd_mod_name(struct rsnd_mod
*mod
);
177 #define RSND_DAI_NAME_SIZE 16
178 struct rsnd_dai_stream
{
179 struct list_head head
; /* head of rsnd_mod list */
180 struct snd_pcm_substream
*substream
;
184 int next_period_byte
;
188 char name
[RSND_DAI_NAME_SIZE
];
189 struct rsnd_dai_platform_info
*info
; /* rcar_snd.h */
190 struct rsnd_dai_stream playback
;
191 struct rsnd_dai_stream capture
;
193 unsigned int clk_master
:1;
194 unsigned int bit_clk_inv
:1;
195 unsigned int frm_clk_inv
:1;
196 unsigned int sys_delay
:1;
197 unsigned int data_alignment
:1;
200 #define rsnd_dai_nr(priv) ((priv)->dai_nr)
201 #define for_each_rsnd_dai(rdai, priv, i) \
202 for (i = 0, (rdai) = rsnd_dai_get(priv, i); \
203 i < rsnd_dai_nr(priv); \
204 i++, (rdai) = rsnd_dai_get(priv, i))
206 struct rsnd_dai
*rsnd_dai_get(struct rsnd_priv
*priv
, int id
);
207 int rsnd_dai_disconnect(struct rsnd_mod
*mod
);
208 int rsnd_dai_connect(struct rsnd_dai
*rdai
, struct rsnd_mod
*mod
,
209 struct rsnd_dai_stream
*io
);
210 int rsnd_dai_is_play(struct rsnd_dai
*rdai
, struct rsnd_dai_stream
*io
);
211 int rsnd_dai_id(struct rsnd_priv
*priv
, struct rsnd_dai
*rdai
);
212 #define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
213 #define rsnd_io_to_runtime(io) ((io)->substream->runtime)
215 void rsnd_dai_pointer_update(struct rsnd_dai_stream
*io
, int cnt
);
216 int rsnd_dai_pointer_offset(struct rsnd_dai_stream
*io
, int additional
);
217 #define rsnd_dai_is_clk_master(rdai) ((rdai)->clk_master)
222 int rsnd_gen_probe(struct platform_device
*pdev
,
223 struct rcar_snd_info
*info
,
224 struct rsnd_priv
*priv
);
225 void rsnd_gen_remove(struct platform_device
*pdev
,
226 struct rsnd_priv
*priv
);
227 int rsnd_gen_path_init(struct rsnd_priv
*priv
,
228 struct rsnd_dai
*rdai
,
229 struct rsnd_dai_stream
*io
);
230 int rsnd_gen_path_exit(struct rsnd_priv
*priv
,
231 struct rsnd_dai
*rdai
,
232 struct rsnd_dai_stream
*io
);
233 void __iomem
*rsnd_gen_reg_get(struct rsnd_priv
*priv
,
234 struct rsnd_mod
*mod
,
236 #define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
237 #define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2)
242 int rsnd_adg_ssi_clk_stop(struct rsnd_mod
*mod
);
243 int rsnd_adg_ssi_clk_try_start(struct rsnd_mod
*mod
, unsigned int rate
);
244 int rsnd_adg_probe(struct platform_device
*pdev
,
245 struct rcar_snd_info
*info
,
246 struct rsnd_priv
*priv
);
247 void rsnd_adg_remove(struct platform_device
*pdev
,
248 struct rsnd_priv
*priv
);
249 int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv
*priv
,
250 struct rsnd_mod
*mod
,
251 unsigned int src_rate
,
252 unsigned int dst_rate
);
260 struct rcar_snd_info
*info
;
264 * below value will be filled on rsnd_gen_probe()
269 * below value will be filled on rsnd_scu_probe()
275 * below value will be filled on rsnd_adg_probe()
280 * below value will be filled on rsnd_ssi_probe()
286 * below value will be filled on rsnd_dai_probe()
288 struct snd_soc_dai_driver
*daidrv
;
289 struct rsnd_dai
*rdai
;
293 #define rsnd_priv_to_dev(priv) ((priv)->dev)
294 #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
295 #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
300 int rsnd_scu_probe(struct platform_device
*pdev
,
301 struct rcar_snd_info
*info
,
302 struct rsnd_priv
*priv
);
303 void rsnd_scu_remove(struct platform_device
*pdev
,
304 struct rsnd_priv
*priv
);
305 struct rsnd_mod
*rsnd_scu_mod_get(struct rsnd_priv
*priv
, int id
);
306 unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv
*priv
,
307 struct rsnd_mod
*ssi_mod
,
308 struct snd_pcm_runtime
*runtime
);
310 #define rsnd_scu_nr(priv) ((priv)->scu_nr)
315 int rsnd_ssi_probe(struct platform_device
*pdev
,
316 struct rcar_snd_info
*info
,
317 struct rsnd_priv
*priv
);
318 void rsnd_ssi_remove(struct platform_device
*pdev
,
319 struct rsnd_priv
*priv
);
320 struct rsnd_mod
*rsnd_ssi_mod_get(struct rsnd_priv
*priv
, int id
);
321 struct rsnd_mod
*rsnd_ssi_mod_get_frm_dai(struct rsnd_priv
*priv
,
322 int dai_id
, int is_play
);
323 int rsnd_ssi_is_pin_sharing(struct rsnd_mod
*mod
);
324 int rsnd_ssi_is_play(struct rsnd_mod
*mod
);
This page took 0.05152 seconds and 5 git commands to generate.