Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * atmel_ssc_dai.c -- ALSA SoC ATMEL SSC Audio Layer Platform driver |
| 3 | * |
| 4 | * Copyright (C) 2005 SAN People |
| 5 | * Copyright (C) 2008 Atmel |
| 6 | * |
| 7 | * Author: Sedji Gaouaou <sedji.gaouaou@atmel.com> |
| 8 | * ATMEL CORP. |
| 9 | * |
| 10 | * Based on at91-ssc.c by |
| 11 | * Frank Mandarino <fmandarino@endrelia.com> |
| 12 | * Based on pxa2xx Platform drivers by |
Liam Girdwood | 64ca040 | 2009-02-02 22:23:22 +0000 | [diff] [blame] | 13 | * Liam Girdwood <lrg@slimlogic.co.uk> |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 14 | * |
| 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. |
| 19 | * |
| 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. |
| 24 | * |
| 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 |
| 28 | */ |
| 29 | |
| 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> |
| 37 | |
| 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> |
| 44 | |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 45 | #include "atmel-pcm.h" |
| 46 | #include "atmel_ssc_dai.h" |
| 47 | |
| 48 | |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 49 | #define NUM_SSC_DEVICES 3 |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * SSC PDC registers required by the PCM DMA engine. |
| 53 | */ |
| 54 | static struct atmel_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 atmel_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 atmel_ssc_mask ssc_tx_mask = { |
| 72 | .ssc_enable = SSC_BIT(CR_TXEN), |
| 73 | .ssc_disable = SSC_BIT(CR_TXDIS), |
| 74 | .ssc_endx = SSC_BIT(SR_ENDTX), |
| 75 | .ssc_endbuf = SSC_BIT(SR_TXBUFE), |
Bo Shen | f1b0dd8 | 2013-07-03 16:37:57 +0800 | [diff] [blame] | 76 | .ssc_error = SSC_BIT(SR_OVRUN), |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 77 | .pdc_enable = ATMEL_PDC_TXTEN, |
| 78 | .pdc_disable = ATMEL_PDC_TXTDIS, |
| 79 | }; |
| 80 | |
| 81 | static struct atmel_ssc_mask ssc_rx_mask = { |
| 82 | .ssc_enable = SSC_BIT(CR_RXEN), |
| 83 | .ssc_disable = SSC_BIT(CR_RXDIS), |
| 84 | .ssc_endx = SSC_BIT(SR_ENDRX), |
| 85 | .ssc_endbuf = SSC_BIT(SR_RXBUFF), |
Bo Shen | f1b0dd8 | 2013-07-03 16:37:57 +0800 | [diff] [blame] | 86 | .ssc_error = SSC_BIT(SR_OVRUN), |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 87 | .pdc_enable = ATMEL_PDC_RXTEN, |
| 88 | .pdc_disable = ATMEL_PDC_RXTDIS, |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | /* |
| 93 | * DMA parameters. |
| 94 | */ |
| 95 | static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = { |
| 96 | {{ |
| 97 | .name = "SSC0 PCM out", |
| 98 | .pdc = &pdc_tx_reg, |
| 99 | .mask = &ssc_tx_mask, |
| 100 | }, |
| 101 | { |
| 102 | .name = "SSC0 PCM in", |
| 103 | .pdc = &pdc_rx_reg, |
| 104 | .mask = &ssc_rx_mask, |
| 105 | } }, |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 106 | {{ |
| 107 | .name = "SSC1 PCM out", |
| 108 | .pdc = &pdc_tx_reg, |
| 109 | .mask = &ssc_tx_mask, |
| 110 | }, |
| 111 | { |
| 112 | .name = "SSC1 PCM in", |
| 113 | .pdc = &pdc_rx_reg, |
| 114 | .mask = &ssc_rx_mask, |
| 115 | } }, |
| 116 | {{ |
| 117 | .name = "SSC2 PCM out", |
| 118 | .pdc = &pdc_tx_reg, |
| 119 | .mask = &ssc_tx_mask, |
| 120 | }, |
| 121 | { |
| 122 | .name = "SSC2 PCM in", |
| 123 | .pdc = &pdc_rx_reg, |
| 124 | .mask = &ssc_rx_mask, |
| 125 | } }, |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | |
| 129 | static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = { |
| 130 | { |
| 131 | .name = "ssc0", |
| 132 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[0].lock), |
| 133 | .dir_mask = SSC_DIR_MASK_UNUSED, |
| 134 | .initialized = 0, |
| 135 | }, |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 136 | { |
| 137 | .name = "ssc1", |
| 138 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[1].lock), |
| 139 | .dir_mask = SSC_DIR_MASK_UNUSED, |
| 140 | .initialized = 0, |
| 141 | }, |
| 142 | { |
| 143 | .name = "ssc2", |
| 144 | .lock = __SPIN_LOCK_UNLOCKED(ssc_info[2].lock), |
| 145 | .dir_mask = SSC_DIR_MASK_UNUSED, |
| 146 | .initialized = 0, |
| 147 | }, |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | |
| 151 | /* |
| 152 | * SSC interrupt handler. Passes PDC interrupts to the DMA |
| 153 | * interrupt handler in the PCM driver. |
| 154 | */ |
| 155 | static irqreturn_t atmel_ssc_interrupt(int irq, void *dev_id) |
| 156 | { |
| 157 | struct atmel_ssc_info *ssc_p = dev_id; |
| 158 | struct atmel_pcm_dma_params *dma_params; |
| 159 | u32 ssc_sr; |
| 160 | u32 ssc_substream_mask; |
| 161 | int i; |
| 162 | |
| 163 | ssc_sr = (unsigned long)ssc_readl(ssc_p->ssc->regs, SR) |
| 164 | & (unsigned long)ssc_readl(ssc_p->ssc->regs, IMR); |
| 165 | |
| 166 | /* |
| 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. |
| 171 | */ |
| 172 | for (i = 0; i < ARRAY_SIZE(ssc_p->dma_params); i++) { |
| 173 | dma_params = ssc_p->dma_params[i]; |
| 174 | |
| 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, |
| 181 | dma_params-> |
| 182 | substream); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return IRQ_HANDLED; |
| 188 | } |
| 189 | |
| 190 | |
| 191 | /*-------------------------------------------------------------------------*\ |
| 192 | * DAI functions |
| 193 | \*-------------------------------------------------------------------------*/ |
| 194 | /* |
| 195 | * Startup. Only that one substream allowed in each direction. |
| 196 | */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 197 | static int atmel_ssc_startup(struct snd_pcm_substream *substream, |
| 198 | struct snd_soc_dai *dai) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 199 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 200 | struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; |
Bo Shen | 01f00d5 | 2013-07-03 16:37:56 +0800 | [diff] [blame] | 201 | struct atmel_pcm_dma_params *dma_params; |
| 202 | int dir, dir_mask; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 203 | |
| 204 | pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n", |
| 205 | ssc_readl(ssc_p->ssc->regs, SR)); |
| 206 | |
Bo Shen | 01f00d5 | 2013-07-03 16:37:56 +0800 | [diff] [blame] | 207 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 208 | dir = 0; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 209 | dir_mask = SSC_DIR_MASK_PLAYBACK; |
Bo Shen | 01f00d5 | 2013-07-03 16:37:56 +0800 | [diff] [blame] | 210 | } else { |
| 211 | dir = 1; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 212 | dir_mask = SSC_DIR_MASK_CAPTURE; |
Bo Shen | 01f00d5 | 2013-07-03 16:37:56 +0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | dma_params = &ssc_dma_params[dai->id][dir]; |
| 216 | dma_params->ssc = ssc_p->ssc; |
| 217 | dma_params->substream = substream; |
| 218 | |
| 219 | ssc_p->dma_params[dir] = dma_params; |
| 220 | |
| 221 | snd_soc_dai_set_dma_data(dai, substream, dma_params); |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 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 | |
| 234 | /* |
| 235 | * Shutdown. Clear DMA parameters and shutdown the SSC if there |
| 236 | * are no other substreams open. |
| 237 | */ |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 238 | static void atmel_ssc_shutdown(struct snd_pcm_substream *substream, |
| 239 | struct snd_soc_dai *dai) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 240 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 241 | struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 242 | struct atmel_pcm_dma_params *dma_params; |
| 243 | int dir, dir_mask; |
| 244 | |
| 245 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 246 | dir = 0; |
| 247 | else |
| 248 | dir = 1; |
| 249 | |
| 250 | dma_params = ssc_p->dma_params[dir]; |
| 251 | |
| 252 | if (dma_params != NULL) { |
| 253 | ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable); |
| 254 | pr_debug("atmel_ssc_shutdown: %s disabled SSC_SR=0x%08x\n", |
| 255 | (dir ? "receive" : "transmit"), |
| 256 | ssc_readl(ssc_p->ssc->regs, SR)); |
| 257 | |
| 258 | dma_params->ssc = NULL; |
| 259 | dma_params->substream = NULL; |
| 260 | ssc_p->dma_params[dir] = NULL; |
| 261 | } |
| 262 | |
| 263 | dir_mask = 1 << dir; |
| 264 | |
| 265 | spin_lock_irq(&ssc_p->lock); |
| 266 | ssc_p->dir_mask &= ~dir_mask; |
| 267 | if (!ssc_p->dir_mask) { |
| 268 | if (ssc_p->initialized) { |
| 269 | /* Shutdown the SSC clock. */ |
Matthieu Crapet | 15f6c58 | 2014-12-08 11:58:29 +0100 | [diff] [blame] | 270 | pr_debug("atmel_ssc_dai: Stopping clock\n"); |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 271 | clk_disable(ssc_p->ssc->clk); |
| 272 | |
| 273 | free_irq(ssc_p->ssc->irq, ssc_p); |
| 274 | ssc_p->initialized = 0; |
| 275 | } |
| 276 | |
| 277 | /* Reset the SSC */ |
| 278 | ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST)); |
| 279 | /* Clear the SSC dividers */ |
| 280 | ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0; |
| 281 | } |
| 282 | spin_unlock_irq(&ssc_p->lock); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | /* |
| 287 | * Record the DAI format for use in hw_params(). |
| 288 | */ |
| 289 | static int atmel_ssc_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
| 290 | unsigned int fmt) |
| 291 | { |
| 292 | struct atmel_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; |
| 293 | |
| 294 | ssc_p->daifmt = fmt; |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Record SSC clock dividers for use in hw_params(). |
| 300 | */ |
| 301 | static int atmel_ssc_set_dai_clkdiv(struct snd_soc_dai *cpu_dai, |
| 302 | int div_id, int div) |
| 303 | { |
| 304 | struct atmel_ssc_info *ssc_p = &ssc_info[cpu_dai->id]; |
| 305 | |
| 306 | switch (div_id) { |
| 307 | case ATMEL_SSC_CMR_DIV: |
| 308 | /* |
| 309 | * The same master clock divider is used for both |
| 310 | * transmit and receive, so if a value has already |
| 311 | * been set, it must match this value. |
| 312 | */ |
Peter Rosin | eb58960 | 2014-10-24 21:25:59 +0200 | [diff] [blame] | 313 | if (ssc_p->dir_mask != |
| 314 | (SSC_DIR_MASK_PLAYBACK | SSC_DIR_MASK_CAPTURE)) |
| 315 | ssc_p->cmr_div = div; |
| 316 | else if (ssc_p->cmr_div == 0) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 317 | ssc_p->cmr_div = div; |
| 318 | else |
| 319 | if (div != ssc_p->cmr_div) |
| 320 | return -EBUSY; |
| 321 | break; |
| 322 | |
| 323 | case ATMEL_SSC_TCMR_PERIOD: |
| 324 | ssc_p->tcmr_period = div; |
| 325 | break; |
| 326 | |
| 327 | case ATMEL_SSC_RCMR_PERIOD: |
| 328 | ssc_p->rcmr_period = div; |
| 329 | break; |
| 330 | |
| 331 | default: |
| 332 | return -EINVAL; |
| 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * Configure the SSC. |
| 340 | */ |
| 341 | static int atmel_ssc_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 342 | struct snd_pcm_hw_params *params, |
| 343 | struct snd_soc_dai *dai) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 344 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 345 | int id = dai->id; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 346 | struct atmel_ssc_info *ssc_p = &ssc_info[id]; |
Bo Shen | 048d4ff | 2014-02-10 14:09:45 +0800 | [diff] [blame] | 347 | struct ssc_device *ssc = ssc_p->ssc; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 348 | struct atmel_pcm_dma_params *dma_params; |
| 349 | int dir, channels, bits; |
| 350 | u32 tfmr, rfmr, tcmr, rcmr; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 351 | int ret; |
Bo Shen | dfaf535 | 2014-06-11 18:14:40 +0800 | [diff] [blame] | 352 | int fslen, fslen_ext; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 353 | |
| 354 | /* |
| 355 | * Currently, there is only one set of dma params for |
| 356 | * each direction. If more are added, this code will |
| 357 | * have to be changed to select the proper set. |
| 358 | */ |
| 359 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 360 | dir = 0; |
| 361 | else |
| 362 | dir = 1; |
| 363 | |
Bo Shen | 01f00d5 | 2013-07-03 16:37:56 +0800 | [diff] [blame] | 364 | dma_params = ssc_p->dma_params[dir]; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 365 | |
| 366 | channels = params_channels(params); |
| 367 | |
| 368 | /* |
| 369 | * Determine sample size in bits and the PDC increment. |
| 370 | */ |
| 371 | switch (params_format(params)) { |
| 372 | case SNDRV_PCM_FORMAT_S8: |
| 373 | bits = 8; |
| 374 | dma_params->pdc_xfer_size = 1; |
| 375 | break; |
| 376 | case SNDRV_PCM_FORMAT_S16_LE: |
| 377 | bits = 16; |
| 378 | dma_params->pdc_xfer_size = 2; |
| 379 | break; |
| 380 | case SNDRV_PCM_FORMAT_S24_LE: |
| 381 | bits = 24; |
| 382 | dma_params->pdc_xfer_size = 4; |
| 383 | break; |
| 384 | case SNDRV_PCM_FORMAT_S32_LE: |
| 385 | bits = 32; |
| 386 | dma_params->pdc_xfer_size = 4; |
| 387 | break; |
| 388 | default: |
| 389 | printk(KERN_WARNING "atmel_ssc_dai: unsupported PCM format"); |
| 390 | return -EINVAL; |
| 391 | } |
| 392 | |
| 393 | /* |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 394 | * Compute SSC register settings. |
| 395 | */ |
| 396 | switch (ssc_p->daifmt |
| 397 | & (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_MASTER_MASK)) { |
| 398 | |
| 399 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS: |
| 400 | /* |
| 401 | * I2S format, SSC provides BCLK and LRC clocks. |
| 402 | * |
| 403 | * The SSC transmit and receive clocks are generated |
| 404 | * from the MCK divider, and the BCLK signal |
| 405 | * is output on the SSC TK line. |
| 406 | */ |
Bo Shen | dfaf535 | 2014-06-11 18:14:40 +0800 | [diff] [blame] | 407 | |
| 408 | if (bits > 16 && !ssc->pdata->has_fslen_ext) { |
| 409 | dev_err(dai->dev, |
| 410 | "sample size %d is too large for SSC device\n", |
| 411 | bits); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | |
| 415 | fslen_ext = (bits - 1) / 16; |
| 416 | fslen = (bits - 1) % 16; |
| 417 | |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 418 | rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period) |
| 419 | | SSC_BF(RCMR_STTDLY, START_DELAY) |
| 420 | | SSC_BF(RCMR_START, SSC_START_FALLING_RF) |
| 421 | | SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
| 422 | | SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
| 423 | | SSC_BF(RCMR_CKS, SSC_CKS_DIV); |
| 424 | |
Bo Shen | dfaf535 | 2014-06-11 18:14:40 +0800 | [diff] [blame] | 425 | rfmr = SSC_BF(RFMR_FSLEN_EXT, fslen_ext) |
| 426 | | SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 427 | | SSC_BF(RFMR_FSOS, SSC_FSOS_NEGATIVE) |
Bo Shen | dfaf535 | 2014-06-11 18:14:40 +0800 | [diff] [blame] | 428 | | SSC_BF(RFMR_FSLEN, fslen) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 429 | | SSC_BF(RFMR_DATNB, (channels - 1)) |
| 430 | | SSC_BIT(RFMR_MSBF) |
| 431 | | SSC_BF(RFMR_LOOP, 0) |
| 432 | | SSC_BF(RFMR_DATLEN, (bits - 1)); |
| 433 | |
| 434 | tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period) |
| 435 | | SSC_BF(TCMR_STTDLY, START_DELAY) |
| 436 | | SSC_BF(TCMR_START, SSC_START_FALLING_RF) |
| 437 | | SSC_BF(TCMR_CKI, SSC_CKI_FALLING) |
| 438 | | SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS) |
| 439 | | SSC_BF(TCMR_CKS, SSC_CKS_DIV); |
| 440 | |
Bo Shen | dfaf535 | 2014-06-11 18:14:40 +0800 | [diff] [blame] | 441 | tfmr = SSC_BF(TFMR_FSLEN_EXT, fslen_ext) |
| 442 | | SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 443 | | SSC_BF(TFMR_FSDEN, 0) |
| 444 | | SSC_BF(TFMR_FSOS, SSC_FSOS_NEGATIVE) |
Bo Shen | dfaf535 | 2014-06-11 18:14:40 +0800 | [diff] [blame] | 445 | | SSC_BF(TFMR_FSLEN, fslen) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 446 | | SSC_BF(TFMR_DATNB, (channels - 1)) |
| 447 | | SSC_BIT(TFMR_MSBF) |
| 448 | | SSC_BF(TFMR_DATDEF, 0) |
| 449 | | SSC_BF(TFMR_DATLEN, (bits - 1)); |
| 450 | break; |
| 451 | |
| 452 | case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM: |
| 453 | /* |
| 454 | * I2S format, CODEC supplies BCLK and LRC clocks. |
| 455 | * |
| 456 | * The SSC transmit clock is obtained from the BCLK signal on |
| 457 | * on the TK line, and the SSC receive clock is |
| 458 | * generated from the transmit clock. |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 459 | */ |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 460 | rcmr = SSC_BF(RCMR_PERIOD, 0) |
| 461 | | SSC_BF(RCMR_STTDLY, START_DELAY) |
Bo Shen | a43bd7e | 2015-01-20 15:43:16 +0800 | [diff] [blame] | 462 | | SSC_BF(RCMR_START, SSC_START_FALLING_RF) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 463 | | SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
| 464 | | SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
Bo Shen | 048d4ff | 2014-02-10 14:09:45 +0800 | [diff] [blame] | 465 | | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ? |
| 466 | SSC_CKS_PIN : SSC_CKS_CLOCK); |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 467 | |
| 468 | rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
| 469 | | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE) |
| 470 | | SSC_BF(RFMR_FSLEN, 0) |
Bo Shen | a43bd7e | 2015-01-20 15:43:16 +0800 | [diff] [blame] | 471 | | SSC_BF(RFMR_DATNB, (channels - 1)) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 472 | | SSC_BIT(RFMR_MSBF) |
| 473 | | SSC_BF(RFMR_LOOP, 0) |
| 474 | | SSC_BF(RFMR_DATLEN, (bits - 1)); |
| 475 | |
| 476 | tcmr = SSC_BF(TCMR_PERIOD, 0) |
| 477 | | SSC_BF(TCMR_STTDLY, START_DELAY) |
Bo Shen | a43bd7e | 2015-01-20 15:43:16 +0800 | [diff] [blame] | 478 | | SSC_BF(TCMR_START, SSC_START_FALLING_RF) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 479 | | SSC_BF(TCMR_CKI, SSC_CKI_FALLING) |
| 480 | | SSC_BF(TCMR_CKO, SSC_CKO_NONE) |
Bo Shen | 048d4ff | 2014-02-10 14:09:45 +0800 | [diff] [blame] | 481 | | SSC_BF(TCMR_CKS, ssc->clk_from_rk_pin ? |
| 482 | SSC_CKS_CLOCK : SSC_CKS_PIN); |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 483 | |
| 484 | tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
| 485 | | SSC_BF(TFMR_FSDEN, 0) |
| 486 | | SSC_BF(TFMR_FSOS, SSC_FSOS_NONE) |
| 487 | | SSC_BF(TFMR_FSLEN, 0) |
Bo Shen | a43bd7e | 2015-01-20 15:43:16 +0800 | [diff] [blame] | 488 | | SSC_BF(TFMR_DATNB, (channels - 1)) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 489 | | SSC_BIT(TFMR_MSBF) |
| 490 | | SSC_BF(TFMR_DATDEF, 0) |
| 491 | | SSC_BF(TFMR_DATLEN, (bits - 1)); |
| 492 | break; |
| 493 | |
| 494 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBS_CFS: |
| 495 | /* |
| 496 | * DSP/PCM Mode A format, SSC provides BCLK and LRC clocks. |
| 497 | * |
| 498 | * The SSC transmit and receive clocks are generated from the |
| 499 | * MCK divider, and the BCLK signal is output |
| 500 | * on the SSC TK line. |
| 501 | */ |
| 502 | rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period) |
| 503 | | SSC_BF(RCMR_STTDLY, 1) |
| 504 | | SSC_BF(RCMR_START, SSC_START_RISING_RF) |
| 505 | | SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
| 506 | | SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
| 507 | | SSC_BF(RCMR_CKS, SSC_CKS_DIV); |
| 508 | |
| 509 | rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
| 510 | | SSC_BF(RFMR_FSOS, SSC_FSOS_POSITIVE) |
| 511 | | SSC_BF(RFMR_FSLEN, 0) |
| 512 | | SSC_BF(RFMR_DATNB, (channels - 1)) |
| 513 | | SSC_BIT(RFMR_MSBF) |
| 514 | | SSC_BF(RFMR_LOOP, 0) |
| 515 | | SSC_BF(RFMR_DATLEN, (bits - 1)); |
| 516 | |
| 517 | tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period) |
| 518 | | SSC_BF(TCMR_STTDLY, 1) |
| 519 | | SSC_BF(TCMR_START, SSC_START_RISING_RF) |
| 520 | | SSC_BF(TCMR_CKI, SSC_CKI_RISING) |
| 521 | | SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS) |
| 522 | | SSC_BF(TCMR_CKS, SSC_CKS_DIV); |
| 523 | |
| 524 | tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
| 525 | | SSC_BF(TFMR_FSDEN, 0) |
| 526 | | SSC_BF(TFMR_FSOS, SSC_FSOS_POSITIVE) |
| 527 | | SSC_BF(TFMR_FSLEN, 0) |
| 528 | | SSC_BF(TFMR_DATNB, (channels - 1)) |
| 529 | | SSC_BIT(TFMR_MSBF) |
| 530 | | SSC_BF(TFMR_DATDEF, 0) |
| 531 | | SSC_BF(TFMR_DATLEN, (bits - 1)); |
| 532 | break; |
| 533 | |
| 534 | case SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBM_CFM: |
Zoltan Puskas | f6a75d9 | 2013-02-20 17:31:35 +0100 | [diff] [blame] | 535 | /* |
| 536 | * DSP/PCM Mode A format, CODEC supplies BCLK and LRC clocks. |
| 537 | * |
| 538 | * The SSC transmit clock is obtained from the BCLK signal on |
| 539 | * on the TK line, and the SSC receive clock is |
| 540 | * generated from the transmit clock. |
| 541 | * |
| 542 | * Data is transferred on first BCLK after LRC pulse rising |
| 543 | * edge.If stereo, the right channel data is contiguous with |
| 544 | * the left channel data. |
| 545 | */ |
| 546 | rcmr = SSC_BF(RCMR_PERIOD, 0) |
| 547 | | SSC_BF(RCMR_STTDLY, START_DELAY) |
| 548 | | SSC_BF(RCMR_START, SSC_START_RISING_RF) |
| 549 | | SSC_BF(RCMR_CKI, SSC_CKI_RISING) |
| 550 | | SSC_BF(RCMR_CKO, SSC_CKO_NONE) |
Bo Shen | 048d4ff | 2014-02-10 14:09:45 +0800 | [diff] [blame] | 551 | | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ? |
| 552 | SSC_CKS_PIN : SSC_CKS_CLOCK); |
Zoltan Puskas | f6a75d9 | 2013-02-20 17:31:35 +0100 | [diff] [blame] | 553 | |
| 554 | rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
| 555 | | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE) |
| 556 | | SSC_BF(RFMR_FSLEN, 0) |
| 557 | | SSC_BF(RFMR_DATNB, (channels - 1)) |
| 558 | | SSC_BIT(RFMR_MSBF) |
| 559 | | SSC_BF(RFMR_LOOP, 0) |
| 560 | | SSC_BF(RFMR_DATLEN, (bits - 1)); |
| 561 | |
| 562 | tcmr = SSC_BF(TCMR_PERIOD, 0) |
| 563 | | SSC_BF(TCMR_STTDLY, START_DELAY) |
| 564 | | SSC_BF(TCMR_START, SSC_START_RISING_RF) |
| 565 | | SSC_BF(TCMR_CKI, SSC_CKI_FALLING) |
| 566 | | SSC_BF(TCMR_CKO, SSC_CKO_NONE) |
Bo Shen | 048d4ff | 2014-02-10 14:09:45 +0800 | [diff] [blame] | 567 | | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ? |
| 568 | SSC_CKS_CLOCK : SSC_CKS_PIN); |
Zoltan Puskas | f6a75d9 | 2013-02-20 17:31:35 +0100 | [diff] [blame] | 569 | |
| 570 | tfmr = SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_POSITIVE) |
| 571 | | SSC_BF(TFMR_FSDEN, 0) |
| 572 | | SSC_BF(TFMR_FSOS, SSC_FSOS_NONE) |
| 573 | | SSC_BF(TFMR_FSLEN, 0) |
| 574 | | SSC_BF(TFMR_DATNB, (channels - 1)) |
| 575 | | SSC_BIT(TFMR_MSBF) |
| 576 | | SSC_BF(TFMR_DATDEF, 0) |
| 577 | | SSC_BF(TFMR_DATLEN, (bits - 1)); |
| 578 | break; |
| 579 | |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 580 | default: |
| 581 | printk(KERN_WARNING "atmel_ssc_dai: unsupported DAI format 0x%x\n", |
| 582 | ssc_p->daifmt); |
| 583 | return -EINVAL; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 584 | } |
| 585 | pr_debug("atmel_ssc_hw_params: " |
| 586 | "RCMR=%08x RFMR=%08x TCMR=%08x TFMR=%08x\n", |
| 587 | rcmr, rfmr, tcmr, tfmr); |
| 588 | |
| 589 | if (!ssc_p->initialized) { |
| 590 | |
| 591 | /* Enable PMC peripheral clock for this SSC */ |
| 592 | pr_debug("atmel_ssc_dai: Starting clock\n"); |
| 593 | clk_enable(ssc_p->ssc->clk); |
| 594 | |
| 595 | /* Reset the SSC and its PDC registers */ |
| 596 | ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST)); |
| 597 | |
| 598 | ssc_writel(ssc_p->ssc->regs, PDC_RPR, 0); |
| 599 | ssc_writel(ssc_p->ssc->regs, PDC_RCR, 0); |
| 600 | ssc_writel(ssc_p->ssc->regs, PDC_RNPR, 0); |
| 601 | ssc_writel(ssc_p->ssc->regs, PDC_RNCR, 0); |
| 602 | |
| 603 | ssc_writel(ssc_p->ssc->regs, PDC_TPR, 0); |
| 604 | ssc_writel(ssc_p->ssc->regs, PDC_TCR, 0); |
| 605 | ssc_writel(ssc_p->ssc->regs, PDC_TNPR, 0); |
| 606 | ssc_writel(ssc_p->ssc->regs, PDC_TNCR, 0); |
| 607 | |
| 608 | ret = request_irq(ssc_p->ssc->irq, atmel_ssc_interrupt, 0, |
| 609 | ssc_p->name, ssc_p); |
| 610 | if (ret < 0) { |
| 611 | printk(KERN_WARNING |
| 612 | "atmel_ssc_dai: request_irq failure\n"); |
| 613 | pr_debug("Atmel_ssc_dai: Stoping clock\n"); |
| 614 | clk_disable(ssc_p->ssc->clk); |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | ssc_p->initialized = 1; |
| 619 | } |
| 620 | |
| 621 | /* set SSC clock mode register */ |
| 622 | ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->cmr_div); |
| 623 | |
| 624 | /* set receive clock mode and format */ |
| 625 | ssc_writel(ssc_p->ssc->regs, RCMR, rcmr); |
| 626 | ssc_writel(ssc_p->ssc->regs, RFMR, rfmr); |
| 627 | |
| 628 | /* set transmit clock mode and format */ |
| 629 | ssc_writel(ssc_p->ssc->regs, TCMR, tcmr); |
| 630 | ssc_writel(ssc_p->ssc->regs, TFMR, tfmr); |
| 631 | |
| 632 | pr_debug("atmel_ssc_dai,hw_params: SSC initialized\n"); |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 637 | static int atmel_ssc_prepare(struct snd_pcm_substream *substream, |
| 638 | struct snd_soc_dai *dai) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 639 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 640 | struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 641 | struct atmel_pcm_dma_params *dma_params; |
| 642 | int dir; |
| 643 | |
| 644 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 645 | dir = 0; |
| 646 | else |
| 647 | dir = 1; |
| 648 | |
| 649 | dma_params = ssc_p->dma_params[dir]; |
| 650 | |
Bo Shen | a8f1f10 | 2013-12-04 10:37:03 +0800 | [diff] [blame] | 651 | ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable); |
Bo Shen | e011143 | 2013-09-04 15:27:46 +0800 | [diff] [blame] | 652 | ssc_writel(ssc_p->ssc->regs, IDR, dma_params->mask->ssc_error); |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 653 | |
| 654 | pr_debug("%s enabled SSC_SR=0x%08x\n", |
| 655 | dir ? "receive" : "transmit", |
| 656 | ssc_readl(ssc_p->ssc->regs, SR)); |
| 657 | return 0; |
| 658 | } |
| 659 | |
Bo Shen | a8f1f10 | 2013-12-04 10:37:03 +0800 | [diff] [blame] | 660 | static int atmel_ssc_trigger(struct snd_pcm_substream *substream, |
| 661 | int cmd, struct snd_soc_dai *dai) |
| 662 | { |
| 663 | struct atmel_ssc_info *ssc_p = &ssc_info[dai->id]; |
| 664 | struct atmel_pcm_dma_params *dma_params; |
| 665 | int dir; |
| 666 | |
| 667 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 668 | dir = 0; |
| 669 | else |
| 670 | dir = 1; |
| 671 | |
| 672 | dma_params = ssc_p->dma_params[dir]; |
| 673 | |
| 674 | switch (cmd) { |
| 675 | case SNDRV_PCM_TRIGGER_START: |
| 676 | case SNDRV_PCM_TRIGGER_RESUME: |
| 677 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 678 | ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_enable); |
| 679 | break; |
| 680 | default: |
| 681 | ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable); |
| 682 | break; |
| 683 | } |
| 684 | |
| 685 | return 0; |
| 686 | } |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 687 | |
| 688 | #ifdef CONFIG_PM |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 689 | static int atmel_ssc_suspend(struct snd_soc_dai *cpu_dai) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 690 | { |
| 691 | struct atmel_ssc_info *ssc_p; |
| 692 | |
| 693 | if (!cpu_dai->active) |
| 694 | return 0; |
| 695 | |
| 696 | ssc_p = &ssc_info[cpu_dai->id]; |
| 697 | |
| 698 | /* Save the status register before disabling transmit and receive */ |
| 699 | ssc_p->ssc_state.ssc_sr = ssc_readl(ssc_p->ssc->regs, SR); |
| 700 | ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_TXDIS) | SSC_BIT(CR_RXDIS)); |
| 701 | |
| 702 | /* Save the current interrupt mask, then disable unmasked interrupts */ |
| 703 | ssc_p->ssc_state.ssc_imr = ssc_readl(ssc_p->ssc->regs, IMR); |
| 704 | ssc_writel(ssc_p->ssc->regs, IDR, ssc_p->ssc_state.ssc_imr); |
| 705 | |
| 706 | ssc_p->ssc_state.ssc_cmr = ssc_readl(ssc_p->ssc->regs, CMR); |
| 707 | ssc_p->ssc_state.ssc_rcmr = ssc_readl(ssc_p->ssc->regs, RCMR); |
| 708 | ssc_p->ssc_state.ssc_rfmr = ssc_readl(ssc_p->ssc->regs, RFMR); |
| 709 | ssc_p->ssc_state.ssc_tcmr = ssc_readl(ssc_p->ssc->regs, TCMR); |
| 710 | ssc_p->ssc_state.ssc_tfmr = ssc_readl(ssc_p->ssc->regs, TFMR); |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | |
| 716 | |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 717 | static int atmel_ssc_resume(struct snd_soc_dai *cpu_dai) |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 718 | { |
| 719 | struct atmel_ssc_info *ssc_p; |
| 720 | u32 cr; |
| 721 | |
| 722 | if (!cpu_dai->active) |
| 723 | return 0; |
| 724 | |
| 725 | ssc_p = &ssc_info[cpu_dai->id]; |
| 726 | |
| 727 | /* restore SSC register settings */ |
| 728 | ssc_writel(ssc_p->ssc->regs, TFMR, ssc_p->ssc_state.ssc_tfmr); |
| 729 | ssc_writel(ssc_p->ssc->regs, TCMR, ssc_p->ssc_state.ssc_tcmr); |
| 730 | ssc_writel(ssc_p->ssc->regs, RFMR, ssc_p->ssc_state.ssc_rfmr); |
| 731 | ssc_writel(ssc_p->ssc->regs, RCMR, ssc_p->ssc_state.ssc_rcmr); |
| 732 | ssc_writel(ssc_p->ssc->regs, CMR, ssc_p->ssc_state.ssc_cmr); |
| 733 | |
| 734 | /* re-enable interrupts */ |
| 735 | ssc_writel(ssc_p->ssc->regs, IER, ssc_p->ssc_state.ssc_imr); |
| 736 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 737 | /* Re-enable receive and transmit as appropriate */ |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 738 | cr = 0; |
| 739 | cr |= |
| 740 | (ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_RXEN)) ? SSC_BIT(CR_RXEN) : 0; |
| 741 | cr |= |
| 742 | (ssc_p->ssc_state.ssc_sr & SSC_BIT(SR_TXEN)) ? SSC_BIT(CR_TXEN) : 0; |
| 743 | ssc_writel(ssc_p->ssc->regs, CR, cr); |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | #else /* CONFIG_PM */ |
| 748 | # define atmel_ssc_suspend NULL |
| 749 | # define atmel_ssc_resume NULL |
| 750 | #endif /* CONFIG_PM */ |
| 751 | |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 752 | #define ATMEL_SSC_RATES (SNDRV_PCM_RATE_8000_96000) |
| 753 | |
| 754 | #define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ |
| 755 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 756 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 757 | static const struct snd_soc_dai_ops atmel_ssc_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 758 | .startup = atmel_ssc_startup, |
| 759 | .shutdown = atmel_ssc_shutdown, |
| 760 | .prepare = atmel_ssc_prepare, |
Bo Shen | a8f1f10 | 2013-12-04 10:37:03 +0800 | [diff] [blame] | 761 | .trigger = atmel_ssc_trigger, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 762 | .hw_params = atmel_ssc_hw_params, |
| 763 | .set_fmt = atmel_ssc_set_dai_fmt, |
| 764 | .set_clkdiv = atmel_ssc_set_dai_clkdiv, |
| 765 | }; |
| 766 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 767 | static struct snd_soc_dai_driver atmel_ssc_dai = { |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 768 | .suspend = atmel_ssc_suspend, |
| 769 | .resume = atmel_ssc_resume, |
| 770 | .playback = { |
| 771 | .channels_min = 1, |
| 772 | .channels_max = 2, |
| 773 | .rates = ATMEL_SSC_RATES, |
| 774 | .formats = ATMEL_SSC_FORMATS,}, |
| 775 | .capture = { |
| 776 | .channels_min = 1, |
| 777 | .channels_max = 2, |
| 778 | .rates = ATMEL_SSC_RATES, |
| 779 | .formats = ATMEL_SSC_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 780 | .ops = &atmel_ssc_dai_ops, |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 781 | }; |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 782 | |
Kuninori Morimoto | a2c662c | 2013-03-21 03:28:24 -0700 | [diff] [blame] | 783 | static const struct snd_soc_component_driver atmel_ssc_component = { |
| 784 | .name = "atmel-ssc", |
| 785 | }; |
| 786 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 787 | static int asoc_ssc_init(struct device *dev) |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 788 | { |
Bo Shen | 3951e4a | 2012-11-28 11:46:13 +0800 | [diff] [blame] | 789 | struct platform_device *pdev = to_platform_device(dev); |
| 790 | struct ssc_device *ssc = platform_get_drvdata(pdev); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 791 | int ret; |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 792 | |
Kuninori Morimoto | a2c662c | 2013-03-21 03:28:24 -0700 | [diff] [blame] | 793 | ret = snd_soc_register_component(dev, &atmel_ssc_component, |
| 794 | &atmel_ssc_dai, 1); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 795 | if (ret) { |
| 796 | dev_err(dev, "Could not register DAI: %d\n", ret); |
| 797 | goto err; |
| 798 | } |
| 799 | |
Bo Shen | 3951e4a | 2012-11-28 11:46:13 +0800 | [diff] [blame] | 800 | if (ssc->pdata->use_dma) |
| 801 | ret = atmel_pcm_dma_platform_register(dev); |
| 802 | else |
| 803 | ret = atmel_pcm_pdc_platform_register(dev); |
| 804 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 805 | if (ret) { |
| 806 | dev_err(dev, "Could not register PCM: %d\n", ret); |
| 807 | goto err_unregister_dai; |
Joe Perches | 1d198f2 | 2013-10-08 15:55:45 -0700 | [diff] [blame] | 808 | } |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 809 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 810 | return 0; |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 811 | |
| 812 | err_unregister_dai: |
Kuninori Morimoto | a2c662c | 2013-03-21 03:28:24 -0700 | [diff] [blame] | 813 | snd_soc_unregister_component(dev); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 814 | err: |
| 815 | return ret; |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 816 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 817 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 818 | static void asoc_ssc_exit(struct device *dev) |
| 819 | { |
Bo Shen | 3951e4a | 2012-11-28 11:46:13 +0800 | [diff] [blame] | 820 | struct platform_device *pdev = to_platform_device(dev); |
| 821 | struct ssc_device *ssc = platform_get_drvdata(pdev); |
| 822 | |
| 823 | if (ssc->pdata->use_dma) |
| 824 | atmel_pcm_dma_platform_unregister(dev); |
| 825 | else |
| 826 | atmel_pcm_pdc_platform_unregister(dev); |
| 827 | |
Kuninori Morimoto | a2c662c | 2013-03-21 03:28:24 -0700 | [diff] [blame] | 828 | snd_soc_unregister_component(dev); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 829 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 830 | |
Mark Brown | abfa4ea | 2010-08-18 16:29:37 +0100 | [diff] [blame] | 831 | /** |
| 832 | * atmel_ssc_set_audio - Allocate the specified SSC for audio use. |
| 833 | */ |
| 834 | int atmel_ssc_set_audio(int ssc_id) |
| 835 | { |
| 836 | struct ssc_device *ssc; |
Mark Brown | abfa4ea | 2010-08-18 16:29:37 +0100 | [diff] [blame] | 837 | int ret; |
| 838 | |
Mark Brown | abfa4ea | 2010-08-18 16:29:37 +0100 | [diff] [blame] | 839 | /* If we can grab the SSC briefly to parent the DAI device off it */ |
| 840 | ssc = ssc_request(ssc_id); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 841 | if (IS_ERR(ssc)) { |
| 842 | pr_err("Unable to parent ASoC SSC DAI on SSC: %ld\n", |
Mark Brown | abfa4ea | 2010-08-18 16:29:37 +0100 | [diff] [blame] | 843 | PTR_ERR(ssc)); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 844 | return PTR_ERR(ssc); |
| 845 | } else { |
| 846 | ssc_info[ssc_id].ssc = ssc; |
Joachim Eastwood | 840d8e5 | 2011-06-01 23:59:10 +0200 | [diff] [blame] | 847 | } |
Mark Brown | abfa4ea | 2010-08-18 16:29:37 +0100 | [diff] [blame] | 848 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 849 | ret = asoc_ssc_init(&ssc->pdev->dev); |
Mark Brown | abfa4ea | 2010-08-18 16:29:37 +0100 | [diff] [blame] | 850 | |
| 851 | return ret; |
| 852 | } |
| 853 | EXPORT_SYMBOL_GPL(atmel_ssc_set_audio); |
| 854 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 855 | void atmel_ssc_put_audio(int ssc_id) |
| 856 | { |
| 857 | struct ssc_device *ssc = ssc_info[ssc_id].ssc; |
| 858 | |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 859 | asoc_ssc_exit(&ssc->pdev->dev); |
Bo Shen | 6970602 | 2013-01-31 11:53:39 +0800 | [diff] [blame] | 860 | ssc_free(ssc); |
Bo Shen | be681a8 | 2012-11-14 18:09:09 +0800 | [diff] [blame] | 861 | } |
| 862 | EXPORT_SYMBOL_GPL(atmel_ssc_put_audio); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 863 | |
Sedji Gaouaou | 6c74250 | 2008-10-03 16:57:50 +0200 | [diff] [blame] | 864 | /* Module information */ |
| 865 | MODULE_AUTHOR("Sedji Gaouaou, sedji.gaouaou@atmel.com, www.atmel.com"); |
| 866 | MODULE_DESCRIPTION("ATMEL SSC ASoC Interface"); |
| 867 | MODULE_LICENSE("GPL"); |