]>
Commit | Line | Data |
---|---|---|
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 | 33 | enum rsnd_reg { |
507d466c | 34 | /* SRU/SCU/SSIU */ |
2582718c KM |
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 */ | |
07539c1d KM |
40 | RSND_REG_SSI_MODE0, |
41 | RSND_REG_SSI_MODE1, | |
52ea2a79 | 42 | RSND_REG_INT_ENABLE, /* for Gen2 */ |
0290d2a4 | 43 | RSND_REG_SRC_BUSIF_MODE, |
ef749400 KM |
44 | RSND_REG_SRC_ROUTE_MODE0, |
45 | RSND_REG_SRC_SWRSR, | |
46 | RSND_REG_SRC_SRCIR, | |
690ef81e | 47 | RSND_REG_SRC_ADINR, |
ef749400 KM |
48 | RSND_REG_SRC_IFSCR, |
49 | RSND_REG_SRC_IFSVR, | |
50 | RSND_REG_SRC_SRCCR, | |
51 | RSND_REG_SRC_MNFSR, | |
07539c1d | 52 | |
dfc9403b KM |
53 | /* ADG */ |
54 | RSND_REG_BRRA, | |
55 | RSND_REG_BRRB, | |
56 | RSND_REG_SSICKR, | |
57 | RSND_REG_AUDIO_CLK_SEL0, | |
58 | RSND_REG_AUDIO_CLK_SEL1, | |
59 | RSND_REG_AUDIO_CLK_SEL2, | |
ef749400 KM |
60 | RSND_REG_AUDIO_CLK_SEL3, /* for Gen1 */ |
61 | RSND_REG_AUDIO_CLK_SEL4, /* for Gen1 */ | |
62 | RSND_REG_AUDIO_CLK_SEL5, /* for Gen1 */ | |
dfc9403b | 63 | |
ae5c3223 KM |
64 | /* SSI */ |
65 | RSND_REG_SSICR, | |
66 | RSND_REG_SSISR, | |
67 | RSND_REG_SSITDR, | |
68 | RSND_REG_SSIRDR, | |
69 | RSND_REG_SSIWSR, | |
70 | ||
3337744a KM |
71 | RSND_REG_MAX, |
72 | }; | |
73 | ||
1536a968 | 74 | struct rsnd_priv; |
cdaa3cdf | 75 | struct rsnd_mod; |
1536a968 KM |
76 | struct rsnd_dai; |
77 | struct rsnd_dai_stream; | |
78 | ||
3337744a KM |
79 | /* |
80 | * R-Car basic functions | |
81 | */ | |
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) | |
88 | ||
3337744a KM |
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, | |
93 | u32 mask, u32 data); | |
94 | ||
0a4d94c0 KM |
95 | /* |
96 | * R-Car DMA | |
97 | */ | |
98 | struct rsnd_dma { | |
99 | struct rsnd_priv *priv; | |
100 | struct sh_dmae_slave slave; | |
101 | struct work_struct work; | |
102 | struct dma_chan *chan; | |
103 | enum dma_data_direction dir; | |
104 | int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len); | |
105 | int (*complete)(struct rsnd_dma *dma); | |
106 | ||
107 | int submit_loop; | |
108 | }; | |
109 | ||
110 | void rsnd_dma_start(struct rsnd_dma *dma); | |
111 | void rsnd_dma_stop(struct rsnd_dma *dma); | |
112 | int rsnd_dma_available(struct rsnd_dma *dma); | |
113 | int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma, | |
114 | int is_play, int id, | |
115 | int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len), | |
116 | int (*complete)(struct rsnd_dma *dma)); | |
117 | void rsnd_dma_quit(struct rsnd_priv *priv, | |
118 | struct rsnd_dma *dma); | |
119 | ||
120 | ||
cdaa3cdf KM |
121 | /* |
122 | * R-Car sound mod | |
123 | */ | |
124 | ||
125 | struct rsnd_mod_ops { | |
126 | char *name; | |
127 | int (*init)(struct rsnd_mod *mod, | |
128 | struct rsnd_dai *rdai, | |
129 | struct rsnd_dai_stream *io); | |
130 | int (*quit)(struct rsnd_mod *mod, | |
131 | struct rsnd_dai *rdai, | |
132 | struct rsnd_dai_stream *io); | |
133 | int (*start)(struct rsnd_mod *mod, | |
134 | struct rsnd_dai *rdai, | |
135 | struct rsnd_dai_stream *io); | |
136 | int (*stop)(struct rsnd_mod *mod, | |
137 | struct rsnd_dai *rdai, | |
138 | struct rsnd_dai_stream *io); | |
139 | }; | |
140 | ||
141 | struct rsnd_mod { | |
142 | int id; | |
143 | struct rsnd_priv *priv; | |
144 | struct rsnd_mod_ops *ops; | |
145 | struct list_head list; /* connect to rsnd_dai playback/capture */ | |
0a4d94c0 | 146 | struct rsnd_dma dma; |
cdaa3cdf KM |
147 | }; |
148 | ||
149 | #define rsnd_mod_to_priv(mod) ((mod)->priv) | |
0a4d94c0 KM |
150 | #define rsnd_mod_to_dma(mod) (&(mod)->dma) |
151 | #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) | |
cdaa3cdf KM |
152 | #define rsnd_mod_id(mod) ((mod)->id) |
153 | #define for_each_rsnd_mod(pos, n, io) \ | |
154 | list_for_each_entry_safe(pos, n, &(io)->head, list) | |
92d9587e KM |
155 | #define __rsnd_mod_call(mod, func, rdai, io) \ |
156 | ({ \ | |
157 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ | |
158 | struct device *dev = rsnd_priv_to_dev(priv); \ | |
159 | dev_dbg(dev, "%s-%d-%s\n", \ | |
160 | rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \ | |
161 | (mod)->ops->func(mod, rdai, io); \ | |
162 | }) | |
163 | ||
cdaa3cdf KM |
164 | #define rsnd_mod_call(mod, func, rdai, io) \ |
165 | (!(mod) ? -ENODEV : \ | |
166 | !((mod)->ops->func) ? 0 : \ | |
92d9587e | 167 | __rsnd_mod_call(mod, func, rdai, io)) |
cdaa3cdf KM |
168 | |
169 | void rsnd_mod_init(struct rsnd_priv *priv, | |
170 | struct rsnd_mod *mod, | |
171 | struct rsnd_mod_ops *ops, | |
172 | int id); | |
173 | char *rsnd_mod_name(struct rsnd_mod *mod); | |
174 | ||
1536a968 KM |
175 | /* |
176 | * R-Car sound DAI | |
177 | */ | |
178 | #define RSND_DAI_NAME_SIZE 16 | |
179 | struct rsnd_dai_stream { | |
180 | struct list_head head; /* head of rsnd_mod list */ | |
181 | struct snd_pcm_substream *substream; | |
182 | int byte_pos; | |
183 | int period_pos; | |
184 | int byte_per_period; | |
185 | int next_period_byte; | |
186 | }; | |
187 | ||
188 | struct rsnd_dai { | |
189 | char name[RSND_DAI_NAME_SIZE]; | |
190 | struct rsnd_dai_platform_info *info; /* rcar_snd.h */ | |
191 | struct rsnd_dai_stream playback; | |
192 | struct rsnd_dai_stream capture; | |
193 | ||
a3737731 DC |
194 | unsigned int clk_master:1; |
195 | unsigned int bit_clk_inv:1; | |
196 | unsigned int frm_clk_inv:1; | |
197 | unsigned int sys_delay:1; | |
198 | unsigned int data_alignment:1; | |
1536a968 KM |
199 | }; |
200 | ||
201 | #define rsnd_dai_nr(priv) ((priv)->dai_nr) | |
202 | #define for_each_rsnd_dai(rdai, priv, i) \ | |
203 | for (i = 0, (rdai) = rsnd_dai_get(priv, i); \ | |
204 | i < rsnd_dai_nr(priv); \ | |
205 | i++, (rdai) = rsnd_dai_get(priv, i)) | |
206 | ||
207 | struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id); | |
cdaa3cdf KM |
208 | int rsnd_dai_disconnect(struct rsnd_mod *mod); |
209 | int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod, | |
210 | struct rsnd_dai_stream *io); | |
1536a968 | 211 | int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io); |
4b4dab82 | 212 | int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai); |
1536a968 | 213 | #define rsnd_dai_get_platform_info(rdai) ((rdai)->info) |
ae5c3223 | 214 | #define rsnd_io_to_runtime(io) ((io)->substream->runtime) |
1536a968 KM |
215 | |
216 | void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); | |
217 | int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); | |
e779a20d | 218 | #define rsnd_dai_is_clk_master(rdai) ((rdai)->clk_master) |
1536a968 | 219 | |
3337744a KM |
220 | /* |
221 | * R-Car Gen1/Gen2 | |
222 | */ | |
223 | int rsnd_gen_probe(struct platform_device *pdev, | |
224 | struct rcar_snd_info *info, | |
225 | struct rsnd_priv *priv); | |
226 | void rsnd_gen_remove(struct platform_device *pdev, | |
227 | struct rsnd_priv *priv); | |
228 | int rsnd_gen_path_init(struct rsnd_priv *priv, | |
229 | struct rsnd_dai *rdai, | |
230 | struct rsnd_dai_stream *io); | |
231 | int rsnd_gen_path_exit(struct rsnd_priv *priv, | |
232 | struct rsnd_dai *rdai, | |
233 | struct rsnd_dai_stream *io); | |
234 | void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv, | |
235 | struct rsnd_mod *mod, | |
236 | enum rsnd_reg reg); | |
c5d5a58d KM |
237 | #define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1) |
238 | #define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2) | |
3337744a | 239 | |
dfc9403b KM |
240 | /* |
241 | * R-Car ADG | |
242 | */ | |
243 | int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod); | |
244 | int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate); | |
245 | int rsnd_adg_probe(struct platform_device *pdev, | |
246 | struct rcar_snd_info *info, | |
247 | struct rsnd_priv *priv); | |
248 | void rsnd_adg_remove(struct platform_device *pdev, | |
249 | struct rsnd_priv *priv); | |
ef749400 KM |
250 | int rsnd_adg_set_convert_clk(struct rsnd_priv *priv, |
251 | struct rsnd_mod *mod, | |
252 | unsigned int src_rate, | |
253 | unsigned int dst_rate); | |
dfc9403b | 254 | |
1536a968 KM |
255 | /* |
256 | * R-Car sound priv | |
257 | */ | |
258 | struct rsnd_priv { | |
259 | ||
260 | struct device *dev; | |
261 | struct rcar_snd_info *info; | |
262 | spinlock_t lock; | |
263 | ||
3337744a KM |
264 | /* |
265 | * below value will be filled on rsnd_gen_probe() | |
266 | */ | |
267 | void *gen; | |
268 | ||
07539c1d KM |
269 | /* |
270 | * below value will be filled on rsnd_scu_probe() | |
271 | */ | |
272 | void *scu; | |
273 | int scu_nr; | |
274 | ||
dfc9403b KM |
275 | /* |
276 | * below value will be filled on rsnd_adg_probe() | |
277 | */ | |
278 | void *adg; | |
279 | ||
ae5c3223 KM |
280 | /* |
281 | * below value will be filled on rsnd_ssi_probe() | |
282 | */ | |
283 | void *ssiu; | |
284 | ||
1536a968 KM |
285 | /* |
286 | * below value will be filled on rsnd_dai_probe() | |
287 | */ | |
288 | struct snd_soc_dai_driver *daidrv; | |
289 | struct rsnd_dai *rdai; | |
290 | int dai_nr; | |
291 | }; | |
292 | ||
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) | |
296 | ||
07539c1d KM |
297 | /* |
298 | * R-Car SCU | |
299 | */ | |
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); | |
cdcfcac9 | 306 | bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod); |
ef749400 KM |
307 | unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv, |
308 | struct rsnd_mod *ssi_mod, | |
309 | struct snd_pcm_runtime *runtime); | |
310 | ||
07539c1d KM |
311 | #define rsnd_scu_nr(priv) ((priv)->scu_nr) |
312 | ||
ae5c3223 KM |
313 | /* |
314 | * R-Car SSI | |
315 | */ | |
316 | int rsnd_ssi_probe(struct platform_device *pdev, | |
317 | struct rcar_snd_info *info, | |
318 | struct rsnd_priv *priv); | |
319 | void rsnd_ssi_remove(struct platform_device *pdev, | |
320 | struct rsnd_priv *priv); | |
321 | struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); | |
4b4dab82 KM |
322 | struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv, |
323 | int dai_id, int is_play); | |
7b5ce975 | 324 | int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod); |
ae5c3223 | 325 | |
1536a968 | 326 | #endif |