1 /* 2 * Renesas R-Car SRC support 3 * 4 * Copyright (C) 2013 Renesas Solutions Corp. 5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 #include "rsnd.h" 12 13 #define SRC_NAME "src" 14 15 /* SRCx_STATUS */ 16 #define OUF_SRCO ((1 << 12) | (1 << 13)) 17 #define OUF_SRCI ((1 << 9) | (1 << 8)) 18 19 /* SCU_SYSTEM_STATUS0/1 */ 20 #define OUF_SRC(id) ((1 << (id + 16)) | (1 << id)) 21 22 struct rsnd_src { 23 struct rsnd_src_platform_info *info; /* rcar_snd.h */ 24 struct rsnd_mod mod; 25 struct rsnd_mod *dma; 26 struct rsnd_kctrl_cfg_s sen; /* sync convert enable */ 27 struct rsnd_kctrl_cfg_s sync; /* sync convert */ 28 u32 convert_rate; /* sampling rate convert */ 29 int err; 30 }; 31 32 #define RSND_SRC_NAME_SIZE 16 33 34 #define rsnd_src_to_dma(src) ((src)->dma) 35 #define rsnd_src_nr(priv) ((priv)->src_nr) 36 #define rsnd_enable_sync_convert(src) ((src)->sen.val) 37 #define rsnd_src_of_node(priv) \ 38 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") 39 40 #define rsnd_mod_to_src(_mod) \ 41 container_of((_mod), struct rsnd_src, mod) 42 43 #define for_each_rsnd_src(pos, priv, i) \ 44 for ((i) = 0; \ 45 ((i) < rsnd_src_nr(priv)) && \ 46 ((pos) = (struct rsnd_src *)(priv)->src + i); \ 47 i++) 48 49 50 /* 51 * image of SRC (Sampling Rate Converter) 52 * 53 * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+ 54 * 48kHz <-> | SRC | <------> | SSI | <-----> | codec | 55 * 44.1kHz <-> +-----+ +-----+ +-------+ 56 * ... 57 * 58 */ 59 60 /* 61 * src.c is caring... 62 * 63 * Gen1 64 * 65 * [mem] -> [SRU] -> [SSI] 66 * |--------| 67 * 68 * Gen2 69 * 70 * [mem] -> [SRC] -> [SSIU] -> [SSI] 71 * |-----------------| 72 */ 73 74 /* 75 * How to use SRC bypass mode for debugging 76 * 77 * SRC has bypass mode, and it is useful for debugging. 78 * In Gen2 case, 79 * SRCm_MODE controls whether SRC is used or not 80 * SSI_MODE0 controls whether SSIU which receives SRC data 81 * is used or not. 82 * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC, 83 * but SRC bypass mode needs SSI_MODE0 only. 84 * 85 * This driver request 86 * struct rsnd_src_platform_info { 87 * u32 convert_rate; 88 * int dma_id; 89 * } 90 * 91 * rsnd_src_convert_rate() indicates 92 * above convert_rate, and it controls 93 * whether SRC is used or not. 94 * 95 * ex) doesn't use SRC 96 * static struct rsnd_dai_platform_info rsnd_dai = { 97 * .playback = { .ssi = &rsnd_ssi[0], }, 98 * }; 99 * 100 * ex) uses SRC 101 * static struct rsnd_src_platform_info rsnd_src[] = { 102 * RSND_SCU(48000, 0), 103 * ... 104 * }; 105 * static struct rsnd_dai_platform_info rsnd_dai = { 106 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, 107 * }; 108 * 109 * ex) uses SRC bypass mode 110 * static struct rsnd_src_platform_info rsnd_src[] = { 111 * RSND_SCU(0, 0), 112 * ... 113 * }; 114 * static struct rsnd_dai_platform_info rsnd_dai = { 115 * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] }, 116 * }; 117 * 118 */ 119 120 /* 121 * Gen1/Gen2 common functions 122 */ 123 static void rsnd_src_soft_reset(struct rsnd_mod *mod) 124 { 125 rsnd_mod_write(mod, SRC_SWRSR, 0); 126 rsnd_mod_write(mod, SRC_SWRSR, 1); 127 } 128 129 130 #define rsnd_src_initialize_lock(mod) __rsnd_src_initialize_lock(mod, 1) 131 #define rsnd_src_initialize_unlock(mod) __rsnd_src_initialize_lock(mod, 0) 132 static void __rsnd_src_initialize_lock(struct rsnd_mod *mod, u32 enable) 133 { 134 rsnd_mod_write(mod, SRC_SRCIR, enable); 135 } 136 137 static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, 138 struct rsnd_mod *mod) 139 { 140 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 141 int is_play = rsnd_io_is_play(io); 142 143 return rsnd_dma_request_channel(rsnd_src_of_node(priv), 144 mod, 145 is_play ? "rx" : "tx"); 146 } 147 148 static u32 rsnd_src_convert_rate(struct rsnd_dai_stream *io, 149 struct rsnd_src *src) 150 { 151 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 152 u32 convert_rate; 153 154 if (!runtime) 155 return 0; 156 157 if (!rsnd_enable_sync_convert(src)) 158 return src->convert_rate; 159 160 convert_rate = src->sync.val; 161 162 if (!convert_rate) 163 convert_rate = src->convert_rate; 164 165 if (!convert_rate) 166 convert_rate = runtime->rate; 167 168 return convert_rate; 169 } 170 171 unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv, 172 struct rsnd_dai_stream *io, 173 struct snd_pcm_runtime *runtime) 174 { 175 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); 176 struct rsnd_src *src; 177 unsigned int rate = 0; 178 179 if (src_mod) { 180 src = rsnd_mod_to_src(src_mod); 181 182 /* 183 * return convert rate if SRC is used, 184 * otherwise, return runtime->rate as usual 185 */ 186 rate = rsnd_src_convert_rate(io, src); 187 } 188 189 if (!rate) 190 rate = runtime->rate; 191 192 return rate; 193 } 194 195 static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, 196 struct rsnd_dai_stream *io) 197 { 198 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 199 struct rsnd_src *src = rsnd_mod_to_src(mod); 200 u32 convert_rate = rsnd_src_convert_rate(io, src); 201 u32 fsrate = 0; 202 203 if (convert_rate) 204 fsrate = 0x0400000 / convert_rate * runtime->rate; 205 206 /* Set channel number and output bit length */ 207 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr_bit(mod, io)); 208 209 /* Enable the initial value of IFS */ 210 if (fsrate) { 211 rsnd_mod_write(mod, SRC_IFSCR, 1); 212 213 /* Set initial value of IFS */ 214 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 215 } 216 217 /* use DMA transfer */ 218 rsnd_mod_write(mod, SRC_BUSIF_MODE, 1); 219 220 return 0; 221 } 222 223 static int rsnd_src_hw_params(struct rsnd_mod *mod, 224 struct rsnd_dai_stream *io, 225 struct snd_pcm_substream *substream, 226 struct snd_pcm_hw_params *fe_params) 227 { 228 struct rsnd_src *src = rsnd_mod_to_src(mod); 229 struct snd_soc_pcm_runtime *fe = substream->private_data; 230 231 /* default value (mainly for non-DT) */ 232 src->convert_rate = src->info->convert_rate; 233 234 /* 235 * SRC assumes that it is used under DPCM if user want to use 236 * sampling rate convert. Then, SRC should be FE. 237 * And then, this function will be called *after* BE settings. 238 * this means, each BE already has fixuped hw_params. 239 * see 240 * dpcm_fe_dai_hw_params() 241 * dpcm_be_dai_hw_params() 242 */ 243 if (fe->dai_link->dynamic) { 244 int stream = substream->stream; 245 struct snd_soc_dpcm *dpcm; 246 struct snd_pcm_hw_params *be_params; 247 248 list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { 249 be_params = &dpcm->hw_params; 250 251 if (params_rate(fe_params) != params_rate(be_params)) 252 src->convert_rate = params_rate(be_params); 253 } 254 } 255 256 return 0; 257 } 258 259 static int rsnd_src_init(struct rsnd_mod *mod, 260 struct rsnd_priv *priv) 261 { 262 struct rsnd_src *src = rsnd_mod_to_src(mod); 263 264 rsnd_mod_power_on(mod); 265 266 rsnd_src_soft_reset(mod); 267 268 rsnd_src_initialize_lock(mod); 269 270 src->err = 0; 271 272 /* reset sync convert_rate */ 273 src->sync.val = 0; 274 275 return 0; 276 } 277 278 static int rsnd_src_quit(struct rsnd_mod *mod, 279 struct rsnd_dai_stream *io, 280 struct rsnd_priv *priv) 281 { 282 struct rsnd_src *src = rsnd_mod_to_src(mod); 283 struct device *dev = rsnd_priv_to_dev(priv); 284 285 rsnd_mod_power_off(mod); 286 287 if (src->err) 288 dev_warn(dev, "%s[%d] under/over flow err = %d\n", 289 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err); 290 291 src->convert_rate = 0; 292 293 /* reset sync convert_rate */ 294 src->sync.val = 0; 295 296 return 0; 297 } 298 299 static int rsnd_src_start(struct rsnd_mod *mod) 300 { 301 rsnd_src_initialize_unlock(mod); 302 303 return 0; 304 } 305 306 static int rsnd_src_stop(struct rsnd_mod *mod) 307 { 308 /* nothing to do */ 309 return 0; 310 } 311 312 /* 313 * Gen2 functions 314 */ 315 #define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1) 316 #define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0) 317 static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable) 318 { 319 struct rsnd_src *src = rsnd_mod_to_src(mod); 320 u32 sys_int_val, int_val, sys_int_mask; 321 int irq = src->info->irq; 322 int id = rsnd_mod_id(mod); 323 324 sys_int_val = 325 sys_int_mask = OUF_SRC(id); 326 int_val = 0x3300; 327 328 /* 329 * IRQ is not supported on non-DT 330 * see 331 * rsnd_src_probe_gen2() 332 */ 333 if ((irq <= 0) || !enable) { 334 sys_int_val = 0; 335 int_val = 0; 336 } 337 338 /* 339 * WORKAROUND 340 * 341 * ignore over flow error when rsnd_enable_sync_convert() 342 */ 343 if (rsnd_enable_sync_convert(src)) 344 sys_int_val = sys_int_val & 0xffff; 345 346 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); 347 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); 348 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); 349 } 350 351 static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod) 352 { 353 u32 val = OUF_SRC(rsnd_mod_id(mod)); 354 355 rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val); 356 rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val); 357 } 358 359 static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod) 360 { 361 struct rsnd_src *src = rsnd_mod_to_src(mod); 362 u32 val0, val1; 363 bool ret = false; 364 365 val0 = val1 = OUF_SRC(rsnd_mod_id(mod)); 366 367 /* 368 * WORKAROUND 369 * 370 * ignore over flow error when rsnd_enable_sync_convert() 371 */ 372 if (rsnd_enable_sync_convert(src)) 373 val0 = val0 & 0xffff; 374 375 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) || 376 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) { 377 struct rsnd_src *src = rsnd_mod_to_src(mod); 378 379 src->err++; 380 ret = true; 381 } 382 383 /* clear error static */ 384 rsnd_src_error_clear_gen2(mod); 385 386 return ret; 387 } 388 389 static int rsnd_src_start_gen2(struct rsnd_mod *mod, 390 struct rsnd_dai_stream *io, 391 struct rsnd_priv *priv) 392 { 393 struct rsnd_src *src = rsnd_mod_to_src(mod); 394 u32 val; 395 396 val = rsnd_get_dalign(mod, io); 397 398 rsnd_mod_write(mod, SRC_BUSIF_DALIGN, val); 399 400 /* 401 * WORKAROUND 402 * 403 * Enable SRC output if you want to use sync convert together with DVC 404 */ 405 val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ? 406 0x01 : 0x11; 407 408 rsnd_mod_write(mod, SRC_CTRL, val); 409 410 rsnd_src_error_clear_gen2(mod); 411 412 rsnd_src_start(mod); 413 414 rsnd_src_irq_enable_gen2(mod); 415 416 return 0; 417 } 418 419 static int rsnd_src_stop_gen2(struct rsnd_mod *mod, 420 struct rsnd_dai_stream *io, 421 struct rsnd_priv *priv) 422 { 423 rsnd_src_irq_disable_gen2(mod); 424 425 /* 426 * stop SRC output only 427 * see rsnd_src_quit_gen2 428 */ 429 rsnd_mod_write(mod, SRC_CTRL, 0x01); 430 431 rsnd_src_error_record_gen2(mod); 432 433 return rsnd_src_stop(mod); 434 } 435 436 static int rsnd_src_quit_gen2(struct rsnd_mod *mod, 437 struct rsnd_dai_stream *io, 438 struct rsnd_priv *priv) 439 { 440 /* stop both out/in */ 441 rsnd_mod_write(mod, SRC_CTRL, 0); 442 443 return rsnd_src_quit(mod, io, priv); 444 } 445 446 static void __rsnd_src_interrupt_gen2(struct rsnd_mod *mod, 447 struct rsnd_dai_stream *io) 448 { 449 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 450 struct rsnd_src *src = rsnd_mod_to_src(mod); 451 struct device *dev = rsnd_priv_to_dev(priv); 452 453 spin_lock(&priv->lock); 454 455 /* ignore all cases if not working */ 456 if (!rsnd_io_is_working(io)) 457 goto rsnd_src_interrupt_gen2_out; 458 459 if (rsnd_src_error_record_gen2(mod)) { 460 461 dev_dbg(dev, "%s[%d] restart\n", 462 rsnd_mod_name(mod), rsnd_mod_id(mod)); 463 464 rsnd_src_stop_gen2(mod, io, priv); 465 rsnd_src_start_gen2(mod, io, priv); 466 } 467 468 if (src->err > 1024) { 469 rsnd_src_irq_disable_gen2(mod); 470 471 dev_warn(dev, "no more %s[%d] restart\n", 472 rsnd_mod_name(mod), rsnd_mod_id(mod)); 473 } 474 475 rsnd_src_interrupt_gen2_out: 476 spin_unlock(&priv->lock); 477 } 478 479 static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data) 480 { 481 struct rsnd_mod *mod = data; 482 483 rsnd_mod_interrupt(mod, __rsnd_src_interrupt_gen2); 484 485 return IRQ_HANDLED; 486 } 487 488 static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, 489 struct rsnd_dai_stream *io) 490 { 491 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 492 struct device *dev = rsnd_priv_to_dev(priv); 493 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 494 struct rsnd_src *src = rsnd_mod_to_src(mod); 495 u32 convert_rate = rsnd_src_convert_rate(io, src); 496 u32 cr, route; 497 uint ratio; 498 int ret; 499 500 /* 6 - 1/6 are very enough ratio for SRC_BSDSR */ 501 if (!convert_rate) 502 ratio = 0; 503 else if (convert_rate > runtime->rate) 504 ratio = 100 * convert_rate / runtime->rate; 505 else 506 ratio = 100 * runtime->rate / convert_rate; 507 508 if (ratio > 600) { 509 dev_err(dev, "FSO/FSI ratio error\n"); 510 return -EINVAL; 511 } 512 513 ret = rsnd_src_set_convert_rate(mod, io); 514 if (ret < 0) 515 return ret; 516 517 cr = 0x00011110; 518 route = 0x0; 519 if (convert_rate) { 520 route = 0x1; 521 522 if (rsnd_enable_sync_convert(src)) { 523 cr |= 0x1; 524 route |= rsnd_io_is_play(io) ? 525 (0x1 << 24) : (0x1 << 25); 526 } 527 } 528 529 rsnd_mod_write(mod, SRC_SRCCR, cr); 530 rsnd_mod_write(mod, SRC_ROUTE_MODE0, route); 531 532 switch (rsnd_mod_id(mod)) { 533 case 5: 534 case 6: 535 case 7: 536 case 8: 537 rsnd_mod_write(mod, SRC_BSDSR, 0x02400000); 538 break; 539 default: 540 rsnd_mod_write(mod, SRC_BSDSR, 0x01800000); 541 break; 542 } 543 544 rsnd_mod_write(mod, SRC_BSISR, 0x00100060); 545 546 return 0; 547 } 548 549 static int rsnd_src_set_convert_timing_gen2(struct rsnd_dai_stream *io, 550 struct rsnd_mod *mod) 551 { 552 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 553 struct rsnd_src *src = rsnd_mod_to_src(mod); 554 u32 convert_rate = rsnd_src_convert_rate(io, src); 555 int ret; 556 557 if (convert_rate) 558 ret = rsnd_adg_set_convert_clk_gen2(mod, io, 559 runtime->rate, 560 convert_rate); 561 else 562 ret = rsnd_adg_set_convert_timing_gen2(mod, io); 563 564 return ret; 565 } 566 567 static int rsnd_src_probe_gen2(struct rsnd_mod *mod, 568 struct rsnd_dai_stream *io, 569 struct rsnd_priv *priv) 570 { 571 struct rsnd_src *src = rsnd_mod_to_src(mod); 572 struct device *dev = rsnd_priv_to_dev(priv); 573 int irq = src->info->irq; 574 int ret; 575 576 if (irq > 0) { 577 /* 578 * IRQ is not supported on non-DT 579 * see 580 * rsnd_src_irq_enable_gen2() 581 */ 582 ret = devm_request_irq(dev, irq, 583 rsnd_src_interrupt_gen2, 584 IRQF_SHARED, 585 dev_name(dev), mod); 586 if (ret) 587 return ret; 588 } 589 590 src->dma = rsnd_dma_attach(io, mod, src->info->dma_id); 591 if (IS_ERR(src->dma)) 592 return PTR_ERR(src->dma); 593 594 return ret; 595 } 596 597 static int rsnd_src_init_gen2(struct rsnd_mod *mod, 598 struct rsnd_dai_stream *io, 599 struct rsnd_priv *priv) 600 { 601 int ret; 602 603 ret = rsnd_src_init(mod, priv); 604 if (ret < 0) 605 return ret; 606 607 ret = rsnd_src_set_convert_rate_gen2(mod, io); 608 if (ret < 0) 609 return ret; 610 611 ret = rsnd_src_set_convert_timing_gen2(io, mod); 612 if (ret < 0) 613 return ret; 614 615 return 0; 616 } 617 618 static void rsnd_src_reconvert_update(struct rsnd_dai_stream *io, 619 struct rsnd_mod *mod) 620 { 621 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 622 struct rsnd_src *src = rsnd_mod_to_src(mod); 623 u32 convert_rate = rsnd_src_convert_rate(io, src); 624 u32 fsrate; 625 626 if (!runtime) 627 return; 628 629 if (!convert_rate) 630 convert_rate = runtime->rate; 631 632 fsrate = 0x0400000 / convert_rate * runtime->rate; 633 634 /* update IFS */ 635 rsnd_mod_write(mod, SRC_IFSVR, fsrate); 636 } 637 638 static int rsnd_src_pcm_new_gen2(struct rsnd_mod *mod, 639 struct rsnd_dai_stream *io, 640 struct snd_soc_pcm_runtime *rtd) 641 { 642 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 643 struct rsnd_src *src = rsnd_mod_to_src(mod); 644 int ret; 645 646 /* 647 * enable SRC sync convert if possible 648 */ 649 650 /* 651 * SRC sync convert needs clock master 652 */ 653 if (!rsnd_rdai_is_clk_master(rdai)) 654 return 0; 655 656 /* 657 * enable sync convert 658 */ 659 ret = rsnd_kctrl_new_s(mod, io, rtd, 660 rsnd_io_is_play(io) ? 661 "SRC Out Rate Switch" : 662 "SRC In Rate Switch", 663 rsnd_src_reconvert_update, 664 &src->sen, 1); 665 if (ret < 0) 666 return ret; 667 668 ret = rsnd_kctrl_new_s(mod, io, rtd, 669 rsnd_io_is_play(io) ? 670 "SRC Out Rate" : 671 "SRC In Rate", 672 rsnd_src_reconvert_update, 673 &src->sync, 192000); 674 675 return ret; 676 } 677 678 static struct rsnd_mod_ops rsnd_src_gen2_ops = { 679 .name = SRC_NAME, 680 .dma_req = rsnd_src_dma_req, 681 .probe = rsnd_src_probe_gen2, 682 .init = rsnd_src_init_gen2, 683 .quit = rsnd_src_quit_gen2, 684 .start = rsnd_src_start_gen2, 685 .stop = rsnd_src_stop_gen2, 686 .hw_params = rsnd_src_hw_params, 687 .pcm_new = rsnd_src_pcm_new_gen2, 688 }; 689 690 struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id) 691 { 692 if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv))) 693 id = 0; 694 695 return rsnd_mod_get((struct rsnd_src *)(priv->src) + id); 696 } 697 698 static void rsnd_of_parse_src(struct platform_device *pdev, 699 const struct rsnd_of_data *of_data, 700 struct rsnd_priv *priv) 701 { 702 struct device_node *src_node; 703 struct device_node *np; 704 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 705 struct rsnd_src_platform_info *src_info; 706 struct device *dev = &pdev->dev; 707 int nr, i; 708 709 if (!of_data) 710 return; 711 712 src_node = rsnd_src_of_node(priv); 713 if (!src_node) 714 return; 715 716 nr = of_get_child_count(src_node); 717 if (!nr) 718 goto rsnd_of_parse_src_end; 719 720 src_info = devm_kzalloc(dev, 721 sizeof(struct rsnd_src_platform_info) * nr, 722 GFP_KERNEL); 723 if (!src_info) { 724 dev_err(dev, "src info allocation error\n"); 725 goto rsnd_of_parse_src_end; 726 } 727 728 info->src_info = src_info; 729 info->src_info_nr = nr; 730 731 i = 0; 732 for_each_child_of_node(src_node, np) { 733 src_info[i].irq = irq_of_parse_and_map(np, 0); 734 735 i++; 736 } 737 738 rsnd_of_parse_src_end: 739 of_node_put(src_node); 740 } 741 742 int rsnd_src_probe(struct platform_device *pdev, 743 const struct rsnd_of_data *of_data, 744 struct rsnd_priv *priv) 745 { 746 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 747 struct device *dev = rsnd_priv_to_dev(priv); 748 struct rsnd_src *src; 749 struct clk *clk; 750 char name[RSND_SRC_NAME_SIZE]; 751 int i, nr, ret; 752 753 /* This driver doesn't support Gen1 at this point */ 754 if (rsnd_is_gen1(priv)) 755 return 0; 756 757 rsnd_of_parse_src(pdev, of_data, priv); 758 759 /* 760 * init SRC 761 */ 762 nr = info->src_info_nr; 763 if (!nr) 764 return 0; 765 766 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); 767 if (!src) 768 return -ENOMEM; 769 770 priv->src_nr = nr; 771 priv->src = src; 772 773 for_each_rsnd_src(src, priv, i) { 774 snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d", 775 SRC_NAME, i); 776 777 clk = devm_clk_get(dev, name); 778 if (IS_ERR(clk)) 779 return PTR_ERR(clk); 780 781 src->info = &info->src_info[i]; 782 783 ret = rsnd_mod_init(priv, rsnd_mod_get(src), 784 &rsnd_src_gen2_ops, clk, RSND_MOD_SRC, i); 785 if (ret) 786 return ret; 787 } 788 789 return 0; 790 } 791 792 void rsnd_src_remove(struct platform_device *pdev, 793 struct rsnd_priv *priv) 794 { 795 struct rsnd_src *src; 796 int i; 797 798 for_each_rsnd_src(src, priv, i) { 799 rsnd_mod_quit(rsnd_mod_get(src)); 800 } 801 } 802