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