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>
17 #include <linux/module.h>
19 #include <sound/soc.h>
20 #include <sound/pcm_params.h>
22 #include <plat/audio.h>
29 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
32 /* Platform device for this DAI */
33 struct platform_device
*pdev
;
36 /* Physical base address of SFRs */
38 /* Rate of RCLK source clock */
39 unsigned long rclk_srcrate
;
43 * Specifically requested RCLK,BCLK by MACHINE Driver.
44 * 0 indicates CPU driver is free to choose any value.
47 /* I2S Controller's core clock */
49 /* Clock for generating I2S signals */
51 /* Array of clock names for op_clk */
53 /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
54 struct i2s_dai
*pri_dai
;
55 /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
56 struct i2s_dai
*sec_dai
;
57 #define DAI_OPENED (1 << 0) /* Dai is opened */
58 #define DAI_MANAGER (1 << 1) /* Dai is the manager */
60 /* Driver for this DAI */
61 struct snd_soc_dai_driver i2s_dai_drv
;
63 struct s3c_dma_params dma_playback
;
64 struct s3c_dma_params dma_capture
;
65 struct s3c_dma_params idma_playback
;
72 /* Lock for cross i/f checks */
73 static DEFINE_SPINLOCK(lock
);
75 /* If this is the 'overlay' stereo DAI */
76 static inline bool is_secondary(struct i2s_dai
*i2s
)
78 return i2s
->pri_dai
? true : false;
81 /* If operating in SoC-Slave mode */
82 static inline bool is_slave(struct i2s_dai
*i2s
)
84 return (readl(i2s
->addr
+ I2SMOD
) & MOD_SLAVE
) ? true : false;
87 /* If this interface of the controller is transmitting data */
88 static inline bool tx_active(struct i2s_dai
*i2s
)
95 active
= readl(i2s
->addr
+ I2SCON
);
97 if (is_secondary(i2s
))
98 active
&= CON_TXSDMA_ACTIVE
;
100 active
&= CON_TXDMA_ACTIVE
;
102 return active
? true : false;
105 /* If the other interface of the controller is transmitting data */
106 static inline bool other_tx_active(struct i2s_dai
*i2s
)
108 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
110 return tx_active(other
);
113 /* If any interface of the controller is transmitting data */
114 static inline bool any_tx_active(struct i2s_dai
*i2s
)
116 return tx_active(i2s
) || other_tx_active(i2s
);
119 /* If this interface of the controller is receiving data */
120 static inline bool rx_active(struct i2s_dai
*i2s
)
127 active
= readl(i2s
->addr
+ I2SCON
) & CON_RXDMA_ACTIVE
;
129 return active
? true : false;
132 /* If the other interface of the controller is receiving data */
133 static inline bool other_rx_active(struct i2s_dai
*i2s
)
135 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
137 return rx_active(other
);
140 /* If any interface of the controller is receiving data */
141 static inline bool any_rx_active(struct i2s_dai
*i2s
)
143 return rx_active(i2s
) || other_rx_active(i2s
);
146 /* If the other DAI is transmitting or receiving data */
147 static inline bool other_active(struct i2s_dai
*i2s
)
149 return other_rx_active(i2s
) || other_tx_active(i2s
);
152 /* If this DAI is transmitting or receiving data */
153 static inline bool this_active(struct i2s_dai
*i2s
)
155 return tx_active(i2s
) || rx_active(i2s
);
158 /* If the controller is active anyway */
159 static inline bool any_active(struct i2s_dai
*i2s
)
161 return this_active(i2s
) || other_active(i2s
);
164 static inline struct i2s_dai
*to_info(struct snd_soc_dai
*dai
)
166 return snd_soc_dai_get_drvdata(dai
);
169 static inline bool is_opened(struct i2s_dai
*i2s
)
171 if (i2s
&& (i2s
->mode
& DAI_OPENED
))
177 static inline bool is_manager(struct i2s_dai
*i2s
)
179 if (is_opened(i2s
) && (i2s
->mode
& DAI_MANAGER
))
185 /* Read RCLK of I2S (in multiples of LRCLK) */
186 static inline unsigned get_rfs(struct i2s_dai
*i2s
)
188 u32 rfs
= (readl(i2s
->addr
+ I2SMOD
) >> 3) & 0x3;
198 /* Write RCLK of I2S (in multiples of LRCLK) */
199 static inline void set_rfs(struct i2s_dai
*i2s
, unsigned rfs
)
201 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
203 mod
&= ~MOD_RCLK_MASK
;
207 mod
|= MOD_RCLK_768FS
;
210 mod
|= MOD_RCLK_512FS
;
213 mod
|= MOD_RCLK_384FS
;
216 mod
|= MOD_RCLK_256FS
;
220 writel(mod
, i2s
->addr
+ I2SMOD
);
223 /* Read Bit-Clock of I2S (in multiples of LRCLK) */
224 static inline unsigned get_bfs(struct i2s_dai
*i2s
)
226 u32 bfs
= (readl(i2s
->addr
+ I2SMOD
) >> 1) & 0x3;
236 /* Write Bit-Clock of I2S (in multiples of LRCLK) */
237 static inline void set_bfs(struct i2s_dai
*i2s
, unsigned bfs
)
239 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
241 mod
&= ~MOD_BCLK_MASK
;
245 mod
|= MOD_BCLK_48FS
;
248 mod
|= MOD_BCLK_32FS
;
251 mod
|= MOD_BCLK_24FS
;
254 mod
|= MOD_BCLK_16FS
;
257 dev_err(&i2s
->pdev
->dev
, "Wrong BCLK Divider!\n");
261 writel(mod
, i2s
->addr
+ I2SMOD
);
265 static inline int get_blc(struct i2s_dai
*i2s
)
267 int blc
= readl(i2s
->addr
+ I2SMOD
);
269 blc
= (blc
>> 13) & 0x3;
278 /* TX Channel Control */
279 static void i2s_txctrl(struct i2s_dai
*i2s
, int on
)
281 void __iomem
*addr
= i2s
->addr
;
282 u32 con
= readl(addr
+ I2SCON
);
283 u32 mod
= readl(addr
+ I2SMOD
) & ~MOD_MASK
;
287 con
&= ~CON_TXCH_PAUSE
;
289 if (is_secondary(i2s
)) {
290 con
|= CON_TXSDMA_ACTIVE
;
291 con
&= ~CON_TXSDMA_PAUSE
;
293 con
|= CON_TXDMA_ACTIVE
;
294 con
&= ~CON_TXDMA_PAUSE
;
297 if (any_rx_active(i2s
))
302 if (is_secondary(i2s
)) {
303 con
|= CON_TXSDMA_PAUSE
;
304 con
&= ~CON_TXSDMA_ACTIVE
;
306 con
|= CON_TXDMA_PAUSE
;
307 con
&= ~CON_TXDMA_ACTIVE
;
310 if (other_tx_active(i2s
)) {
311 writel(con
, addr
+ I2SCON
);
315 con
|= CON_TXCH_PAUSE
;
317 if (any_rx_active(i2s
))
323 writel(mod
, addr
+ I2SMOD
);
324 writel(con
, addr
+ I2SCON
);
327 /* RX Channel Control */
328 static void i2s_rxctrl(struct i2s_dai
*i2s
, int on
)
330 void __iomem
*addr
= i2s
->addr
;
331 u32 con
= readl(addr
+ I2SCON
);
332 u32 mod
= readl(addr
+ I2SMOD
) & ~MOD_MASK
;
335 con
|= CON_RXDMA_ACTIVE
| CON_ACTIVE
;
336 con
&= ~(CON_RXDMA_PAUSE
| CON_RXCH_PAUSE
);
338 if (any_tx_active(i2s
))
343 con
|= CON_RXDMA_PAUSE
| CON_RXCH_PAUSE
;
344 con
&= ~CON_RXDMA_ACTIVE
;
346 if (any_tx_active(i2s
))
352 writel(mod
, addr
+ I2SMOD
);
353 writel(con
, addr
+ I2SCON
);
356 /* Flush FIFO of an interface */
357 static inline void i2s_fifo(struct i2s_dai
*i2s
, u32 flush
)
365 if (is_secondary(i2s
))
366 fic
= i2s
->addr
+ I2SFICS
;
368 fic
= i2s
->addr
+ I2SFIC
;
371 writel(readl(fic
) | flush
, fic
);
374 val
= msecs_to_loops(1) / 1000; /* 1 usec */
378 writel(readl(fic
) & ~flush
, fic
);
381 static int i2s_set_sysclk(struct snd_soc_dai
*dai
,
382 int clk_id
, unsigned int rfs
, int dir
)
384 struct i2s_dai
*i2s
= to_info(dai
);
385 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
386 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
389 case SAMSUNG_I2S_CDCLK
:
390 /* Shouldn't matter in GATING(CLOCK_IN) mode */
391 if (dir
== SND_SOC_CLOCK_IN
)
394 if ((rfs
&& other
->rfs
&& (other
->rfs
!= rfs
)) ||
396 (((dir
== SND_SOC_CLOCK_IN
)
397 && !(mod
& MOD_CDCLKCON
)) ||
398 ((dir
== SND_SOC_CLOCK_OUT
)
399 && (mod
& MOD_CDCLKCON
))))) {
400 dev_err(&i2s
->pdev
->dev
,
401 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
405 if (dir
== SND_SOC_CLOCK_IN
)
408 mod
&= ~MOD_CDCLKCON
;
413 case SAMSUNG_I2S_RCLKSRC_0
: /* clock corrsponding to IISMOD[10] := 0 */
414 case SAMSUNG_I2S_RCLKSRC_1
: /* clock corrsponding to IISMOD[10] := 1 */
415 if ((i2s
->quirks
& QUIRK_NO_MUXPSR
)
416 || (clk_id
== SAMSUNG_I2S_RCLKSRC_0
))
421 if (!any_active(i2s
)) {
423 if ((clk_id
&& !(mod
& MOD_IMS_SYSMUX
)) ||
424 (!clk_id
&& (mod
& MOD_IMS_SYSMUX
))) {
425 clk_disable(i2s
->op_clk
);
426 clk_put(i2s
->op_clk
);
429 clk_get_rate(i2s
->op_clk
);
434 i2s
->op_clk
= clk_get(&i2s
->pdev
->dev
,
435 i2s
->src_clk
[clk_id
]);
436 clk_enable(i2s
->op_clk
);
437 i2s
->rclk_srcrate
= clk_get_rate(i2s
->op_clk
);
439 /* Over-ride the other's */
441 other
->op_clk
= i2s
->op_clk
;
442 other
->rclk_srcrate
= i2s
->rclk_srcrate
;
444 } else if ((!clk_id
&& (mod
& MOD_IMS_SYSMUX
))
445 || (clk_id
&& !(mod
& MOD_IMS_SYSMUX
))) {
446 dev_err(&i2s
->pdev
->dev
,
447 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
450 /* Call can't be on the active DAI */
451 i2s
->op_clk
= other
->op_clk
;
452 i2s
->rclk_srcrate
= other
->rclk_srcrate
;
457 mod
&= ~MOD_IMS_SYSMUX
;
459 mod
|= MOD_IMS_SYSMUX
;
463 dev_err(&i2s
->pdev
->dev
, "We don't serve that!\n");
467 writel(mod
, i2s
->addr
+ I2SMOD
);
472 static int i2s_set_fmt(struct snd_soc_dai
*dai
,
475 struct i2s_dai
*i2s
= to_info(dai
);
476 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
479 /* Format is priority */
480 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
481 case SND_SOC_DAIFMT_RIGHT_J
:
485 case SND_SOC_DAIFMT_LEFT_J
:
489 case SND_SOC_DAIFMT_I2S
:
493 dev_err(&i2s
->pdev
->dev
, "Format not supported\n");
498 * INV flag is relative to the FORMAT flag - if set it simply
499 * flips the polarity specified by the Standard
501 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
502 case SND_SOC_DAIFMT_NB_NF
:
504 case SND_SOC_DAIFMT_NB_IF
:
505 if (tmp
& MOD_LR_RLOW
)
511 dev_err(&i2s
->pdev
->dev
, "Polarity not supported\n");
515 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
516 case SND_SOC_DAIFMT_CBM_CFM
:
519 case SND_SOC_DAIFMT_CBS_CFS
:
520 /* Set default source clock in Master mode */
521 if (i2s
->rclk_srcrate
== 0)
522 i2s_set_sysclk(dai
, SAMSUNG_I2S_RCLKSRC_0
,
523 0, SND_SOC_CLOCK_IN
);
526 dev_err(&i2s
->pdev
->dev
, "master/slave format not supported\n");
530 if (any_active(i2s
) &&
531 ((mod
& (MOD_SDF_MASK
| MOD_LR_RLOW
532 | MOD_SLAVE
)) != tmp
)) {
533 dev_err(&i2s
->pdev
->dev
,
534 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
538 mod
&= ~(MOD_SDF_MASK
| MOD_LR_RLOW
| MOD_SLAVE
);
540 writel(mod
, i2s
->addr
+ I2SMOD
);
545 static int i2s_hw_params(struct snd_pcm_substream
*substream
,
546 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
548 struct i2s_dai
*i2s
= to_info(dai
);
549 u32 mod
= readl(i2s
->addr
+ I2SMOD
);
551 if (!is_secondary(i2s
))
552 mod
&= ~(MOD_DC2_EN
| MOD_DC1_EN
);
554 switch (params_channels(params
)) {
563 dev_err(&i2s
->pdev
->dev
, "%d channels not supported\n",
564 params_channels(params
));
568 if (is_secondary(i2s
))
569 mod
&= ~MOD_BLCS_MASK
;
571 mod
&= ~MOD_BLCP_MASK
;
574 mod
&= ~MOD_BLC_MASK
;
576 switch (params_format(params
)) {
577 case SNDRV_PCM_FORMAT_S8
:
578 if (is_secondary(i2s
))
579 mod
|= MOD_BLCS_8BIT
;
581 mod
|= MOD_BLCP_8BIT
;
585 case SNDRV_PCM_FORMAT_S16_LE
:
586 if (is_secondary(i2s
))
587 mod
|= MOD_BLCS_16BIT
;
589 mod
|= MOD_BLCP_16BIT
;
591 mod
|= MOD_BLC_16BIT
;
593 case SNDRV_PCM_FORMAT_S24_LE
:
594 if (is_secondary(i2s
))
595 mod
|= MOD_BLCS_24BIT
;
597 mod
|= MOD_BLCP_24BIT
;
599 mod
|= MOD_BLC_24BIT
;
602 dev_err(&i2s
->pdev
->dev
, "Format(%d) not supported\n",
603 params_format(params
));
606 writel(mod
, i2s
->addr
+ I2SMOD
);
608 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
609 snd_soc_dai_set_dma_data(dai
, substream
,
610 (void *)&i2s
->dma_playback
);
612 snd_soc_dai_set_dma_data(dai
, substream
,
613 (void *)&i2s
->dma_capture
);
615 i2s
->frmclk
= params_rate(params
);
620 /* We set constraints on the substream acc to the version of I2S */
621 static int i2s_startup(struct snd_pcm_substream
*substream
,
622 struct snd_soc_dai
*dai
)
624 struct i2s_dai
*i2s
= to_info(dai
);
625 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
628 spin_lock_irqsave(&lock
, flags
);
630 i2s
->mode
|= DAI_OPENED
;
632 if (is_manager(other
))
633 i2s
->mode
&= ~DAI_MANAGER
;
635 i2s
->mode
|= DAI_MANAGER
;
637 /* Enforce set_sysclk in Master mode */
638 i2s
->rclk_srcrate
= 0;
640 spin_unlock_irqrestore(&lock
, flags
);
645 static void i2s_shutdown(struct snd_pcm_substream
*substream
,
646 struct snd_soc_dai
*dai
)
648 struct i2s_dai
*i2s
= to_info(dai
);
649 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
652 spin_lock_irqsave(&lock
, flags
);
654 i2s
->mode
&= ~DAI_OPENED
;
655 i2s
->mode
&= ~DAI_MANAGER
;
657 if (is_opened(other
))
658 other
->mode
|= DAI_MANAGER
;
660 /* Reset any constraint on RFS and BFS */
664 spin_unlock_irqrestore(&lock
, flags
);
666 /* Gate CDCLK by default */
667 if (!is_opened(other
))
668 i2s_set_sysclk(dai
, SAMSUNG_I2S_CDCLK
,
669 0, SND_SOC_CLOCK_IN
);
672 static int config_setup(struct i2s_dai
*i2s
)
674 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
675 unsigned rfs
, bfs
, blc
;
685 /* Select least possible multiple(2) if no constraint set */
694 if ((rfs
== 256 || rfs
== 512) && (blc
== 24)) {
695 dev_err(&i2s
->pdev
->dev
,
696 "%d-RFS not supported for 24-blc\n", rfs
);
701 if (bfs
== 16 || bfs
== 32)
707 /* If already setup and running */
708 if (any_active(i2s
) && (get_rfs(i2s
) != rfs
|| get_bfs(i2s
) != bfs
)) {
709 dev_err(&i2s
->pdev
->dev
,
710 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
714 /* Don't bother RFS, BFS & PSR in Slave mode */
721 if (!(i2s
->quirks
& QUIRK_NO_MUXPSR
)) {
722 psr
= i2s
->rclk_srcrate
/ i2s
->frmclk
/ rfs
;
723 writel(((psr
- 1) << 8) | PSR_PSREN
, i2s
->addr
+ I2SPSR
);
724 dev_dbg(&i2s
->pdev
->dev
,
725 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
726 i2s
->rclk_srcrate
, psr
, rfs
, bfs
);
732 static int i2s_trigger(struct snd_pcm_substream
*substream
,
733 int cmd
, struct snd_soc_dai
*dai
)
735 int capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
736 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
737 struct i2s_dai
*i2s
= to_info(rtd
->cpu_dai
);
741 case SNDRV_PCM_TRIGGER_START
:
742 case SNDRV_PCM_TRIGGER_RESUME
:
743 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
744 local_irq_save(flags
);
746 if (config_setup(i2s
)) {
747 local_irq_restore(flags
);
756 local_irq_restore(flags
);
758 case SNDRV_PCM_TRIGGER_STOP
:
759 case SNDRV_PCM_TRIGGER_SUSPEND
:
760 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
761 local_irq_save(flags
);
769 i2s_fifo(i2s
, FIC_RXFLUSH
);
771 i2s_fifo(i2s
, FIC_TXFLUSH
);
773 local_irq_restore(flags
);
780 static int i2s_set_clkdiv(struct snd_soc_dai
*dai
,
783 struct i2s_dai
*i2s
= to_info(dai
);
784 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
787 case SAMSUNG_I2S_DIV_BCLK
:
788 if ((any_active(i2s
) && div
&& (get_bfs(i2s
) != div
))
789 || (other
&& other
->bfs
&& (other
->bfs
!= div
))) {
790 dev_err(&i2s
->pdev
->dev
,
791 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
797 dev_err(&i2s
->pdev
->dev
,
798 "Invalid clock divider(%d)\n", div_id
);
805 static snd_pcm_sframes_t
806 i2s_delay(struct snd_pcm_substream
*substream
, struct snd_soc_dai
*dai
)
808 struct i2s_dai
*i2s
= to_info(dai
);
809 u32 reg
= readl(i2s
->addr
+ I2SFIC
);
810 snd_pcm_sframes_t delay
;
812 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
813 delay
= FIC_RXCOUNT(reg
);
814 else if (is_secondary(i2s
))
815 delay
= FICS_TXCOUNT(readl(i2s
->addr
+ I2SFICS
));
817 delay
= FIC_TXCOUNT(reg
);
823 static int i2s_suspend(struct snd_soc_dai
*dai
)
825 struct i2s_dai
*i2s
= to_info(dai
);
828 i2s
->suspend_i2smod
= readl(i2s
->addr
+ I2SMOD
);
829 i2s
->suspend_i2scon
= readl(i2s
->addr
+ I2SCON
);
830 i2s
->suspend_i2spsr
= readl(i2s
->addr
+ I2SPSR
);
836 static int i2s_resume(struct snd_soc_dai
*dai
)
838 struct i2s_dai
*i2s
= to_info(dai
);
841 writel(i2s
->suspend_i2scon
, i2s
->addr
+ I2SCON
);
842 writel(i2s
->suspend_i2smod
, i2s
->addr
+ I2SMOD
);
843 writel(i2s
->suspend_i2spsr
, i2s
->addr
+ I2SPSR
);
849 #define i2s_suspend NULL
850 #define i2s_resume NULL
853 static int samsung_i2s_dai_probe(struct snd_soc_dai
*dai
)
855 struct i2s_dai
*i2s
= to_info(dai
);
856 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
858 if (other
&& other
->clk
) /* If this is probe on secondary */
861 i2s
->addr
= ioremap(i2s
->base
, 0x100);
862 if (i2s
->addr
== NULL
) {
863 dev_err(&i2s
->pdev
->dev
, "cannot ioremap registers\n");
867 i2s
->clk
= clk_get(&i2s
->pdev
->dev
, "iis");
868 if (IS_ERR(i2s
->clk
)) {
869 dev_err(&i2s
->pdev
->dev
, "failed to get i2s_clock\n");
873 clk_enable(i2s
->clk
);
876 other
->addr
= i2s
->addr
;
877 other
->clk
= i2s
->clk
;
880 if (i2s
->quirks
& QUIRK_NEED_RSTCLR
)
881 writel(CON_RSTCLR
, i2s
->addr
+ I2SCON
);
883 if (i2s
->quirks
& QUIRK_SEC_DAI
)
884 idma_reg_addr_init((void *)i2s
->addr
,
885 i2s
->sec_dai
->idma_playback
.dma_addr
);
888 /* Reset any constraint on RFS and BFS */
893 i2s_fifo(i2s
, FIC_TXFLUSH
);
894 i2s_fifo(other
, FIC_TXFLUSH
);
895 i2s_fifo(i2s
, FIC_RXFLUSH
);
897 /* Gate CDCLK by default */
898 if (!is_opened(other
))
899 i2s_set_sysclk(dai
, SAMSUNG_I2S_CDCLK
,
900 0, SND_SOC_CLOCK_IN
);
905 static int samsung_i2s_dai_remove(struct snd_soc_dai
*dai
)
907 struct i2s_dai
*i2s
= snd_soc_dai_get_drvdata(dai
);
908 struct i2s_dai
*other
= i2s
->pri_dai
? : i2s
->sec_dai
;
910 if (!other
|| !other
->clk
) {
912 if (i2s
->quirks
& QUIRK_NEED_RSTCLR
)
913 writel(0, i2s
->addr
+ I2SCON
);
915 clk_disable(i2s
->clk
);
926 static struct snd_soc_dai_ops samsung_i2s_dai_ops
= {
927 .trigger
= i2s_trigger
,
928 .hw_params
= i2s_hw_params
,
929 .set_fmt
= i2s_set_fmt
,
930 .set_clkdiv
= i2s_set_clkdiv
,
931 .set_sysclk
= i2s_set_sysclk
,
932 .startup
= i2s_startup
,
933 .shutdown
= i2s_shutdown
,
937 #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
939 #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
940 SNDRV_PCM_FMTBIT_S16_LE | \
941 SNDRV_PCM_FMTBIT_S24_LE)
944 struct i2s_dai
*i2s_alloc_dai(struct platform_device
*pdev
, bool sec
)
948 i2s
= kzalloc(sizeof(struct i2s_dai
), GFP_KERNEL
);
955 i2s
->i2s_dai_drv
.symmetric_rates
= 1;
956 i2s
->i2s_dai_drv
.probe
= samsung_i2s_dai_probe
;
957 i2s
->i2s_dai_drv
.remove
= samsung_i2s_dai_remove
;
958 i2s
->i2s_dai_drv
.ops
= &samsung_i2s_dai_ops
;
959 i2s
->i2s_dai_drv
.suspend
= i2s_suspend
;
960 i2s
->i2s_dai_drv
.resume
= i2s_resume
;
961 i2s
->i2s_dai_drv
.playback
.channels_min
= 2;
962 i2s
->i2s_dai_drv
.playback
.channels_max
= 2;
963 i2s
->i2s_dai_drv
.playback
.rates
= SAMSUNG_I2S_RATES
;
964 i2s
->i2s_dai_drv
.playback
.formats
= SAMSUNG_I2S_FMTS
;
967 i2s
->i2s_dai_drv
.capture
.channels_min
= 2;
968 i2s
->i2s_dai_drv
.capture
.channels_max
= 2;
969 i2s
->i2s_dai_drv
.capture
.rates
= SAMSUNG_I2S_RATES
;
970 i2s
->i2s_dai_drv
.capture
.formats
= SAMSUNG_I2S_FMTS
;
971 } else { /* Create a new platform_device for Secondary */
972 i2s
->pdev
= platform_device_register_resndata(NULL
,
973 pdev
->name
, pdev
->id
+ SAMSUNG_I2S_SECOFF
,
975 if (IS_ERR(i2s
->pdev
)) {
981 /* Pre-assign snd_soc_dai_set_drvdata */
982 dev_set_drvdata(&i2s
->pdev
->dev
, i2s
);
987 static __devinit
int samsung_i2s_probe(struct platform_device
*pdev
)
989 u32 dma_pl_chan
, dma_cp_chan
, dma_pl_sec_chan
;
990 struct i2s_dai
*pri_dai
, *sec_dai
= NULL
;
991 struct s3c_audio_pdata
*i2s_pdata
;
992 struct samsung_i2s
*i2s_cfg
;
993 struct resource
*res
;
994 u32 regs_base
, quirks
;
997 /* Call during Seconday interface registration */
998 if (pdev
->id
>= SAMSUNG_I2S_SECOFF
) {
999 sec_dai
= dev_get_drvdata(&pdev
->dev
);
1000 snd_soc_register_dai(&sec_dai
->pdev
->dev
,
1001 &sec_dai
->i2s_dai_drv
);
1005 i2s_pdata
= pdev
->dev
.platform_data
;
1006 if (i2s_pdata
== NULL
) {
1007 dev_err(&pdev
->dev
, "Can't work without s3c_audio_pdata\n");
1011 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 0);
1013 dev_err(&pdev
->dev
, "Unable to get I2S-TX dma resource\n");
1016 dma_pl_chan
= res
->start
;
1018 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 1);
1020 dev_err(&pdev
->dev
, "Unable to get I2S-RX dma resource\n");
1023 dma_cp_chan
= res
->start
;
1025 res
= platform_get_resource(pdev
, IORESOURCE_DMA
, 2);
1027 dma_pl_sec_chan
= res
->start
;
1029 dma_pl_sec_chan
= 0;
1031 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1033 dev_err(&pdev
->dev
, "Unable to get I2S SFR address\n");
1037 if (!request_mem_region(res
->start
, resource_size(res
),
1039 dev_err(&pdev
->dev
, "Unable to request SFR region\n");
1042 regs_base
= res
->start
;
1044 i2s_cfg
= &i2s_pdata
->type
.i2s
;
1045 quirks
= i2s_cfg
->quirks
;
1047 pri_dai
= i2s_alloc_dai(pdev
, false);
1049 dev_err(&pdev
->dev
, "Unable to alloc I2S_pri\n");
1054 pri_dai
->dma_playback
.dma_addr
= regs_base
+ I2STXD
;
1055 pri_dai
->dma_capture
.dma_addr
= regs_base
+ I2SRXD
;
1056 pri_dai
->dma_playback
.client
=
1057 (struct s3c2410_dma_client
*)&pri_dai
->dma_playback
;
1058 pri_dai
->dma_capture
.client
=
1059 (struct s3c2410_dma_client
*)&pri_dai
->dma_capture
;
1060 pri_dai
->dma_playback
.channel
= dma_pl_chan
;
1061 pri_dai
->dma_capture
.channel
= dma_cp_chan
;
1062 pri_dai
->src_clk
= i2s_cfg
->src_clk
;
1063 pri_dai
->dma_playback
.dma_size
= 4;
1064 pri_dai
->dma_capture
.dma_size
= 4;
1065 pri_dai
->base
= regs_base
;
1066 pri_dai
->quirks
= quirks
;
1068 if (quirks
& QUIRK_PRI_6CHAN
)
1069 pri_dai
->i2s_dai_drv
.playback
.channels_max
= 6;
1071 if (quirks
& QUIRK_SEC_DAI
) {
1072 sec_dai
= i2s_alloc_dai(pdev
, true);
1074 dev_err(&pdev
->dev
, "Unable to alloc I2S_sec\n");
1078 sec_dai
->dma_playback
.dma_addr
= regs_base
+ I2STXDS
;
1079 sec_dai
->dma_playback
.client
=
1080 (struct s3c2410_dma_client
*)&sec_dai
->dma_playback
;
1081 /* Use iDMA always if SysDMA not provided */
1082 sec_dai
->dma_playback
.channel
= dma_pl_sec_chan
? : -1;
1083 sec_dai
->src_clk
= i2s_cfg
->src_clk
;
1084 sec_dai
->dma_playback
.dma_size
= 4;
1085 sec_dai
->base
= regs_base
;
1086 sec_dai
->quirks
= quirks
;
1087 sec_dai
->idma_playback
.dma_addr
= i2s_cfg
->idma_addr
;
1088 sec_dai
->pri_dai
= pri_dai
;
1089 pri_dai
->sec_dai
= sec_dai
;
1092 if (i2s_pdata
->cfg_gpio
&& i2s_pdata
->cfg_gpio(pdev
)) {
1093 dev_err(&pdev
->dev
, "Unable to configure gpio\n");
1098 snd_soc_register_dai(&pri_dai
->pdev
->dev
, &pri_dai
->i2s_dai_drv
);
1106 release_mem_region(regs_base
, resource_size(res
));
1111 static __devexit
int samsung_i2s_remove(struct platform_device
*pdev
)
1113 struct i2s_dai
*i2s
, *other
;
1115 i2s
= dev_get_drvdata(&pdev
->dev
);
1116 other
= i2s
->pri_dai
? : i2s
->sec_dai
;
1119 other
->pri_dai
= NULL
;
1120 other
->sec_dai
= NULL
;
1122 struct resource
*res
;
1123 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1125 release_mem_region(res
->start
, resource_size(res
));
1128 i2s
->pri_dai
= NULL
;
1129 i2s
->sec_dai
= NULL
;
1133 snd_soc_unregister_dai(&pdev
->dev
);
1138 static struct platform_driver samsung_i2s_driver
= {
1139 .probe
= samsung_i2s_probe
,
1140 .remove
= __devexit_p(samsung_i2s_remove
),
1142 .name
= "samsung-i2s",
1143 .owner
= THIS_MODULE
,
1147 static int __init
samsung_i2s_init(void)
1149 return platform_driver_register(&samsung_i2s_driver
);
1151 module_init(samsung_i2s_init
);
1153 static void __exit
samsung_i2s_exit(void)
1155 platform_driver_unregister(&samsung_i2s_driver
);
1157 module_exit(samsung_i2s_exit
);
1159 /* Module information */
1160 MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
1161 MODULE_DESCRIPTION("Samsung I2S Interface");
1162 MODULE_ALIAS("platform:samsung-i2s");
1163 MODULE_LICENSE("GPL");