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