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