1 /* 2 * linux/sound/arm/pxa2xx-pcm.c -- ALSA PCM interface for the Intel PXA2xx chip 3 * 4 * Author: Nicolas Pitre 5 * Created: Nov 30, 2004 6 * Copyright: (C) 2004 MontaVista Software, Inc. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 */ 12 13 #include <linux/dma-mapping.h> 14 #include <linux/module.h> 15 #include <linux/dmaengine.h> 16 #include <linux/of.h> 17 18 #include <sound/core.h> 19 #include <sound/soc.h> 20 #include <sound/pxa2xx-lib.h> 21 #include <sound/dmaengine_pcm.h> 22 23 static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream, 24 struct snd_pcm_hw_params *params) 25 { 26 struct snd_soc_pcm_runtime *rtd = substream->private_data; 27 struct snd_dmaengine_dai_dma_data *dma; 28 29 dma = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); 30 31 /* return if this is a bufferless transfer e.g. 32 * codec <--> BT codec or GSM modem -- lg FIXME */ 33 if (!dma) 34 return 0; 35 36 return __pxa2xx_pcm_hw_params(substream, params); 37 } 38 39 static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream) 40 { 41 __pxa2xx_pcm_hw_free(substream); 42 43 return 0; 44 } 45 46 static const struct snd_pcm_ops pxa2xx_pcm_ops = { 47 .open = __pxa2xx_pcm_open, 48 .close = __pxa2xx_pcm_close, 49 .ioctl = snd_pcm_lib_ioctl, 50 .hw_params = pxa2xx_pcm_hw_params, 51 .hw_free = pxa2xx_pcm_hw_free, 52 .prepare = __pxa2xx_pcm_prepare, 53 .trigger = pxa2xx_pcm_trigger, 54 .pointer = pxa2xx_pcm_pointer, 55 .mmap = pxa2xx_pcm_mmap, 56 }; 57 58 static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd) 59 { 60 struct snd_card *card = rtd->card->snd_card; 61 struct snd_pcm *pcm = rtd->pcm; 62 int ret; 63 64 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); 65 if (ret) 66 return ret; 67 68 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 69 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 70 SNDRV_PCM_STREAM_PLAYBACK); 71 if (ret) 72 goto out; 73 } 74 75 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { 76 ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, 77 SNDRV_PCM_STREAM_CAPTURE); 78 if (ret) 79 goto out; 80 } 81 out: 82 return ret; 83 } 84 85 static const struct snd_soc_component_driver pxa2xx_soc_platform = { 86 .ops = &pxa2xx_pcm_ops, 87 .pcm_new = pxa2xx_soc_pcm_new, 88 .pcm_free = pxa2xx_pcm_free_dma_buffers, 89 }; 90 91 static int pxa2xx_soc_platform_probe(struct platform_device *pdev) 92 { 93 return devm_snd_soc_register_component(&pdev->dev, &pxa2xx_soc_platform, 94 NULL, 0); 95 } 96 97 #ifdef CONFIG_OF 98 static const struct of_device_id snd_soc_pxa_audio_match[] = { 99 { .compatible = "mrvl,pxa-pcm-audio" }, 100 { } 101 }; 102 MODULE_DEVICE_TABLE(of, snd_soc_pxa_audio_match); 103 #endif 104 105 static struct platform_driver pxa_pcm_driver = { 106 .driver = { 107 .name = "pxa-pcm-audio", 108 .of_match_table = of_match_ptr(snd_soc_pxa_audio_match), 109 }, 110 111 .probe = pxa2xx_soc_platform_probe, 112 }; 113 114 module_platform_driver(pxa_pcm_driver); 115 116 MODULE_AUTHOR("Nicolas Pitre"); 117 MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module"); 118 MODULE_LICENSE("GPL"); 119 MODULE_ALIAS("platform:pxa-pcm-audio"); 120