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