diff options
author | Sedji Gaouaou <sedji.gaouaou@atmel.com> | 2008-10-03 10:57:50 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2008-10-31 09:12:26 -0400 |
commit | 6c7425095c9ee23d080dba3e27217a254cce4562 (patch) | |
tree | c6c27e1c986b2adeda4adbdcad934b816d654b75 /sound/soc/at91 | |
parent | dc06102a0c8b5aa0dd7f9a40ce241e793c252a87 (diff) |
ASoC: Merge AT91 and AVR32 support into a single atmel architecture
The Ateml AT91 and AVR32 SoC share common IP for audio and can share the
same driver code using the atmel-ssc API provided for both architectures.
Do this, creating a new unified atmel ASoC architecture to replace the
previous at32 and at91 ones.
[This was contributed as a patch series for reviewability but has been
squashed down to a single commit to help preserve both the history and
bisectability. A small bugfix from Jukka is included.]
Tested-by: Jukka Hynninen <ext-jukka.hynninen@vaisala.com>
Signed-off-by: Sedji Gaouaou <sedji.gaouaou@atmel.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/at91')
-rw-r--r-- | sound/soc/at91/Kconfig | 10 | ||||
-rw-r--r-- | sound/soc/at91/Makefile | 6 | ||||
-rw-r--r-- | sound/soc/at91/at91-pcm.c | 434 | ||||
-rw-r--r-- | sound/soc/at91/at91-pcm.h | 72 | ||||
-rw-r--r-- | sound/soc/at91/at91-ssc.c | 791 | ||||
-rw-r--r-- | sound/soc/at91/at91-ssc.h | 27 |
6 files changed, 0 insertions, 1340 deletions
diff --git a/sound/soc/at91/Kconfig b/sound/soc/at91/Kconfig deleted file mode 100644 index 85a883299c2e..000000000000 --- a/sound/soc/at91/Kconfig +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | config SND_AT91_SOC | ||
2 | tristate "SoC Audio for the Atmel AT91 System-on-Chip" | ||
3 | depends on ARCH_AT91 | ||
4 | help | ||
5 | Say Y or M if you want to add support for codecs attached to | ||
6 | the AT91 SSC interface. You will also need | ||
7 | to select the audio interfaces to support below. | ||
8 | |||
9 | config SND_AT91_SOC_SSC | ||
10 | tristate | ||
diff --git a/sound/soc/at91/Makefile b/sound/soc/at91/Makefile deleted file mode 100644 index b817f11df286..000000000000 --- a/sound/soc/at91/Makefile +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | # AT91 Platform Support | ||
2 | snd-soc-at91-objs := at91-pcm.o | ||
3 | snd-soc-at91-ssc-objs := at91-ssc.o | ||
4 | |||
5 | obj-$(CONFIG_SND_AT91_SOC) += snd-soc-at91.o | ||
6 | obj-$(CONFIG_SND_AT91_SOC_SSC) += snd-soc-at91-ssc.o | ||
diff --git a/sound/soc/at91/at91-pcm.c b/sound/soc/at91/at91-pcm.c deleted file mode 100644 index 7ab48bd25e4c..000000000000 --- a/sound/soc/at91/at91-pcm.c +++ /dev/null | |||
@@ -1,434 +0,0 @@ | |||
1 | /* | ||
2 | * at91-pcm.c -- ALSA PCM interface for the Atmel AT91 SoC | ||
3 | * | ||
4 | * Author: Frank Mandarino <fmandarino@endrelia.com> | ||
5 | * Endrelia Technologies Inc. | ||
6 | * Created: Mar 3, 2006 | ||
7 | * | ||
8 | * Based on pxa2xx-pcm.c by: | ||
9 | * | ||
10 | * Author: Nicolas Pitre | ||
11 | * Created: Nov 30, 2004 | ||
12 | * Copyright: (C) 2004 MontaVista Software, Inc. | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/platform_device.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/dma-mapping.h> | ||
24 | #include <linux/atmel_pdc.h> | ||
25 | |||
26 | #include <sound/core.h> | ||
27 | #include <sound/pcm.h> | ||
28 | #include <sound/pcm_params.h> | ||
29 | #include <sound/soc.h> | ||
30 | |||
31 | #include <mach/hardware.h> | ||
32 | #include <mach/at91_ssc.h> | ||
33 | |||
34 | #include "at91-pcm.h" | ||
35 | |||
36 | #if 0 | ||
37 | #define DBG(x...) printk(KERN_INFO "at91-pcm: " x) | ||
38 | #else | ||
39 | #define DBG(x...) | ||
40 | #endif | ||
41 | |||
42 | static const struct snd_pcm_hardware at91_pcm_hardware = { | ||
43 | .info = SNDRV_PCM_INFO_MMAP | | ||
44 | SNDRV_PCM_INFO_MMAP_VALID | | ||
45 | SNDRV_PCM_INFO_INTERLEAVED | | ||
46 | SNDRV_PCM_INFO_PAUSE, | ||
47 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | ||
48 | .period_bytes_min = 32, | ||
49 | .period_bytes_max = 8192, | ||
50 | .periods_min = 2, | ||
51 | .periods_max = 1024, | ||
52 | .buffer_bytes_max = 32 * 1024, | ||
53 | }; | ||
54 | |||
55 | struct at91_runtime_data { | ||
56 | struct at91_pcm_dma_params *params; | ||
57 | dma_addr_t dma_buffer; /* physical address of dma buffer */ | ||
58 | dma_addr_t dma_buffer_end; /* first address beyond DMA buffer */ | ||
59 | size_t period_size; | ||
60 | dma_addr_t period_ptr; /* physical address of next period */ | ||
61 | u32 pdc_xpr_save; /* PDC register save */ | ||
62 | u32 pdc_xcr_save; | ||
63 | u32 pdc_xnpr_save; | ||
64 | u32 pdc_xncr_save; | ||
65 | }; | ||
66 | |||
67 | static void at91_pcm_dma_irq(u32 ssc_sr, | ||
68 | struct snd_pcm_substream *substream) | ||
69 | { | ||
70 | struct at91_runtime_data *prtd = substream->runtime->private_data; | ||
71 | struct at91_pcm_dma_params *params = prtd->params; | ||
72 | static int count = 0; | ||
73 | |||
74 | count++; | ||
75 | |||
76 | if (ssc_sr & params->mask->ssc_endbuf) { | ||
77 | |||
78 | printk(KERN_WARNING | ||
79 | "at91-pcm: buffer %s on %s (SSC_SR=%#x, count=%d)\n", | ||
80 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK | ||
81 | ? "underrun" : "overrun", | ||
82 | params->name, ssc_sr, count); | ||
83 | |||
84 | /* re-start the PDC */ | ||
85 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_disable); | ||
86 | |||
87 | prtd->period_ptr += prtd->period_size; | ||
88 | if (prtd->period_ptr >= prtd->dma_buffer_end) { | ||
89 | prtd->period_ptr = prtd->dma_buffer; | ||
90 | } | ||
91 | |||
92 | at91_ssc_write(params->ssc_base + params->pdc->xpr, prtd->period_ptr); | ||
93 | at91_ssc_write(params->ssc_base + params->pdc->xcr, | ||
94 | prtd->period_size / params->pdc_xfer_size); | ||
95 | |||
96 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_enable); | ||
97 | } | ||
98 | |||
99 | if (ssc_sr & params->mask->ssc_endx) { | ||
100 | |||
101 | /* Load the PDC next pointer and counter registers */ | ||
102 | prtd->period_ptr += prtd->period_size; | ||
103 | if (prtd->period_ptr >= prtd->dma_buffer_end) { | ||
104 | prtd->period_ptr = prtd->dma_buffer; | ||
105 | } | ||
106 | at91_ssc_write(params->ssc_base + params->pdc->xnpr, | ||
107 | prtd->period_ptr); | ||
108 | at91_ssc_write(params->ssc_base + params->pdc->xncr, | ||
109 | prtd->period_size / params->pdc_xfer_size); | ||
110 | } | ||
111 | |||
112 | snd_pcm_period_elapsed(substream); | ||
113 | } | ||
114 | |||
115 | static int at91_pcm_hw_params(struct snd_pcm_substream *substream, | ||
116 | struct snd_pcm_hw_params *params) | ||
117 | { | ||
118 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
119 | struct at91_runtime_data *prtd = runtime->private_data; | ||
120 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
121 | |||
122 | /* this may get called several times by oss emulation | ||
123 | * with different params */ | ||
124 | |||
125 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); | ||
126 | runtime->dma_bytes = params_buffer_bytes(params); | ||
127 | |||
128 | prtd->params = rtd->dai->cpu_dai->dma_data; | ||
129 | prtd->params->dma_intr_handler = at91_pcm_dma_irq; | ||
130 | |||
131 | prtd->dma_buffer = runtime->dma_addr; | ||
132 | prtd->dma_buffer_end = runtime->dma_addr + runtime->dma_bytes; | ||
133 | prtd->period_size = params_period_bytes(params); | ||
134 | |||
135 | DBG("hw_params: DMA for %s initialized (dma_bytes=%d, period_size=%d)\n", | ||
136 | prtd->params->name, runtime->dma_bytes, prtd->period_size); | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | static int at91_pcm_hw_free(struct snd_pcm_substream *substream) | ||
141 | { | ||
142 | struct at91_runtime_data *prtd = substream->runtime->private_data; | ||
143 | struct at91_pcm_dma_params *params = prtd->params; | ||
144 | |||
145 | if (params != NULL) { | ||
146 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_disable); | ||
147 | prtd->params->dma_intr_handler = NULL; | ||
148 | } | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static int at91_pcm_prepare(struct snd_pcm_substream *substream) | ||
154 | { | ||
155 | struct at91_runtime_data *prtd = substream->runtime->private_data; | ||
156 | struct at91_pcm_dma_params *params = prtd->params; | ||
157 | |||
158 | at91_ssc_write(params->ssc_base + AT91_SSC_IDR, | ||
159 | params->mask->ssc_endx | params->mask->ssc_endbuf); | ||
160 | |||
161 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_disable); | ||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static int at91_pcm_trigger(struct snd_pcm_substream *substream, | ||
166 | int cmd) | ||
167 | { | ||
168 | struct at91_runtime_data *prtd = substream->runtime->private_data; | ||
169 | struct at91_pcm_dma_params *params = prtd->params; | ||
170 | int ret = 0; | ||
171 | |||
172 | switch (cmd) { | ||
173 | case SNDRV_PCM_TRIGGER_START: | ||
174 | prtd->period_ptr = prtd->dma_buffer; | ||
175 | |||
176 | at91_ssc_write(params->ssc_base + params->pdc->xpr, prtd->period_ptr); | ||
177 | at91_ssc_write(params->ssc_base + params->pdc->xcr, | ||
178 | prtd->period_size / params->pdc_xfer_size); | ||
179 | |||
180 | prtd->period_ptr += prtd->period_size; | ||
181 | at91_ssc_write(params->ssc_base + params->pdc->xnpr, prtd->period_ptr); | ||
182 | at91_ssc_write(params->ssc_base + params->pdc->xncr, | ||
183 | prtd->period_size / params->pdc_xfer_size); | ||
184 | |||
185 | DBG("trigger: period_ptr=%lx, xpr=%lx, xcr=%ld, xnpr=%lx, xncr=%ld\n", | ||
186 | (unsigned long) prtd->period_ptr, | ||
187 | at91_ssc_read(params->ssc_base + params->pdc->xpr), | ||
188 | at91_ssc_read(params->ssc_base + params->pdc->xcr), | ||
189 | at91_ssc_read(params->ssc_base + params->pdc->xnpr), | ||
190 | at91_ssc_read(params->ssc_base + params->pdc->xncr)); | ||
191 | |||
192 | at91_ssc_write(params->ssc_base + AT91_SSC_IER, | ||
193 | params->mask->ssc_endx | params->mask->ssc_endbuf); | ||
194 | |||
195 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, | ||
196 | params->mask->pdc_enable); | ||
197 | |||
198 | DBG("sr=%lx imr=%lx\n", | ||
199 | at91_ssc_read(params->ssc_base + AT91_SSC_SR), | ||
200 | at91_ssc_read(params->ssc_base + AT91_SSC_IMR)); | ||
201 | break; | ||
202 | |||
203 | case SNDRV_PCM_TRIGGER_STOP: | ||
204 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
205 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
206 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_disable); | ||
207 | break; | ||
208 | |||
209 | case SNDRV_PCM_TRIGGER_RESUME: | ||
210 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
211 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_enable); | ||
212 | break; | ||
213 | |||
214 | default: | ||
215 | ret = -EINVAL; | ||
216 | } | ||
217 | |||
218 | return ret; | ||
219 | } | ||
220 | |||
221 | static snd_pcm_uframes_t at91_pcm_pointer( | ||
222 | struct snd_pcm_substream *substream) | ||
223 | { | ||
224 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
225 | struct at91_runtime_data *prtd = runtime->private_data; | ||
226 | struct at91_pcm_dma_params *params = prtd->params; | ||
227 | dma_addr_t ptr; | ||
228 | snd_pcm_uframes_t x; | ||
229 | |||
230 | ptr = (dma_addr_t) at91_ssc_read(params->ssc_base + params->pdc->xpr); | ||
231 | x = bytes_to_frames(runtime, ptr - prtd->dma_buffer); | ||
232 | |||
233 | if (x == runtime->buffer_size) | ||
234 | x = 0; | ||
235 | return x; | ||
236 | } | ||
237 | |||
238 | static int at91_pcm_open(struct snd_pcm_substream *substream) | ||
239 | { | ||
240 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
241 | struct at91_runtime_data *prtd; | ||
242 | int ret = 0; | ||
243 | |||
244 | snd_soc_set_runtime_hwparams(substream, &at91_pcm_hardware); | ||
245 | |||
246 | /* ensure that buffer size is a multiple of period size */ | ||
247 | ret = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); | ||
248 | if (ret < 0) | ||
249 | goto out; | ||
250 | |||
251 | prtd = kzalloc(sizeof(struct at91_runtime_data), GFP_KERNEL); | ||
252 | if (prtd == NULL) { | ||
253 | ret = -ENOMEM; | ||
254 | goto out; | ||
255 | } | ||
256 | runtime->private_data = prtd; | ||
257 | |||
258 | out: | ||
259 | return ret; | ||
260 | } | ||
261 | |||
262 | static int at91_pcm_close(struct snd_pcm_substream *substream) | ||
263 | { | ||
264 | struct at91_runtime_data *prtd = substream->runtime->private_data; | ||
265 | |||
266 | kfree(prtd); | ||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | static int at91_pcm_mmap(struct snd_pcm_substream *substream, | ||
271 | struct vm_area_struct *vma) | ||
272 | { | ||
273 | struct snd_pcm_runtime *runtime = substream->runtime; | ||
274 | |||
275 | return dma_mmap_writecombine(substream->pcm->card->dev, vma, | ||
276 | runtime->dma_area, | ||
277 | runtime->dma_addr, | ||
278 | runtime->dma_bytes); | ||
279 | } | ||
280 | |||
281 | struct snd_pcm_ops at91_pcm_ops = { | ||
282 | .open = at91_pcm_open, | ||
283 | .close = at91_pcm_close, | ||
284 | .ioctl = snd_pcm_lib_ioctl, | ||
285 | .hw_params = at91_pcm_hw_params, | ||
286 | .hw_free = at91_pcm_hw_free, | ||
287 | .prepare = at91_pcm_prepare, | ||
288 | .trigger = at91_pcm_trigger, | ||
289 | .pointer = at91_pcm_pointer, | ||
290 | .mmap = at91_pcm_mmap, | ||
291 | }; | ||
292 | |||
293 | static int at91_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, | ||
294 | int stream) | ||
295 | { | ||
296 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; | ||
297 | struct snd_dma_buffer *buf = &substream->dma_buffer; | ||
298 | size_t size = at91_pcm_hardware.buffer_bytes_max; | ||
299 | |||
300 | buf->dev.type = SNDRV_DMA_TYPE_DEV; | ||
301 | buf->dev.dev = pcm->card->dev; | ||
302 | buf->private_data = NULL; | ||
303 | buf->area = dma_alloc_writecombine(pcm->card->dev, size, | ||
304 | &buf->addr, GFP_KERNEL); | ||
305 | |||
306 | DBG("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n", | ||
307 | (void *) buf->area, | ||
308 | (void *) buf->addr, | ||
309 | size); | ||
310 | |||
311 | if (!buf->area) | ||
312 | return -ENOMEM; | ||
313 | |||
314 | buf->bytes = size; | ||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | static u64 at91_pcm_dmamask = 0xffffffff; | ||
319 | |||
320 | static int at91_pcm_new(struct snd_card *card, | ||
321 | struct snd_soc_dai *dai, struct snd_pcm *pcm) | ||
322 | { | ||
323 | int ret = 0; | ||
324 | |||
325 | if (!card->dev->dma_mask) | ||
326 | card->dev->dma_mask = &at91_pcm_dmamask; | ||
327 | if (!card->dev->coherent_dma_mask) | ||
328 | card->dev->coherent_dma_mask = 0xffffffff; | ||
329 | |||
330 | if (dai->playback.channels_min) { | ||
331 | ret = at91_pcm_preallocate_dma_buffer(pcm, | ||
332 | SNDRV_PCM_STREAM_PLAYBACK); | ||
333 | if (ret) | ||
334 | goto out; | ||
335 | } | ||
336 | |||
337 | if (dai->capture.channels_min) { | ||
338 | ret = at91_pcm_preallocate_dma_buffer(pcm, | ||
339 | SNDRV_PCM_STREAM_CAPTURE); | ||
340 | if (ret) | ||
341 | goto out; | ||
342 | } | ||
343 | out: | ||
344 | return ret; | ||
345 | } | ||
346 | |||
347 | static void at91_pcm_free_dma_buffers(struct snd_pcm *pcm) | ||
348 | { | ||
349 | struct snd_pcm_substream *substream; | ||
350 | struct snd_dma_buffer *buf; | ||
351 | int stream; | ||
352 | |||
353 | for (stream = 0; stream < 2; stream++) { | ||
354 | substream = pcm->streams[stream].substream; | ||
355 | if (!substream) | ||
356 | continue; | ||
357 | |||
358 | buf = &substream->dma_buffer; | ||
359 | if (!buf->area) | ||
360 | continue; | ||
361 | |||
362 | dma_free_writecombine(pcm->card->dev, buf->bytes, | ||
363 | buf->area, buf->addr); | ||
364 | buf->area = NULL; | ||
365 | } | ||
366 | } | ||
367 | |||
368 | #ifdef CONFIG_PM | ||
369 | static int at91_pcm_suspend(struct platform_device *pdev, | ||
370 | struct snd_soc_dai *dai) | ||
371 | { | ||
372 | struct snd_pcm_runtime *runtime = dai->runtime; | ||
373 | struct at91_runtime_data *prtd; | ||
374 | struct at91_pcm_dma_params *params; | ||
375 | |||
376 | if (!runtime) | ||
377 | return 0; | ||
378 | |||
379 | prtd = runtime->private_data; | ||
380 | params = prtd->params; | ||
381 | |||
382 | /* disable the PDC and save the PDC registers */ | ||
383 | |||
384 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_disable); | ||
385 | |||
386 | prtd->pdc_xpr_save = at91_ssc_read(params->ssc_base + params->pdc->xpr); | ||
387 | prtd->pdc_xcr_save = at91_ssc_read(params->ssc_base + params->pdc->xcr); | ||
388 | prtd->pdc_xnpr_save = at91_ssc_read(params->ssc_base + params->pdc->xnpr); | ||
389 | prtd->pdc_xncr_save = at91_ssc_read(params->ssc_base + params->pdc->xncr); | ||
390 | |||
391 | return 0; | ||
392 | } | ||
393 | |||
394 | static int at91_pcm_resume(struct platform_device *pdev, | ||
395 | struct snd_soc_dai *dai) | ||
396 | { | ||
397 | struct snd_pcm_runtime *runtime = dai->runtime; | ||
398 | struct at91_runtime_data *prtd; | ||
399 | struct at91_pcm_dma_params *params; | ||
400 | |||
401 | if (!runtime) | ||
402 | return 0; | ||
403 | |||
404 | prtd = runtime->private_data; | ||
405 | params = prtd->params; | ||
406 | |||
407 | /* restore the PDC registers and enable the PDC */ | ||
408 | at91_ssc_write(params->ssc_base + params->pdc->xpr, prtd->pdc_xpr_save); | ||
409 | at91_ssc_write(params->ssc_base + params->pdc->xcr, prtd->pdc_xcr_save); | ||
410 | at91_ssc_write(params->ssc_base + params->pdc->xnpr, prtd->pdc_xnpr_save); | ||
411 | at91_ssc_write(params->ssc_base + params->pdc->xncr, prtd->pdc_xncr_save); | ||
412 | |||
413 | at91_ssc_write(params->ssc_base + ATMEL_PDC_PTCR, params->mask->pdc_enable); | ||
414 | return 0; | ||
415 | } | ||
416 | #else | ||
417 | #define at91_pcm_suspend NULL | ||
418 | #define at91_pcm_resume NULL | ||
419 | #endif | ||
420 | |||
421 | struct snd_soc_platform at91_soc_platform = { | ||
422 | .name = "at91-audio", | ||
423 | .pcm_ops = &at91_pcm_ops, | ||
424 | .pcm_new = at91_pcm_new, | ||
425 | .pcm_free = at91_pcm_free_dma_buffers, | ||
426 | .suspend = at91_pcm_suspend, | ||
427 | .resume = at91_pcm_resume, | ||
428 | }; | ||
429 | |||
430 | EXPORT_SYMBOL_GPL(at91_soc_platform); | ||
431 | |||
432 | MODULE_AUTHOR("Frank Mandarino <fmandarino@endrelia.com>"); | ||
433 | MODULE_DESCRIPTION("Atmel AT91 PCM module"); | ||
434 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/at91/at91-pcm.h b/sound/soc/at91/at91-pcm.h deleted file mode 100644 index e5aada2cb102..000000000000 --- a/sound/soc/at91/at91-pcm.h +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | /* | ||
2 | * at91-pcm.h - ALSA PCM interface for the Atmel AT91 SoC | ||
3 | * | ||
4 | * Author: Frank Mandarino <fmandarino@endrelia.com> | ||
5 | * Endrelia Technologies Inc. | ||
6 | * Created: Mar 3, 2006 | ||
7 | * | ||
8 | * Based on pxa2xx-pcm.h by: | ||
9 | * | ||
10 | * Author: Nicolas Pitre | ||
11 | * Created: Nov 30, 2004 | ||
12 | * Copyright: MontaVista Software, Inc. | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License version 2 as | ||
16 | * published by the Free Software Foundation. | ||
17 | */ | ||
18 | |||
19 | #ifndef _AT91_PCM_H | ||
20 | #define _AT91_PCM_H | ||
21 | |||
22 | #include <mach/hardware.h> | ||
23 | |||
24 | struct at91_ssc_periph { | ||
25 | void __iomem *base; | ||
26 | u32 pid; | ||
27 | }; | ||
28 | |||
29 | /* | ||
30 | * Registers and status bits that are required by the PCM driver. | ||
31 | */ | ||
32 | struct at91_pdc_regs { | ||
33 | unsigned int xpr; /* PDC recv/trans pointer */ | ||
34 | unsigned int xcr; /* PDC recv/trans counter */ | ||
35 | unsigned int xnpr; /* PDC next recv/trans pointer */ | ||
36 | unsigned int xncr; /* PDC next recv/trans counter */ | ||
37 | unsigned int ptcr; /* PDC transfer control */ | ||
38 | }; | ||
39 | |||
40 | struct at91_ssc_mask { | ||
41 | u32 ssc_enable; /* SSC recv/trans enable */ | ||
42 | u32 ssc_disable; /* SSC recv/trans disable */ | ||
43 | u32 ssc_endx; /* SSC ENDTX or ENDRX */ | ||
44 | u32 ssc_endbuf; /* SSC TXBUFE or RXBUFF */ | ||
45 | u32 pdc_enable; /* PDC recv/trans enable */ | ||
46 | u32 pdc_disable; /* PDC recv/trans disable */ | ||
47 | }; | ||
48 | |||
49 | /* | ||
50 | * This structure, shared between the PCM driver and the interface, | ||
51 | * contains all information required by the PCM driver to perform the | ||
52 | * PDC DMA operation. All fields except dma_intr_handler() are initialized | ||
53 | * by the interface. The dms_intr_handler() pointer is set by the PCM | ||
54 | * driver and called by the interface SSC interrupt handler if it is | ||
55 | * non-NULL. | ||
56 | */ | ||
57 | struct at91_pcm_dma_params { | ||
58 | char *name; /* stream identifier */ | ||
59 | int pdc_xfer_size; /* PDC counter increment in bytes */ | ||
60 | void __iomem *ssc_base; /* SSC base address */ | ||
61 | struct at91_pdc_regs *pdc; /* PDC receive or transmit registers */ | ||
62 | struct at91_ssc_mask *mask;/* SSC & PDC status bits */ | ||
63 | struct snd_pcm_substream *substream; | ||
64 | void (*dma_intr_handler)(u32, struct snd_pcm_substream *); | ||
65 | }; | ||
66 | |||
67 | extern struct snd_soc_platform at91_soc_platform; | ||
68 | |||
69 | #define at91_ssc_read(a) ((unsigned long) __raw_readl(a)) | ||
70 | #define at91_ssc_write(a,v) __raw_writel((v),(a)) | ||
71 | |||
72 | #endif /* _AT91_PCM_H */ | ||
diff --git a/sound/soc/at91/at91-ssc.c b/sound/soc/at91/at91-ssc.c deleted file mode 100644 index 1b61cc461261..000000000000 --- a/sound/soc/at91/at91-ssc.c +++ /dev/null | |||
@@ -1,791 +0,0 @@ | |||
1 | /* | ||
2 | * at91-ssc.c -- ALSA SoC AT91 SSC Audio Layer Platform driver | ||
3 | * | ||
4 | * Author: Frank Mandarino <fmandarino@endrelia.com> | ||
5 | * Endrelia Technologies Inc. | ||
6 | * | ||
7 | * Based on pxa2xx Platform drivers by | ||
8 | * Liam Girdwood <lrg@slimlogic.co.uk> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/init.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/device.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/clk.h> | ||
23 | #include <linux/atmel_pdc.h> | ||
24 | |||
25 | #include <sound/core.h> | ||
26 | #include <sound/pcm.h> | ||
27 | #include <sound/pcm_params.h> | ||
28 | #include <sound/initval.h> | ||
29 | #include <sound/soc.h> | ||
30 | |||
31 | #include <mach/hardware.h> | ||
32 | #include <mach/at91_pmc.h> | ||
33 | #include <mach/at91_ssc.h> | ||
34 | |||
35 | #include "at91-pcm.h" | ||
36 | #include "at91-ssc.h" | ||
37 | |||
38 | #if 0 | ||
39 | #define DBG(x...) printk(KERN_DEBUG "at91-ssc:" x) | ||
40 | #else | ||
41 | #define DBG(x...) | ||
42 | #endif | ||
43 | |||
44 | #if defined(CONFIG_ARCH_AT91SAM9260) || defined(CONFIG_ARCH_AT91SAM9G20) | ||
45 | #define NUM_SSC_DEVICES 1 | ||
46 | #else | ||
47 | #define NUM_SSC_DEVICES 3 | ||
48 | #endif | ||
49 | |||
50 | |||
51 | /* | ||
52 | * SSC PDC registers required by the PCM DMA engine. | ||
53 | */ | ||
54 | static struct at91_pdc_regs pdc_tx_reg = { | ||
55 | .xpr = ATMEL_PDC_TPR, | ||
56 | .xcr = ATMEL_PDC_TCR, | ||
57 | .xnpr = ATMEL_PDC_TNPR, | ||
58 | .xncr = ATMEL_PDC_TNCR, | ||
59 | }; | ||
60 | |||
61 | static struct at91_pdc_regs pdc_rx_reg = { | ||
62 | .xpr = ATMEL_PDC_RPR, | ||
63 | .xcr = ATMEL_PDC_RCR, | ||
64 | .xnpr = ATMEL_PDC_RNPR, | ||
65 | .xncr = ATMEL_PDC_RNCR, | ||
66 | }; | ||
67 | |||
68 | /* | ||
69 | * SSC & PDC status bits for transmit and receive. | ||
70 | */ | ||
71 | static struct at91_ssc_mask ssc_tx_mask = { | ||
72 | .ssc_enable = AT91_SSC_TXEN, | ||
73 | .ssc_disable = AT91_SSC_TXDIS, | ||
74 | .ssc_endx = AT91_SSC_ENDTX, | ||
75 | .ssc_endbuf = AT91_SSC_TXBUFE, | ||
76 | .pdc_enable = ATMEL_PDC_TXTEN, | ||
77 | .pdc_disable = ATMEL_PDC_TXTDIS, | ||
78 | }; | ||
79 | |||
80 | static struct at91_ssc_mask ssc_rx_mask = { | ||
81 | .ssc_enable = AT91_SSC_RXEN, | ||
82 | .ssc_disable = AT91_SSC_RXDIS, | ||
83 | .ssc_endx = AT91_SSC_ENDRX, | ||
84 | .ssc_endbuf = AT91_SSC_RXBUFF, | ||
85 | .pdc_enable = ATMEL_PDC_RXTEN, | ||
86 | .pdc_disable = ATMEL_PDC_RXTDIS, | ||
87 | }; | ||
88 | |||
89 | |||
90 | /* | ||
91 | * DMA parameters. | ||
92 | */ | ||
93 | static struct at91_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = { | ||
94 | {{ | ||
95 | .name = "SSC0 PCM out", | ||
96 | .pdc = &pdc_tx_reg, | ||
97 | .mask = &ssc_tx_mask, | ||
98 | }, | ||
99 | { | ||
100 | .name = "SSC0 PCM in", | ||
101 | .pdc = &pdc_rx_reg, | ||
102 | .mask = &ssc_rx_mask, | ||
103 | }}, | ||
104 | #if NUM_SSC_DEVICES == 3 | ||
105 | {{ | ||
106 | .name = "SSC1 PCM out", | ||
107 | .pdc = &pdc_tx_reg, | ||
108 | .mask = &ssc_tx_mask, | ||
109 | }, | ||
110 | { | ||
111 | .name = "SSC1 PCM in", | ||
112 | .pdc = &pdc_rx_reg, | ||
113 | .mask = &ssc_rx_mask, | ||
114 | }}, | ||
115 | {{ | ||
116 | .name = "SSC2 PCM out", | ||
117 | .pdc = &pdc_tx_reg, | ||
118 | .mask = &ssc_tx_mask, | ||
119 | }, | ||
120 | { | ||
121 | .name = "SSC2 PCM in", | ||
122 | .pdc = &pdc_rx_reg, | ||
123 | .mask = &ssc_rx_mask, | ||
124 | }}, | ||
125 | #endif | ||
126 | }; | ||
127 | |||
128 | struct at91_ssc_state { | ||
129 | u32 ssc_cmr; | ||
130 | u32 ssc_rcmr; | ||
131 | u32 ssc_rfmr; | ||
132 | u32 ssc_tcmr; | ||
133 | u32 ssc_tfmr; | ||
134 | u32 ssc_sr; | ||
135 | u32 ssc_imr; | ||
136 | }; | ||
137 | |||
138 | static struct at91_ssc_info { | ||
139 | char *name; | ||
140 | struct at91_ssc_periph ssc; | ||
141 | spinlock_t lock; /* lock for dir_mask */ | ||
142 | unsigned short dir_mask; /* 0=unused, 1=playback, 2=capture */ | ||
143 | unsigned short initialized; /* 1=SSC has been initialized */ | ||
144 | unsigned short daifmt; | ||
145 | unsigned short cmr_div; | ||
146 | unsigned short tcmr_period; | ||
147 | unsigned short rcmr_period; | ||
148 | struct at91_pcm_dma_params *dma_params[2]; | ||
149 | struct at91_ssc_state ssc_state; | ||
150 | |||
151 | } ssc_info[NUM_SSC_DEVICES] = { | ||
152 | { | ||
153 | .name = "ssc0", | ||
154 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[0].lock), | ||
155 | .dir_mask = 0, | ||
156 | .initialized = 0, | ||
157 | }, | ||
158 | #if NUM_SSC_DEVICES == 3 | ||
159 | { | ||
160 | .name = "ssc1", | ||
161 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock), | ||
162 | .dir_mask = 0, | ||
163 | .initialized = 0, | ||
164 | }, | ||
165 | { | ||
166 | .name = "ssc2", | ||
167 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock), | ||
168 | .dir_mask = 0, | ||
169 | .initialized = 0, | ||
170 | }, | ||
171 | #endif | ||
172 | }; | ||
173 | |||
174 | static unsigned int at91_ssc_sysclk; | ||
175 | |||
176 | /* | ||
177 | * SSC interrupt handler. Passes PDC interrupts to the DMA | ||
178 | * interrupt handler in the PCM driver. | ||
179 | */ | ||
180 | static irqreturn_t at91_ssc_interrupt(int irq, void *dev_id) | ||
181 | { | ||
182 | struct at91_ssc_info *ssc_p = dev_id; | ||
183 | struct at91_pcm_dma_params *dma_params; | ||
184 | u32 ssc_sr; | ||
185 | int i; | ||
186 | |||
187 | ssc_sr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR) | ||
188 | & at91_ssc_read(ssc_p->ssc.base + AT91_SSC_IMR); | ||
189 | |||
190 | /* | ||
191 | * Loop through the substreams attached to this SSC. If | ||
192 | * a DMA-related interrupt occurred on that substream, call | ||
193 | * the DMA interrupt handler function, if one has been | ||
194 | * registered in the dma_params structure by the PCM driver. | ||
195 | */ | ||
196 | for (i = 0; i < ARRAY_SIZE(ssc_p->dma_params); i++) { | ||
197 | dma_params = ssc_p->dma_params[i]; | ||
198 | |||
199 | if (dma_params != NULL && dma_params->dma_intr_handler != NULL && | ||
200 | (ssc_sr & | ||
201 | (dma_params->mask->ssc_endx | dma_params->mask->ssc_endbuf))) | ||
202 | |||
203 | dma_params->dma_intr_handler(ssc_sr, dma_params->substream); | ||
204 | } | ||
205 | |||
206 | return IRQ_HANDLED; | ||
207 | } | ||
208 | |||
209 | /* | ||
210 | * Startup. Only that one substream allowed in each direction. | ||
211 | */ | ||
212 | static int at91_ssc_startup(struct snd_pcm_substream *substream) | ||
213 | { | ||
214 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
215 | struct at91_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id]; | ||
216 | int dir_mask; | ||
217 | |||
218 | DBG("ssc_startup: SSC_SR=0x%08lx\n", | ||
219 | at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR)); | ||
220 | dir_mask = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0x1 : 0x2; | ||
221 | |||
222 | spin_lock_irq(&ssc_p->lock); | ||
223 | if (ssc_p->dir_mask & dir_mask) { | ||
224 | spin_unlock_irq(&ssc_p->lock); | ||
225 | return -EBUSY; | ||
226 | } | ||
227 | ssc_p->dir_mask |= dir_mask; | ||
228 | spin_unlock_irq(&ssc_p->lock); | ||
229 | |||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | /* | ||
234 | * Shutdown. Clear DMA parameters and shutdown the SSC if there | ||
235 | * are no other substreams open. | ||
236 | */ | ||
237 | static void at91_ssc_shutdown(struct snd_pcm_substream *substream) | ||
238 | { | ||
239 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
240 | struct at91_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id]; | ||
241 | struct at91_pcm_dma_params *dma_params; | ||
242 | int dir, dir_mask; | ||
243 | |||
244 | dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; | ||
245 | dma_params = ssc_p->dma_params[dir]; | ||
246 | |||
247 | if (dma_params != NULL) { | ||
248 | at91_ssc_write(dma_params->ssc_base + AT91_SSC_CR, | ||
249 | dma_params->mask->ssc_disable); | ||
250 | DBG("%s disabled SSC_SR=0x%08lx\n", (dir ? "receive" : "transmit"), | ||
251 | at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR)); | ||
252 | |||
253 | dma_params->ssc_base = NULL; | ||
254 | dma_params->substream = NULL; | ||
255 | ssc_p->dma_params[dir] = NULL; | ||
256 | } | ||
257 | |||
258 | dir_mask = 1 << dir; | ||
259 | |||
260 | spin_lock_irq(&ssc_p->lock); | ||
261 | ssc_p->dir_mask &= ~dir_mask; | ||
262 | if (!ssc_p->dir_mask) { | ||
263 | /* Shutdown the SSC clock. */ | ||
264 | DBG("Stopping pid %d clock\n", ssc_p->ssc.pid); | ||
265 | at91_sys_write(AT91_PMC_PCDR, 1<<ssc_p->ssc.pid); | ||
266 | |||
267 | if (ssc_p->initialized) { | ||
268 | free_irq(ssc_p->ssc.pid, ssc_p); | ||
269 | ssc_p->initialized = 0; | ||
270 | } | ||
271 | |||
272 | /* Reset the SSC */ | ||
273 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, AT91_SSC_SWRST); | ||
274 | |||
275 | /* Clear the SSC dividers */ | ||
276 | ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0; | ||
277 | } | ||
278 | spin_unlock_irq(&ssc_p->lock); | ||
279 | } | ||
280 | |||
281 | /* | ||
282 | * Record the SSC system clock rate. | ||
283 | */ | ||
284 | static int at91_ssc_set_dai_sysclk(struct snd_soc_dai *cpu_dai, | ||
285 | int clk_id, unsigned int freq, int dir) | ||
286 | { | ||
287 | /* | ||
288 | * The only clock supplied to the SSC is the AT91 master clock, | ||
289 | * which is only used if the SSC is generating BCLK and/or | ||
290 | * LRC clocks. | ||
291 | */ | ||
292 | switch (clk_id) { | ||
293 | case AT91_SYSCLK_MCK: | ||
294 | at91_ssc_sysclk = freq; | ||
295 | break; | ||
296 | default: | ||
297 | return -EINVAL; | ||
298 | } | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | /* | ||
304 | * Record the DAI format for use in hw_params(). | ||
305 | */ | ||
306 | static int at91_ssc_set_dai_fmt(struct snd_soc_dai *cpu_dai, | ||
307 | unsigned int fmt) | ||
308 | { | ||
309 | struct at91_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; | ||
310 | |||
311 | ssc_p->daifmt = fmt; | ||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | /* | ||
316 | * Record SSC clock dividers for use in hw_params(). | ||
317 | */ | ||
318 | static int at91_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai, | ||
319 | int div_id, int div) | ||
320 | { | ||
321 | struct at91_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; | ||
322 | |||
323 | switch (div_id) { | ||
324 | case AT91SSC_CMR_DIV: | ||
325 | /* | ||
326 | * The same master clock divider is used for both | ||
327 | * transmit and receive, so if a value has already | ||
328 | * been set, it must match this value. | ||
329 | */ | ||
330 | if (ssc_p->cmr_div == 0) | ||
331 | ssc_p->cmr_div = div; | ||
332 | else | ||
333 | if (div != ssc_p->cmr_div) | ||
334 | return -EBUSY; | ||
335 | break; | ||
336 | |||
337 | case AT91SSC_TCMR_PERIOD: | ||
338 | ssc_p->tcmr_period = div; | ||
339 | break; | ||
340 | |||
341 | case AT91SSC_RCMR_PERIOD: | ||
342 | ssc_p->rcmr_period = div; | ||
343 | break; | ||
344 | |||
345 | default: | ||
346 | return -EINVAL; | ||
347 | } | ||
348 | |||
349 | return 0; | ||
350 | } | ||
351 | |||
352 | /* | ||
353 | * Configure the SSC. | ||
354 | */ | ||
355 | static int at91_ssc_hw_params(struct snd_pcm_substream *substream, | ||
356 | struct snd_pcm_hw_params *params) | ||
357 | { | ||
358 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
359 | int id = rtd->dai->cpu_dai->id; | ||
360 | struct at91_ssc_info *ssc_p = &ssc_info[id]; | ||
361 | struct at91_pcm_dma_params *dma_params; | ||
362 | int dir, channels, bits; | ||
363 | u32 tfmr, rfmr, tcmr, rcmr; | ||
364 | int start_event; | ||
365 | int ret; | ||
366 | |||
367 | /* | ||
368 | * Currently, there is only one set of dma params for | ||
369 | * each direction. If more are added, this code will | ||
370 | * have to be changed to select the proper set. | ||
371 | */ | ||
372 | dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; | ||
373 | |||
374 | dma_params = &ssc_dma_params[id][dir]; | ||
375 | dma_params->ssc_base = ssc_p->ssc.base; | ||
376 | dma_params->substream = substream; | ||
377 | |||
378 | ssc_p->dma_params[dir] = dma_params; | ||
379 | |||
380 | /* | ||
381 | * The cpu_dai->dma_data field is only used to communicate the | ||
382 | * appropriate DMA parameters to the pcm driver hw_params() | ||
383 | * function. It should not be used for other purposes | ||
384 | * as it is common to all substreams. | ||
385 | */ | ||
386 | rtd->dai->cpu_dai->dma_data = dma_params; | ||
387 | |||
388 | channels = params_channels(params); | ||
389 | |||
390 | /* | ||
391 | * Determine sample size in bits and the PDC increment. | ||
392 | */ | ||
393 | switch(params_format(params)) { | ||
394 | case SNDRV_PCM_FORMAT_S8: | ||
395 | bits = 8; | ||
396 | dma_params->pdc_xfer_size = 1; | ||
397 | break; | ||
398 | case SNDRV_PCM_FORMAT_S16_LE: | ||
399 | bits = 16; | ||
400 | dma_params->pdc_xfer_size = 2; | ||
401 | break; | ||
402 | case SNDRV_PCM_FORMAT_S24_LE: | ||
403 | bits = 24; | ||
404 | dma_params->pdc_xfer_size = 4; | ||
405 | break; | ||
406 | case SNDRV_PCM_FORMAT_S32_LE: | ||
407 | bits = 32; | ||
408 | dma_params->pdc_xfer_size = 4; | ||
409 | break; | ||
410 | default: | ||
411 | printk(KERN_WARNING "at91-ssc: unsupported PCM format\n"); | ||
412 | return -EINVAL; | ||
413 | } | ||
414 | |||
415 | /* | ||
416 | * The SSC only supports up to 16-bit samples in I2S format, due | ||
417 | * to the size of the Frame Mode Register FSLEN field. | ||
418 | */ | ||
419 | if ((ssc_p->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S | ||
420 | && bits > 16) { | ||
421 | printk(KERN_WARNING | ||
422 | "at91-ssc: sample size %d is too large for I2S\n", bits); | ||
423 | return -EINVAL; | ||
424 | } | ||
425 | |||
426 | /* | ||
427 | * Compute SSC register settings. | ||
428 | */ | ||
429 | switch (ssc_p->daifmt | ||
430 | & (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_MASTER_MASK)) { | ||
431 | |||
432 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS: | ||
433 | /* | ||
434 | * I2S format, SSC provides BCLK and LRC clocks. | ||
435 | * | ||
436 | * The SSC transmit and receive clocks are generated from the | ||
437 | * MCK divider, and the BCLK signal is output on the SSC TK line. | ||
438 | */ | ||
439 | rcmr = (( ssc_p->rcmr_period << 24) & AT91_SSC_PERIOD) | ||
440 | | (( 1 << 16) & AT91_SSC_STTDLY) | ||
441 | | (( AT91_SSC_START_FALLING_RF ) & AT91_SSC_START) | ||
442 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) | ||
443 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) | ||
444 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); | ||
445 | |||
446 | rfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) | ||
447 | | (( AT91_SSC_FSOS_NEGATIVE ) & AT91_SSC_FSOS) | ||
448 | | (((bits - 1) << 16) & AT91_SSC_FSLEN) | ||
449 | | (((channels - 1) << 8) & AT91_SSC_DATNB) | ||
450 | | (( 1 << 7) & AT91_SSC_MSBF) | ||
451 | | (( 0 << 5) & AT91_SSC_LOOP) | ||
452 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); | ||
453 | |||
454 | tcmr = (( ssc_p->tcmr_period << 24) & AT91_SSC_PERIOD) | ||
455 | | (( 1 << 16) & AT91_SSC_STTDLY) | ||
456 | | (( AT91_SSC_START_FALLING_RF ) & AT91_SSC_START) | ||
457 | | (( AT91_SSC_CKI_FALLING ) & AT91_SSC_CKI) | ||
458 | | (( AT91_SSC_CKO_CONTINUOUS ) & AT91_SSC_CKO) | ||
459 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); | ||
460 | |||
461 | tfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) | ||
462 | | (( 0 << 23) & AT91_SSC_FSDEN) | ||
463 | | (( AT91_SSC_FSOS_NEGATIVE ) & AT91_SSC_FSOS) | ||
464 | | (((bits - 1) << 16) & AT91_SSC_FSLEN) | ||
465 | | (((channels - 1) << 8) & AT91_SSC_DATNB) | ||
466 | | (( 1 << 7) & AT91_SSC_MSBF) | ||
467 | | (( 0 << 5) & AT91_SSC_DATDEF) | ||
468 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); | ||
469 | break; | ||
470 | |||
471 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM: | ||
472 | /* | ||
473 | * I2S format, CODEC supplies BCLK and LRC clocks. | ||
474 | * | ||
475 | * The SSC transmit clock is obtained from the BCLK signal on | ||
476 | * on the TK line, and the SSC receive clock is generated from the | ||
477 | * transmit clock. | ||
478 | * | ||
479 | * For single channel data, one sample is transferred on the falling | ||
480 | * edge of the LRC clock. For two channel data, one sample is | ||
481 | * transferred on both edges of the LRC clock. | ||
482 | */ | ||
483 | start_event = channels == 1 | ||
484 | ? AT91_SSC_START_FALLING_RF | ||
485 | : AT91_SSC_START_EDGE_RF; | ||
486 | |||
487 | rcmr = (( 0 << 24) & AT91_SSC_PERIOD) | ||
488 | | (( 1 << 16) & AT91_SSC_STTDLY) | ||
489 | | (( start_event ) & AT91_SSC_START) | ||
490 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) | ||
491 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) | ||
492 | | (( AT91_SSC_CKS_CLOCK ) & AT91_SSC_CKS); | ||
493 | |||
494 | rfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) | ||
495 | | (( AT91_SSC_FSOS_NONE ) & AT91_SSC_FSOS) | ||
496 | | (( 0 << 16) & AT91_SSC_FSLEN) | ||
497 | | (( 0 << 8) & AT91_SSC_DATNB) | ||
498 | | (( 1 << 7) & AT91_SSC_MSBF) | ||
499 | | (( 0 << 5) & AT91_SSC_LOOP) | ||
500 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); | ||
501 | |||
502 | tcmr = (( 0 << 24) & AT91_SSC_PERIOD) | ||
503 | | (( 1 << 16) & AT91_SSC_STTDLY) | ||
504 | | (( start_event ) & AT91_SSC_START) | ||
505 | | (( AT91_SSC_CKI_FALLING ) & AT91_SSC_CKI) | ||
506 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) | ||
507 | | (( AT91_SSC_CKS_PIN ) & AT91_SSC_CKS); | ||
508 | |||
509 | tfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) | ||
510 | | (( 0 << 23) & AT91_SSC_FSDEN) | ||
511 | | (( AT91_SSC_FSOS_NONE ) & AT91_SSC_FSOS) | ||
512 | | (( 0 << 16) & AT91_SSC_FSLEN) | ||
513 | | (( 0 << 8) & AT91_SSC_DATNB) | ||
514 | | (( 1 << 7) & AT91_SSC_MSBF) | ||
515 | | (( 0 << 5) & AT91_SSC_DATDEF) | ||
516 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); | ||
517 | break; | ||
518 | |||
519 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS: | ||
520 | /* | ||
521 | * DSP/PCM Mode A format, SSC provides BCLK and LRC clocks. | ||
522 | * | ||
523 | * The SSC transmit and receive clocks are generated from the | ||
524 | * MCK divider, and the BCLK signal is output on the SSC TK line. | ||
525 | */ | ||
526 | rcmr = (( ssc_p->rcmr_period << 24) & AT91_SSC_PERIOD) | ||
527 | | (( 1 << 16) & AT91_SSC_STTDLY) | ||
528 | | (( AT91_SSC_START_RISING_RF ) & AT91_SSC_START) | ||
529 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) | ||
530 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) | ||
531 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); | ||
532 | |||
533 | rfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) | ||
534 | | (( AT91_SSC_FSOS_POSITIVE ) & AT91_SSC_FSOS) | ||
535 | | (( 0 << 16) & AT91_SSC_FSLEN) | ||
536 | | (((channels - 1) << 8) & AT91_SSC_DATNB) | ||
537 | | (( 1 << 7) & AT91_SSC_MSBF) | ||
538 | | (( 0 << 5) & AT91_SSC_LOOP) | ||
539 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); | ||
540 | |||
541 | tcmr = (( ssc_p->tcmr_period << 24) & AT91_SSC_PERIOD) | ||
542 | | (( 1 << 16) & AT91_SSC_STTDLY) | ||
543 | | (( AT91_SSC_START_RISING_RF ) & AT91_SSC_START) | ||
544 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) | ||
545 | | (( AT91_SSC_CKO_CONTINUOUS ) & AT91_SSC_CKO) | ||
546 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); | ||
547 | |||
548 | tfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) | ||
549 | | (( 0 << 23) & AT91_SSC_FSDEN) | ||
550 | | (( AT91_SSC_FSOS_POSITIVE ) & AT91_SSC_FSOS) | ||
551 | | (( 0 << 16) & AT91_SSC_FSLEN) | ||
552 | | (((channels - 1) << 8) & AT91_SSC_DATNB) | ||
553 | | (( 1 << 7) & AT91_SSC_MSBF) | ||
554 | | (( 0 << 5) & AT91_SSC_DATDEF) | ||
555 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); | ||
556 | |||
557 | |||
558 | |||
559 | break; | ||
560 | |||
561 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM: | ||
562 | default: | ||
563 | printk(KERN_WARNING "at91-ssc: unsupported DAI format 0x%x.\n", | ||
564 | ssc_p->daifmt); | ||
565 | return -EINVAL; | ||
566 | break; | ||
567 | } | ||
568 | DBG("RCMR=%08x RFMR=%08x TCMR=%08x TFMR=%08x\n", rcmr, rfmr, tcmr, tfmr); | ||
569 | |||
570 | if (!ssc_p->initialized) { | ||
571 | |||
572 | /* Enable PMC peripheral clock for this SSC */ | ||
573 | DBG("Starting pid %d clock\n", ssc_p->ssc.pid); | ||
574 | at91_sys_write(AT91_PMC_PCER, 1<<ssc_p->ssc.pid); | ||
575 | |||
576 | /* Reset the SSC and its PDC registers */ | ||
577 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, AT91_SSC_SWRST); | ||
578 | |||
579 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RPR, 0); | ||
580 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RCR, 0); | ||
581 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RNPR, 0); | ||
582 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RNCR, 0); | ||
583 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TPR, 0); | ||
584 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TCR, 0); | ||
585 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TNPR, 0); | ||
586 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TNCR, 0); | ||
587 | |||
588 | if ((ret = request_irq(ssc_p->ssc.pid, at91_ssc_interrupt, | ||
589 | 0, ssc_p->name, ssc_p)) < 0) { | ||
590 | printk(KERN_WARNING "at91-ssc: request_irq failure\n"); | ||
591 | |||
592 | DBG("Stopping pid %d clock\n", ssc_p->ssc.pid); | ||
593 | at91_sys_write(AT91_PMC_PCDR, 1<<ssc_p->ssc.pid); | ||
594 | return ret; | ||
595 | } | ||
596 | |||
597 | ssc_p->initialized = 1; | ||
598 | } | ||
599 | |||
600 | /* set SSC clock mode register */ | ||
601 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CMR, ssc_p->cmr_div); | ||
602 | |||
603 | /* set receive clock mode and format */ | ||
604 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RCMR, rcmr); | ||
605 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RFMR, rfmr); | ||
606 | |||
607 | /* set transmit clock mode and format */ | ||
608 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TCMR, tcmr); | ||
609 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TFMR, tfmr); | ||
610 | |||
611 | DBG("hw_params: SSC initialized\n"); | ||
612 | return 0; | ||
613 | } | ||
614 | |||
615 | |||
616 | static int at91_ssc_prepare(struct snd_pcm_substream *substream) | ||
617 | { | ||
618 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
619 | struct at91_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id]; | ||
620 | struct at91_pcm_dma_params *dma_params; | ||
621 | int dir; | ||
622 | |||
623 | dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; | ||
624 | dma_params = ssc_p->dma_params[dir]; | ||
625 | |||
626 | at91_ssc_write(dma_params->ssc_base + AT91_SSC_CR, | ||
627 | dma_params->mask->ssc_enable); | ||
628 | |||
629 | DBG("%s enabled SSC_SR=0x%08lx\n", dir ? "receive" : "transmit", | ||
630 | at91_ssc_read(dma_params->ssc_base + AT91_SSC_SR)); | ||
631 | return 0; | ||
632 | } | ||
633 | |||
634 | |||
635 | #ifdef CONFIG_PM | ||
636 | static int at91_ssc_suspend(struct platform_device *pdev, | ||
637 | struct snd_soc_dai *cpu_dai) | ||
638 | { | ||
639 | struct at91_ssc_info *ssc_p; | ||
640 | |||
641 | if(!cpu_dai->active) | ||
642 | return 0; | ||
643 | |||
644 | ssc_p = &ssc_info[cpu_dai->id]; | ||
645 | |||
646 | /* Save the status register before disabling transmit and receive. */ | ||
647 | ssc_p->ssc_state.ssc_sr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR); | ||
648 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, | ||
649 | AT91_SSC_TXDIS | AT91_SSC_RXDIS); | ||
650 | |||
651 | /* Save the current interrupt mask, then disable unmasked interrupts. */ | ||
652 | ssc_p->ssc_state.ssc_imr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_IMR); | ||
653 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_IDR, ssc_p->ssc_state.ssc_imr); | ||
654 | |||
655 | ssc_p->ssc_state.ssc_cmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_CMR); | ||
656 | ssc_p->ssc_state.ssc_rcmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_RCMR); | ||
657 | ssc_p->ssc_state.ssc_rfmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_RFMR); | ||
658 | ssc_p->ssc_state.ssc_tcmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_TCMR); | ||
659 | ssc_p->ssc_state.ssc_tfmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_TFMR); | ||
660 | |||
661 | return 0; | ||
662 | } | ||
663 | |||
664 | static int at91_ssc_resume(struct platform_device *pdev, | ||
665 | struct snd_soc_dai *cpu_dai) | ||
666 | { | ||
667 | struct at91_ssc_info *ssc_p; | ||
668 | |||
669 | if(!cpu_dai->active) | ||
670 | return 0; | ||
671 | |||
672 | ssc_p = &ssc_info[cpu_dai->id]; | ||
673 | |||
674 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TFMR, ssc_p->ssc_state.ssc_tfmr); | ||
675 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TCMR, ssc_p->ssc_state.ssc_tcmr); | ||
676 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RFMR, ssc_p->ssc_state.ssc_rfmr); | ||
677 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RCMR, ssc_p->ssc_state.ssc_rcmr); | ||
678 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CMR, ssc_p->ssc_state.ssc_cmr); | ||
679 | |||
680 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_IER, ssc_p->ssc_state.ssc_imr); | ||
681 | |||
682 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, | ||
683 | ((ssc_p->ssc_state.ssc_sr & AT91_SSC_RXENA) ? AT91_SSC_RXEN : 0) | | ||
684 | ((ssc_p->ssc_state.ssc_sr & AT91_SSC_TXENA) ? AT91_SSC_TXEN : 0)); | ||
685 | |||
686 | return 0; | ||
687 | } | ||
688 | |||
689 | #else | ||
690 | #define at91_ssc_suspend NULL | ||
691 | #define at91_ssc_resume NULL | ||
692 | #endif | ||
693 | |||
694 | #define AT91_SSC_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ | ||
695 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ | ||
696 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ | ||
697 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ | ||
698 | SNDRV_PCM_RATE_96000) | ||
699 | |||
700 | #define AT91_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ | ||
701 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) | ||
702 | |||
703 | struct snd_soc_dai at91_ssc_dai[NUM_SSC_DEVICES] = { | ||
704 | { .name = "at91-ssc0", | ||
705 | .id = 0, | ||
706 | .type = SND_SOC_DAI_PCM, | ||
707 | .suspend = at91_ssc_suspend, | ||
708 | .resume = at91_ssc_resume, | ||
709 | .playback = { | ||
710 | .channels_min = 1, | ||
711 | .channels_max = 2, | ||
712 | .rates = AT91_SSC_RATES, | ||
713 | .formats = AT91_SSC_FORMATS,}, | ||
714 | .capture = { | ||
715 | .channels_min = 1, | ||
716 | .channels_max = 2, | ||
717 | .rates = AT91_SSC_RATES, | ||
718 | .formats = AT91_SSC_FORMATS,}, | ||
719 | .ops = { | ||
720 | .startup = at91_ssc_startup, | ||
721 | .shutdown = at91_ssc_shutdown, | ||
722 | .prepare = at91_ssc_prepare, | ||
723 | .hw_params = at91_ssc_hw_params,}, | ||
724 | .dai_ops = { | ||
725 | .set_sysclk = at91_ssc_set_dai_sysclk, | ||
726 | .set_fmt = at91_ssc_set_dai_fmt, | ||
727 | .set_clkdiv = at91_ssc_set_dai_clkdiv,}, | ||
728 | .private_data = &ssc_info[0].ssc, | ||
729 | }, | ||
730 | #if NUM_SSC_DEVICES == 3 | ||
731 | { .name = "at91-ssc1", | ||
732 | .id = 1, | ||
733 | .type = SND_SOC_DAI_PCM, | ||
734 | .suspend = at91_ssc_suspend, | ||
735 | .resume = at91_ssc_resume, | ||
736 | .playback = { | ||
737 | .channels_min = 1, | ||
738 | .channels_max = 2, | ||
739 | .rates = AT91_SSC_RATES, | ||
740 | .formats = AT91_SSC_FORMATS,}, | ||
741 | .capture = { | ||
742 | .channels_min = 1, | ||
743 | .channels_max = 2, | ||
744 | .rates = AT91_SSC_RATES, | ||
745 | .formats = AT91_SSC_FORMATS,}, | ||
746 | .ops = { | ||
747 | .startup = at91_ssc_startup, | ||
748 | .shutdown = at91_ssc_shutdown, | ||
749 | .prepare = at91_ssc_prepare, | ||
750 | .hw_params = at91_ssc_hw_params,}, | ||
751 | .dai_ops = { | ||
752 | .set_sysclk = at91_ssc_set_dai_sysclk, | ||
753 | .set_fmt = at91_ssc_set_dai_fmt, | ||
754 | .set_clkdiv = at91_ssc_set_dai_clkdiv,}, | ||
755 | .private_data = &ssc_info[1].ssc, | ||
756 | }, | ||
757 | { .name = "at91-ssc2", | ||
758 | .id = 2, | ||
759 | .type = SND_SOC_DAI_PCM, | ||
760 | .suspend = at91_ssc_suspend, | ||
761 | .resume = at91_ssc_resume, | ||
762 | .playback = { | ||
763 | .channels_min = 1, | ||
764 | .channels_max = 2, | ||
765 | .rates = AT91_SSC_RATES, | ||
766 | .formats = AT91_SSC_FORMATS,}, | ||
767 | .capture = { | ||
768 | .channels_min = 1, | ||
769 | .channels_max = 2, | ||
770 | .rates = AT91_SSC_RATES, | ||
771 | .formats = AT91_SSC_FORMATS,}, | ||
772 | .ops = { | ||
773 | .startup = at91_ssc_startup, | ||
774 | .shutdown = at91_ssc_shutdown, | ||
775 | .prepare = at91_ssc_prepare, | ||
776 | .hw_params = at91_ssc_hw_params,}, | ||
777 | .dai_ops = { | ||
778 | .set_sysclk = at91_ssc_set_dai_sysclk, | ||
779 | .set_fmt = at91_ssc_set_dai_fmt, | ||
780 | .set_clkdiv = at91_ssc_set_dai_clkdiv,}, | ||
781 | .private_data = &ssc_info[2].ssc, | ||
782 | }, | ||
783 | #endif | ||
784 | }; | ||
785 | |||
786 | EXPORT_SYMBOL_GPL(at91_ssc_dai); | ||
787 | |||
788 | /* Module information */ | ||
789 | MODULE_AUTHOR("Frank Mandarino, fmandarino@endrelia.com, www.endrelia.com"); | ||
790 | MODULE_DESCRIPTION("AT91 SSC ASoC Interface"); | ||
791 | MODULE_LICENSE("GPL"); | ||
diff --git a/sound/soc/at91/at91-ssc.h b/sound/soc/at91/at91-ssc.h deleted file mode 100644 index 6b7bf382d06f..000000000000 --- a/sound/soc/at91/at91-ssc.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | * at91-ssc.h - ALSA SSC interface for the Atmel AT91 SoC | ||
3 | * | ||
4 | * Author: Frank Mandarino <fmandarino@endrelia.com> | ||
5 | * Endrelia Technologies Inc. | ||
6 | * Created: Jan 9, 2007 | ||
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 | #ifndef _AT91_SSC_H | ||
14 | #define _AT91_SSC_H | ||
15 | |||
16 | /* SSC system clock ids */ | ||
17 | #define AT91_SYSCLK_MCK 0 /* SSC uses AT91 MCK as system clock */ | ||
18 | |||
19 | /* SSC divider ids */ | ||
20 | #define AT91SSC_CMR_DIV 0 /* MCK divider for BCLK */ | ||
21 | #define AT91SSC_TCMR_PERIOD 1 /* BCLK divider for transmit FS */ | ||
22 | #define AT91SSC_RCMR_PERIOD 2 /* BCLK divider for receive FS */ | ||
23 | |||
24 | extern struct snd_soc_dai at91_ssc_dai[]; | ||
25 | |||
26 | #endif /* _AT91_SSC_H */ | ||
27 | |||