Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 1 | /* |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 2 | * at91-ssc.c -- ALSA SoC AT91 SSC Audio Layer Platform driver |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 3 | * |
| 4 | * Author: Frank Mandarino <fmandarino@endrelia.com> |
| 5 | * Endrelia Technologies Inc. |
| 6 | * |
| 7 | * Based on pxa2xx Platform drivers by |
| 8 | * Liam Girdwood <liam.girdwood@wolfsonmicro.com> |
| 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 | * |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 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> |
Frank Mandarino | fa8f878 | 2007-02-12 14:06:22 +0100 | [diff] [blame] | 23 | #include <linux/atmel_pdc.h> |
| 24 | |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 25 | #include <sound/driver.h> |
| 26 | #include <sound/core.h> |
| 27 | #include <sound/pcm.h> |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 28 | #include <sound/pcm_params.h> |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 29 | #include <sound/initval.h> |
| 30 | #include <sound/soc.h> |
| 31 | |
| 32 | #include <asm/arch/hardware.h> |
| 33 | #include <asm/arch/at91_pmc.h> |
| 34 | #include <asm/arch/at91_ssc.h> |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 35 | |
| 36 | #include "at91-pcm.h" |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 37 | #include "at91-ssc.h" |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 38 | |
| 39 | #if 0 |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 40 | #define DBG(x...) printk(KERN_DEBUG "at91-ssc:" x) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 41 | #else |
| 42 | #define DBG(x...) |
| 43 | #endif |
| 44 | |
| 45 | #if defined(CONFIG_ARCH_AT91SAM9260) |
| 46 | #define NUM_SSC_DEVICES 1 |
| 47 | #else |
| 48 | #define NUM_SSC_DEVICES 3 |
| 49 | #endif |
| 50 | |
| 51 | |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 52 | /* |
| 53 | * SSC PDC registers required by the PCM DMA engine. |
| 54 | */ |
| 55 | static struct at91_pdc_regs pdc_tx_reg = { |
Frank Mandarino | fa8f878 | 2007-02-12 14:06:22 +0100 | [diff] [blame] | 56 | .xpr = ATMEL_PDC_TPR, |
| 57 | .xcr = ATMEL_PDC_TCR, |
| 58 | .xnpr = ATMEL_PDC_TNPR, |
| 59 | .xncr = ATMEL_PDC_TNCR, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static struct at91_pdc_regs pdc_rx_reg = { |
Frank Mandarino | fa8f878 | 2007-02-12 14:06:22 +0100 | [diff] [blame] | 63 | .xpr = ATMEL_PDC_RPR, |
| 64 | .xcr = ATMEL_PDC_RCR, |
| 65 | .xnpr = ATMEL_PDC_RNPR, |
| 66 | .xncr = ATMEL_PDC_RNCR, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * SSC & PDC status bits for transmit and receive. |
| 71 | */ |
| 72 | static struct at91_ssc_mask ssc_tx_mask = { |
| 73 | .ssc_enable = AT91_SSC_TXEN, |
| 74 | .ssc_disable = AT91_SSC_TXDIS, |
| 75 | .ssc_endx = AT91_SSC_ENDTX, |
| 76 | .ssc_endbuf = AT91_SSC_TXBUFE, |
Frank Mandarino | fa8f878 | 2007-02-12 14:06:22 +0100 | [diff] [blame] | 77 | .pdc_enable = ATMEL_PDC_TXTEN, |
| 78 | .pdc_disable = ATMEL_PDC_TXTDIS, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static struct at91_ssc_mask ssc_rx_mask = { |
| 82 | .ssc_enable = AT91_SSC_RXEN, |
| 83 | .ssc_disable = AT91_SSC_RXDIS, |
| 84 | .ssc_endx = AT91_SSC_ENDRX, |
| 85 | .ssc_endbuf = AT91_SSC_RXBUFF, |
Frank Mandarino | fa8f878 | 2007-02-12 14:06:22 +0100 | [diff] [blame] | 86 | .pdc_enable = ATMEL_PDC_RXTEN, |
| 87 | .pdc_disable = ATMEL_PDC_RXTDIS, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * DMA parameters. |
| 93 | */ |
| 94 | static struct at91_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = { |
| 95 | {{ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 96 | .name = "SSC0 PCM out", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 97 | .pdc = &pdc_tx_reg, |
| 98 | .mask = &ssc_tx_mask, |
| 99 | }, |
| 100 | { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 101 | .name = "SSC0 PCM in", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 102 | .pdc = &pdc_rx_reg, |
| 103 | .mask = &ssc_rx_mask, |
| 104 | }}, |
| 105 | #if NUM_SSC_DEVICES == 3 |
| 106 | {{ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 107 | .name = "SSC1 PCM out", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 108 | .pdc = &pdc_tx_reg, |
| 109 | .mask = &ssc_tx_mask, |
| 110 | }, |
| 111 | { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 112 | .name = "SSC1 PCM in", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 113 | .pdc = &pdc_rx_reg, |
| 114 | .mask = &ssc_rx_mask, |
| 115 | }}, |
| 116 | {{ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 117 | .name = "SSC2 PCM out", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 118 | .pdc = &pdc_tx_reg, |
| 119 | .mask = &ssc_tx_mask, |
| 120 | }, |
| 121 | { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 122 | .name = "SSC2 PCM in", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 123 | .pdc = &pdc_rx_reg, |
| 124 | .mask = &ssc_rx_mask, |
| 125 | }}, |
| 126 | #endif |
| 127 | }; |
| 128 | |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 129 | struct at91_ssc_state { |
| 130 | u32 ssc_cmr; |
| 131 | u32 ssc_rcmr; |
| 132 | u32 ssc_rfmr; |
| 133 | u32 ssc_tcmr; |
| 134 | u32 ssc_tfmr; |
| 135 | u32 ssc_sr; |
| 136 | u32 ssc_imr; |
| 137 | }; |
| 138 | |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 139 | static struct at91_ssc_info { |
| 140 | char *name; |
| 141 | struct at91_ssc_periph ssc; |
| 142 | spinlock_t lock; /* lock for dir_mask */ |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 143 | unsigned short dir_mask; /* 0=unused, 1=playback, 2=capture */ |
| 144 | unsigned short initialized; /* 1=SSC has been initialized */ |
| 145 | unsigned short daifmt; |
| 146 | unsigned short cmr_div; |
| 147 | unsigned short tcmr_period; |
| 148 | unsigned short rcmr_period; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 149 | struct at91_pcm_dma_params *dma_params[2]; |
| 150 | struct at91_ssc_state ssc_state; |
| 151 | |
| 152 | } ssc_info[NUM_SSC_DEVICES] = { |
| 153 | { |
| 154 | .name = "ssc0", |
Milind Arun Choudhary | c9758b2 | 2007-04-19 15:22:56 +0200 | [diff] [blame] | 155 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[0].lock), |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 156 | .dir_mask = 0, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 157 | .initialized = 0, |
| 158 | }, |
| 159 | #if NUM_SSC_DEVICES == 3 |
| 160 | { |
| 161 | .name = "ssc1", |
Milind Arun Choudhary | c9758b2 | 2007-04-19 15:22:56 +0200 | [diff] [blame] | 162 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock), |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 163 | .dir_mask = 0, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 164 | .initialized = 0, |
| 165 | }, |
| 166 | { |
| 167 | .name = "ssc2", |
Milind Arun Choudhary | c9758b2 | 2007-04-19 15:22:56 +0200 | [diff] [blame] | 168 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock), |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 169 | .dir_mask = 0, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 170 | .initialized = 0, |
| 171 | }, |
| 172 | #endif |
| 173 | }; |
| 174 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 175 | static unsigned int at91_ssc_sysclk; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 176 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 177 | /* |
| 178 | * SSC interrupt handler. Passes PDC interrupts to the DMA |
| 179 | * interrupt handler in the PCM driver. |
| 180 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 181 | static irqreturn_t at91_ssc_interrupt(int irq, void *dev_id) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 182 | { |
| 183 | struct at91_ssc_info *ssc_p = dev_id; |
| 184 | struct at91_pcm_dma_params *dma_params; |
| 185 | u32 ssc_sr; |
| 186 | int i; |
| 187 | |
| 188 | ssc_sr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR) |
| 189 | & at91_ssc_read(ssc_p->ssc.base + AT91_SSC_IMR); |
| 190 | |
| 191 | /* |
| 192 | * Loop through the substreams attached to this SSC. If |
| 193 | * a DMA-related interrupt occurred on that substream, call |
| 194 | * the DMA interrupt handler function, if one has been |
| 195 | * registered in the dma_params structure by the PCM driver. |
| 196 | */ |
| 197 | for (i = 0; i < ARRAY_SIZE(ssc_p->dma_params); i++) { |
| 198 | dma_params = ssc_p->dma_params[i]; |
| 199 | |
| 200 | if (dma_params != NULL && dma_params->dma_intr_handler != NULL && |
| 201 | (ssc_sr & |
| 202 | (dma_params->mask->ssc_endx | dma_params->mask->ssc_endbuf))) |
| 203 | |
| 204 | dma_params->dma_intr_handler(ssc_sr, dma_params->substream); |
| 205 | } |
| 206 | |
| 207 | return IRQ_HANDLED; |
| 208 | } |
| 209 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 210 | /* |
| 211 | * Startup. Only that one substream allowed in each direction. |
| 212 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 213 | static int at91_ssc_startup(struct snd_pcm_substream *substream) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 214 | { |
| 215 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 216 | struct at91_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id]; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 217 | int dir_mask; |
| 218 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 219 | DBG("ssc_startup: SSC_SR=0x%08lx\n", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 220 | at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR)); |
| 221 | dir_mask = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0x1 : 0x2; |
| 222 | |
| 223 | spin_lock_irq(&ssc_p->lock); |
| 224 | if (ssc_p->dir_mask & dir_mask) { |
| 225 | spin_unlock_irq(&ssc_p->lock); |
| 226 | return -EBUSY; |
| 227 | } |
| 228 | ssc_p->dir_mask |= dir_mask; |
| 229 | spin_unlock_irq(&ssc_p->lock); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 234 | /* |
| 235 | * Shutdown. Clear DMA parameters and shutdown the SSC if there |
| 236 | * are no other substreams open. |
| 237 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 238 | static void at91_ssc_shutdown(struct snd_pcm_substream *substream) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 239 | { |
| 240 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 241 | struct at91_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id]; |
| 242 | struct at91_pcm_dma_params *dma_params; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 243 | int dir, dir_mask; |
| 244 | |
| 245 | dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 246 | dma_params = ssc_p->dma_params[dir]; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 247 | |
| 248 | if (dma_params != NULL) { |
| 249 | at91_ssc_write(dma_params->ssc_base + AT91_SSC_CR, |
| 250 | dma_params->mask->ssc_disable); |
| 251 | DBG("%s disabled SSC_SR=0x%08lx\n", (dir ? "receive" : "transmit"), |
| 252 | at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR)); |
| 253 | |
| 254 | dma_params->ssc_base = NULL; |
| 255 | dma_params->substream = NULL; |
| 256 | ssc_p->dma_params[dir] = NULL; |
| 257 | } |
| 258 | |
| 259 | dir_mask = 1 << dir; |
| 260 | |
| 261 | spin_lock_irq(&ssc_p->lock); |
| 262 | ssc_p->dir_mask &= ~dir_mask; |
| 263 | if (!ssc_p->dir_mask) { |
| 264 | /* Shutdown the SSC clock. */ |
| 265 | DBG("Stopping pid %d clock\n", ssc_p->ssc.pid); |
| 266 | at91_sys_write(AT91_PMC_PCDR, 1<<ssc_p->ssc.pid); |
| 267 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 268 | if (ssc_p->initialized) { |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 269 | free_irq(ssc_p->ssc.pid, ssc_p); |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 270 | ssc_p->initialized = 0; |
| 271 | } |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 272 | |
| 273 | /* Reset the SSC */ |
| 274 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, AT91_SSC_SWRST); |
| 275 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 276 | /* Clear the SSC dividers */ |
| 277 | ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 278 | } |
| 279 | spin_unlock_irq(&ssc_p->lock); |
| 280 | } |
| 281 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 282 | /* |
| 283 | * Record the SSC system clock rate. |
| 284 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 285 | static int at91_ssc_set_dai_sysclk(struct snd_soc_cpu_dai *cpu_dai, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 286 | int clk_id, unsigned int freq, int dir) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 287 | { |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 288 | /* |
| 289 | * The only clock supplied to the SSC is the AT91 master clock, |
| 290 | * which is only used if the SSC is generating BCLK and/or |
| 291 | * LRC clocks. |
| 292 | */ |
| 293 | switch (clk_id) { |
| 294 | case AT91_SYSCLK_MCK: |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 295 | at91_ssc_sysclk = freq; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 296 | break; |
| 297 | default: |
| 298 | return -EINVAL; |
| 299 | } |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 304 | /* |
| 305 | * Record the DAI format for use in hw_params(). |
| 306 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 307 | static int at91_ssc_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 308 | unsigned int fmt) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 309 | { |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 310 | struct at91_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 311 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 312 | ssc_p->daifmt = fmt; |
| 313 | return 0; |
| 314 | } |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 315 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 316 | /* |
| 317 | * Record SSC clock dividers for use in hw_params(). |
| 318 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 319 | static int at91_ssc_set_dai_clkdiv(struct snd_soc_cpu_dai *cpu_dai, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 320 | int div_id, int div) |
| 321 | { |
| 322 | struct at91_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 323 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 324 | switch (div_id) { |
| 325 | case AT91SSC_CMR_DIV: |
| 326 | /* |
| 327 | * The same master clock divider is used for both |
| 328 | * transmit and receive, so if a value has already |
| 329 | * been set, it must match this value. |
| 330 | */ |
| 331 | if (ssc_p->cmr_div == 0) |
| 332 | ssc_p->cmr_div = div; |
| 333 | else |
| 334 | if (div != ssc_p->cmr_div) |
| 335 | return -EBUSY; |
| 336 | break; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 337 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 338 | case AT91SSC_TCMR_PERIOD: |
| 339 | ssc_p->tcmr_period = div; |
| 340 | break; |
| 341 | |
| 342 | case AT91SSC_RCMR_PERIOD: |
| 343 | ssc_p->rcmr_period = div; |
| 344 | break; |
| 345 | |
| 346 | default: |
| 347 | return -EINVAL; |
| 348 | } |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 353 | /* |
| 354 | * Configure the SSC. |
| 355 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 356 | static int at91_ssc_hw_params(struct snd_pcm_substream *substream, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 357 | struct snd_pcm_hw_params *params) |
| 358 | { |
| 359 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 360 | int id = rtd->dai->cpu_dai->id; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 361 | struct at91_ssc_info *ssc_p = &ssc_info[id]; |
| 362 | struct at91_pcm_dma_params *dma_params; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 363 | int dir, channels, bits; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 364 | u32 tfmr, rfmr, tcmr, rcmr; |
| 365 | int start_event; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 366 | int ret; |
| 367 | |
| 368 | /* |
| 369 | * Currently, there is only one set of dma params for |
| 370 | * each direction. If more are added, this code will |
| 371 | * have to be changed to select the proper set. |
| 372 | */ |
| 373 | dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; |
| 374 | |
| 375 | dma_params = &ssc_dma_params[id][dir]; |
| 376 | dma_params->ssc_base = ssc_p->ssc.base; |
| 377 | dma_params->substream = substream; |
| 378 | |
| 379 | ssc_p->dma_params[dir] = dma_params; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 380 | |
| 381 | /* |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 382 | * The cpu_dai->dma_data field is only used to communicate the |
| 383 | * appropriate DMA parameters to the pcm driver hw_params() |
| 384 | * function. It should not be used for other purposes |
| 385 | * as it is common to all substreams. |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 386 | */ |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 387 | rtd->dai->cpu_dai->dma_data = dma_params; |
| 388 | |
| 389 | channels = params_channels(params); |
| 390 | |
| 391 | /* |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 392 | * Determine sample size in bits and the PDC increment. |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 393 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 394 | switch(params_format(params)) { |
| 395 | case SNDRV_PCM_FORMAT_S8: |
| 396 | bits = 8; |
| 397 | dma_params->pdc_xfer_size = 1; |
| 398 | break; |
| 399 | case SNDRV_PCM_FORMAT_S16_LE: |
| 400 | bits = 16; |
| 401 | dma_params->pdc_xfer_size = 2; |
| 402 | break; |
| 403 | case SNDRV_PCM_FORMAT_S24_LE: |
| 404 | bits = 24; |
| 405 | dma_params->pdc_xfer_size = 4; |
| 406 | break; |
| 407 | case SNDRV_PCM_FORMAT_S32_LE: |
| 408 | bits = 32; |
| 409 | dma_params->pdc_xfer_size = 4; |
| 410 | break; |
| 411 | default: |
| 412 | printk(KERN_WARNING "at91-ssc: unsupported PCM format"); |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * The SSC only supports up to 16-bit samples in I2S format, due |
| 418 | * to the size of the Frame Mode Register FSLEN field. |
| 419 | */ |
| 420 | if ((ssc_p->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_I2S |
| 421 | && bits > 16) { |
| 422 | printk(KERN_WARNING |
| 423 | "at91-ssc: sample size %d is too large for I2S\n", bits); |
| 424 | return -EINVAL; |
| 425 | } |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 426 | |
| 427 | /* |
| 428 | * Compute SSC register settings. |
| 429 | */ |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 430 | switch (ssc_p->daifmt |
| 431 | & (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_MASTER_MASK)) { |
| 432 | |
| 433 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS: |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 434 | /* |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 435 | * I2S format, SSC provides BCLK and LRC clocks. |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 436 | * |
| 437 | * The SSC transmit and receive clocks are generated from the |
| 438 | * MCK divider, and the BCLK signal is output on the SSC TK line. |
| 439 | */ |
| 440 | rcmr = (( ssc_p->rcmr_period << 24) & AT91_SSC_PERIOD) |
| 441 | | (( 1 << 16) & AT91_SSC_STTDLY) |
| 442 | | (( AT91_SSC_START_FALLING_RF ) & AT91_SSC_START) |
| 443 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) |
| 444 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) |
| 445 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); |
| 446 | |
| 447 | rfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) |
| 448 | | (( AT91_SSC_FSOS_NEGATIVE ) & AT91_SSC_FSOS) |
| 449 | | (((bits - 1) << 16) & AT91_SSC_FSLEN) |
| 450 | | (((channels - 1) << 8) & AT91_SSC_DATNB) |
| 451 | | (( 1 << 7) & AT91_SSC_MSBF) |
| 452 | | (( 0 << 5) & AT91_SSC_LOOP) |
| 453 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); |
| 454 | |
| 455 | tcmr = (( ssc_p->tcmr_period << 24) & AT91_SSC_PERIOD) |
| 456 | | (( 1 << 16) & AT91_SSC_STTDLY) |
| 457 | | (( AT91_SSC_START_FALLING_RF ) & AT91_SSC_START) |
| 458 | | (( AT91_SSC_CKI_FALLING ) & AT91_SSC_CKI) |
| 459 | | (( AT91_SSC_CKO_CONTINUOUS ) & AT91_SSC_CKO) |
| 460 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); |
| 461 | |
| 462 | tfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) |
| 463 | | (( 0 << 23) & AT91_SSC_FSDEN) |
| 464 | | (( AT91_SSC_FSOS_NEGATIVE ) & AT91_SSC_FSOS) |
| 465 | | (((bits - 1) << 16) & AT91_SSC_FSLEN) |
| 466 | | (((channels - 1) << 8) & AT91_SSC_DATNB) |
| 467 | | (( 1 << 7) & AT91_SSC_MSBF) |
| 468 | | (( 0 << 5) & AT91_SSC_DATDEF) |
| 469 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); |
| 470 | break; |
| 471 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 472 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM: |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 473 | /* |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 474 | * I2S format, CODEC supplies BCLK and LRC clocks. |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 475 | * |
| 476 | * The SSC transmit clock is obtained from the BCLK signal on |
| 477 | * on the TK line, and the SSC receive clock is generated from the |
| 478 | * transmit clock. |
| 479 | * |
| 480 | * For single channel data, one sample is transferred on the falling |
| 481 | * edge of the LRC clock. For two channel data, one sample is |
| 482 | * transferred on both edges of the LRC clock. |
| 483 | */ |
| 484 | start_event = channels == 1 |
| 485 | ? AT91_SSC_START_FALLING_RF |
| 486 | : AT91_SSC_START_EDGE_RF; |
| 487 | |
| 488 | rcmr = (( 0 << 24) & AT91_SSC_PERIOD) |
| 489 | | (( 1 << 16) & AT91_SSC_STTDLY) |
| 490 | | (( start_event ) & AT91_SSC_START) |
| 491 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) |
| 492 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) |
| 493 | | (( AT91_SSC_CKS_CLOCK ) & AT91_SSC_CKS); |
| 494 | |
| 495 | rfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) |
| 496 | | (( AT91_SSC_FSOS_NONE ) & AT91_SSC_FSOS) |
| 497 | | (( 0 << 16) & AT91_SSC_FSLEN) |
| 498 | | (( 0 << 8) & AT91_SSC_DATNB) |
| 499 | | (( 1 << 7) & AT91_SSC_MSBF) |
| 500 | | (( 0 << 5) & AT91_SSC_LOOP) |
| 501 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); |
| 502 | |
| 503 | tcmr = (( 0 << 24) & AT91_SSC_PERIOD) |
| 504 | | (( 1 << 16) & AT91_SSC_STTDLY) |
| 505 | | (( start_event ) & AT91_SSC_START) |
| 506 | | (( AT91_SSC_CKI_FALLING ) & AT91_SSC_CKI) |
| 507 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) |
| 508 | | (( AT91_SSC_CKS_PIN ) & AT91_SSC_CKS); |
| 509 | |
| 510 | tfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) |
| 511 | | (( 0 << 23) & AT91_SSC_FSDEN) |
| 512 | | (( AT91_SSC_FSOS_NONE ) & AT91_SSC_FSOS) |
| 513 | | (( 0 << 16) & AT91_SSC_FSLEN) |
| 514 | | (( 0 << 8) & AT91_SSC_DATNB) |
| 515 | | (( 1 << 7) & AT91_SSC_MSBF) |
| 516 | | (( 0 << 5) & AT91_SSC_DATDEF) |
| 517 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); |
| 518 | break; |
| 519 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 520 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS: |
| 521 | /* |
| 522 | * DSP/PCM Mode A format, SSC provides BCLK and LRC clocks. |
| 523 | * |
| 524 | * The SSC transmit and receive clocks are generated from the |
| 525 | * MCK divider, and the BCLK signal is output on the SSC TK line. |
| 526 | */ |
| 527 | rcmr = (( ssc_p->rcmr_period << 24) & AT91_SSC_PERIOD) |
| 528 | | (( 1 << 16) & AT91_SSC_STTDLY) |
| 529 | | (( AT91_SSC_START_RISING_RF ) & AT91_SSC_START) |
| 530 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) |
| 531 | | (( AT91_SSC_CKO_NONE ) & AT91_SSC_CKO) |
| 532 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); |
| 533 | |
| 534 | rfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) |
| 535 | | (( AT91_SSC_FSOS_POSITIVE ) & AT91_SSC_FSOS) |
| 536 | | (( 0 << 16) & AT91_SSC_FSLEN) |
| 537 | | (((channels - 1) << 8) & AT91_SSC_DATNB) |
| 538 | | (( 1 << 7) & AT91_SSC_MSBF) |
| 539 | | (( 0 << 5) & AT91_SSC_LOOP) |
| 540 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); |
| 541 | |
| 542 | tcmr = (( ssc_p->tcmr_period << 24) & AT91_SSC_PERIOD) |
| 543 | | (( 1 << 16) & AT91_SSC_STTDLY) |
| 544 | | (( AT91_SSC_START_RISING_RF ) & AT91_SSC_START) |
| 545 | | (( AT91_SSC_CK_RISING ) & AT91_SSC_CKI) |
| 546 | | (( AT91_SSC_CKO_CONTINUOUS ) & AT91_SSC_CKO) |
| 547 | | (( AT91_SSC_CKS_DIV ) & AT91_SSC_CKS); |
| 548 | |
| 549 | tfmr = (( AT91_SSC_FSEDGE_POSITIVE ) & AT91_SSC_FSEDGE) |
| 550 | | (( 0 << 23) & AT91_SSC_FSDEN) |
| 551 | | (( AT91_SSC_FSOS_POSITIVE ) & AT91_SSC_FSOS) |
| 552 | | (( 0 << 16) & AT91_SSC_FSLEN) |
| 553 | | (((channels - 1) << 8) & AT91_SSC_DATNB) |
| 554 | | (( 1 << 7) & AT91_SSC_MSBF) |
| 555 | | (( 0 << 5) & AT91_SSC_DATDEF) |
| 556 | | (((bits - 1) << 0) & AT91_SSC_DATALEN); |
| 557 | |
| 558 | |
| 559 | |
| 560 | break; |
| 561 | |
| 562 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM: |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 563 | default: |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 564 | printk(KERN_WARNING "at91-ssc: unsupported DAI format 0x%x.\n", |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 565 | ssc_p->daifmt); |
| 566 | return -EINVAL; |
| 567 | break; |
| 568 | } |
| 569 | DBG("RCMR=%08x RFMR=%08x TCMR=%08x TFMR=%08x\n", rcmr, rfmr, tcmr, tfmr); |
| 570 | |
| 571 | if (!ssc_p->initialized) { |
| 572 | |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 573 | /* Enable PMC peripheral clock for this SSC */ |
| 574 | DBG("Starting pid %d clock\n", ssc_p->ssc.pid); |
| 575 | at91_sys_write(AT91_PMC_PCER, 1<<ssc_p->ssc.pid); |
| 576 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 577 | /* Reset the SSC and its PDC registers */ |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 578 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, AT91_SSC_SWRST); |
| 579 | |
Frank Mandarino | fa8f878 | 2007-02-12 14:06:22 +0100 | [diff] [blame] | 580 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RPR, 0); |
| 581 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RCR, 0); |
| 582 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RNPR, 0); |
| 583 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_RNCR, 0); |
| 584 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TPR, 0); |
| 585 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TCR, 0); |
| 586 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TNPR, 0); |
| 587 | at91_ssc_write(ssc_p->ssc.base + ATMEL_PDC_TNCR, 0); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 588 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 589 | if ((ret = request_irq(ssc_p->ssc.pid, at91_ssc_interrupt, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 590 | 0, ssc_p->name, ssc_p)) < 0) { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 591 | printk(KERN_WARNING "at91-ssc: request_irq failure\n"); |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 592 | |
| 593 | DBG("Stopping pid %d clock\n", ssc_p->ssc.pid); |
| 594 | at91_sys_write(AT91_PMC_PCER, 1<<ssc_p->ssc.pid); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 595 | return ret; |
| 596 | } |
| 597 | |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 598 | ssc_p->initialized = 1; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 599 | } |
| 600 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 601 | /* set SSC clock mode register */ |
| 602 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CMR, ssc_p->cmr_div); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 603 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 604 | /* set receive clock mode and format */ |
| 605 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RCMR, rcmr); |
| 606 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RFMR, rfmr); |
| 607 | |
| 608 | /* set transmit clock mode and format */ |
| 609 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TCMR, tcmr); |
| 610 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TFMR, tfmr); |
| 611 | |
| 612 | DBG("hw_params: SSC initialized\n"); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 617 | static int at91_ssc_prepare(struct snd_pcm_substream *substream) |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 618 | { |
| 619 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 620 | struct at91_ssc_info *ssc_p = &ssc_info[rtd->dai->cpu_dai->id]; |
| 621 | struct at91_pcm_dma_params *dma_params; |
| 622 | int dir; |
| 623 | |
| 624 | dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; |
| 625 | dma_params = ssc_p->dma_params[dir]; |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 626 | |
| 627 | at91_ssc_write(dma_params->ssc_base + AT91_SSC_CR, |
| 628 | dma_params->mask->ssc_enable); |
| 629 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 630 | DBG("%s enabled SSC_SR=0x%08lx\n", dir ? "receive" : "transmit", |
| 631 | at91_ssc_read(dma_params->ssc_base + AT91_SSC_SR)); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 636 | #ifdef CONFIG_PM |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 637 | static int at91_ssc_suspend(struct platform_device *pdev, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 638 | struct snd_soc_cpu_dai *cpu_dai) |
| 639 | { |
| 640 | struct at91_ssc_info *ssc_p; |
| 641 | |
| 642 | if(!cpu_dai->active) |
| 643 | return 0; |
| 644 | |
| 645 | ssc_p = &ssc_info[cpu_dai->id]; |
| 646 | |
| 647 | /* Save the status register before disabling transmit and receive. */ |
| 648 | ssc_p->ssc_state.ssc_sr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_SR); |
| 649 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, |
| 650 | AT91_SSC_TXDIS | AT91_SSC_RXDIS); |
| 651 | |
| 652 | /* Save the current interrupt mask, then disable unmasked interrupts. */ |
| 653 | ssc_p->ssc_state.ssc_imr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_IMR); |
| 654 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_IDR, ssc_p->ssc_state.ssc_imr); |
| 655 | |
| 656 | ssc_p->ssc_state.ssc_cmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_CMR); |
| 657 | ssc_p->ssc_state.ssc_rcmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_RCMR); |
| 658 | ssc_p->ssc_state.ssc_rfmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_RFMR); |
| 659 | ssc_p->ssc_state.ssc_tcmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_TCMR); |
| 660 | ssc_p->ssc_state.ssc_tfmr = at91_ssc_read(ssc_p->ssc.base + AT91_SSC_TFMR); |
| 661 | |
| 662 | return 0; |
| 663 | } |
| 664 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 665 | static int at91_ssc_resume(struct platform_device *pdev, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 666 | struct snd_soc_cpu_dai *cpu_dai) |
| 667 | { |
| 668 | struct at91_ssc_info *ssc_p; |
| 669 | |
| 670 | if(!cpu_dai->active) |
| 671 | return 0; |
| 672 | |
| 673 | ssc_p = &ssc_info[cpu_dai->id]; |
| 674 | |
| 675 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TFMR, ssc_p->ssc_state.ssc_tfmr); |
| 676 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_TCMR, ssc_p->ssc_state.ssc_tcmr); |
| 677 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RFMR, ssc_p->ssc_state.ssc_rfmr); |
| 678 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_RCMR, ssc_p->ssc_state.ssc_rcmr); |
| 679 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CMR, ssc_p->ssc_state.ssc_cmr); |
| 680 | |
| 681 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_IER, ssc_p->ssc_state.ssc_imr); |
| 682 | |
| 683 | at91_ssc_write(ssc_p->ssc.base + AT91_SSC_CR, |
| 684 | ((ssc_p->ssc_state.ssc_sr & AT91_SSC_RXENA) ? AT91_SSC_RXEN : 0) | |
| 685 | ((ssc_p->ssc_state.ssc_sr & AT91_SSC_TXENA) ? AT91_SSC_TXEN : 0)); |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | #else |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 691 | #define at91_ssc_suspend NULL |
| 692 | #define at91_ssc_resume NULL |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 693 | #endif |
| 694 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 695 | #define AT91_SSC_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 696 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ |
| 697 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ |
| 698 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ |
| 699 | SNDRV_PCM_RATE_96000) |
| 700 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 701 | #define AT91_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ |
| 702 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 703 | |
| 704 | struct snd_soc_cpu_dai at91_ssc_dai[NUM_SSC_DEVICES] = { |
| 705 | { .name = "at91-ssc0", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 706 | .id = 0, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 707 | .type = SND_SOC_DAI_PCM, |
| 708 | .suspend = at91_ssc_suspend, |
| 709 | .resume = at91_ssc_resume, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 710 | .playback = { |
| 711 | .channels_min = 1, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 712 | .channels_max = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 713 | .rates = AT91_SSC_RATES, |
| 714 | .formats = AT91_SSC_FORMATS,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 715 | .capture = { |
| 716 | .channels_min = 1, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 717 | .channels_max = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 718 | .rates = AT91_SSC_RATES, |
| 719 | .formats = AT91_SSC_FORMATS,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 720 | .ops = { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 721 | .startup = at91_ssc_startup, |
| 722 | .shutdown = at91_ssc_shutdown, |
| 723 | .prepare = at91_ssc_prepare, |
| 724 | .hw_params = at91_ssc_hw_params,}, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 725 | .dai_ops = { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 726 | .set_sysclk = at91_ssc_set_dai_sysclk, |
| 727 | .set_fmt = at91_ssc_set_dai_fmt, |
| 728 | .set_clkdiv = at91_ssc_set_dai_clkdiv,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 729 | .private_data = &ssc_info[0].ssc, |
| 730 | }, |
| 731 | #if NUM_SSC_DEVICES == 3 |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 732 | { .name = "at91-ssc1", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 733 | .id = 1, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 734 | .type = SND_SOC_DAI_PCM, |
| 735 | .suspend = at91_ssc_suspend, |
| 736 | .resume = at91_ssc_resume, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 737 | .playback = { |
| 738 | .channels_min = 1, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 739 | .channels_max = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 740 | .rates = AT91_SSC_RATES, |
| 741 | .formats = AT91_SSC_FORMATS,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 742 | .capture = { |
| 743 | .channels_min = 1, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 744 | .channels_max = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 745 | .rates = AT91_SSC_RATES, |
| 746 | .formats = AT91_SSC_FORMATS,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 747 | .ops = { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 748 | .startup = at91_ssc_startup, |
| 749 | .shutdown = at91_ssc_shutdown, |
| 750 | .prepare = at91_ssc_prepare, |
| 751 | .hw_params = at91_ssc_hw_params,}, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 752 | .dai_ops = { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 753 | .set_sysclk = at91_ssc_set_dai_sysclk, |
| 754 | .set_fmt = at91_ssc_set_dai_fmt, |
| 755 | .set_clkdiv = at91_ssc_set_dai_clkdiv,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 756 | .private_data = &ssc_info[1].ssc, |
| 757 | }, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 758 | { .name = "at91-ssc2", |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 759 | .id = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 760 | .type = SND_SOC_DAI_PCM, |
| 761 | .suspend = at91_ssc_suspend, |
| 762 | .resume = at91_ssc_resume, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 763 | .playback = { |
| 764 | .channels_min = 1, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 765 | .channels_max = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 766 | .rates = AT91_SSC_RATES, |
| 767 | .formats = AT91_SSC_FORMATS,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 768 | .capture = { |
| 769 | .channels_min = 1, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 770 | .channels_max = 2, |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 771 | .rates = AT91_SSC_RATES, |
| 772 | .formats = AT91_SSC_FORMATS,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 773 | .ops = { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 774 | .startup = at91_ssc_startup, |
| 775 | .shutdown = at91_ssc_shutdown, |
| 776 | .prepare = at91_ssc_prepare, |
| 777 | .hw_params = at91_ssc_hw_params,}, |
Frank Mandarino | 171eb8f | 2007-02-02 17:18:38 +0100 | [diff] [blame] | 778 | .dai_ops = { |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 779 | .set_sysclk = at91_ssc_set_dai_sysclk, |
| 780 | .set_fmt = at91_ssc_set_dai_fmt, |
| 781 | .set_clkdiv = at91_ssc_set_dai_clkdiv,}, |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 782 | .private_data = &ssc_info[2].ssc, |
| 783 | }, |
| 784 | #endif |
| 785 | }; |
| 786 | |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 787 | EXPORT_SYMBOL_GPL(at91_ssc_dai); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 788 | |
| 789 | /* Module information */ |
| 790 | MODULE_AUTHOR("Frank Mandarino, fmandarino@endrelia.com, www.endrelia.com"); |
Frank Mandarino | 36b8a8b | 2007-04-16 17:18:52 +0200 | [diff] [blame] | 791 | MODULE_DESCRIPTION("AT91 SSC ASoC Interface"); |
Frank Mandarino | 9f0ac6e | 2006-11-24 15:49:39 +0100 | [diff] [blame] | 792 | MODULE_LICENSE("GPL"); |