ALSA: snd-atmel-ac97c: set correct size for buffer hardware parameter
[safe/jmp/linux-2.6] / sound / atmel / ac97c.c
index dd72e00..c9bc345 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Driver for the Atmel AC97C controller
+ * Driver for Atmel AC97C
  *
  * Copyright (C) 2005-2009 Atmel Corporation
  *
@@ -10,6 +10,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/bitmap.h>
+#include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
 #include <linux/init.h>
@@ -150,10 +151,10 @@ static struct snd_pcm_hardware atmel_ac97c_hw = {
        .rate_max               = 48000,
        .channels_min           = 1,
        .channels_max           = 2,
-       .buffer_bytes_max       = 64 * 4096,
+       .buffer_bytes_max       = 2 * 2 * 64 * 2048,
        .period_bytes_min       = 4096,
        .period_bytes_max       = 4096,
-       .periods_min            = 4,
+       .periods_min            = 6,
        .periods_max            = 64,
 };
 
@@ -297,9 +298,11 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
-       unsigned long word = 0;
+       unsigned long word = ac97c_readl(chip, OCA);
        int retval;
 
+       word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
+
        /* assign channels to AC97C channel A */
        switch (runtime->channels) {
        case 1:
@@ -312,7 +315,6 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
        default:
                /* TODO: support more than two channels */
                return -EINVAL;
-               break;
        }
        ac97c_writel(chip, OCA, word);
 
@@ -324,9 +326,13 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
                word |= AC97C_CMR_CEM_LITTLE;
                break;
        case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
-       default:
                word &= ~(AC97C_CMR_CEM_LITTLE);
                break;
+       default:
+               word = ac97c_readl(chip, OCA);
+               word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
+               ac97c_writel(chip, OCA, word);
+               return -EINVAL;
        }
 
        ac97c_writel(chip, CAMR, word);
@@ -359,9 +365,11 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
-       unsigned long word = 0;
+       unsigned long word = ac97c_readl(chip, ICA);
        int retval;
 
+       word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
+
        /* assign channels to AC97C channel A */
        switch (runtime->channels) {
        case 1:
@@ -374,7 +382,6 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
        default:
                /* TODO: support more than two channels */
                return -EINVAL;
-               break;
        }
        ac97c_writel(chip, ICA, word);
 
@@ -386,9 +393,13 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
                word |= AC97C_CMR_CEM_LITTLE;
                break;
        case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
-       default:
                word &= ~(AC97C_CMR_CEM_LITTLE);
                break;
+       default:
+               word = ac97c_readl(chip, ICA);
+               word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
+               ac97c_writel(chip, ICA, word);
+               return -EINVAL;
        }
 
        ac97c_writel(chip, CAMR, word);