1 /* sound/soc/samsung/i2s.c
3 * ALSA SoC Audio Layer - Samsung I2S Controller driver
5 * Copyright (c) 2010 Samsung Electronics Co. Ltd.
6 * Jaswinder Singh <jassi.brar@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/delay.h>
14 #include <linux/slab.h>
15 #include <linux/clk.h>
18 #include <sound/soc.h>
19 #include <sound/pcm_params.h>
21 #include <plat/audio.h>
27 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
30 /* Platform device for this DAI */
31 struct platform_device
*pdev
;
34 /* Physical base address of SFRs */
36 /* Rate of RCLK source clock */
37 unsigned long rclk_srcrate
;
41 * Specifically requested RCLK,BCLK by MACHINE Driver.
42 * 0 indicates CPU driver is free to choose any value.
45 /* I2S Controller's core clock */
47 /* Clock for generating I2S signals */
49 /* Array of clock names for op_clk */
51 /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
52 struct i2s_dai
*pri_dai
;
53 /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
54 struct i2s_dai
*sec_dai
;
55 #define DAI_OPENED (1 << 0) /* Dai is opened */
56 #define DAI_MANAGER (1 << 1) /* Dai is the manager */
58 /* Driver for this DAI */
59 struct snd_soc_dai_driver i2s_dai_drv
;
61 struct s3c_dma_params dma_playback
;
62 struct s3c_dma_params dma_capture
;
69 /* Lock for cross i/f checks */
70 static DEFINE_SPINLOCK(lock
);
72 /* If this is the 'overlay' stereo DAI */
73 static inline bool is_secondary(struct i2s_dai
*i2s
)
75 return i2s
->pri_dai
? true : false;
78 /* If operating in SoC-Slave mode */
79 static inline bool is_slave(struct i2s_dai
*i2s
)
81 return (readl(i2s
->addr
+ I2SMOD
) & MOD_SLAVE
) ? true : false;
84 /* If this interface of the controller is transmitting data */
85 static inline bool tx_active(struct i2s_dai
*i2s
)
92 active
= readl(i2s
->addr
+ I2SCON
);
94 if (is_secondary(i2s
))
95 active
&= CON_TXSDMA_ACTIVE
;
97 active
&= CON_TXDMA_ACTIVE
;
99 return active
? true : false;
102 /* If the other interface of the controller is transmitting data */
103 static inline bool other_tx_active(struct i2s_dai
*i2s
)
105 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
107 return tx_active(other
);
110 /* If any interface of the controller is transmitting data */
111 static inline bool any_tx_active(struct i2s_dai
*i2s
)
113 return tx_active(i2s
) || other_tx_active(i2s
);
116 /* If this interface of the controller is receiving data */
117 static inline bool rx_active(struct i2s_dai
*i2s
)
124 active
= readl(i2s
->addr
+ I2SCON
) & CON_RXDMA_ACTIVE
;
126 return active
? true : false;
129 /* If the other interface of the controller is receiving data */
130 static inline bool other_rx_active(struct i2s_dai
*i2s
)
132 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
134 return rx_active(other
);
137 /* If any interface of the controller is receiving data */
138 static inline bool any_rx_active(struct i2s_dai
*i2s
)
140 return rx_active(i2s
) || other_rx_active(i2s
);
143 /* If the other DAI is transmitting or receiving data */
144 static inline bool other_active(struct i2s_dai
*i2s
)
146 return other_rx_active(i2s
) || other_tx_active(i2s
);
149 /* If this DAI is transmitting or receiving data */
150 static inline bool this_active(struct i2s_dai
*i2s
)
152 return tx_active(i2s
) || rx_active(i2s
);
155 /* If the controller is active anyway */
156 static inline bool any_active(struct i2s_dai
*i2s
)
158 return this_active(i2s
) || other_active(i2s
);
161 static inline struct i2s_dai
*to_info(struct snd_soc_dai
*dai
)
163 return snd_soc_dai_get_drvdata(dai
);
166 static inline bool is_opened(struct i2s_dai
*i2s
)
168 if (i2s
&& (i2s
->mode
& DAI_OPENED
))
174 static inline bool is_manager(struct i2s_dai
*i2s
)
176 if (is_opened(i2s
) && (i2s
->mode
& DAI_MANAGER
))
182 /* Read RCLK of I2S (in multiples of LRCLK) */
183 static inline unsigned get_rfs(struct i2s_dai
*i2s
)
185 u32 rfs
= (readl(i2s
->addr
+ I2SMOD
) >> 3) & 0x3;
195 /* Write RCLK of I2S (in multiples of LRCLK) */
196 static inline void set_rfs(struct i2s_dai
*i2s
, unsigned rfs
)
198 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
200 mod
&= ~MOD_RCLK_MASK
;
204 mod
|= MOD_RCLK_768FS
;
207 mod
|= MOD_RCLK_512FS
;
210 mod
|= MOD_RCLK_384FS
;
213 mod
|= MOD_RCLK_256FS
;
217 writel(mod
, i2s
->addr
+ I2SMOD
);
220 /* Read Bit-Clock of I2S (in multiples of LRCLK) */
221 static inline unsigned get_bfs(struct i2s_dai
*i2s
)
223 u32 bfs
= (readl(i2s
->addr
+ I2SMOD
) >> 1) & 0x3;
233 /* Write Bit-Clock of I2S (in multiples of LRCLK) */
234 static inline void set_bfs(struct i2s_dai
*i2s
, unsigned bfs
)
236 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
238 mod
&= ~MOD_BCLK_MASK
;
242 mod
|= MOD_BCLK_48FS
;
245 mod
|= MOD_BCLK_32FS
;
248 mod
|= MOD_BCLK_24FS
;
251 mod
|= MOD_BCLK_16FS
;
254 dev_err(&i2s
->pdev
->dev
, "Wrong BCLK Divider!\n");
258 writel(mod
, i2s
->addr
+ I2SMOD
);
262 static inline int get_blc(struct i2s_dai
*i2s
)
264 int blc
= readl(i2s
->addr
+ I2SMOD
);
266 blc
= (blc
>> 13) & 0x3;
275 /* TX Channel Control */
276 static void i2s_txctrl(struct i2s_dai
*i2s
, int on
)
278 void __iomem
*addr
= i2s
->addr
;
279 u32 con
= readl(addr
+ I2SCON
);
280 u32 mod
= readl(addr
+ I2SMOD
) & ~MOD_MASK
;
284 con
&= ~CON_TXCH_PAUSE
;
286 if (is_secondary(i2s
)) {
287 con
|= CON_TXSDMA_ACTIVE
;
288 con
&= ~CON_TXSDMA_PAUSE
;
290 con
|= CON_TXDMA_ACTIVE
;
291 con
&= ~CON_TXDMA_PAUSE
;
294 if (any_rx_active(i2s
))
299 if (is_secondary(i2s
)) {
300 con
|= CON_TXSDMA_PAUSE
;
301 con
&= ~CON_TXSDMA_ACTIVE
;
303 con
|= CON_TXDMA_PAUSE
;
304 con
&= ~CON_TXDMA_ACTIVE
;
307 if (other_tx_active(i2s
)) {
308 writel(con
, addr
+ I2SCON
);
312 con
|= CON_TXCH_PAUSE
;
314 if (any_rx_active(i2s
))
320 writel(mod
, addr
+ I2SMOD
);
321 writel(con
, addr
+ I2SCON
);
324 /* RX Channel Control */
325 static void i2s_rxctrl(struct i2s_dai
*i2s
, int on
)
327 void __iomem
*addr
= i2s
->addr
;
328 u32 con
= readl(addr
+ I2SCON
);
329 u32 mod
= readl(addr
+ I2SMOD
) & ~MOD_MASK
;
332 con
|= CON_RXDMA_ACTIVE
| CON_ACTIVE
;
333 con
&= ~(CON_RXDMA_PAUSE
| CON_RXCH_PAUSE
);
335 if (any_tx_active(i2s
))
340 con
|= CON_RXDMA_PAUSE
| CON_RXCH_PAUSE
;
341 con
&= ~CON_RXDMA_ACTIVE
;
343 if (any_tx_active(i2s
))
349 writel(mod
, addr
+ I2SMOD
);
350 writel(con
, addr
+ I2SCON
);
353 /* Flush FIFO of an interface */
354 static inline void i2s_fifo(struct i2s_dai
*i2s
, u32 flush
)
362 if (is_secondary(i2s
))
363 fic
= i2s
->addr
+ I2SFICS
;
365 fic
= i2s
->addr
+ I2SFIC
;
368 writel(readl(fic
) | flush
, fic
);
371 val
= msecs_to_loops(1) / 1000; /* 1 usec */
375 writel(readl(fic
) & ~flush
, fic
);
378 static int i2s_set_sysclk(struct snd_soc_dai
*dai
,
379 int clk_id
, unsigned int rfs
, int dir
)
381 struct i2s_dai
*i2s
= to_info(dai
);
382 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
383 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
386 case SAMSUNG_I2S_CDCLK
:
387 /* Shouldn't matter in GATING(CLOCK_IN) mode */
388 if (dir
== SND_SOC_CLOCK_IN
)
391 if ((rfs
&& other
->rfs
&& (other
->rfs
!= rfs
)) ||
393 (((dir
== SND_SOC_CLOCK_IN
)
394 && !(mod
& MOD_CDCLKCON
)) ||
395 ((dir
== SND_SOC_CLOCK_OUT
)
396 && (mod
& MOD_CDCLKCON
))))) {
397 dev_err(&i2s
->pdev
->dev
,
398 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
402 if (dir
== SND_SOC_CLOCK_IN
)
405 mod
&= ~MOD_CDCLKCON
;
410 case SAMSUNG_I2S_RCLKSRC_0
: /* clock corrsponding to IISMOD[10] := 0 */
411 case SAMSUNG_I2S_RCLKSRC_1
: /* clock corrsponding to IISMOD[10] := 1 */
412 if ((i2s
->quirks
& QUIRK_NO_MUXPSR
)
413 || (clk_id
== SAMSUNG_I2S_RCLKSRC_0
))
418 if (!any_active(i2s
)) {
420 if ((clk_id
&& !(mod
& MOD_IMS_SYSMUX
)) ||
421 (!clk_id
&& (mod
& MOD_IMS_SYSMUX
))) {
422 clk_disable(i2s
->op_clk
);
423 clk_put(i2s
->op_clk
);
426 clk_get_rate(i2s
->op_clk
);
431 i2s
->op_clk
= clk_get(&i2s
->pdev
->dev
,
432 i2s
->src_clk
[clk_id
]);
433 clk_enable(i2s
->op_clk
);
434 i2s
->rclk_srcrate
= clk_get_rate(i2s
->op_clk
);
436 /* Over-ride the other's */
438 other
->op_clk
= i2s
->op_clk
;
439 other
->rclk_srcrate
= i2s
->rclk_srcrate
;
441 } else if ((!clk_id
&& (mod
& MOD_IMS_SYSMUX
))
442 || (clk_id
&& !(mod
& MOD_IMS_SYSMUX
))) {
443 dev_err(&i2s
->pdev
->dev
,
444 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
447 /* Call can't be on the active DAI */
448 i2s
->op_clk
= other
->op_clk
;
449 i2s
->rclk_srcrate
= other
->rclk_srcrate
;
454 mod
&= ~MOD_IMS_SYSMUX
;
456 mod
|= MOD_IMS_SYSMUX
;
460 dev_err(&i2s
->pdev
->dev
, "We don't serve that!\n");
464 writel(mod
, i2s
->addr
+ I2SMOD
);
469 static int i2s_set_fmt(struct snd_soc_dai
*dai
,
472 struct i2s_dai
*i2s
= to_info(dai
);
473 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
476 /* Format is priority */
477 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
478 case SND_SOC_DAIFMT_RIGHT_J
:
482 case SND_SOC_DAIFMT_LEFT_J
:
486 case SND_SOC_DAIFMT_I2S
:
490 dev_err(&i2s
->pdev
->dev
, "Format not supported\n");
495 * INV flag is relative to the FORMAT flag - if set it simply
496 * flips the polarity specified by the Standard
498 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
499 case SND_SOC_DAIFMT_NB_NF
:
501 case SND_SOC_DAIFMT_NB_IF
:
502 if (tmp
& MOD_LR_RLOW
)
508 dev_err(&i2s
->pdev
->dev
, "Polarity not supported\n");
512 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
513 case SND_SOC_DAIFMT_CBM_CFM
:
516 case SND_SOC_DAIFMT_CBS_CFS
:
517 /* Set default source clock in Master mode */
518 if (i2s
->rclk_srcrate
== 0)
519 i2s_set_sysclk(dai
, SAMSUNG_I2S_RCLKSRC_0
,
520 0, SND_SOC_CLOCK_IN
);
523 dev_err(&i2s
->pdev
->dev
, "master/slave format not supported\n");
527 if (any_active(i2s
) &&
528 ((mod
& (MOD_SDF_MASK
| MOD_LR_RLOW
529 | MOD_SLAVE
)) != tmp
)) {
530 dev_err(&i2s
->pdev
->dev
,
531 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
535 mod
&= ~(MOD_SDF_MASK
| MOD_LR_RLOW
| MOD_SLAVE
);
537 writel(mod
, i2s
->addr
+ I2SMOD
);
542 static int i2s_hw_params(struct snd_pcm_substream
*substream
,
543 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
545 struct i2s_dai
*i2s
= to_info(dai
);
546 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
548 if (!is_secondary(i2s
))
549 mod
&= ~(MOD_DC2_EN
| MOD_DC1_EN
);
551 switch (params_channels(params
)) {
560 dev_err(&i2s
->pdev
->dev
, "%d channels not supported\n",
561 params_channels(params
));
565 if (is_secondary(i2s
))
566 mod
&= ~MOD_BLCS_MASK
;
568 mod
&= ~MOD_BLCP_MASK
;
571 mod
&= ~MOD_BLC_MASK
;
573 switch (params_format(params
)) {
574 case SNDRV_PCM_FORMAT_S8
:
575 if (is_secondary(i2s
))
576 mod
|= MOD_BLCS_8BIT
;
578 mod
|= MOD_BLCP_8BIT
;
582 case SNDRV_PCM_FORMAT_S16_LE
:
583 if (is_secondary(i2s
))
584 mod
|= MOD_BLCS_16BIT
;
586 mod
|= MOD_BLCP_16BIT
;
588 mod
|= MOD_BLC_16BIT
;
590 case SNDRV_PCM_FORMAT_S24_LE
:
591 if (is_secondary(i2s
))
592 mod
|= MOD_BLCS_24BIT
;
594 mod
|= MOD_BLCP_24BIT
;
596 mod
|= MOD_BLC_24BIT
;
599 dev_err(&i2s
->pdev
->dev
, "Format(%d) not supported\n",
600 params_format(params
));
603 writel(mod
, i2s
->addr
+ I2SMOD
);
605 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
606 snd_soc_dai_set_dma_data(dai
, substream
,
607 (void *)&i2s
->dma_playback
);
609 snd_soc_dai_set_dma_data(dai
, substream
,
610 (void *)&i2s
->dma_capture
);
612 i2s
->frmclk
= params_rate(params
);
617 /* We set constraints on the substream acc to the version of I2S */
618 static int i2s_startup(struct snd_pcm_substream
*substream
,
619 struct snd_soc_dai
*dai
)
621 struct i2s_dai
*i2s
= to_info(dai
);
622 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
625 spin_lock_irqsave(&lock
, flags
);
627 i2s
->mode
|= DAI_OPENED
;
629 if (is_manager(other
))
630 i2s
->mode
&= ~DAI_MANAGER
;
632 i2s
->mode
|= DAI_MANAGER
;
634 /* Enforce set_sysclk in Master mode */
635 i2s
->rclk_srcrate
= 0;
637 spin_unlock_irqrestore(&lock
, flags
);
642 static void i2s_shutdown(struct snd_pcm_substream
*substream
,
643 struct snd_soc_dai
*dai
)
645 struct i2s_dai
*i2s
= to_info(dai
);
646 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
649 spin_lock_irqsave(&lock
, flags
);
651 i2s
->mode
&= ~DAI_OPENED
;
652 i2s
->mode
&= ~DAI_MANAGER
;
654 if (is_opened(other
))
655 other
->mode
|= DAI_MANAGER
;
657 /* Reset any constraint on RFS and BFS */
661 spin_unlock_irqrestore(&lock
, flags
);
663 /* Gate CDCLK by default */
664 if (!is_opened(other
))
665 i2s_set_sysclk(dai
, SAMSUNG_I2S_CDCLK
,
666 0, SND_SOC_CLOCK_IN
);
669 static int config_setup(struct i2s_dai
*i2s
)
671 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
672 unsigned rfs
, bfs
, blc
;
682 /* Select least possible multiple(2) if no constraint set */
691 if ((rfs
== 256 || rfs
== 512) && (blc
== 24)) {
692 dev_err(&i2s
->pdev
->dev
,
693 "%d-RFS not supported for 24-blc\n", rfs
);
698 if (bfs
== 16 || bfs
== 32)
704 /* If already setup and running */
705 if (any_active(i2s
) && (get_rfs(i2s
) != rfs
|| get_bfs(i2s
) != bfs
)) {
706 dev_err(&i2s
->pdev
->dev
,
707 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
711 /* Don't bother RFS, BFS & PSR in Slave mode */
718 if (!(i2s
->quirks
& QUIRK_NO_MUXPSR
)) {
719 psr
= i2s
->rclk_srcrate
/ i2s
->frmclk
/ rfs
;
720 writel(((psr
- 1) << 8) | PSR_PSREN
, i2s
->addr
+ I2SPSR
);
721 dev_dbg(&i2s
->pdev
->dev
,
722 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
723 i2s
->rclk_srcrate
, psr
, rfs
, bfs
);
729 static int i2s_trigger(struct snd_pcm_substream
*substream
,
730 int cmd
, struct snd_soc_dai
*dai
)
732 int capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
733 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
734 struct i2s_dai
*i2s
= to_info(rtd
->cpu_dai
);
738 case SNDRV_PCM_TRIGGER_START
:
739 case SNDRV_PCM_TRIGGER_RESUME
:
740 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
741 local_irq_save(flags
);
743 if (config_setup(i2s
)) {
744 local_irq_restore(flags
);
753 local_irq_restore(flags
);
755 case SNDRV_PCM_TRIGGER_STOP
:
756 case SNDRV_PCM_TRIGGER_SUSPEND
:
757 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
758 local_irq_save(flags
);
766 i2s_fifo(i2s
, FIC_RXFLUSH
);
768 i2s_fifo(i2s
, FIC_TXFLUSH
);
770 local_irq_restore(flags
);
777 static int i2s_set_clkdiv(struct snd_soc_dai
*dai
,
780 struct i2s_dai
*i2s
= to_info(dai
);
781 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
784 case SAMSUNG_I2S_DIV_BCLK
:
785 if ((any_active(i2s
) && div
&& (get_bfs(i2s
) != div
))
786 || (other
&& other
->bfs
&& (other
->bfs
!= div
))) {
787 dev_err(&i2s
->pdev
->dev
,
788 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
794 dev_err(&i2s
->pdev
->dev
,
795 "Invalid clock divider(%d)\n", div_id
);
802 static snd_pcm_sframes_t
803 i2s_delay(struct snd_pcm_substream
*substream
, struct snd_soc_dai
*dai
)
805 struct i2s_dai
*i2s
= to_info(dai
);
806 u32 reg
= readl(i2s
->addr
+ I2SFIC
);
807 snd_pcm_sframes_t delay
;
809 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
810 delay
= FIC_RXCOUNT(reg
);
811 else if (is_secondary(i2s
))
812 delay
= FICS_TXCOUNT(readl(i2s
->addr
+ I2SFICS
));
814 delay
= FIC_TXCOUNT(reg
);
820 static int i2s_suspend(struct snd_soc_dai
*dai
)
822 struct i2s_dai
*i2s
= to_info(dai
);
825 i2s
->suspend_i2smod
= readl(i2s
->addr
+ I2SMOD
);
826 i2s
->suspend_i2scon
= readl(i2s
->addr
+ I2SCON
);
827 i2s
->suspend_i2spsr
= readl(i2s
->addr
+ I2SPSR
);
833 static int i2s_resume(struct snd_soc_dai
*dai
)
835 struct i2s_dai
*i2s
= to_info(dai
);
838 writel(i2s
->suspend_i2scon
, i2s
->addr
+ I2SCON
);
839 writel(i2s
->suspend_i2smod
, i2s
->addr
+ I2SMOD
);
840 writel(i2s
->suspend_i2spsr
, i2s
->addr
+ I2SPSR
);
846 #define i2s_suspend NULL
847 #define i2s_resume NULL
850 static int samsung_i2s_dai_probe(struct snd_soc_dai
*dai
)
852 struct i2s_dai
*i2s
= to_info(dai
);
853 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
855 if (other
&& other
->clk
) /* If this is probe on secondary */
858 i2s
->addr
= ioremap(i2s
->base
, 0x100);
859 if (i2s
->addr
== NULL
) {
860 dev_err(&i2s
->pdev
->dev
, "cannot ioremap registers\n");
864 i2s
->clk
= clk_get(&i2s
->pdev
->dev
, "iis");
865 if (IS_ERR(i2s
->clk
)) {
866 dev_err(&i2s
->pdev
->dev
, "failed to get i2s_clock\n");
870 clk_enable(i2s
->clk
);
873 other
->addr
= i2s
->addr
;
874 other
->clk
= i2s
->clk
;
877 if (i2s
->quirks
& QUIRK_NEED_RSTCLR
)
878 writel(CON_RSTCLR
, i2s
->addr
+ I2SCON
);
881 /* Reset any constraint on RFS and BFS */
886 i2s_fifo(i2s
, FIC_TXFLUSH
);
887 i2s_fifo(other
, FIC_TXFLUSH
);
888 i2s_fifo(i2s
, FIC_RXFLUSH
);
890 /* Gate CDCLK by default */
891 if (!is_opened(other
))
892 i2s_set_sysclk(dai
, SAMSUNG_I2S_CDCLK
,
893 0, SND_SOC_CLOCK_IN
);
898 static int samsung_i2s_dai_remove(struct snd_soc_dai
*dai
)
900 struct i2s_dai
*i2s
= snd_soc_dai_get_drvdata(dai
);
901 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
903 if (!other
|| !other
->clk
) {
905 if (i2s
->quirks
& QUIRK_NEED_RSTCLR
)
906 writel(0, i2s
->addr
+ I2SCON
);
908 clk_disable(i2s
->clk
);
919 static struct snd_soc_dai_ops samsung_i2s_dai_ops
= {
920 .trigger
= i2s_trigger
,
921 .hw_params
= i2s_hw_params
,
922 .set_fmt
= i2s_set_fmt
,
923 .set_clkdiv
= i2s_set_clkdiv
,
924 .set_sysclk
= i2s_set_sysclk
,
925 .startup
= i2s_startup
,
926 .shutdown
= i2s_shutdown
,
930 #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
932 #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
933 SNDRV_PCM_FMTBIT_S16_LE | \
934 SNDRV_PCM_FMTBIT_S24_LE)
937 struct i2s_dai
*i2s_alloc_dai(struct platform_device
*pdev
, bool sec
)
941 i2s
= kzalloc(sizeof(struct i2s_dai
), GFP_KERNEL
);
948 i2s
->i2s_dai_drv
.symmetric_rates
= 1;
949 i2s
->i2s_dai_drv
.probe
= samsung_i2s_dai_probe
;
950 i2s
->i2s_dai_drv
.remove
= samsung_i2s_dai_remove
;
951 i2s
->i2s_dai_drv
.ops
= &samsung_i2s_dai_ops
;
952 i2s
->i2s_dai_drv
.suspend
= i2s_suspend
;
953 i2s
->i2s_dai_drv
.resume
= i2s_resume
;
954 i2s
->i2s_dai_drv
.playback
.channels_min
= 2;
955 i2s
->i2s_dai_drv
.playback
.channels_max
= 2;
956 i2s
->i2s_dai_drv
.playback
.rates
= SAMSUNG_I2S_RATES
;
957 i2s
->i2s_dai_drv
.playback
.formats
= SAMSUNG_I2S_FMTS
;
960 i2s
->i2s_dai_drv
.capture
.channels_min
= 2;
961 i2s
->i2s_dai_drv
.capture
.channels_max
= 2;
962 i2s
->i2s_dai_drv
.capture
.rates
= SAMSUNG_I2S_RATES
;
963 i2s
->i2s_dai_drv
.capture
.formats
= SAMSUNG_I2S_FMTS
;
964 } else { /* Create a new platform_device for Secondary */
965 i2s
->pdev
= platform_device_register_resndata(NULL
,
966 pdev
->name
, pdev
->id
+ SAMSUNG_I2S_SECOFF
,
968 if (IS_ERR(i2s
->pdev
)) {
974 /* Pre-assign snd_soc_dai_set_drvdata */
975 dev_set_drvdata(&i2s
->pdev
->dev
, i2s
);
980 static __devinit
int samsung_i2s_probe(struct platform_device
*pdev
)
982 u32 dma_pl_chan
, dma_cp_chan
, dma_pl_sec_chan
;
983 struct i2s_dai
*pri_dai
, *sec_dai
= NULL
;
984 struct s3c_audio_pdata
*i2s_pdata
;
985 struct samsung_i2s
*i2s_cfg
;
986 struct resource
*res
;
987 u32 regs_base
, quirks
;
990 /* Call during Seconday interface registration */
991 if (pdev
->id
>= SAMSUNG_I2S_SECOFF
) {
992 sec_dai
= dev_get_drvdata(&pdev
->dev
);
993 snd_soc_register_dai(&sec_dai
->pdev
->dev
,
994 &sec_dai
->i2s_dai_drv
);
998 i2s_pdata
= pdev
->dev
.platform_data
;
999 if (i2s_pdata
== NULL
) {
1000 dev_err(&pdev
->dev
, "Can't work without s3c_audio_pdata\n");
1004 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 0);
1006 dev_err(&pdev
->dev
, "Unable to get I2S-TX dma resource\n");
1009 dma_pl_chan
= res
->start
;
1011 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 1);
1013 dev_err(&pdev
->dev
, "Unable to get I2S-RX dma resource\n");
1016 dma_cp_chan
= res
->start
;
1018 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 2);
1020 dma_pl_sec_chan
= res
->start
;
1022 dma_pl_sec_chan
= 0;
1024 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1026 dev_err(&pdev
->dev
, "Unable to get I2S SFR address\n");
1030 if (!request_mem_region(res
->start
, resource_size(res
),
1032 dev_err(&pdev
->dev
, "Unable to request SFR region\n");
1035 regs_base
= res
->start
;
1037 i2s_cfg
= &i2s_pdata
->type
.i2s
;
1038 quirks
= i2s_cfg
->quirks
;
1040 pri_dai
= i2s_alloc_dai(pdev
, false);
1042 dev_err(&pdev
->dev
, "Unable to alloc I2S_pri\n");
1047 pri_dai
->dma_playback
.dma_addr
= regs_base
+ I2STXD
;
1048 pri_dai
->dma_capture
.dma_addr
= regs_base
+ I2SRXD
;
1049 pri_dai
->dma_playback
.client
=
1050 (struct s3c2410_dma_client
*)&pri_dai
->dma_playback
;
1051 pri_dai
->dma_capture
.client
=
1052 (struct s3c2410_dma_client
*)&pri_dai
->dma_capture
;
1053 pri_dai
->dma_playback
.channel
= dma_pl_chan
;
1054 pri_dai
->dma_capture
.channel
= dma_cp_chan
;
1055 pri_dai
->src_clk
= i2s_cfg
->src_clk
;
1056 pri_dai
->dma_playback
.dma_size
= 4;
1057 pri_dai
->dma_capture
.dma_size
= 4;
1058 pri_dai
->base
= regs_base
;
1059 pri_dai
->quirks
= quirks
;
1061 if (quirks
& QUIRK_PRI_6CHAN
)
1062 pri_dai
->i2s_dai_drv
.playback
.channels_max
= 6;
1064 if (quirks
& QUIRK_SEC_DAI
) {
1065 sec_dai
= i2s_alloc_dai(pdev
, true);
1067 dev_err(&pdev
->dev
, "Unable to alloc I2S_sec\n");
1071 sec_dai
->dma_playback
.dma_addr
= regs_base
+ I2STXDS
;
1072 sec_dai
->dma_playback
.client
=
1073 (struct s3c2410_dma_client
*)&sec_dai
->dma_playback
;
1074 /* Use iDMA always if SysDMA not provided */
1075 sec_dai
->dma_playback
.channel
= dma_pl_sec_chan
? : -1;
1076 sec_dai
->src_clk
= i2s_cfg
->src_clk
;
1077 sec_dai
->dma_playback
.dma_size
= 4;
1078 sec_dai
->base
= regs_base
;
1079 sec_dai
->quirks
= quirks
;
1080 sec_dai
->pri_dai
= pri_dai
;
1081 pri_dai
->sec_dai
= sec_dai
;
1084 if (i2s_pdata
->cfg_gpio
&& i2s_pdata
->cfg_gpio(pdev
)) {
1085 dev_err(&pdev
->dev
, "Unable to configure gpio\n");
1090 snd_soc_register_dai(&pri_dai
->pdev
->dev
, &pri_dai
->i2s_dai_drv
);
1098 release_mem_region(regs_base
, resource_size(res
));
1103 static __devexit
int samsung_i2s_remove(struct platform_device
*pdev
)
1105 struct i2s_dai
*i2s
, *other
;
1107 i2s
= dev_get_drvdata(&pdev
->dev
);
1108 other
= i2s
->pri_dai
? : i2s
->sec_dai
;
1111 other
->pri_dai
= NULL
;
1112 other
->sec_dai
= NULL
;
1114 struct resource
*res
;
1115 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1117 release_mem_region(res
->start
, resource_size(res
));
1120 i2s
->pri_dai
= NULL
;
1121 i2s
->sec_dai
= NULL
;
1125 snd_soc_unregister_dai(&pdev
->dev
);
1130 static struct platform_driver samsung_i2s_driver
= {
1131 .probe
= samsung_i2s_probe
,
1132 .remove
= samsung_i2s_remove
,
1134 .name
= "samsung-i2s",
1135 .owner
= THIS_MODULE
,
1139 static int __init
samsung_i2s_init(void)
1141 return platform_driver_register(&samsung_i2s_driver
);
1143 module_init(samsung_i2s_init
);
1145 static void __exit
samsung_i2s_exit(void)
1147 platform_driver_unregister(&samsung_i2s_driver
);
1149 module_exit(samsung_i2s_exit
);
1151 /* Module information */
1152 MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
1153 MODULE_DESCRIPTION("Samsung I2S Interface");
1154 MODULE_ALIAS("platform:samsung-i2s");
1155 MODULE_LICENSE("GPL");