ALSA: lola - Allow granularity changes
authorTakashi Iwai <tiwai@suse.de>
Tue, 3 May 2011 14:51:56 +0000 (16:51 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 3 May 2011 14:51:56 +0000 (16:51 +0200)
Add some sanity checks.
Change PCM parameters appropriately per granularity.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/lola/lola.c
sound/pci/lola/lola.h
sound/pci/lola/lola_pcm.c

index 3d2516b11f224a16f6a1a026102c26222b6e5777..8ee22bee10c97a706fa2274c2bbe5104868310a4 100644 (file)
@@ -587,14 +587,31 @@ static int __devinit lola_create(struct snd_card *card, struct pci_dev *pci,
        chip->pci = pci;
        chip->irq = -1;
 
-       chip->sample_rate_min = sample_rate_min[dev];
        chip->granularity = granularity[dev];
-       /* FIXME */
-       if (chip->granularity != LOLA_GRANULARITY_MAX) {
+       switch (chip->granularity) {
+       case 8:
+               chip->sample_rate_max = 48000;
+               break;
+       case 16:
+               chip->sample_rate_max = 96000;
+               break;
+       case 32:
+               chip->sample_rate_max = 192000;
+               break;
+       default:
                snd_printk(KERN_WARNING SFX
-                          "Only %d granularity is supported for now\n",
-                          LOLA_GRANULARITY_MAX);
+                          "Invalid granularity %d, reset to %d\n",
+                          chip->granularity, LOLA_GRANULARITY_MAX);
                chip->granularity = LOLA_GRANULARITY_MAX;
+               chip->sample_rate_max = 192000;
+               break;
+       }
+       chip->sample_rate_min = sample_rate_min[dev];
+       if (chip->sample_rate_min > chip->sample_rate_max) {
+               snd_printk(KERN_WARNING SFX
+                          "Invalid sample_rate_min %d, reset to 16000\n",
+                          chip->sample_rate_min);
+               chip->sample_rate_min = 16000;
        }
 
        err = pci_request_regions(pci, DRVNAME);
index 839779dc32f99e6e6c422ba046b4fa80850a1518..bc8110ff6b467fe320a5a777669ecea2a413e852 100644 (file)
@@ -367,6 +367,7 @@ struct lola {
        /* parameters */
        unsigned int granularity;
        unsigned int sample_rate_min;
+       unsigned int sample_rate_max;
 
        /* flags */
        unsigned int running :1;
index dc2e811dcb3c3a7fd826fe2382a37df05568afa7..4bb5b5bd6371f78fda1adb900d9e4e764643d0b3 100644 (file)
@@ -178,14 +178,16 @@ static int lola_pcm_open(struct snd_pcm_substream *substream)
        str->opened = 1;
        runtime->hw = lola_pcm_hw;
        runtime->hw.channels_max = pcm->num_streams - str->index;
+       runtime->hw.rate_min = chip->sample_rate_min;
+       runtime->hw.rate_max = chip->sample_rate_max;
        snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
        /* period size = multiple of chip->granularity (8, 16 or 32 frames)
         * use LOLA_GRANULARITY_MAX = 32 for instance
         */
        snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
-                                  LOLA_GRANULARITY_MAX);
+                                  chip->granularity);
        snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
-                                  LOLA_GRANULARITY_MAX);
+                                  chip->granularity);
        mutex_unlock(&chip->open_mutex);
        return 0;
 }