2 * Copyright 2011 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <linux/module.h>
20 #include <linux/init.h>
22 #include <linux/of_device.h>
23 #include <linux/platform_device.h>
24 #include <linux/slab.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/clk.h>
27 #include <linux/clk-provider.h>
28 #include <linux/delay.h>
29 #include <linux/time.h>
30 #include <sound/core.h>
31 #include <sound/pcm.h>
32 #include <sound/pcm_params.h>
33 #include <sound/soc.h>
37 #define MXS_SET_ADDR 0x4
38 #define MXS_CLR_ADDR 0x8
40 static struct mxs_saif
*mxs_saif
[2];
43 * SAIF is a little different with other normal SOC DAIs on clock using.
45 * For MXS, two SAIF modules are instantiated on-chip.
46 * Each SAIF has a set of clock pins and can be operating in master
47 * mode simultaneously if they are connected to different off-chip codecs.
48 * Also, one of the two SAIFs can master or drive the clock pins while the
49 * other SAIF, in slave mode, receives clocking from the master SAIF.
50 * This also means that both SAIFs must operate at the same sample rate.
52 * We abstract this as each saif has a master, the master could be
53 * itself or other saifs. In the generic saif driver, saif does not need
54 * to know the different clkmux. Saif only needs to know who is its master
55 * and operating its master to generate the proper clock rate for it.
56 * The master id is provided in mach-specific layer according to different
60 static int mxs_saif_set_dai_sysclk(struct snd_soc_dai
*cpu_dai
,
61 int clk_id
, unsigned int freq
, int dir
)
63 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
76 * Since SAIF may work on EXTMASTER mode, IOW, it's working BITCLK&LRCLK
77 * is provided by other SAIF, we provide a interface here to get its master
79 * Note that the master could be itself.
81 static inline struct mxs_saif
*mxs_saif_get_master(struct mxs_saif
* saif
)
83 return mxs_saif
[saif
->master_id
];
87 * Set SAIF clock and MCLK
89 static int mxs_saif_set_clk(struct mxs_saif
*saif
,
95 struct mxs_saif
*master_saif
;
97 dev_dbg(saif
->dev
, "mclk %d rate %d\n", mclk
, rate
);
99 /* Set master saif to generate proper clock */
100 master_saif
= mxs_saif_get_master(saif
);
104 dev_dbg(saif
->dev
, "master saif%d\n", master_saif
->id
);
106 /* Checking if can playback and capture simutaneously */
107 if (master_saif
->ongoing
&& rate
!= master_saif
->cur_rate
) {
109 "can not change clock, master saif%d(rate %d) is ongoing\n",
110 master_saif
->id
, master_saif
->cur_rate
);
114 scr
= __raw_readl(master_saif
->base
+ SAIF_CTRL
);
115 scr
&= ~BM_SAIF_CTRL_BITCLK_MULT_RATE
;
116 scr
&= ~BM_SAIF_CTRL_BITCLK_BASE_RATE
;
121 * The SAIF clock should be either 384*fs or 512*fs.
122 * If MCLK is used, the SAIF clk ratio need to match mclk ratio.
123 * For 32x mclk, set saif clk as 512*fs.
124 * For 48x mclk, set saif clk as 384*fs.
126 * If MCLK is not used, we just set saif clk to 512*fs.
128 clk_prepare_enable(master_saif
->clk
);
130 if (master_saif
->mclk_in_use
) {
131 if (mclk
% 32 == 0) {
132 scr
&= ~BM_SAIF_CTRL_BITCLK_BASE_RATE
;
133 ret
= clk_set_rate(master_saif
->clk
, 512 * rate
);
134 } else if (mclk
% 48 == 0) {
135 scr
|= BM_SAIF_CTRL_BITCLK_BASE_RATE
;
136 ret
= clk_set_rate(master_saif
->clk
, 384 * rate
);
138 /* SAIF MCLK should be either 32x or 48x */
139 clk_disable_unprepare(master_saif
->clk
);
143 ret
= clk_set_rate(master_saif
->clk
, 512 * rate
);
144 scr
&= ~BM_SAIF_CTRL_BITCLK_BASE_RATE
;
147 clk_disable_unprepare(master_saif
->clk
);
152 master_saif
->cur_rate
= rate
;
154 if (!master_saif
->mclk_in_use
) {
155 __raw_writel(scr
, master_saif
->base
+ SAIF_CTRL
);
160 * Program the over-sample rate for MCLK output
162 * The available MCLK range is 32x, 48x... 512x. The rate
163 * could be from 8kHz to 192kH.
165 switch (mclk
/ rate
) {
167 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(4);
170 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(3);
173 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(2);
176 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(1);
179 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(0);
182 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(3);
185 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(2);
188 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(1);
191 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(0);
197 __raw_writel(scr
, master_saif
->base
+ SAIF_CTRL
);
203 * Put and disable MCLK.
205 int mxs_saif_put_mclk(unsigned int saif_id
)
207 struct mxs_saif
*saif
= mxs_saif
[saif_id
];
213 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
214 if (stat
& BM_SAIF_STAT_BUSY
) {
215 dev_err(saif
->dev
, "error: busy\n");
219 clk_disable_unprepare(saif
->clk
);
221 /* disable MCLK output */
222 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
223 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
224 __raw_writel(BM_SAIF_CTRL_RUN
,
225 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
227 saif
->mclk_in_use
= 0;
230 EXPORT_SYMBOL_GPL(mxs_saif_put_mclk
);
233 * Get MCLK and set clock rate, then enable it
235 * This interface is used for codecs who are using MCLK provided
238 int mxs_saif_get_mclk(unsigned int saif_id
, unsigned int mclk
,
241 struct mxs_saif
*saif
= mxs_saif
[saif_id
];
244 struct mxs_saif
*master_saif
;
250 __raw_writel(BM_SAIF_CTRL_SFTRST
,
251 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
253 /* FIXME: need clear clk gate for register r/w */
254 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
255 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
257 master_saif
= mxs_saif_get_master(saif
);
258 if (saif
!= master_saif
) {
259 dev_err(saif
->dev
, "can not get mclk from a non-master saif\n");
263 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
264 if (stat
& BM_SAIF_STAT_BUSY
) {
265 dev_err(saif
->dev
, "error: busy\n");
269 saif
->mclk_in_use
= 1;
270 ret
= mxs_saif_set_clk(saif
, mclk
, rate
);
274 ret
= clk_prepare_enable(saif
->clk
);
278 /* enable MCLK output */
279 __raw_writel(BM_SAIF_CTRL_RUN
,
280 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
284 EXPORT_SYMBOL_GPL(mxs_saif_get_mclk
);
287 * SAIF DAI format configuration.
288 * Should only be called when port is inactive.
290 static int mxs_saif_set_dai_fmt(struct snd_soc_dai
*cpu_dai
, unsigned int fmt
)
294 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
296 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
297 if (stat
& BM_SAIF_STAT_BUSY
) {
298 dev_err(cpu_dai
->dev
, "error: busy\n");
302 scr0
= __raw_readl(saif
->base
+ SAIF_CTRL
);
303 scr0
= scr0
& ~BM_SAIF_CTRL_BITCLK_EDGE
& ~BM_SAIF_CTRL_LRCLK_POLARITY \
304 & ~BM_SAIF_CTRL_JUSTIFY
& ~BM_SAIF_CTRL_DELAY
;
308 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
309 case SND_SOC_DAIFMT_I2S
:
310 /* data frame low 1clk before data */
311 scr
|= BM_SAIF_CTRL_DELAY
;
312 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
314 case SND_SOC_DAIFMT_LEFT_J
:
315 /* data frame high with data */
316 scr
&= ~BM_SAIF_CTRL_DELAY
;
317 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
318 scr
&= ~BM_SAIF_CTRL_JUSTIFY
;
324 /* DAI clock inversion */
325 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
326 case SND_SOC_DAIFMT_IB_IF
:
327 scr
|= BM_SAIF_CTRL_BITCLK_EDGE
;
328 scr
|= BM_SAIF_CTRL_LRCLK_POLARITY
;
330 case SND_SOC_DAIFMT_IB_NF
:
331 scr
|= BM_SAIF_CTRL_BITCLK_EDGE
;
332 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
334 case SND_SOC_DAIFMT_NB_IF
:
335 scr
&= ~BM_SAIF_CTRL_BITCLK_EDGE
;
336 scr
|= BM_SAIF_CTRL_LRCLK_POLARITY
;
338 case SND_SOC_DAIFMT_NB_NF
:
339 scr
&= ~BM_SAIF_CTRL_BITCLK_EDGE
;
340 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
345 * Note: We simply just support master mode since SAIF TX can only
347 * Here the master is relative to codec side.
348 * Saif internally could be slave when working on EXTMASTER mode.
349 * We just hide this to machine driver.
351 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
352 case SND_SOC_DAIFMT_CBS_CFS
:
353 if (saif
->id
== saif
->master_id
)
354 scr
&= ~BM_SAIF_CTRL_SLAVE_MODE
;
356 scr
|= BM_SAIF_CTRL_SLAVE_MODE
;
358 __raw_writel(scr
| scr0
, saif
->base
+ SAIF_CTRL
);
367 static int mxs_saif_startup(struct snd_pcm_substream
*substream
,
368 struct snd_soc_dai
*cpu_dai
)
370 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
372 /* clear error status to 0 for each re-open */
373 saif
->fifo_underrun
= 0;
374 saif
->fifo_overrun
= 0;
376 /* Clear Reset for normal operations */
377 __raw_writel(BM_SAIF_CTRL_SFTRST
,
378 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
380 /* clear clock gate */
381 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
382 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
384 clk_prepare(saif
->clk
);
389 static void mxs_saif_shutdown(struct snd_pcm_substream
*substream
,
390 struct snd_soc_dai
*cpu_dai
)
392 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
394 clk_unprepare(saif
->clk
);
398 * Should only be called when port is inactive.
399 * although can be called multiple times by upper layers.
401 static int mxs_saif_hw_params(struct snd_pcm_substream
*substream
,
402 struct snd_pcm_hw_params
*params
,
403 struct snd_soc_dai
*cpu_dai
)
405 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
406 struct mxs_saif
*master_saif
;
410 master_saif
= mxs_saif_get_master(saif
);
414 /* mclk should already be set */
415 if (!saif
->mclk
&& saif
->mclk_in_use
) {
416 dev_err(cpu_dai
->dev
, "set mclk first\n");
420 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
421 if (!saif
->mclk_in_use
&& (stat
& BM_SAIF_STAT_BUSY
)) {
422 dev_err(cpu_dai
->dev
, "error: busy\n");
427 * Set saif clk based on sample rate.
428 * If mclk is used, we also set mclk, if not, saif->mclk is
429 * default 0, means not used.
431 ret
= mxs_saif_set_clk(saif
, saif
->mclk
, params_rate(params
));
433 dev_err(cpu_dai
->dev
, "unable to get proper clk\n");
437 if (saif
!= master_saif
) {
439 * Set an initial clock rate for the saif internal logic to work
440 * properly. This is important when working in EXTMASTER mode
441 * that uses the other saif's BITCLK&LRCLK but it still needs a
442 * basic clock which should be fast enough for the internal
445 clk_enable(saif
->clk
);
446 ret
= clk_set_rate(saif
->clk
, 24000000);
447 clk_disable(saif
->clk
);
451 clk_prepare(master_saif
->clk
);
454 scr
= __raw_readl(saif
->base
+ SAIF_CTRL
);
456 scr
&= ~BM_SAIF_CTRL_WORD_LENGTH
;
457 scr
&= ~BM_SAIF_CTRL_BITCLK_48XFS_ENABLE
;
458 switch (params_format(params
)) {
459 case SNDRV_PCM_FORMAT_S16_LE
:
460 scr
|= BF_SAIF_CTRL_WORD_LENGTH(0);
462 case SNDRV_PCM_FORMAT_S20_3LE
:
463 scr
|= BF_SAIF_CTRL_WORD_LENGTH(4);
464 scr
|= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE
;
466 case SNDRV_PCM_FORMAT_S24_LE
:
467 scr
|= BF_SAIF_CTRL_WORD_LENGTH(8);
468 scr
|= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE
;
475 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
477 scr
&= ~BM_SAIF_CTRL_READ_MODE
;
480 scr
|= BM_SAIF_CTRL_READ_MODE
;
483 __raw_writel(scr
, saif
->base
+ SAIF_CTRL
);
487 static int mxs_saif_prepare(struct snd_pcm_substream
*substream
,
488 struct snd_soc_dai
*cpu_dai
)
490 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
492 /* enable FIFO error irqs */
493 __raw_writel(BM_SAIF_CTRL_FIFO_ERROR_IRQ_EN
,
494 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
499 static int mxs_saif_trigger(struct snd_pcm_substream
*substream
, int cmd
,
500 struct snd_soc_dai
*cpu_dai
)
502 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
503 struct mxs_saif
*master_saif
;
507 master_saif
= mxs_saif_get_master(saif
);
512 case SNDRV_PCM_TRIGGER_START
:
513 case SNDRV_PCM_TRIGGER_RESUME
:
514 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
515 if (saif
->state
== MXS_SAIF_STATE_RUNNING
)
518 dev_dbg(cpu_dai
->dev
, "start\n");
520 ret
= clk_enable(master_saif
->clk
);
522 dev_err(saif
->dev
, "Failed to enable master clock\n");
527 * If the saif's master is not itself, we also need to enable
528 * itself clk for its internal basic logic to work.
530 if (saif
!= master_saif
) {
531 ret
= clk_enable(saif
->clk
);
533 dev_err(saif
->dev
, "Failed to enable master clock\n");
534 clk_disable(master_saif
->clk
);
538 __raw_writel(BM_SAIF_CTRL_RUN
,
539 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
542 if (!master_saif
->mclk_in_use
)
543 __raw_writel(BM_SAIF_CTRL_RUN
,
544 master_saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
546 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
548 * write data to saif data register to trigger
550 * For 24-bit format the 32-bit FIFO register stores
551 * only one channel, so we need to write twice.
552 * This is also safe for the other non 24-bit formats.
554 __raw_writel(0, saif
->base
+ SAIF_DATA
);
555 __raw_writel(0, saif
->base
+ SAIF_DATA
);
558 * read data from saif data register to trigger
560 * For 24-bit format the 32-bit FIFO register stores
561 * only one channel, so we need to read twice.
562 * This is also safe for the other non 24-bit formats.
564 __raw_readl(saif
->base
+ SAIF_DATA
);
565 __raw_readl(saif
->base
+ SAIF_DATA
);
568 master_saif
->ongoing
= 1;
569 saif
->state
= MXS_SAIF_STATE_RUNNING
;
571 dev_dbg(saif
->dev
, "CTRL 0x%x STAT 0x%x\n",
572 __raw_readl(saif
->base
+ SAIF_CTRL
),
573 __raw_readl(saif
->base
+ SAIF_STAT
));
575 dev_dbg(master_saif
->dev
, "CTRL 0x%x STAT 0x%x\n",
576 __raw_readl(master_saif
->base
+ SAIF_CTRL
),
577 __raw_readl(master_saif
->base
+ SAIF_STAT
));
579 case SNDRV_PCM_TRIGGER_SUSPEND
:
580 case SNDRV_PCM_TRIGGER_STOP
:
581 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
582 if (saif
->state
== MXS_SAIF_STATE_STOPPED
)
585 dev_dbg(cpu_dai
->dev
, "stop\n");
587 /* wait a while for the current sample to complete */
588 delay
= USEC_PER_SEC
/ master_saif
->cur_rate
;
590 if (!master_saif
->mclk_in_use
) {
591 __raw_writel(BM_SAIF_CTRL_RUN
,
592 master_saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
595 clk_disable(master_saif
->clk
);
597 if (saif
!= master_saif
) {
598 __raw_writel(BM_SAIF_CTRL_RUN
,
599 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
601 clk_disable(saif
->clk
);
604 master_saif
->ongoing
= 0;
605 saif
->state
= MXS_SAIF_STATE_STOPPED
;
615 #define MXS_SAIF_RATES SNDRV_PCM_RATE_8000_192000
616 #define MXS_SAIF_FORMATS \
617 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
618 SNDRV_PCM_FMTBIT_S24_LE)
620 static const struct snd_soc_dai_ops mxs_saif_dai_ops
= {
621 .startup
= mxs_saif_startup
,
622 .shutdown
= mxs_saif_shutdown
,
623 .trigger
= mxs_saif_trigger
,
624 .prepare
= mxs_saif_prepare
,
625 .hw_params
= mxs_saif_hw_params
,
626 .set_sysclk
= mxs_saif_set_dai_sysclk
,
627 .set_fmt
= mxs_saif_set_dai_fmt
,
630 static int mxs_saif_dai_probe(struct snd_soc_dai
*dai
)
632 struct mxs_saif
*saif
= dev_get_drvdata(dai
->dev
);
634 snd_soc_dai_set_drvdata(dai
, saif
);
639 static struct snd_soc_dai_driver mxs_saif_dai
= {
641 .probe
= mxs_saif_dai_probe
,
645 .rates
= MXS_SAIF_RATES
,
646 .formats
= MXS_SAIF_FORMATS
,
651 .rates
= MXS_SAIF_RATES
,
652 .formats
= MXS_SAIF_FORMATS
,
654 .ops
= &mxs_saif_dai_ops
,
657 static const struct snd_soc_component_driver mxs_saif_component
= {
661 static irqreturn_t
mxs_saif_irq(int irq
, void *dev_id
)
663 struct mxs_saif
*saif
= dev_id
;
666 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
667 if (!(stat
& (BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ
|
668 BM_SAIF_STAT_FIFO_OVERFLOW_IRQ
)))
671 if (stat
& BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ
) {
672 dev_dbg(saif
->dev
, "underrun!!! %d\n", ++saif
->fifo_underrun
);
673 __raw_writel(BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ
,
674 saif
->base
+ SAIF_STAT
+ MXS_CLR_ADDR
);
677 if (stat
& BM_SAIF_STAT_FIFO_OVERFLOW_IRQ
) {
678 dev_dbg(saif
->dev
, "overrun!!! %d\n", ++saif
->fifo_overrun
);
679 __raw_writel(BM_SAIF_STAT_FIFO_OVERFLOW_IRQ
,
680 saif
->base
+ SAIF_STAT
+ MXS_CLR_ADDR
);
683 dev_dbg(saif
->dev
, "SAIF_CTRL %x SAIF_STAT %x\n",
684 __raw_readl(saif
->base
+ SAIF_CTRL
),
685 __raw_readl(saif
->base
+ SAIF_STAT
));
690 static int mxs_saif_mclk_init(struct platform_device
*pdev
)
692 struct mxs_saif
*saif
= platform_get_drvdata(pdev
);
693 struct device_node
*np
= pdev
->dev
.of_node
;
697 clk
= clk_register_divider(&pdev
->dev
, "mxs_saif_mclk",
698 __clk_get_name(saif
->clk
), 0,
699 saif
->base
+ SAIF_CTRL
,
700 BP_SAIF_CTRL_BITCLK_MULT_RATE
, 3,
706 dev_err(&pdev
->dev
, "failed to register mclk: %d\n", ret
);
710 ret
= of_clk_add_provider(np
, of_clk_src_simple_get
, clk
);
717 static int mxs_saif_probe(struct platform_device
*pdev
)
719 struct device_node
*np
= pdev
->dev
.of_node
;
720 struct resource
*iores
;
721 struct mxs_saif
*saif
;
723 struct device_node
*master
;
728 saif
= devm_kzalloc(&pdev
->dev
, sizeof(*saif
), GFP_KERNEL
);
732 ret
= of_alias_get_id(np
, "saif");
738 if (saif
->id
>= ARRAY_SIZE(mxs_saif
)) {
739 dev_err(&pdev
->dev
, "get wrong saif id\n");
744 * If there is no "fsl,saif-master" phandle, it's a saif
745 * master. Otherwise, it's a slave and its phandle points
748 master
= of_parse_phandle(np
, "fsl,saif-master", 0);
750 saif
->master_id
= saif
->id
;
752 ret
= of_alias_get_id(master
, "saif");
756 saif
->master_id
= ret
;
758 if (saif
->master_id
>= ARRAY_SIZE(mxs_saif
)) {
759 dev_err(&pdev
->dev
, "get wrong master id\n");
764 mxs_saif
[saif
->id
] = saif
;
766 saif
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
767 if (IS_ERR(saif
->clk
)) {
768 ret
= PTR_ERR(saif
->clk
);
769 dev_err(&pdev
->dev
, "Cannot get the clock: %d\n",
774 iores
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
776 saif
->base
= devm_ioremap_resource(&pdev
->dev
, iores
);
777 if (IS_ERR(saif
->base
))
778 return PTR_ERR(saif
->base
);
780 irq
= platform_get_irq(pdev
, 0);
783 dev_err(&pdev
->dev
, "failed to get irq resource: %d\n",
788 saif
->dev
= &pdev
->dev
;
789 ret
= devm_request_irq(&pdev
->dev
, irq
, mxs_saif_irq
, 0,
790 dev_name(&pdev
->dev
), saif
);
792 dev_err(&pdev
->dev
, "failed to request irq\n");
796 platform_set_drvdata(pdev
, saif
);
798 /* We only support saif0 being tx and clock master */
800 ret
= mxs_saif_mclk_init(pdev
);
802 dev_warn(&pdev
->dev
, "failed to init clocks\n");
805 ret
= devm_snd_soc_register_component(&pdev
->dev
, &mxs_saif_component
,
808 dev_err(&pdev
->dev
, "register DAI failed\n");
812 ret
= mxs_pcm_platform_register(&pdev
->dev
);
814 dev_err(&pdev
->dev
, "register PCM failed: %d\n", ret
);
821 static const struct of_device_id mxs_saif_dt_ids
[] = {
822 { .compatible
= "fsl,imx28-saif", },
825 MODULE_DEVICE_TABLE(of
, mxs_saif_dt_ids
);
827 static struct platform_driver mxs_saif_driver
= {
828 .probe
= mxs_saif_probe
,
832 .of_match_table
= mxs_saif_dt_ids
,
836 module_platform_driver(mxs_saif_driver
);
838 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
839 MODULE_DESCRIPTION("MXS ASoC SAIF driver");
840 MODULE_LICENSE("GPL");
841 MODULE_ALIAS("platform:mxs-saif");