xref: /linux/sound/soc/pxa/pxa2xx-pcm.c (revision a7160670b5e2d6b59e0f7a5b7e5bcef3b532c24c)
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 const struct snd_pcm_ops pxa2xx_pcm_ops = {
40 	.open		= pxa2xx_pcm_open,
41 	.close		= pxa2xx_pcm_close,
42 	.ioctl		= snd_pcm_lib_ioctl,
43 	.hw_params	= __pxa2xx_pcm_hw_params,
44 	.hw_free	= pxa2xx_pcm_hw_free,
45 	.prepare	= pxa2xx_pcm_prepare,
46 	.trigger	= pxa2xx_pcm_trigger,
47 	.pointer	= pxa2xx_pcm_pointer,
48 	.mmap		= pxa2xx_pcm_mmap,
49 };
50 
51 static int pxa2xx_soc_pcm_new(struct snd_soc_pcm_runtime *rtd)
52 {
53 	struct snd_card *card = rtd->card->snd_card;
54 	struct snd_pcm *pcm = rtd->pcm;
55 	int ret;
56 
57 	ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
58 	if (ret)
59 		return ret;
60 
61 	if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
62 		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
63 			SNDRV_PCM_STREAM_PLAYBACK);
64 		if (ret)
65 			goto out;
66 	}
67 
68 	if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
69 		ret = pxa2xx_pcm_preallocate_dma_buffer(pcm,
70 			SNDRV_PCM_STREAM_CAPTURE);
71 		if (ret)
72 			goto out;
73 	}
74  out:
75 	return ret;
76 }
77 
78 static const struct snd_soc_component_driver pxa2xx_soc_platform = {
79 	.ops		= &pxa2xx_pcm_ops,
80 	.pcm_new	= pxa2xx_soc_pcm_new,
81 	.pcm_free	= pxa2xx_pcm_free_dma_buffers,
82 };
83 
84 static int pxa2xx_soc_platform_probe(struct platform_device *pdev)
85 {
86 	return devm_snd_soc_register_component(&pdev->dev, &pxa2xx_soc_platform,
87 					       NULL, 0);
88 }
89 
90 #ifdef CONFIG_OF
91 static const struct of_device_id snd_soc_pxa_audio_match[] = {
92 	{ .compatible   = "mrvl,pxa-pcm-audio" },
93 	{ }
94 };
95 MODULE_DEVICE_TABLE(of, snd_soc_pxa_audio_match);
96 #endif
97 
98 static struct platform_driver pxa_pcm_driver = {
99 	.driver = {
100 		.name = "pxa-pcm-audio",
101 		.of_match_table = of_match_ptr(snd_soc_pxa_audio_match),
102 	},
103 
104 	.probe = pxa2xx_soc_platform_probe,
105 };
106 
107 module_platform_driver(pxa_pcm_driver);
108 
109 MODULE_AUTHOR("Nicolas Pitre");
110 MODULE_DESCRIPTION("Intel PXA2xx PCM DMA module");
111 MODULE_LICENSE("GPL");
112 MODULE_ALIAS("platform:pxa-pcm-audio");
113