soc: codecs: rt5639: Implement i2c shutdown
[linux-2.6.git] / sound / soc / tegra / tegra_pcm.c
index f471faf..4f19bd4 100644 (file)
@@ -48,7 +48,10 @@ 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,
@@ -70,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;
@@ -117,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,
@@ -130,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,
@@ -351,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;
@@ -369,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)
@@ -378,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;
 }
 
@@ -388,16 +435,15 @@ static u64 tegra_dma_mask = DMA_BIT_MASK(32);
 int tegra_pcm_dma_allocate(struct snd_soc_pcm_runtime *rtd, size_t size)
 {
        struct snd_card *card = rtd->card->snd_card;
-       struct snd_soc_dai *dai = rtd->cpu_dai;
        struct snd_pcm *pcm = rtd->pcm;
        int ret = 0;
 
        if (!card->dev->dma_mask)
                card->dev->dma_mask = &tegra_dma_mask;
        if (!card->dev->coherent_dma_mask)
-               card->dev->coherent_dma_mask = 0xffffffff;
+               card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
 
-       if (dai->driver->playback.channels_min) {
+       if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
                ret = tegra_pcm_preallocate_dma_buffer(pcm,
                                                SNDRV_PCM_STREAM_PLAYBACK,
                                                size);
@@ -405,7 +451,7 @@ int tegra_pcm_dma_allocate(struct snd_soc_pcm_runtime *rtd, size_t size)
                        goto err;
        }
 
-       if (dai->driver->capture.channels_min) {
+       if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
                ret = tegra_pcm_preallocate_dma_buffer(pcm,
                                                SNDRV_PCM_STREAM_CAPTURE,
                                                size);
@@ -435,13 +481,11 @@ void tegra_pcm_free(struct snd_pcm *pcm)
 
 static int tegra_pcm_probe(struct snd_soc_platform *platform)
 {
-       if(machine_is_kai() || machine_is_tegra_enterprise())
-               platform->dapm.idle_bias_off = 1;
-
+       platform->dapm.idle_bias_off = 1;
        return 0;
 }
 
-struct snd_soc_platform_driver tegra_pcm_platform = {
+static struct snd_soc_platform_driver tegra_pcm_platform = {
        .ops            = &tegra_pcm_ops,
        .pcm_new        = tegra_pcm_new,
        .pcm_free       = tegra_pcm_free,
@@ -467,18 +511,7 @@ static struct platform_driver tegra_pcm_driver = {
        .probe = tegra_pcm_platform_probe,
        .remove = __devexit_p(tegra_pcm_platform_remove),
 };
-
-static int __init snd_tegra_pcm_init(void)
-{
-       return platform_driver_register(&tegra_pcm_driver);
-}
-module_init(snd_tegra_pcm_init);
-
-static void __exit snd_tegra_pcm_exit(void)
-{
-       platform_driver_unregister(&tegra_pcm_driver);
-}
-module_exit(snd_tegra_pcm_exit);
+module_platform_driver(tegra_pcm_driver);
 
 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
 MODULE_DESCRIPTION("Tegra PCM ASoC driver");