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> 14f11a96d5SLiam Girdwood 15f11a96d5SLiam Girdwood #include <sound/core.h> 16f11a96d5SLiam Girdwood #include <sound/soc.h> 17a6d77317SDmitry Baryshkov #include <sound/pxa2xx-lib.h> 18f11a96d5SLiam Girdwood 19f11a96d5SLiam Girdwood #include "pxa2xx-pcm.h" 20a6d77317SDmitry Baryshkov #include "../../arm/pxa2xx-pcm.h" 21f11a96d5SLiam Girdwood 22f11a96d5SLiam Girdwood static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream, 23f11a96d5SLiam Girdwood struct snd_pcm_hw_params *params) 24f11a96d5SLiam Girdwood { 25f11a96d5SLiam Girdwood struct snd_pcm_runtime *runtime = substream->runtime; 26f11a96d5SLiam Girdwood struct pxa2xx_runtime_data *prtd = runtime->private_data; 27f11a96d5SLiam Girdwood struct snd_soc_pcm_runtime *rtd = substream->private_data; 285f712b2bSDaniel Mack struct pxa2xx_pcm_dma_params *dma; 29f11a96d5SLiam Girdwood int ret; 30f11a96d5SLiam Girdwood 31f0fba2adSLiam Girdwood dma = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 325f712b2bSDaniel Mack 33a8f5d0a5SAndrew Johnson /* return if this is a bufferless transfer e.g. 34a8f5d0a5SAndrew Johnson * codec <--> BT codec or GSM modem -- lg FIXME */ 35a8f5d0a5SAndrew Johnson if (!dma) 36a8f5d0a5SAndrew Johnson return 0; 37a8f5d0a5SAndrew Johnson 38f11a96d5SLiam Girdwood /* this may get called several times by oss emulation 39f11a96d5SLiam Girdwood * with different params */ 40f11a96d5SLiam Girdwood if (prtd->params == NULL) { 41f11a96d5SLiam Girdwood prtd->params = dma; 42f11a96d5SLiam Girdwood ret = pxa_request_dma(prtd->params->name, DMA_PRIO_LOW, 43f11a96d5SLiam Girdwood pxa2xx_pcm_dma_irq, substream); 44f11a96d5SLiam Girdwood if (ret < 0) 45f11a96d5SLiam Girdwood return ret; 46f11a96d5SLiam Girdwood prtd->dma_ch = ret; 47f11a96d5SLiam Girdwood } else if (prtd->params != dma) { 48f11a96d5SLiam Girdwood pxa_free_dma(prtd->dma_ch); 49f11a96d5SLiam Girdwood prtd->params = dma; 50f11a96d5SLiam Girdwood ret = pxa_request_dma(prtd->params->name, DMA_PRIO_LOW, 51f11a96d5SLiam Girdwood pxa2xx_pcm_dma_irq, substream); 52f11a96d5SLiam Girdwood if (ret < 0) 53f11a96d5SLiam Girdwood return ret; 54f11a96d5SLiam Girdwood prtd->dma_ch = ret; 55f11a96d5SLiam Girdwood } 56f11a96d5SLiam Girdwood 57a6d77317SDmitry Baryshkov return __pxa2xx_pcm_hw_params(substream, params); 58f11a96d5SLiam Girdwood } 59f11a96d5SLiam Girdwood 60f11a96d5SLiam Girdwood static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream) 61f11a96d5SLiam Girdwood { 62f11a96d5SLiam Girdwood struct pxa2xx_runtime_data *prtd = substream->runtime->private_data; 63f11a96d5SLiam Girdwood 64a6d77317SDmitry Baryshkov __pxa2xx_pcm_hw_free(substream); 65f11a96d5SLiam Girdwood 669bef6489SStephen Ware if (prtd->dma_ch >= 0) { 67f11a96d5SLiam Girdwood pxa_free_dma(prtd->dma_ch); 689bef6489SStephen Ware prtd->dma_ch = -1; 69f11a96d5SLiam Girdwood } 70f11a96d5SLiam Girdwood 71f11a96d5SLiam Girdwood return 0; 72f11a96d5SLiam Girdwood } 73f11a96d5SLiam Girdwood 740e734ad5SMark Brown static struct snd_pcm_ops pxa2xx_pcm_ops = { 75a6d77317SDmitry Baryshkov .open = __pxa2xx_pcm_open, 76a6d77317SDmitry Baryshkov .close = __pxa2xx_pcm_close, 77f11a96d5SLiam Girdwood .ioctl = snd_pcm_lib_ioctl, 78f11a96d5SLiam Girdwood .hw_params = pxa2xx_pcm_hw_params, 79f11a96d5SLiam Girdwood .hw_free = pxa2xx_pcm_hw_free, 80a6d77317SDmitry Baryshkov .prepare = __pxa2xx_pcm_prepare, 81f11a96d5SLiam Girdwood .trigger = pxa2xx_pcm_trigger, 82f11a96d5SLiam Girdwood .pointer = pxa2xx_pcm_pointer, 83f11a96d5SLiam Girdwood .mmap = pxa2xx_pcm_mmap, 84f11a96d5SLiam Girdwood }; 85f11a96d5SLiam Girdwood 86284901a9SYang Hongyang static u64 pxa2xx_pcm_dmamask = DMA_BIT_MASK(32); 87f11a96d5SLiam Girdwood 888a33de9eSDmitry Baryshkov static int pxa2xx_soc_pcm_new(struct snd_card *card, struct snd_soc_dai *dai, 89f11a96d5SLiam Girdwood struct snd_pcm *pcm) 90f11a96d5SLiam Girdwood { 91f11a96d5SLiam Girdwood int ret = 0; 92f11a96d5SLiam Girdwood 93f11a96d5SLiam Girdwood if (!card->dev->dma_mask) 94f11a96d5SLiam Girdwood card->dev->dma_mask = &pxa2xx_pcm_dmamask; 95f11a96d5SLiam Girdwood if (!card->dev->coherent_dma_mask) 96284901a9SYang Hongyang card->dev->coherent_dma_mask = DMA_BIT_MASK(32); 97f11a96d5SLiam Girdwood 98f0fba2adSLiam Girdwood if (dai->driver->playback.channels_min) { 99f11a96d5SLiam Girdwood ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 100f11a96d5SLiam Girdwood SNDRV_PCM_STREAM_PLAYBACK); 101f11a96d5SLiam Girdwood if (ret) 102f11a96d5SLiam Girdwood goto out; 103f11a96d5SLiam Girdwood } 104f11a96d5SLiam Girdwood 105f0fba2adSLiam Girdwood if (dai->driver->capture.channels_min) { 106f11a96d5SLiam Girdwood ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 107f11a96d5SLiam Girdwood SNDRV_PCM_STREAM_CAPTURE); 108f11a96d5SLiam Girdwood if (ret) 109f11a96d5SLiam Girdwood goto out; 110f11a96d5SLiam Girdwood } 111f11a96d5SLiam Girdwood out: 112f11a96d5SLiam Girdwood return ret; 113f11a96d5SLiam Girdwood } 114f11a96d5SLiam Girdwood 115f0fba2adSLiam Girdwood static struct snd_soc_platform_driver pxa2xx_soc_platform = { 116f0fba2adSLiam Girdwood .ops = &pxa2xx_pcm_ops, 1178a33de9eSDmitry Baryshkov .pcm_new = pxa2xx_soc_pcm_new, 118f11a96d5SLiam Girdwood .pcm_free = pxa2xx_pcm_free_dma_buffers, 119f11a96d5SLiam Girdwood }; 120f11a96d5SLiam Girdwood 121f0fba2adSLiam Girdwood static int __devinit pxa2xx_soc_platform_probe(struct platform_device *pdev) 122958e792cSMark Brown { 123f0fba2adSLiam Girdwood return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform); 124958e792cSMark Brown } 125958e792cSMark Brown 126f0fba2adSLiam Girdwood static int __devexit pxa2xx_soc_platform_remove(struct platform_device *pdev) 127958e792cSMark Brown { 128f0fba2adSLiam Girdwood snd_soc_unregister_platform(&pdev->dev); 129f0fba2adSLiam Girdwood return 0; 130958e792cSMark Brown } 131f0fba2adSLiam Girdwood 132f0fba2adSLiam Girdwood static struct platform_driver pxa_pcm_driver = { 133f0fba2adSLiam Girdwood .driver = { 134f0fba2adSLiam Girdwood .name = "pxa-pcm-audio", 135f0fba2adSLiam Girdwood .owner = THIS_MODULE, 136f0fba2adSLiam Girdwood }, 137f0fba2adSLiam Girdwood 138f0fba2adSLiam Girdwood .probe = pxa2xx_soc_platform_probe, 139f0fba2adSLiam Girdwood .remove = __devexit_p(pxa2xx_soc_platform_remove), 140f0fba2adSLiam Girdwood }; 141f0fba2adSLiam Girdwood 142f0fba2adSLiam Girdwood static int __init snd_pxa_pcm_init(void) 143f0fba2adSLiam Girdwood { 144f0fba2adSLiam Girdwood return platform_driver_register(&pxa_pcm_driver); 145f0fba2adSLiam Girdwood } 146f0fba2adSLiam Girdwood module_init(snd_pxa_pcm_init); 147f0fba2adSLiam Girdwood 148f0fba2adSLiam Girdwood static void __exit snd_pxa_pcm_exit(void) 149f0fba2adSLiam Girdwood { 150f0fba2adSLiam Girdwood platform_driver_unregister(&pxa_pcm_driver); 151f0fba2adSLiam Girdwood } 152f0fba2adSLiam Girdwood module_exit(snd_pxa_pcm_exit); 153958e792cSMark Brown 154f11a96d5SLiam Girdwood MODULE_AUTHOR("Nicolas Pitre"); 155f11a96d5SLiam Girdwood MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module"); 156f11a96d5SLiam Girdwood MODULE_LICENSE("GPL"); 157