lola_pcm.c 17 KB

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