1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Support for Digigram Lola PCI-e boards 4 * 5 * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de> 6 */ 7 8 #include <linux/kernel.h> 9 #include <linux/init.h> 10 #include <linux/dma-mapping.h> 11 #include <linux/pci.h> 12 #include <linux/delay.h> 13 #include <sound/core.h> 14 #include <sound/pcm.h> 15 #include "lola.h" 16 17 #define LOLA_MAX_BDL_ENTRIES 8 18 #define LOLA_MAX_BUF_SIZE (1024*1024*1024) 19 #define LOLA_BDL_ENTRY_SIZE (16 * 16) 20 21 static struct lola_pcm *lola_get_pcm(struct snd_pcm_substream *substream) 22 { 23 struct lola *chip = snd_pcm_substream_chip(substream); 24 return &chip->pcm[substream->stream]; 25 } 26 27 static struct lola_stream *lola_get_stream(struct snd_pcm_substream *substream) 28 { 29 struct lola_pcm *pcm = lola_get_pcm(substream); 30 unsigned int idx = substream->number; 31 return &pcm->streams[idx]; 32 } 33 34 static unsigned int lola_get_lrc(struct lola *chip) 35 { 36 return lola_readl(chip, BAR1, LRC); 37 } 38 39 static unsigned int lola_get_tstamp(struct lola *chip, bool quick_no_sync) 40 { 41 unsigned int tstamp = lola_get_lrc(chip) >> 8; 42 if (chip->granularity) { 43 unsigned int wait_banks = quick_no_sync ? 0 : 8; 44 tstamp += (wait_banks + 1) * chip->granularity - 1; 45 tstamp -= tstamp % chip->granularity; 46 } 47 return tstamp << 8; 48 } 49 50 /* clear any pending interrupt status */ 51 static void lola_stream_clear_pending_irq(struct lola *chip, 52 struct lola_stream *str) 53 { 54 unsigned int val = lola_dsd_read(chip, str->dsd, STS); 55 val &= LOLA_DSD_STS_DESE | LOLA_DSD_STS_BCIS; 56 if (val) 57 lola_dsd_write(chip, str->dsd, STS, val); 58 } 59 60 static void lola_stream_start(struct lola *chip, struct lola_stream *str, 61 unsigned int tstamp) 62 { 63 lola_stream_clear_pending_irq(chip, str); 64 lola_dsd_write(chip, str->dsd, CTL, 65 LOLA_DSD_CTL_SRUN | 66 LOLA_DSD_CTL_IOCE | 67 LOLA_DSD_CTL_DEIE | 68 LOLA_DSD_CTL_VLRCV | 69 tstamp); 70 } 71 72 static void lola_stream_stop(struct lola *chip, struct lola_stream *str, 73 unsigned int tstamp) 74 { 75 lola_dsd_write(chip, str->dsd, CTL, 76 LOLA_DSD_CTL_IOCE | 77 LOLA_DSD_CTL_DEIE | 78 LOLA_DSD_CTL_VLRCV | 79 tstamp); 80 lola_stream_clear_pending_irq(chip, str); 81 } 82 83 static void wait_for_srst_clear(struct lola *chip, struct lola_stream *str) 84 { 85 unsigned long end_time = jiffies + msecs_to_jiffies(200); 86 while (time_before(jiffies, end_time)) { 87 unsigned int val; 88 val = lola_dsd_read(chip, str->dsd, CTL); 89 if (!(val & LOLA_DSD_CTL_SRST)) 90 return; 91 msleep(1); 92 } 93 dev_warn(chip->card->dev, "SRST not clear (stream %d)\n", str->dsd); 94 } 95 96 static int lola_stream_wait_for_fifo(struct lola *chip, 97 struct lola_stream *str, 98 bool ready) 99 { 100 unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0; 101 unsigned long end_time = jiffies + msecs_to_jiffies(200); 102 while (time_before(jiffies, end_time)) { 103 unsigned int reg = lola_dsd_read(chip, str->dsd, STS); 104 if ((reg & LOLA_DSD_STS_FIFORDY) == val) 105 return 0; 106 msleep(1); 107 } 108 dev_warn(chip->card->dev, "FIFO not ready (stream %d)\n", str->dsd); 109 return -EIO; 110 } 111 112 /* sync for FIFO ready/empty for all linked streams; 113 * clear paused flag when FIFO gets ready again 114 */ 115 static int lola_sync_wait_for_fifo(struct lola *chip, 116 struct snd_pcm_substream *substream, 117 bool ready) 118 { 119 unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0; 120 unsigned long end_time = jiffies + msecs_to_jiffies(200); 121 struct snd_pcm_substream *s; 122 int pending = 0; 123 124 while (time_before(jiffies, end_time)) { 125 pending = 0; 126 snd_pcm_group_for_each_entry(s, substream) { 127 struct lola_stream *str; 128 if (s->pcm->card != substream->pcm->card) 129 continue; 130 str = lola_get_stream(s); 131 if (str->prepared && str->paused) { 132 unsigned int reg; 133 reg = lola_dsd_read(chip, str->dsd, STS); 134 if ((reg & LOLA_DSD_STS_FIFORDY) != val) { 135 pending = str->dsd + 1; 136 break; 137 } 138 if (ready) 139 str->paused = 0; 140 } 141 } 142 if (!pending) 143 return 0; 144 msleep(1); 145 } 146 dev_warn(chip->card->dev, "FIFO not ready (pending %d)\n", pending - 1); 147 return -EIO; 148 } 149 150 /* finish pause - prepare for a new resume */ 151 static void lola_sync_pause(struct lola *chip, 152 struct snd_pcm_substream *substream) 153 { 154 struct snd_pcm_substream *s; 155 156 lola_sync_wait_for_fifo(chip, substream, false); 157 snd_pcm_group_for_each_entry(s, substream) { 158 struct lola_stream *str; 159 if (s->pcm->card != substream->pcm->card) 160 continue; 161 str = lola_get_stream(s); 162 if (str->paused && str->prepared) 163 lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRUN | 164 LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE); 165 } 166 lola_sync_wait_for_fifo(chip, substream, true); 167 } 168 169 static void lola_stream_reset(struct lola *chip, struct lola_stream *str) 170 { 171 if (str->prepared) { 172 if (str->paused) 173 lola_sync_pause(chip, str->substream); 174 str->prepared = 0; 175 lola_dsd_write(chip, str->dsd, CTL, 176 LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE); 177 lola_stream_wait_for_fifo(chip, str, false); 178 lola_stream_clear_pending_irq(chip, str); 179 lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRST); 180 lola_dsd_write(chip, str->dsd, LVI, 0); 181 lola_dsd_write(chip, str->dsd, BDPU, 0); 182 lola_dsd_write(chip, str->dsd, BDPL, 0); 183 wait_for_srst_clear(chip, str); 184 } 185 } 186 187 static const struct snd_pcm_hardware lola_pcm_hw = { 188 .info = (SNDRV_PCM_INFO_MMAP | 189 SNDRV_PCM_INFO_INTERLEAVED | 190 SNDRV_PCM_INFO_BLOCK_TRANSFER | 191 SNDRV_PCM_INFO_MMAP_VALID | 192 SNDRV_PCM_INFO_PAUSE), 193 .formats = (SNDRV_PCM_FMTBIT_S16_LE | 194 SNDRV_PCM_FMTBIT_S24_LE | 195 SNDRV_PCM_FMTBIT_S32_LE | 196 SNDRV_PCM_FMTBIT_FLOAT_LE), 197 .rates = SNDRV_PCM_RATE_8000_192000, 198 .rate_min = 8000, 199 .rate_max = 192000, 200 .channels_min = 1, 201 .channels_max = 2, 202 .buffer_bytes_max = LOLA_MAX_BUF_SIZE, 203 .period_bytes_min = 128, 204 .period_bytes_max = LOLA_MAX_BUF_SIZE / 2, 205 .periods_min = 2, 206 .periods_max = LOLA_MAX_BDL_ENTRIES, 207 .fifo_size = 0, 208 }; 209 210 static int lola_pcm_open(struct snd_pcm_substream *substream) 211 { 212 struct lola *chip = snd_pcm_substream_chip(substream); 213 struct lola_pcm *pcm = lola_get_pcm(substream); 214 struct lola_stream *str = lola_get_stream(substream); 215 struct snd_pcm_runtime *runtime = substream->runtime; 216 217 guard(mutex)(&chip->open_mutex); 218 if (str->opened) 219 return -EBUSY; 220 str->substream = substream; 221 str->master = NULL; 222 str->opened = 1; 223 runtime->hw = lola_pcm_hw; 224 runtime->hw.channels_max = pcm->num_streams - str->index; 225 if (chip->sample_rate) { 226 /* sample rate is locked */ 227 runtime->hw.rate_min = chip->sample_rate; 228 runtime->hw.rate_max = chip->sample_rate; 229 } else { 230 runtime->hw.rate_min = chip->sample_rate_min; 231 runtime->hw.rate_max = chip->sample_rate_max; 232 } 233 chip->ref_count_rate++; 234 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 235 /* period size = multiple of chip->granularity (8, 16 or 32 frames)*/ 236 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 237 chip->granularity); 238 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 239 chip->granularity); 240 return 0; 241 } 242 243 static void lola_cleanup_slave_streams(struct lola_pcm *pcm, 244 struct lola_stream *str) 245 { 246 int i; 247 for (i = str->index + 1; i < pcm->num_streams; i++) { 248 struct lola_stream *s = &pcm->streams[i]; 249 if (s->master != str) 250 break; 251 s->master = NULL; 252 s->opened = 0; 253 } 254 } 255 256 static int lola_pcm_close(struct snd_pcm_substream *substream) 257 { 258 struct lola *chip = snd_pcm_substream_chip(substream); 259 struct lola_stream *str = lola_get_stream(substream); 260 261 guard(mutex)(&chip->open_mutex); 262 if (str->substream == substream) { 263 str->substream = NULL; 264 str->opened = 0; 265 } 266 if (--chip->ref_count_rate == 0) { 267 /* release sample rate */ 268 chip->sample_rate = 0; 269 } 270 return 0; 271 } 272 273 static int lola_pcm_hw_params(struct snd_pcm_substream *substream, 274 struct snd_pcm_hw_params *hw_params) 275 { 276 struct lola_stream *str = lola_get_stream(substream); 277 278 str->bufsize = 0; 279 str->period_bytes = 0; 280 str->format_verb = 0; 281 return 0; 282 } 283 284 static int lola_pcm_hw_free(struct snd_pcm_substream *substream) 285 { 286 struct lola *chip = snd_pcm_substream_chip(substream); 287 struct lola_pcm *pcm = lola_get_pcm(substream); 288 struct lola_stream *str = lola_get_stream(substream); 289 290 guard(mutex)(&chip->open_mutex); 291 lola_stream_reset(chip, str); 292 lola_cleanup_slave_streams(pcm, str); 293 return 0; 294 } 295 296 /* 297 * set up a BDL entry 298 */ 299 static int setup_bdle(struct snd_pcm_substream *substream, 300 struct lola_stream *str, __le32 **bdlp, 301 int ofs, int size) 302 { 303 __le32 *bdl = *bdlp; 304 305 while (size > 0) { 306 dma_addr_t addr; 307 int chunk; 308 309 if (str->frags >= LOLA_MAX_BDL_ENTRIES) 310 return -EINVAL; 311 312 addr = snd_pcm_sgbuf_get_addr(substream, ofs); 313 /* program the address field of the BDL entry */ 314 bdl[0] = cpu_to_le32((u32)addr); 315 bdl[1] = cpu_to_le32(upper_32_bits(addr)); 316 /* program the size field of the BDL entry */ 317 chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size); 318 bdl[2] = cpu_to_le32(chunk); 319 /* program the IOC to enable interrupt 320 * only when the whole fragment is processed 321 */ 322 size -= chunk; 323 bdl[3] = size ? 0 : cpu_to_le32(0x01); 324 bdl += 4; 325 str->frags++; 326 ofs += chunk; 327 } 328 *bdlp = bdl; 329 return ofs; 330 } 331 332 /* 333 * set up BDL entries 334 */ 335 static int lola_setup_periods(struct lola *chip, struct lola_pcm *pcm, 336 struct snd_pcm_substream *substream, 337 struct lola_stream *str) 338 { 339 __le32 *bdl; 340 int i, ofs, periods, period_bytes; 341 342 period_bytes = str->period_bytes; 343 periods = str->bufsize / period_bytes; 344 345 /* program the initial BDL entries */ 346 bdl = (__le32 *)(pcm->bdl->area + LOLA_BDL_ENTRY_SIZE * str->index); 347 ofs = 0; 348 str->frags = 0; 349 for (i = 0; i < periods; i++) { 350 ofs = setup_bdle(substream, str, &bdl, ofs, period_bytes); 351 if (ofs < 0) 352 goto error; 353 } 354 return 0; 355 356 error: 357 dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n", 358 str->bufsize, period_bytes); 359 return -EINVAL; 360 } 361 362 static unsigned int lola_get_format_verb(struct snd_pcm_substream *substream) 363 { 364 unsigned int verb; 365 366 switch (substream->runtime->format) { 367 case SNDRV_PCM_FORMAT_S16_LE: 368 verb = 0x00000000; 369 break; 370 case SNDRV_PCM_FORMAT_S24_LE: 371 verb = 0x00000200; 372 break; 373 case SNDRV_PCM_FORMAT_S32_LE: 374 verb = 0x00000300; 375 break; 376 case SNDRV_PCM_FORMAT_FLOAT_LE: 377 verb = 0x00001300; 378 break; 379 default: 380 return 0; 381 } 382 verb |= substream->runtime->channels; 383 return verb; 384 } 385 386 static int lola_set_stream_config(struct lola *chip, 387 struct lola_stream *str, 388 int channels) 389 { 390 int i, err; 391 unsigned int verb, val; 392 393 /* set format info for all channels 394 * (with only one command for the first channel) 395 */ 396 err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT, 397 str->format_verb, 0, &val, NULL); 398 if (err < 0) { 399 dev_err(chip->card->dev, "Cannot set stream format 0x%x\n", 400 str->format_verb); 401 return err; 402 } 403 404 /* update stream - channel config */ 405 for (i = 0; i < channels; i++) { 406 verb = (str->index << 6) | i; 407 err = lola_codec_read(chip, str[i].nid, 408 LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb, 409 &val, NULL); 410 if (err < 0) { 411 dev_err(chip->card->dev, 412 "Cannot set stream channel %d\n", i); 413 return err; 414 } 415 } 416 return 0; 417 } 418 419 /* 420 * set up the SD for streaming 421 */ 422 static int lola_setup_controller(struct lola *chip, struct lola_pcm *pcm, 423 struct lola_stream *str) 424 { 425 dma_addr_t bdl; 426 427 if (str->prepared) 428 return -EINVAL; 429 430 /* set up BDL */ 431 bdl = pcm->bdl->addr + LOLA_BDL_ENTRY_SIZE * str->index; 432 lola_dsd_write(chip, str->dsd, BDPL, (u32)bdl); 433 lola_dsd_write(chip, str->dsd, BDPU, upper_32_bits(bdl)); 434 /* program the stream LVI (last valid index) of the BDL */ 435 lola_dsd_write(chip, str->dsd, LVI, str->frags - 1); 436 lola_stream_clear_pending_irq(chip, str); 437 438 lola_dsd_write(chip, str->dsd, CTL, 439 LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE | LOLA_DSD_CTL_SRUN); 440 441 str->prepared = 1; 442 443 return lola_stream_wait_for_fifo(chip, str, true); 444 } 445 446 static int lola_pcm_prepare(struct snd_pcm_substream *substream) 447 { 448 struct lola *chip = snd_pcm_substream_chip(substream); 449 struct lola_pcm *pcm = lola_get_pcm(substream); 450 struct lola_stream *str = lola_get_stream(substream); 451 struct snd_pcm_runtime *runtime = substream->runtime; 452 unsigned int bufsize, period_bytes, format_verb; 453 int i, err; 454 455 scoped_guard(mutex, &chip->open_mutex) { 456 lola_stream_reset(chip, str); 457 lola_cleanup_slave_streams(pcm, str); 458 if (str->index + runtime->channels > pcm->num_streams) 459 return -EINVAL; 460 for (i = 1; i < runtime->channels; i++) { 461 str[i].master = str; 462 str[i].opened = 1; 463 } 464 } 465 466 bufsize = snd_pcm_lib_buffer_bytes(substream); 467 period_bytes = snd_pcm_lib_period_bytes(substream); 468 format_verb = lola_get_format_verb(substream); 469 470 str->bufsize = bufsize; 471 str->period_bytes = period_bytes; 472 str->format_verb = format_verb; 473 474 err = lola_setup_periods(chip, pcm, substream, str); 475 if (err < 0) 476 return err; 477 478 err = lola_set_sample_rate(chip, runtime->rate); 479 if (err < 0) 480 return err; 481 chip->sample_rate = runtime->rate; /* sample rate gets locked */ 482 483 err = lola_set_stream_config(chip, str, runtime->channels); 484 if (err < 0) 485 return err; 486 487 err = lola_setup_controller(chip, pcm, str); 488 if (err < 0) { 489 lola_stream_reset(chip, str); 490 return err; 491 } 492 493 return 0; 494 } 495 496 static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 497 { 498 struct lola *chip = snd_pcm_substream_chip(substream); 499 struct lola_stream *str; 500 struct snd_pcm_substream *s; 501 unsigned int start; 502 unsigned int tstamp; 503 bool sync_streams; 504 505 switch (cmd) { 506 case SNDRV_PCM_TRIGGER_START: 507 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 508 case SNDRV_PCM_TRIGGER_RESUME: 509 start = 1; 510 break; 511 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 512 case SNDRV_PCM_TRIGGER_SUSPEND: 513 case SNDRV_PCM_TRIGGER_STOP: 514 start = 0; 515 break; 516 default: 517 return -EINVAL; 518 } 519 520 /* 521 * sample correct synchronization is only needed starting several 522 * streams. On stop or if only one stream do as quick as possible 523 */ 524 sync_streams = (start && snd_pcm_stream_linked(substream)); 525 tstamp = lola_get_tstamp(chip, !sync_streams); 526 guard(spinlock)(&chip->reg_lock); 527 snd_pcm_group_for_each_entry(s, substream) { 528 if (s->pcm->card != substream->pcm->card) 529 continue; 530 str = lola_get_stream(s); 531 if (start) 532 lola_stream_start(chip, str, tstamp); 533 else 534 lola_stream_stop(chip, str, tstamp); 535 str->running = start; 536 str->paused = !start; 537 snd_pcm_trigger_done(s, substream); 538 } 539 return 0; 540 } 541 542 static snd_pcm_uframes_t lola_pcm_pointer(struct snd_pcm_substream *substream) 543 { 544 struct lola *chip = snd_pcm_substream_chip(substream); 545 struct lola_stream *str = lola_get_stream(substream); 546 unsigned int pos = lola_dsd_read(chip, str->dsd, LPIB); 547 548 if (pos >= str->bufsize) 549 pos = 0; 550 return bytes_to_frames(substream->runtime, pos); 551 } 552 553 void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits) 554 { 555 int i; 556 u8 num_streams = min_t(u8, pcm->num_streams, ARRAY_SIZE(pcm->streams)); 557 558 for (i = 0; bits && i < num_streams; i++) { 559 if (bits & (1 << i)) { 560 struct lola_stream *str = &pcm->streams[i]; 561 if (str->substream && str->running) 562 snd_pcm_period_elapsed(str->substream); 563 bits &= ~(1 << i); 564 } 565 } 566 } 567 568 static const struct snd_pcm_ops lola_pcm_ops = { 569 .open = lola_pcm_open, 570 .close = lola_pcm_close, 571 .hw_params = lola_pcm_hw_params, 572 .hw_free = lola_pcm_hw_free, 573 .prepare = lola_pcm_prepare, 574 .trigger = lola_pcm_trigger, 575 .pointer = lola_pcm_pointer, 576 }; 577 578 int lola_create_pcm(struct lola *chip) 579 { 580 struct snd_pcm *pcm; 581 int i, err; 582 583 for (i = 0; i < 2; i++) { 584 chip->pcm[i].bdl = 585 snd_devm_alloc_pages(&chip->pci->dev, SNDRV_DMA_TYPE_DEV, 586 PAGE_SIZE); 587 if (!chip->pcm[i].bdl) 588 return -ENOMEM; 589 } 590 591 err = snd_pcm_new(chip->card, "Digigram Lola", 0, 592 chip->pcm[SNDRV_PCM_STREAM_PLAYBACK].num_streams, 593 chip->pcm[SNDRV_PCM_STREAM_CAPTURE].num_streams, 594 &pcm); 595 if (err < 0) 596 return err; 597 strscpy(pcm->name, "Digigram Lola", sizeof(pcm->name)); 598 pcm->private_data = chip; 599 for (i = 0; i < 2; i++) { 600 if (chip->pcm[i].num_streams) 601 snd_pcm_set_ops(pcm, i, &lola_pcm_ops); 602 } 603 /* buffer pre-allocation */ 604 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 605 &chip->pci->dev, 606 1024 * 64, 32 * 1024 * 1024); 607 return 0; 608 } 609 610 /* 611 */ 612 613 static int lola_init_stream(struct lola *chip, struct lola_stream *str, 614 int idx, int nid, int dir) 615 { 616 unsigned int val; 617 int err; 618 619 str->nid = nid; 620 str->index = idx; 621 str->dsd = idx; 622 if (dir == PLAY) 623 str->dsd += MAX_STREAM_IN_COUNT; 624 err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val); 625 if (err < 0) { 626 dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid); 627 return err; 628 } 629 if (dir == PLAY) { 630 /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */ 631 if ((val & 0x00f00dff) != 0x00000010) { 632 dev_err(chip->card->dev, 633 "Invalid wcaps 0x%x for 0x%x\n", 634 val, nid); 635 return -EINVAL; 636 } 637 } else { 638 /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) 639 * (bug : ignore bit8: Conn list = 0/1) 640 */ 641 if ((val & 0x00f00cff) != 0x00100010) { 642 dev_err(chip->card->dev, 643 "Invalid wcaps 0x%x for 0x%x\n", 644 val, nid); 645 return -EINVAL; 646 } 647 /* test bit9:DIGITAL and bit12:SRC_PRESENT*/ 648 if ((val & 0x00001200) == 0x00001200) 649 chip->input_src_caps_mask |= (1 << idx); 650 } 651 652 err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val); 653 if (err < 0) { 654 dev_err(chip->card->dev, "Can't read FORMATS 0x%x\n", nid); 655 return err; 656 } 657 val &= 3; 658 if (val == 3) 659 str->can_float = true; 660 if (!(val & 1)) { 661 dev_err(chip->card->dev, 662 "Invalid formats 0x%x for 0x%x", val, nid); 663 return -EINVAL; 664 } 665 return 0; 666 } 667 668 int lola_init_pcm(struct lola *chip, int dir, int *nidp) 669 { 670 struct lola_pcm *pcm = &chip->pcm[dir]; 671 int i, nid, err; 672 673 nid = *nidp; 674 for (i = 0; i < pcm->num_streams; i++, nid++) { 675 err = lola_init_stream(chip, &pcm->streams[i], i, nid, dir); 676 if (err < 0) 677 return err; 678 } 679 *nidp = nid; 680 return 0; 681 } 682