ASoC: rsnd: make sure variable name for 44.1kHz/48kHz
[deliverable/linux.git] / sound / soc / sh / rcar / rsnd.h
CommitLineData
1536a968
KM
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>
0a4d94c0 16#include <linux/dma-mapping.h>
1536a968
KM
17#include <linux/io.h>
18#include <linux/list.h>
19#include <linux/module.h>
0a4d94c0
KM
20#include <linux/sh_dma.h>
21#include <linux/workqueue.h>
1536a968
KM
22#include <sound/rcar_snd.h>
23#include <sound/soc.h>
24#include <sound/pcm_params.h>
25
26/*
27 * pseudo register
28 *
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
32 */
3337744a 33enum rsnd_reg {
507d466c 34 /* SRU/SCU/SSIU */
374a5281
KM
35 RSND_REG_SRC_ROUTE_SEL,
36 RSND_REG_SRC_TMG_SEL0,
37 RSND_REG_SRC_TMG_SEL1,
38 RSND_REG_SRC_TMG_SEL2,
690ef81e 39 RSND_REG_SRC_ROUTE_CTRL,
07539c1d
KM
40 RSND_REG_SSI_MODE0,
41 RSND_REG_SSI_MODE1,
374a5281 42 RSND_REG_BUSIF_MODE,
507d466c 43 RSND_REG_INT_ENABLE,
690ef81e 44 RSND_REG_SRC_ADINR,
07539c1d 45
dfc9403b
KM
46 /* ADG */
47 RSND_REG_BRRA,
48 RSND_REG_BRRB,
49 RSND_REG_SSICKR,
50 RSND_REG_AUDIO_CLK_SEL0,
51 RSND_REG_AUDIO_CLK_SEL1,
52 RSND_REG_AUDIO_CLK_SEL2,
dfc9403b 53
ae5c3223
KM
54 /* SSI */
55 RSND_REG_SSICR,
56 RSND_REG_SSISR,
57 RSND_REG_SSITDR,
58 RSND_REG_SSIRDR,
59 RSND_REG_SSIWSR,
60
3337744a
KM
61 RSND_REG_MAX,
62};
63
1536a968 64struct rsnd_priv;
cdaa3cdf 65struct rsnd_mod;
1536a968
KM
66struct rsnd_dai;
67struct rsnd_dai_stream;
68
3337744a
KM
69/*
70 * R-Car basic functions
71 */
72#define rsnd_mod_read(m, r) \
73 rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
74#define rsnd_mod_write(m, r, d) \
75 rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
76#define rsnd_mod_bset(m, r, s, d) \
77 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
78
3337744a
KM
79u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
80void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
81 enum rsnd_reg reg, u32 data);
82void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
83 u32 mask, u32 data);
84
0a4d94c0
KM
85/*
86 * R-Car DMA
87 */
88struct rsnd_dma {
89 struct rsnd_priv *priv;
90 struct sh_dmae_slave slave;
91 struct work_struct work;
92 struct dma_chan *chan;
93 enum dma_data_direction dir;
94 int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len);
95 int (*complete)(struct rsnd_dma *dma);
96
97 int submit_loop;
98};
99
100void rsnd_dma_start(struct rsnd_dma *dma);
101void rsnd_dma_stop(struct rsnd_dma *dma);
102int rsnd_dma_available(struct rsnd_dma *dma);
103int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
104 int is_play, int id,
105 int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len),
106 int (*complete)(struct rsnd_dma *dma));
107void rsnd_dma_quit(struct rsnd_priv *priv,
108 struct rsnd_dma *dma);
109
110
cdaa3cdf
KM
111/*
112 * R-Car sound mod
113 */
114
115struct rsnd_mod_ops {
116 char *name;
117 int (*init)(struct rsnd_mod *mod,
118 struct rsnd_dai *rdai,
119 struct rsnd_dai_stream *io);
120 int (*quit)(struct rsnd_mod *mod,
121 struct rsnd_dai *rdai,
122 struct rsnd_dai_stream *io);
123 int (*start)(struct rsnd_mod *mod,
124 struct rsnd_dai *rdai,
125 struct rsnd_dai_stream *io);
126 int (*stop)(struct rsnd_mod *mod,
127 struct rsnd_dai *rdai,
128 struct rsnd_dai_stream *io);
129};
130
131struct rsnd_mod {
132 int id;
133 struct rsnd_priv *priv;
134 struct rsnd_mod_ops *ops;
135 struct list_head list; /* connect to rsnd_dai playback/capture */
0a4d94c0 136 struct rsnd_dma dma;
cdaa3cdf
KM
137};
138
139#define rsnd_mod_to_priv(mod) ((mod)->priv)
0a4d94c0
KM
140#define rsnd_mod_to_dma(mod) (&(mod)->dma)
141#define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
cdaa3cdf
KM
142#define rsnd_mod_id(mod) ((mod)->id)
143#define for_each_rsnd_mod(pos, n, io) \
144 list_for_each_entry_safe(pos, n, &(io)->head, list)
145#define rsnd_mod_call(mod, func, rdai, io) \
146 (!(mod) ? -ENODEV : \
147 !((mod)->ops->func) ? 0 : \
148 (mod)->ops->func(mod, rdai, io))
149
150void rsnd_mod_init(struct rsnd_priv *priv,
151 struct rsnd_mod *mod,
152 struct rsnd_mod_ops *ops,
153 int id);
154char *rsnd_mod_name(struct rsnd_mod *mod);
155
1536a968
KM
156/*
157 * R-Car sound DAI
158 */
159#define RSND_DAI_NAME_SIZE 16
160struct rsnd_dai_stream {
161 struct list_head head; /* head of rsnd_mod list */
162 struct snd_pcm_substream *substream;
163 int byte_pos;
164 int period_pos;
165 int byte_per_period;
166 int next_period_byte;
167};
168
169struct rsnd_dai {
170 char name[RSND_DAI_NAME_SIZE];
171 struct rsnd_dai_platform_info *info; /* rcar_snd.h */
172 struct rsnd_dai_stream playback;
173 struct rsnd_dai_stream capture;
174
a3737731
DC
175 unsigned int clk_master:1;
176 unsigned int bit_clk_inv:1;
177 unsigned int frm_clk_inv:1;
178 unsigned int sys_delay:1;
179 unsigned int data_alignment:1;
1536a968
KM
180};
181
182#define rsnd_dai_nr(priv) ((priv)->dai_nr)
183#define for_each_rsnd_dai(rdai, priv, i) \
184 for (i = 0, (rdai) = rsnd_dai_get(priv, i); \
185 i < rsnd_dai_nr(priv); \
186 i++, (rdai) = rsnd_dai_get(priv, i))
187
188struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
cdaa3cdf
KM
189int rsnd_dai_disconnect(struct rsnd_mod *mod);
190int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod,
191 struct rsnd_dai_stream *io);
1536a968 192int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
4b4dab82 193int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
1536a968 194#define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
ae5c3223 195#define rsnd_io_to_runtime(io) ((io)->substream->runtime)
1536a968
KM
196
197void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
198int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
199
3337744a
KM
200/*
201 * R-Car Gen1/Gen2
202 */
203int rsnd_gen_probe(struct platform_device *pdev,
204 struct rcar_snd_info *info,
205 struct rsnd_priv *priv);
206void rsnd_gen_remove(struct platform_device *pdev,
207 struct rsnd_priv *priv);
208int rsnd_gen_path_init(struct rsnd_priv *priv,
209 struct rsnd_dai *rdai,
210 struct rsnd_dai_stream *io);
211int rsnd_gen_path_exit(struct rsnd_priv *priv,
212 struct rsnd_dai *rdai,
213 struct rsnd_dai_stream *io);
214void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
215 struct rsnd_mod *mod,
216 enum rsnd_reg reg);
c5d5a58d
KM
217#define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
218#define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2)
3337744a 219
dfc9403b
KM
220/*
221 * R-Car ADG
222 */
223int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
224int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
225int rsnd_adg_probe(struct platform_device *pdev,
226 struct rcar_snd_info *info,
227 struct rsnd_priv *priv);
228void rsnd_adg_remove(struct platform_device *pdev,
229 struct rsnd_priv *priv);
230
1536a968
KM
231/*
232 * R-Car sound priv
233 */
234struct rsnd_priv {
235
236 struct device *dev;
237 struct rcar_snd_info *info;
238 spinlock_t lock;
239
3337744a
KM
240 /*
241 * below value will be filled on rsnd_gen_probe()
242 */
243 void *gen;
244
07539c1d
KM
245 /*
246 * below value will be filled on rsnd_scu_probe()
247 */
248 void *scu;
249 int scu_nr;
250
dfc9403b
KM
251 /*
252 * below value will be filled on rsnd_adg_probe()
253 */
254 void *adg;
255
ae5c3223
KM
256 /*
257 * below value will be filled on rsnd_ssi_probe()
258 */
259 void *ssiu;
260
1536a968
KM
261 /*
262 * below value will be filled on rsnd_dai_probe()
263 */
264 struct snd_soc_dai_driver *daidrv;
265 struct rsnd_dai *rdai;
266 int dai_nr;
267};
268
269#define rsnd_priv_to_dev(priv) ((priv)->dev)
270#define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
271#define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
272
07539c1d
KM
273/*
274 * R-Car SCU
275 */
276int rsnd_scu_probe(struct platform_device *pdev,
277 struct rcar_snd_info *info,
278 struct rsnd_priv *priv);
279void rsnd_scu_remove(struct platform_device *pdev,
280 struct rsnd_priv *priv);
281struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
cdcfcac9 282bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod);
07539c1d
KM
283#define rsnd_scu_nr(priv) ((priv)->scu_nr)
284
ae5c3223
KM
285/*
286 * R-Car SSI
287 */
288int rsnd_ssi_probe(struct platform_device *pdev,
289 struct rcar_snd_info *info,
290 struct rsnd_priv *priv);
291void rsnd_ssi_remove(struct platform_device *pdev,
292 struct rsnd_priv *priv);
293struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
4b4dab82
KM
294struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
295 int dai_id, int is_play);
ae5c3223 296
1536a968 297#endif
This page took 0.047878 seconds and 5 git commands to generate.