lola_pcm.c 16 KB

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