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 | ||
379febfd KM |
73 | static void rsnd_src_soft_reset(struct rsnd_mod *mod) |
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 | */ | |
202 | adinr = rsnd_get_adinr_bit(mod, io); | |
1b7b08ef | 203 | |
75916f65 KM |
204 | /* |
205 | * SRC_IFSCR / SRC_IFSVR | |
206 | */ | |
207 | ifscr = 0; | |
208 | fsrate = 0; | |
209 | if (convert_rate) { | |
210 | ifscr = 1; | |
211 | fsrate = 0x0400000 / convert_rate * runtime->rate; | |
212 | } | |
cfcefe01 | 213 | |
75916f65 KM |
214 | /* |
215 | * SRC_SRCCR / SRC_ROUTE_MODE0 | |
216 | */ | |
217 | cr = 0x00011110; | |
218 | route = 0x0; | |
219 | if (convert_rate) { | |
220 | route = 0x1; | |
3b7843ff | 221 | |
75916f65 KM |
222 | if (rsnd_enable_sync_convert(src)) { |
223 | cr |= 0x1; | |
224 | route |= rsnd_io_is_play(io) ? | |
225 | (0x1 << 24) : (0x1 << 25); | |
226 | } | |
227 | } | |
43cb6954 | 228 | |
75916f65 KM |
229 | /* |
230 | * SRC_BSDSR / SRC_BSISR | |
231 | */ | |
232 | switch (rsnd_mod_id(mod)) { | |
233 | case 5: | |
234 | case 6: | |
235 | case 7: | |
236 | case 8: | |
237 | bsdsr = 0x02400000; /* 6 - 1/6 */ | |
238 | bsisr = 0x00100060; /* 6 - 1/6 */ | |
239 | break; | |
240 | default: | |
241 | bsdsr = 0x01800000; /* 6 - 1/6 */ | |
242 | bsisr = 0x00100060 ;/* 6 - 1/6 */ | |
243 | break; | |
244 | } | |
1b7b08ef | 245 | |
75916f65 KM |
246 | rsnd_mod_write(mod, SRC_SRCIR, 1); /* initialize */ |
247 | rsnd_mod_write(mod, SRC_ADINR, adinr); | |
248 | rsnd_mod_write(mod, SRC_IFSCR, ifscr); | |
249 | rsnd_mod_write(mod, SRC_IFSVR, fsrate); | |
250 | rsnd_mod_write(mod, SRC_SRCCR, cr); | |
251 | rsnd_mod_write(mod, SRC_BSDSR, bsdsr); | |
252 | rsnd_mod_write(mod, SRC_BSISR, bsisr); | |
253 | rsnd_mod_write(mod, SRC_SRCIR, 0); /* cancel initialize */ | |
1b7b08ef | 254 | |
75916f65 KM |
255 | rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); |
256 | rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); | |
257 | rsnd_mod_write(mod, SRC_BUSIF_DALIGN, rsnd_get_dalign(mod, io)); | |
1b7b08ef | 258 | |
75916f65 KM |
259 | if (convert_rate) |
260 | rsnd_adg_set_convert_clk_gen2(mod, io, | |
261 | runtime->rate, | |
262 | convert_rate); | |
263 | else | |
264 | rsnd_adg_set_convert_timing_gen2(mod, io); | |
1b7b08ef KM |
265 | } |
266 | ||
75916f65 KM |
267 | #define rsnd_src_irq_enable(mod) rsnd_src_irq_ctrol(mod, 1) |
268 | #define rsnd_src_irq_disable(mod) rsnd_src_irq_ctrol(mod, 0) | |
269 | static void rsnd_src_irq_ctrol(struct rsnd_mod *mod, int enable) | |
cfcefe01 KM |
270 | { |
271 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
272 | u32 sys_int_val, int_val, sys_int_mask; | |
adf6a681 | 273 | int irq = src->irq; |
cfcefe01 KM |
274 | int id = rsnd_mod_id(mod); |
275 | ||
276 | sys_int_val = | |
277 | sys_int_mask = OUF_SRC(id); | |
278 | int_val = 0x3300; | |
279 | ||
280 | /* | |
281 | * IRQ is not supported on non-DT | |
282 | * see | |
75916f65 | 283 | * rsnd_src_probe_() |
cfcefe01 KM |
284 | */ |
285 | if ((irq <= 0) || !enable) { | |
286 | sys_int_val = 0; | |
287 | int_val = 0; | |
288 | } | |
289 | ||
1a1bf58a KM |
290 | /* |
291 | * WORKAROUND | |
292 | * | |
293 | * ignore over flow error when rsnd_enable_sync_convert() | |
294 | */ | |
295 | if (rsnd_enable_sync_convert(src)) | |
296 | sys_int_val = sys_int_val & 0xffff; | |
297 | ||
cfcefe01 KM |
298 | rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); |
299 | rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); | |
300 | rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); | |
301 | } | |
302 | ||
8cc225f7 | 303 | static void rsnd_src_status_clear(struct rsnd_mod *mod) |
cfcefe01 KM |
304 | { |
305 | u32 val = OUF_SRC(rsnd_mod_id(mod)); | |
306 | ||
307 | rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); | |
308 | rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); | |
309 | } | |
310 | ||
8cc225f7 | 311 | static bool rsnd_src_record_error(struct rsnd_mod *mod) |
cfcefe01 | 312 | { |
1a1bf58a KM |
313 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
314 | u32 val0, val1; | |
cfcefe01 KM |
315 | bool ret = false; |
316 | ||
1a1bf58a KM |
317 | val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); |
318 | ||
319 | /* | |
320 | * WORKAROUND | |
321 | * | |
322 | * ignore over flow error when rsnd_enable_sync_convert() | |
323 | */ | |
324 | if (rsnd_enable_sync_convert(src)) | |
325 | val0 = val0 & 0xffff; | |
326 | ||
327 | if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) || | |
328 | (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) { | |
cfcefe01 KM |
329 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
330 | ||
331 | src->err++; | |
332 | ret = true; | |
333 | } | |
334 | ||
cfcefe01 KM |
335 | return ret; |
336 | } | |
337 | ||
75916f65 KM |
338 | static int rsnd_src_start(struct rsnd_mod *mod, |
339 | struct rsnd_dai_stream *io, | |
340 | struct rsnd_priv *priv) | |
cfcefe01 | 341 | { |
1a1bf58a KM |
342 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
343 | u32 val; | |
344 | ||
345 | /* | |
346 | * WORKAROUND | |
347 | * | |
348 | * Enable SRC output if you want to use sync convert together with DVC | |
349 | */ | |
350 | val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ? | |
351 | 0x01 : 0x11; | |
cfcefe01 KM |
352 | |
353 | rsnd_mod_write(mod, SRC_CTRL, val); | |
354 | ||
cfcefe01 KM |
355 | return 0; |
356 | } | |
357 | ||
75916f65 KM |
358 | static int rsnd_src_stop(struct rsnd_mod *mod, |
359 | struct rsnd_dai_stream *io, | |
360 | struct rsnd_priv *priv) | |
cfcefe01 | 361 | { |
b761bf27 KM |
362 | /* |
363 | * stop SRC output only | |
75916f65 | 364 | * see rsnd_src_quit |
b761bf27 KM |
365 | */ |
366 | rsnd_mod_write(mod, SRC_CTRL, 0x01); | |
cfcefe01 | 367 | |
75916f65 KM |
368 | return 0; |
369 | } | |
370 | ||
371 | static int rsnd_src_init(struct rsnd_mod *mod, | |
372 | struct rsnd_dai_stream *io, | |
373 | struct rsnd_priv *priv) | |
374 | { | |
375 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
cfcefe01 | 376 | |
75916f65 KM |
377 | rsnd_mod_power_on(mod); |
378 | ||
379 | rsnd_src_soft_reset(mod); | |
380 | ||
381 | rsnd_src_set_convert_rate(io, mod); | |
382 | ||
8cc225f7 | 383 | rsnd_src_status_clear(mod); |
75916f65 KM |
384 | |
385 | rsnd_src_irq_enable(mod); | |
386 | ||
387 | src->err = 0; | |
388 | ||
389 | /* reset sync convert_rate */ | |
390 | src->sync.val = 0; | |
391 | ||
392 | return 0; | |
cfcefe01 KM |
393 | } |
394 | ||
75916f65 KM |
395 | static int rsnd_src_quit(struct rsnd_mod *mod, |
396 | struct rsnd_dai_stream *io, | |
397 | struct rsnd_priv *priv) | |
b761bf27 | 398 | { |
75916f65 KM |
399 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
400 | struct device *dev = rsnd_priv_to_dev(priv); | |
401 | ||
402 | rsnd_src_irq_disable(mod); | |
403 | ||
b761bf27 KM |
404 | /* stop both out/in */ |
405 | rsnd_mod_write(mod, SRC_CTRL, 0); | |
406 | ||
75916f65 KM |
407 | rsnd_mod_power_off(mod); |
408 | ||
409 | if (src->err) | |
410 | dev_warn(dev, "%s[%d] under/over flow err = %d\n", | |
411 | rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); | |
412 | ||
413 | src->convert_rate = 0; | |
414 | ||
415 | /* reset sync convert_rate */ | |
416 | src->sync.val = 0; | |
417 | ||
418 | return 0; | |
b761bf27 KM |
419 | } |
420 | ||
75916f65 KM |
421 | static void __rsnd_src_interrupt(struct rsnd_mod *mod, |
422 | struct rsnd_dai_stream *io) | |
cfcefe01 | 423 | { |
02299d98 | 424 | struct rsnd_priv *priv = rsnd_mod_to_priv(mod); |
69e32a58 KM |
425 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
426 | struct device *dev = rsnd_priv_to_dev(priv); | |
02299d98 KM |
427 | |
428 | spin_lock(&priv->lock); | |
cfcefe01 | 429 | |
02299d98 | 430 | /* ignore all cases if not working */ |
d5bbe7de | 431 | if (!rsnd_io_is_working(io)) |
75916f65 | 432 | goto rsnd_src_interrupt_out; |
cfcefe01 | 433 | |
8cc225f7 | 434 | if (rsnd_src_record_error(mod)) { |
cfcefe01 | 435 | |
cfcefe01 KM |
436 | dev_dbg(dev, "%s[%d] restart\n", |
437 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | |
639b231f | 438 | |
75916f65 KM |
439 | rsnd_src_stop(mod, io, priv); |
440 | rsnd_src_start(mod, io, priv); | |
69e32a58 KM |
441 | } |
442 | ||
443 | if (src->err > 1024) { | |
75916f65 | 444 | rsnd_src_irq_disable(mod); |
69e32a58 KM |
445 | |
446 | dev_warn(dev, "no more %s[%d] restart\n", | |
447 | rsnd_mod_name(mod), rsnd_mod_id(mod)); | |
cfcefe01 | 448 | } |
88c61cff | 449 | |
8cc225f7 | 450 | rsnd_src_status_clear(mod); |
75916f65 | 451 | rsnd_src_interrupt_out: |
8cc225f7 | 452 | |
02299d98 | 453 | spin_unlock(&priv->lock); |
88c61cff KM |
454 | } |
455 | ||
75916f65 | 456 | static irqreturn_t rsnd_src_interrupt(int irq, void *data) |
88c61cff KM |
457 | { |
458 | struct rsnd_mod *mod = data; | |
459 | ||
75916f65 | 460 | rsnd_mod_interrupt(mod, __rsnd_src_interrupt); |
cfcefe01 KM |
461 | |
462 | return IRQ_HANDLED; | |
463 | } | |
464 | ||
75916f65 KM |
465 | static int rsnd_src_probe_(struct rsnd_mod *mod, |
466 | struct rsnd_dai_stream *io, | |
467 | struct rsnd_priv *priv) | |
76c6fb5c | 468 | { |
ba9c949f | 469 | struct rsnd_src *src = rsnd_mod_to_src(mod); |
76c6fb5c | 470 | struct device *dev = rsnd_priv_to_dev(priv); |
adf6a681 | 471 | int irq = src->irq; |
76c6fb5c | 472 | int ret; |
76c6fb5c | 473 | |
cfcefe01 KM |
474 | if (irq > 0) { |
475 | /* | |
476 | * IRQ is not supported on non-DT | |
477 | * see | |
75916f65 | 478 | * rsnd_src_irq_enable() |
cfcefe01 KM |
479 | */ |
480 | ret = devm_request_irq(dev, irq, | |
75916f65 | 481 | rsnd_src_interrupt, |
cfcefe01 KM |
482 | IRQF_SHARED, |
483 | dev_name(dev), mod); | |
484 | if (ret) | |
b543b52a | 485 | return ret; |
cfcefe01 KM |
486 | } |
487 | ||
adf6a681 | 488 | src->dma = rsnd_dma_attach(io, mod, 0); |
232c00b6 KM |
489 | if (IS_ERR(src->dma)) |
490 | return PTR_ERR(src->dma); | |
8aefda50 | 491 | |
76c6fb5c KM |
492 | return ret; |
493 | } | |
494 | ||
75916f65 | 495 | static int rsnd_src_pcm_new(struct rsnd_mod *mod, |
2c0fac19 | 496 | struct rsnd_dai_stream *io, |
43cb6954 KM |
497 | struct snd_soc_pcm_runtime *rtd) |
498 | { | |
43cb6954 KM |
499 | struct rsnd_dai *rdai = rsnd_io_to_rdai(io); |
500 | struct rsnd_src *src = rsnd_mod_to_src(mod); | |
501 | int ret; | |
502 | ||
503 | /* | |
504 | * enable SRC sync convert if possible | |
505 | */ | |
506 | ||
43cb6954 KM |
507 | /* |
508 | * SRC sync convert needs clock master | |
509 | */ | |
510 | if (!rsnd_rdai_is_clk_master(rdai)) | |
511 | return 0; | |
512 | ||
43cb6954 KM |
513 | /* |
514 | * enable sync convert | |
515 | */ | |
b65a7ccc | 516 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
43cb6954 KM |
517 | rsnd_io_is_play(io) ? |
518 | "SRC Out Rate Switch" : | |
519 | "SRC In Rate Switch", | |
75916f65 | 520 | rsnd_src_set_convert_rate, |
43cb6954 KM |
521 | &src->sen, 1); |
522 | if (ret < 0) | |
523 | return ret; | |
524 | ||
b65a7ccc | 525 | ret = rsnd_kctrl_new_s(mod, io, rtd, |
43cb6954 KM |
526 | rsnd_io_is_play(io) ? |
527 | "SRC Out Rate" : | |
528 | "SRC In Rate", | |
75916f65 | 529 | rsnd_src_set_convert_rate, |
43cb6954 KM |
530 | &src->sync, 192000); |
531 | ||
532 | return ret; | |
533 | } | |
534 | ||
75916f65 | 535 | static struct rsnd_mod_ops rsnd_src_ops = { |
8aefda50 | 536 | .name = SRC_NAME, |
72adc61f | 537 | .dma_req = rsnd_src_dma_req, |
75916f65 KM |
538 | .probe = rsnd_src_probe_, |
539 | .init = rsnd_src_init, | |
540 | .quit = rsnd_src_quit, | |
541 | .start = rsnd_src_start, | |
542 | .stop = rsnd_src_stop, | |
3b7843ff | 543 | .hw_params = rsnd_src_hw_params, |
75916f65 | 544 | .pcm_new = rsnd_src_pcm_new, |
629509c5 KM |
545 | }; |
546 | ||
ba9c949f | 547 | struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) |
07539c1d | 548 | { |
ba9c949f | 549 | if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) |
8b14719b | 550 | id = 0; |
07539c1d | 551 | |
adf6a681 | 552 | return rsnd_mod_get(rsnd_src_get(priv, id)); |
90e8e50f KM |
553 | } |
554 | ||
2ea6b074 | 555 | int rsnd_src_probe(struct rsnd_priv *priv) |
07539c1d | 556 | { |
adf6a681 KM |
557 | struct device_node *node; |
558 | struct device_node *np; | |
07539c1d | 559 | struct device *dev = rsnd_priv_to_dev(priv); |
ba9c949f | 560 | struct rsnd_src *src; |
ef749400 | 561 | struct clk *clk; |
ba9c949f | 562 | char name[RSND_SRC_NAME_SIZE]; |
2f78dd7f | 563 | int i, nr, ret; |
07539c1d | 564 | |
e8e7b7bd KM |
565 | /* This driver doesn't support Gen1 at this point */ |
566 | if (rsnd_is_gen1(priv)) | |
567 | return 0; | |
033e7ed8 | 568 | |
adf6a681 KM |
569 | node = rsnd_src_of_node(priv); |
570 | if (!node) | |
571 | return 0; /* not used is not error */ | |
90e8e50f | 572 | |
adf6a681 KM |
573 | nr = of_get_child_count(node); |
574 | if (!nr) { | |
575 | ret = -EINVAL; | |
576 | goto rsnd_src_probe_done; | |
577 | } | |
389933d9 | 578 | |
ba9c949f | 579 | src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); |
adf6a681 KM |
580 | if (!src) { |
581 | ret = -ENOMEM; | |
582 | goto rsnd_src_probe_done; | |
583 | } | |
07539c1d | 584 | |
ba9c949f KM |
585 | priv->src_nr = nr; |
586 | priv->src = src; | |
07539c1d | 587 | |
adf6a681 KM |
588 | i = 0; |
589 | for_each_child_of_node(node, np) { | |
590 | src = rsnd_src_get(priv, i); | |
591 | ||
8aefda50 KM |
592 | snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", |
593 | SRC_NAME, i); | |
ef749400 | 594 | |
adf6a681 KM |
595 | src->irq = irq_of_parse_and_map(np, 0); |
596 | if (!src->irq) { | |
597 | ret = -EINVAL; | |
598 | goto rsnd_src_probe_done; | |
599 | } | |
ef749400 | 600 | |
adf6a681 KM |
601 | clk = devm_clk_get(dev, name); |
602 | if (IS_ERR(clk)) { | |
603 | ret = PTR_ERR(clk); | |
604 | goto rsnd_src_probe_done; | |
605 | } | |
07539c1d | 606 | |
e8e7b7bd | 607 | ret = rsnd_mod_init(priv, rsnd_mod_get(src), |
75916f65 | 608 | &rsnd_src_ops, clk, RSND_MOD_SRC, i); |
2f78dd7f | 609 | if (ret) |
adf6a681 KM |
610 | goto rsnd_src_probe_done; |
611 | ||
612 | i++; | |
374a5281 | 613 | } |
07539c1d | 614 | |
adf6a681 KM |
615 | ret = 0; |
616 | ||
617 | rsnd_src_probe_done: | |
618 | of_node_put(node); | |
619 | ||
620 | return ret; | |
07539c1d | 621 | } |
2f78dd7f | 622 | |
2ea6b074 | 623 | void rsnd_src_remove(struct rsnd_priv *priv) |
2f78dd7f KM |
624 | { |
625 | struct rsnd_src *src; | |
626 | int i; | |
627 | ||
628 | for_each_rsnd_src(src, priv, i) { | |
b76e218a | 629 | rsnd_mod_quit(rsnd_mod_get(src)); |
2f78dd7f KM |
630 | } |
631 | } |