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