xref: /openbmc/linux/sound/soc/pxa/pxa2xx-pcm.c (revision e5b7d71a)
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 
18f11a96d5SLiam Girdwood #include <sound/core.h>
19f11a96d5SLiam Girdwood #include <sound/soc.h>
20a6d77317SDmitry Baryshkov #include <sound/pxa2xx-lib.h>
21d65a1458SDaniel Mack #include <sound/dmaengine_pcm.h>
22f11a96d5SLiam Girdwood 
23a6d77317SDmitry Baryshkov #include "../../arm/pxa2xx-pcm.h"
24f11a96d5SLiam Girdwood 
25f11a96d5SLiam Girdwood static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
26f11a96d5SLiam Girdwood 	struct snd_pcm_hw_params *params)
27f11a96d5SLiam Girdwood {
28f11a96d5SLiam Girdwood 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
29d65a1458SDaniel Mack 	struct snd_dmaengine_dai_dma_data *dma;
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 
38a6d77317SDmitry Baryshkov 	return __pxa2xx_pcm_hw_params(substream, params);
39f11a96d5SLiam Girdwood }
40f11a96d5SLiam Girdwood 
41f11a96d5SLiam Girdwood static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
42f11a96d5SLiam Girdwood {
43a6d77317SDmitry Baryshkov 	__pxa2xx_pcm_hw_free(substream);
44f11a96d5SLiam Girdwood 
45f11a96d5SLiam Girdwood 	return 0;
46f11a96d5SLiam Girdwood }
47f11a96d5SLiam Girdwood 
480e734ad5SMark Brown static struct snd_pcm_ops pxa2xx_pcm_ops = {
49a6d77317SDmitry Baryshkov 	.open		= __pxa2xx_pcm_open,
50a6d77317SDmitry Baryshkov 	.close		= __pxa2xx_pcm_close,
51f11a96d5SLiam Girdwood 	.ioctl		= snd_pcm_lib_ioctl,
52f11a96d5SLiam Girdwood 	.hw_params	= pxa2xx_pcm_hw_params,
53f11a96d5SLiam Girdwood 	.hw_free	= pxa2xx_pcm_hw_free,
54a6d77317SDmitry Baryshkov 	.prepare	= __pxa2xx_pcm_prepare,
55f11a96d5SLiam Girdwood 	.trigger	= pxa2xx_pcm_trigger,
56f11a96d5SLiam Girdwood 	.pointer	= pxa2xx_pcm_pointer,
57f11a96d5SLiam Girdwood 	.mmap		= pxa2xx_pcm_mmap,
58f11a96d5SLiam Girdwood };
59f11a96d5SLiam Girdwood 
60552d1ef6SLiam Girdwood static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd)
61f11a96d5SLiam Girdwood {
62552d1ef6SLiam Girdwood 	struct snd_card *card = rtd->card->snd_card;
63552d1ef6SLiam Girdwood 	struct snd_pcm *pcm = rtd->pcm;
64c9bd5e69SRussell King 	int ret;
65f11a96d5SLiam Girdwood 
66c9bd5e69SRussell King 	ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
67c9bd5e69SRussell King 	if (ret)
68c9bd5e69SRussell King 		return ret;
69f11a96d5SLiam Girdwood 
7053dea36cSDaniel Mack 	if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
71f11a96d5SLiam Girdwood 		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
72f11a96d5SLiam Girdwood 			SNDRV_PCM_STREAM_PLAYBACK);
73f11a96d5SLiam Girdwood 		if (ret)
74f11a96d5SLiam Girdwood 			goto out;
75f11a96d5SLiam Girdwood 	}
76f11a96d5SLiam Girdwood 
7753dea36cSDaniel Mack 	if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
78f11a96d5SLiam Girdwood 		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
79f11a96d5SLiam Girdwood 			SNDRV_PCM_STREAM_CAPTURE);
80f11a96d5SLiam Girdwood 		if (ret)
81f11a96d5SLiam Girdwood 			goto out;
82f11a96d5SLiam Girdwood 	}
83f11a96d5SLiam Girdwood  out:
84f11a96d5SLiam Girdwood 	return ret;
85f11a96d5SLiam Girdwood }
86f11a96d5SLiam Girdwood 
87f0fba2adSLiam Girdwood static struct snd_soc_platform_driver pxa2xx_soc_platform = {
88f0fba2adSLiam Girdwood 	.ops 	= &pxa2xx_pcm_ops,
898a33de9eSDmitry Baryshkov 	.pcm_new	= pxa2xx_soc_pcm_new,
90f11a96d5SLiam Girdwood 	.pcm_free	= pxa2xx_pcm_free_dma_buffers,
91f11a96d5SLiam Girdwood };
92f11a96d5SLiam Girdwood 
93570f6fe1SBill Pemberton static int pxa2xx_soc_platform_probe(struct platform_device *pdev)
94958e792cSMark Brown {
95637c4497SAxel Lin 	return devm_snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
96958e792cSMark Brown }
97f0fba2adSLiam Girdwood 
98c529ca4aSDaniel Mack #ifdef CONFIG_OF
99c529ca4aSDaniel Mack static const struct of_device_id snd_soc_pxa_audio_match[] = {
100c529ca4aSDaniel Mack 	{ .compatible   = "mrvl,pxa-pcm-audio" },
101c529ca4aSDaniel Mack 	{ }
102c529ca4aSDaniel Mack };
103baafd373SLuis de Bethencourt MODULE_DEVICE_TABLE(of, snd_soc_pxa_audio_match);
104c529ca4aSDaniel Mack #endif
105c529ca4aSDaniel Mack 
106f0fba2adSLiam Girdwood static struct platform_driver pxa_pcm_driver = {
107f0fba2adSLiam Girdwood 	.driver = {
108f0fba2adSLiam Girdwood 		.name = "pxa-pcm-audio",
109c529ca4aSDaniel Mack 		.of_match_table = of_match_ptr(snd_soc_pxa_audio_match),
110f0fba2adSLiam Girdwood 	},
111f0fba2adSLiam Girdwood 
112f0fba2adSLiam Girdwood 	.probe = pxa2xx_soc_platform_probe,
113f0fba2adSLiam Girdwood };
114f0fba2adSLiam Girdwood 
1152f702a19SAxel Lin module_platform_driver(pxa_pcm_driver);
116958e792cSMark Brown 
117f11a96d5SLiam Girdwood MODULE_AUTHOR("Nicolas Pitre");
118f11a96d5SLiam Girdwood MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
119f11a96d5SLiam Girdwood MODULE_LICENSE("GPL");
120e5b7d71aSAndrea Adami MODULE_ALIAS("platform:pxa-pcm-audio");
121