blob: 628739f13f9990e16f003771186639f088e7ce12 [file] [log] [blame]
Kuninori Morimotoae5c3222013-07-21 21:36:57 -07001/*
2 * Renesas R-Car SSIU/SSI support
3 *
4 * Copyright (C) 2013 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * Based on fsi.c
8 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14#include <linux/delay.h>
15#include "rsnd.h"
16#define RSND_SSI_NAME_SIZE 16
17
18/*
19 * SSICR
20 */
21#define FORCE (1 << 31) /* Fixed */
Kuninori Morimoto849fc822013-07-28 18:59:02 -070022#define DMEN (1 << 28) /* DMA Enable */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070023#define UIEN (1 << 27) /* Underflow Interrupt Enable */
24#define OIEN (1 << 26) /* Overflow Interrupt Enable */
25#define IIEN (1 << 25) /* Idle Mode Interrupt Enable */
26#define DIEN (1 << 24) /* Data Interrupt Enable */
Kuninori Morimoto186fadc2015-11-30 08:54:03 +000027#define CHNL_4 (1 << 22) /* Channels */
28#define CHNL_6 (2 << 22) /* Channels */
29#define CHNL_8 (3 << 22) /* Channels */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070030#define DWL_8 (0 << 19) /* Data Word Length */
31#define DWL_16 (1 << 19) /* Data Word Length */
32#define DWL_18 (2 << 19) /* Data Word Length */
33#define DWL_20 (3 << 19) /* Data Word Length */
34#define DWL_22 (4 << 19) /* Data Word Length */
35#define DWL_24 (5 << 19) /* Data Word Length */
36#define DWL_32 (6 << 19) /* Data Word Length */
37
38#define SWL_32 (3 << 16) /* R/W System Word Length */
39#define SCKD (1 << 15) /* Serial Bit Clock Direction */
40#define SWSD (1 << 14) /* Serial WS Direction */
41#define SCKP (1 << 13) /* Serial Bit Clock Polarity */
42#define SWSP (1 << 12) /* Serial WS Polarity */
43#define SDTA (1 << 10) /* Serial Data Alignment */
Kuninori Morimotof46a93b2015-11-17 08:28:11 +000044#define PDTA (1 << 9) /* Parallel Data Alignment */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070045#define DEL (1 << 8) /* Serial Data Delay */
46#define CKDV(v) (v << 4) /* Serial Clock Division Ratio */
47#define TRMD (1 << 1) /* Transmit/Receive Mode Select */
48#define EN (1 << 0) /* SSI Module Enable */
49
50/*
51 * SSISR
52 */
53#define UIRQ (1 << 27) /* Underflow Error Interrupt Status */
54#define OIRQ (1 << 26) /* Overflow Error Interrupt Status */
55#define IIRQ (1 << 25) /* Idle Mode Interrupt Status */
56#define DIRQ (1 << 24) /* Data Interrupt Status Flag */
57
Kuninori Morimoto849fc822013-07-28 18:59:02 -070058/*
59 * SSIWSR
60 */
61#define CONT (1 << 8) /* WS Continue Function */
Kuninori Morimoto186fadc2015-11-30 08:54:03 +000062#define WS_MODE (1 << 0) /* WS Mode */
Kuninori Morimoto849fc822013-07-28 18:59:02 -070063
Kuninori Morimoto8aefda52014-05-22 23:25:43 -070064#define SSI_NAME "ssi"
65
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070066struct rsnd_ssi {
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070067 struct rsnd_ssi *parent;
68 struct rsnd_mod mod;
Kuninori Morimoto940e9472015-10-26 08:42:25 +000069 struct rsnd_mod *dma;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070070
Kuninori Morimoto02534f22015-11-10 05:11:35 +000071 u32 flags;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070072 u32 cr_own;
73 u32 cr_clk;
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +000074 u32 cr_mode;
Kuninori Morimoto08bada22015-11-30 08:53:04 +000075 u32 wsr;
Kuninori Morimoto919567d2015-04-10 08:50:30 +000076 int chan;
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +000077 int rate;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070078 int err;
Kuninori Morimoto02534f22015-11-10 05:11:35 +000079 int irq;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070080 unsigned int usrcnt;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070081};
82
Kuninori Morimoto02534f22015-11-10 05:11:35 +000083/* flags */
84#define RSND_SSI_CLK_PIN_SHARE (1 << 0)
85#define RSND_SSI_NO_BUSIF (1 << 1) /* SSI+DMA without BUSIF */
86
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070087#define for_each_rsnd_ssi(pos, priv, i) \
88 for (i = 0; \
89 (i < rsnd_ssi_nr(priv)) && \
Kuninori Morimotodd27d802014-01-23 18:39:40 -080090 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070091 i++)
92
Kuninori Morimoto02534f22015-11-10 05:11:35 +000093#define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
Kuninori Morimoto232c00b2015-10-26 08:38:26 +000094#define rsnd_ssi_to_dma(mod) ((ssi)->dma)
Kuninori Morimotodd27d802014-01-23 18:39:40 -080095#define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070096#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
Kuninori Morimoto02534f22015-11-10 05:11:35 +000097#define rsnd_ssi_mode_flags(p) ((p)->flags)
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +000098#define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070099
Kuninori Morimotob415b4d2015-10-22 03:15:46 +0000100int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700101{
Kuninori Morimotob415b4d2015-10-22 03:15:46 +0000102 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700103 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700104 int use_busif = 0;
105
Kuninori Morimoto7b466fc2014-11-27 08:05:54 +0000106 if (!rsnd_ssi_is_dma_mode(mod))
107 return 0;
108
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700109 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
110 use_busif = 1;
111 if (rsnd_io_to_mod_src(io))
112 use_busif = 1;
113
114 return use_busif;
115}
116
Kuninori Morimotoe10369d2015-10-26 08:42:09 +0000117static void rsnd_ssi_status_clear(struct rsnd_mod *mod)
118{
119 rsnd_mod_write(mod, SSISR, 0);
120}
121
122static u32 rsnd_ssi_status_get(struct rsnd_mod *mod)
123{
124 return rsnd_mod_read(mod, SSISR);
125}
126
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700127static void rsnd_ssi_status_check(struct rsnd_mod *mod,
128 u32 bit)
129{
130 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
131 struct device *dev = rsnd_priv_to_dev(priv);
132 u32 status;
133 int i;
134
135 for (i = 0; i < 1024; i++) {
Kuninori Morimotoe10369d2015-10-26 08:42:09 +0000136 status = rsnd_ssi_status_get(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700137 if (status & bit)
138 return;
139
140 udelay(50);
141 }
142
143 dev_warn(dev, "status check failed\n");
144}
145
Kuninori Morimoto37447b42015-10-26 08:40:41 +0000146static int rsnd_ssi_irq_enable(struct rsnd_mod *ssi_mod)
147{
148 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
149
150 if (rsnd_is_gen1(priv))
151 return 0;
152
153 /* enable SSI interrupt if Gen2 */
154 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE,
155 rsnd_ssi_is_dma_mode(ssi_mod) ?
156 0x0e000000 : 0x0f000000);
157
158 return 0;
159}
160
161static int rsnd_ssi_irq_disable(struct rsnd_mod *ssi_mod)
162{
163 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
164
165 if (rsnd_is_gen1(priv))
166 return 0;
167
168 /* disable SSI interrupt if Gen2 */
169 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 0x00000000);
170
171 return 0;
172}
173
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700174static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
Kuninori Morimotoadcf7d52013-12-19 19:28:39 -0800175 struct rsnd_dai_stream *io)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700176{
Kuninori Morimoto1b13d1182015-01-15 08:08:34 +0000177 struct rsnd_priv *priv = rsnd_io_to_priv(io);
Kuninori Morimotoadcf7d52013-12-19 19:28:39 -0800178 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700179 struct device *dev = rsnd_priv_to_dev(priv);
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000180 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000181 struct rsnd_mod *mod = rsnd_mod_get(ssi);
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000182 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
Kuninori Morimoto8ec85e72015-11-30 08:53:27 +0000183 int slots = rsnd_get_slot_extend(io);
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000184 int j, ret;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700185 int ssi_clk_mul_table[] = {
186 1, 2, 4, 8, 16, 6, 12,
187 };
188 unsigned int main_rate;
Kuninori Morimotoba9c9492014-03-03 20:51:21 -0800189 unsigned int rate = rsnd_src_get_ssi_rate(priv, io, runtime);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700190
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000191 if (!rsnd_rdai_is_clk_master(rdai))
192 return 0;
193
194 if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io))
195 return 0;
196
197 if (ssi->usrcnt > 1) {
198 if (ssi->rate != rate) {
199 dev_err(dev, "SSI parent/child should use same rate\n");
200 return -EINVAL;
201 }
202
203 return 0;
204 }
205
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700206 /*
207 * Find best clock, and try to start ADG
208 */
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000209 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700210
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000211 /*
212 * this driver is assuming that
Kuninori Morimoto8ec85e72015-11-30 08:53:27 +0000213 * system word is 32bit x slots
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000214 * see rsnd_ssi_init()
215 */
Kuninori Morimoto8ec85e72015-11-30 08:53:27 +0000216 main_rate = rate * 32 * slots * ssi_clk_mul_table[j];
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700217
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000218 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
219 if (0 == ret) {
220 ssi->cr_clk = FORCE | SWL_32 |
221 SCKD | SWSD | CKDV(j);
Kuninori Morimoto08bada22015-11-30 08:53:04 +0000222 ssi->wsr = CONT;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700223
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000224 ssi->rate = rate;
225
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000226 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
227 rsnd_mod_name(mod),
228 rsnd_mod_id(mod), rate);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700229
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000230 return 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700231 }
232 }
233
234 dev_err(dev, "unsupported clock rate\n");
235 return -EIO;
236}
237
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000238static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi,
239 struct rsnd_dai_stream *io)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700240{
Kuninori Morimotof708d942015-01-15 08:07:19 +0000241 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000242 struct rsnd_mod *mod = rsnd_mod_get(ssi);
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000243 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700244
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000245 if (!rsnd_rdai_is_clk_master(rdai))
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700246 return;
247
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000248 if (ssi_parent_mod && !rsnd_ssi_is_parent(mod, io))
249 return;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700250
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000251 if (ssi->usrcnt > 1)
252 return;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700253
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000254 ssi->cr_clk = 0;
255 ssi->rate = 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700256
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000257 rsnd_adg_ssi_clk_stop(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700258}
259
Kuninori Morimoto840ada32015-11-30 08:52:38 +0000260static int rsnd_ssi_config_init(struct rsnd_ssi *ssi,
261 struct rsnd_dai_stream *io)
262{
263 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
264 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
265 u32 cr_own;
266 u32 cr_mode;
Kuninori Morimoto186fadc2015-11-30 08:54:03 +0000267 u32 wsr;
Kuninori Morimoto840ada32015-11-30 08:52:38 +0000268
269 /*
270 * always use 32bit system word.
271 * see also rsnd_ssi_master_clk_enable()
272 */
273 cr_own = FORCE | SWL_32 | PDTA;
274
275 if (rdai->bit_clk_inv)
276 cr_own |= SCKP;
277 if (rdai->frm_clk_inv)
278 cr_own |= SWSP;
279 if (rdai->data_alignment)
280 cr_own |= SDTA;
281 if (rdai->sys_delay)
282 cr_own |= DEL;
283 if (rsnd_io_is_play(io))
284 cr_own |= TRMD;
285
286 switch (runtime->sample_bits) {
287 case 16:
288 cr_own |= DWL_16;
289 break;
290 case 32:
291 cr_own |= DWL_24;
292 break;
293 default:
294 return -EINVAL;
295 }
296
297 if (rsnd_ssi_is_dma_mode(rsnd_mod_get(ssi))) {
298 cr_mode = UIEN | OIEN | /* over/under run */
299 DMEN; /* DMA : enable DMA */
300 } else {
301 cr_mode = DIEN; /* PIO : enable Data interrupt */
302 }
303
Kuninori Morimoto186fadc2015-11-30 08:54:03 +0000304 /*
305 * TDM Extend Mode
306 * see
307 * rsnd_ssiu_init_gen2()
308 */
309 wsr = ssi->wsr;
310 if (rsnd_get_slot_runtime(io) >= 6) {
311 wsr |= WS_MODE;
312 cr_own |= CHNL_8;
313 }
314
Kuninori Morimoto840ada32015-11-30 08:52:38 +0000315 ssi->cr_own = cr_own;
316 ssi->cr_mode = cr_mode;
Kuninori Morimoto186fadc2015-11-30 08:54:03 +0000317 ssi->wsr = wsr;
Kuninori Morimoto840ada32015-11-30 08:52:38 +0000318
319 return 0;
320}
321
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700322/*
323 * SSI mod common functions
324 */
325static int rsnd_ssi_init(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000326 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000327 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700328{
329 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000330 int ret;
331
332 ssi->usrcnt++;
333
334 rsnd_mod_power_on(mod);
335
336 ret = rsnd_ssi_master_clk_start(ssi, io);
337 if (ret < 0)
338 return ret;
339
340 if (rsnd_ssi_is_parent(mod, io))
341 return 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700342
Kuninori Morimoto840ada32015-11-30 08:52:38 +0000343 ret = rsnd_ssi_config_init(ssi, io);
344 if (ret < 0)
345 return ret;
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000346
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700347 ssi->err = -1; /* ignore 1st error */
348
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000349 /* clear error status */
350 rsnd_ssi_status_clear(mod);
351
352 rsnd_ssi_irq_enable(mod);
353
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700354 return 0;
355}
356
357static int rsnd_ssi_quit(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000358 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000359 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700360{
361 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700362 struct device *dev = rsnd_priv_to_dev(priv);
363
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000364 if (rsnd_ssi_is_parent(mod, io))
365 goto rsnd_ssi_quit_end;
366
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700367 if (ssi->err > 0)
Kuninori Morimoto337b0b42015-01-15 08:08:57 +0000368 dev_warn(dev, "%s[%d] under/over flow err = %d\n",
369 rsnd_mod_name(mod), rsnd_mod_id(mod), ssi->err);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700370
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700371 ssi->cr_own = 0;
372 ssi->err = 0;
373
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000374 rsnd_ssi_irq_disable(mod);
375
376rsnd_ssi_quit_end:
377 rsnd_ssi_master_clk_stop(ssi, io);
378
379 rsnd_mod_power_off(mod);
380
381 ssi->usrcnt--;
382
383 if (ssi->usrcnt < 0)
384 dev_err(dev, "%s[%d] usrcnt error\n",
385 rsnd_mod_name(mod), rsnd_mod_id(mod));
386
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700387 return 0;
388}
389
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000390static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000391 struct rsnd_dai_stream *io,
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000392 struct snd_pcm_substream *substream,
393 struct snd_pcm_hw_params *params)
394{
395 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000396 int chan = params_channels(params);
397
398 /*
399 * Already working.
400 * It will happen if SSI has parent/child connection.
401 */
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000402 if (ssi->usrcnt > 1) {
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000403 /*
404 * it is error if child <-> parent SSI uses
405 * different channels.
406 */
407 if (ssi->chan != chan)
408 return -EIO;
409 }
410
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000411 ssi->chan = chan;
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000412
413 return 0;
414}
415
Kuninori Morimotoe10369d2015-10-26 08:42:09 +0000416static u32 rsnd_ssi_record_error(struct rsnd_ssi *ssi)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700417{
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000418 struct rsnd_mod *mod = rsnd_mod_get(ssi);
Kuninori Morimotoe10369d2015-10-26 08:42:09 +0000419 u32 status = rsnd_ssi_status_get(mod);
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000420
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700421 /* under/over flow error */
Kuninori Morimoto5342dff2015-11-26 11:13:40 +0000422 if (status & (UIRQ | OIRQ))
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700423 ssi->err++;
424
Kuninori Morimotoe10369d2015-10-26 08:42:09 +0000425 return status;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700426}
427
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000428static int __rsnd_ssi_start(struct rsnd_mod *mod,
429 struct rsnd_dai_stream *io,
430 struct rsnd_priv *priv)
431{
432 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
433 u32 cr;
434
435 cr = ssi->cr_own |
436 ssi->cr_clk |
437 ssi->cr_mode |
438 EN;
439
440 rsnd_mod_write(mod, SSICR, cr);
Kuninori Morimoto08bada22015-11-30 08:53:04 +0000441 rsnd_mod_write(mod, SSIWSR, ssi->wsr);
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000442
443 return 0;
444}
445
Kuninori Morimoto49229852014-11-27 08:07:17 +0000446static int rsnd_ssi_start(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000447 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000448 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700449{
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000450 /*
451 * no limit to start
452 * see also
453 * rsnd_ssi_stop
454 * rsnd_ssi_interrupt
455 */
456 return __rsnd_ssi_start(mod, io, priv);
457}
458
459static int __rsnd_ssi_stop(struct rsnd_mod *mod,
460 struct rsnd_dai_stream *io,
461 struct rsnd_priv *priv)
462{
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700463 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000464 u32 cr;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700465
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000466 /*
467 * disable all IRQ,
468 * and, wait all data was sent
469 */
470 cr = ssi->cr_own |
471 ssi->cr_clk;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700472
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000473 rsnd_mod_write(mod, SSICR, cr | EN);
474 rsnd_ssi_status_check(mod, DIRQ);
475
476 /*
477 * disable SSI,
478 * and, wait idle state
479 */
480 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
481 rsnd_ssi_status_check(mod, IIRQ);
Kuninori Morimotoc17dba82014-11-27 08:05:09 +0000482
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700483 return 0;
484}
485
Kuninori Morimoto49229852014-11-27 08:07:17 +0000486static int rsnd_ssi_stop(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000487 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000488 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700489{
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700490 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
491
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000492 /*
493 * don't stop if not last user
494 * see also
495 * rsnd_ssi_start
496 * rsnd_ssi_interrupt
497 */
498 if (ssi->usrcnt > 1)
499 return 0;
Kuninori Morimotoc17dba82014-11-27 08:05:09 +0000500
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000501 return __rsnd_ssi_stop(mod, io, priv);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700502}
503
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000504static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
505 struct rsnd_dai_stream *io)
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000506{
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000507 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000508 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
Kuninori Morimoto69e32a52015-10-26 08:41:36 +0000509 struct device *dev = rsnd_priv_to_dev(priv);
Kuninori Morimoto765ae7c2015-01-15 08:09:13 +0000510 int is_dma = rsnd_ssi_is_dma_mode(mod);
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000511 u32 status;
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000512 bool elapsed = false;
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000513
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000514 spin_lock(&priv->lock);
515
516 /* ignore all cases if not working */
Kuninori Morimotod5bbe7d2015-06-15 06:27:47 +0000517 if (!rsnd_io_is_working(io))
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000518 goto rsnd_ssi_interrupt_out;
519
Kuninori Morimotoe10369d2015-10-26 08:42:09 +0000520 status = rsnd_ssi_record_error(ssi);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000521
522 /* PIO only */
Kuninori Morimoto765ae7c2015-01-15 08:09:13 +0000523 if (!is_dma && (status & DIRQ)) {
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000524 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
525 u32 *buf = (u32 *)(runtime->dma_area +
526 rsnd_dai_pointer_offset(io, 0));
527
528 /*
529 * 8/16/32 data can be assesse to TDR/RDR register
530 * directly as 32bit data
531 * see rsnd_ssi_init()
532 */
Kuninori Morimoto985a4f62015-01-15 08:06:49 +0000533 if (rsnd_io_is_play(io))
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000534 rsnd_mod_write(mod, SSITDR, *buf);
535 else
536 *buf = rsnd_mod_read(mod, SSIRDR);
537
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000538 elapsed = rsnd_dai_pointer_update(io, sizeof(*buf));
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000539 }
540
Kuninori Morimoto12927a82015-06-15 06:20:54 +0000541 /* DMA only */
542 if (is_dma && (status & (UIRQ | OIRQ))) {
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000543 /*
544 * restart SSI
545 */
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000546 dev_dbg(dev, "%s[%d] restart\n",
547 rsnd_mod_name(mod), rsnd_mod_id(mod));
Kuninori Morimoto044930b2015-03-19 04:13:47 +0000548
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000549 __rsnd_ssi_stop(mod, io, priv);
550 __rsnd_ssi_start(mod, io, priv);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000551 }
552
Kuninori Morimoto69e32a52015-10-26 08:41:36 +0000553 if (ssi->err > 1024) {
554 rsnd_ssi_irq_disable(mod);
555
556 dev_warn(dev, "no more %s[%d] restart\n",
557 rsnd_mod_name(mod), rsnd_mod_id(mod));
558 }
559
Kuninori Morimoto5342dff2015-11-26 11:13:40 +0000560 rsnd_ssi_status_clear(mod);
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000561rsnd_ssi_interrupt_out:
562 spin_unlock(&priv->lock);
563
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000564 if (elapsed)
565 rsnd_dai_period_elapsed(io);
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000566}
567
568static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
569{
570 struct rsnd_mod *mod = data;
571
572 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000573
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000574 return IRQ_HANDLED;
575}
576
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000577/*
578 * SSI PIO
579 */
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000580static void rsnd_ssi_parent_attach(struct rsnd_mod *mod,
581 struct rsnd_dai_stream *io,
582 struct rsnd_priv *priv)
583{
584 if (!__rsnd_ssi_is_pin_sharing(mod))
585 return;
586
587 switch (rsnd_mod_id(mod)) {
588 case 1:
589 case 2:
590 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 0), io, RSND_MOD_SSIP);
591 break;
592 case 4:
593 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 3), io, RSND_MOD_SSIP);
594 break;
595 case 8:
596 rsnd_dai_connect(rsnd_ssi_mod_get(priv, 7), io, RSND_MOD_SSIP);
597 break;
598 }
599}
600
Kuninori Morimotoc7f69ab2015-10-26 08:43:41 +0000601static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
602 struct rsnd_dai_stream *io,
603 struct rsnd_priv *priv)
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000604{
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000605 struct device *dev = rsnd_priv_to_dev(priv);
606 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000607 int ret;
608
Kuninori Morimotoe7d850d2015-10-26 08:43:57 +0000609 rsnd_ssi_parent_attach(mod, io, priv);
610
Kuninori Morimotoc7f69ab2015-10-26 08:43:41 +0000611 ret = rsnd_ssiu_attach(io, mod);
612 if (ret < 0)
613 return ret;
614
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000615 ret = devm_request_irq(dev, ssi->irq,
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000616 rsnd_ssi_interrupt,
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000617 IRQF_SHARED,
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000618 dev_name(dev), mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000619
620 return ret;
621}
622
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700623static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700624 .name = SSI_NAME,
Kuninori Morimotoc7f69ab2015-10-26 08:43:41 +0000625 .probe = rsnd_ssi_common_probe,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700626 .init = rsnd_ssi_init,
627 .quit = rsnd_ssi_quit,
Kuninori Morimoto49229852014-11-27 08:07:17 +0000628 .start = rsnd_ssi_start,
629 .stop = rsnd_ssi_stop,
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000630 .hw_params = rsnd_ssi_hw_params,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700631};
632
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800633static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000634 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000635 struct rsnd_priv *priv)
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800636{
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800637 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000638 int dma_id = 0; /* not needed */
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800639 int ret;
640
Kuninori Morimotoc7f69ab2015-10-26 08:43:41 +0000641 ret = rsnd_ssi_common_probe(mod, io, priv);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000642 if (ret)
Kuninori Morimotob543b522015-03-26 04:02:32 +0000643 return ret;
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000644
Kuninori Morimoto81ecbb62015-10-26 08:39:20 +0000645 ssi->dma = rsnd_dma_attach(io, mod, dma_id);
Kuninori Morimoto232c00b2015-10-26 08:38:26 +0000646 if (IS_ERR(ssi->dma))
647 return PTR_ERR(ssi->dma);
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700648
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800649 return ret;
650}
651
652static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000653 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000654 struct rsnd_priv *priv)
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800655{
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000656 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
657 struct device *dev = rsnd_priv_to_dev(priv);
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000658 int irq = ssi->irq;
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000659
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000660 /* PIO will request IRQ again */
Kuninori Morimotob05ce4c2015-10-22 03:13:44 +0000661 devm_free_irq(dev, irq, mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000662
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000663 return 0;
664}
665
666static int rsnd_ssi_fallback(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000667 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000668 struct rsnd_priv *priv)
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000669{
Kuninori Morimotod3a76822014-11-09 20:00:58 -0800670 struct device *dev = rsnd_priv_to_dev(priv);
671
Kuninori Morimotod3a76822014-11-09 20:00:58 -0800672 /*
673 * fallback to PIO
674 *
675 * SSI .probe might be called again.
676 * see
677 * rsnd_rdai_continuance_probe()
678 */
679 mod->ops = &rsnd_ssi_pio_ops;
680
681 dev_info(dev, "%s[%d] fallback to PIO mode\n",
682 rsnd_mod_name(mod), rsnd_mod_id(mod));
683
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800684 return 0;
685}
686
Kuninori Morimoto9b99e9a2015-06-15 06:26:25 +0000687static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
688 struct rsnd_mod *mod)
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700689{
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000690 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000691 int is_play = rsnd_io_is_play(io);
692 char *name;
693
Kuninori Morimotob415b4d2015-10-22 03:15:46 +0000694 if (rsnd_ssi_use_busif(io))
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000695 name = is_play ? "rxu" : "txu";
696 else
697 name = is_play ? "rx" : "tx";
698
699 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
700 mod, name);
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700701}
702
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700703static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700704 .name = SSI_NAME,
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000705 .dma_req = rsnd_ssi_dma_req,
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800706 .probe = rsnd_ssi_dma_probe,
707 .remove = rsnd_ssi_dma_remove,
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700708 .init = rsnd_ssi_init,
709 .quit = rsnd_ssi_quit,
Kuninori Morimoto497deba2015-10-26 08:43:01 +0000710 .start = rsnd_ssi_start,
711 .stop = rsnd_ssi_stop,
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000712 .fallback = rsnd_ssi_fallback,
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000713 .hw_params = rsnd_ssi_hw_params,
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700714};
715
Kuninori Morimoto05795412014-11-27 08:05:01 +0000716int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
717{
718 return mod->ops == &rsnd_ssi_dma_ops;
719}
720
721
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700722/*
723 * Non SSI
724 */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700725static struct rsnd_mod_ops rsnd_ssi_non_ops = {
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700726 .name = SSI_NAME,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700727};
728
729/*
730 * ssi mod function
731 */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700732struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
733{
Takashi Iwai8b147192013-11-05 18:40:05 +0100734 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
735 id = 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700736
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000737 return rsnd_mod_get(rsnd_ssi_get(priv, id));
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700738}
739
Kuninori Morimotob415b4d2015-10-22 03:15:46 +0000740int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800741{
742 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
743
744 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
745}
746
Kuninori Morimoto2ea6b072015-11-10 05:14:12 +0000747int rsnd_ssi_probe(struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700748{
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000749 struct device_node *node;
750 struct device_node *np;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700751 struct device *dev = rsnd_priv_to_dev(priv);
752 struct rsnd_mod_ops *ops;
753 struct clk *clk;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700754 struct rsnd_ssi *ssi;
755 char name[RSND_SSI_NAME_SIZE];
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000756 int i, nr, ret;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700757
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000758 node = rsnd_ssi_of_node(priv);
759 if (!node)
760 return -EINVAL;
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700761
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000762 nr = of_get_child_count(node);
763 if (!nr) {
764 ret = -EINVAL;
765 goto rsnd_ssi_probe_done;
766 }
767
Kuninori Morimotodd27d802014-01-23 18:39:40 -0800768 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000769 if (!ssi) {
770 ret = -ENOMEM;
771 goto rsnd_ssi_probe_done;
772 }
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700773
Kuninori Morimotodd27d802014-01-23 18:39:40 -0800774 priv->ssi = ssi;
775 priv->ssi_nr = nr;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700776
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000777 i = 0;
778 for_each_child_of_node(node, np) {
779 ssi = rsnd_ssi_get(priv, i);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700780
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700781 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
782 SSI_NAME, i);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700783
Kuninori Morimoto60dbb4f2013-12-03 22:09:33 -0800784 clk = devm_clk_get(dev, name);
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000785 if (IS_ERR(clk)) {
786 ret = PTR_ERR(clk);
787 goto rsnd_ssi_probe_done;
788 }
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700789
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000790 if (of_get_property(np, "shared-pin", NULL))
791 ssi->flags |= RSND_SSI_CLK_PIN_SHARE;
792
793 if (of_get_property(np, "no-busif", NULL))
794 ssi->flags |= RSND_SSI_NO_BUSIF;
795
796 ssi->irq = irq_of_parse_and_map(np, 0);
797 if (!ssi->irq) {
798 ret = -EINVAL;
799 goto rsnd_ssi_probe_done;
800 }
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700801
802 ops = &rsnd_ssi_non_ops;
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000803 if (of_get_property(np, "pio-transfer", NULL))
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800804 ops = &rsnd_ssi_pio_ops;
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000805 else
806 ops = &rsnd_ssi_dma_ops;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700807
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000808 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
809 RSND_MOD_SSI, i);
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000810 if (ret)
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000811 goto rsnd_ssi_probe_done;
812
813 i++;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700814 }
815
Kuninori Morimoto02534f22015-11-10 05:11:35 +0000816 ret = 0;
817
818rsnd_ssi_probe_done:
819 of_node_put(node);
820
821 return ret;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700822}
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000823
Kuninori Morimoto2ea6b072015-11-10 05:14:12 +0000824void rsnd_ssi_remove(struct rsnd_priv *priv)
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000825{
826 struct rsnd_ssi *ssi;
827 int i;
828
829 for_each_rsnd_ssi(ssi, priv, i) {
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000830 rsnd_mod_quit(rsnd_mod_get(ssi));
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000831 }
832}