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