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_dma_available(ssi) \ 84 rsnd_dma_available(rsnd_mod_to_dma(&(ssi)->mod)) 85 #define rsnd_ssi_clk_from_parent(ssi) ((ssi)->parent) 86 #define rsnd_ssi_mode_flags(p) ((p)->info->flags) 87 #define rsnd_ssi_dai_id(ssi) ((ssi)->info->dai_id) 88 89 static 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 rsnd_ssi_stop(mod, priv); 420 rsnd_ssi_start(mod, priv); 421 422 dev_dbg(dev, "%s[%d] restart\n", 423 rsnd_mod_name(mod), rsnd_mod_id(mod)); 424 } 425 426 rsnd_ssi_record_error(ssi, status); 427 428 return IRQ_HANDLED; 429 } 430 431 /* 432 * SSI PIO 433 */ 434 static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, 435 struct rsnd_priv *priv) 436 { 437 struct device *dev = rsnd_priv_to_dev(priv); 438 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 439 int ret; 440 441 ret = devm_request_irq(dev, ssi->info->irq, 442 rsnd_ssi_interrupt, 443 IRQF_SHARED, 444 dev_name(dev), ssi); 445 if (ret) 446 dev_err(dev, "%s[%d] (PIO) request interrupt failed\n", 447 rsnd_mod_name(mod), rsnd_mod_id(mod)); 448 else 449 dev_dbg(dev, "%s[%d] (PIO) is probed\n", 450 rsnd_mod_name(mod), rsnd_mod_id(mod)); 451 452 return ret; 453 } 454 455 static struct rsnd_mod_ops rsnd_ssi_pio_ops = { 456 .name = SSI_NAME, 457 .probe = rsnd_ssi_pio_probe, 458 .init = rsnd_ssi_init, 459 .quit = rsnd_ssi_quit, 460 .start = rsnd_ssi_start, 461 .stop = rsnd_ssi_stop, 462 }; 463 464 static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, 465 struct rsnd_priv *priv) 466 { 467 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 468 struct device *dev = rsnd_priv_to_dev(priv); 469 int dma_id = ssi->info->dma_id; 470 int ret; 471 472 ret = devm_request_irq(dev, ssi->info->irq, 473 rsnd_ssi_interrupt, 474 IRQF_SHARED, 475 dev_name(dev), ssi); 476 if (ret) 477 goto rsnd_ssi_dma_probe_fail; 478 479 ret = rsnd_dma_init( 480 priv, rsnd_mod_to_dma(mod), 481 rsnd_info_is_playback(priv, ssi), 482 dma_id); 483 if (ret) 484 goto rsnd_ssi_dma_probe_fail; 485 486 dev_dbg(dev, "%s[%d] (DMA) is probed\n", 487 rsnd_mod_name(mod), rsnd_mod_id(mod)); 488 489 return ret; 490 491 rsnd_ssi_dma_probe_fail: 492 dev_err(dev, "%s[%d] (DMA) is failed\n", 493 rsnd_mod_name(mod), rsnd_mod_id(mod)); 494 495 return ret; 496 } 497 498 static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, 499 struct rsnd_priv *priv) 500 { 501 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 502 struct device *dev = rsnd_priv_to_dev(priv); 503 int irq = ssi->info->irq; 504 505 rsnd_dma_quit(priv, rsnd_mod_to_dma(mod)); 506 507 /* PIO will request IRQ again */ 508 devm_free_irq(dev, irq, ssi); 509 510 return 0; 511 } 512 513 static int rsnd_ssi_fallback(struct rsnd_mod *mod, 514 struct rsnd_priv *priv) 515 { 516 struct device *dev = rsnd_priv_to_dev(priv); 517 518 /* 519 * fallback to PIO 520 * 521 * SSI .probe might be called again. 522 * see 523 * rsnd_rdai_continuance_probe() 524 */ 525 mod->ops = &rsnd_ssi_pio_ops; 526 527 dev_info(dev, "%s[%d] fallback to PIO mode\n", 528 rsnd_mod_name(mod), rsnd_mod_id(mod)); 529 530 return 0; 531 } 532 533 static int rsnd_ssi_dma_start(struct rsnd_mod *mod, 534 struct rsnd_priv *priv) 535 { 536 struct rsnd_dma *dma = rsnd_mod_to_dma(mod); 537 538 rsnd_dma_start(dma); 539 540 rsnd_ssi_start(mod, priv); 541 542 return 0; 543 } 544 545 static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, 546 struct rsnd_priv *priv) 547 { 548 struct rsnd_dma *dma = rsnd_mod_to_dma(mod); 549 550 rsnd_ssi_stop(mod, priv); 551 552 rsnd_dma_stop(dma); 553 554 return 0; 555 } 556 557 static char *rsnd_ssi_dma_name(struct rsnd_mod *mod) 558 { 559 return rsnd_ssi_use_busif(mod) ? "ssiu" : SSI_NAME; 560 } 561 562 static struct rsnd_mod_ops rsnd_ssi_dma_ops = { 563 .name = SSI_NAME, 564 .dma_name = rsnd_ssi_dma_name, 565 .probe = rsnd_ssi_dma_probe, 566 .remove = rsnd_ssi_dma_remove, 567 .init = rsnd_ssi_init, 568 .quit = rsnd_ssi_quit, 569 .start = rsnd_ssi_dma_start, 570 .stop = rsnd_ssi_dma_stop, 571 .fallback = rsnd_ssi_fallback, 572 }; 573 574 int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod) 575 { 576 return mod->ops == &rsnd_ssi_dma_ops; 577 } 578 579 580 /* 581 * Non SSI 582 */ 583 static struct rsnd_mod_ops rsnd_ssi_non_ops = { 584 .name = SSI_NAME, 585 }; 586 587 /* 588 * ssi mod function 589 */ 590 struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id) 591 { 592 if (WARN_ON(id < 0 || id >= rsnd_ssi_nr(priv))) 593 id = 0; 594 595 return &((struct rsnd_ssi *)(priv->ssi) + id)->mod; 596 } 597 598 int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod) 599 { 600 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 601 602 return !!(rsnd_ssi_mode_flags(ssi) & RSND_SSI_CLK_PIN_SHARE); 603 } 604 605 static void rsnd_ssi_parent_clk_setup(struct rsnd_priv *priv, struct rsnd_ssi *ssi) 606 { 607 if (!rsnd_ssi_is_pin_sharing(&ssi->mod)) 608 return; 609 610 switch (rsnd_mod_id(&ssi->mod)) { 611 case 1: 612 case 2: 613 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 0)); 614 break; 615 case 4: 616 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 3)); 617 break; 618 case 8: 619 ssi->parent = rsnd_mod_to_ssi(rsnd_ssi_mod_get(priv, 7)); 620 break; 621 } 622 } 623 624 625 static void rsnd_of_parse_ssi(struct platform_device *pdev, 626 const struct rsnd_of_data *of_data, 627 struct rsnd_priv *priv) 628 { 629 struct device_node *node; 630 struct device_node *np; 631 struct rsnd_ssi_platform_info *ssi_info; 632 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 633 struct device *dev = &pdev->dev; 634 int nr, i; 635 636 if (!of_data) 637 return; 638 639 node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi"); 640 if (!node) 641 return; 642 643 nr = of_get_child_count(node); 644 if (!nr) 645 goto rsnd_of_parse_ssi_end; 646 647 ssi_info = devm_kzalloc(dev, 648 sizeof(struct rsnd_ssi_platform_info) * nr, 649 GFP_KERNEL); 650 if (!ssi_info) { 651 dev_err(dev, "ssi info allocation error\n"); 652 goto rsnd_of_parse_ssi_end; 653 } 654 655 info->ssi_info = ssi_info; 656 info->ssi_info_nr = nr; 657 658 i = -1; 659 for_each_child_of_node(node, np) { 660 i++; 661 662 ssi_info = info->ssi_info + i; 663 664 /* 665 * pin settings 666 */ 667 if (of_get_property(np, "shared-pin", NULL)) 668 ssi_info->flags |= RSND_SSI_CLK_PIN_SHARE; 669 670 /* 671 * irq 672 */ 673 ssi_info->irq = irq_of_parse_and_map(np, 0); 674 675 /* 676 * DMA 677 */ 678 ssi_info->dma_id = of_get_property(np, "pio-transfer", NULL) ? 679 0 : 1; 680 681 if (of_get_property(np, "no-busif", NULL)) 682 ssi_info->flags |= RSND_SSI_NO_BUSIF; 683 } 684 685 rsnd_of_parse_ssi_end: 686 of_node_put(node); 687 } 688 689 int rsnd_ssi_probe(struct platform_device *pdev, 690 const struct rsnd_of_data *of_data, 691 struct rsnd_priv *priv) 692 { 693 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 694 struct rsnd_ssi_platform_info *pinfo; 695 struct device *dev = rsnd_priv_to_dev(priv); 696 struct rsnd_mod_ops *ops; 697 struct clk *clk; 698 struct rsnd_ssi *ssi; 699 char name[RSND_SSI_NAME_SIZE]; 700 int i, nr; 701 702 rsnd_of_parse_ssi(pdev, of_data, priv); 703 704 /* 705 * init SSI 706 */ 707 nr = info->ssi_info_nr; 708 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL); 709 if (!ssi) { 710 dev_err(dev, "SSI allocate failed\n"); 711 return -ENOMEM; 712 } 713 714 priv->ssi = ssi; 715 priv->ssi_nr = nr; 716 717 for_each_rsnd_ssi(ssi, priv, i) { 718 pinfo = &info->ssi_info[i]; 719 720 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d", 721 SSI_NAME, i); 722 723 clk = devm_clk_get(dev, name); 724 if (IS_ERR(clk)) 725 return PTR_ERR(clk); 726 727 ssi->info = pinfo; 728 729 ops = &rsnd_ssi_non_ops; 730 if (pinfo->dma_id > 0) 731 ops = &rsnd_ssi_dma_ops; 732 else if (rsnd_ssi_pio_available(ssi)) 733 ops = &rsnd_ssi_pio_ops; 734 735 rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i); 736 737 rsnd_ssi_parent_clk_setup(priv, ssi); 738 } 739 740 return 0; 741 } 742