soc: codecs: rt5639: Implement i2c shutdown
[linux-2.6.git] / sound / soc / tegra / tegra_pcm.c
index 9beb921..4f19bd4 100644 (file)
@@ -2,7 +2,7 @@
  * tegra_pcm.c - Tegra PCM driver
  *
  * Author: Stephen Warren <swarren@nvidia.com>
- * Copyright (C) 2010 - NVIDIA, Inc.
+ * Copyright (C) 2010-2012 - NVIDIA, Inc.
  *
  * Based on code copyright/by:
  *
@@ -29,6 +29,7 @@
  *
  */
 
+#include <asm/mach-types.h>
 #include <linux/module.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
@@ -47,12 +48,15 @@ static const struct snd_pcm_hardware tegra_pcm_hardware = {
                                  SNDRV_PCM_INFO_PAUSE |
                                  SNDRV_PCM_INFO_RESUME |
                                  SNDRV_PCM_INFO_INTERLEAVED,
-       .formats                = SNDRV_PCM_FMTBIT_S16_LE,
+       .formats                = SNDRV_PCM_FMTBIT_S8 |
+                                 SNDRV_PCM_FMTBIT_S16_LE |
+                                 SNDRV_PCM_FMTBIT_S24_LE |
+                                 SNDRV_PCM_FMTBIT_S32_LE,
        .channels_min           = 1,
        .channels_max           = 2,
        .period_bytes_min       = 128,
-       .period_bytes_max       = PAGE_SIZE,
-       .periods_min            = 2,
+       .period_bytes_max       = PAGE_SIZE * 2,
+       .periods_min            = 1,
        .periods_max            = 8,
        .buffer_bytes_max       = PAGE_SIZE * 8,
        .fifo_size              = 4,
@@ -69,7 +73,11 @@ static void tegra_pcm_queue_dma(struct tegra_runtime_data *prtd)
        if (++prtd->dma_req_idx >= prtd->dma_req_count)
                prtd->dma_req_idx -= prtd->dma_req_count;
 
-       addr = buf->addr + prtd->dma_pos;
+       if (prtd->avp_dma_addr)
+               addr = prtd->avp_dma_addr + prtd->dma_pos;
+       else
+               addr = buf->addr + prtd->dma_pos;
+
        prtd->dma_pos += dma_req->size;
        if (prtd->dma_pos >= prtd->dma_pos_end)
                prtd->dma_pos = 0;
@@ -116,6 +124,10 @@ static void setup_dma_tx_request(struct tegra_dma_req *req,
        req->source_wrap = 0;
        req->dest_bus_width = dmap->width;
        req->req_sel = dmap->req_sel;
+       req->use_smmu = false;
+#if TEGRA30_USE_SMMU
+       req->use_smmu = true;
+#endif
 }
 
 static void setup_dma_rx_request(struct tegra_dma_req *req,
@@ -129,6 +141,10 @@ static void setup_dma_rx_request(struct tegra_dma_req *req,
        req->source_wrap = dmap->wrap;
        req->dest_bus_width = 32;
        req->req_sel = dmap->req_sel;
+       req->use_smmu = false;
+#if TEGRA30_USE_SMMU
+       req->use_smmu = true;
+#endif
 }
 
 int tegra_pcm_allocate(struct snd_pcm_substream *substream,
@@ -256,15 +272,30 @@ int tegra_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct tegra_runtime_data *prtd = runtime->private_data;
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct tegra_pcm_dma_params * dmap;
        unsigned long flags;
        int i;
 
+       dmap = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+       if (!dmap)
+               return 0;
+
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
                prtd->dma_pos = 0;
                prtd->dma_pos_end = frames_to_bytes(runtime, runtime->periods * runtime->period_size);
                prtd->period_index = 0;
                prtd->dma_req_idx = 0;
+               if (prtd->disable_intr) {
+                       prtd->dma_req_count = 1;
+                       prtd->dma_req[0].complete = NULL;
+               } else if (!prtd->dma_req[0].complete) {
+                       prtd->dma_req[0].complete = dma_complete_callback;
+                       prtd->dma_req_count =
+                               (MAX_DMA_REQ_COUNT <= runtime->periods) ?
+                               MAX_DMA_REQ_COUNT : runtime->periods;
+               }
                /* Fall-through */
        case SNDRV_PCM_TRIGGER_RESUME:
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -282,8 +313,9 @@ int tegra_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
                spin_unlock_irqrestore(&prtd->lock, flags);
                tegra_dma_cancel(prtd->dma_chan);
                for (i = 0; i < prtd->dma_req_count; i++) {
-                       if (prtd->dma_req[i].status ==
-                               -TEGRA_DMA_REQ_ERROR_ABORTED)
+                       if (prtd->dma_req[i].complete &&
+                               (prtd->dma_req[i].status ==
+                                -TEGRA_DMA_REQ_ERROR_ABORTED))
                                prtd->dma_req[i].complete(&prtd->dma_req[i]);
                }
                break;
@@ -334,15 +366,33 @@ static int tegra_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
 {
        struct snd_pcm_substream *substream = pcm->streams[stream].substream;
        struct snd_dma_buffer *buf = &substream->dma_buffer;
-
+#if TEGRA30_USE_SMMU
+       unsigned char *vaddr;
+       phys_addr_t paddr;
+       struct tegra_smmu_data *ptsd;
+
+       ptsd = kzalloc(sizeof(struct tegra_smmu_data), GFP_KERNEL);
+       ptsd->pcm_nvmap_client = nvmap_create_client(nvmap_dev, "Audio_SMMU");
+       ptsd->pcm_nvmap_handle = nvmap_alloc(ptsd->pcm_nvmap_client,
+                                size,
+                                32,
+                                NVMAP_HANDLE_WRITE_COMBINE,
+                                NVMAP_HEAP_IOVMM);
+
+       vaddr = (unsigned char *) nvmap_mmap(ptsd->pcm_nvmap_handle);
+       paddr = nvmap_pin(ptsd->pcm_nvmap_client, ptsd->pcm_nvmap_handle);
+       buf->area = vaddr;
+       buf->addr = paddr;
+       buf->private_data = ptsd;
+#else
        buf->area = dma_alloc_writecombine(pcm->card->dev, size,
                                                &buf->addr, GFP_KERNEL);
        if (!buf->area)
                return -ENOMEM;
-
+       buf->private_data = NULL;
+#endif
        buf->dev.type = SNDRV_DMA_TYPE_DEV;
        buf->dev.dev = pcm->card->dev;
-       buf->private_data = NULL;
        buf->bytes = size;
 
        return 0;
@@ -352,6 +402,9 @@ void tegra_pcm_deallocate_dma_buffer(struct snd_pcm *pcm, int stream)
 {
        struct snd_pcm_substream *substream;
        struct snd_dma_buffer *buf;
+#if TEGRA30_USE_SMMU
+       struct tegra_smmu_data *ptsd;
+#endif
 
        substream = pcm->streams[stream].substream;
        if (!substream)
@@ -361,8 +414,19 @@ void tegra_pcm_deallocate_dma_buffer(struct snd_pcm *pcm, int stream)
        if (!buf->area)
                return;
 
+#if TEGRA30_USE_SMMU
+       if (!buf->private_data)
+               return;
+       ptsd = (struct tegra_smmu_data *)buf->private_data;
+       nvmap_unpin(ptsd->pcm_nvmap_client, ptsd->pcm_nvmap_handle);
+       nvmap_munmap(ptsd->pcm_nvmap_handle, buf->area);
+       nvmap_free(ptsd->pcm_nvmap_client, ptsd->pcm_nvmap_handle);
+       kfree(ptsd);
+       buf->private_data = NULL;
+#else
        dma_free_writecombine(pcm->card->dev, buf->bytes,
                                buf->area, buf->addr);
+#endif
        buf->area = NULL;
 }
 
@@ -415,10 +479,17 @@ void tegra_pcm_free(struct snd_pcm *pcm)
        tegra_pcm_deallocate_dma_buffer(pcm, SNDRV_PCM_STREAM_PLAYBACK);
 }
 
+static int tegra_pcm_probe(struct snd_soc_platform *platform)
+{
+       platform->dapm.idle_bias_off = 1;
+       return 0;
+}
+
 static struct snd_soc_platform_driver tegra_pcm_platform = {
        .ops            = &tegra_pcm_ops,
        .pcm_new        = tegra_pcm_new,
        .pcm_free       = tegra_pcm_free,
+       .probe          = tegra_pcm_probe,
 };
 
 static int __devinit tegra_pcm_platform_probe(struct platform_device *pdev)