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