lola_pcm.c 16 KB

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