2 * atmel_ssc_dai.c -- ALSA SoC ATMEL SSC Audio Layer Platform driver
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2008 Atmel
7 * Author: Sedji Gaouaou <sedji.gaouaou@atmel.com>
10 * Based on at91-ssc.c by
11 * Frank Mandarino <fmandarino@endrelia.com>
12 * Based on pxa2xx Platform drivers by
13 * Liam Girdwood <lrg@slimlogic.co.uk>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <linux/init.h>
31 #include <linux/module.h>
32 #include <linux/interrupt.h>
33 #include <linux/device.h>
34 #include <linux/delay.h>
35 #include <linux/clk.h>
36 #include <linux/atmel_pdc.h>
38 #include <linux/atmel-ssc.h>
39 #include <sound/core.h>
40 #include <sound/pcm.h>
41 #include <sound/pcm_params.h>
42 #include <sound/initval.h>
43 #include <sound/soc.h>
45 #include <mach/hardware.h>
47 #include "atmel-pcm.h"
48 #include "atmel_ssc_dai.h"
51 #define NUM_SSC_DEVICES 3
54 * SSC PDC registers required by the PCM DMA engine.
56 static struct atmel_pdc_regs pdc_tx_reg = {
59 .xnpr = ATMEL_PDC_TNPR,
60 .xncr = ATMEL_PDC_TNCR,
63 static struct atmel_pdc_regs pdc_rx_reg = {
66 .xnpr = ATMEL_PDC_RNPR,
67 .xncr = ATMEL_PDC_RNCR,
71 * SSC & PDC status bits for transmit and receive.
73 static struct atmel_ssc_mask ssc_tx_mask = {
74 .ssc_enable = SSC_BIT(CR_TXEN),
75 .ssc_disable = SSC_BIT(CR_TXDIS),
76 .ssc_endx = SSC_BIT(SR_ENDTX),
77 .ssc_endbuf = SSC_BIT(SR_TXBUFE),
78 .pdc_enable = ATMEL_PDC_TXTEN,
79 .pdc_disable = ATMEL_PDC_TXTDIS,
82 static struct atmel_ssc_mask ssc_rx_mask = {
83 .ssc_enable = SSC_BIT(CR_RXEN),
84 .ssc_disable = SSC_BIT(CR_RXDIS),
85 .ssc_endx = SSC_BIT(SR_ENDRX),
86 .ssc_endbuf = SSC_BIT(SR_RXBUFF),
87 .pdc_enable = ATMEL_PDC_RXTEN,
88 .pdc_disable = ATMEL_PDC_RXTDIS,
95 static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
97 .name = "SSC0 PCM out",
102 .name = "SSC0 PCM in",
104 .mask = &ssc_rx_mask,
107 .name = "SSC1 PCM out",
109 .mask = &ssc_tx_mask,
112 .name = "SSC1 PCM in",
114 .mask = &ssc_rx_mask,
117 .name = "SSC2 PCM out",
119 .mask = &ssc_tx_mask,
122 .name = "SSC2 PCM in",
124 .mask = &ssc_rx_mask,
129 static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = {
132 .lock = __SPIN_LOCK_UNLOCKED(ssc_info[0].lock),
133 .dir_mask = SSC_DIR_MASK_UNUSED,
138 .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock),
139 .dir_mask = SSC_DIR_MASK_UNUSED,
144 .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock),
145 .dir_mask = SSC_DIR_MASK_UNUSED,
152 * SSC interrupt handler. Passes PDC interrupts to the DMA
153 * interrupt handler in the PCM driver.
155 static irqreturn_t atmel_ssc_interrupt(int irq, void *dev_id)
157 struct atmel_ssc_info *ssc_p = dev_id;
158 struct atmel_pcm_dma_params *dma_params;
160 u32 ssc_substream_mask;
163 ssc_sr = (unsigned long)ssc_readl(ssc_p->ssc->regs, SR)
164 & (unsigned long)ssc_readl(ssc_p->ssc->regs, IMR);
167 * Loop through the substreams attached to this SSC. If
168 * a DMA-related interrupt occurred on that substream, call
169 * the DMA interrupt handler function, if one has been
170 * registered in the dma_params structure by the PCM driver.
172 for (i = 0; i < ARRAY_SIZE(ssc_p->dma_params); i++) {
173 dma_params = ssc_p->dma_params[i];
175 if ((dma_params != NULL) &&
176 (dma_params->dma_intr_handler != NULL)) {
177 ssc_substream_mask = (dma_params->mask->ssc_endx |
178 dma_params->mask->ssc_endbuf);
179 if (ssc_sr & ssc_substream_mask) {
180 dma_params->dma_intr_handler(ssc_sr,
191 /*-------------------------------------------------------------------------*\
193 \*-------------------------------------------------------------------------*/
195 * Startup. Only that one substream allowed in each direction.
197 static int atmel_ssc_startup(struct snd_pcm_substream *substream,
198 struct snd_soc_dai *dai)
200 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
203 pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n",
204 ssc_readl(ssc_p->ssc->regs, SR));
206 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
207 dir_mask = SSC_DIR_MASK_PLAYBACK;
209 dir_mask = SSC_DIR_MASK_CAPTURE;
211 spin_lock_irq(&ssc_p->lock);
212 if (ssc_p->dir_mask & dir_mask) {
213 spin_unlock_irq(&ssc_p->lock);
216 ssc_p->dir_mask |= dir_mask;
217 spin_unlock_irq(&ssc_p->lock);
223 * Shutdown. Clear DMA parameters and shutdown the SSC if there
224 * are no other substreams open.
226 static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
227 struct snd_soc_dai *dai)
229 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
230 struct atmel_pcm_dma_params *dma_params;
233 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
238 dma_params = ssc_p->dma_params[dir];
240 if (dma_params != NULL) {
241 ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable);
242 pr_debug("atmel_ssc_shutdown: %s disabled SSC_SR=0x%08x\n",
243 (dir ? "receive" : "transmit"),
244 ssc_readl(ssc_p->ssc->regs, SR));
246 dma_params->ssc = NULL;
247 dma_params->substream = NULL;
248 ssc_p->dma_params[dir] = NULL;
253 spin_lock_irq(&ssc_p->lock);
254 ssc_p->dir_mask &= ~dir_mask;
255 if (!ssc_p->dir_mask) {
256 if (ssc_p->initialized) {
257 /* Shutdown the SSC clock. */
258 pr_debug("atmel_ssc_dau: Stopping clock\n");
259 clk_disable(ssc_p->ssc->clk);
261 free_irq(ssc_p->ssc->irq, ssc_p);
262 ssc_p->initialized = 0;
266 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
267 /* Clear the SSC dividers */
268 ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
270 spin_unlock_irq(&ssc_p->lock);
275 * Record the DAI format for use in hw_params().
277 static int atmel_ssc_set_dai_fmt(struct snd_soc_dai *cpu_dai,
280 struct atmel_ssc_info *ssc_p = &ssc_info[cpu_dai->id];
287 * Record SSC clock dividers for use in hw_params().
289 static int atmel_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
292 struct atmel_ssc_info *ssc_p = &ssc_info[cpu_dai->id];
295 case ATMEL_SSC_CMR_DIV:
297 * The same master clock divider is used for both
298 * transmit and receive, so if a value has already
299 * been set, it must match this value.
301 if (ssc_p->cmr_div == 0)
302 ssc_p->cmr_div = div;
304 if (div != ssc_p->cmr_div)
308 case ATMEL_SSC_TCMR_PERIOD:
309 ssc_p->tcmr_period = div;
312 case ATMEL_SSC_RCMR_PERIOD:
313 ssc_p->rcmr_period = div;
326 static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
327 struct snd_pcm_hw_params *params,
328 struct snd_soc_dai *dai)
330 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
332 struct atmel_ssc_info *ssc_p = &ssc_info[id];
333 struct atmel_pcm_dma_params *dma_params;
334 int dir, channels, bits;
335 u32 tfmr, rfmr, tcmr, rcmr;
340 * Currently, there is only one set of dma params for
341 * each direction. If more are added, this code will
342 * have to be changed to select the proper set.
344 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
349 dma_params = &ssc_dma_params[id][dir];
350 dma_params->ssc = ssc_p->ssc;
351 dma_params->substream = substream;
353 ssc_p->dma_params[dir] = dma_params;
356 * The snd_soc_pcm_stream->dma_data field is only used to communicate
357 * the appropriate DMA parameters to the pcm driver hw_params()
358 * function. It should not be used for other purposes
359 * as it is common to all substreams.
361 snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_params);
363 channels = params_channels(params);
366 * Determine sample size in bits and the PDC increment.
368 switch (params_format(params)) {
369 case SNDRV_PCM_FORMAT_S8:
371 dma_params->pdc_xfer_size = 1;
373 case SNDRV_PCM_FORMAT_S16_LE:
375 dma_params->pdc_xfer_size = 2;
377 case SNDRV_PCM_FORMAT_S24_LE:
379 dma_params->pdc_xfer_size = 4;
381 case SNDRV_PCM_FORMAT_S32_LE:
383 dma_params->pdc_xfer_size = 4;
386 printk(KERN_WARNING "atmel_ssc_dai: unsupported PCM format");
391 * The SSC only supports up to 16-bit samples in I2S format, due
392 * to the size of the Frame Mode Register FSLEN field.
394 if ((ssc_p->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S
397 "atmel_ssc_dai: sample size %d "
398 "is too large for I2S\n", bits);
403 * Compute SSC register settings.
405 switch (ssc_p->daifmt
406 & (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_MASTER_MASK)) {
408 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS:
410 * I2S format, SSC provides BCLK and LRC clocks.
412 * The SSC transmit and receive clocks are generated
413 * from the MCK divider, and the BCLK signal
414 * is output on the SSC TK line.
416 rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period)
417 | SSC_BF(RCMR_STTDLY, START_DELAY)
418 | SSC_BF(RCMR_START, SSC_START_FALLING_RF)
419 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
420 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
421 | SSC_BF(RCMR_CKS, SSC_CKS_DIV);
423 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
424 | SSC_BF(RFMR_FSOS, SSC_FSOS_NEGATIVE)
425 | SSC_BF(RFMR_FSLEN, (bits - 1))
426 | SSC_BF(RFMR_DATNB, (channels - 1))
428 | SSC_BF(RFMR_LOOP, 0)
429 | SSC_BF(RFMR_DATLEN, (bits - 1));
431 tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period)
432 | SSC_BF(TCMR_STTDLY, START_DELAY)
433 | SSC_BF(TCMR_START, SSC_START_FALLING_RF)
434 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
435 | SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS)
436 | SSC_BF(TCMR_CKS, SSC_CKS_DIV);
438 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
439 | SSC_BF(TFMR_FSDEN, 0)
440 | SSC_BF(TFMR_FSOS, SSC_FSOS_NEGATIVE)
441 | SSC_BF(TFMR_FSLEN, (bits - 1))
442 | SSC_BF(TFMR_DATNB, (channels - 1))
444 | SSC_BF(TFMR_DATDEF, 0)
445 | SSC_BF(TFMR_DATLEN, (bits - 1));
448 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM:
450 * I2S format, CODEC supplies BCLK and LRC clocks.
452 * The SSC transmit clock is obtained from the BCLK signal on
453 * on the TK line, and the SSC receive clock is
454 * generated from the transmit clock.
456 * For single channel data, one sample is transferred
457 * on the falling edge of the LRC clock.
458 * For two channel data, one sample is
459 * transferred on both edges of the LRC clock.
461 start_event = ((channels == 1)
462 ? SSC_START_FALLING_RF
463 : SSC_START_EDGE_RF);
465 rcmr = SSC_BF(RCMR_PERIOD, 0)
466 | SSC_BF(RCMR_STTDLY, START_DELAY)
467 | SSC_BF(RCMR_START, start_event)
468 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
469 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
470 | SSC_BF(RCMR_CKS, SSC_CKS_CLOCK);
472 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
473 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE)
474 | SSC_BF(RFMR_FSLEN, 0)
475 | SSC_BF(RFMR_DATNB, 0)
477 | SSC_BF(RFMR_LOOP, 0)
478 | SSC_BF(RFMR_DATLEN, (bits - 1));
480 tcmr = SSC_BF(TCMR_PERIOD, 0)
481 | SSC_BF(TCMR_STTDLY, START_DELAY)
482 | SSC_BF(TCMR_START, start_event)
483 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
484 | SSC_BF(TCMR_CKO, SSC_CKO_NONE)
485 | SSC_BF(TCMR_CKS, SSC_CKS_PIN);
487 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
488 | SSC_BF(TFMR_FSDEN, 0)
489 | SSC_BF(TFMR_FSOS, SSC_FSOS_NONE)
490 | SSC_BF(TFMR_FSLEN, 0)
491 | SSC_BF(TFMR_DATNB, 0)
493 | SSC_BF(TFMR_DATDEF, 0)
494 | SSC_BF(TFMR_DATLEN, (bits - 1));
497 case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS:
499 * DSP/PCM Mode A format, SSC provides BCLK and LRC clocks.
501 * The SSC transmit and receive clocks are generated from the
502 * MCK divider, and the BCLK signal is output
503 * on the SSC TK line.
505 rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period)
506 | SSC_BF(RCMR_STTDLY, 1)
507 | SSC_BF(RCMR_START, SSC_START_RISING_RF)
508 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
509 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
510 | SSC_BF(RCMR_CKS, SSC_CKS_DIV);
512 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
513 | SSC_BF(RFMR_FSOS, SSC_FSOS_POSITIVE)
514 | SSC_BF(RFMR_FSLEN, 0)
515 | SSC_BF(RFMR_DATNB, (channels - 1))
517 | SSC_BF(RFMR_LOOP, 0)
518 | SSC_BF(RFMR_DATLEN, (bits - 1));
520 tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period)
521 | SSC_BF(TCMR_STTDLY, 1)
522 | SSC_BF(TCMR_START, SSC_START_RISING_RF)
523 | SSC_BF(TCMR_CKI, SSC_CKI_RISING)
524 | SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS)
525 | SSC_BF(TCMR_CKS, SSC_CKS_DIV);
527 tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
528 | SSC_BF(TFMR_FSDEN, 0)
529 | SSC_BF(TFMR_FSOS, SSC_FSOS_POSITIVE)
530 | SSC_BF(TFMR_FSLEN, 0)
531 | SSC_BF(TFMR_DATNB, (channels - 1))
533 | SSC_BF(TFMR_DATDEF, 0)
534 | SSC_BF(TFMR_DATLEN, (bits - 1));
537 case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM:
539 printk(KERN_WARNING "atmel_ssc_dai: unsupported DAI format 0x%x\n",
543 pr_debug("atmel_ssc_hw_params: "
544 "RCMR=%08x RFMR=%08x TCMR=%08x TFMR=%08x\n",
545 rcmr, rfmr, tcmr, tfmr);
547 if (!ssc_p->initialized) {
549 /* Enable PMC peripheral clock for this SSC */
550 pr_debug("atmel_ssc_dai: Starting clock\n");
551 clk_enable(ssc_p->ssc->clk);
553 /* Reset the SSC and its PDC registers */
554 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
556 ssc_writel(ssc_p->ssc->regs, PDC_RPR, 0);
557 ssc_writel(ssc_p->ssc->regs, PDC_RCR, 0);
558 ssc_writel(ssc_p->ssc->regs, PDC_RNPR, 0);
559 ssc_writel(ssc_p->ssc->regs, PDC_RNCR, 0);
561 ssc_writel(ssc_p->ssc->regs, PDC_TPR, 0);
562 ssc_writel(ssc_p->ssc->regs, PDC_TCR, 0);
563 ssc_writel(ssc_p->ssc->regs, PDC_TNPR, 0);
564 ssc_writel(ssc_p->ssc->regs, PDC_TNCR, 0);
566 ret = request_irq(ssc_p->ssc->irq, atmel_ssc_interrupt, 0,
570 "atmel_ssc_dai: request_irq failure\n");
571 pr_debug("Atmel_ssc_dai: Stoping clock\n");
572 clk_disable(ssc_p->ssc->clk);
576 ssc_p->initialized = 1;
579 /* set SSC clock mode register */
580 ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->cmr_div);
582 /* set receive clock mode and format */
583 ssc_writel(ssc_p->ssc->regs, RCMR, rcmr);
584 ssc_writel(ssc_p->ssc->regs, RFMR, rfmr);
586 /* set transmit clock mode and format */
587 ssc_writel(ssc_p->ssc->regs, TCMR, tcmr);
588 ssc_writel(ssc_p->ssc->regs, TFMR, tfmr);
590 pr_debug("atmel_ssc_dai,hw_params: SSC initialized\n");
595 static int atmel_ssc_prepare(struct snd_pcm_substream *substream,
596 struct snd_soc_dai *dai)
598 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
599 struct atmel_pcm_dma_params *dma_params;
602 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
607 dma_params = ssc_p->dma_params[dir];
609 ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_enable);
611 pr_debug("%s enabled SSC_SR=0x%08x\n",
612 dir ? "receive" : "transmit",
613 ssc_readl(ssc_p->ssc->regs, SR));
619 static int atmel_ssc_suspend(struct snd_soc_dai *cpu_dai)
621 struct atmel_ssc_info *ssc_p;
623 if (!cpu_dai->active)
626 ssc_p = &ssc_info[cpu_dai->id];
628 /* Save the status register before disabling transmit and receive */
629 ssc_p->ssc_state.ssc_sr = ssc_readl(ssc_p->ssc->regs, SR);
630 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_TXDIS) | SSC_BIT(CR_RXDIS));
632 /* Save the current interrupt mask, then disable unmasked interrupts */
633 ssc_p->ssc_state.ssc_imr = ssc_readl(ssc_p->ssc->regs, IMR);
634 ssc_writel(ssc_p->ssc->regs, IDR, ssc_p->ssc_state.ssc_imr);
636 ssc_p->ssc_state.ssc_cmr = ssc_readl(ssc_p->ssc->regs, CMR);
637 ssc_p->ssc_state.ssc_rcmr = ssc_readl(ssc_p->ssc->regs, RCMR);
638 ssc_p->ssc_state.ssc_rfmr = ssc_readl(ssc_p->ssc->regs, RFMR);
639 ssc_p->ssc_state.ssc_tcmr = ssc_readl(ssc_p->ssc->regs, TCMR);
640 ssc_p->ssc_state.ssc_tfmr = ssc_readl(ssc_p->ssc->regs, TFMR);
647 static int atmel_ssc_resume(struct snd_soc_dai *cpu_dai)
649 struct atmel_ssc_info *ssc_p;
652 if (!cpu_dai->active)
655 ssc_p = &ssc_info[cpu_dai->id];
657 /* restore SSC register settings */
658 ssc_writel(ssc_p->ssc->regs, TFMR, ssc_p->ssc_state.ssc_tfmr);
659 ssc_writel(ssc_p->ssc->regs, TCMR, ssc_p->ssc_state.ssc_tcmr);
660 ssc_writel(ssc_p->ssc->regs, RFMR, ssc_p->ssc_state.ssc_rfmr);
661 ssc_writel(ssc_p->ssc->regs, RCMR, ssc_p->ssc_state.ssc_rcmr);
662 ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->ssc_state.ssc_cmr);
664 /* re-enable interrupts */
665 ssc_writel(ssc_p->ssc->regs, IER, ssc_p->ssc_state.ssc_imr);
667 /* Re-enable receive and transmit as appropriate */
670 (ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_RXEN)) ? SSC_BIT(CR_RXEN) : 0;
672 (ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_TXEN)) ? SSC_BIT(CR_TXEN) : 0;
673 ssc_writel(ssc_p->ssc->regs, CR, cr);
677 #else /* CONFIG_PM */
678 # define atmel_ssc_suspend NULL
679 # define atmel_ssc_resume NULL
680 #endif /* CONFIG_PM */
682 static int atmel_ssc_probe(struct snd_soc_dai *dai)
684 struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
686 snd_soc_dai_set_drvdata(dai, ssc_p);
691 #define ATMEL_SSC_RATES (SNDRV_PCM_RATE_8000_96000)
693 #define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
694 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
696 static const struct snd_soc_dai_ops atmel_ssc_dai_ops = {
697 .startup = atmel_ssc_startup,
698 .shutdown = atmel_ssc_shutdown,
699 .prepare = atmel_ssc_prepare,
700 .hw_params = atmel_ssc_hw_params,
701 .set_fmt = atmel_ssc_set_dai_fmt,
702 .set_clkdiv = atmel_ssc_set_dai_clkdiv,
705 static struct snd_soc_dai_driver atmel_ssc_dai = {
706 .probe = atmel_ssc_probe,
707 .suspend = atmel_ssc_suspend,
708 .resume = atmel_ssc_resume,
712 .rates = ATMEL_SSC_RATES,
713 .formats = ATMEL_SSC_FORMATS,},
717 .rates = ATMEL_SSC_RATES,
718 .formats = ATMEL_SSC_FORMATS,},
719 .ops = &atmel_ssc_dai_ops,
722 static int asoc_ssc_init(struct device *dev)
724 struct platform_device *pdev = to_platform_device(dev);
725 struct ssc_device *ssc = platform_get_drvdata(pdev);
728 ret = snd_soc_register_dai(dev, &atmel_ssc_dai);
730 dev_err(dev, "Could not register DAI: %d\n", ret);
734 if (ssc->pdata->use_dma)
735 ret = atmel_pcm_dma_platform_register(dev);
737 ret = atmel_pcm_pdc_platform_register(dev);
740 dev_err(dev, "Could not register PCM: %d\n", ret);
741 goto err_unregister_dai;
747 snd_soc_unregister_dai(dev);
752 static void asoc_ssc_exit(struct device *dev)
754 struct platform_device *pdev = to_platform_device(dev);
755 struct ssc_device *ssc = platform_get_drvdata(pdev);
757 if (ssc->pdata->use_dma)
758 atmel_pcm_dma_platform_unregister(dev);
760 atmel_pcm_pdc_platform_unregister(dev);
762 snd_soc_unregister_dai(dev);
766 * atmel_ssc_set_audio - Allocate the specified SSC for audio use.
768 int atmel_ssc_set_audio(int ssc_id)
770 struct ssc_device *ssc;
773 /* If we can grab the SSC briefly to parent the DAI device off it */
774 ssc = ssc_request(ssc_id);
776 pr_err("Unable to parent ASoC SSC DAI on SSC: %ld\n",
780 ssc_info[ssc_id].ssc = ssc;
783 ret = asoc_ssc_init(&ssc->pdev->dev);
787 EXPORT_SYMBOL_GPL(atmel_ssc_set_audio);
789 void atmel_ssc_put_audio(int ssc_id)
791 struct ssc_device *ssc = ssc_info[ssc_id].ssc;
794 asoc_ssc_exit(&ssc->pdev->dev);
796 EXPORT_SYMBOL_GPL(atmel_ssc_put_audio);
798 /* Module information */
799 MODULE_AUTHOR("Sedji Gaouaou, sedji.gaouaou@atmel.com, www.atmel.com");
800 MODULE_DESCRIPTION("ATMEL SSC ASoC Interface");
801 MODULE_LICENSE("GPL");