Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Support for Digigram Lola PCI-e boards
0004  *
0005  *  Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
0006  */
0007 
0008 #include <linux/kernel.h>
0009 #include <linux/init.h>
0010 #include <linux/dma-mapping.h>
0011 #include <linux/pci.h>
0012 #include <linux/delay.h>
0013 #include <sound/core.h>
0014 #include <sound/pcm.h>
0015 #include "lola.h"
0016 
0017 #define LOLA_MAX_BDL_ENTRIES    8
0018 #define LOLA_MAX_BUF_SIZE   (1024*1024*1024)
0019 #define LOLA_BDL_ENTRY_SIZE (16 * 16)
0020 
0021 static struct lola_pcm *lola_get_pcm(struct snd_pcm_substream *substream)
0022 {
0023     struct lola *chip = snd_pcm_substream_chip(substream);
0024     return &chip->pcm[substream->stream];
0025 }
0026 
0027 static struct lola_stream *lola_get_stream(struct snd_pcm_substream *substream)
0028 {
0029     struct lola_pcm *pcm = lola_get_pcm(substream);
0030     unsigned int idx = substream->number;
0031     return &pcm->streams[idx];
0032 }
0033 
0034 static unsigned int lola_get_lrc(struct lola *chip)
0035 {
0036     return lola_readl(chip, BAR1, LRC);
0037 }
0038 
0039 static unsigned int lola_get_tstamp(struct lola *chip, bool quick_no_sync)
0040 {
0041     unsigned int tstamp = lola_get_lrc(chip) >> 8;
0042     if (chip->granularity) {
0043         unsigned int wait_banks = quick_no_sync ? 0 : 8;
0044         tstamp += (wait_banks + 1) * chip->granularity - 1;
0045         tstamp -= tstamp % chip->granularity;
0046     }
0047     return tstamp << 8;
0048 }
0049 
0050 /* clear any pending interrupt status */
0051 static void lola_stream_clear_pending_irq(struct lola *chip,
0052                       struct lola_stream *str)
0053 {
0054     unsigned int val = lola_dsd_read(chip, str->dsd, STS);
0055     val &= LOLA_DSD_STS_DESE | LOLA_DSD_STS_BCIS;
0056     if (val)
0057         lola_dsd_write(chip, str->dsd, STS, val);
0058 }
0059 
0060 static void lola_stream_start(struct lola *chip, struct lola_stream *str,
0061                   unsigned int tstamp)
0062 {
0063     lola_stream_clear_pending_irq(chip, str);
0064     lola_dsd_write(chip, str->dsd, CTL,
0065                LOLA_DSD_CTL_SRUN |
0066                LOLA_DSD_CTL_IOCE |
0067                LOLA_DSD_CTL_DEIE |
0068                LOLA_DSD_CTL_VLRCV |
0069                tstamp);
0070 }
0071 
0072 static void lola_stream_stop(struct lola *chip, struct lola_stream *str,
0073                  unsigned int tstamp)
0074 {
0075     lola_dsd_write(chip, str->dsd, CTL,
0076                LOLA_DSD_CTL_IOCE |
0077                LOLA_DSD_CTL_DEIE |
0078                LOLA_DSD_CTL_VLRCV |
0079                tstamp);
0080     lola_stream_clear_pending_irq(chip, str);
0081 }
0082 
0083 static void wait_for_srst_clear(struct lola *chip, struct lola_stream *str)
0084 {
0085     unsigned long end_time = jiffies + msecs_to_jiffies(200);
0086     while (time_before(jiffies, end_time)) {
0087         unsigned int val;
0088         val = lola_dsd_read(chip, str->dsd, CTL);
0089         if (!(val & LOLA_DSD_CTL_SRST))
0090             return;
0091         msleep(1);
0092     }
0093     dev_warn(chip->card->dev, "SRST not clear (stream %d)\n", str->dsd);
0094 }
0095 
0096 static int lola_stream_wait_for_fifo(struct lola *chip,
0097                      struct lola_stream *str,
0098                      bool ready)
0099 {
0100     unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0;
0101     unsigned long end_time = jiffies + msecs_to_jiffies(200);
0102     while (time_before(jiffies, end_time)) {
0103         unsigned int reg = lola_dsd_read(chip, str->dsd, STS);
0104         if ((reg & LOLA_DSD_STS_FIFORDY) == val)
0105             return 0;
0106         msleep(1);
0107     }
0108     dev_warn(chip->card->dev, "FIFO not ready (stream %d)\n", str->dsd);
0109     return -EIO;
0110 }
0111 
0112 /* sync for FIFO ready/empty for all linked streams;
0113  * clear paused flag when FIFO gets ready again
0114  */
0115 static int lola_sync_wait_for_fifo(struct lola *chip,
0116                    struct snd_pcm_substream *substream,
0117                    bool ready)
0118 {
0119     unsigned int val = ready ? LOLA_DSD_STS_FIFORDY : 0;
0120     unsigned long end_time = jiffies + msecs_to_jiffies(200);
0121     struct snd_pcm_substream *s;
0122     int pending = 0;
0123 
0124     while (time_before(jiffies, end_time)) {
0125         pending = 0;
0126         snd_pcm_group_for_each_entry(s, substream) {
0127             struct lola_stream *str;
0128             if (s->pcm->card != substream->pcm->card)
0129                 continue;
0130             str = lola_get_stream(s);
0131             if (str->prepared && str->paused) {
0132                 unsigned int reg;
0133                 reg = lola_dsd_read(chip, str->dsd, STS);
0134                 if ((reg & LOLA_DSD_STS_FIFORDY) != val) {
0135                     pending = str->dsd + 1;
0136                     break;
0137                 }
0138                 if (ready)
0139                     str->paused = 0;
0140             }
0141         }
0142         if (!pending)
0143             return 0;
0144         msleep(1);
0145     }
0146     dev_warn(chip->card->dev, "FIFO not ready (pending %d)\n", pending - 1);
0147     return -EIO;
0148 }
0149 
0150 /* finish pause - prepare for a new resume */
0151 static void lola_sync_pause(struct lola *chip,
0152                 struct snd_pcm_substream *substream)
0153 {
0154     struct snd_pcm_substream *s;
0155 
0156     lola_sync_wait_for_fifo(chip, substream, false);
0157     snd_pcm_group_for_each_entry(s, substream) {
0158         struct lola_stream *str;
0159         if (s->pcm->card != substream->pcm->card)
0160             continue;
0161         str = lola_get_stream(s);
0162         if (str->paused && str->prepared)
0163             lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRUN |
0164                        LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE);
0165     }
0166     lola_sync_wait_for_fifo(chip, substream, true);
0167 }
0168 
0169 static void lola_stream_reset(struct lola *chip, struct lola_stream *str)
0170 {
0171     if (str->prepared) {
0172         if (str->paused)
0173             lola_sync_pause(chip, str->substream);
0174         str->prepared = 0;
0175         lola_dsd_write(chip, str->dsd, CTL,
0176                    LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE);
0177         lola_stream_wait_for_fifo(chip, str, false);
0178         lola_stream_clear_pending_irq(chip, str);
0179         lola_dsd_write(chip, str->dsd, CTL, LOLA_DSD_CTL_SRST);
0180         lola_dsd_write(chip, str->dsd, LVI, 0);
0181         lola_dsd_write(chip, str->dsd, BDPU, 0);
0182         lola_dsd_write(chip, str->dsd, BDPL, 0);
0183         wait_for_srst_clear(chip, str);
0184     }
0185 }
0186 
0187 static const struct snd_pcm_hardware lola_pcm_hw = {
0188     .info =         (SNDRV_PCM_INFO_MMAP |
0189                  SNDRV_PCM_INFO_INTERLEAVED |
0190                  SNDRV_PCM_INFO_BLOCK_TRANSFER |
0191                  SNDRV_PCM_INFO_MMAP_VALID |
0192                  SNDRV_PCM_INFO_PAUSE),
0193     .formats =      (SNDRV_PCM_FMTBIT_S16_LE |
0194                  SNDRV_PCM_FMTBIT_S24_LE |
0195                  SNDRV_PCM_FMTBIT_S32_LE |
0196                  SNDRV_PCM_FMTBIT_FLOAT_LE),
0197     .rates =        SNDRV_PCM_RATE_8000_192000,
0198     .rate_min =     8000,
0199     .rate_max =     192000,
0200     .channels_min =     1,
0201     .channels_max =     2,
0202     .buffer_bytes_max = LOLA_MAX_BUF_SIZE,
0203     .period_bytes_min = 128,
0204     .period_bytes_max = LOLA_MAX_BUF_SIZE / 2,
0205     .periods_min =      2,
0206     .periods_max =      LOLA_MAX_BDL_ENTRIES,
0207     .fifo_size =        0,
0208 };
0209 
0210 static int lola_pcm_open(struct snd_pcm_substream *substream)
0211 {
0212     struct lola *chip = snd_pcm_substream_chip(substream);
0213     struct lola_pcm *pcm = lola_get_pcm(substream);
0214     struct lola_stream *str = lola_get_stream(substream);
0215     struct snd_pcm_runtime *runtime = substream->runtime;
0216 
0217     mutex_lock(&chip->open_mutex);
0218     if (str->opened) {
0219         mutex_unlock(&chip->open_mutex);
0220         return -EBUSY;
0221     }
0222     str->substream = substream;
0223     str->master = NULL;
0224     str->opened = 1;
0225     runtime->hw = lola_pcm_hw;
0226     runtime->hw.channels_max = pcm->num_streams - str->index;
0227     if (chip->sample_rate) {
0228         /* sample rate is locked */
0229         runtime->hw.rate_min = chip->sample_rate;
0230         runtime->hw.rate_max = chip->sample_rate;
0231     } else {
0232         runtime->hw.rate_min = chip->sample_rate_min;
0233         runtime->hw.rate_max = chip->sample_rate_max;
0234     }
0235     chip->ref_count_rate++;
0236     snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
0237     /* period size = multiple of chip->granularity (8, 16 or 32 frames)*/
0238     snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
0239                    chip->granularity);
0240     snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
0241                    chip->granularity);
0242     mutex_unlock(&chip->open_mutex);
0243     return 0;
0244 }
0245 
0246 static void lola_cleanup_slave_streams(struct lola_pcm *pcm,
0247                        struct lola_stream *str)
0248 {
0249     int i;
0250     for (i = str->index + 1; i < pcm->num_streams; i++) {
0251         struct lola_stream *s = &pcm->streams[i];
0252         if (s->master != str)
0253             break;
0254         s->master = NULL;
0255         s->opened = 0;
0256     }
0257 }
0258 
0259 static int lola_pcm_close(struct snd_pcm_substream *substream)
0260 {
0261     struct lola *chip = snd_pcm_substream_chip(substream);
0262     struct lola_stream *str = lola_get_stream(substream);
0263 
0264     mutex_lock(&chip->open_mutex);
0265     if (str->substream == substream) {
0266         str->substream = NULL;
0267         str->opened = 0;
0268     }
0269     if (--chip->ref_count_rate == 0) {
0270         /* release sample rate */
0271         chip->sample_rate = 0;
0272     }
0273     mutex_unlock(&chip->open_mutex);
0274     return 0;
0275 }
0276 
0277 static int lola_pcm_hw_params(struct snd_pcm_substream *substream,
0278                   struct snd_pcm_hw_params *hw_params)
0279 {
0280     struct lola_stream *str = lola_get_stream(substream);
0281 
0282     str->bufsize = 0;
0283     str->period_bytes = 0;
0284     str->format_verb = 0;
0285     return 0;
0286 }
0287 
0288 static int lola_pcm_hw_free(struct snd_pcm_substream *substream)
0289 {
0290     struct lola *chip = snd_pcm_substream_chip(substream);
0291     struct lola_pcm *pcm = lola_get_pcm(substream);
0292     struct lola_stream *str = lola_get_stream(substream);
0293 
0294     mutex_lock(&chip->open_mutex);
0295     lola_stream_reset(chip, str);
0296     lola_cleanup_slave_streams(pcm, str);
0297     mutex_unlock(&chip->open_mutex);
0298     return 0;
0299 }
0300 
0301 /*
0302  * set up a BDL entry
0303  */
0304 static int setup_bdle(struct snd_pcm_substream *substream,
0305               struct lola_stream *str, __le32 **bdlp,
0306               int ofs, int size)
0307 {
0308     __le32 *bdl = *bdlp;
0309 
0310     while (size > 0) {
0311         dma_addr_t addr;
0312         int chunk;
0313 
0314         if (str->frags >= LOLA_MAX_BDL_ENTRIES)
0315             return -EINVAL;
0316 
0317         addr = snd_pcm_sgbuf_get_addr(substream, ofs);
0318         /* program the address field of the BDL entry */
0319         bdl[0] = cpu_to_le32((u32)addr);
0320         bdl[1] = cpu_to_le32(upper_32_bits(addr));
0321         /* program the size field of the BDL entry */
0322         chunk = snd_pcm_sgbuf_get_chunk_size(substream, ofs, size);
0323         bdl[2] = cpu_to_le32(chunk);
0324         /* program the IOC to enable interrupt
0325          * only when the whole fragment is processed
0326          */
0327         size -= chunk;
0328         bdl[3] = size ? 0 : cpu_to_le32(0x01);
0329         bdl += 4;
0330         str->frags++;
0331         ofs += chunk;
0332     }
0333     *bdlp = bdl;
0334     return ofs;
0335 }
0336 
0337 /*
0338  * set up BDL entries
0339  */
0340 static int lola_setup_periods(struct lola *chip, struct lola_pcm *pcm,
0341                   struct snd_pcm_substream *substream,
0342                   struct lola_stream *str)
0343 {
0344     __le32 *bdl;
0345     int i, ofs, periods, period_bytes;
0346 
0347     period_bytes = str->period_bytes;
0348     periods = str->bufsize / period_bytes;
0349 
0350     /* program the initial BDL entries */
0351     bdl = (__le32 *)(pcm->bdl->area + LOLA_BDL_ENTRY_SIZE * str->index);
0352     ofs = 0;
0353     str->frags = 0;
0354     for (i = 0; i < periods; i++) {
0355         ofs = setup_bdle(substream, str, &bdl, ofs, period_bytes);
0356         if (ofs < 0)
0357             goto error;
0358     }
0359     return 0;
0360 
0361  error:
0362     dev_err(chip->card->dev, "Too many BDL entries: buffer=%d, period=%d\n",
0363            str->bufsize, period_bytes);
0364     return -EINVAL;
0365 }
0366 
0367 static unsigned int lola_get_format_verb(struct snd_pcm_substream *substream)
0368 {
0369     unsigned int verb;
0370 
0371     switch (substream->runtime->format) {
0372     case SNDRV_PCM_FORMAT_S16_LE:
0373         verb = 0x00000000;
0374         break;
0375     case SNDRV_PCM_FORMAT_S24_LE:
0376         verb = 0x00000200;
0377         break;
0378     case SNDRV_PCM_FORMAT_S32_LE:
0379         verb = 0x00000300;
0380         break;
0381     case SNDRV_PCM_FORMAT_FLOAT_LE:
0382         verb = 0x00001300;
0383         break;
0384     default:
0385         return 0;
0386     }
0387     verb |= substream->runtime->channels;
0388     return verb;
0389 }
0390 
0391 static int lola_set_stream_config(struct lola *chip,
0392                   struct lola_stream *str,
0393                   int channels)
0394 {
0395     int i, err;
0396     unsigned int verb, val;
0397 
0398     /* set format info for all channels
0399      * (with only one command for the first channel)
0400      */
0401     err = lola_codec_read(chip, str->nid, LOLA_VERB_SET_STREAM_FORMAT,
0402                   str->format_verb, 0, &val, NULL);
0403     if (err < 0) {
0404         dev_err(chip->card->dev, "Cannot set stream format 0x%x\n",
0405                str->format_verb);
0406         return err;
0407     }
0408 
0409     /* update stream - channel config */
0410     for (i = 0; i < channels; i++) {
0411         verb = (str->index << 6) | i;
0412         err = lola_codec_read(chip, str[i].nid,
0413                       LOLA_VERB_SET_CHANNEL_STREAMID, 0, verb,
0414                       &val, NULL);
0415         if (err < 0) {
0416             dev_err(chip->card->dev,
0417                 "Cannot set stream channel %d\n", i);
0418             return err;
0419         }
0420     }
0421     return 0;
0422 }
0423 
0424 /*
0425  * set up the SD for streaming
0426  */
0427 static int lola_setup_controller(struct lola *chip, struct lola_pcm *pcm,
0428                  struct lola_stream *str)
0429 {
0430     dma_addr_t bdl;
0431 
0432     if (str->prepared)
0433         return -EINVAL;
0434 
0435     /* set up BDL */
0436     bdl = pcm->bdl->addr + LOLA_BDL_ENTRY_SIZE * str->index;
0437     lola_dsd_write(chip, str->dsd, BDPL, (u32)bdl);
0438     lola_dsd_write(chip, str->dsd, BDPU, upper_32_bits(bdl));
0439     /* program the stream LVI (last valid index) of the BDL */
0440     lola_dsd_write(chip, str->dsd, LVI, str->frags - 1);
0441     lola_stream_clear_pending_irq(chip, str);
0442 
0443     lola_dsd_write(chip, str->dsd, CTL,
0444                LOLA_DSD_CTL_IOCE | LOLA_DSD_CTL_DEIE | LOLA_DSD_CTL_SRUN);
0445 
0446     str->prepared = 1;
0447 
0448     return lola_stream_wait_for_fifo(chip, str, true);
0449 }
0450 
0451 static int lola_pcm_prepare(struct snd_pcm_substream *substream)
0452 {
0453     struct lola *chip = snd_pcm_substream_chip(substream);
0454     struct lola_pcm *pcm = lola_get_pcm(substream);
0455     struct lola_stream *str = lola_get_stream(substream);
0456     struct snd_pcm_runtime *runtime = substream->runtime;
0457     unsigned int bufsize, period_bytes, format_verb;
0458     int i, err;
0459 
0460     mutex_lock(&chip->open_mutex);
0461     lola_stream_reset(chip, str);
0462     lola_cleanup_slave_streams(pcm, str);
0463     if (str->index + runtime->channels > pcm->num_streams) {
0464         mutex_unlock(&chip->open_mutex);
0465         return -EINVAL;
0466     }
0467     for (i = 1; i < runtime->channels; i++) {
0468         str[i].master = str;
0469         str[i].opened = 1;
0470     }
0471     mutex_unlock(&chip->open_mutex);
0472 
0473     bufsize = snd_pcm_lib_buffer_bytes(substream);
0474     period_bytes = snd_pcm_lib_period_bytes(substream);
0475     format_verb = lola_get_format_verb(substream);
0476 
0477     str->bufsize = bufsize;
0478     str->period_bytes = period_bytes;
0479     str->format_verb = format_verb;
0480 
0481     err = lola_setup_periods(chip, pcm, substream, str);
0482     if (err < 0)
0483         return err;
0484 
0485     err = lola_set_sample_rate(chip, runtime->rate);
0486     if (err < 0)
0487         return err;
0488     chip->sample_rate = runtime->rate;  /* sample rate gets locked */
0489 
0490     err = lola_set_stream_config(chip, str, runtime->channels);
0491     if (err < 0)
0492         return err;
0493 
0494     err = lola_setup_controller(chip, pcm, str);
0495     if (err < 0) {
0496         lola_stream_reset(chip, str);
0497         return err;
0498     }
0499 
0500     return 0;
0501 }
0502 
0503 static int lola_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
0504 {
0505     struct lola *chip = snd_pcm_substream_chip(substream);
0506     struct lola_stream *str;
0507     struct snd_pcm_substream *s;
0508     unsigned int start;
0509     unsigned int tstamp;
0510     bool sync_streams;
0511 
0512     switch (cmd) {
0513     case SNDRV_PCM_TRIGGER_START:
0514     case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
0515     case SNDRV_PCM_TRIGGER_RESUME:
0516         start = 1;
0517         break;
0518     case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
0519     case SNDRV_PCM_TRIGGER_SUSPEND:
0520     case SNDRV_PCM_TRIGGER_STOP:
0521         start = 0;
0522         break;
0523     default:
0524         return -EINVAL;
0525     }
0526 
0527     /*
0528      * sample correct synchronization is only needed starting several
0529      * streams. On stop or if only one stream do as quick as possible
0530      */
0531     sync_streams = (start && snd_pcm_stream_linked(substream));
0532     tstamp = lola_get_tstamp(chip, !sync_streams);
0533     spin_lock(&chip->reg_lock);
0534     snd_pcm_group_for_each_entry(s, substream) {
0535         if (s->pcm->card != substream->pcm->card)
0536             continue;
0537         str = lola_get_stream(s);
0538         if (start)
0539             lola_stream_start(chip, str, tstamp);
0540         else
0541             lola_stream_stop(chip, str, tstamp);
0542         str->running = start;
0543         str->paused = !start;
0544         snd_pcm_trigger_done(s, substream);
0545     }
0546     spin_unlock(&chip->reg_lock);
0547     return 0;
0548 }
0549 
0550 static snd_pcm_uframes_t lola_pcm_pointer(struct snd_pcm_substream *substream)
0551 {
0552     struct lola *chip = snd_pcm_substream_chip(substream);
0553     struct lola_stream *str = lola_get_stream(substream);
0554     unsigned int pos = lola_dsd_read(chip, str->dsd, LPIB);
0555 
0556     if (pos >= str->bufsize)
0557         pos = 0;
0558     return bytes_to_frames(substream->runtime, pos);
0559 }
0560 
0561 void lola_pcm_update(struct lola *chip, struct lola_pcm *pcm, unsigned int bits)
0562 {
0563     int i;
0564     u8 num_streams = min_t(u8, pcm->num_streams, ARRAY_SIZE(pcm->streams));
0565 
0566     for (i = 0; bits && i < num_streams; i++) {
0567         if (bits & (1 << i)) {
0568             struct lola_stream *str = &pcm->streams[i];
0569             if (str->substream && str->running)
0570                 snd_pcm_period_elapsed(str->substream);
0571             bits &= ~(1 << i);
0572         }
0573     }
0574 }
0575 
0576 static const struct snd_pcm_ops lola_pcm_ops = {
0577     .open = lola_pcm_open,
0578     .close = lola_pcm_close,
0579     .hw_params = lola_pcm_hw_params,
0580     .hw_free = lola_pcm_hw_free,
0581     .prepare = lola_pcm_prepare,
0582     .trigger = lola_pcm_trigger,
0583     .pointer = lola_pcm_pointer,
0584 };
0585 
0586 int lola_create_pcm(struct lola *chip)
0587 {
0588     struct snd_pcm *pcm;
0589     int i, err;
0590 
0591     for (i = 0; i < 2; i++) {
0592         chip->pcm[i].bdl =
0593             snd_devm_alloc_pages(&chip->pci->dev, SNDRV_DMA_TYPE_DEV,
0594                          PAGE_SIZE);
0595         if (!chip->pcm[i].bdl)
0596             return -ENOMEM;
0597     }
0598 
0599     err = snd_pcm_new(chip->card, "Digigram Lola", 0,
0600               chip->pcm[SNDRV_PCM_STREAM_PLAYBACK].num_streams,
0601               chip->pcm[SNDRV_PCM_STREAM_CAPTURE].num_streams,
0602               &pcm);
0603     if (err < 0)
0604         return err;
0605     strscpy(pcm->name, "Digigram Lola", sizeof(pcm->name));
0606     pcm->private_data = chip;
0607     for (i = 0; i < 2; i++) {
0608         if (chip->pcm[i].num_streams)
0609             snd_pcm_set_ops(pcm, i, &lola_pcm_ops);
0610     }
0611     /* buffer pre-allocation */
0612     snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
0613                        &chip->pci->dev,
0614                        1024 * 64, 32 * 1024 * 1024);
0615     return 0;
0616 }
0617 
0618 /*
0619  */
0620 
0621 static int lola_init_stream(struct lola *chip, struct lola_stream *str,
0622                 int idx, int nid, int dir)
0623 {
0624     unsigned int val;
0625     int err;
0626 
0627     str->nid = nid;
0628     str->index = idx;
0629     str->dsd = idx;
0630     if (dir == PLAY)
0631         str->dsd += MAX_STREAM_IN_COUNT;
0632     err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
0633     if (err < 0) {
0634         dev_err(chip->card->dev, "Can't read wcaps for 0x%x\n", nid);
0635         return err;
0636     }
0637     if (dir == PLAY) {
0638         /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1) */
0639         if ((val & 0x00f00dff) != 0x00000010) {
0640             dev_err(chip->card->dev,
0641                 "Invalid wcaps 0x%x for 0x%x\n",
0642                    val, nid);
0643             return -EINVAL;
0644         }
0645     } else {
0646         /* test TYPE and bits 0..11 (no test bit9 : Digital = 0/1)
0647          * (bug : ignore bit8: Conn list = 0/1)
0648          */
0649         if ((val & 0x00f00cff) != 0x00100010) {
0650             dev_err(chip->card->dev,
0651                 "Invalid wcaps 0x%x for 0x%x\n",
0652                    val, nid);
0653             return -EINVAL;
0654         }
0655         /* test bit9:DIGITAL and bit12:SRC_PRESENT*/
0656         if ((val & 0x00001200) == 0x00001200)
0657             chip->input_src_caps_mask |= (1 << idx);
0658     }
0659 
0660     err = lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
0661     if (err < 0) {
0662         dev_err(chip->card->dev, "Can't read FORMATS 0x%x\n", nid);
0663         return err;
0664     }
0665     val &= 3;
0666     if (val == 3)
0667         str->can_float = true;
0668     if (!(val & 1)) {
0669         dev_err(chip->card->dev,
0670             "Invalid formats 0x%x for 0x%x", val, nid);
0671         return -EINVAL;
0672     }
0673     return 0;
0674 }
0675 
0676 int lola_init_pcm(struct lola *chip, int dir, int *nidp)
0677 {
0678     struct lola_pcm *pcm = &chip->pcm[dir];
0679     int i, nid, err;
0680 
0681     nid = *nidp;
0682     for (i = 0; i < pcm->num_streams; i++, nid++) {
0683         err = lola_init_stream(chip, &pcm->streams[i], i, nid, dir);
0684         if (err < 0)
0685             return err;
0686     }
0687     *nidp = nid;
0688     return 0;
0689 }