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 needs to match mclk ratio.
123 * For 256x, 128x, 64x, and 32x sub-rates, set saif clk as 512*fs.
124 * For 192x, 96x, and 48x sub-rates, 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 switch (mclk
/ rate
) {
137 scr
&= ~BM_SAIF_CTRL_BITCLK_BASE_RATE
;
138 ret
= clk_set_rate(master_saif
->clk
, 512 * rate
);
144 scr
|= BM_SAIF_CTRL_BITCLK_BASE_RATE
;
145 ret
= clk_set_rate(master_saif
->clk
, 384 * rate
);
148 /* SAIF MCLK should be a sub-rate of 512x or 384x */
149 clk_disable_unprepare(master_saif
->clk
);
153 ret
= clk_set_rate(master_saif
->clk
, 512 * rate
);
154 scr
&= ~BM_SAIF_CTRL_BITCLK_BASE_RATE
;
157 clk_disable_unprepare(master_saif
->clk
);
162 master_saif
->cur_rate
= rate
;
164 if (!master_saif
->mclk_in_use
) {
165 __raw_writel(scr
, master_saif
->base
+ SAIF_CTRL
);
170 * Program the over-sample rate for MCLK output
172 * The available MCLK range is 32x, 48x... 512x. The rate
173 * could be from 8kHz to 192kH.
175 switch (mclk
/ rate
) {
177 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(4);
180 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(3);
183 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(2);
186 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(1);
189 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(0);
192 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(3);
195 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(2);
198 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(1);
201 scr
|= BF_SAIF_CTRL_BITCLK_MULT_RATE(0);
207 __raw_writel(scr
, master_saif
->base
+ SAIF_CTRL
);
213 * Put and disable MCLK.
215 int mxs_saif_put_mclk(unsigned int saif_id
)
217 struct mxs_saif
*saif
= mxs_saif
[saif_id
];
223 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
224 if (stat
& BM_SAIF_STAT_BUSY
) {
225 dev_err(saif
->dev
, "error: busy\n");
229 clk_disable_unprepare(saif
->clk
);
231 /* disable MCLK output */
232 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
233 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
234 __raw_writel(BM_SAIF_CTRL_RUN
,
235 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
237 saif
->mclk_in_use
= 0;
240 EXPORT_SYMBOL_GPL(mxs_saif_put_mclk
);
243 * Get MCLK and set clock rate, then enable it
245 * This interface is used for codecs who are using MCLK provided
248 int mxs_saif_get_mclk(unsigned int saif_id
, unsigned int mclk
,
251 struct mxs_saif
*saif
= mxs_saif
[saif_id
];
254 struct mxs_saif
*master_saif
;
260 __raw_writel(BM_SAIF_CTRL_SFTRST
,
261 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
263 /* FIXME: need clear clk gate for register r/w */
264 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
265 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
267 master_saif
= mxs_saif_get_master(saif
);
268 if (saif
!= master_saif
) {
269 dev_err(saif
->dev
, "can not get mclk from a non-master saif\n");
273 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
274 if (stat
& BM_SAIF_STAT_BUSY
) {
275 dev_err(saif
->dev
, "error: busy\n");
279 saif
->mclk_in_use
= 1;
280 ret
= mxs_saif_set_clk(saif
, mclk
, rate
);
284 ret
= clk_prepare_enable(saif
->clk
);
288 /* enable MCLK output */
289 __raw_writel(BM_SAIF_CTRL_RUN
,
290 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
294 EXPORT_SYMBOL_GPL(mxs_saif_get_mclk
);
297 * SAIF DAI format configuration.
298 * Should only be called when port is inactive.
300 static int mxs_saif_set_dai_fmt(struct snd_soc_dai
*cpu_dai
, unsigned int fmt
)
304 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
306 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
307 if (stat
& BM_SAIF_STAT_BUSY
) {
308 dev_err(cpu_dai
->dev
, "error: busy\n");
312 /* If SAIF1 is configured as slave, the clk gate needs to be cleared
313 * before the register can be written.
315 if (saif
->id
!= saif
->master_id
) {
316 __raw_writel(BM_SAIF_CTRL_SFTRST
,
317 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
318 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
319 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
322 scr0
= __raw_readl(saif
->base
+ SAIF_CTRL
);
323 scr0
= scr0
& ~BM_SAIF_CTRL_BITCLK_EDGE
& ~BM_SAIF_CTRL_LRCLK_POLARITY \
324 & ~BM_SAIF_CTRL_JUSTIFY
& ~BM_SAIF_CTRL_DELAY
;
328 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
329 case SND_SOC_DAIFMT_I2S
:
330 /* data frame low 1clk before data */
331 scr
|= BM_SAIF_CTRL_DELAY
;
332 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
334 case SND_SOC_DAIFMT_LEFT_J
:
335 /* data frame high with data */
336 scr
&= ~BM_SAIF_CTRL_DELAY
;
337 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
338 scr
&= ~BM_SAIF_CTRL_JUSTIFY
;
344 /* DAI clock inversion */
345 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
346 case SND_SOC_DAIFMT_IB_IF
:
347 scr
|= BM_SAIF_CTRL_BITCLK_EDGE
;
348 scr
|= BM_SAIF_CTRL_LRCLK_POLARITY
;
350 case SND_SOC_DAIFMT_IB_NF
:
351 scr
|= BM_SAIF_CTRL_BITCLK_EDGE
;
352 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
354 case SND_SOC_DAIFMT_NB_IF
:
355 scr
&= ~BM_SAIF_CTRL_BITCLK_EDGE
;
356 scr
|= BM_SAIF_CTRL_LRCLK_POLARITY
;
358 case SND_SOC_DAIFMT_NB_NF
:
359 scr
&= ~BM_SAIF_CTRL_BITCLK_EDGE
;
360 scr
&= ~BM_SAIF_CTRL_LRCLK_POLARITY
;
365 * Note: We simply just support master mode since SAIF TX can only
367 * Here the master is relative to codec side.
368 * Saif internally could be slave when working on EXTMASTER mode.
369 * We just hide this to machine driver.
371 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
372 case SND_SOC_DAIFMT_CBS_CFS
:
373 if (saif
->id
== saif
->master_id
)
374 scr
&= ~BM_SAIF_CTRL_SLAVE_MODE
;
376 scr
|= BM_SAIF_CTRL_SLAVE_MODE
;
378 __raw_writel(scr
| scr0
, saif
->base
+ SAIF_CTRL
);
387 static int mxs_saif_startup(struct snd_pcm_substream
*substream
,
388 struct snd_soc_dai
*cpu_dai
)
390 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
392 /* clear error status to 0 for each re-open */
393 saif
->fifo_underrun
= 0;
394 saif
->fifo_overrun
= 0;
396 /* Clear Reset for normal operations */
397 __raw_writel(BM_SAIF_CTRL_SFTRST
,
398 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
400 /* clear clock gate */
401 __raw_writel(BM_SAIF_CTRL_CLKGATE
,
402 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
404 clk_prepare(saif
->clk
);
409 static void mxs_saif_shutdown(struct snd_pcm_substream
*substream
,
410 struct snd_soc_dai
*cpu_dai
)
412 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
414 clk_unprepare(saif
->clk
);
418 * Should only be called when port is inactive.
419 * although can be called multiple times by upper layers.
421 static int mxs_saif_hw_params(struct snd_pcm_substream
*substream
,
422 struct snd_pcm_hw_params
*params
,
423 struct snd_soc_dai
*cpu_dai
)
425 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
426 struct mxs_saif
*master_saif
;
430 master_saif
= mxs_saif_get_master(saif
);
434 /* mclk should already be set */
435 if (!saif
->mclk
&& saif
->mclk_in_use
) {
436 dev_err(cpu_dai
->dev
, "set mclk first\n");
440 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
441 if (!saif
->mclk_in_use
&& (stat
& BM_SAIF_STAT_BUSY
)) {
442 dev_err(cpu_dai
->dev
, "error: busy\n");
447 * Set saif clk based on sample rate.
448 * If mclk is used, we also set mclk, if not, saif->mclk is
449 * default 0, means not used.
451 ret
= mxs_saif_set_clk(saif
, saif
->mclk
, params_rate(params
));
453 dev_err(cpu_dai
->dev
, "unable to get proper clk\n");
457 if (saif
!= master_saif
) {
459 * Set an initial clock rate for the saif internal logic to work
460 * properly. This is important when working in EXTMASTER mode
461 * that uses the other saif's BITCLK&LRCLK but it still needs a
462 * basic clock which should be fast enough for the internal
465 clk_enable(saif
->clk
);
466 ret
= clk_set_rate(saif
->clk
, 24000000);
467 clk_disable(saif
->clk
);
471 clk_prepare(master_saif
->clk
);
474 scr
= __raw_readl(saif
->base
+ SAIF_CTRL
);
476 scr
&= ~BM_SAIF_CTRL_WORD_LENGTH
;
477 scr
&= ~BM_SAIF_CTRL_BITCLK_48XFS_ENABLE
;
478 switch (params_format(params
)) {
479 case SNDRV_PCM_FORMAT_S16_LE
:
480 scr
|= BF_SAIF_CTRL_WORD_LENGTH(0);
482 case SNDRV_PCM_FORMAT_S20_3LE
:
483 scr
|= BF_SAIF_CTRL_WORD_LENGTH(4);
484 scr
|= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE
;
486 case SNDRV_PCM_FORMAT_S24_LE
:
487 scr
|= BF_SAIF_CTRL_WORD_LENGTH(8);
488 scr
|= BM_SAIF_CTRL_BITCLK_48XFS_ENABLE
;
495 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
497 scr
&= ~BM_SAIF_CTRL_READ_MODE
;
500 scr
|= BM_SAIF_CTRL_READ_MODE
;
503 __raw_writel(scr
, saif
->base
+ SAIF_CTRL
);
507 static int mxs_saif_prepare(struct snd_pcm_substream
*substream
,
508 struct snd_soc_dai
*cpu_dai
)
510 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
512 /* enable FIFO error irqs */
513 __raw_writel(BM_SAIF_CTRL_FIFO_ERROR_IRQ_EN
,
514 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
519 static int mxs_saif_trigger(struct snd_pcm_substream
*substream
, int cmd
,
520 struct snd_soc_dai
*cpu_dai
)
522 struct mxs_saif
*saif
= snd_soc_dai_get_drvdata(cpu_dai
);
523 struct mxs_saif
*master_saif
;
527 master_saif
= mxs_saif_get_master(saif
);
532 case SNDRV_PCM_TRIGGER_START
:
533 case SNDRV_PCM_TRIGGER_RESUME
:
534 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
535 if (saif
->state
== MXS_SAIF_STATE_RUNNING
)
538 dev_dbg(cpu_dai
->dev
, "start\n");
540 ret
= clk_enable(master_saif
->clk
);
542 dev_err(saif
->dev
, "Failed to enable master clock\n");
547 * If the saif's master is not itself, we also need to enable
548 * itself clk for its internal basic logic to work.
550 if (saif
!= master_saif
) {
551 ret
= clk_enable(saif
->clk
);
553 dev_err(saif
->dev
, "Failed to enable master clock\n");
554 clk_disable(master_saif
->clk
);
558 __raw_writel(BM_SAIF_CTRL_RUN
,
559 saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
562 if (!master_saif
->mclk_in_use
)
563 __raw_writel(BM_SAIF_CTRL_RUN
,
564 master_saif
->base
+ SAIF_CTRL
+ MXS_SET_ADDR
);
566 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
568 * write data to saif data register to trigger
570 * For 24-bit format the 32-bit FIFO register stores
571 * only one channel, so we need to write twice.
572 * This is also safe for the other non 24-bit formats.
574 __raw_writel(0, saif
->base
+ SAIF_DATA
);
575 __raw_writel(0, saif
->base
+ SAIF_DATA
);
578 * read data from saif data register to trigger
580 * For 24-bit format the 32-bit FIFO register stores
581 * only one channel, so we need to read twice.
582 * This is also safe for the other non 24-bit formats.
584 __raw_readl(saif
->base
+ SAIF_DATA
);
585 __raw_readl(saif
->base
+ SAIF_DATA
);
588 master_saif
->ongoing
= 1;
589 saif
->state
= MXS_SAIF_STATE_RUNNING
;
591 dev_dbg(saif
->dev
, "CTRL 0x%x STAT 0x%x\n",
592 __raw_readl(saif
->base
+ SAIF_CTRL
),
593 __raw_readl(saif
->base
+ SAIF_STAT
));
595 dev_dbg(master_saif
->dev
, "CTRL 0x%x STAT 0x%x\n",
596 __raw_readl(master_saif
->base
+ SAIF_CTRL
),
597 __raw_readl(master_saif
->base
+ SAIF_STAT
));
599 case SNDRV_PCM_TRIGGER_SUSPEND
:
600 case SNDRV_PCM_TRIGGER_STOP
:
601 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
602 if (saif
->state
== MXS_SAIF_STATE_STOPPED
)
605 dev_dbg(cpu_dai
->dev
, "stop\n");
607 /* wait a while for the current sample to complete */
608 delay
= USEC_PER_SEC
/ master_saif
->cur_rate
;
610 if (!master_saif
->mclk_in_use
) {
611 __raw_writel(BM_SAIF_CTRL_RUN
,
612 master_saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
615 clk_disable(master_saif
->clk
);
617 if (saif
!= master_saif
) {
618 __raw_writel(BM_SAIF_CTRL_RUN
,
619 saif
->base
+ SAIF_CTRL
+ MXS_CLR_ADDR
);
621 clk_disable(saif
->clk
);
624 master_saif
->ongoing
= 0;
625 saif
->state
= MXS_SAIF_STATE_STOPPED
;
635 #define MXS_SAIF_RATES SNDRV_PCM_RATE_8000_192000
636 #define MXS_SAIF_FORMATS \
637 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
638 SNDRV_PCM_FMTBIT_S24_LE)
640 static const struct snd_soc_dai_ops mxs_saif_dai_ops
= {
641 .startup
= mxs_saif_startup
,
642 .shutdown
= mxs_saif_shutdown
,
643 .trigger
= mxs_saif_trigger
,
644 .prepare
= mxs_saif_prepare
,
645 .hw_params
= mxs_saif_hw_params
,
646 .set_sysclk
= mxs_saif_set_dai_sysclk
,
647 .set_fmt
= mxs_saif_set_dai_fmt
,
650 static int mxs_saif_dai_probe(struct snd_soc_dai
*dai
)
652 struct mxs_saif
*saif
= dev_get_drvdata(dai
->dev
);
654 snd_soc_dai_set_drvdata(dai
, saif
);
659 static struct snd_soc_dai_driver mxs_saif_dai
= {
661 .probe
= mxs_saif_dai_probe
,
665 .rates
= MXS_SAIF_RATES
,
666 .formats
= MXS_SAIF_FORMATS
,
671 .rates
= MXS_SAIF_RATES
,
672 .formats
= MXS_SAIF_FORMATS
,
674 .ops
= &mxs_saif_dai_ops
,
677 static const struct snd_soc_component_driver mxs_saif_component
= {
681 static irqreturn_t
mxs_saif_irq(int irq
, void *dev_id
)
683 struct mxs_saif
*saif
= dev_id
;
686 stat
= __raw_readl(saif
->base
+ SAIF_STAT
);
687 if (!(stat
& (BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ
|
688 BM_SAIF_STAT_FIFO_OVERFLOW_IRQ
)))
691 if (stat
& BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ
) {
692 dev_dbg(saif
->dev
, "underrun!!! %d\n", ++saif
->fifo_underrun
);
693 __raw_writel(BM_SAIF_STAT_FIFO_UNDERFLOW_IRQ
,
694 saif
->base
+ SAIF_STAT
+ MXS_CLR_ADDR
);
697 if (stat
& BM_SAIF_STAT_FIFO_OVERFLOW_IRQ
) {
698 dev_dbg(saif
->dev
, "overrun!!! %d\n", ++saif
->fifo_overrun
);
699 __raw_writel(BM_SAIF_STAT_FIFO_OVERFLOW_IRQ
,
700 saif
->base
+ SAIF_STAT
+ MXS_CLR_ADDR
);
703 dev_dbg(saif
->dev
, "SAIF_CTRL %x SAIF_STAT %x\n",
704 __raw_readl(saif
->base
+ SAIF_CTRL
),
705 __raw_readl(saif
->base
+ SAIF_STAT
));
710 static int mxs_saif_mclk_init(struct platform_device
*pdev
)
712 struct mxs_saif
*saif
= platform_get_drvdata(pdev
);
713 struct device_node
*np
= pdev
->dev
.of_node
;
717 clk
= clk_register_divider(&pdev
->dev
, "mxs_saif_mclk",
718 __clk_get_name(saif
->clk
), 0,
719 saif
->base
+ SAIF_CTRL
,
720 BP_SAIF_CTRL_BITCLK_MULT_RATE
, 3,
726 dev_err(&pdev
->dev
, "failed to register mclk: %d\n", ret
);
730 ret
= of_clk_add_provider(np
, of_clk_src_simple_get
, clk
);
737 static int mxs_saif_probe(struct platform_device
*pdev
)
739 struct device_node
*np
= pdev
->dev
.of_node
;
740 struct resource
*iores
;
741 struct mxs_saif
*saif
;
743 struct device_node
*master
;
748 saif
= devm_kzalloc(&pdev
->dev
, sizeof(*saif
), GFP_KERNEL
);
752 ret
= of_alias_get_id(np
, "saif");
758 if (saif
->id
>= ARRAY_SIZE(mxs_saif
)) {
759 dev_err(&pdev
->dev
, "get wrong saif id\n");
764 * If there is no "fsl,saif-master" phandle, it's a saif
765 * master. Otherwise, it's a slave and its phandle points
768 master
= of_parse_phandle(np
, "fsl,saif-master", 0);
770 saif
->master_id
= saif
->id
;
772 ret
= of_alias_get_id(master
, "saif");
776 saif
->master_id
= ret
;
778 if (saif
->master_id
>= ARRAY_SIZE(mxs_saif
)) {
779 dev_err(&pdev
->dev
, "get wrong master id\n");
784 mxs_saif
[saif
->id
] = saif
;
786 saif
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
787 if (IS_ERR(saif
->clk
)) {
788 ret
= PTR_ERR(saif
->clk
);
789 dev_err(&pdev
->dev
, "Cannot get the clock: %d\n",
794 iores
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
796 saif
->base
= devm_ioremap_resource(&pdev
->dev
, iores
);
797 if (IS_ERR(saif
->base
))
798 return PTR_ERR(saif
->base
);
800 irq
= platform_get_irq(pdev
, 0);
803 dev_err(&pdev
->dev
, "failed to get irq resource: %d\n",
808 saif
->dev
= &pdev
->dev
;
809 ret
= devm_request_irq(&pdev
->dev
, irq
, mxs_saif_irq
, 0,
810 dev_name(&pdev
->dev
), saif
);
812 dev_err(&pdev
->dev
, "failed to request irq\n");
816 platform_set_drvdata(pdev
, saif
);
818 /* We only support saif0 being tx and clock master */
820 ret
= mxs_saif_mclk_init(pdev
);
822 dev_warn(&pdev
->dev
, "failed to init clocks\n");
825 ret
= devm_snd_soc_register_component(&pdev
->dev
, &mxs_saif_component
,
828 dev_err(&pdev
->dev
, "register DAI failed\n");
832 ret
= mxs_pcm_platform_register(&pdev
->dev
);
834 dev_err(&pdev
->dev
, "register PCM failed: %d\n", ret
);
841 static const struct of_device_id mxs_saif_dt_ids
[] = {
842 { .compatible
= "fsl,imx28-saif", },
845 MODULE_DEVICE_TABLE(of
, mxs_saif_dt_ids
);
847 static struct platform_driver mxs_saif_driver
= {
848 .probe
= mxs_saif_probe
,
852 .of_match_table
= mxs_saif_dt_ids
,
856 module_platform_driver(mxs_saif_driver
);
858 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
859 MODULE_DESCRIPTION("MXS ASoC SAIF driver");
860 MODULE_LICENSE("GPL");
861 MODULE_ALIAS("platform:mxs-saif");