lola_pcm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Support for Digigram Lola PCI-e boards
  3. *
  4. * Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59
  18. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/pci.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include "lola.h"
  27. #define BDL_SIZE 4096
  28. #define LOLA_MAX_BDL_ENTRIES (BDL_SIZE / 16)
  29. #define LOLA_MAX_FRAG 32
  30. #define LOLA_MAX_BUF_SIZE (1024*1024*1024)
  31. static struct lola_pcm *lola_get_pcm(struct snd_pcm_substream *substream)
  32. {
  33. struct lola *chip = snd_pcm_substream_chip(substream);
  34. return &chip->pcm[substream->stream];
  35. }
  36. static struct lola_stream *lola_get_stream(struct snd_pcm_substream *substream)
  37. {
  38. struct lola_pcm *pcm = lola_get_pcm(substream);
  39. unsigned int idx = substream->number;
  40. return &pcm->streams[idx];
  41. }
  42. static unsigned int lola_get_lrc(struct lola *chip)
  43. {
  44. return lola_readl(chip, BAR1, LRC);
  45. }
  46. static unsigned int lola_get_tstamp(struct lola *chip, bool quick_no_sync)
  47. {
  48. unsigned int tstamp = lola_get_lrc(chip) >> 8;
  49. if (chip->granularity) {
  50. unsigned int wait_banks = quick_no_sync ? 0 : 8;
  51. tstamp += (wait_banks + 1) * chip->granularity - 1;
  52. tstamp -= tstamp % chip->granularity;
  53. }
  54. return tstamp << 8;
  55. }
  56. /* clear any pending interrupt status */
  57. static void lola_stream_clear_pending_irq(struct lola *chip,
  58. struct lola_stream *str)
  59. {
  60. unsigned int val = lola_dsd_read(chip, str->dsd, STS);
  61. val &= LOLA_DSD_STS_DESE | LOLA_DSD_STS_BCIS;
  62. if (val)
  63. lola_dsd_write(chip, str->dsd, STS, val);
  64. }
  65. static void lola_stream_start(struct lola *chip, struct lola_stream *str,
  66. unsigned int tstamp)
  67. {
  68. lola_stream_clear_pending_irq(chip, str);
  69. lola_dsd_write(chip, str->dsd, CTL,
  70. LOLA_DSD_CTL_SRUN |
  71. LOLA_DSD_CTL_IOCE |
  72. LOLA_DSD_CTL_DEIE |
  73. LOLA_DSD_CTL_VLRCV |
  74. tstamp);
  75. }
  76. static void lola_stream_stop(struct lola *chip, struct lola_stream *str,
  77. unsigned int tstamp)
  78. {
  79. lola_dsd_write(chip, str->dsd, CTL,
  80. LOLA_DSD_CTL_IOCE |
  81. LOLA_DSD_CTL_DEIE |
  82. LOLA_DSD_CTL_VLRCV |
  83. tstamp);
  84. lola_stream_clear_pending_irq(chip, str);
  85. }
  86. static void lola_stream_clear(struct lola *chip, struct lola_stream *str)
  87. {
  88. lola_dsd_write(chip, str->dsd, CTL, 0);
  89. lola_stream_clear_pending_irq(chip, str);
  90. }
  91. static void wait_for_srst_clear(struct lola *chip, struct lola_stream *str)
  92. {
  93. unsigned long end_time = jiffies + msecs_to_jiffies(50);
  94. while (time_before(jiffies, end_time)) {
  95. unsigned int val;
  96. val = lola_dsd_read(chip, str->dsd, CTL);
  97. if (!(val & LOLA_DSD_CTL_SRST))
  98. return;
  99. msleep(1);
  100. }
  101. printk(KERN_WARNING SFX "SRST not clear (stream %d)\n", str->dsd);
  102. }
  103. static void lola_stream_reset(struct lola *chip, struct lola_stream *str)
  104. {
  105. lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRST);
  106. lola_dsd_write(chip, str->dsd, LVI, 0);
  107. lola_dsd_write(chip, str->dsd, BDPU, 0);
  108. lola_dsd_write(chip, str->dsd, BDPL, 0);
  109. wait_for_srst_clear(chip, str);
  110. }
  111. static int lola_stream_wait_for_fifo_ready(struct lola *chip,
  112. struct lola_stream *str)
  113. {
  114. unsigned long end_time = jiffies + msecs_to_jiffies(50);
  115. while (time_before(jiffies, end_time)) {
  116. unsigned int val = lola_dsd_read(chip, str->dsd, STS);
  117. if (val & LOLA_DSD_STS_FIFORDY)
  118. return 0;
  119. msleep(1);
  120. }
  121. printk(KERN_WARNING SFX "FIFO not ready (stream %d)\n", str->dsd);
  122. return -EIO;
  123. }
  124. static struct snd_pcm_hardware lola_pcm_hw = {
  125. .info = (SNDRV_PCM_INFO_MMAP |
  126. SNDRV_PCM_INFO_INTERLEAVED |
  127. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  128. SNDRV_PCM_INFO_MMAP_VALID |
  129. SNDRV_PCM_INFO_PAUSE),
  130. .formats = (SNDRV_PCM_FMTBIT_S16_LE |
  131. SNDRV_PCM_FMTBIT_S24_LE |
  132. SNDRV_PCM_FMTBIT_S32_LE |
  133. SNDRV_PCM_FMTBIT_FLOAT_LE),
  134. .rates = SNDRV_PCM_RATE_48000,
  135. .rate_min = 48000,
  136. .rate_max = 48000,
  137. .channels_min = 1,
  138. .channels_max = 2,
  139. .buffer_bytes_max = LOLA_MAX_BUF_SIZE,
  140. .period_bytes_min = 128,
  141. .period_bytes_max = LOLA_MAX_BUF_SIZE / 2,
  142. .periods_min = 2,
  143. .periods_max = LOLA_MAX_FRAG,
  144. .fifo_size = 0,
  145. };
  146. static int lola_pcm_open(struct snd_pcm_substream *substream)
  147. {
  148. struct lola *chip = snd_pcm_substream_chip(substream);
  149. struct lola_pcm *pcm = lola_get_pcm(substream);
  150. struct lola_stream *str = lola_get_stream(substream);
  151. struct snd_pcm_runtime *runtime = substream->runtime;
  152. int err;
  153. mutex_lock(&chip->open_mutex);
  154. if (str->opened) {
  155. mutex_unlock(&chip->open_mutex);
  156. return -EBUSY;
  157. }
  158. err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
  159. snd_dma_pci_data(chip->pci),
  160. PAGE_SIZE, &str->bdl);
  161. if (err < 0) {
  162. mutex_unlock(&chip->open_mutex);
  163. printk(KERN_ERR SFX "Can't allocate BDL\n");
  164. return err;
  165. }
  166. str->substream = substream;
  167. str->master = NULL;
  168. str->opened = 1;
  169. runtime->hw = lola_pcm_hw;
  170. runtime->hw.channels_max = pcm->num_streams - str->index;
  171. snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
  172. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  173. 128);
  174. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  175. 128);
  176. mutex_unlock(&chip->open_mutex);
  177. return 0;
  178. }
  179. static void lola_cleanup_slave_streams(struct lola_pcm *pcm,
  180. struct lola_stream *str)
  181. {
  182. int i;
  183. for (i = str->index + 1; i < pcm->num_streams; i++) {
  184. struct lola_stream *s = &pcm->streams[i];
  185. if (s->master != str)
  186. break;
  187. s->master = NULL;
  188. s->opened = 0;
  189. }
  190. }
  191. static int lola_pcm_close(struct snd_pcm_substream *substream)
  192. {
  193. struct lola *chip = snd_pcm_substream_chip(substream);
  194. struct lola_stream *str = lola_get_stream(substream);
  195. mutex_lock(&chip->open_mutex);
  196. if (str->substream == substream) {
  197. str->substream = NULL;
  198. str->opened = 0;
  199. }
  200. snd_dma_free_pages(&str->bdl);
  201. mutex_unlock(&chip->open_mutex);
  202. return 0;
  203. }
  204. static int lola_pcm_hw_params(struct snd_pcm_substream *substream,
  205. struct snd_pcm_hw_params *hw_params)
  206. {
  207. struct lola_stream *str = lola_get_stream(substream);
  208. str->bufsize = 0;
  209. str->period_bytes = 0;
  210. str->format_verb = 0;
  211. return snd_pcm_lib_malloc_pages(substream,
  212. params_buffer_bytes(hw_params));
  213. }
  214. static int lola_pcm_hw_free(struct snd_pcm_substream *substream)
  215. {
  216. struct lola *chip = snd_pcm_substream_chip(substream);
  217. struct lola_pcm *pcm = lola_get_pcm(substream);
  218. struct lola_stream *str = lola_get_stream(substream);
  219. mutex_lock(&chip->open_mutex);
  220. lola_stream_reset(chip, str);
  221. lola_cleanup_slave_streams(pcm, str);
  222. mutex_unlock(&chip->open_mutex);
  223. return snd_pcm_lib_free_pages(substream);
  224. }
  225. /*
  226. * set up a BDL entry
  227. */
  228. static int setup_bdle(struct snd_pcm_substream *substream,
  229. struct lola_stream *str, u32 **bdlp,
  230. int ofs, int size)
  231. {
  232. u32 *bdl = *bdlp;
  233. while (size > 0) {
  234. dma_addr_t addr;
  235. int chunk;
  236. if (str->frags >= LOLA_MAX_BDL_ENTRIES)
  237. return -EINVAL;
  238. addr = snd_pcm_sgbuf_get_addr(substream, ofs);
  239. /* program the address field of the BDL entry */
  240. bdl[0] = cpu_to_le32((u32)addr);
  241. bdl[1] = cpu_to_le32(upper_32_bits(addr));
  242. /* program the size field of the BDL entry */
  243. chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
  244. bdl[2] = cpu_to_le32(chunk);
  245. /* program the IOC to enable interrupt
  246. * only when the whole fragment is processed
  247. */
  248. size -= chunk;
  249. bdl[3] = size ? 0 : cpu_to_le32(0x01);
  250. bdl += 4;
  251. str->frags++;
  252. ofs += chunk;
  253. }
  254. *bdlp = bdl;
  255. return ofs;
  256. }
  257. /*
  258. * set up BDL entries
  259. */
  260. static int lola_setup_periods(struct lola *chip,
  261. struct snd_pcm_substream *substream,
  262. struct lola_stream *str)
  263. {
  264. u32 *bdl;
  265. int i, ofs, periods, period_bytes;
  266. period_bytes = str->period_bytes;
  267. periods = str->bufsize / period_bytes;
  268. /* program the initial BDL entries */
  269. bdl = (u32 *)str->bdl.area;
  270. ofs = 0;
  271. str->frags = 0;
  272. for (i = 0; i < periods; i++) {
  273. ofs = setup_bdle(substream, str, &bdl, ofs, period_bytes);
  274. if (ofs < 0)
  275. goto error;
  276. }
  277. return 0;
  278. error:
  279. snd_printk(KERN_ERR SFX "Too many BDL entries: buffer=%d, period=%d\n",
  280. str->bufsize, period_bytes);
  281. return -EINVAL;
  282. }
  283. static unsigned int lola_get_format_verb(struct snd_pcm_substream *substream)
  284. {
  285. unsigned int verb;
  286. switch (substream->runtime->format) {
  287. case SNDRV_PCM_FORMAT_S16_LE:
  288. verb = 0x00000000;
  289. break;
  290. case SNDRV_PCM_FORMAT_S24_LE:
  291. verb = 0x00000200;
  292. break;
  293. case SNDRV_PCM_FORMAT_S32_LE:
  294. verb = 0x00000300;
  295. break;
  296. case SNDRV_PCM_FORMAT_FLOAT_LE:
  297. verb = 0x00001300;
  298. break;
  299. default:
  300. return 0;
  301. }
  302. verb |= substream->runtime->channels;
  303. return verb;
  304. }
  305. static int lola_set_stream_config(struct lola *chip,
  306. struct lola_stream *str,
  307. int channels)
  308. {
  309. int i, err;
  310. unsigned int verb, val;
  311. /* set format info for all channels
  312. * (with only one command for the first channel)
  313. */
  314. err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT,
  315. str->format_verb, 0, &val, NULL);
  316. if (err < 0) {
  317. printk(KERN_ERR SFX "Cannot set stream format 0x%x\n",
  318. str->format_verb);
  319. return err;
  320. }
  321. /* update stream - channel config */
  322. for (i = 0; i < channels; i++) {
  323. verb = (str->index << 6) | i;
  324. err = lola_codec_read(chip, str[i].nid,
  325. LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb,
  326. &val, NULL);
  327. if (err < 0) {
  328. printk(KERN_ERR SFX "Cannot set stream channel %d\n", i);
  329. return err;
  330. }
  331. }
  332. return 0;
  333. }
  334. /*
  335. * set up the SD for streaming
  336. */
  337. static int lola_setup_controller(struct lola *chip, struct lola_stream *str)
  338. {
  339. /* make sure the run bit is zero for SD */
  340. lola_stream_clear(chip, str);
  341. /* set up BDL */
  342. lola_dsd_write(chip, str->dsd, BDPL, (u32)str->bdl.addr);
  343. lola_dsd_write(chip, str->dsd, BDPU, upper_32_bits(str->bdl.addr));
  344. /* program the stream LVI (last valid index) of the BDL */
  345. lola_dsd_write(chip, str->dsd, LVI, str->frags - 1);
  346. lola_stream_stop(chip, str, lola_get_tstamp(chip, false));
  347. lola_stream_wait_for_fifo_ready(chip, str);
  348. return 0;
  349. }
  350. static int lola_pcm_prepare(struct snd_pcm_substream *substream)
  351. {
  352. struct lola *chip = snd_pcm_substream_chip(substream);
  353. struct lola_pcm *pcm = lola_get_pcm(substream);
  354. struct lola_stream *str = lola_get_stream(substream);
  355. struct snd_pcm_runtime *runtime = substream->runtime;
  356. unsigned int bufsize, period_bytes, format_verb;
  357. int i, err;
  358. mutex_lock(&chip->open_mutex);
  359. lola_stream_reset(chip, str);
  360. lola_cleanup_slave_streams(pcm, str);
  361. if (str->index + runtime->channels >= pcm->num_streams) {
  362. mutex_unlock(&chip->open_mutex);
  363. return -EINVAL;
  364. }
  365. for (i = 1; i < runtime->channels; i++) {
  366. str[i].master = str;
  367. str[i].opened = 1;
  368. }
  369. mutex_unlock(&chip->open_mutex);
  370. bufsize = snd_pcm_lib_buffer_bytes(substream);
  371. period_bytes = snd_pcm_lib_period_bytes(substream);
  372. format_verb = lola_get_format_verb(substream);
  373. if (bufsize != str->bufsize ||
  374. period_bytes != str->period_bytes ||
  375. format_verb != str->format_verb) {
  376. str->bufsize = bufsize;
  377. str->period_bytes = period_bytes;
  378. str->format_verb = format_verb;
  379. err = lola_setup_periods(chip, substream, str);
  380. if (err < 0)
  381. return err;
  382. }
  383. err = lola_set_stream_config(chip, str, runtime->channels);
  384. if (err < 0)
  385. return err;
  386. return lola_setup_controller(chip, str);
  387. }
  388. static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  389. {
  390. struct lola *chip = snd_pcm_substream_chip(substream);
  391. struct lola_stream *str;
  392. struct snd_pcm_substream *s;
  393. unsigned int start;
  394. unsigned int tstamp;
  395. switch (cmd) {
  396. case SNDRV_PCM_TRIGGER_START:
  397. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  398. case SNDRV_PCM_TRIGGER_RESUME:
  399. start = 1;
  400. break;
  401. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  402. case SNDRV_PCM_TRIGGER_SUSPEND:
  403. case SNDRV_PCM_TRIGGER_STOP:
  404. start = 0;
  405. break;
  406. default:
  407. return -EINVAL;
  408. }
  409. tstamp = lola_get_tstamp(chip, false);
  410. spin_lock(&chip->reg_lock);
  411. snd_pcm_group_for_each_entry(s, substream) {
  412. if (s->pcm->card != substream->pcm->card)
  413. continue;
  414. str = lola_get_stream(s);
  415. if (start)
  416. lola_stream_start(chip, str, tstamp);
  417. else
  418. lola_stream_stop(chip, str, tstamp);
  419. str->running = start;
  420. snd_pcm_trigger_done(s, substream);
  421. }
  422. spin_unlock(&chip->reg_lock);
  423. return 0;
  424. }
  425. static snd_pcm_uframes_t lola_pcm_pointer(struct snd_pcm_substream *substream)
  426. {
  427. struct lola *chip = snd_pcm_substream_chip(substream);
  428. struct lola_stream *str = lola_get_stream(substream);
  429. unsigned int pos = lola_dsd_read(chip, str->dsd, LPIB);
  430. if (pos >= str->bufsize)
  431. pos = 0;
  432. return bytes_to_frames(substream->runtime, pos);
  433. }
  434. void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits)
  435. {
  436. int i;
  437. for (i = 0; bits && i < pcm->num_streams; i++) {
  438. if (bits & (1 << i)) {
  439. struct lola_stream *str = &pcm->streams[i];
  440. if (str->substream && str->running)
  441. snd_pcm_period_elapsed(str->substream);
  442. bits &= ~(1 << i);
  443. }
  444. }
  445. }
  446. static struct snd_pcm_ops lola_pcm_ops = {
  447. .open = lola_pcm_open,
  448. .close = lola_pcm_close,
  449. .ioctl = snd_pcm_lib_ioctl,
  450. .hw_params = lola_pcm_hw_params,
  451. .hw_free = lola_pcm_hw_free,
  452. .prepare = lola_pcm_prepare,
  453. .trigger = lola_pcm_trigger,
  454. .pointer = lola_pcm_pointer,
  455. .page = snd_pcm_sgbuf_ops_page,
  456. };
  457. int __devinit lola_create_pcm(struct lola *chip)
  458. {
  459. struct snd_pcm *pcm;
  460. int i, err;
  461. err = snd_pcm_new(chip->card, "Digigram Lola", 0,
  462. chip->pcm[SNDRV_PCM_STREAM_PLAYBACK].num_streams,
  463. chip->pcm[SNDRV_PCM_STREAM_CAPTURE].num_streams,
  464. &pcm);
  465. if (err < 0)
  466. return err;
  467. strlcpy(pcm->name, "Digigram Lola", sizeof(pcm->name));
  468. pcm->private_data = chip;
  469. for (i = 0; i < 2; i++) {
  470. if (chip->pcm[i].num_streams)
  471. snd_pcm_set_ops(pcm, i, &lola_pcm_ops);
  472. }
  473. /* buffer pre-allocation */
  474. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
  475. snd_dma_pci_data(chip->pci),
  476. 1024 * 64, 32 * 1024 * 1024);
  477. return 0;
  478. }
  479. void lola_free_pcm(struct lola *chip)
  480. {
  481. /* nothing to do */
  482. }
  483. /*
  484. */
  485. static int lola_init_stream(struct lola *chip, struct lola_stream *str,
  486. int idx, int nid, int dir)
  487. {
  488. unsigned int val;
  489. int err;
  490. str->nid = nid;
  491. str->index = idx;
  492. str->dsd = idx;
  493. if (dir == PLAY)
  494. str->dsd += MAX_STREAM_IN_COUNT;
  495. err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
  496. if (err < 0) {
  497. printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid);
  498. return err;
  499. }
  500. if (dir == PLAY) {
  501. /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */
  502. if ((val & 0x00f00dff) != 0x00000010) {
  503. printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n",
  504. val, nid);
  505. return -EINVAL;
  506. }
  507. } else {
  508. /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1)
  509. * (bug : ignore bit8: Conn list = 0/1)
  510. */
  511. if ((val & 0x00f00cff) != 0x00100010) {
  512. printk(KERN_ERR SFX "Invalid wcaps 0x%x for 0x%x\n",
  513. val, nid);
  514. return -EINVAL;
  515. }
  516. /* test bit9:DIGITAL and bit12:SRC_PRESENT*/
  517. if ((val & 0x00001200) == 0x00001200)
  518. chip->input_src_caps_mask |= (1 << idx);
  519. }
  520. err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
  521. if (err < 0) {
  522. printk(KERN_ERR SFX "Can't read FORMATS 0x%x\n", nid);
  523. return err;
  524. }
  525. val &= 3;
  526. if (val == 3)
  527. str->can_float = true;
  528. if (!(val & 1)) {
  529. printk(KERN_ERR SFX "Invalid formats 0x%x for 0x%x", val, nid);
  530. return -EINVAL;
  531. }
  532. return 0;
  533. }
  534. int __devinit lola_init_pcm(struct lola *chip, int dir, int *nidp)
  535. {
  536. struct lola_pcm *pcm = &chip->pcm[dir];
  537. int i, nid, err;
  538. nid = *nidp;
  539. for (i = 0; i < pcm->num_streams; i++, nid++) {
  540. err = lola_init_stream(chip, &pcm->streams[i], i, nid, dir);
  541. if (err < 0)
  542. return err;
  543. }
  544. *nidp = nid;
  545. return 0;
  546. }