Commit | Line | Data |
---|---|---|
07539c1d | 1 | /* |
ba9c949f | 2 | * Renesas R-Car SRC support |
07539c1d KM |
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 | #include "rsnd.h" | |
12 | ||
8aefda50 KM |
13 | #define SRC_NAME "src" |
14 | ||
cfcefe01 KM |
15 | /* SRCx_STATUS */ |
16 | #define OUF_SRCO ((1 << 12) | (1 << 13)) | |
17 | #define OUF_SRCI ((1 << 9) | (1 << 8)) | |
18 | ||
19 | /* SCU_SYSTEM_STATUS0/1 */ | |
20 | #define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) | |
21 | ||
ba9c949f | 22 | struct rsnd_src { |
07539c1d | 23 | struct rsnd_mod mod; |
940e9479 | 24 | struct rsnd_mod *dma; |
43cb6954 KM |
25 | struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ |
26 | struct rsnd_kctrl_cfg_s sync; /* sync convert */ | |
3b7843ff | 27 | u32 convert_rate; /* sampling rate convert */ |
cfcefe01 | 28 | int err; |
adf6a681 | 29 | int irq; |
07539c1d KM |
30 | }; |
31 | ||
ba9c949f | 32 | #define RSND_SRC_NAME_SIZE 16 |
374a5281 | 33 | |
adf6a681 | 34 | #define rsnd_src_get(priv, id) ((struct rsnd_src *)(priv->src) + id) |
232c00b6 | 35 | #define rsnd_src_to_dma(src) ((src)->dma) |
da599fd3 | 36 | #define rsnd_src_nr(priv) ((priv)->src_nr) |
43cb6954 | 37 | #define rsnd_enable_sync_convert(src) ((src)->sen.val) |
82e76ed3 | 38 | |
ba9c949f KM |
39 | #define rsnd_mod_to_src(_mod) \ |
40 | container_of((_mod), struct rsnd_src, mod) | |
39cf3c40 | 41 | |
ba9c949f | 42 | #define for_each_rsnd_src(pos, priv, i) \ |
39cf3c40 | 43 | for ((i) = 0; \ |
ba9c949f KM |
44 | ((i) < rsnd_src_nr(priv)) && \ |
45 | ((pos) = (struct rsnd_src *)(priv)->src + i); \ | |
39cf3c40 KM |
46 | i++) |
47 | ||
48 | ||
ef749400 KM |
49 | /* |
50 | * image of SRC (Sampling Rate Converter) | |
51 | * | |
52 | * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ | |
53 | * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | | |
54 | * 44.1kHz <-> +-----+ +-----+ +-------+ | |
55 | * ... | |
56 | * | |
57 | */ | |
374a5281 | 58 | |
c926b746 | 59 | /* |
ba9c949f | 60 | * src.c is caring... |
c926b746 KM |
61 | * |
62 | * Gen1 | |
63 | * | |
64 | * [mem] -> [SRU] -> [SSI] | |
65 | * |--------| | |
66 | * | |
67 | * Gen2 | |
68 | * | |
ba9c949f | 69 | * [mem] -> [SRC] -> [SSIU] -> [SSI] |
c926b746 KM |
70 | * |-----------------| |
71 | */ | |
72 | ||
98efeeae | 73 | static void rsnd_src_activation(struct rsnd_mod *mod) |
379febfd KM |
74 | { |
75 | rsnd_mod_write(mod, SRC_SWRSR, 0); | |
76 | rsnd_mod_write(mod, SRC_SWRSR, 1); | |
77 | } | |
78 | ||
9b99e9a7 KM |
79 | static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, |
80 | struct rsnd_mod *mod) | |
72adc61f KM |
81 | { |
82 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); | |
72adc61f KM |
83 | int is_play = rsnd_io_is_play(io); |
84 | ||
85 | return rsnd_dma_request_channel(rsnd_src_of_node(priv), | |
86 | mod, | |
87 | is_play ? "rx" : "tx"); | |
88 | } | |
89 | ||
88c61cff KM |
90 | static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io, |
91 | struct rsnd_src *src) | |
43cb6954 | 92 | { |
43cb6954 KM |
93 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); |
94 | u32 convert_rate; | |
95 | ||
96 | if (!runtime) | |
97 | return 0; | |
98 | ||
99 | if (!rsnd_enable_sync_convert(src)) | |
100 | return src->convert_rate; | |
101 | ||
102 | convert_rate = src->sync.val; | |
103 | ||
104 | if (!convert_rate) | |
105 | convert_rate = src->convert_rate; | |
106 | ||
107 | if (!convert_rate) | |
108 | convert_rate = runtime->rate; | |
109 | ||
110 | return convert_rate; | |
111 | } | |
112 | ||
ba9c949f | 113 | unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, |
374e5426 | 114 | struct rsnd_dai_stream *io, |
1b7b08ef KM |
115 | struct snd_pcm_runtime *runtime) |
116 | { | |
b1eac430 | 117 | struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); |
ba9c949f | 118 | struct rsnd_src *src; |
b1eac430 | 119 | unsigned int rate = 0; |
1b7b08ef | 120 | |
b1eac430 KM |
121 | if (src_mod) { |
122 | src = rsnd_mod_to_src(src_mod); | |
123 | ||
124 | /* | |
125 | * return convert rate if SRC is used, | |
126 | * otherwise, return runtime->rate as usual | |
127 | */ | |
88c61cff | 128 | rate = rsnd_src_convert_rate(io, src); |
b1eac430 | 129 | } |
1b7b08ef | 130 | |
1b7b08ef KM |
131 | if (!rate) |
132 | rate = runtime->rate; | |
133 | ||
134 | return rate; | |
135 | } | |
136 | ||
3b7843ff | 137 | static int rsnd_src_hw_params(struct rsnd_mod *mod, |
2c0fac19 | 138 | struct rsnd_dai_stream *io, |
3b7843ff KM |
139 | struct snd_pcm_substream *substream, |
140 | struct snd_pcm_hw_params *fe_params) | |
141 | { | |
142 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
143 | struct snd_soc_pcm_runtime *fe = substream->private_data; | |
144 | ||
3b7843ff KM |
145 | /* |
146 | * SRC assumes that it is used under DPCM if user want to use | |
147 | * sampling rate convert. Then, SRC should be FE. | |
148 | * And then, this function will be called *after* BE settings. | |
149 | * this means, each BE already has fixuped hw_params. | |
150 | * see | |
151 | * dpcm_fe_dai_hw_params() | |
152 | * dpcm_be_dai_hw_params() | |
153 | */ | |
154 | if (fe->dai_link->dynamic) { | |
155 | int stream = substream->stream; | |
156 | struct snd_soc_dpcm *dpcm; | |
157 | struct snd_pcm_hw_params *be_params; | |
158 | ||
159 | list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { | |
160 | be_params = &dpcm->hw_params; | |
161 | ||
162 | if (params_rate(fe_params) != params_rate(be_params)) | |
163 | src->convert_rate = params_rate(be_params); | |
164 | } | |
165 | } | |
166 | ||
167 | return 0; | |
168 | } | |
169 | ||
75916f65 KM |
170 | static void rsnd_src_set_convert_rate(struct rsnd_dai_stream *io, |
171 | struct rsnd_mod *mod) | |
1b7b08ef | 172 | { |
75916f65 KM |
173 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
174 | struct device *dev = rsnd_priv_to_dev(priv); | |
175 | struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); | |
ba9c949f | 176 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
75916f65 KM |
177 | u32 convert_rate = rsnd_src_convert_rate(io, src); |
178 | u32 ifscr, fsrate, adinr; | |
179 | u32 cr, route; | |
180 | u32 bsdsr, bsisr; | |
181 | uint ratio; | |
1b7b08ef | 182 | |
75916f65 KM |
183 | if (!runtime) |
184 | return; | |
43cb6954 | 185 | |
75916f65 KM |
186 | /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ |
187 | if (!convert_rate) | |
188 | ratio = 0; | |
189 | else if (convert_rate > runtime->rate) | |
190 | ratio = 100 * convert_rate / runtime->rate; | |
191 | else | |
192 | ratio = 100 * runtime->rate / convert_rate; | |
1b7b08ef | 193 | |
75916f65 KM |
194 | if (ratio > 600) { |
195 | dev_err(dev, "FSO/FSI ratio error\n"); | |
196 | return; | |
197 | } | |
1b7b08ef | 198 | |
75916f65 KM |
199 | /* |
200 | * SRC_ADINR | |
201 | */ | |
c45f7263 KM |
202 | adinr = rsnd_get_adinr_bit(mod, io) | |
203 | rsnd_get_adinr_chan(mod, io); | |
1b7b08ef | 204 | |
75916f65 KM |
205 | /* |
206 | * SRC_IFSCR / SRC_IFSVR | |
207 | */ | |
208 | ifscr = 0; | |
209 | fsrate = 0; | |
210 | if (convert_rate) { | |
211 | ifscr = 1; | |
212 | fsrate = 0x0400000 / convert_rate * runtime->rate; | |
213 | } | |
cfcefe01 | 214 | |
75916f65 KM |
215 | /* |
216 | * SRC_SRCCR / SRC_ROUTE_MODE0 | |
217 | */ | |
218 | cr = 0x00011110; | |
219 | route = 0x0; | |
220 | if (convert_rate) { | |
221 | route = 0x1; | |
3b7843ff | 222 | |
75916f65 KM |
223 | if (rsnd_enable_sync_convert(src)) { |
224 | cr |= 0x1; | |
225 | route |= rsnd_io_is_play(io) ? | |
226 | (0x1 << 24) : (0x1 << 25); | |
227 | } | |
228 | } | |
43cb6954 | 229 | |
75916f65 KM |
230 | /* |
231 | * SRC_BSDSR / SRC_BSISR | |
232 | */ | |
233 | switch (rsnd_mod_id(mod)) { | |
234 | case 5: | |
235 | case 6: | |
236 | case 7: | |
237 | case 8: | |
238 | bsdsr = 0x02400000; /* 6 - 1/6 */ | |
239 | bsisr = 0x00100060; /* 6 - 1/6 */ | |
240 | break; | |
241 | default: | |
242 | bsdsr = 0x01800000; /* 6 - 1/6 */ | |
243 | bsisr = 0x00100060 ;/* 6 - 1/6 */ | |
244 | break; | |
245 | } | |
1b7b08ef | 246 | |
75916f65 KM |
247 | rsnd_mod_write(mod, SRC_SRCIR, 1); /* initialize */ |
248 | rsnd_mod_write(mod, SRC_ADINR, adinr); | |
249 | rsnd_mod_write(mod, SRC_IFSCR, ifscr); | |
250 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); | |
251 | rsnd_mod_write(mod, SRC_SRCCR, cr); | |
252 | rsnd_mod_write(mod, SRC_BSDSR, bsdsr); | |
253 | rsnd_mod_write(mod, SRC_BSISR, bsisr); | |
254 | rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */ | |
1b7b08ef | 255 | |
75916f65 | 256 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); |
bf4e8d7c KM |
257 | rsnd_mod_write(mod, SRC_I_BUSIF_MODE, 1); |
258 | rsnd_mod_write(mod, SRC_O_BUSIF_MODE, 1); | |
75916f65 | 259 | rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io)); |
1b7b08ef | 260 | |
75916f65 KM |
261 | if (convert_rate) |
262 | rsnd_adg_set_convert_clk_gen2(mod, io, | |
263 | runtime->rate, | |
264 | convert_rate); | |
265 | else | |
266 | rsnd_adg_set_convert_timing_gen2(mod, io); | |
1b7b08ef KM |
267 | } |
268 | ||
75916f65 KM |
269 | #define rsnd_src_irq_enable(mod) rsnd_src_irq_ctrol(mod, 1) |
270 | #define rsnd_src_irq_disable(mod) rsnd_src_irq_ctrol(mod, 0) | |
271 | static void rsnd_src_irq_ctrol(struct rsnd_mod *mod, int enable) | |
cfcefe01 KM |
272 | { |
273 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
274 | u32 sys_int_val, int_val, sys_int_mask; | |
adf6a681 | 275 | int irq = src->irq; |
cfcefe01 KM |
276 | int id = rsnd_mod_id(mod); |
277 | ||
278 | sys_int_val = | |
279 | sys_int_mask = OUF_SRC(id); | |
280 | int_val = 0x3300; | |
281 | ||
282 | /* | |
283 | * IRQ is not supported on non-DT | |
284 | * see | |
75916f65 | 285 | * rsnd_src_probe_() |
cfcefe01 KM |
286 | */ |
287 | if ((irq <= 0) || !enable) { | |
288 | sys_int_val = 0; | |
289 | int_val = 0; | |
290 | } | |
291 | ||
1a1bf58a KM |
292 | /* |
293 | * WORKAROUND | |
294 | * | |
295 | * ignore over flow error when rsnd_enable_sync_convert() | |
296 | */ | |
297 | if (rsnd_enable_sync_convert(src)) | |
298 | sys_int_val = sys_int_val & 0xffff; | |
299 | ||
cfcefe01 KM |
300 | rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); |
301 | rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); | |
302 | rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); | |
303 | } | |
304 | ||
8cc225f7 | 305 | static void rsnd_src_status_clear(struct rsnd_mod *mod) |
cfcefe01 KM |
306 | { |
307 | u32 val = OUF_SRC(rsnd_mod_id(mod)); | |
308 | ||
309 | rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); | |
310 | rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); | |
311 | } | |
312 | ||
8cc225f7 | 313 | static bool rsnd_src_record_error(struct rsnd_mod *mod) |
cfcefe01 | 314 | { |
1a1bf58a KM |
315 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
316 | u32 val0, val1; | |
cfcefe01 KM |
317 | bool ret = false; |
318 | ||
1a1bf58a KM |
319 | val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); |
320 | ||
321 | /* | |
322 | * WORKAROUND | |
323 | * | |
324 | * ignore over flow error when rsnd_enable_sync_convert() | |
325 | */ | |
326 | if (rsnd_enable_sync_convert(src)) | |
327 | val0 = val0 & 0xffff; | |
328 | ||
329 | if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) || | |
330 | (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) { | |
cfcefe01 KM |
331 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
332 | ||
333 | src->err++; | |
334 | ret = true; | |
335 | } | |
336 | ||
cfcefe01 KM |
337 | return ret; |
338 | } | |
339 | ||
75916f65 KM |
340 | static int rsnd_src_start(struct rsnd_mod *mod, |
341 | struct rsnd_dai_stream *io, | |
342 | struct rsnd_priv *priv) | |
cfcefe01 | 343 | { |
1a1bf58a KM |
344 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
345 | u32 val; | |
346 | ||
347 | /* | |
348 | * WORKAROUND | |
349 | * | |
350 | * Enable SRC output if you want to use sync convert together with DVC | |
351 | */ | |
352 | val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ? | |
353 | 0x01 : 0x11; | |
cfcefe01 KM |
354 | |
355 | rsnd_mod_write(mod, SRC_CTRL, val); | |
356 | ||
cfcefe01 KM |
357 | return 0; |
358 | } | |
359 | ||
75916f65 KM |
360 | static int rsnd_src_stop(struct rsnd_mod *mod, |
361 | struct rsnd_dai_stream *io, | |
362 | struct rsnd_priv *priv) | |
cfcefe01 | 363 | { |
b761bf27 KM |
364 | /* |
365 | * stop SRC output only | |
75916f65 | 366 | * see rsnd_src_quit |
b761bf27 KM |
367 | */ |
368 | rsnd_mod_write(mod, SRC_CTRL, 0x01); | |
cfcefe01 | 369 | |
75916f65 KM |
370 | return 0; |
371 | } | |
372 | ||
373 | static int rsnd_src_init(struct rsnd_mod *mod, | |
374 | struct rsnd_dai_stream *io, | |
375 | struct rsnd_priv *priv) | |
376 | { | |
377 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
cfcefe01 | 378 | |
75916f65 KM |
379 | rsnd_mod_power_on(mod); |
380 | ||
98efeeae | 381 | rsnd_src_activation(mod); |
75916f65 KM |
382 | |
383 | rsnd_src_set_convert_rate(io, mod); | |
384 | ||
8cc225f7 | 385 | rsnd_src_status_clear(mod); |
75916f65 KM |
386 | |
387 | rsnd_src_irq_enable(mod); | |
388 | ||
389 | src->err = 0; | |
390 | ||
391 | /* reset sync convert_rate */ | |
392 | src->sync.val = 0; | |
393 | ||
394 | return 0; | |
cfcefe01 KM |
395 | } |
396 | ||
75916f65 KM |
397 | static int rsnd_src_quit(struct rsnd_mod *mod, |
398 | struct rsnd_dai_stream *io, | |
399 | struct rsnd_priv *priv) | |
b761bf27 | 400 | { |
75916f65 KM |
401 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
402 | struct device *dev = rsnd_priv_to_dev(priv); | |
403 | ||
404 | rsnd_src_irq_disable(mod); | |
405 | ||
b761bf27 KM |
406 | /* stop both out/in */ |
407 | rsnd_mod_write(mod, SRC_CTRL, 0); | |
408 | ||
75916f65 KM |
409 | rsnd_mod_power_off(mod); |
410 | ||
411 | if (src->err) | |
412 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", | |
413 | rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); | |
414 | ||
415 | src->convert_rate = 0; | |
416 | ||
417 | /* reset sync convert_rate */ | |
418 | src->sync.val = 0; | |
419 | ||
420 | return 0; | |
b761bf27 KM |
421 | } |
422 | ||
75916f65 KM |
423 | static void __rsnd_src_interrupt(struct rsnd_mod *mod, |
424 | struct rsnd_dai_stream *io) | |
cfcefe01 | 425 | { |
02299d98 | 426 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
69e32a58 KM |
427 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
428 | struct device *dev = rsnd_priv_to_dev(priv); | |
02299d98 KM |
429 | |
430 | spin_lock(&priv->lock); | |
cfcefe01 | 431 | |
02299d98 | 432 | /* ignore all cases if not working */ |
d5bbe7de | 433 | if (!rsnd_io_is_working(io)) |
75916f65 | 434 | goto rsnd_src_interrupt_out; |
cfcefe01 | 435 | |
8cc225f7 | 436 | if (rsnd_src_record_error(mod)) { |
cfcefe01 | 437 | |
cfcefe01 KM |
438 | dev_dbg(dev, "%s[%d] restart\n", |
439 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | |
639b231f | 440 | |
75916f65 KM |
441 | rsnd_src_stop(mod, io, priv); |
442 | rsnd_src_start(mod, io, priv); | |
69e32a58 KM |
443 | } |
444 | ||
445 | if (src->err > 1024) { | |
75916f65 | 446 | rsnd_src_irq_disable(mod); |
69e32a58 KM |
447 | |
448 | dev_warn(dev, "no more %s[%d] restart\n", | |
449 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | |
cfcefe01 | 450 | } |
88c61cff | 451 | |
8cc225f7 | 452 | rsnd_src_status_clear(mod); |
75916f65 | 453 | rsnd_src_interrupt_out: |
8cc225f7 | 454 | |
02299d98 | 455 | spin_unlock(&priv->lock); |
88c61cff KM |
456 | } |
457 | ||
75916f65 | 458 | static irqreturn_t rsnd_src_interrupt(int irq, void *data) |
88c61cff KM |
459 | { |
460 | struct rsnd_mod *mod = data; | |
461 | ||
75916f65 | 462 | rsnd_mod_interrupt(mod, __rsnd_src_interrupt); |
cfcefe01 KM |
463 | |
464 | return IRQ_HANDLED; | |
465 | } | |
466 | ||
75916f65 KM |
467 | static int rsnd_src_probe_(struct rsnd_mod *mod, |
468 | struct rsnd_dai_stream *io, | |
469 | struct rsnd_priv *priv) | |
76c6fb5c | 470 | { |
ba9c949f | 471 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
76c6fb5c | 472 | struct device *dev = rsnd_priv_to_dev(priv); |
adf6a681 | 473 | int irq = src->irq; |
76c6fb5c | 474 | int ret; |
76c6fb5c | 475 | |
cfcefe01 KM |
476 | if (irq > 0) { |
477 | /* | |
478 | * IRQ is not supported on non-DT | |
479 | * see | |
75916f65 | 480 | * rsnd_src_irq_enable() |
cfcefe01 KM |
481 | */ |
482 | ret = devm_request_irq(dev, irq, | |
75916f65 | 483 | rsnd_src_interrupt, |
cfcefe01 KM |
484 | IRQF_SHARED, |
485 | dev_name(dev), mod); | |
486 | if (ret) | |
b543b52a | 487 | return ret; |
cfcefe01 KM |
488 | } |
489 | ||
adf6a681 | 490 | src->dma = rsnd_dma_attach(io, mod, 0); |
232c00b6 KM |
491 | if (IS_ERR(src->dma)) |
492 | return PTR_ERR(src->dma); | |
8aefda50 | 493 | |
76c6fb5c KM |
494 | return ret; |
495 | } | |
496 | ||
75916f65 | 497 | static int rsnd_src_pcm_new(struct rsnd_mod *mod, |
2c0fac19 | 498 | struct rsnd_dai_stream *io, |
43cb6954 KM |
499 | struct snd_soc_pcm_runtime *rtd) |
500 | { | |
43cb6954 KM |
501 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
502 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
503 | int ret; | |
504 | ||
505 | /* | |
506 | * enable SRC sync convert if possible | |
507 | */ | |
508 | ||
43cb6954 KM |
509 | /* |
510 | * SRC sync convert needs clock master | |
511 | */ | |
512 | if (!rsnd_rdai_is_clk_master(rdai)) | |
513 | return 0; | |
514 | ||
43cb6954 KM |
515 | /* |
516 | * enable sync convert | |
517 | */ | |
b65a7ccc | 518 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
43cb6954 KM |
519 | rsnd_io_is_play(io) ? |
520 | "SRC Out Rate Switch" : | |
521 | "SRC In Rate Switch", | |
75916f65 | 522 | rsnd_src_set_convert_rate, |
43cb6954 KM |
523 | &src->sen, 1); |
524 | if (ret < 0) | |
525 | return ret; | |
526 | ||
b65a7ccc | 527 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
43cb6954 KM |
528 | rsnd_io_is_play(io) ? |
529 | "SRC Out Rate" : | |
530 | "SRC In Rate", | |
75916f65 | 531 | rsnd_src_set_convert_rate, |
43cb6954 KM |
532 | &src->sync, 192000); |
533 | ||
534 | return ret; | |
535 | } | |
536 | ||
75916f65 | 537 | static struct rsnd_mod_ops rsnd_src_ops = { |
8aefda50 | 538 | .name = SRC_NAME, |
72adc61f | 539 | .dma_req = rsnd_src_dma_req, |
75916f65 KM |
540 | .probe = rsnd_src_probe_, |
541 | .init = rsnd_src_init, | |
542 | .quit = rsnd_src_quit, | |
543 | .start = rsnd_src_start, | |
544 | .stop = rsnd_src_stop, | |
3b7843ff | 545 | .hw_params = rsnd_src_hw_params, |
75916f65 | 546 | .pcm_new = rsnd_src_pcm_new, |
629509c5 KM |
547 | }; |
548 | ||
ba9c949f | 549 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) |
07539c1d | 550 | { |
ba9c949f | 551 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
8b14719b | 552 | id = 0; |
07539c1d | 553 | |
adf6a681 | 554 | return rsnd_mod_get(rsnd_src_get(priv, id)); |
90e8e50f KM |
555 | } |
556 | ||
2ea6b074 | 557 | int rsnd_src_probe(struct rsnd_priv *priv) |
07539c1d | 558 | { |
adf6a681 KM |
559 | struct device_node *node; |
560 | struct device_node *np; | |
07539c1d | 561 | struct device *dev = rsnd_priv_to_dev(priv); |
ba9c949f | 562 | struct rsnd_src *src; |
ef749400 | 563 | struct clk *clk; |
ba9c949f | 564 | char name[RSND_SRC_NAME_SIZE]; |
2f78dd7f | 565 | int i, nr, ret; |
07539c1d | 566 | |
e8e7b7bd KM |
567 | /* This driver doesn't support Gen1 at this point */ |
568 | if (rsnd_is_gen1(priv)) | |
569 | return 0; | |
033e7ed8 | 570 | |
adf6a681 KM |
571 | node = rsnd_src_of_node(priv); |
572 | if (!node) | |
573 | return 0; /* not used is not error */ | |
90e8e50f | 574 | |
adf6a681 KM |
575 | nr = of_get_child_count(node); |
576 | if (!nr) { | |
577 | ret = -EINVAL; | |
578 | goto rsnd_src_probe_done; | |
579 | } | |
389933d9 | 580 | |
ba9c949f | 581 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
adf6a681 KM |
582 | if (!src) { |
583 | ret = -ENOMEM; | |
584 | goto rsnd_src_probe_done; | |
585 | } | |
07539c1d | 586 | |
ba9c949f KM |
587 | priv->src_nr = nr; |
588 | priv->src = src; | |
07539c1d | 589 | |
adf6a681 KM |
590 | i = 0; |
591 | for_each_child_of_node(node, np) { | |
592 | src = rsnd_src_get(priv, i); | |
593 | ||
8aefda50 KM |
594 | snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", |
595 | SRC_NAME, i); | |
ef749400 | 596 | |
adf6a681 KM |
597 | src->irq = irq_of_parse_and_map(np, 0); |
598 | if (!src->irq) { | |
599 | ret = -EINVAL; | |
600 | goto rsnd_src_probe_done; | |
601 | } | |
ef749400 | 602 | |
adf6a681 KM |
603 | clk = devm_clk_get(dev, name); |
604 | if (IS_ERR(clk)) { | |
605 | ret = PTR_ERR(clk); | |
606 | goto rsnd_src_probe_done; | |
607 | } | |
07539c1d | 608 | |
e8e7b7bd | 609 | ret = rsnd_mod_init(priv, rsnd_mod_get(src), |
75916f65 | 610 | &rsnd_src_ops, clk, RSND_MOD_SRC, i); |
2f78dd7f | 611 | if (ret) |
adf6a681 KM |
612 | goto rsnd_src_probe_done; |
613 | ||
614 | i++; | |
374a5281 | 615 | } |
07539c1d | 616 | |
adf6a681 KM |
617 | ret = 0; |
618 | ||
619 | rsnd_src_probe_done: | |
620 | of_node_put(node); | |
621 | ||
622 | return ret; | |
07539c1d | 623 | } |
2f78dd7f | 624 | |
2ea6b074 | 625 | void rsnd_src_remove(struct rsnd_priv *priv) |
2f78dd7f KM |
626 | { |
627 | struct rsnd_src *src; | |
628 | int i; | |
629 | ||
630 | for_each_rsnd_src(src, priv, i) { | |
b76e218a | 631 | rsnd_mod_quit(rsnd_mod_get(src)); |
2f78dd7f KM |
632 | } |
633 | } |