xref: /linux/sound/soc/sh/rcar/ssi.c (revision 827634added7f38b7d724cab1dccdb2b004c13c3)
1 /*
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 */
22 #define	DMEN		(1 << 28)	/* DMA Enable */
23 #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 
55 /*
56  * SSIWSR
57  */
58 #define CONT		(1 << 8)	/* WS Continue Function */
59 
60 #define SSI_NAME "ssi"
61 
62 struct rsnd_ssi {
63 	struct rsnd_ssi_platform_info *info; /* rcar_snd.h */
64 	struct rsnd_ssi *parent;
65 	struct rsnd_mod mod;
66 
67 	u32 cr_own;
68 	u32 cr_clk;
69 	int err;
70 	unsigned int usrcnt;
71 };
72 
73 #define for_each_rsnd_ssi(pos, priv, i)					\
74 	for (i = 0;							\
75 	     (i < rsnd_ssi_nr(priv)) &&					\
76 		((pos) = ((struct rsnd_ssi *)(priv)->ssi + i));		\
77 	     i++)
78 
79 #define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
80 #define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
81 #define rsnd_dma_to_ssi(dma)  rsnd_mod_to_ssi(rsnd_dma_to_mod(dma))
82 #define rsnd_ssi_pio_available(ssi) ((ssi)->info->irq > 0)
83 #define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent)
84 #define rsnd_ssi_mode_flags(p) ((p)->info->flags)
85 #define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id)
86 #define rsnd_ssi_of_node(priv) \
87 	of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,ssi")
88 
89 int rsnd_ssi_use_busif(struct rsnd_mod *mod)
90 {
91 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
92 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
93 	int use_busif = 0;
94 
95 	if (!rsnd_ssi_is_dma_mode(mod))
96 		return 0;
97 
98 	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 
106 static 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 
125 static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
126 				     struct rsnd_dai_stream *io)
127 {
128 	struct rsnd_priv *priv = rsnd_io_to_priv(io);
129 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
130 	struct device *dev = rsnd_priv_to_dev(priv);
131 	int i, j, ret;
132 	int adg_clk_div_table[] = {
133 		1, 6, /* see adg.c */
134 	};
135 	int ssi_clk_mul_table[] = {
136 		1, 2, 4, 8, 16, 6, 12,
137 	};
138 	unsigned int main_rate;
139 	unsigned int rate = rsnd_src_get_ssi_rate(priv, io, runtime);
140 
141 	/*
142 	 * Find best clock, and try to start ADG
143 	 */
144 	for (i = 0; i < ARRAY_SIZE(adg_clk_div_table); i++) {
145 		for (j = 0; j < ARRAY_SIZE(ssi_clk_mul_table); j++) {
146 
147 			/*
148 			 * this driver is assuming that
149 			 * system word is 64fs (= 2 x 32bit)
150 			 * see rsnd_ssi_init()
151 			 */
152 			main_rate = rate / adg_clk_div_table[i]
153 				* 32 * 2 * ssi_clk_mul_table[j];
154 
155 			ret = rsnd_adg_ssi_clk_try_start(&ssi->mod, main_rate);
156 			if (0 == ret) {
157 				ssi->cr_clk	= FORCE | SWL_32 |
158 						  SCKD | SWSD | CKDV(j);
159 
160 				dev_dbg(dev, "%s[%d] outputs %u Hz\n",
161 					rsnd_mod_name(&ssi->mod),
162 					rsnd_mod_id(&ssi->mod), rate);
163 
164 				return 0;
165 			}
166 		}
167 	}
168 
169 	dev_err(dev, "unsupported clock rate\n");
170 	return -EIO;
171 }
172 
173 static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi)
174 {
175 	ssi->cr_clk = 0;
176 	rsnd_adg_ssi_clk_stop(&ssi->mod);
177 }
178 
179 static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
180 			      struct rsnd_dai_stream *io)
181 {
182 	struct rsnd_priv *priv = rsnd_io_to_priv(io);
183 	struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
184 	struct device *dev = rsnd_priv_to_dev(priv);
185 	u32 cr_mode;
186 	u32 cr;
187 
188 	if (0 == ssi->usrcnt) {
189 		rsnd_mod_hw_start(&ssi->mod);
190 
191 		if (rsnd_rdai_is_clk_master(rdai)) {
192 			if (rsnd_ssi_clk_from_parent(ssi))
193 				rsnd_ssi_hw_start(ssi->parent, io);
194 			else
195 				rsnd_ssi_master_clk_start(ssi, io);
196 		}
197 	}
198 
199 	cr_mode = rsnd_ssi_is_dma_mode(&ssi->mod) ?
200 		DMEN :	/* DMA : enable DMA */
201 		DIEN;	/* PIO : enable Data interrupt */
202 
203 
204 	cr  =	ssi->cr_own	|
205 		ssi->cr_clk	|
206 		cr_mode		|
207 		UIEN | OIEN | EN;
208 
209 	rsnd_mod_write(&ssi->mod, SSICR, cr);
210 
211 	/* enable WS continue */
212 	if (rsnd_rdai_is_clk_master(rdai))
213 		rsnd_mod_write(&ssi->mod, SSIWSR, CONT);
214 
215 	/* clear error status */
216 	rsnd_mod_write(&ssi->mod, SSISR, 0);
217 
218 	ssi->usrcnt++;
219 
220 	dev_dbg(dev, "%s[%d] hw started\n",
221 		rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
222 }
223 
224 static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi)
225 {
226 	struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
227 	struct rsnd_dai_stream *io = rsnd_mod_to_io(&ssi->mod);
228 	struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
229 	struct device *dev = rsnd_priv_to_dev(priv);
230 	u32 cr;
231 
232 	if (0 == ssi->usrcnt) /* stop might be called without start */
233 		return;
234 
235 	ssi->usrcnt--;
236 
237 	if (0 == ssi->usrcnt) {
238 		/*
239 		 * disable all IRQ,
240 		 * and, wait all data was sent
241 		 */
242 		cr  =	ssi->cr_own	|
243 			ssi->cr_clk;
244 
245 		rsnd_mod_write(&ssi->mod, SSICR, cr | EN);
246 		rsnd_ssi_status_check(&ssi->mod, DIRQ);
247 
248 		/*
249 		 * disable SSI,
250 		 * and, wait idle state
251 		 */
252 		rsnd_mod_write(&ssi->mod, SSICR, cr);	/* disabled all */
253 		rsnd_ssi_status_check(&ssi->mod, IIRQ);
254 
255 		if (rsnd_rdai_is_clk_master(rdai)) {
256 			if (rsnd_ssi_clk_from_parent(ssi))
257 				rsnd_ssi_hw_stop(ssi->parent);
258 			else
259 				rsnd_ssi_master_clk_stop(ssi);
260 		}
261 
262 		rsnd_mod_hw_stop(&ssi->mod);
263 	}
264 
265 	dev_dbg(dev, "%s[%d] hw stopped\n",
266 		rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
267 }
268 
269 /*
270  *	SSI mod common functions
271  */
272 static int rsnd_ssi_init(struct rsnd_mod *mod,
273 			 struct rsnd_priv *priv)
274 {
275 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
276 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
277 	struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
278 	struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
279 	u32 cr;
280 
281 	cr = FORCE;
282 
283 	/*
284 	 * always use 32bit system word for easy clock calculation.
285 	 * see also rsnd_ssi_master_clk_enable()
286 	 */
287 	cr |= SWL_32;
288 
289 	/*
290 	 * init clock settings for SSICR
291 	 */
292 	switch (runtime->sample_bits) {
293 	case 16:
294 		cr |= DWL_16;
295 		break;
296 	case 32:
297 		cr |= DWL_24;
298 		break;
299 	default:
300 		return -EIO;
301 	}
302 
303 	if (rdai->bit_clk_inv)
304 		cr |= SCKP;
305 	if (rdai->frm_clk_inv)
306 		cr |= SWSP;
307 	if (rdai->data_alignment)
308 		cr |= SDTA;
309 	if (rdai->sys_delay)
310 		cr |= DEL;
311 	if (rsnd_io_is_play(io))
312 		cr |= TRMD;
313 
314 	/*
315 	 * set ssi parameter
316 	 */
317 	ssi->cr_own	= cr;
318 	ssi->err	= -1; /* ignore 1st error */
319 
320 	return 0;
321 }
322 
323 static int rsnd_ssi_quit(struct rsnd_mod *mod,
324 			 struct rsnd_priv *priv)
325 {
326 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
327 	struct device *dev = rsnd_priv_to_dev(priv);
328 
329 	if (ssi->err > 0)
330 		dev_warn(dev, "%s[%d] under/over flow err = %d\n",
331 			 rsnd_mod_name(mod), rsnd_mod_id(mod), ssi->err);
332 
333 	ssi->cr_own	= 0;
334 	ssi->err	= 0;
335 
336 	return 0;
337 }
338 
339 static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
340 {
341 	/* under/over flow error */
342 	if (status & (UIRQ | OIRQ)) {
343 		ssi->err++;
344 
345 		/* clear error status */
346 		rsnd_mod_write(&ssi->mod, SSISR, 0);
347 	}
348 }
349 
350 static int rsnd_ssi_start(struct rsnd_mod *mod,
351 			  struct rsnd_priv *priv)
352 {
353 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
354 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
355 
356 	rsnd_src_ssiu_start(mod, rsnd_ssi_use_busif(mod));
357 
358 	rsnd_ssi_hw_start(ssi, io);
359 
360 	rsnd_src_ssi_irq_enable(mod);
361 
362 	return 0;
363 }
364 
365 static int rsnd_ssi_stop(struct rsnd_mod *mod,
366 			 struct rsnd_priv *priv)
367 {
368 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
369 
370 	rsnd_src_ssi_irq_disable(mod);
371 
372 	rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
373 
374 	rsnd_ssi_hw_stop(ssi);
375 
376 	rsnd_src_ssiu_stop(mod);
377 
378 	return 0;
379 }
380 
381 static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
382 {
383 	struct rsnd_ssi *ssi = data;
384 	struct rsnd_mod *mod = &ssi->mod;
385 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
386 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
387 	int is_dma = rsnd_ssi_is_dma_mode(mod);
388 	u32 status = rsnd_mod_read(mod, SSISR);
389 
390 	if (!io)
391 		return IRQ_NONE;
392 
393 	/* PIO only */
394 	if (!is_dma && (status & DIRQ)) {
395 		struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
396 		u32 *buf = (u32 *)(runtime->dma_area +
397 				   rsnd_dai_pointer_offset(io, 0));
398 
399 		/*
400 		 * 8/16/32 data can be assesse to TDR/RDR register
401 		 * directly as 32bit data
402 		 * see rsnd_ssi_init()
403 		 */
404 		if (rsnd_io_is_play(io))
405 			rsnd_mod_write(mod, SSITDR, *buf);
406 		else
407 			*buf = rsnd_mod_read(mod, SSIRDR);
408 
409 		rsnd_dai_pointer_update(io, sizeof(*buf));
410 	}
411 
412 	/* PIO / DMA */
413 	if (status & (UIRQ | OIRQ)) {
414 		struct device *dev = rsnd_priv_to_dev(priv);
415 
416 		/*
417 		 * restart SSI
418 		 */
419 		dev_dbg(dev, "%s[%d] restart\n",
420 			rsnd_mod_name(mod), rsnd_mod_id(mod));
421 
422 		rsnd_ssi_stop(mod, priv);
423 		if (ssi->err < 1024)
424 			rsnd_ssi_start(mod, priv);
425 		else
426 			dev_warn(dev, "no more SSI restart\n");
427 	}
428 
429 	rsnd_ssi_record_error(ssi, status);
430 
431 	return IRQ_HANDLED;
432 }
433 
434 /*
435  *		SSI PIO
436  */
437 static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
438 			      struct rsnd_priv *priv)
439 {
440 	struct device *dev = rsnd_priv_to_dev(priv);
441 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
442 	int ret;
443 
444 	ret = devm_request_irq(dev, ssi->info->irq,
445 			       rsnd_ssi_interrupt,
446 			       IRQF_SHARED,
447 			       dev_name(dev), ssi);
448 
449 	return ret;
450 }
451 
452 static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
453 	.name	= SSI_NAME,
454 	.probe	= rsnd_ssi_pio_probe,
455 	.init	= rsnd_ssi_init,
456 	.quit	= rsnd_ssi_quit,
457 	.start	= rsnd_ssi_start,
458 	.stop	= rsnd_ssi_stop,
459 };
460 
461 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
462 			      struct rsnd_priv *priv)
463 {
464 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
465 	struct device *dev = rsnd_priv_to_dev(priv);
466 	int dma_id = ssi->info->dma_id;
467 	int ret;
468 
469 	ret = devm_request_irq(dev, ssi->info->irq,
470 			       rsnd_ssi_interrupt,
471 			       IRQF_SHARED,
472 			       dev_name(dev), ssi);
473 	if (ret)
474 		return ret;
475 
476 	ret = rsnd_dma_init(
477 		priv, rsnd_mod_to_dma(mod),
478 		dma_id);
479 
480 	return ret;
481 }
482 
483 static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
484 			       struct rsnd_priv *priv)
485 {
486 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
487 	struct device *dev = rsnd_priv_to_dev(priv);
488 	int irq = ssi->info->irq;
489 
490 	rsnd_dma_quit(rsnd_mod_to_dma(mod));
491 
492 	/* PIO will request IRQ again */
493 	devm_free_irq(dev, irq, ssi);
494 
495 	return 0;
496 }
497 
498 static int rsnd_ssi_fallback(struct rsnd_mod *mod,
499 			     struct rsnd_priv *priv)
500 {
501 	struct device *dev = rsnd_priv_to_dev(priv);
502 
503 	/*
504 	 * fallback to PIO
505 	 *
506 	 * SSI .probe might be called again.
507 	 * see
508 	 *	rsnd_rdai_continuance_probe()
509 	 */
510 	mod->ops = &rsnd_ssi_pio_ops;
511 
512 	dev_info(dev, "%s[%d] fallback to PIO mode\n",
513 		 rsnd_mod_name(mod), rsnd_mod_id(mod));
514 
515 	return 0;
516 }
517 
518 static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
519 			      struct rsnd_priv *priv)
520 {
521 	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
522 
523 	rsnd_dma_start(dma);
524 
525 	rsnd_ssi_start(mod, priv);
526 
527 	return 0;
528 }
529 
530 static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
531 			     struct rsnd_priv *priv)
532 {
533 	struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
534 
535 	rsnd_ssi_stop(mod, priv);
536 
537 	rsnd_dma_stop(dma);
538 
539 	return 0;
540 }
541 
542 static struct dma_chan *rsnd_ssi_dma_req(struct rsnd_mod *mod)
543 {
544 	struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
545 	struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
546 	int is_play = rsnd_io_is_play(io);
547 	char *name;
548 
549 	if (rsnd_ssi_use_busif(mod))
550 		name = is_play ? "rxu" : "txu";
551 	else
552 		name = is_play ? "rx" : "tx";
553 
554 	return rsnd_dma_request_channel(rsnd_ssi_of_node(priv),
555 					mod, name);
556 }
557 
558 static struct rsnd_mod_ops rsnd_ssi_dma_ops = {
559 	.name	= SSI_NAME,
560 	.dma_req = rsnd_ssi_dma_req,
561 	.probe	= rsnd_ssi_dma_probe,
562 	.remove	= rsnd_ssi_dma_remove,
563 	.init	= rsnd_ssi_init,
564 	.quit	= rsnd_ssi_quit,
565 	.start	= rsnd_ssi_dma_start,
566 	.stop	= rsnd_ssi_dma_stop,
567 	.fallback = rsnd_ssi_fallback,
568 };
569 
570 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod)
571 {
572 	return mod->ops == &rsnd_ssi_dma_ops;
573 }
574 
575 
576 /*
577  *		Non SSI
578  */
579 static struct rsnd_mod_ops rsnd_ssi_non_ops = {
580 	.name	= SSI_NAME,
581 };
582 
583 /*
584  *		ssi mod function
585  */
586 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id)
587 {
588 	if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv)))
589 		id = 0;
590 
591 	return &((struct rsnd_ssi *)(priv->ssi) + id)->mod;
592 }
593 
594 int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
595 {
596 	struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
597 
598 	return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE);
599 }
600 
601 static void rsnd_ssi_parent_clk_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi)
602 {
603 	if (!rsnd_ssi_is_pin_sharing(&ssi->mod))
604 		return;
605 
606 	switch (rsnd_mod_id(&ssi->mod)) {
607 	case 1:
608 	case 2:
609 		ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0));
610 		break;
611 	case 4:
612 		ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 3));
613 		break;
614 	case 8:
615 		ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 7));
616 		break;
617 	}
618 }
619 
620 
621 static void rsnd_of_parse_ssi(struct platform_device *pdev,
622 			      const struct rsnd_of_data *of_data,
623 			      struct rsnd_priv *priv)
624 {
625 	struct device_node *node;
626 	struct device_node *np;
627 	struct rsnd_ssi_platform_info *ssi_info;
628 	struct rcar_snd_info *info = rsnd_priv_to_info(priv);
629 	struct device *dev = &pdev->dev;
630 	int nr, i;
631 
632 	if (!of_data)
633 		return;
634 
635 	node = rsnd_ssi_of_node(priv);
636 	if (!node)
637 		return;
638 
639 	nr = of_get_child_count(node);
640 	if (!nr)
641 		goto rsnd_of_parse_ssi_end;
642 
643 	ssi_info = devm_kzalloc(dev,
644 				sizeof(struct rsnd_ssi_platform_info) * nr,
645 				GFP_KERNEL);
646 	if (!ssi_info) {
647 		dev_err(dev, "ssi info allocation error\n");
648 		goto rsnd_of_parse_ssi_end;
649 	}
650 
651 	info->ssi_info		= ssi_info;
652 	info->ssi_info_nr	= nr;
653 
654 	i = -1;
655 	for_each_child_of_node(node, np) {
656 		i++;
657 
658 		ssi_info = info->ssi_info + i;
659 
660 		/*
661 		 * pin settings
662 		 */
663 		if (of_get_property(np, "shared-pin", NULL))
664 			ssi_info->flags |= RSND_SSI_CLK_PIN_SHARE;
665 
666 		/*
667 		 * irq
668 		 */
669 		ssi_info->irq = irq_of_parse_and_map(np, 0);
670 
671 		/*
672 		 * DMA
673 		 */
674 		ssi_info->dma_id = of_get_property(np, "pio-transfer", NULL) ?
675 			0 : 1;
676 
677 		if (of_get_property(np, "no-busif", NULL))
678 			ssi_info->flags |= RSND_SSI_NO_BUSIF;
679 	}
680 
681 rsnd_of_parse_ssi_end:
682 	of_node_put(node);
683 }
684 
685 int rsnd_ssi_probe(struct platform_device *pdev,
686 		   const struct rsnd_of_data *of_data,
687 		   struct rsnd_priv *priv)
688 {
689 	struct rcar_snd_info *info = rsnd_priv_to_info(priv);
690 	struct rsnd_ssi_platform_info *pinfo;
691 	struct device *dev = rsnd_priv_to_dev(priv);
692 	struct rsnd_mod_ops *ops;
693 	struct clk *clk;
694 	struct rsnd_ssi *ssi;
695 	char name[RSND_SSI_NAME_SIZE];
696 	int i, nr, ret;
697 
698 	rsnd_of_parse_ssi(pdev, of_data, priv);
699 
700 	/*
701 	 *	init SSI
702 	 */
703 	nr	= info->ssi_info_nr;
704 	ssi	= devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
705 	if (!ssi) {
706 		dev_err(dev, "SSI allocate failed\n");
707 		return -ENOMEM;
708 	}
709 
710 	priv->ssi	= ssi;
711 	priv->ssi_nr	= nr;
712 
713 	for_each_rsnd_ssi(ssi, priv, i) {
714 		pinfo = &info->ssi_info[i];
715 
716 		snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
717 			 SSI_NAME, i);
718 
719 		clk = devm_clk_get(dev, name);
720 		if (IS_ERR(clk))
721 			return PTR_ERR(clk);
722 
723 		ssi->info	= pinfo;
724 
725 		ops = &rsnd_ssi_non_ops;
726 		if (pinfo->dma_id > 0)
727 			ops = &rsnd_ssi_dma_ops;
728 		else if (rsnd_ssi_pio_available(ssi))
729 			ops = &rsnd_ssi_pio_ops;
730 
731 		ret = rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i);
732 		if (ret)
733 			return ret;
734 
735 		rsnd_ssi_parent_clk_setup(priv, ssi);
736 	}
737 
738 	return 0;
739 }
740 
741 void rsnd_ssi_remove(struct platform_device *pdev,
742 		     struct rsnd_priv *priv)
743 {
744 	struct rsnd_ssi *ssi;
745 	int i;
746 
747 	for_each_rsnd_ssi(ssi, priv, i) {
748 		rsnd_mod_quit(&ssi->mod);
749 	}
750 }
751