2 * Freescale S/PDIF ALSA SoC Digital Audio Interface (DAI) driver
4 * Copyright (C) 2013 Freescale Semiconductor, Inc.
6 * Based on stmp3xxx_spdif_dai.c
7 * Vladimir Barinov <vbarinov@embeddedalley.com>
8 * Copyright 2008 SigmaTel, Inc
9 * Copyright 2008 Embedded Alley Solutions, Inc
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
16 #include <linux/bitrev.h>
17 #include <linux/clk.h>
18 #include <linux/module.h>
19 #include <linux/of_address.h>
20 #include <linux/of_device.h>
21 #include <linux/of_irq.h>
22 #include <linux/regmap.h>
24 #include <sound/asoundef.h>
25 #include <sound/dmaengine_pcm.h>
26 #include <sound/soc.h>
28 #include "fsl_spdif.h"
31 #define FSL_SPDIF_TXFIFO_WML 0x8
32 #define FSL_SPDIF_RXFIFO_WML 0x8
34 #define INTR_FOR_PLAYBACK (INT_TXFIFO_RESYNC)
35 #define INTR_FOR_CAPTURE (INT_SYM_ERR | INT_BIT_ERR | INT_URX_FUL |\
36 INT_URX_OV | INT_QRX_FUL | INT_QRX_OV |\
37 INT_UQ_SYNC | INT_UQ_ERR | INT_RXFIFO_RESYNC |\
38 INT_LOSS_LOCK | INT_DPLL_LOCKED)
40 #define SIE_INTR_FOR(tx) (tx ? INTR_FOR_PLAYBACK : INTR_FOR_CAPTURE)
42 /* Index list for the values that has if (DPLL Locked) condition */
43 static u8 srpc_dpll_locked[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0xa, 0xb };
44 #define SRPC_NODPLL_START1 0x5
45 #define SRPC_NODPLL_START2 0xc
47 #define DEFAULT_RXCLK_SRC 1
50 * SPDIF control structure
51 * Defines channel status, subcode and Q sub
53 struct spdif_mixer_control {
54 /* spinlock to access control data */
57 /* IEC958 channel tx status bit */
58 unsigned char ch_status[4];
61 unsigned char subcode[2 * SPDIF_UBITS_SIZE];
63 /* Q subcode part of user bits */
64 unsigned char qsub[2 * SPDIF_QSUB_SIZE];
66 /* Buffer offset for U/Q */
70 /* Ready buffer index of the two buffers */
75 * fsl_spdif_priv: Freescale SPDIF private data
77 * @fsl_spdif_control: SPDIF control data
78 * @cpu_dai_drv: cpu dai driver
79 * @pdev: platform device pointer
80 * @regmap: regmap handler
81 * @dpll_locked: dpll lock flag
82 * @txrate: the best rates for playback
83 * @txclk_df: STC_TXCLK_DF dividers value for playback
84 * @sysclk_df: STC_SYSCLK_DF dividers value for playback
85 * @txclk_src: STC_TXCLK_SRC values for playback
86 * @rxclk_src: SRPC_CLKSRC_SEL values for capture
87 * @txclk: tx clock sources for playback
88 * @rxclk: rx clock sources for capture
89 * @coreclk: core clock for register access via DMA
90 * @sysclk: system clock for rx clock rate measurement
91 * @spbaclk: SPBA clock (optional, depending on SoC design)
92 * @dma_params_tx: DMA parameters for transmit channel
93 * @dma_params_rx: DMA parameters for receive channel
95 struct fsl_spdif_priv {
96 struct spdif_mixer_control fsl_spdif_control;
97 struct snd_soc_dai_driver cpu_dai_drv;
98 struct platform_device *pdev;
99 struct regmap *regmap;
101 u32 txrate[SPDIF_TXRATE_MAX];
102 u8 txclk_df[SPDIF_TXRATE_MAX];
103 u8 sysclk_df[SPDIF_TXRATE_MAX];
104 u8 txclk_src[SPDIF_TXRATE_MAX];
106 struct clk *txclk[SPDIF_TXRATE_MAX];
111 struct snd_dmaengine_dai_dma_data dma_params_tx;
112 struct snd_dmaengine_dai_dma_data dma_params_rx;
113 /* regcache for SRPC */
117 /* DPLL locked and lock loss interrupt handler */
118 static void spdif_irq_dpll_lock(struct fsl_spdif_priv *spdif_priv)
120 struct regmap *regmap = spdif_priv->regmap;
121 struct platform_device *pdev = spdif_priv->pdev;
124 regmap_read(regmap, REG_SPDIF_SRPC, &locked);
125 locked &= SRPC_DPLL_LOCKED;
127 dev_dbg(&pdev->dev, "isr: Rx dpll %s \n",
128 locked ? "locked" : "loss lock");
130 spdif_priv->dpll_locked = locked ? true : false;
133 /* Receiver found illegal symbol interrupt handler */
134 static void spdif_irq_sym_error(struct fsl_spdif_priv *spdif_priv)
136 struct regmap *regmap = spdif_priv->regmap;
137 struct platform_device *pdev = spdif_priv->pdev;
139 dev_dbg(&pdev->dev, "isr: receiver found illegal symbol\n");
141 /* Clear illegal symbol if DPLL unlocked since no audio stream */
142 if (!spdif_priv->dpll_locked)
143 regmap_update_bits(regmap, REG_SPDIF_SIE, INT_SYM_ERR, 0);
146 /* U/Q Channel receive register full */
147 static void spdif_irq_uqrx_full(struct fsl_spdif_priv *spdif_priv, char name)
149 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
150 struct regmap *regmap = spdif_priv->regmap;
151 struct platform_device *pdev = spdif_priv->pdev;
152 u32 *pos, size, val, reg;
157 size = SPDIF_UBITS_SIZE;
162 size = SPDIF_QSUB_SIZE;
166 dev_err(&pdev->dev, "unsupported channel name\n");
170 dev_dbg(&pdev->dev, "isr: %c Channel receive register full\n", name);
172 if (*pos >= size * 2) {
174 } else if (unlikely((*pos % size) + 3 > size)) {
175 dev_err(&pdev->dev, "User bit receive buffer overflow\n");
179 regmap_read(regmap, reg, &val);
180 ctrl->subcode[*pos++] = val >> 16;
181 ctrl->subcode[*pos++] = val >> 8;
182 ctrl->subcode[*pos++] = val;
185 /* U/Q Channel sync found */
186 static void spdif_irq_uq_sync(struct fsl_spdif_priv *spdif_priv)
188 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
189 struct platform_device *pdev = spdif_priv->pdev;
191 dev_dbg(&pdev->dev, "isr: U/Q Channel sync found\n");
193 /* U/Q buffer reset */
197 /* Set ready to this buffer */
198 ctrl->ready_buf = (ctrl->qpos - 1) / SPDIF_QSUB_SIZE + 1;
201 /* U/Q Channel framing error */
202 static void spdif_irq_uq_err(struct fsl_spdif_priv *spdif_priv)
204 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
205 struct regmap *regmap = spdif_priv->regmap;
206 struct platform_device *pdev = spdif_priv->pdev;
209 dev_dbg(&pdev->dev, "isr: U/Q Channel framing error\n");
211 /* Read U/Q data to clear the irq and do buffer reset */
212 regmap_read(regmap, REG_SPDIF_SRU, &val);
213 regmap_read(regmap, REG_SPDIF_SRQ, &val);
215 /* Drop this U/Q buffer */
221 /* Get spdif interrupt status and clear the interrupt */
222 static u32 spdif_intr_status_clear(struct fsl_spdif_priv *spdif_priv)
224 struct regmap *regmap = spdif_priv->regmap;
227 regmap_read(regmap, REG_SPDIF_SIS, &val);
228 regmap_read(regmap, REG_SPDIF_SIE, &val2);
230 regmap_write(regmap, REG_SPDIF_SIC, val & val2);
235 static irqreturn_t spdif_isr(int irq, void *devid)
237 struct fsl_spdif_priv *spdif_priv = (struct fsl_spdif_priv *)devid;
238 struct platform_device *pdev = spdif_priv->pdev;
241 sis = spdif_intr_status_clear(spdif_priv);
243 if (sis & INT_DPLL_LOCKED)
244 spdif_irq_dpll_lock(spdif_priv);
246 if (sis & INT_TXFIFO_UNOV)
247 dev_dbg(&pdev->dev, "isr: Tx FIFO under/overrun\n");
249 if (sis & INT_TXFIFO_RESYNC)
250 dev_dbg(&pdev->dev, "isr: Tx FIFO resync\n");
253 dev_dbg(&pdev->dev, "isr: cstatus new\n");
255 if (sis & INT_VAL_NOGOOD)
256 dev_dbg(&pdev->dev, "isr: validity flag no good\n");
258 if (sis & INT_SYM_ERR)
259 spdif_irq_sym_error(spdif_priv);
261 if (sis & INT_BIT_ERR)
262 dev_dbg(&pdev->dev, "isr: receiver found parity bit error\n");
264 if (sis & INT_URX_FUL)
265 spdif_irq_uqrx_full(spdif_priv, 'U');
267 if (sis & INT_URX_OV)
268 dev_dbg(&pdev->dev, "isr: U Channel receive register overrun\n");
270 if (sis & INT_QRX_FUL)
271 spdif_irq_uqrx_full(spdif_priv, 'Q');
273 if (sis & INT_QRX_OV)
274 dev_dbg(&pdev->dev, "isr: Q Channel receive register overrun\n");
276 if (sis & INT_UQ_SYNC)
277 spdif_irq_uq_sync(spdif_priv);
279 if (sis & INT_UQ_ERR)
280 spdif_irq_uq_err(spdif_priv);
282 if (sis & INT_RXFIFO_UNOV)
283 dev_dbg(&pdev->dev, "isr: Rx FIFO under/overrun\n");
285 if (sis & INT_RXFIFO_RESYNC)
286 dev_dbg(&pdev->dev, "isr: Rx FIFO resync\n");
288 if (sis & INT_LOSS_LOCK)
289 spdif_irq_dpll_lock(spdif_priv);
291 /* FIXME: Write Tx FIFO to clear TxEm */
293 dev_dbg(&pdev->dev, "isr: Tx FIFO empty\n");
295 /* FIXME: Read Rx FIFO to clear RxFIFOFul */
296 if (sis & INT_RXFIFO_FUL)
297 dev_dbg(&pdev->dev, "isr: Rx FIFO full\n");
302 static int spdif_softreset(struct fsl_spdif_priv *spdif_priv)
304 struct regmap *regmap = spdif_priv->regmap;
305 u32 val, cycle = 1000;
307 regcache_cache_bypass(regmap, true);
309 regmap_write(regmap, REG_SPDIF_SCR, SCR_SOFT_RESET);
312 * RESET bit would be cleared after finishing its reset procedure,
313 * which typically lasts 8 cycles. 1000 cycles will keep it safe.
316 regmap_read(regmap, REG_SPDIF_SCR, &val);
317 } while ((val & SCR_SOFT_RESET) && cycle--);
319 regcache_cache_bypass(regmap, false);
320 regcache_mark_dirty(regmap);
321 regcache_sync(regmap);
329 static void spdif_set_cstatus(struct spdif_mixer_control *ctrl,
332 ctrl->ch_status[3] &= ~mask;
333 ctrl->ch_status[3] |= cstatus & mask;
336 static void spdif_write_channel_status(struct fsl_spdif_priv *spdif_priv)
338 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
339 struct regmap *regmap = spdif_priv->regmap;
340 struct platform_device *pdev = spdif_priv->pdev;
343 ch_status = (bitrev8(ctrl->ch_status[0]) << 16) |
344 (bitrev8(ctrl->ch_status[1]) << 8) |
345 bitrev8(ctrl->ch_status[2]);
346 regmap_write(regmap, REG_SPDIF_STCSCH, ch_status);
348 dev_dbg(&pdev->dev, "STCSCH: 0x%06x\n", ch_status);
350 ch_status = bitrev8(ctrl->ch_status[3]) << 16;
351 regmap_write(regmap, REG_SPDIF_STCSCL, ch_status);
353 dev_dbg(&pdev->dev, "STCSCL: 0x%06x\n", ch_status);
356 /* Set SPDIF PhaseConfig register for rx clock */
357 static int spdif_set_rx_clksrc(struct fsl_spdif_priv *spdif_priv,
358 enum spdif_gainsel gainsel, int dpll_locked)
360 struct regmap *regmap = spdif_priv->regmap;
361 u8 clksrc = spdif_priv->rxclk_src;
363 if (clksrc >= SRPC_CLKSRC_MAX || gainsel >= GAINSEL_MULTI_MAX)
366 regmap_update_bits(regmap, REG_SPDIF_SRPC,
367 SRPC_CLKSRC_SEL_MASK | SRPC_GAINSEL_MASK,
368 SRPC_CLKSRC_SEL_SET(clksrc) | SRPC_GAINSEL_SET(gainsel));
373 static int spdif_set_sample_rate(struct snd_pcm_substream *substream,
376 struct snd_soc_pcm_runtime *rtd = substream->private_data;
377 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
378 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
379 struct regmap *regmap = spdif_priv->regmap;
380 struct platform_device *pdev = spdif_priv->pdev;
381 unsigned long csfs = 0;
383 u8 clk, txclk_df, sysclk_df;
386 switch (sample_rate) {
388 rate = SPDIF_TXRATE_32000;
389 csfs = IEC958_AES3_CON_FS_32000;
392 rate = SPDIF_TXRATE_44100;
393 csfs = IEC958_AES3_CON_FS_44100;
396 rate = SPDIF_TXRATE_48000;
397 csfs = IEC958_AES3_CON_FS_48000;
400 rate = SPDIF_TXRATE_96000;
401 csfs = IEC958_AES3_CON_FS_96000;
404 rate = SPDIF_TXRATE_192000;
405 csfs = IEC958_AES3_CON_FS_192000;
408 dev_err(&pdev->dev, "unsupported sample rate %d\n", sample_rate);
412 clk = spdif_priv->txclk_src[rate];
413 if (clk >= STC_TXCLK_SRC_MAX) {
414 dev_err(&pdev->dev, "tx clock source is out of range\n");
418 txclk_df = spdif_priv->txclk_df[rate];
420 dev_err(&pdev->dev, "the txclk_df can't be zero\n");
424 sysclk_df = spdif_priv->sysclk_df[rate];
426 /* Don't mess up the clocks from other modules */
427 if (clk != STC_TXCLK_SPDIF_ROOT)
430 /* The S/PDIF block needs a clock of 64 * fs * txclk_df */
431 ret = clk_set_rate(spdif_priv->txclk[rate],
432 64 * sample_rate * txclk_df);
434 dev_err(&pdev->dev, "failed to set tx clock rate\n");
439 dev_dbg(&pdev->dev, "expected clock rate = %d\n",
440 (64 * sample_rate * txclk_df * sysclk_df));
441 dev_dbg(&pdev->dev, "actual clock rate = %ld\n",
442 clk_get_rate(spdif_priv->txclk[rate]));
444 /* set fs field in consumer channel status */
445 spdif_set_cstatus(ctrl, IEC958_AES3_CON_FS, csfs);
447 /* select clock source and divisor */
448 stc = STC_TXCLK_ALL_EN | STC_TXCLK_SRC_SET(clk) |
449 STC_TXCLK_DF(txclk_df) | STC_SYSCLK_DF(sysclk_df);
450 mask = STC_TXCLK_ALL_EN_MASK | STC_TXCLK_SRC_MASK |
451 STC_TXCLK_DF_MASK | STC_SYSCLK_DF_MASK;
452 regmap_update_bits(regmap, REG_SPDIF_STC, mask, stc);
454 dev_dbg(&pdev->dev, "set sample rate to %dHz for %dHz playback\n",
455 spdif_priv->txrate[rate], sample_rate);
460 static int fsl_spdif_startup(struct snd_pcm_substream *substream,
461 struct snd_soc_dai *cpu_dai)
463 struct snd_soc_pcm_runtime *rtd = substream->private_data;
464 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
465 struct platform_device *pdev = spdif_priv->pdev;
466 struct regmap *regmap = spdif_priv->regmap;
471 /* Reset module and interrupts only for first initialization */
472 if (!cpu_dai->active) {
473 ret = clk_prepare_enable(spdif_priv->coreclk);
475 dev_err(&pdev->dev, "failed to enable core clock\n");
479 if (!IS_ERR(spdif_priv->spbaclk)) {
480 ret = clk_prepare_enable(spdif_priv->spbaclk);
482 dev_err(&pdev->dev, "failed to enable spba clock\n");
487 ret = spdif_softreset(spdif_priv);
489 dev_err(&pdev->dev, "failed to soft reset\n");
493 /* Disable all the interrupts */
494 regmap_update_bits(regmap, REG_SPDIF_SIE, 0xffffff, 0);
497 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
498 scr = SCR_TXFIFO_AUTOSYNC | SCR_TXFIFO_CTRL_NORMAL |
499 SCR_TXSEL_NORMAL | SCR_USRC_SEL_CHIP |
501 mask = SCR_TXFIFO_AUTOSYNC_MASK | SCR_TXFIFO_CTRL_MASK |
502 SCR_TXSEL_MASK | SCR_USRC_SEL_MASK |
503 SCR_TXFIFO_FSEL_MASK;
504 for (i = 0; i < SPDIF_TXRATE_MAX; i++) {
505 ret = clk_prepare_enable(spdif_priv->txclk[i]);
510 scr = SCR_RXFIFO_FSEL_IF8 | SCR_RXFIFO_AUTOSYNC;
511 mask = SCR_RXFIFO_FSEL_MASK | SCR_RXFIFO_AUTOSYNC_MASK|
512 SCR_RXFIFO_CTL_MASK | SCR_RXFIFO_OFF_MASK;
513 ret = clk_prepare_enable(spdif_priv->rxclk);
517 regmap_update_bits(regmap, REG_SPDIF_SCR, mask, scr);
519 /* Power up SPDIF module */
520 regmap_update_bits(regmap, REG_SPDIF_SCR, SCR_LOW_POWER, 0);
525 for (i--; i >= 0; i--)
526 clk_disable_unprepare(spdif_priv->txclk[i]);
528 if (!IS_ERR(spdif_priv->spbaclk))
529 clk_disable_unprepare(spdif_priv->spbaclk);
531 clk_disable_unprepare(spdif_priv->coreclk);
536 static void fsl_spdif_shutdown(struct snd_pcm_substream *substream,
537 struct snd_soc_dai *cpu_dai)
539 struct snd_soc_pcm_runtime *rtd = substream->private_data;
540 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
541 struct regmap *regmap = spdif_priv->regmap;
544 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
546 mask = SCR_TXFIFO_AUTOSYNC_MASK | SCR_TXFIFO_CTRL_MASK |
547 SCR_TXSEL_MASK | SCR_USRC_SEL_MASK |
548 SCR_TXFIFO_FSEL_MASK;
549 for (i = 0; i < SPDIF_TXRATE_MAX; i++)
550 clk_disable_unprepare(spdif_priv->txclk[i]);
552 scr = SCR_RXFIFO_OFF | SCR_RXFIFO_CTL_ZERO;
553 mask = SCR_RXFIFO_FSEL_MASK | SCR_RXFIFO_AUTOSYNC_MASK|
554 SCR_RXFIFO_CTL_MASK | SCR_RXFIFO_OFF_MASK;
555 clk_disable_unprepare(spdif_priv->rxclk);
557 regmap_update_bits(regmap, REG_SPDIF_SCR, mask, scr);
559 /* Power down SPDIF module only if tx&rx are both inactive */
560 if (!cpu_dai->active) {
561 spdif_intr_status_clear(spdif_priv);
562 regmap_update_bits(regmap, REG_SPDIF_SCR,
563 SCR_LOW_POWER, SCR_LOW_POWER);
564 if (!IS_ERR(spdif_priv->spbaclk))
565 clk_disable_unprepare(spdif_priv->spbaclk);
566 clk_disable_unprepare(spdif_priv->coreclk);
570 static int fsl_spdif_hw_params(struct snd_pcm_substream *substream,
571 struct snd_pcm_hw_params *params,
572 struct snd_soc_dai *dai)
574 struct snd_soc_pcm_runtime *rtd = substream->private_data;
575 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
576 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
577 struct platform_device *pdev = spdif_priv->pdev;
578 u32 sample_rate = params_rate(params);
581 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
582 ret = spdif_set_sample_rate(substream, sample_rate);
584 dev_err(&pdev->dev, "%s: set sample rate failed: %d\n",
585 __func__, sample_rate);
588 spdif_set_cstatus(ctrl, IEC958_AES3_CON_CLOCK,
589 IEC958_AES3_CON_CLOCK_1000PPM);
590 spdif_write_channel_status(spdif_priv);
592 /* Setup rx clock source */
593 ret = spdif_set_rx_clksrc(spdif_priv, SPDIF_DEFAULT_GAINSEL, 1);
599 static int fsl_spdif_trigger(struct snd_pcm_substream *substream,
600 int cmd, struct snd_soc_dai *dai)
602 struct snd_soc_pcm_runtime *rtd = substream->private_data;
603 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
604 struct regmap *regmap = spdif_priv->regmap;
605 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
606 u32 intr = SIE_INTR_FOR(tx);
607 u32 dmaen = SCR_DMA_xX_EN(tx);
610 case SNDRV_PCM_TRIGGER_START:
611 case SNDRV_PCM_TRIGGER_RESUME:
612 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
613 regmap_update_bits(regmap, REG_SPDIF_SIE, intr, intr);
614 regmap_update_bits(regmap, REG_SPDIF_SCR, dmaen, dmaen);
616 case SNDRV_PCM_TRIGGER_STOP:
617 case SNDRV_PCM_TRIGGER_SUSPEND:
618 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
619 regmap_update_bits(regmap, REG_SPDIF_SCR, dmaen, 0);
620 regmap_update_bits(regmap, REG_SPDIF_SIE, intr, 0);
621 regmap_write(regmap, REG_SPDIF_STL, 0x0);
622 regmap_write(regmap, REG_SPDIF_STR, 0x0);
631 static const struct snd_soc_dai_ops fsl_spdif_dai_ops = {
632 .startup = fsl_spdif_startup,
633 .hw_params = fsl_spdif_hw_params,
634 .trigger = fsl_spdif_trigger,
635 .shutdown = fsl_spdif_shutdown,
640 * FSL SPDIF IEC958 controller(mixer) functions
642 * Channel status get/put control
643 * User bit value get/put control
644 * Valid bit value get control
645 * DPLL lock status get control
646 * User bit sync mode selection control
649 static int fsl_spdif_info(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_info *uinfo)
652 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
658 static int fsl_spdif_pb_get(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *uvalue)
661 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
662 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
663 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
665 uvalue->value.iec958.status[0] = ctrl->ch_status[0];
666 uvalue->value.iec958.status[1] = ctrl->ch_status[1];
667 uvalue->value.iec958.status[2] = ctrl->ch_status[2];
668 uvalue->value.iec958.status[3] = ctrl->ch_status[3];
673 static int fsl_spdif_pb_put(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_value *uvalue)
676 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
677 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
678 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
680 ctrl->ch_status[0] = uvalue->value.iec958.status[0];
681 ctrl->ch_status[1] = uvalue->value.iec958.status[1];
682 ctrl->ch_status[2] = uvalue->value.iec958.status[2];
683 ctrl->ch_status[3] = uvalue->value.iec958.status[3];
685 spdif_write_channel_status(spdif_priv);
690 /* Get channel status from SPDIF_RX_CCHAN register */
691 static int fsl_spdif_capture_get(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
694 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
695 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
696 struct regmap *regmap = spdif_priv->regmap;
699 regmap_read(regmap, REG_SPDIF_SIS, &val);
700 if (!(val & INT_CNEW))
703 regmap_read(regmap, REG_SPDIF_SRCSH, &cstatus);
704 ucontrol->value.iec958.status[0] = (cstatus >> 16) & 0xFF;
705 ucontrol->value.iec958.status[1] = (cstatus >> 8) & 0xFF;
706 ucontrol->value.iec958.status[2] = cstatus & 0xFF;
708 regmap_read(regmap, REG_SPDIF_SRCSL, &cstatus);
709 ucontrol->value.iec958.status[3] = (cstatus >> 16) & 0xFF;
710 ucontrol->value.iec958.status[4] = (cstatus >> 8) & 0xFF;
711 ucontrol->value.iec958.status[5] = cstatus & 0xFF;
714 regmap_write(regmap, REG_SPDIF_SIC, INT_CNEW);
720 * Get User bits (subcode) from chip value which readed out
721 * in UChannel register.
723 static int fsl_spdif_subcode_get(struct snd_kcontrol *kcontrol,
724 struct snd_ctl_elem_value *ucontrol)
726 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
727 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
728 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
732 spin_lock_irqsave(&ctrl->ctl_lock, flags);
733 if (ctrl->ready_buf) {
734 int idx = (ctrl->ready_buf - 1) * SPDIF_UBITS_SIZE;
735 memcpy(&ucontrol->value.iec958.subcode[0],
736 &ctrl->subcode[idx], SPDIF_UBITS_SIZE);
739 spin_unlock_irqrestore(&ctrl->ctl_lock, flags);
744 /* Q-subcode information. The byte size is SPDIF_UBITS_SIZE/8 */
745 static int fsl_spdif_qinfo(struct snd_kcontrol *kcontrol,
746 struct snd_ctl_elem_info *uinfo)
748 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
749 uinfo->count = SPDIF_QSUB_SIZE;
754 /* Get Q subcode from chip value which readed out in QChannel register */
755 static int fsl_spdif_qget(struct snd_kcontrol *kcontrol,
756 struct snd_ctl_elem_value *ucontrol)
758 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
759 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
760 struct spdif_mixer_control *ctrl = &spdif_priv->fsl_spdif_control;
764 spin_lock_irqsave(&ctrl->ctl_lock, flags);
765 if (ctrl->ready_buf) {
766 int idx = (ctrl->ready_buf - 1) * SPDIF_QSUB_SIZE;
767 memcpy(&ucontrol->value.bytes.data[0],
768 &ctrl->qsub[idx], SPDIF_QSUB_SIZE);
771 spin_unlock_irqrestore(&ctrl->ctl_lock, flags);
776 /* Valid bit information */
777 static int fsl_spdif_vbit_info(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_info *uinfo)
780 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
782 uinfo->value.integer.min = 0;
783 uinfo->value.integer.max = 1;
788 /* Get valid good bit from interrupt status register */
789 static int fsl_spdif_vbit_get(struct snd_kcontrol *kcontrol,
790 struct snd_ctl_elem_value *ucontrol)
792 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
793 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
794 struct regmap *regmap = spdif_priv->regmap;
797 regmap_read(regmap, REG_SPDIF_SIS, &val);
798 ucontrol->value.integer.value[0] = (val & INT_VAL_NOGOOD) != 0;
799 regmap_write(regmap, REG_SPDIF_SIC, INT_VAL_NOGOOD);
804 /* DPLL lock information */
805 static int fsl_spdif_rxrate_info(struct snd_kcontrol *kcontrol,
806 struct snd_ctl_elem_info *uinfo)
808 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
810 uinfo->value.integer.min = 16000;
811 uinfo->value.integer.max = 96000;
816 static u32 gainsel_multi[GAINSEL_MULTI_MAX] = {
817 24, 16, 12, 8, 6, 4, 3,
820 /* Get RX data clock rate given the SPDIF bus_clk */
821 static int spdif_get_rxclk_rate(struct fsl_spdif_priv *spdif_priv,
822 enum spdif_gainsel gainsel)
824 struct regmap *regmap = spdif_priv->regmap;
825 struct platform_device *pdev = spdif_priv->pdev;
826 u64 tmpval64, busclk_freq = 0;
827 u32 freqmeas, phaseconf;
830 regmap_read(regmap, REG_SPDIF_SRFM, &freqmeas);
831 regmap_read(regmap, REG_SPDIF_SRPC, &phaseconf);
833 clksrc = (phaseconf >> SRPC_CLKSRC_SEL_OFFSET) & 0xf;
835 /* Get bus clock from system */
836 if (srpc_dpll_locked[clksrc] && (phaseconf & SRPC_DPLL_LOCKED))
837 busclk_freq = clk_get_rate(spdif_priv->sysclk);
839 /* FreqMeas_CLK = (BUS_CLK * FreqMeas) / 2 ^ 10 / GAINSEL / 128 */
840 tmpval64 = (u64) busclk_freq * freqmeas;
841 do_div(tmpval64, gainsel_multi[gainsel] * 1024);
842 do_div(tmpval64, 128 * 1024);
844 dev_dbg(&pdev->dev, "FreqMeas: %d\n", freqmeas);
845 dev_dbg(&pdev->dev, "BusclkFreq: %lld\n", busclk_freq);
846 dev_dbg(&pdev->dev, "RxRate: %lld\n", tmpval64);
848 return (int)tmpval64;
852 * Get DPLL lock or not info from stable interrupt status register.
853 * User application must use this control to get locked,
854 * then can do next PCM operation
856 static int fsl_spdif_rxrate_get(struct snd_kcontrol *kcontrol,
857 struct snd_ctl_elem_value *ucontrol)
859 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
860 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
863 if (spdif_priv->dpll_locked)
864 rate = spdif_get_rxclk_rate(spdif_priv, SPDIF_DEFAULT_GAINSEL);
866 ucontrol->value.integer.value[0] = rate;
871 /* User bit sync mode info */
872 static int fsl_spdif_usync_info(struct snd_kcontrol *kcontrol,
873 struct snd_ctl_elem_info *uinfo)
875 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
877 uinfo->value.integer.min = 0;
878 uinfo->value.integer.max = 1;
884 * User bit sync mode:
885 * 1 CD User channel subcode
888 static int fsl_spdif_usync_get(struct snd_kcontrol *kcontrol,
889 struct snd_ctl_elem_value *ucontrol)
891 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
892 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
893 struct regmap *regmap = spdif_priv->regmap;
896 regmap_read(regmap, REG_SPDIF_SRCD, &val);
897 ucontrol->value.integer.value[0] = (val & SRCD_CD_USER) != 0;
903 * User bit sync mode:
904 * 1 CD User channel subcode
907 static int fsl_spdif_usync_put(struct snd_kcontrol *kcontrol,
908 struct snd_ctl_elem_value *ucontrol)
910 struct snd_soc_dai *cpu_dai = snd_kcontrol_chip(kcontrol);
911 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(cpu_dai);
912 struct regmap *regmap = spdif_priv->regmap;
913 u32 val = ucontrol->value.integer.value[0] << SRCD_CD_USER_OFFSET;
915 regmap_update_bits(regmap, REG_SPDIF_SRCD, SRCD_CD_USER, val);
920 /* FSL SPDIF IEC958 controller defines */
921 static struct snd_kcontrol_new fsl_spdif_ctrls[] = {
922 /* Status cchanel controller */
924 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
925 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
926 .access = SNDRV_CTL_ELEM_ACCESS_READ |
927 SNDRV_CTL_ELEM_ACCESS_WRITE |
928 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
929 .info = fsl_spdif_info,
930 .get = fsl_spdif_pb_get,
931 .put = fsl_spdif_pb_put,
934 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
935 .name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
936 .access = SNDRV_CTL_ELEM_ACCESS_READ |
937 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
938 .info = fsl_spdif_info,
939 .get = fsl_spdif_capture_get,
941 /* User bits controller */
943 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
944 .name = "IEC958 Subcode Capture Default",
945 .access = SNDRV_CTL_ELEM_ACCESS_READ |
946 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
947 .info = fsl_spdif_info,
948 .get = fsl_spdif_subcode_get,
951 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
952 .name = "IEC958 Q-subcode Capture Default",
953 .access = SNDRV_CTL_ELEM_ACCESS_READ |
954 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
955 .info = fsl_spdif_qinfo,
956 .get = fsl_spdif_qget,
958 /* Valid bit error controller */
960 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
961 .name = "IEC958 V-Bit Errors",
962 .access = SNDRV_CTL_ELEM_ACCESS_READ |
963 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
964 .info = fsl_spdif_vbit_info,
965 .get = fsl_spdif_vbit_get,
967 /* DPLL lock info get controller */
969 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
970 .name = "RX Sample Rate",
971 .access = SNDRV_CTL_ELEM_ACCESS_READ |
972 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
973 .info = fsl_spdif_rxrate_info,
974 .get = fsl_spdif_rxrate_get,
976 /* User bit sync mode set/get controller */
978 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
979 .name = "IEC958 USyncMode CDText",
980 .access = SNDRV_CTL_ELEM_ACCESS_READ |
981 SNDRV_CTL_ELEM_ACCESS_WRITE |
982 SNDRV_CTL_ELEM_ACCESS_VOLATILE,
983 .info = fsl_spdif_usync_info,
984 .get = fsl_spdif_usync_get,
985 .put = fsl_spdif_usync_put,
989 static int fsl_spdif_dai_probe(struct snd_soc_dai *dai)
991 struct fsl_spdif_priv *spdif_private = snd_soc_dai_get_drvdata(dai);
993 snd_soc_dai_init_dma_data(dai, &spdif_private->dma_params_tx,
994 &spdif_private->dma_params_rx);
996 snd_soc_add_dai_controls(dai, fsl_spdif_ctrls, ARRAY_SIZE(fsl_spdif_ctrls));
1001 static struct snd_soc_dai_driver fsl_spdif_dai = {
1002 .probe = &fsl_spdif_dai_probe,
1004 .stream_name = "CPU-Playback",
1007 .rates = FSL_SPDIF_RATES_PLAYBACK,
1008 .formats = FSL_SPDIF_FORMATS_PLAYBACK,
1011 .stream_name = "CPU-Capture",
1014 .rates = FSL_SPDIF_RATES_CAPTURE,
1015 .formats = FSL_SPDIF_FORMATS_CAPTURE,
1017 .ops = &fsl_spdif_dai_ops,
1020 static const struct snd_soc_component_driver fsl_spdif_component = {
1021 .name = "fsl-spdif",
1024 /* FSL SPDIF REGMAP */
1025 static const struct reg_default fsl_spdif_reg_defaults[] = {
1026 {REG_SPDIF_SCR, 0x00000400},
1027 {REG_SPDIF_SRCD, 0x00000000},
1028 {REG_SPDIF_SIE, 0x00000000},
1029 {REG_SPDIF_STL, 0x00000000},
1030 {REG_SPDIF_STR, 0x00000000},
1031 {REG_SPDIF_STCSCH, 0x00000000},
1032 {REG_SPDIF_STCSCL, 0x00000000},
1033 {REG_SPDIF_STC, 0x00020f00},
1036 static bool fsl_spdif_readable_reg(struct device *dev, unsigned int reg)
1040 case REG_SPDIF_SRCD:
1041 case REG_SPDIF_SRPC:
1046 case REG_SPDIF_SRCSH:
1047 case REG_SPDIF_SRCSL:
1050 case REG_SPDIF_STCSCH:
1051 case REG_SPDIF_STCSCL:
1052 case REG_SPDIF_SRFM:
1060 static bool fsl_spdif_volatile_reg(struct device *dev, unsigned int reg)
1063 case REG_SPDIF_SRPC:
1067 case REG_SPDIF_SRCSH:
1068 case REG_SPDIF_SRCSL:
1071 case REG_SPDIF_SRFM:
1078 static bool fsl_spdif_writeable_reg(struct device *dev, unsigned int reg)
1082 case REG_SPDIF_SRCD:
1083 case REG_SPDIF_SRPC:
1088 case REG_SPDIF_STCSCH:
1089 case REG_SPDIF_STCSCL:
1097 static const struct regmap_config fsl_spdif_regmap_config = {
1102 .max_register = REG_SPDIF_STC,
1103 .reg_defaults = fsl_spdif_reg_defaults,
1104 .num_reg_defaults = ARRAY_SIZE(fsl_spdif_reg_defaults),
1105 .readable_reg = fsl_spdif_readable_reg,
1106 .volatile_reg = fsl_spdif_volatile_reg,
1107 .writeable_reg = fsl_spdif_writeable_reg,
1108 .cache_type = REGCACHE_FLAT,
1111 static u32 fsl_spdif_txclk_caldiv(struct fsl_spdif_priv *spdif_priv,
1112 struct clk *clk, u64 savesub,
1113 enum spdif_txrate index, bool round)
1115 const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 };
1116 bool is_sysclk = clk_is_match(clk, spdif_priv->sysclk);
1117 u64 rate_ideal, rate_actual, sub;
1118 u32 sysclk_dfmin, sysclk_dfmax;
1119 u32 txclk_df, sysclk_df, arate;
1121 /* The sysclk has an extra divisor [2, 512] */
1122 sysclk_dfmin = is_sysclk ? 2 : 1;
1123 sysclk_dfmax = is_sysclk ? 512 : 1;
1125 for (sysclk_df = sysclk_dfmin; sysclk_df <= sysclk_dfmax; sysclk_df++) {
1126 for (txclk_df = 1; txclk_df <= 128; txclk_df++) {
1127 rate_ideal = rate[index] * txclk_df * 64;
1129 rate_actual = clk_round_rate(clk, rate_ideal);
1131 rate_actual = clk_get_rate(clk);
1133 arate = rate_actual / 64;
1134 arate /= txclk_df * sysclk_df;
1136 if (arate == rate[index]) {
1139 spdif_priv->txclk_df[index] = txclk_df;
1140 spdif_priv->sysclk_df[index] = sysclk_df;
1141 spdif_priv->txrate[index] = arate;
1143 } else if (arate / rate[index] == 1) {
1144 /* A little bigger than expect */
1145 sub = (u64)(arate - rate[index]) * 100000;
1146 do_div(sub, rate[index]);
1150 spdif_priv->txclk_df[index] = txclk_df;
1151 spdif_priv->sysclk_df[index] = sysclk_df;
1152 spdif_priv->txrate[index] = arate;
1153 } else if (rate[index] / arate == 1) {
1154 /* A little smaller than expect */
1155 sub = (u64)(rate[index] - arate) * 100000;
1156 do_div(sub, rate[index]);
1160 spdif_priv->txclk_df[index] = txclk_df;
1161 spdif_priv->sysclk_df[index] = sysclk_df;
1162 spdif_priv->txrate[index] = arate;
1171 static int fsl_spdif_probe_txclk(struct fsl_spdif_priv *spdif_priv,
1172 enum spdif_txrate index)
1174 const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 };
1175 struct platform_device *pdev = spdif_priv->pdev;
1176 struct device *dev = &pdev->dev;
1177 u64 savesub = 100000, ret;
1182 for (i = 0; i < STC_TXCLK_SRC_MAX; i++) {
1183 sprintf(tmp, "rxtx%d", i);
1184 clk = devm_clk_get(&pdev->dev, tmp);
1186 dev_err(dev, "no rxtx%d clock in devicetree\n", i);
1187 return PTR_ERR(clk);
1189 if (!clk_get_rate(clk))
1192 ret = fsl_spdif_txclk_caldiv(spdif_priv, clk, savesub, index,
1193 i == STC_TXCLK_SPDIF_ROOT);
1198 spdif_priv->txclk[index] = clk;
1199 spdif_priv->txclk_src[index] = i;
1201 /* To quick catch a divisor, we allow a 0.1% deviation */
1206 dev_dbg(&pdev->dev, "use rxtx%d as tx clock source for %dHz sample rate\n",
1207 spdif_priv->txclk_src[index], rate[index]);
1208 dev_dbg(&pdev->dev, "use txclk df %d for %dHz sample rate\n",
1209 spdif_priv->txclk_df[index], rate[index]);
1210 if (clk_is_match(spdif_priv->txclk[index], spdif_priv->sysclk))
1211 dev_dbg(&pdev->dev, "use sysclk df %d for %dHz sample rate\n",
1212 spdif_priv->sysclk_df[index], rate[index]);
1213 dev_dbg(&pdev->dev, "the best rate for %dHz sample rate is %dHz\n",
1214 rate[index], spdif_priv->txrate[index]);
1219 static int fsl_spdif_probe(struct platform_device *pdev)
1221 struct device_node *np = pdev->dev.of_node;
1222 struct fsl_spdif_priv *spdif_priv;
1223 struct spdif_mixer_control *ctrl;
1224 struct resource *res;
1231 spdif_priv = devm_kzalloc(&pdev->dev, sizeof(*spdif_priv), GFP_KERNEL);
1235 spdif_priv->pdev = pdev;
1237 /* Initialize this copy of the CPU DAI driver structure */
1238 memcpy(&spdif_priv->cpu_dai_drv, &fsl_spdif_dai, sizeof(fsl_spdif_dai));
1239 spdif_priv->cpu_dai_drv.name = dev_name(&pdev->dev);
1241 /* Get the addresses and IRQ */
1242 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1243 regs = devm_ioremap_resource(&pdev->dev, res);
1245 return PTR_ERR(regs);
1247 spdif_priv->regmap = devm_regmap_init_mmio_clk(&pdev->dev,
1248 "core", regs, &fsl_spdif_regmap_config);
1249 if (IS_ERR(spdif_priv->regmap)) {
1250 dev_err(&pdev->dev, "regmap init failed\n");
1251 return PTR_ERR(spdif_priv->regmap);
1254 irq = platform_get_irq(pdev, 0);
1256 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
1260 ret = devm_request_irq(&pdev->dev, irq, spdif_isr, 0,
1261 dev_name(&pdev->dev), spdif_priv);
1263 dev_err(&pdev->dev, "could not claim irq %u\n", irq);
1267 /* Get system clock for rx clock rate calculation */
1268 spdif_priv->sysclk = devm_clk_get(&pdev->dev, "rxtx5");
1269 if (IS_ERR(spdif_priv->sysclk)) {
1270 dev_err(&pdev->dev, "no sys clock (rxtx5) in devicetree\n");
1271 return PTR_ERR(spdif_priv->sysclk);
1274 /* Get core clock for data register access via DMA */
1275 spdif_priv->coreclk = devm_clk_get(&pdev->dev, "core");
1276 if (IS_ERR(spdif_priv->coreclk)) {
1277 dev_err(&pdev->dev, "no core clock in devicetree\n");
1278 return PTR_ERR(spdif_priv->coreclk);
1281 spdif_priv->spbaclk = devm_clk_get(&pdev->dev, "spba");
1282 if (IS_ERR(spdif_priv->spbaclk))
1283 dev_warn(&pdev->dev, "no spba clock in devicetree\n");
1285 /* Select clock source for rx/tx clock */
1286 spdif_priv->rxclk = devm_clk_get(&pdev->dev, "rxtx1");
1287 if (IS_ERR(spdif_priv->rxclk)) {
1288 dev_err(&pdev->dev, "no rxtx1 clock in devicetree\n");
1289 return PTR_ERR(spdif_priv->rxclk);
1291 spdif_priv->rxclk_src = DEFAULT_RXCLK_SRC;
1293 for (i = 0; i < SPDIF_TXRATE_MAX; i++) {
1294 ret = fsl_spdif_probe_txclk(spdif_priv, i);
1299 /* Initial spinlock for control data */
1300 ctrl = &spdif_priv->fsl_spdif_control;
1301 spin_lock_init(&ctrl->ctl_lock);
1303 /* Init tx channel status default value */
1304 ctrl->ch_status[0] = IEC958_AES0_CON_NOT_COPYRIGHT |
1305 IEC958_AES0_CON_EMPHASIS_5015;
1306 ctrl->ch_status[1] = IEC958_AES1_CON_DIGDIGCONV_ID;
1307 ctrl->ch_status[2] = 0x00;
1308 ctrl->ch_status[3] = IEC958_AES3_CON_FS_44100 |
1309 IEC958_AES3_CON_CLOCK_1000PPM;
1311 spdif_priv->dpll_locked = false;
1313 spdif_priv->dma_params_tx.maxburst = FSL_SPDIF_TXFIFO_WML;
1314 spdif_priv->dma_params_rx.maxburst = FSL_SPDIF_RXFIFO_WML;
1315 spdif_priv->dma_params_tx.addr = res->start + REG_SPDIF_STL;
1316 spdif_priv->dma_params_rx.addr = res->start + REG_SPDIF_SRL;
1318 /* Register with ASoC */
1319 dev_set_drvdata(&pdev->dev, spdif_priv);
1321 ret = devm_snd_soc_register_component(&pdev->dev, &fsl_spdif_component,
1322 &spdif_priv->cpu_dai_drv, 1);
1324 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
1328 ret = imx_pcm_dma_init(pdev, IMX_SPDIF_DMABUF_SIZE);
1330 dev_err(&pdev->dev, "imx_pcm_dma_init failed: %d\n", ret);
1335 #ifdef CONFIG_PM_SLEEP
1336 static int fsl_spdif_suspend(struct device *dev)
1338 struct fsl_spdif_priv *spdif_priv = dev_get_drvdata(dev);
1340 regmap_read(spdif_priv->regmap, REG_SPDIF_SRPC,
1341 &spdif_priv->regcache_srpc);
1343 regcache_cache_only(spdif_priv->regmap, true);
1344 regcache_mark_dirty(spdif_priv->regmap);
1349 static int fsl_spdif_resume(struct device *dev)
1351 struct fsl_spdif_priv *spdif_priv = dev_get_drvdata(dev);
1353 regcache_cache_only(spdif_priv->regmap, false);
1355 regmap_update_bits(spdif_priv->regmap, REG_SPDIF_SRPC,
1356 SRPC_CLKSRC_SEL_MASK | SRPC_GAINSEL_MASK,
1357 spdif_priv->regcache_srpc);
1359 return regcache_sync(spdif_priv->regmap);
1361 #endif /* CONFIG_PM_SLEEP */
1363 static const struct dev_pm_ops fsl_spdif_pm = {
1364 SET_SYSTEM_SLEEP_PM_OPS(fsl_spdif_suspend, fsl_spdif_resume)
1367 static const struct of_device_id fsl_spdif_dt_ids[] = {
1368 { .compatible = "fsl,imx35-spdif", },
1369 { .compatible = "fsl,vf610-spdif", },
1372 MODULE_DEVICE_TABLE(of, fsl_spdif_dt_ids);
1374 static struct platform_driver fsl_spdif_driver = {
1376 .name = "fsl-spdif-dai",
1377 .of_match_table = fsl_spdif_dt_ids,
1378 .pm = &fsl_spdif_pm,
1380 .probe = fsl_spdif_probe,
1383 module_platform_driver(fsl_spdif_driver);
1385 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
1386 MODULE_DESCRIPTION("Freescale S/PDIF CPU DAI Driver");
1387 MODULE_LICENSE("GPL v2");
1388 MODULE_ALIAS("platform:fsl-spdif-dai");