1515#include <linux/module.h>
1616#include <linux/platform_device.h>
1717#include <linux/dmaengine.h>
18- #include <linux/dma/pxa-dma .h>
18+ #include <linux/dma-mapping .h>
1919
2020#include <sound/core.h>
2121#include <sound/pcm.h>
2727#include <mach/regs-ac97.h>
2828#include <mach/audio.h>
2929
30- #include "pxa2xx-pcm.h"
31-
3230static void pxa2xx_ac97_legacy_reset (struct snd_ac97 * ac97 )
3331{
3432 if (!pxa2xx_ac97_try_cold_reset ())
@@ -63,69 +61,62 @@ static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
6361 .reset = pxa2xx_ac97_legacy_reset ,
6462};
6563
66- static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_out = {
67- .addr = __PREG (PCDR ),
68- .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES ,
69- .chan_name = "pcm_pcm_stereo_out" ,
70- .maxburst = 32 ,
71- };
72-
73- static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_in = {
74- .addr = __PREG (PCDR ),
75- .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES ,
76- .chan_name = "pcm_pcm_stereo_in" ,
77- .maxburst = 32 ,
78- };
79-
8064static struct snd_pcm * pxa2xx_ac97_pcm ;
8165static struct snd_ac97 * pxa2xx_ac97_ac97 ;
8266
83- static int pxa2xx_ac97_pcm_startup (struct snd_pcm_substream * substream )
67+ static int pxa2xx_ac97_pcm_open (struct snd_pcm_substream * substream )
8468{
8569 struct snd_pcm_runtime * runtime = substream -> runtime ;
8670 pxa2xx_audio_ops_t * platform_ops ;
87- int r ;
71+ int ret , i ;
72+
73+ ret = __pxa2xx_pcm_open (substream );
74+ if (ret )
75+ return ret ;
8876
8977 runtime -> hw .channels_min = 2 ;
9078 runtime -> hw .channels_max = 2 ;
9179
92- r = (substream -> stream == SNDRV_PCM_STREAM_PLAYBACK ) ?
93- AC97_RATES_FRONT_DAC : AC97_RATES_ADC ;
94- runtime -> hw .rates = pxa2xx_ac97_ac97 -> rates [r ];
80+ i = (substream -> stream == SNDRV_PCM_STREAM_PLAYBACK ) ?
81+ AC97_RATES_FRONT_DAC : AC97_RATES_ADC ;
82+ runtime -> hw .rates = pxa2xx_ac97_ac97 -> rates [i ];
9583 snd_pcm_limit_hw_rates (runtime );
9684
97- platform_ops = substream -> pcm -> card -> dev -> platform_data ;
98- if (platform_ops && platform_ops -> startup )
99- return platform_ops -> startup (substream , platform_ops -> priv );
100- else
101- return 0 ;
85+ platform_ops = substream -> pcm -> card -> dev -> platform_data ;
86+ if (platform_ops && platform_ops -> startup ) {
87+ ret = platform_ops -> startup (substream , platform_ops -> priv );
88+ if (ret < 0 )
89+ __pxa2xx_pcm_close (substream );
90+ }
91+
92+ return ret ;
10293}
10394
104- static void pxa2xx_ac97_pcm_shutdown (struct snd_pcm_substream * substream )
95+ static int pxa2xx_ac97_pcm_close (struct snd_pcm_substream * substream )
10596{
10697 pxa2xx_audio_ops_t * platform_ops ;
10798
108- platform_ops = substream -> pcm -> card -> dev -> platform_data ;
99+ platform_ops = substream -> pcm -> card -> dev -> platform_data ;
109100 if (platform_ops && platform_ops -> shutdown )
110101 platform_ops -> shutdown (substream , platform_ops -> priv );
102+
103+ return 0 ;
111104}
112105
113106static int pxa2xx_ac97_pcm_prepare (struct snd_pcm_substream * substream )
114107{
115108 struct snd_pcm_runtime * runtime = substream -> runtime ;
116109 int reg = (substream -> stream == SNDRV_PCM_STREAM_PLAYBACK ) ?
117110 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE ;
111+ int ret ;
112+
113+ ret = __pxa2xx_pcm_prepare (substream );
114+ if (ret < 0 )
115+ return ret ;
116+
118117 return snd_ac97_set_rate (pxa2xx_ac97_ac97 , reg , runtime -> rate );
119118}
120119
121- static struct pxa2xx_pcm_client pxa2xx_ac97_pcm_client = {
122- .playback_params = & pxa2xx_ac97_pcm_out ,
123- .capture_params = & pxa2xx_ac97_pcm_in ,
124- .startup = pxa2xx_ac97_pcm_startup ,
125- .shutdown = pxa2xx_ac97_pcm_shutdown ,
126- .prepare = pxa2xx_ac97_pcm_prepare ,
127- };
128-
129120#ifdef CONFIG_PM_SLEEP
130121
131122static int pxa2xx_ac97_do_suspend (struct snd_card * card )
@@ -183,6 +174,53 @@ static int pxa2xx_ac97_resume(struct device *dev)
183174static SIMPLE_DEV_PM_OPS (pxa2xx_ac97_pm_ops , pxa2xx_ac97_suspend , pxa2xx_ac97_resume ) ;
184175#endif
185176
177+ static const struct snd_pcm_ops pxa2xx_pcm_ops = {
178+ .open = pxa2xx_ac97_pcm_open ,
179+ .close = pxa2xx_ac97_pcm_close ,
180+ .ioctl = snd_pcm_lib_ioctl ,
181+ .hw_params = __pxa2xx_pcm_hw_params ,
182+ .hw_free = __pxa2xx_pcm_hw_free ,
183+ .prepare = pxa2xx_ac97_pcm_prepare ,
184+ .trigger = pxa2xx_pcm_trigger ,
185+ .pointer = pxa2xx_pcm_pointer ,
186+ .mmap = pxa2xx_pcm_mmap ,
187+ };
188+
189+
190+ static int pxa2xx_ac97_pcm_new (struct snd_card * card )
191+ {
192+ struct snd_pcm * pcm ;
193+ int stream , ret ;
194+
195+ ret = snd_pcm_new (card , "PXA2xx-PCM" , 0 , 1 , 1 , & pcm );
196+ if (ret )
197+ goto out ;
198+
199+ pcm -> private_free = pxa2xx_pcm_free_dma_buffers ;
200+
201+ ret = dma_coerce_mask_and_coherent (card -> dev , DMA_BIT_MASK (32 ));
202+ if (ret )
203+ goto out ;
204+
205+ stream = SNDRV_PCM_STREAM_PLAYBACK ;
206+ snd_pcm_set_ops (pcm , stream , & pxa2xx_pcm_ops );
207+ ret = pxa2xx_pcm_preallocate_dma_buffer (pcm , stream );
208+ if (ret )
209+ goto out ;
210+
211+ stream = SNDRV_PCM_STREAM_CAPTURE ;
212+ snd_pcm_set_ops (pcm , stream , & pxa2xx_pcm_ops );
213+ ret = pxa2xx_pcm_preallocate_dma_buffer (pcm , stream );
214+ if (ret )
215+ goto out ;
216+
217+ pxa2xx_ac97_pcm = pcm ;
218+ ret = 0 ;
219+
220+ out :
221+ return ret ;
222+ }
223+
186224static int pxa2xx_ac97_probe (struct platform_device * dev )
187225{
188226 struct snd_card * card ;
@@ -204,7 +242,7 @@ static int pxa2xx_ac97_probe(struct platform_device *dev)
204242
205243 strlcpy (card -> driver , dev -> dev .driver -> name , sizeof (card -> driver ));
206244
207- ret = pxa2xx_pcm_new (card , & pxa2xx_ac97_pcm_client , & pxa2xx_ac97_pcm );
245+ ret = pxa2xx_ac97_pcm_new (card );
208246 if (ret )
209247 goto err ;
210248
0 commit comments