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 315f712b2bSDaniel Mack dma = snd_soc_dai_get_dma_data(rtd->dai->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 98f11a96d5SLiam Girdwood if (dai->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 105f11a96d5SLiam Girdwood if (dai->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 115f11a96d5SLiam Girdwood struct snd_soc_platform pxa2xx_soc_platform = { 116f11a96d5SLiam Girdwood .name = "pxa2xx-audio", 117f11a96d5SLiam Girdwood .pcm_ops = &pxa2xx_pcm_ops, 1188a33de9eSDmitry Baryshkov .pcm_new = pxa2xx_soc_pcm_new, 119f11a96d5SLiam Girdwood .pcm_free = pxa2xx_pcm_free_dma_buffers, 120f11a96d5SLiam Girdwood }; 121f11a96d5SLiam Girdwood EXPORT_SYMBOL_GPL(pxa2xx_soc_platform); 122f11a96d5SLiam Girdwood 123c9b3a40fSTakashi Iwai static int __init pxa2xx_soc_platform_init(void) 124958e792cSMark Brown { 125958e792cSMark Brown return snd_soc_register_platform(&pxa2xx_soc_platform); 126958e792cSMark Brown } 127958e792cSMark Brown module_init(pxa2xx_soc_platform_init); 128958e792cSMark Brown 129958e792cSMark Brown static void __exit pxa2xx_soc_platform_exit(void) 130958e792cSMark Brown { 131958e792cSMark Brown snd_soc_unregister_platform(&pxa2xx_soc_platform); 132958e792cSMark Brown } 133958e792cSMark Brown module_exit(pxa2xx_soc_platform_exit); 134958e792cSMark Brown 135f11a96d5SLiam Girdwood MODULE_AUTHOR("Nicolas Pitre"); 136f11a96d5SLiam Girdwood MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module"); 137f11a96d5SLiam Girdwood MODULE_LICENSE("GPL"); 138