1f11a96d5SLiam Girdwood /* 2f11a96d5SLiam Girdwood * linux/sound/arm/pxa2xx-pcm.c -- ALSA PCM interface for the Intel PXA2xx chip 3f11a96d5SLiam Girdwood * 4f11a96d5SLiam Girdwood * Author: Nicolas Pitre 5f11a96d5SLiam Girdwood * Created: Nov 30, 2004 6f11a96d5SLiam Girdwood * Copyright: (C) 2004 MontaVista Software, Inc. 7f11a96d5SLiam Girdwood * 8f11a96d5SLiam Girdwood * This program is free software; you can redistribute it and/or modify 9f11a96d5SLiam Girdwood * it under the terms of the GNU General Public License version 2 as 10f11a96d5SLiam Girdwood * published by the Free Software Foundation. 11f11a96d5SLiam Girdwood */ 12f11a96d5SLiam Girdwood 13f11a96d5SLiam Girdwood #include <linux/dma-mapping.h> 14da155d5bSPaul Gortmaker #include <linux/module.h> 15d65a1458SDaniel Mack #include <linux/dmaengine.h> 16c529ca4aSDaniel Mack #include <linux/of.h> 17f11a96d5SLiam Girdwood 18b4528141SArnd Bergmann #include <mach/dma.h> 19b4528141SArnd Bergmann 20f11a96d5SLiam Girdwood #include <sound/core.h> 21f11a96d5SLiam Girdwood #include <sound/soc.h> 22a6d77317SDmitry Baryshkov #include <sound/pxa2xx-lib.h> 23d65a1458SDaniel Mack #include <sound/dmaengine_pcm.h> 24f11a96d5SLiam Girdwood 25a6d77317SDmitry Baryshkov #include "../../arm/pxa2xx-pcm.h" 26f11a96d5SLiam Girdwood 27f11a96d5SLiam Girdwood static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream, 28f11a96d5SLiam Girdwood struct snd_pcm_hw_params *params) 29f11a96d5SLiam Girdwood { 30f11a96d5SLiam Girdwood struct snd_pcm_runtime *runtime = substream->runtime; 31f11a96d5SLiam Girdwood struct pxa2xx_runtime_data *prtd = runtime->private_data; 32f11a96d5SLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 33d65a1458SDaniel Mack struct snd_dmaengine_dai_dma_data *dma; 34f11a96d5SLiam Girdwood int ret; 35f11a96d5SLiam Girdwood 36f0fba2adSLiam Girdwood dma = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 375f712b2bSDaniel Mack 38a8f5d0a5SAndrew Johnson /* return if this is a bufferless transfer e.g. 39a8f5d0a5SAndrew Johnson * codec <--> BT codec or GSM modem -- lg FIXME */ 40a8f5d0a5SAndrew Johnson if (!dma) 41a8f5d0a5SAndrew Johnson return 0; 42a8f5d0a5SAndrew Johnson 43f11a96d5SLiam Girdwood /* this may get called several times by oss emulation 44f11a96d5SLiam Girdwood * with different params */ 45f11a96d5SLiam Girdwood if (prtd->params == NULL) { 46f11a96d5SLiam Girdwood prtd->params = dma; 47d65a1458SDaniel Mack ret = pxa_request_dma("name", DMA_PRIO_LOW, 48f11a96d5SLiam Girdwood pxa2xx_pcm_dma_irq, substream); 49f11a96d5SLiam Girdwood if (ret < 0) 50f11a96d5SLiam Girdwood return ret; 51f11a96d5SLiam Girdwood prtd->dma_ch = ret; 52f11a96d5SLiam Girdwood } else if (prtd->params != dma) { 53f11a96d5SLiam Girdwood pxa_free_dma(prtd->dma_ch); 54f11a96d5SLiam Girdwood prtd->params = dma; 55d65a1458SDaniel Mack ret = pxa_request_dma("name", DMA_PRIO_LOW, 56f11a96d5SLiam Girdwood pxa2xx_pcm_dma_irq, substream); 57f11a96d5SLiam Girdwood if (ret < 0) 58f11a96d5SLiam Girdwood return ret; 59f11a96d5SLiam Girdwood prtd->dma_ch = ret; 60f11a96d5SLiam Girdwood } 61f11a96d5SLiam Girdwood 62a6d77317SDmitry Baryshkov return __pxa2xx_pcm_hw_params(substream, params); 63f11a96d5SLiam Girdwood } 64f11a96d5SLiam Girdwood 65f11a96d5SLiam Girdwood static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream) 66f11a96d5SLiam Girdwood { 67f11a96d5SLiam Girdwood struct pxa2xx_runtime_data *prtd = substream->runtime->private_data; 68f11a96d5SLiam Girdwood 69a6d77317SDmitry Baryshkov __pxa2xx_pcm_hw_free(substream); 70f11a96d5SLiam Girdwood 719bef6489SStephen Ware if (prtd->dma_ch >= 0) { 72f11a96d5SLiam Girdwood pxa_free_dma(prtd->dma_ch); 739bef6489SStephen Ware prtd->dma_ch = -1; 7497c96c07SVasily Khoruzhick prtd->params = NULL; 75f11a96d5SLiam Girdwood } 76f11a96d5SLiam Girdwood 77f11a96d5SLiam Girdwood return 0; 78f11a96d5SLiam Girdwood } 79f11a96d5SLiam Girdwood 800e734ad5SMark Brown static struct snd_pcm_ops pxa2xx_pcm_ops = { 81a6d77317SDmitry Baryshkov .open = __pxa2xx_pcm_open, 82a6d77317SDmitry Baryshkov .close = __pxa2xx_pcm_close, 83f11a96d5SLiam Girdwood .ioctl = snd_pcm_lib_ioctl, 84f11a96d5SLiam Girdwood .hw_params = pxa2xx_pcm_hw_params, 85f11a96d5SLiam Girdwood .hw_free = pxa2xx_pcm_hw_free, 86a6d77317SDmitry Baryshkov .prepare = __pxa2xx_pcm_prepare, 87f11a96d5SLiam Girdwood .trigger = pxa2xx_pcm_trigger, 88f11a96d5SLiam Girdwood .pointer = pxa2xx_pcm_pointer, 89f11a96d5SLiam Girdwood .mmap = pxa2xx_pcm_mmap, 90f11a96d5SLiam Girdwood }; 91f11a96d5SLiam Girdwood 92552d1ef6SLiam Girdwood static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd) 93f11a96d5SLiam Girdwood { 94552d1ef6SLiam Girdwood struct snd_card *card = rtd->card->snd_card; 95552d1ef6SLiam Girdwood struct snd_pcm *pcm = rtd->pcm; 96c9bd5e69SRussell King int ret; 97f11a96d5SLiam Girdwood 98c9bd5e69SRussell King ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); 99c9bd5e69SRussell King if (ret) 100c9bd5e69SRussell King return ret; 101f11a96d5SLiam Girdwood 10253dea36cSDaniel Mack if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 103f11a96d5SLiam Girdwood ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 104f11a96d5SLiam Girdwood SNDRV_PCM_STREAM_PLAYBACK); 105f11a96d5SLiam Girdwood if (ret) 106f11a96d5SLiam Girdwood goto out; 107f11a96d5SLiam Girdwood } 108f11a96d5SLiam Girdwood 10953dea36cSDaniel Mack if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { 110f11a96d5SLiam Girdwood ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 111f11a96d5SLiam Girdwood SNDRV_PCM_STREAM_CAPTURE); 112f11a96d5SLiam Girdwood if (ret) 113f11a96d5SLiam Girdwood goto out; 114f11a96d5SLiam Girdwood } 115f11a96d5SLiam Girdwood out: 116f11a96d5SLiam Girdwood return ret; 117f11a96d5SLiam Girdwood } 118f11a96d5SLiam Girdwood 119f0fba2adSLiam Girdwood static struct snd_soc_platform_driver pxa2xx_soc_platform = { 120f0fba2adSLiam Girdwood .ops = &pxa2xx_pcm_ops, 1218a33de9eSDmitry Baryshkov .pcm_new = pxa2xx_soc_pcm_new, 122f11a96d5SLiam Girdwood .pcm_free = pxa2xx_pcm_free_dma_buffers, 123f11a96d5SLiam Girdwood }; 124f11a96d5SLiam Girdwood 125570f6fe1SBill Pemberton static int pxa2xx_soc_platform_probe(struct platform_device *pdev) 126958e792cSMark Brown { 127f0fba2adSLiam Girdwood return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform); 128958e792cSMark Brown } 129958e792cSMark Brown 130570f6fe1SBill Pemberton static int pxa2xx_soc_platform_remove(struct platform_device *pdev) 131958e792cSMark Brown { 132f0fba2adSLiam Girdwood snd_soc_unregister_platform(&pdev->dev); 133f0fba2adSLiam Girdwood return 0; 134958e792cSMark Brown } 135f0fba2adSLiam Girdwood 136c529ca4aSDaniel Mack #ifdef CONFIG_OF 137c529ca4aSDaniel Mack static const struct of_device_id snd_soc_pxa_audio_match[] = { 138c529ca4aSDaniel Mack { .compatible = "mrvl,pxa-pcm-audio" }, 139c529ca4aSDaniel Mack { } 140c529ca4aSDaniel Mack }; 141c529ca4aSDaniel Mack #endif 142c529ca4aSDaniel Mack 143f0fba2adSLiam Girdwood static struct platform_driver pxa_pcm_driver = { 144f0fba2adSLiam Girdwood .driver = { 145f0fba2adSLiam Girdwood .name = "pxa-pcm-audio", 146f0fba2adSLiam Girdwood .owner = THIS_MODULE, 147c529ca4aSDaniel Mack .of_match_table = of_match_ptr(snd_soc_pxa_audio_match), 148f0fba2adSLiam Girdwood }, 149f0fba2adSLiam Girdwood 150f0fba2adSLiam Girdwood .probe = pxa2xx_soc_platform_probe, 151570f6fe1SBill Pemberton .remove = pxa2xx_soc_platform_remove, 152f0fba2adSLiam Girdwood }; 153f0fba2adSLiam Girdwood 1542f702a19SAxel Lin module_platform_driver(pxa_pcm_driver); 155958e792cSMark Brown 156f11a96d5SLiam Girdwood MODULE_AUTHOR("Nicolas Pitre"); 157f11a96d5SLiam Girdwood MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module"); 158f11a96d5SLiam Girdwood MODULE_LICENSE("GPL"); 159