blob: 6e5c763e1040b3800da2ed0b1491afec1f29977f [file] [log] [blame]
Kuninori Morimoto07539c12013-07-21 21:36:35 -07001/*
2 * Renesas R-Car SCU support
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
13struct rsnd_scu {
14 struct rsnd_scu_platform_info *info; /* rcar_snd.h */
15 struct rsnd_mod mod;
Kuninori Morimotoef749402013-12-19 19:28:51 -080016 struct clk *clk;
Kuninori Morimoto07539c12013-07-21 21:36:35 -070017};
18
Kuninori Morimotoef749402013-12-19 19:28:51 -080019#define RSND_SCU_NAME_SIZE 16
Kuninori Morimoto374a52812013-07-28 18:59:12 -070020
21/*
22 * ADINR
23 */
24#define OTBL_24 (0 << 16)
25#define OTBL_22 (2 << 16)
26#define OTBL_20 (4 << 16)
27#define OTBL_18 (6 << 16)
28#define OTBL_16 (8 << 16)
29
Kuninori Morimoto39cf3c42014-01-23 18:40:47 -080030#define rsnd_scu_mode_flags(p) ((p)->info->flags)
31#define rsnd_scu_convert_rate(p) ((p)->info->convert_rate)
32#define rsnd_mod_to_scu(_mod) \
33 container_of((_mod), struct rsnd_scu, mod)
Kuninori Morimoto96c7c0d2014-01-23 18:40:54 -080034#define rsnd_scu_hpbif_is_enable(scu) \
35 (rsnd_scu_mode_flags(scu) & RSND_SCU_USE_HPBIF)
Kuninori Morimoto629509c2014-01-23 18:42:00 -080036#define rsnd_scu_dma_available(scu) \
37 rsnd_dma_available(rsnd_mod_to_dma(&(scu)->mod))
Kuninori Morimoto39cf3c42014-01-23 18:40:47 -080038
39#define for_each_rsnd_scu(pos, priv, i) \
40 for ((i) = 0; \
41 ((i) < rsnd_scu_nr(priv)) && \
42 ((pos) = (struct rsnd_scu *)(priv)->scu + i); \
43 i++)
44
45
Kuninori Morimotoef749402013-12-19 19:28:51 -080046/*
47 * image of SRC (Sampling Rate Converter)
48 *
49 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
50 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
51 * 44.1kHz <-> +-----+ +-----+ +-------+
52 * ...
53 *
54 */
Kuninori Morimoto374a52812013-07-28 18:59:12 -070055
Kuninori Morimoto41c62212014-01-23 18:39:56 -080056/*
Kuninori Morimotoc926b742014-01-23 18:40:41 -080057 * scu.c is caring...
58 *
59 * Gen1
60 *
61 * [mem] -> [SRU] -> [SSI]
62 * |--------|
63 *
64 * Gen2
65 *
66 * [mem] -> [SCU] -> [SSIU] -> [SSI]
67 * |-----------------|
68 */
69
70/*
Kuninori Morimoto41c62212014-01-23 18:39:56 -080071 * How to use SRC bypass mode for debugging
72 *
73 * SRC has bypass mode, and it is useful for debugging.
74 * In Gen2 case,
75 * SRCm_MODE controls whether SRC is used or not
76 * SSI_MODE0 controls whether SSIU which receives SRC data
77 * is used or not.
78 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
79 * but SRC bypass mode needs SSI_MODE0 only.
80 *
81 * This driver request
82 * struct rsnd_scu_platform_info {
83 * u32 flags;
84 * u32 convert_rate;
85 * }
86 *
87 * rsnd_scu_hpbif_is_enable() will be true
88 * if flags had RSND_SCU_USE_HPBIF,
89 * and it controls whether SSIU is used or not.
90 *
91 * rsnd_scu_convert_rate() indicates
92 * above convert_rate, and it controls
93 * whether SRC is used or not.
94 *
95 * ex) doesn't use SRC
96 * struct rsnd_scu_platform_info info = {
97 * .flags = 0,
98 * .convert_rate = 0,
99 * };
100 *
101 * ex) uses SRC
102 * struct rsnd_scu_platform_info info = {
103 * .flags = RSND_SCU_USE_HPBIF,
104 * .convert_rate = 48000,
105 * };
106 *
107 * ex) uses SRC bypass mode
108 * struct rsnd_scu_platform_info info = {
109 * .flags = RSND_SCU_USE_HPBIF,
110 * .convert_rate = 0,
111 * };
112 *
113 */
114
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800115/*
116 * Gen1/Gen2 common functions
117 */
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800118static int rsnd_scu_ssi_mode_init(struct rsnd_mod *mod,
119 struct rsnd_dai *rdai,
120 struct rsnd_dai_stream *io)
121{
122 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
Kuninori Morimoto96c7c0d2014-01-23 18:40:54 -0800123 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800124 int id = rsnd_mod_id(mod);
125
126 /*
127 * SSI_MODE0
128 */
129 rsnd_mod_bset(mod, SSI_MODE0, (1 << id),
Kuninori Morimoto96c7c0d2014-01-23 18:40:54 -0800130 rsnd_scu_hpbif_is_enable(scu) ? 0 : (1 << id));
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800131
132 /*
133 * SSI_MODE1
134 */
135 if (rsnd_ssi_is_pin_sharing(rsnd_ssi_mod_get(priv, id))) {
136 int shift = -1;
137 switch (id) {
138 case 1:
139 shift = 0;
140 break;
141 case 2:
142 shift = 2;
143 break;
144 case 4:
145 shift = 16;
146 break;
147 }
148
149 if (shift >= 0)
150 rsnd_mod_bset(mod, SSI_MODE1,
151 0x3 << shift,
152 rsnd_dai_is_clk_master(rdai) ?
153 0x2 << shift : 0x1 << shift);
154 }
155
156 return 0;
157}
158
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800159unsigned int rsnd_scu_get_ssi_rate(struct rsnd_priv *priv,
160 struct rsnd_mod *ssi_mod,
161 struct snd_pcm_runtime *runtime)
162{
163 struct rsnd_scu *scu;
164 unsigned int rate;
165
166 /* this function is assuming SSI id = SCU id here */
167 scu = rsnd_mod_to_scu(rsnd_scu_mod_get(priv, rsnd_mod_id(ssi_mod)));
168
169 /*
170 * return convert rate if SRC is used,
171 * otherwise, return runtime->rate as usual
172 */
173 rate = rsnd_scu_convert_rate(scu);
174 if (!rate)
175 rate = runtime->rate;
176
177 return rate;
178}
179
180static int rsnd_scu_set_convert_rate(struct rsnd_mod *mod,
181 struct rsnd_dai *rdai,
182 struct rsnd_dai_stream *io)
183{
184 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
185 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
186 u32 convert_rate = rsnd_scu_convert_rate(scu);
187 u32 adinr = runtime->channels;
188 u32 fsrate = 0;
189
190 if (convert_rate)
191 fsrate = 0x0400000 / convert_rate * runtime->rate;
192
193 /* set/clear soft reset */
194 rsnd_mod_write(mod, SRC_SWRSR, 0);
195 rsnd_mod_write(mod, SRC_SWRSR, 1);
196
197 /*
198 * Initialize the operation of the SRC internal circuits
199 * see rsnd_scu_start()
200 */
201 rsnd_mod_write(mod, SRC_SRCIR, 1);
202
203 /* Set channel number and output bit length */
204 switch (runtime->sample_bits) {
205 case 16:
206 adinr |= OTBL_16;
207 break;
208 case 32:
209 adinr |= OTBL_24;
210 break;
211 default:
212 return -EIO;
213 }
214 rsnd_mod_write(mod, SRC_ADINR, adinr);
215
216 /* Enable the initial value of IFS */
217 if (fsrate) {
218 rsnd_mod_write(mod, SRC_IFSCR, 1);
219
220 /* Set initial value of IFS */
221 rsnd_mod_write(mod, SRC_IFSVR, fsrate);
222 }
223
224 /* use DMA transfer */
225 rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
226
227 return 0;
228}
229
230static int rsnd_scu_init(struct rsnd_mod *mod,
231 struct rsnd_dai *rdai,
232 struct rsnd_dai_stream *io)
233{
234 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
235 int ret;
236
237 clk_enable(scu->clk);
238
239 ret = rsnd_scu_ssi_mode_init(mod, rdai, io);
240 if (ret < 0)
241 return ret;
242
243 return 0;
244}
245
246static int rsnd_scu_quit(struct rsnd_mod *mod,
247 struct rsnd_dai *rdai,
248 struct rsnd_dai_stream *io)
249{
250 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
251
252 clk_disable(scu->clk);
253
254 return 0;
255}
256
257static int rsnd_scu_start(struct rsnd_mod *mod,
258 struct rsnd_dai *rdai,
259 struct rsnd_dai_stream *io)
260{
261 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
262
263 /*
264 * Cancel the initialization and operate the SRC function
265 * see rsnd_scu_set_convert_rate()
266 */
267 rsnd_mod_write(mod, SRC_SRCIR, 0);
268
269 if (rsnd_scu_convert_rate(scu))
270 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
271
272 return 0;
273}
274
275
276static int rsnd_scu_stop(struct rsnd_mod *mod,
277 struct rsnd_dai *rdai,
278 struct rsnd_dai_stream *io)
279{
280 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
281
282 if (rsnd_scu_convert_rate(scu))
283 rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
284
285 return 0;
286}
287
288static struct rsnd_mod_ops rsnd_scu_non_ops = {
289 .name = "scu (non)",
290};
291
292/*
293 * Gen1 functions
294 */
295static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
296 struct rsnd_dai *rdai,
297 struct rsnd_dai_stream *io)
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700298{
299 struct scu_route_config {
300 u32 mask;
301 int shift;
302 } routes[] = {
303 { 0xF, 0, }, /* 0 */
304 { 0xF, 4, }, /* 1 */
305 { 0xF, 8, }, /* 2 */
306 { 0x7, 12, }, /* 3 */
307 { 0x7, 16, }, /* 4 */
308 { 0x7, 20, }, /* 5 */
309 { 0x7, 24, }, /* 6 */
310 { 0x3, 28, }, /* 7 */
311 { 0x3, 30, }, /* 8 */
312 };
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700313 u32 mask;
314 u32 val;
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700315 int id;
316
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700317 id = rsnd_mod_id(mod);
Dan Carpenterb5f3d7a2013-11-08 12:46:10 +0300318 if (id < 0 || id >= ARRAY_SIZE(routes))
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700319 return -EIO;
320
321 /*
322 * SRC_ROUTE_SELECT
323 */
324 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
325 val = val << routes[id].shift;
326 mask = routes[id].mask << routes[id].shift;
327
328 rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
329
Kuninori Morimoto28dc4b62014-01-23 18:41:10 -0800330 return 0;
331}
332
333static int rsnd_scu_set_convert_timing_gen1(struct rsnd_mod *mod,
334 struct rsnd_dai *rdai,
335 struct rsnd_dai_stream *io)
336{
337 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
338 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
339 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
340 u32 convert_rate = rsnd_scu_convert_rate(scu);
341 u32 mask;
342 u32 val;
343 int shift;
344 int id = rsnd_mod_id(mod);
345 int ret;
346
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700347 /*
348 * SRC_TIMING_SELECT
349 */
350 shift = (id % 4) * 8;
351 mask = 0x1F << shift;
Kuninori Morimotoef749402013-12-19 19:28:51 -0800352
353 /*
354 * ADG is used as source clock if SRC was used,
355 * then, SSI WS is used as destination clock.
356 * SSI WS is used as source clock if SRC is not used
357 * (when playback, source/destination become reverse when capture)
358 */
Kuninori Morimoto28dc4b62014-01-23 18:41:10 -0800359 ret = 0;
360 if (convert_rate) {
361 /* use ADG */
Kuninori Morimotoef749402013-12-19 19:28:51 -0800362 val = 0;
Kuninori Morimoto28dc4b62014-01-23 18:41:10 -0800363 ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
364 runtime->rate,
365 convert_rate);
366 } else if (8 == id) {
367 /* use SSI WS, but SRU8 is special */
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700368 val = id << shift;
Kuninori Morimoto28dc4b62014-01-23 18:41:10 -0800369 } else {
370 /* use SSI WS */
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700371 val = (id + 1) << shift;
Kuninori Morimoto28dc4b62014-01-23 18:41:10 -0800372 }
373
374 if (ret < 0)
375 return ret;
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700376
377 switch (id / 4) {
378 case 0:
379 rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
380 break;
381 case 1:
382 rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
383 break;
384 case 2:
385 rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
386 break;
387 }
388
389 return 0;
390}
391
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800392static int rsnd_scu_set_convert_rate_gen1(struct rsnd_mod *mod,
393 struct rsnd_dai *rdai,
394 struct rsnd_dai_stream *io)
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700395{
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800396 int ret;
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700397
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800398 ret = rsnd_scu_set_convert_rate(mod, rdai, io);
399 if (ret < 0)
400 return ret;
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700401
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800402 /* Select SRC mode (fixed value) */
403 rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
Kuninori Morimotoef749402013-12-19 19:28:51 -0800404
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800405 /* Set the restriction value of the FS ratio (98%) */
406 rsnd_mod_write(mod, SRC_MNFSR,
407 rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700408
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800409 /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
Kuninori Morimotoef749402013-12-19 19:28:51 -0800410
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700411 return 0;
412}
413
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800414static int rsnd_scu_init_gen1(struct rsnd_mod *mod,
415 struct rsnd_dai *rdai,
416 struct rsnd_dai_stream *io)
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700417{
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700418 int ret;
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700419
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800420 ret = rsnd_scu_init(mod, rdai, io);
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800421 if (ret < 0)
422 return ret;
423
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800424 ret = rsnd_src_set_route_gen1(mod, rdai, io);
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700425 if (ret < 0)
426 return ret;
427
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800428 ret = rsnd_scu_set_convert_rate_gen1(mod, rdai, io);
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700429 if (ret < 0)
430 return ret;
431
Kuninori Morimoto28dc4b62014-01-23 18:41:10 -0800432 ret = rsnd_scu_set_convert_timing_gen1(mod, rdai, io);
433 if (ret < 0)
434 return ret;
435
Kuninori Morimotoa204d902014-01-23 18:38:33 -0800436 return 0;
437}
438
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800439static int rsnd_scu_start_gen1(struct rsnd_mod *mod,
440 struct rsnd_dai *rdai,
441 struct rsnd_dai_stream *io)
Kuninori Morimotoa204d902014-01-23 18:38:33 -0800442{
Kuninori Morimotoe7ce74e2014-01-23 18:38:50 -0800443 int id = rsnd_mod_id(mod);
Kuninori Morimotoa204d902014-01-23 18:38:33 -0800444
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800445 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
Kuninori Morimotoe7ce74e2014-01-23 18:38:50 -0800446
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800447 return rsnd_scu_start(mod, rdai, io);
Kuninori Morimotoa204d902014-01-23 18:38:33 -0800448}
449
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800450static int rsnd_scu_stop_gen1(struct rsnd_mod *mod,
451 struct rsnd_dai *rdai,
452 struct rsnd_dai_stream *io)
Kuninori Morimotoef749402013-12-19 19:28:51 -0800453{
Kuninori Morimotoe7ce74e2014-01-23 18:38:50 -0800454 int id = rsnd_mod_id(mod);
Kuninori Morimotoef749402013-12-19 19:28:51 -0800455
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800456 rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
Kuninori Morimotoe7ce74e2014-01-23 18:38:50 -0800457
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800458 return rsnd_scu_stop(mod, rdai, io);
Kuninori Morimotoef749402013-12-19 19:28:51 -0800459}
460
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800461static struct rsnd_mod_ops rsnd_scu_gen1_ops = {
462 .name = "sru (gen1)",
463 .init = rsnd_scu_init_gen1,
Kuninori Morimotoa204d902014-01-23 18:38:33 -0800464 .quit = rsnd_scu_quit,
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800465 .start = rsnd_scu_start_gen1,
466 .stop = rsnd_scu_stop_gen1,
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700467};
468
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800469static struct rsnd_mod_ops rsnd_scu_non_gen1_ops = {
470 .name = "non-sru (gen1)",
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800471 .init = rsnd_scu_ssi_mode_init,
Kuninori Morimoto013f38f2014-01-23 18:38:26 -0800472};
473
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800474/*
475 * Gen2 functions
476 */
Kuninori Morimoto629509c2014-01-23 18:42:00 -0800477static int rsnd_scu_set_convert_rate_gen2(struct rsnd_mod *mod,
478 struct rsnd_dai *rdai,
479 struct rsnd_dai_stream *io)
480{
481 int ret;
482
483 ret = rsnd_scu_set_convert_rate(mod, rdai, io);
484 if (ret < 0)
485 return ret;
486
487 rsnd_mod_write(mod, SSI_BUSIF_ADINR, rsnd_mod_read(mod, SRC_ADINR));
488 rsnd_mod_write(mod, SSI_BUSIF_MODE, rsnd_mod_read(mod, SRC_BUSIF_MODE));
489
490 rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
491
492 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
493 rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
494
495 return 0;
496}
497
498static int rsnd_scu_set_convert_timing_gen2(struct rsnd_mod *mod,
499 struct rsnd_dai *rdai,
500 struct rsnd_dai_stream *io)
501{
502 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
503 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
504 u32 convert_rate = rsnd_scu_convert_rate(scu);
505 int ret;
506
507 if (convert_rate)
508 ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io,
509 runtime->rate,
510 convert_rate);
511 else
512 ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io);
513
514 return ret;
515}
516
517static int rsnd_scu_init_gen2(struct rsnd_mod *mod,
518 struct rsnd_dai *rdai,
519 struct rsnd_dai_stream *io)
520{
521 int ret;
522
523 ret = rsnd_scu_init(mod, rdai, io);
524 if (ret < 0)
525 return ret;
526
527 ret = rsnd_scu_set_convert_rate_gen2(mod, rdai, io);
528 if (ret < 0)
529 return ret;
530
531 ret = rsnd_scu_set_convert_timing_gen2(mod, rdai, io);
532 if (ret < 0)
533 return ret;
534
535 return 0;
536}
537
538static int rsnd_scu_start_gen2(struct rsnd_mod *mod,
539 struct rsnd_dai *rdai,
540 struct rsnd_dai_stream *io)
541{
542 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
543
544 rsnd_dma_start(rsnd_mod_to_dma(&scu->mod));
545
546 rsnd_mod_write(mod, SSI_CTRL, 0x1);
547 rsnd_mod_write(mod, SRC_CTRL, 0x11);
548
549 return rsnd_scu_start(mod, rdai, io);
550}
551
552static int rsnd_scu_stop_gen2(struct rsnd_mod *mod,
553 struct rsnd_dai *rdai,
554 struct rsnd_dai_stream *io)
555{
556 struct rsnd_scu *scu = rsnd_mod_to_scu(mod);
557
558 rsnd_mod_write(mod, SSI_CTRL, 0);
559 rsnd_mod_write(mod, SRC_CTRL, 0);
560
561 rsnd_dma_stop(rsnd_mod_to_dma(&scu->mod));
562
563 return rsnd_scu_stop(mod, rdai, io);
564}
565
566static struct rsnd_mod_ops rsnd_scu_gen2_ops = {
567 .name = "scu (gen2)",
568 .init = rsnd_scu_init_gen2,
569 .quit = rsnd_scu_quit,
570 .start = rsnd_scu_start_gen2,
571 .stop = rsnd_scu_stop_gen2,
572};
573
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800574static int rsnd_scu_start_non_gen2(struct rsnd_mod *mod,
575 struct rsnd_dai *rdai,
576 struct rsnd_dai_stream *io)
577{
578 /* enable PIO interrupt */
579 rsnd_mod_write(mod, INT_ENABLE, 0x0f000000);
580
581 return 0;
582}
583
584static struct rsnd_mod_ops rsnd_scu_non_gen2_ops = {
585 .name = "non-scu (gen2)",
586 .init = rsnd_scu_ssi_mode_init,
587 .start = rsnd_scu_start_non_gen2,
588};
589
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700590struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id)
591{
Takashi Iwai8b147192013-11-05 18:40:05 +0100592 if (WARN_ON(id < 0 || id >= rsnd_scu_nr(priv)))
593 id = 0;
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700594
595 return &((struct rsnd_scu *)(priv->scu) + id)->mod;
596}
597
598int rsnd_scu_probe(struct platform_device *pdev,
599 struct rcar_snd_info *info,
600 struct rsnd_priv *priv)
601{
602 struct device *dev = rsnd_priv_to_dev(priv);
603 struct rsnd_scu *scu;
Kuninori Morimoto013f38f2014-01-23 18:38:26 -0800604 struct rsnd_mod_ops *ops;
Kuninori Morimotoef749402013-12-19 19:28:51 -0800605 struct clk *clk;
606 char name[RSND_SCU_NAME_SIZE];
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700607 int i, nr;
608
609 /*
610 * init SCU
611 */
612 nr = info->scu_info_nr;
613 scu = devm_kzalloc(dev, sizeof(*scu) * nr, GFP_KERNEL);
614 if (!scu) {
615 dev_err(dev, "SCU allocate failed\n");
616 return -ENOMEM;
617 }
618
619 priv->scu_nr = nr;
620 priv->scu = scu;
621
622 for_each_rsnd_scu(scu, priv, i) {
Kuninori Morimotoef749402013-12-19 19:28:51 -0800623 snprintf(name, RSND_SCU_NAME_SIZE, "scu.%d", i);
624
625 clk = devm_clk_get(dev, name);
626 if (IS_ERR(clk))
627 return PTR_ERR(clk);
628
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700629 scu->info = &info->scu_info[i];
Kuninori Morimotoef749402013-12-19 19:28:51 -0800630 scu->clk = clk;
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700631
Kuninori Morimoto013f38f2014-01-23 18:38:26 -0800632 ops = &rsnd_scu_non_ops;
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800633 if (rsnd_scu_hpbif_is_enable(scu)) {
634 if (rsnd_is_gen1(priv))
635 ops = &rsnd_scu_gen1_ops;
Kuninori Morimoto629509c2014-01-23 18:42:00 -0800636 if (rsnd_is_gen2(priv)) {
637 struct rsnd_mod *ssi = rsnd_ssi_mod_get(priv, i);
638 int ret = rsnd_dma_init(priv,
639 rsnd_mod_to_dma(&scu->mod),
640 rsnd_ssi_is_play(ssi),
641 scu->info->dma_id);
642 if (ret < 0)
643 return ret;
644
645 ops = &rsnd_scu_gen2_ops;
646 }
Kuninori Morimoto1b7b08ef2014-01-23 18:41:36 -0800647 } else {
648 if (rsnd_is_gen1(priv))
649 ops = &rsnd_scu_non_gen1_ops;
650 if (rsnd_is_gen2(priv))
651 ops = &rsnd_scu_non_gen2_ops;
652 }
Kuninori Morimoto013f38f2014-01-23 18:38:26 -0800653
654 rsnd_mod_init(priv, &scu->mod, ops, i);
655
Kuninori Morimoto374a52812013-07-28 18:59:12 -0700656 dev_dbg(dev, "SCU%d probed\n", i);
657 }
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700658 dev_dbg(dev, "scu probed\n");
659
660 return 0;
661}
662
663void rsnd_scu_remove(struct platform_device *pdev,
664 struct rsnd_priv *priv)
665{
Kuninori Morimoto629509c2014-01-23 18:42:00 -0800666 struct rsnd_scu *scu;
667 int i;
668
669 for_each_rsnd_scu(scu, priv, i) {
670 if (rsnd_scu_dma_available(scu))
671 rsnd_dma_quit(priv, rsnd_mod_to_dma(&scu->mod));
672 }
Kuninori Morimoto07539c12013-07-21 21:36:35 -0700673}