blob: d70720a42cfdea206037ce157699785315b46794 [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 */
27
28#define DWL_8 (0 << 19) /* Data Word Length */
29#define DWL_16 (1 << 19) /* Data Word Length */
30#define DWL_18 (2 << 19) /* Data Word Length */
31#define DWL_20 (3 << 19) /* Data Word Length */
32#define DWL_22 (4 << 19) /* Data Word Length */
33#define DWL_24 (5 << 19) /* Data Word Length */
34#define DWL_32 (6 << 19) /* Data Word Length */
35
36#define SWL_32 (3 << 16) /* R/W System Word Length */
37#define SCKD (1 << 15) /* Serial Bit Clock Direction */
38#define SWSD (1 << 14) /* Serial WS Direction */
39#define SCKP (1 << 13) /* Serial Bit Clock Polarity */
40#define SWSP (1 << 12) /* Serial WS Polarity */
41#define SDTA (1 << 10) /* Serial Data Alignment */
42#define DEL (1 << 8) /* Serial Data Delay */
43#define CKDV(v) (v << 4) /* Serial Clock Division Ratio */
44#define TRMD (1 << 1) /* Transmit/Receive Mode Select */
45#define EN (1 << 0) /* SSI Module Enable */
46
47/*
48 * SSISR
49 */
50#define UIRQ (1 << 27) /* Underflow Error Interrupt Status */
51#define OIRQ (1 << 26) /* Overflow Error Interrupt Status */
52#define IIRQ (1 << 25) /* Idle Mode Interrupt Status */
53#define DIRQ (1 << 24) /* Data Interrupt Status Flag */
54
Kuninori Morimoto849fc822013-07-28 18:59:02 -070055/*
56 * SSIWSR
57 */
58#define CONT (1 << 8) /* WS Continue Function */
59
Kuninori Morimoto8aefda52014-05-22 23:25:43 -070060#define SSI_NAME "ssi"
61
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070062struct rsnd_ssi {
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070063 struct rsnd_ssi_platform_info *info; /* rcar_snd.h */
64 struct rsnd_ssi *parent;
65 struct rsnd_mod mod;
66
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070067 u32 cr_own;
68 u32 cr_clk;
Kuninori Morimoto919567d2015-04-10 08:50:30 +000069 int chan;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070070 int err;
71 unsigned int usrcnt;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070072};
73
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070074#define for_each_rsnd_ssi(pos, priv, i) \
75 for (i = 0; \
76 (i < rsnd_ssi_nr(priv)) && \
Kuninori Morimotodd27d802014-01-23 18:39:40 -080077 ((pos) = ((struct rsnd_ssi *)(priv)->ssi + i)); \
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070078 i++)
79
Kuninori Morimotodd27d802014-01-23 18:39:40 -080080#define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070081#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
Kuninori Morimoto849fc822013-07-28 18:59:02 -070082#define rsnd_dma_to_ssi(dma) rsnd_mod_to_ssi(rsnd_dma_to_mod(dma))
Kuninori Morimoto6cfad782014-11-27 08:08:10 +000083#define rsnd_ssi_pio_available(ssi) ((ssi)->info->irq > 0)
Kuninori Morimoto8c5c79a2015-04-10 08:50:12 +000084#define rsnd_ssi_parent(ssi) ((ssi)->parent)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070085#define rsnd_ssi_mode_flags(p) ((p)->info->flags)
Kuninori Morimoto4b4dab82013-07-28 18:58:29 -070086#define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id)
Kuninori Morimoto04e627b2015-02-20 10:30:02 +000087#define rsnd_ssi_of_node(priv) \
88 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,ssi")
Kuninori Morimotoae5c3222013-07-21 21:36:57 -070089
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +000090int rsnd_ssi_use_busif(struct rsnd_dai_stream *io, struct rsnd_mod *mod)
Kuninori Morimotod9288d02014-06-22 17:56:23 -070091{
92 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotod9288d02014-06-22 17:56:23 -070093 int use_busif = 0;
94
Kuninori Morimoto7b466fc2014-11-27 08:05:54 +000095 if (!rsnd_ssi_is_dma_mode(mod))
96 return 0;
97
Kuninori Morimotod9288d02014-06-22 17:56:23 -070098 if (!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_NO_BUSIF))
99 use_busif = 1;
100 if (rsnd_io_to_mod_src(io))
101 use_busif = 1;
102
103 return use_busif;
104}
105
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700106static void rsnd_ssi_status_check(struct rsnd_mod *mod,
107 u32 bit)
108{
109 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
110 struct device *dev = rsnd_priv_to_dev(priv);
111 u32 status;
112 int i;
113
114 for (i = 0; i < 1024; i++) {
115 status = rsnd_mod_read(mod, SSISR);
116 if (status & bit)
117 return;
118
119 udelay(50);
120 }
121
122 dev_warn(dev, "status check failed\n");
123}
124
125static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
Kuninori Morimotoadcf7d52013-12-19 19:28:39 -0800126 struct rsnd_dai_stream *io)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700127{
Kuninori Morimoto1b13d1182015-01-15 08:08:34 +0000128 struct rsnd_priv *priv = rsnd_io_to_priv(io);
Kuninori Morimotoadcf7d52013-12-19 19:28:39 -0800129 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700130 struct device *dev = rsnd_priv_to_dev(priv);
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000131 struct rsnd_mod *mod = rsnd_mod_get(ssi);
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000132 int j, ret;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700133 int ssi_clk_mul_table[] = {
134 1, 2, 4, 8, 16, 6, 12,
135 };
136 unsigned int main_rate;
Kuninori Morimotoba9c9492014-03-03 20:51:21 -0800137 unsigned int rate = rsnd_src_get_ssi_rate(priv, io, runtime);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700138
139 /*
140 * Find best clock, and try to start ADG
141 */
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000142 for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700143
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000144 /*
145 * this driver is assuming that
146 * system word is 64fs (= 2 x 32bit)
147 * see rsnd_ssi_init()
148 */
149 main_rate = rate * 32 * 2 * ssi_clk_mul_table[j];
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700150
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000151 ret = rsnd_adg_ssi_clk_try_start(mod, main_rate);
152 if (0 == ret) {
153 ssi->cr_clk = FORCE | SWL_32 |
154 SCKD | SWSD | CKDV(j);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700155
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000156 dev_dbg(dev, "%s[%d] outputs %u Hz\n",
157 rsnd_mod_name(mod),
158 rsnd_mod_id(mod), rate);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700159
Kuninori Morimotoeae6fff2015-09-10 07:03:48 +0000160 return 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700161 }
162 }
163
164 dev_err(dev, "unsupported clock rate\n");
165 return -EIO;
166}
167
168static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi)
169{
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000170 struct rsnd_mod *mod = rsnd_mod_get(ssi);
171
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700172 ssi->cr_clk = 0;
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000173 rsnd_adg_ssi_clk_stop(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700174}
175
176static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700177 struct rsnd_dai_stream *io)
178{
Kuninori Morimoto1b13d1182015-01-15 08:08:34 +0000179 struct rsnd_priv *priv = rsnd_io_to_priv(io);
Kuninori Morimotof708d942015-01-15 08:07:19 +0000180 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700181 struct device *dev = rsnd_priv_to_dev(priv);
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000182 struct rsnd_mod *mod = rsnd_mod_get(ssi);
Kuninori Morimoto05795412014-11-27 08:05:01 +0000183 u32 cr_mode;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700184 u32 cr;
185
186 if (0 == ssi->usrcnt) {
Kuninori Morimotoc9929342015-10-22 03:15:04 +0000187 rsnd_mod_power_on(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700188
Kuninori Morimoto3ed64482015-01-15 08:04:51 +0000189 if (rsnd_rdai_is_clk_master(rdai)) {
Kuninori Morimoto8c5c79a2015-04-10 08:50:12 +0000190 struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi);
191
192 if (ssi_parent)
193 rsnd_ssi_hw_start(ssi_parent, io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700194 else
Kuninori Morimotoadcf7d52013-12-19 19:28:39 -0800195 rsnd_ssi_master_clk_start(ssi, io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700196 }
197 }
198
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000199 if (rsnd_ssi_is_dma_mode(mod)) {
Kuninori Morimoto12927a82015-06-15 06:20:54 +0000200 cr_mode = UIEN | OIEN | /* over/under run */
201 DMEN; /* DMA : enable DMA */
202 } else {
203 cr_mode = DIEN; /* PIO : enable Data interrupt */
204 }
Kuninori Morimoto05795412014-11-27 08:05:01 +0000205
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700206 cr = ssi->cr_own |
207 ssi->cr_clk |
Kuninori Morimoto05795412014-11-27 08:05:01 +0000208 cr_mode |
Kuninori Morimoto12927a82015-06-15 06:20:54 +0000209 EN;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700210
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000211 rsnd_mod_write(mod, SSICR, cr);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700212
Kuninori Morimotod1b64052014-11-27 08:05:34 +0000213 /* enable WS continue */
Kuninori Morimoto3ed64482015-01-15 08:04:51 +0000214 if (rsnd_rdai_is_clk_master(rdai))
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000215 rsnd_mod_write(mod, SSIWSR, CONT);
Kuninori Morimotod1b64052014-11-27 08:05:34 +0000216
Kuninori Morimoto3ba84f42014-11-27 08:05:44 +0000217 /* clear error status */
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000218 rsnd_mod_write(mod, SSISR, 0);
Kuninori Morimoto3ba84f42014-11-27 08:05:44 +0000219
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700220 ssi->usrcnt++;
221
Kuninori Morimoto30cc4fa2014-11-09 20:00:30 -0800222 dev_dbg(dev, "%s[%d] hw started\n",
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000223 rsnd_mod_name(mod), rsnd_mod_id(mod));
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700224}
225
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000226static void rsnd_ssi_hw_stop(struct rsnd_dai_stream *io, struct rsnd_ssi *ssi)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700227{
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000228 struct rsnd_mod *mod = rsnd_mod_get(ssi);
229 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
Kuninori Morimotof708d942015-01-15 08:07:19 +0000230 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700231 struct device *dev = rsnd_priv_to_dev(priv);
232 u32 cr;
233
Kuninori Morimotob8473572015-05-21 03:49:13 +0000234 if (0 == ssi->usrcnt) {
235 dev_err(dev, "%s called without starting\n", __func__);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700236 return;
Kuninori Morimotob8473572015-05-21 03:49:13 +0000237 }
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700238
239 ssi->usrcnt--;
240
241 if (0 == ssi->usrcnt) {
242 /*
243 * disable all IRQ,
244 * and, wait all data was sent
245 */
246 cr = ssi->cr_own |
247 ssi->cr_clk;
248
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000249 rsnd_mod_write(mod, SSICR, cr | EN);
250 rsnd_ssi_status_check(mod, DIRQ);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700251
252 /*
253 * disable SSI,
254 * and, wait idle state
255 */
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000256 rsnd_mod_write(mod, SSICR, cr); /* disabled all */
257 rsnd_ssi_status_check(mod, IIRQ);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700258
Kuninori Morimoto3ed64482015-01-15 08:04:51 +0000259 if (rsnd_rdai_is_clk_master(rdai)) {
Kuninori Morimoto8c5c79a2015-04-10 08:50:12 +0000260 struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi);
261
262 if (ssi_parent)
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000263 rsnd_ssi_hw_stop(io, ssi_parent);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700264 else
265 rsnd_ssi_master_clk_stop(ssi);
266 }
267
Kuninori Morimotoc9929342015-10-22 03:15:04 +0000268 rsnd_mod_power_off(mod);
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000269
270 ssi->chan = 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700271 }
272
Kuninori Morimoto30cc4fa2014-11-09 20:00:30 -0800273 dev_dbg(dev, "%s[%d] hw stopped\n",
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000274 rsnd_mod_name(mod), rsnd_mod_id(mod));
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700275}
276
277/*
278 * SSI mod common functions
279 */
280static int rsnd_ssi_init(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000281 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000282 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700283{
284 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000285 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700286 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
287 u32 cr;
288
289 cr = FORCE;
290
291 /*
292 * always use 32bit system word for easy clock calculation.
293 * see also rsnd_ssi_master_clk_enable()
294 */
295 cr |= SWL_32;
296
297 /*
298 * init clock settings for SSICR
299 */
300 switch (runtime->sample_bits) {
301 case 16:
302 cr |= DWL_16;
303 break;
304 case 32:
305 cr |= DWL_24;
306 break;
307 default:
308 return -EIO;
309 }
310
311 if (rdai->bit_clk_inv)
312 cr |= SCKP;
313 if (rdai->frm_clk_inv)
314 cr |= SWSP;
315 if (rdai->data_alignment)
316 cr |= SDTA;
317 if (rdai->sys_delay)
318 cr |= DEL;
Kuninori Morimoto985a4f62015-01-15 08:06:49 +0000319 if (rsnd_io_is_play(io))
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700320 cr |= TRMD;
321
322 /*
323 * set ssi parameter
324 */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700325 ssi->cr_own = cr;
326 ssi->err = -1; /* ignore 1st error */
327
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700328 return 0;
329}
330
331static int rsnd_ssi_quit(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000332 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000333 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700334{
335 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700336 struct device *dev = rsnd_priv_to_dev(priv);
337
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700338 if (ssi->err > 0)
Kuninori Morimoto337b0b42015-01-15 08:08:57 +0000339 dev_warn(dev, "%s[%d] under/over flow err = %d\n",
340 rsnd_mod_name(mod), rsnd_mod_id(mod), ssi->err);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700341
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700342 ssi->cr_own = 0;
343 ssi->err = 0;
344
345 return 0;
346}
347
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000348static int rsnd_ssi_hw_params(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000349 struct rsnd_dai_stream *io,
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000350 struct snd_pcm_substream *substream,
351 struct snd_pcm_hw_params *params)
352{
353 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
354 struct rsnd_ssi *ssi_parent = rsnd_ssi_parent(ssi);
355 int chan = params_channels(params);
356
357 /*
358 * Already working.
359 * It will happen if SSI has parent/child connection.
360 */
361 if (ssi->usrcnt) {
362 /*
363 * it is error if child <-> parent SSI uses
364 * different channels.
365 */
366 if (ssi->chan != chan)
367 return -EIO;
368 }
369
370 /* It will be removed on rsnd_ssi_hw_stop */
371 ssi->chan = chan;
372 if (ssi_parent)
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000373 return rsnd_ssi_hw_params(rsnd_mod_get(ssi_parent), io,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000374 substream, params);
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000375
376 return 0;
377}
378
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700379static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
380{
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000381 struct rsnd_mod *mod = rsnd_mod_get(ssi);
382
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700383 /* under/over flow error */
384 if (status & (UIRQ | OIRQ)) {
385 ssi->err++;
386
387 /* clear error status */
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000388 rsnd_mod_write(mod, SSISR, 0);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700389 }
390}
391
Kuninori Morimoto49229852014-11-27 08:07:17 +0000392static int rsnd_ssi_start(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000393 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000394 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700395{
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700396 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700397
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000398 rsnd_src_ssiu_start(mod, io, rsnd_ssi_use_busif(io, mod));
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700399
Kuninori Morimotof708d942015-01-15 08:07:19 +0000400 rsnd_ssi_hw_start(ssi, io);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700401
Kuninori Morimotof708d942015-01-15 08:07:19 +0000402 rsnd_src_ssi_irq_enable(mod);
Kuninori Morimotoc17dba82014-11-27 08:05:09 +0000403
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700404 return 0;
405}
406
Kuninori Morimoto49229852014-11-27 08:07:17 +0000407static int rsnd_ssi_stop(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000408 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000409 struct rsnd_priv *priv)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700410{
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700411 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
412
Kuninori Morimotof708d942015-01-15 08:07:19 +0000413 rsnd_src_ssi_irq_disable(mod);
Kuninori Morimotoc17dba82014-11-27 08:05:09 +0000414
Kuninori Morimoto7b466fc2014-11-27 08:05:54 +0000415 rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
416
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000417 rsnd_ssi_hw_stop(io, ssi);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700418
Kuninori Morimoto4e2639f2015-06-15 06:26:08 +0000419 rsnd_src_ssiu_stop(mod, io);
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700420
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700421 return 0;
422}
423
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000424static void __rsnd_ssi_interrupt(struct rsnd_mod *mod,
425 struct rsnd_dai_stream *io)
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000426{
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000427 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000428 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
Kuninori Morimoto765ae7c2015-01-15 08:09:13 +0000429 int is_dma = rsnd_ssi_is_dma_mode(mod);
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000430 u32 status;
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000431 bool elapsed = false;
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000432
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000433 spin_lock(&priv->lock);
434
435 /* ignore all cases if not working */
Kuninori Morimotod5bbe7d2015-06-15 06:27:47 +0000436 if (!rsnd_io_is_working(io))
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000437 goto rsnd_ssi_interrupt_out;
438
439 status = rsnd_mod_read(mod, SSISR);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000440
441 /* PIO only */
Kuninori Morimoto765ae7c2015-01-15 08:09:13 +0000442 if (!is_dma && (status & DIRQ)) {
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000443 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
444 u32 *buf = (u32 *)(runtime->dma_area +
445 rsnd_dai_pointer_offset(io, 0));
446
447 /*
448 * 8/16/32 data can be assesse to TDR/RDR register
449 * directly as 32bit data
450 * see rsnd_ssi_init()
451 */
Kuninori Morimoto985a4f62015-01-15 08:06:49 +0000452 if (rsnd_io_is_play(io))
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000453 rsnd_mod_write(mod, SSITDR, *buf);
454 else
455 *buf = rsnd_mod_read(mod, SSIRDR);
456
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000457 elapsed = rsnd_dai_pointer_update(io, sizeof(*buf));
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000458 }
459
Kuninori Morimoto12927a82015-06-15 06:20:54 +0000460 /* DMA only */
461 if (is_dma && (status & (UIRQ | OIRQ))) {
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000462 struct device *dev = rsnd_priv_to_dev(priv);
463
464 /*
465 * restart SSI
466 */
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000467 dev_dbg(dev, "%s[%d] restart\n",
468 rsnd_mod_name(mod), rsnd_mod_id(mod));
Kuninori Morimoto044930b2015-03-19 04:13:47 +0000469
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000470 rsnd_ssi_stop(mod, io, priv);
Kuninori Morimoto044930b2015-03-19 04:13:47 +0000471 if (ssi->err < 1024)
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000472 rsnd_ssi_start(mod, io, priv);
Kuninori Morimoto044930b2015-03-19 04:13:47 +0000473 else
474 dev_warn(dev, "no more SSI restart\n");
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000475 }
476
477 rsnd_ssi_record_error(ssi, status);
478
Kuninori Morimoto02299d92015-05-21 03:50:23 +0000479rsnd_ssi_interrupt_out:
480 spin_unlock(&priv->lock);
481
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000482 if (elapsed)
483 rsnd_dai_period_elapsed(io);
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000484}
485
486static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
487{
488 struct rsnd_mod *mod = data;
489
490 rsnd_mod_interrupt(mod, __rsnd_ssi_interrupt);
Kuninori Morimoto75defee2015-06-15 06:21:15 +0000491
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000492 return IRQ_HANDLED;
493}
494
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000495/*
496 * SSI PIO
497 */
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000498static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000499 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000500 struct rsnd_priv *priv)
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000501{
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000502 struct device *dev = rsnd_priv_to_dev(priv);
503 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000504 int ret;
505
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000506 ret = devm_request_irq(dev, ssi->info->irq,
507 rsnd_ssi_interrupt,
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000508 IRQF_SHARED,
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000509 dev_name(dev), mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000510
511 return ret;
512}
513
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700514static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700515 .name = SSI_NAME,
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800516 .probe = rsnd_ssi_pio_probe,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700517 .init = rsnd_ssi_init,
518 .quit = rsnd_ssi_quit,
Kuninori Morimoto49229852014-11-27 08:07:17 +0000519 .start = rsnd_ssi_start,
520 .stop = rsnd_ssi_stop,
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000521 .hw_params = rsnd_ssi_hw_params,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700522};
523
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800524static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000525 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000526 struct rsnd_priv *priv)
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800527{
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800528 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800529 struct device *dev = rsnd_priv_to_dev(priv);
530 int dma_id = ssi->info->dma_id;
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800531 int ret;
532
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000533 ret = devm_request_irq(dev, ssi->info->irq,
534 rsnd_ssi_interrupt,
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000535 IRQF_SHARED,
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000536 dev_name(dev), mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000537 if (ret)
Kuninori Morimotob543b522015-03-26 04:02:32 +0000538 return ret;
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000539
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800540 ret = rsnd_dma_init(
Kuninori Morimoto9b99e9a2015-06-15 06:26:25 +0000541 io, rsnd_mod_to_dma(mod),
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800542 dma_id);
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700543
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800544 return ret;
545}
546
547static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000548 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000549 struct rsnd_priv *priv)
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800550{
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000551 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
552 struct device *dev = rsnd_priv_to_dev(priv);
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000553 int irq = ssi->info->irq;
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000554
Kuninori Morimoto9b99e9a2015-06-15 06:26:25 +0000555 rsnd_dma_quit(io, rsnd_mod_to_dma(mod));
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000556
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000557 /* PIO will request IRQ again */
Kuninori Morimotob05ce4c2015-10-22 03:13:44 +0000558 devm_free_irq(dev, irq, mod);
Kuninori Morimoto4e7d6062014-11-27 08:07:47 +0000559
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000560 return 0;
561}
562
563static int rsnd_ssi_fallback(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000564 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000565 struct rsnd_priv *priv)
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000566{
Kuninori Morimotod3a76822014-11-09 20:00:58 -0800567 struct device *dev = rsnd_priv_to_dev(priv);
568
Kuninori Morimotod3a76822014-11-09 20:00:58 -0800569 /*
570 * fallback to PIO
571 *
572 * SSI .probe might be called again.
573 * see
574 * rsnd_rdai_continuance_probe()
575 */
576 mod->ops = &rsnd_ssi_pio_ops;
577
578 dev_info(dev, "%s[%d] fallback to PIO mode\n",
579 rsnd_mod_name(mod), rsnd_mod_id(mod));
580
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800581 return 0;
582}
583
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700584static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000585 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000586 struct rsnd_priv *priv)
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700587{
Kuninori Morimoto49229852014-11-27 08:07:17 +0000588 struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700589
Kuninori Morimoto9b99e9a2015-06-15 06:26:25 +0000590 rsnd_dma_start(io, dma);
Kuninori Morimoto7b466fc2014-11-27 08:05:54 +0000591
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000592 rsnd_ssi_start(mod, io, priv);
Kuninori Morimoto1ceeab22015-01-15 08:09:26 +0000593
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700594 return 0;
595}
596
597static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000598 struct rsnd_dai_stream *io,
Kuninori Morimoto690602f2015-01-15 08:07:47 +0000599 struct rsnd_priv *priv)
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700600{
Kuninori Morimoto49229852014-11-27 08:07:17 +0000601 struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700602
Kuninori Morimoto2c0fac12015-06-15 06:25:20 +0000603 rsnd_ssi_stop(mod, io, priv);
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700604
Kuninori Morimoto9b99e9a2015-06-15 06:26:25 +0000605 rsnd_dma_stop(io, dma);
Kuninori Morimoto1ceeab22015-01-15 08:09:26 +0000606
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700607 return 0;
608}
609
Kuninori Morimoto9b99e9a2015-06-15 06:26:25 +0000610static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_dai_stream *io,
611 struct rsnd_mod *mod)
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700612{
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000613 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000614 int is_play = rsnd_io_is_play(io);
615 char *name;
616
Kuninori Morimotobfc0cfe2015-06-15 06:26:56 +0000617 if (rsnd_ssi_use_busif(io, mod))
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000618 name = is_play ? "rxu" : "txu";
619 else
620 name = is_play ? "rx" : "tx";
621
622 return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
623 mod, name);
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700624}
625
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700626static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700627 .name = SSI_NAME,
Kuninori Morimoto72adc612015-02-20 10:31:23 +0000628 .dma_req = rsnd_ssi_dma_req,
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800629 .probe = rsnd_ssi_dma_probe,
630 .remove = rsnd_ssi_dma_remove,
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700631 .init = rsnd_ssi_init,
632 .quit = rsnd_ssi_quit,
633 .start = rsnd_ssi_dma_start,
634 .stop = rsnd_ssi_dma_stop,
Kuninori Morimoto97463e12014-11-27 08:02:43 +0000635 .fallback = rsnd_ssi_fallback,
Kuninori Morimoto919567d2015-04-10 08:50:30 +0000636 .hw_params = rsnd_ssi_hw_params,
Kuninori Morimoto849fc822013-07-28 18:59:02 -0700637};
638
Kuninori Morimoto05795412014-11-27 08:05:01 +0000639int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
640{
641 return mod->ops == &rsnd_ssi_dma_ops;
642}
643
644
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700645/*
646 * Non SSI
647 */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700648static struct rsnd_mod_ops rsnd_ssi_non_ops = {
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700649 .name = SSI_NAME,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700650};
651
652/*
653 * ssi mod function
654 */
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700655struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
656{
Takashi Iwai8b147192013-11-05 18:40:05 +0100657 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
658 id = 0;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700659
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000660 return rsnd_mod_get((struct rsnd_ssi *)(priv->ssi) + id);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700661}
662
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800663int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
664{
665 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
666
667 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
668}
669
Kuninori Morimoto8c5c79a2015-04-10 08:50:12 +0000670static void rsnd_ssi_parent_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi)
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800671{
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000672 struct rsnd_mod *mod = rsnd_mod_get(ssi);
673
674 if (!rsnd_ssi_is_pin_sharing(mod))
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800675 return;
676
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000677 switch (rsnd_mod_id(mod)) {
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800678 case 1:
679 case 2:
680 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0));
681 break;
682 case 4:
683 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 3));
684 break;
685 case 8:
686 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 7));
687 break;
688 }
689}
690
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700691
692static void rsnd_of_parse_ssi(struct platform_device *pdev,
693 const struct rsnd_of_data *of_data,
694 struct rsnd_priv *priv)
695{
696 struct device_node *node;
697 struct device_node *np;
698 struct rsnd_ssi_platform_info *ssi_info;
699 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
700 struct device *dev = &pdev->dev;
701 int nr, i;
702
Kuninori Morimoto04e627b2015-02-20 10:30:02 +0000703 node = rsnd_ssi_of_node(priv);
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700704 if (!node)
705 return;
706
707 nr = of_get_child_count(node);
708 if (!nr)
Kuninori Morimotof451e482014-05-22 23:24:59 -0700709 goto rsnd_of_parse_ssi_end;
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700710
711 ssi_info = devm_kzalloc(dev,
712 sizeof(struct rsnd_ssi_platform_info) * nr,
713 GFP_KERNEL);
714 if (!ssi_info) {
715 dev_err(dev, "ssi info allocation error\n");
Kuninori Morimotof451e482014-05-22 23:24:59 -0700716 goto rsnd_of_parse_ssi_end;
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700717 }
718
719 info->ssi_info = ssi_info;
720 info->ssi_info_nr = nr;
721
722 i = -1;
723 for_each_child_of_node(node, np) {
724 i++;
725
726 ssi_info = info->ssi_info + i;
727
728 /*
729 * pin settings
730 */
731 if (of_get_property(np, "shared-pin", NULL))
732 ssi_info->flags |= RSND_SSI_CLK_PIN_SHARE;
733
734 /*
735 * irq
736 */
Kuninori Morimoto6cfad782014-11-27 08:08:10 +0000737 ssi_info->irq = irq_of_parse_and_map(np, 0);
Kuninori Morimoto199e76882014-05-22 23:25:49 -0700738
739 /*
740 * DMA
741 */
742 ssi_info->dma_id = of_get_property(np, "pio-transfer", NULL) ?
743 0 : 1;
Kuninori Morimotod9288d02014-06-22 17:56:23 -0700744
745 if (of_get_property(np, "no-busif", NULL))
746 ssi_info->flags |= RSND_SSI_NO_BUSIF;
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700747 }
Kuninori Morimotof451e482014-05-22 23:24:59 -0700748
749rsnd_of_parse_ssi_end:
750 of_node_put(node);
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700751}
752
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700753int rsnd_ssi_probe(struct platform_device *pdev,
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700754 const struct rsnd_of_data *of_data,
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700755 struct rsnd_priv *priv)
756{
Kuninori Morimoto5da39cf2014-02-24 22:15:00 -0800757 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700758 struct rsnd_ssi_platform_info *pinfo;
759 struct device *dev = rsnd_priv_to_dev(priv);
760 struct rsnd_mod_ops *ops;
761 struct clk *clk;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700762 struct rsnd_ssi *ssi;
763 char name[RSND_SSI_NAME_SIZE];
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000764 int i, nr, ret;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700765
Kuninori Morimoto90e8e502014-03-17 19:29:55 -0700766 rsnd_of_parse_ssi(pdev, of_data, priv);
767
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700768 /*
769 * init SSI
770 */
771 nr = info->ssi_info_nr;
Kuninori Morimotodd27d802014-01-23 18:39:40 -0800772 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
Kuninori Morimotoafa700722015-07-15 07:08:24 +0000773 if (!ssi)
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700774 return -ENOMEM;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700775
Kuninori Morimotodd27d802014-01-23 18:39:40 -0800776 priv->ssi = ssi;
777 priv->ssi_nr = nr;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700778
779 for_each_rsnd_ssi(ssi, priv, i) {
780 pinfo = &info->ssi_info[i];
781
Kuninori Morimoto8aefda52014-05-22 23:25:43 -0700782 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
783 SSI_NAME, i);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700784
Kuninori Morimoto60dbb4f2013-12-03 22:09:33 -0800785 clk = devm_clk_get(dev, name);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700786 if (IS_ERR(clk))
787 return PTR_ERR(clk);
788
789 ssi->info = pinfo;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700790
791 ops = &rsnd_ssi_non_ops;
Kuninori Morimotoff8f30e2014-03-03 20:50:49 -0800792 if (pinfo->dma_id > 0)
793 ops = &rsnd_ssi_dma_ops;
794 else if (rsnd_ssi_pio_available(ssi))
795 ops = &rsnd_ssi_pio_ops;
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700796
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000797 ret = rsnd_mod_init(priv, rsnd_mod_get(ssi), ops, clk,
798 RSND_MOD_SSI, i);
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000799 if (ret)
800 return ret;
Kuninori Morimoto7b5ce972014-01-23 18:39:32 -0800801
Kuninori Morimoto8c5c79a2015-04-10 08:50:12 +0000802 rsnd_ssi_parent_setup(priv, ssi);
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700803 }
804
Kuninori Morimotoae5c3222013-07-21 21:36:57 -0700805 return 0;
806}
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000807
808void rsnd_ssi_remove(struct platform_device *pdev,
809 struct rsnd_priv *priv)
810{
811 struct rsnd_ssi *ssi;
812 int i;
813
814 for_each_rsnd_ssi(ssi, priv, i) {
Kuninori Morimotob76e2182015-09-10 07:02:21 +0000815 rsnd_mod_quit(rsnd_mod_get(ssi));
Kuninori Morimoto2f78dd72015-03-26 04:02:09 +0000816 }
817}