1 // SPDX-License-Identifier: GPL-2.0
3 // ALSA SoC Audio Layer - Samsung I2S Controller driver
5 // Copyright (c) 2010 Samsung Electronics Co. Ltd.
6 // Jaswinder Singh <jassisinghbrar@gmail.com>
8 #include <dt-bindings/sound/samsung-i2s.h>
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/clk.h>
12 #include <linux/clk-provider.h>
14 #include <linux/module.h>
16 #include <linux/of_device.h>
17 #include <linux/of_gpio.h>
18 #include <linux/pm_runtime.h>
20 #include <sound/soc.h>
21 #include <sound/pcm_params.h>
23 #include <linux/platform_data/asoc-s3c.h>
30 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
32 #define SAMSUNG_I2S_ID_PRIMARY 1
33 #define SAMSUNG_I2S_ID_SECONDARY 2
35 struct samsung_i2s_variant_regs
{
40 unsigned int rclksrc_off
;
42 unsigned int cdclkcon_off
;
44 unsigned int bfs_mask
;
45 unsigned int rfs_mask
;
46 unsigned int ftx0cnt_off
;
49 struct samsung_i2s_dai_data
{
51 unsigned int pcm_rates
;
52 const struct samsung_i2s_variant_regs
*i2s_variant_regs
;
56 /* Platform device for this DAI */
57 struct platform_device
*pdev
;
62 * Specifically requested RCLK, BCLK by machine driver.
63 * 0 indicates CPU driver is free to choose any value.
66 /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
67 struct i2s_dai
*pri_dai
;
68 /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
69 struct i2s_dai
*sec_dai
;
71 #define DAI_OPENED (1 << 0) /* DAI is opened */
72 #define DAI_MANAGER (1 << 1) /* DAI is the manager */
75 /* Driver for this DAI */
76 struct snd_soc_dai_driver
*drv
;
79 struct snd_dmaengine_dai_dma_data dma_playback
;
80 struct snd_dmaengine_dai_dma_data dma_capture
;
81 struct snd_dmaengine_dai_dma_data idma_playback
;
84 struct samsung_i2s_priv
*priv
;
87 struct samsung_i2s_priv
{
88 struct platform_device
*pdev
;
89 struct platform_device
*pdev_sec
;
91 /* Lock for cross interface checks */
94 /* CPU DAIs and their corresponding drivers */
96 struct snd_soc_dai_driver
*dai_drv
;
99 /* The I2S controller's core clock */
102 /* Clock for generating I2S signals */
105 /* Rate of RCLK source clock */
106 unsigned long rclk_srcrate
;
108 /* Cache of selected I2S registers for system suspend */
113 const struct samsung_i2s_variant_regs
*variant_regs
;
116 /* The clock provider's data */
117 struct clk
*clk_table
[3];
118 struct clk_onecell_data clk_data
;
120 /* Spinlock protecting member fields below */
123 /* Memory mapped SFR region */
126 /* A flag indicating the I2S slave mode operation */
130 /* Returns true if this is the 'overlay' stereo DAI */
131 static inline bool is_secondary(struct i2s_dai
*i2s
)
133 return i2s
->drv
->id
== SAMSUNG_I2S_ID_SECONDARY
;
136 /* If this interface of the controller is transmitting data */
137 static inline bool tx_active(struct i2s_dai
*i2s
)
144 active
= readl(i2s
->priv
->addr
+ I2SCON
);
146 if (is_secondary(i2s
))
147 active
&= CON_TXSDMA_ACTIVE
;
149 active
&= CON_TXDMA_ACTIVE
;
151 return active
? true : false;
154 /* Return pointer to the other DAI */
155 static inline struct i2s_dai
*get_other_dai(struct i2s_dai
*i2s
)
157 return i2s
->pri_dai
? : i2s
->sec_dai
;
160 /* If the other interface of the controller is transmitting data */
161 static inline bool other_tx_active(struct i2s_dai
*i2s
)
163 struct i2s_dai
*other
= get_other_dai(i2s
);
165 return tx_active(other
);
168 /* If any interface of the controller is transmitting data */
169 static inline bool any_tx_active(struct i2s_dai
*i2s
)
171 return tx_active(i2s
) || other_tx_active(i2s
);
174 /* If this interface of the controller is receiving data */
175 static inline bool rx_active(struct i2s_dai
*i2s
)
182 active
= readl(i2s
->priv
->addr
+ I2SCON
) & CON_RXDMA_ACTIVE
;
184 return active
? true : false;
187 /* If the other interface of the controller is receiving data */
188 static inline bool other_rx_active(struct i2s_dai
*i2s
)
190 struct i2s_dai
*other
= get_other_dai(i2s
);
192 return rx_active(other
);
195 /* If any interface of the controller is receiving data */
196 static inline bool any_rx_active(struct i2s_dai
*i2s
)
198 return rx_active(i2s
) || other_rx_active(i2s
);
201 /* If the other DAI is transmitting or receiving data */
202 static inline bool other_active(struct i2s_dai
*i2s
)
204 return other_rx_active(i2s
) || other_tx_active(i2s
);
207 /* If this DAI is transmitting or receiving data */
208 static inline bool this_active(struct i2s_dai
*i2s
)
210 return tx_active(i2s
) || rx_active(i2s
);
213 /* If the controller is active anyway */
214 static inline bool any_active(struct i2s_dai
*i2s
)
216 return this_active(i2s
) || other_active(i2s
);
219 static inline struct i2s_dai
*to_info(struct snd_soc_dai
*dai
)
221 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
223 return &priv
->dai
[dai
->id
- 1];
226 static inline bool is_opened(struct i2s_dai
*i2s
)
228 if (i2s
&& (i2s
->mode
& DAI_OPENED
))
234 static inline bool is_manager(struct i2s_dai
*i2s
)
236 if (is_opened(i2s
) && (i2s
->mode
& DAI_MANAGER
))
242 /* Read RCLK of I2S (in multiples of LRCLK) */
243 static inline unsigned get_rfs(struct i2s_dai
*i2s
)
245 struct samsung_i2s_priv
*priv
= i2s
->priv
;
248 rfs
= readl(priv
->addr
+ I2SMOD
) >> priv
->variant_regs
->rfs_off
;
249 rfs
&= priv
->variant_regs
->rfs_mask
;
263 /* Write RCLK of I2S (in multiples of LRCLK) */
264 static inline void set_rfs(struct i2s_dai
*i2s
, unsigned rfs
)
266 struct samsung_i2s_priv
*priv
= i2s
->priv
;
267 u32 mod
= readl(priv
->addr
+ I2SMOD
);
268 int rfs_shift
= priv
->variant_regs
->rfs_off
;
270 mod
&= ~(priv
->variant_regs
->rfs_mask
<< rfs_shift
);
274 mod
|= (EXYNOS7_MOD_RCLK_192FS
<< rfs_shift
);
277 mod
|= (EXYNOS7_MOD_RCLK_96FS
<< rfs_shift
);
280 mod
|= (EXYNOS7_MOD_RCLK_128FS
<< rfs_shift
);
283 mod
|= (EXYNOS7_MOD_RCLK_64FS
<< rfs_shift
);
286 mod
|= (MOD_RCLK_768FS
<< rfs_shift
);
289 mod
|= (MOD_RCLK_512FS
<< rfs_shift
);
292 mod
|= (MOD_RCLK_384FS
<< rfs_shift
);
295 mod
|= (MOD_RCLK_256FS
<< rfs_shift
);
299 writel(mod
, priv
->addr
+ I2SMOD
);
302 /* Read bit-clock of I2S (in multiples of LRCLK) */
303 static inline unsigned get_bfs(struct i2s_dai
*i2s
)
305 struct samsung_i2s_priv
*priv
= i2s
->priv
;
308 bfs
= readl(priv
->addr
+ I2SMOD
) >> priv
->variant_regs
->bfs_off
;
309 bfs
&= priv
->variant_regs
->bfs_mask
;
324 /* Write bit-clock of I2S (in multiples of LRCLK) */
325 static inline void set_bfs(struct i2s_dai
*i2s
, unsigned bfs
)
327 struct samsung_i2s_priv
*priv
= i2s
->priv
;
328 u32 mod
= readl(priv
->addr
+ I2SMOD
);
329 int tdm
= priv
->quirks
& QUIRK_SUPPORTS_TDM
;
330 int bfs_shift
= priv
->variant_regs
->bfs_off
;
332 /* Non-TDM I2S controllers do not support BCLK > 48 * FS */
333 if (!tdm
&& bfs
> 48) {
334 dev_err(&i2s
->pdev
->dev
, "Unsupported BCLK divider\n");
338 mod
&= ~(priv
->variant_regs
->bfs_mask
<< bfs_shift
);
342 mod
|= (MOD_BCLK_48FS
<< bfs_shift
);
345 mod
|= (MOD_BCLK_32FS
<< bfs_shift
);
348 mod
|= (MOD_BCLK_24FS
<< bfs_shift
);
351 mod
|= (MOD_BCLK_16FS
<< bfs_shift
);
354 mod
|= (EXYNOS5420_MOD_BCLK_64FS
<< bfs_shift
);
357 mod
|= (EXYNOS5420_MOD_BCLK_96FS
<< bfs_shift
);
360 mod
|= (EXYNOS5420_MOD_BCLK_128FS
<< bfs_shift
);
363 mod
|= (EXYNOS5420_MOD_BCLK_192FS
<< bfs_shift
);
366 mod
|= (EXYNOS5420_MOD_BCLK_256FS
<< bfs_shift
);
369 dev_err(&i2s
->pdev
->dev
, "Wrong BCLK Divider!\n");
373 writel(mod
, priv
->addr
+ I2SMOD
);
377 static inline int get_blc(struct i2s_dai
*i2s
)
379 int blc
= readl(i2s
->priv
->addr
+ I2SMOD
);
381 blc
= (blc
>> 13) & 0x3;
390 /* TX channel control */
391 static void i2s_txctrl(struct i2s_dai
*i2s
, int on
)
393 struct samsung_i2s_priv
*priv
= i2s
->priv
;
394 void __iomem
*addr
= priv
->addr
;
395 int txr_off
= priv
->variant_regs
->txr_off
;
396 u32 con
= readl(addr
+ I2SCON
);
397 u32 mod
= readl(addr
+ I2SMOD
) & ~(3 << txr_off
);
401 con
&= ~CON_TXCH_PAUSE
;
403 if (is_secondary(i2s
)) {
404 con
|= CON_TXSDMA_ACTIVE
;
405 con
&= ~CON_TXSDMA_PAUSE
;
407 con
|= CON_TXDMA_ACTIVE
;
408 con
&= ~CON_TXDMA_PAUSE
;
411 if (any_rx_active(i2s
))
416 if (is_secondary(i2s
)) {
417 con
|= CON_TXSDMA_PAUSE
;
418 con
&= ~CON_TXSDMA_ACTIVE
;
420 con
|= CON_TXDMA_PAUSE
;
421 con
&= ~CON_TXDMA_ACTIVE
;
424 if (other_tx_active(i2s
)) {
425 writel(con
, addr
+ I2SCON
);
429 con
|= CON_TXCH_PAUSE
;
431 if (any_rx_active(i2s
))
437 writel(mod
, addr
+ I2SMOD
);
438 writel(con
, addr
+ I2SCON
);
441 /* RX Channel Control */
442 static void i2s_rxctrl(struct i2s_dai
*i2s
, int on
)
444 struct samsung_i2s_priv
*priv
= i2s
->priv
;
445 void __iomem
*addr
= priv
->addr
;
446 int txr_off
= priv
->variant_regs
->txr_off
;
447 u32 con
= readl(addr
+ I2SCON
);
448 u32 mod
= readl(addr
+ I2SMOD
) & ~(3 << txr_off
);
451 con
|= CON_RXDMA_ACTIVE
| CON_ACTIVE
;
452 con
&= ~(CON_RXDMA_PAUSE
| CON_RXCH_PAUSE
);
454 if (any_tx_active(i2s
))
459 con
|= CON_RXDMA_PAUSE
| CON_RXCH_PAUSE
;
460 con
&= ~CON_RXDMA_ACTIVE
;
462 if (any_tx_active(i2s
))
468 writel(mod
, addr
+ I2SMOD
);
469 writel(con
, addr
+ I2SCON
);
472 /* Flush FIFO of an interface */
473 static inline void i2s_fifo(struct i2s_dai
*i2s
, u32 flush
)
481 if (is_secondary(i2s
))
482 fic
= i2s
->priv
->addr
+ I2SFICS
;
484 fic
= i2s
->priv
->addr
+ I2SFIC
;
487 writel(readl(fic
) | flush
, fic
);
490 val
= msecs_to_loops(1) / 1000; /* 1 usec */
494 writel(readl(fic
) & ~flush
, fic
);
497 static int i2s_set_sysclk(struct snd_soc_dai
*dai
, int clk_id
, unsigned int rfs
,
500 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
501 struct i2s_dai
*i2s
= to_info(dai
);
502 struct i2s_dai
*other
= get_other_dai(i2s
);
503 const struct samsung_i2s_variant_regs
*i2s_regs
= priv
->variant_regs
;
504 unsigned int cdcon_mask
= 1 << i2s_regs
->cdclkcon_off
;
505 unsigned int rsrc_mask
= 1 << i2s_regs
->rclksrc_off
;
506 u32 mod
, mask
, val
= 0;
510 pm_runtime_get_sync(dai
->dev
);
512 spin_lock_irqsave(&priv
->lock
, flags
);
513 mod
= readl(priv
->addr
+ I2SMOD
);
514 spin_unlock_irqrestore(&priv
->lock
, flags
);
517 case SAMSUNG_I2S_OPCLK
:
518 mask
= MOD_OPCLK_MASK
;
519 val
= (dir
<< MOD_OPCLK_SHIFT
) & MOD_OPCLK_MASK
;
521 case SAMSUNG_I2S_CDCLK
:
522 mask
= 1 << i2s_regs
->cdclkcon_off
;
523 /* Shouldn't matter in GATING(CLOCK_IN) mode */
524 if (dir
== SND_SOC_CLOCK_IN
)
527 if ((rfs
&& other
&& other
->rfs
&& (other
->rfs
!= rfs
)) ||
529 (((dir
== SND_SOC_CLOCK_IN
)
530 && !(mod
& cdcon_mask
)) ||
531 ((dir
== SND_SOC_CLOCK_OUT
)
532 && (mod
& cdcon_mask
))))) {
533 dev_err(&i2s
->pdev
->dev
,
534 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
539 if (dir
== SND_SOC_CLOCK_IN
)
540 val
= 1 << i2s_regs
->cdclkcon_off
;
545 case SAMSUNG_I2S_RCLKSRC_0
: /* clock corrsponding to IISMOD[10] := 0 */
546 case SAMSUNG_I2S_RCLKSRC_1
: /* clock corrsponding to IISMOD[10] := 1 */
547 mask
= 1 << i2s_regs
->rclksrc_off
;
549 if ((priv
->quirks
& QUIRK_NO_MUXPSR
)
550 || (clk_id
== SAMSUNG_I2S_RCLKSRC_0
))
555 if (!any_active(i2s
)) {
556 if (priv
->op_clk
&& !IS_ERR(priv
->op_clk
)) {
557 if ((clk_id
&& !(mod
& rsrc_mask
)) ||
558 (!clk_id
&& (mod
& rsrc_mask
))) {
559 clk_disable_unprepare(priv
->op_clk
);
560 clk_put(priv
->op_clk
);
563 clk_get_rate(priv
->op_clk
);
569 priv
->op_clk
= clk_get(&i2s
->pdev
->dev
,
572 priv
->op_clk
= clk_get(&i2s
->pdev
->dev
,
575 if (WARN_ON(IS_ERR(priv
->op_clk
))) {
576 ret
= PTR_ERR(priv
->op_clk
);
581 ret
= clk_prepare_enable(priv
->op_clk
);
583 clk_put(priv
->op_clk
);
587 priv
->rclk_srcrate
= clk_get_rate(priv
->op_clk
);
589 } else if ((!clk_id
&& (mod
& rsrc_mask
))
590 || (clk_id
&& !(mod
& rsrc_mask
))) {
591 dev_err(&i2s
->pdev
->dev
,
592 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
596 /* Call can't be on the active DAI */
601 val
= 1 << i2s_regs
->rclksrc_off
;
604 dev_err(&i2s
->pdev
->dev
, "We don't serve that!\n");
609 spin_lock_irqsave(&priv
->lock
, flags
);
610 mod
= readl(priv
->addr
+ I2SMOD
);
611 mod
= (mod
& ~mask
) | val
;
612 writel(mod
, priv
->addr
+ I2SMOD
);
613 spin_unlock_irqrestore(&priv
->lock
, flags
);
615 pm_runtime_put(dai
->dev
);
619 pm_runtime_put(dai
->dev
);
623 static int i2s_set_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
625 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
626 struct i2s_dai
*i2s
= to_info(dai
);
627 int lrp_shift
, sdf_shift
, sdf_mask
, lrp_rlow
, mod_slave
;
631 lrp_shift
= priv
->variant_regs
->lrp_off
;
632 sdf_shift
= priv
->variant_regs
->sdf_off
;
633 mod_slave
= 1 << priv
->variant_regs
->mss_off
;
635 sdf_mask
= MOD_SDF_MASK
<< sdf_shift
;
636 lrp_rlow
= MOD_LR_RLOW
<< lrp_shift
;
638 /* Format is priority */
639 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
640 case SND_SOC_DAIFMT_RIGHT_J
:
642 tmp
|= (MOD_SDF_MSB
<< sdf_shift
);
644 case SND_SOC_DAIFMT_LEFT_J
:
646 tmp
|= (MOD_SDF_LSB
<< sdf_shift
);
648 case SND_SOC_DAIFMT_I2S
:
649 tmp
|= (MOD_SDF_IIS
<< sdf_shift
);
652 dev_err(&i2s
->pdev
->dev
, "Format not supported\n");
657 * INV flag is relative to the FORMAT flag - if set it simply
658 * flips the polarity specified by the Standard
660 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
661 case SND_SOC_DAIFMT_NB_NF
:
663 case SND_SOC_DAIFMT_NB_IF
:
670 dev_err(&i2s
->pdev
->dev
, "Polarity not supported\n");
674 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
675 case SND_SOC_DAIFMT_CBM_CFM
:
678 case SND_SOC_DAIFMT_CBS_CFS
:
680 * Set default source clock in Master mode, only when the
681 * CLK_I2S_RCLK_SRC clock is not exposed so we ensure any
682 * clock configuration assigned in DT is not overwritten.
684 if (priv
->rclk_srcrate
== 0 && priv
->clk_data
.clks
== NULL
)
685 i2s_set_sysclk(dai
, SAMSUNG_I2S_RCLKSRC_0
,
686 0, SND_SOC_CLOCK_IN
);
689 dev_err(&i2s
->pdev
->dev
, "master/slave format not supported\n");
693 pm_runtime_get_sync(dai
->dev
);
694 spin_lock_irqsave(&priv
->lock
, flags
);
695 mod
= readl(priv
->addr
+ I2SMOD
);
697 * Don't change the I2S mode if any controller is active on this
700 if (any_active(i2s
) &&
701 ((mod
& (sdf_mask
| lrp_rlow
| mod_slave
)) != tmp
)) {
702 spin_unlock_irqrestore(&priv
->lock
, flags
);
703 pm_runtime_put(dai
->dev
);
704 dev_err(&i2s
->pdev
->dev
,
705 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
709 mod
&= ~(sdf_mask
| lrp_rlow
| mod_slave
);
711 writel(mod
, priv
->addr
+ I2SMOD
);
712 priv
->slave_mode
= (mod
& mod_slave
);
713 spin_unlock_irqrestore(&priv
->lock
, flags
);
714 pm_runtime_put(dai
->dev
);
719 static int i2s_hw_params(struct snd_pcm_substream
*substream
,
720 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
722 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
723 struct i2s_dai
*i2s
= to_info(dai
);
724 u32 mod
, mask
= 0, val
= 0;
728 WARN_ON(!pm_runtime_active(dai
->dev
));
730 if (!is_secondary(i2s
))
731 mask
|= (MOD_DC2_EN
| MOD_DC1_EN
);
733 switch (params_channels(params
)) {
741 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
742 i2s
->dma_playback
.addr_width
= 4;
744 i2s
->dma_capture
.addr_width
= 4;
747 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
748 i2s
->dma_playback
.addr_width
= 2;
750 i2s
->dma_capture
.addr_width
= 2;
754 dev_err(&i2s
->pdev
->dev
, "%d channels not supported\n",
755 params_channels(params
));
759 if (is_secondary(i2s
))
760 mask
|= MOD_BLCS_MASK
;
762 mask
|= MOD_BLCP_MASK
;
765 mask
|= MOD_BLC_MASK
;
767 switch (params_width(params
)) {
769 if (is_secondary(i2s
))
770 val
|= MOD_BLCS_8BIT
;
772 val
|= MOD_BLCP_8BIT
;
777 if (is_secondary(i2s
))
778 val
|= MOD_BLCS_16BIT
;
780 val
|= MOD_BLCP_16BIT
;
782 val
|= MOD_BLC_16BIT
;
785 if (is_secondary(i2s
))
786 val
|= MOD_BLCS_24BIT
;
788 val
|= MOD_BLCP_24BIT
;
790 val
|= MOD_BLC_24BIT
;
793 dev_err(&i2s
->pdev
->dev
, "Format(%d) not supported\n",
794 params_format(params
));
798 spin_lock_irqsave(&priv
->lock
, flags
);
799 mod
= readl(priv
->addr
+ I2SMOD
);
800 mod
= (mod
& ~mask
) | val
;
801 writel(mod
, priv
->addr
+ I2SMOD
);
802 spin_unlock_irqrestore(&priv
->lock
, flags
);
804 snd_soc_dai_init_dma_data(dai
, &i2s
->dma_playback
, &i2s
->dma_capture
);
806 i2s
->frmclk
= params_rate(params
);
808 rclksrc
= priv
->clk_table
[CLK_I2S_RCLK_SRC
];
809 if (rclksrc
&& !IS_ERR(rclksrc
))
810 priv
->rclk_srcrate
= clk_get_rate(rclksrc
);
815 /* We set constraints on the substream according to the version of I2S */
816 static int i2s_startup(struct snd_pcm_substream
*substream
,
817 struct snd_soc_dai
*dai
)
819 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
820 struct i2s_dai
*i2s
= to_info(dai
);
821 struct i2s_dai
*other
= get_other_dai(i2s
);
824 pm_runtime_get_sync(dai
->dev
);
826 spin_lock_irqsave(&priv
->pcm_lock
, flags
);
828 i2s
->mode
|= DAI_OPENED
;
830 if (is_manager(other
))
831 i2s
->mode
&= ~DAI_MANAGER
;
833 i2s
->mode
|= DAI_MANAGER
;
835 if (!any_active(i2s
) && (priv
->quirks
& QUIRK_NEED_RSTCLR
))
836 writel(CON_RSTCLR
, i2s
->priv
->addr
+ I2SCON
);
838 spin_unlock_irqrestore(&priv
->pcm_lock
, flags
);
843 static void i2s_shutdown(struct snd_pcm_substream
*substream
,
844 struct snd_soc_dai
*dai
)
846 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
847 struct i2s_dai
*i2s
= to_info(dai
);
848 struct i2s_dai
*other
= get_other_dai(i2s
);
851 spin_lock_irqsave(&priv
->pcm_lock
, flags
);
853 i2s
->mode
&= ~DAI_OPENED
;
854 i2s
->mode
&= ~DAI_MANAGER
;
856 if (is_opened(other
))
857 other
->mode
|= DAI_MANAGER
;
859 /* Reset any constraint on RFS and BFS */
863 spin_unlock_irqrestore(&priv
->pcm_lock
, flags
);
865 pm_runtime_put(dai
->dev
);
868 static int config_setup(struct i2s_dai
*i2s
)
870 struct samsung_i2s_priv
*priv
= i2s
->priv
;
871 struct i2s_dai
*other
= get_other_dai(i2s
);
872 unsigned rfs
, bfs
, blc
;
882 /* Select least possible multiple(2) if no constraint set */
891 if ((rfs
== 256 || rfs
== 512) && (blc
== 24)) {
892 dev_err(&i2s
->pdev
->dev
,
893 "%d-RFS not supported for 24-blc\n", rfs
);
898 if (bfs
== 16 || bfs
== 32)
904 /* If already setup and running */
905 if (any_active(i2s
) && (get_rfs(i2s
) != rfs
|| get_bfs(i2s
) != bfs
)) {
906 dev_err(&i2s
->pdev
->dev
,
907 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
914 /* Don't bother with PSR in Slave mode */
915 if (priv
->slave_mode
)
918 if (!(priv
->quirks
& QUIRK_NO_MUXPSR
)) {
919 psr
= priv
->rclk_srcrate
/ i2s
->frmclk
/ rfs
;
920 writel(((psr
- 1) << 8) | PSR_PSREN
, priv
->addr
+ I2SPSR
);
921 dev_dbg(&i2s
->pdev
->dev
,
922 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
923 priv
->rclk_srcrate
, psr
, rfs
, bfs
);
929 static int i2s_trigger(struct snd_pcm_substream
*substream
,
930 int cmd
, struct snd_soc_dai
*dai
)
932 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
933 int capture
= (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
);
934 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
935 struct i2s_dai
*i2s
= to_info(rtd
->cpu_dai
);
939 case SNDRV_PCM_TRIGGER_START
:
940 case SNDRV_PCM_TRIGGER_RESUME
:
941 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
942 pm_runtime_get_sync(dai
->dev
);
943 spin_lock_irqsave(&priv
->lock
, flags
);
945 if (config_setup(i2s
)) {
946 spin_unlock_irqrestore(&priv
->lock
, flags
);
955 spin_unlock_irqrestore(&priv
->lock
, flags
);
957 case SNDRV_PCM_TRIGGER_STOP
:
958 case SNDRV_PCM_TRIGGER_SUSPEND
:
959 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
960 spin_lock_irqsave(&priv
->lock
, flags
);
964 i2s_fifo(i2s
, FIC_RXFLUSH
);
967 i2s_fifo(i2s
, FIC_TXFLUSH
);
970 spin_unlock_irqrestore(&priv
->lock
, flags
);
971 pm_runtime_put(dai
->dev
);
978 static int i2s_set_clkdiv(struct snd_soc_dai
*dai
,
981 struct i2s_dai
*i2s
= to_info(dai
);
982 struct i2s_dai
*other
= get_other_dai(i2s
);
985 case SAMSUNG_I2S_DIV_BCLK
:
986 pm_runtime_get_sync(dai
->dev
);
987 if ((any_active(i2s
) && div
&& (get_bfs(i2s
) != div
))
988 || (other
&& other
->bfs
&& (other
->bfs
!= div
))) {
989 pm_runtime_put(dai
->dev
);
990 dev_err(&i2s
->pdev
->dev
,
991 "%s:%d Other DAI busy\n", __func__
, __LINE__
);
995 pm_runtime_put(dai
->dev
);
998 dev_err(&i2s
->pdev
->dev
,
999 "Invalid clock divider(%d)\n", div_id
);
1006 static snd_pcm_sframes_t
1007 i2s_delay(struct snd_pcm_substream
*substream
, struct snd_soc_dai
*dai
)
1009 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
1010 struct i2s_dai
*i2s
= to_info(dai
);
1011 u32 reg
= readl(priv
->addr
+ I2SFIC
);
1012 snd_pcm_sframes_t delay
;
1014 WARN_ON(!pm_runtime_active(dai
->dev
));
1016 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
1017 delay
= FIC_RXCOUNT(reg
);
1018 else if (is_secondary(i2s
))
1019 delay
= FICS_TXCOUNT(readl(priv
->addr
+ I2SFICS
));
1021 delay
= (reg
>> priv
->variant_regs
->ftx0cnt_off
) & 0x7f;
1027 static int i2s_suspend(struct snd_soc_component
*component
)
1029 return pm_runtime_force_suspend(component
->dev
);
1032 static int i2s_resume(struct snd_soc_component
*component
)
1034 return pm_runtime_force_resume(component
->dev
);
1037 #define i2s_suspend NULL
1038 #define i2s_resume NULL
1041 static int samsung_i2s_dai_probe(struct snd_soc_dai
*dai
)
1043 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
1044 struct i2s_dai
*i2s
= to_info(dai
);
1045 struct i2s_dai
*other
= get_other_dai(i2s
);
1046 unsigned long flags
;
1048 pm_runtime_get_sync(dai
->dev
);
1050 if (is_secondary(i2s
)) {
1051 /* If this is probe on the secondary DAI */
1052 snd_soc_dai_init_dma_data(dai
, &i2s
->dma_playback
, NULL
);
1054 snd_soc_dai_init_dma_data(dai
, &i2s
->dma_playback
,
1057 if (priv
->quirks
& QUIRK_NEED_RSTCLR
)
1058 writel(CON_RSTCLR
, priv
->addr
+ I2SCON
);
1060 if (priv
->quirks
& QUIRK_SUPPORTS_IDMA
)
1061 idma_reg_addr_init(priv
->addr
,
1062 other
->idma_playback
.addr
);
1065 /* Reset any constraint on RFS and BFS */
1069 spin_lock_irqsave(&priv
->lock
, flags
);
1072 i2s_fifo(i2s
, FIC_TXFLUSH
);
1073 i2s_fifo(other
, FIC_TXFLUSH
);
1074 i2s_fifo(i2s
, FIC_RXFLUSH
);
1075 spin_unlock_irqrestore(&priv
->lock
, flags
);
1077 /* Gate CDCLK by default */
1078 if (!is_opened(other
))
1079 i2s_set_sysclk(dai
, SAMSUNG_I2S_CDCLK
,
1080 0, SND_SOC_CLOCK_IN
);
1081 pm_runtime_put(dai
->dev
);
1086 static int samsung_i2s_dai_remove(struct snd_soc_dai
*dai
)
1088 struct samsung_i2s_priv
*priv
= snd_soc_dai_get_drvdata(dai
);
1089 struct i2s_dai
*i2s
= to_info(dai
);
1090 unsigned long flags
;
1092 pm_runtime_get_sync(dai
->dev
);
1094 if (!is_secondary(i2s
)) {
1095 if (priv
->quirks
& QUIRK_NEED_RSTCLR
) {
1096 spin_lock_irqsave(&priv
->lock
, flags
);
1097 writel(0, priv
->addr
+ I2SCON
);
1098 spin_unlock_irqrestore(&priv
->lock
, flags
);
1102 pm_runtime_put(dai
->dev
);
1107 static const struct snd_soc_dai_ops samsung_i2s_dai_ops
= {
1108 .trigger
= i2s_trigger
,
1109 .hw_params
= i2s_hw_params
,
1110 .set_fmt
= i2s_set_fmt
,
1111 .set_clkdiv
= i2s_set_clkdiv
,
1112 .set_sysclk
= i2s_set_sysclk
,
1113 .startup
= i2s_startup
,
1114 .shutdown
= i2s_shutdown
,
1118 static const struct snd_soc_dapm_widget samsung_i2s_widgets
[] = {
1120 SND_SOC_DAPM_AIF_OUT("Mixer DAI TX", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1121 SND_SOC_DAPM_AIF_IN("Mixer DAI RX", NULL
, 0, SND_SOC_NOPM
, 0, 0),
1123 /* Playback Mixer */
1124 SND_SOC_DAPM_MIXER("Playback Mixer", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1127 static const struct snd_soc_dapm_route samsung_i2s_dapm_routes
[] = {
1128 { "Playback Mixer", NULL
, "Primary Playback" },
1129 { "Playback Mixer", NULL
, "Secondary Playback" },
1131 { "Mixer DAI TX", NULL
, "Playback Mixer" },
1132 { "Primary Capture", NULL
, "Mixer DAI RX" },
1135 static const struct snd_soc_component_driver samsung_i2s_component
= {
1136 .name
= "samsung-i2s",
1138 .dapm_widgets
= samsung_i2s_widgets
,
1139 .num_dapm_widgets
= ARRAY_SIZE(samsung_i2s_widgets
),
1141 .dapm_routes
= samsung_i2s_dapm_routes
,
1142 .num_dapm_routes
= ARRAY_SIZE(samsung_i2s_dapm_routes
),
1144 .suspend
= i2s_suspend
,
1145 .resume
= i2s_resume
,
1148 #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \
1149 SNDRV_PCM_FMTBIT_S24_LE)
1151 static int i2s_alloc_dais(struct samsung_i2s_priv
*priv
,
1152 const struct samsung_i2s_dai_data
*i2s_dai_data
,
1155 static const char *dai_names
[] = { "samsung-i2s", "samsung-i2s-sec" };
1156 static const char *stream_names
[] = { "Primary Playback",
1157 "Secondary Playback" };
1158 struct snd_soc_dai_driver
*dai_drv
;
1159 struct i2s_dai
*dai
;
1162 priv
->dai
= devm_kcalloc(&priv
->pdev
->dev
, num_dais
,
1163 sizeof(*dai
), GFP_KERNEL
);
1167 priv
->dai_drv
= devm_kcalloc(&priv
->pdev
->dev
, num_dais
,
1168 sizeof(*dai_drv
), GFP_KERNEL
);
1172 for (i
= 0; i
< num_dais
; i
++) {
1173 dai_drv
= &priv
->dai_drv
[i
];
1175 dai_drv
->probe
= samsung_i2s_dai_probe
;
1176 dai_drv
->remove
= samsung_i2s_dai_remove
;
1178 dai_drv
->symmetric_rates
= 1;
1179 dai_drv
->ops
= &samsung_i2s_dai_ops
;
1181 dai_drv
->playback
.channels_min
= 1;
1182 dai_drv
->playback
.channels_max
= 2;
1183 dai_drv
->playback
.rates
= i2s_dai_data
->pcm_rates
;
1184 dai_drv
->playback
.formats
= SAMSUNG_I2S_FMTS
;
1185 dai_drv
->playback
.stream_name
= stream_names
[i
];
1187 dai_drv
->id
= i
+ 1;
1188 dai_drv
->name
= dai_names
[i
];
1190 priv
->dai
[i
].drv
= &priv
->dai_drv
[i
];
1191 priv
->dai
[i
].pdev
= priv
->pdev
;
1194 /* Initialize capture only for the primary DAI */
1195 dai_drv
= &priv
->dai_drv
[SAMSUNG_I2S_ID_PRIMARY
- 1];
1197 dai_drv
->capture
.channels_min
= 1;
1198 dai_drv
->capture
.channels_max
= 2;
1199 dai_drv
->capture
.rates
= i2s_dai_data
->pcm_rates
;
1200 dai_drv
->capture
.formats
= SAMSUNG_I2S_FMTS
;
1201 dai_drv
->capture
.stream_name
= "Primary Capture";
1207 static int i2s_runtime_suspend(struct device
*dev
)
1209 struct samsung_i2s_priv
*priv
= dev_get_drvdata(dev
);
1211 priv
->suspend_i2smod
= readl(priv
->addr
+ I2SMOD
);
1212 priv
->suspend_i2scon
= readl(priv
->addr
+ I2SCON
);
1213 priv
->suspend_i2spsr
= readl(priv
->addr
+ I2SPSR
);
1216 clk_disable_unprepare(priv
->op_clk
);
1217 clk_disable_unprepare(priv
->clk
);
1222 static int i2s_runtime_resume(struct device
*dev
)
1224 struct samsung_i2s_priv
*priv
= dev_get_drvdata(dev
);
1227 ret
= clk_prepare_enable(priv
->clk
);
1232 ret
= clk_prepare_enable(priv
->op_clk
);
1234 clk_disable_unprepare(priv
->clk
);
1239 writel(priv
->suspend_i2scon
, priv
->addr
+ I2SCON
);
1240 writel(priv
->suspend_i2smod
, priv
->addr
+ I2SMOD
);
1241 writel(priv
->suspend_i2spsr
, priv
->addr
+ I2SPSR
);
1245 #endif /* CONFIG_PM */
1247 static void i2s_unregister_clocks(struct samsung_i2s_priv
*priv
)
1251 for (i
= 0; i
< priv
->clk_data
.clk_num
; i
++) {
1252 if (!IS_ERR(priv
->clk_table
[i
]))
1253 clk_unregister(priv
->clk_table
[i
]);
1257 static void i2s_unregister_clock_provider(struct samsung_i2s_priv
*priv
)
1259 of_clk_del_provider(priv
->pdev
->dev
.of_node
);
1260 i2s_unregister_clocks(priv
);
1264 static int i2s_register_clock_provider(struct samsung_i2s_priv
*priv
)
1267 const char * const i2s_clk_desc
[] = { "cdclk", "rclk_src", "prescaler" };
1268 const char *clk_name
[2] = { "i2s_opclk0", "i2s_opclk1" };
1269 const char *p_names
[2] = { NULL
};
1270 struct device
*dev
= &priv
->pdev
->dev
;
1271 const struct samsung_i2s_variant_regs
*reg_info
= priv
->variant_regs
;
1272 const char *i2s_clk_name
[ARRAY_SIZE(i2s_clk_desc
)];
1273 struct clk
*rclksrc
;
1276 /* Register the clock provider only if it's expected in the DTB */
1277 if (!of_find_property(dev
->of_node
, "#clock-cells", NULL
))
1280 /* Get the RCLKSRC mux clock parent clock names */
1281 for (i
= 0; i
< ARRAY_SIZE(p_names
); i
++) {
1282 rclksrc
= clk_get(dev
, clk_name
[i
]);
1283 if (IS_ERR(rclksrc
))
1285 p_names
[i
] = __clk_get_name(rclksrc
);
1289 for (i
= 0; i
< ARRAY_SIZE(i2s_clk_desc
); i
++) {
1290 i2s_clk_name
[i
] = devm_kasprintf(dev
, GFP_KERNEL
, "%s_%s",
1291 dev_name(dev
), i2s_clk_desc
[i
]);
1292 if (!i2s_clk_name
[i
])
1296 if (!(priv
->quirks
& QUIRK_NO_MUXPSR
)) {
1297 /* Activate the prescaler */
1298 u32 val
= readl(priv
->addr
+ I2SPSR
);
1299 writel(val
| PSR_PSREN
, priv
->addr
+ I2SPSR
);
1301 priv
->clk_table
[CLK_I2S_RCLK_SRC
] = clk_register_mux(dev
,
1302 i2s_clk_name
[CLK_I2S_RCLK_SRC
], p_names
,
1303 ARRAY_SIZE(p_names
),
1304 CLK_SET_RATE_NO_REPARENT
| CLK_SET_RATE_PARENT
,
1305 priv
->addr
+ I2SMOD
, reg_info
->rclksrc_off
,
1308 priv
->clk_table
[CLK_I2S_RCLK_PSR
] = clk_register_divider(dev
,
1309 i2s_clk_name
[CLK_I2S_RCLK_PSR
],
1310 i2s_clk_name
[CLK_I2S_RCLK_SRC
],
1311 CLK_SET_RATE_PARENT
,
1312 priv
->addr
+ I2SPSR
, 8, 6, 0, &priv
->lock
);
1314 p_names
[0] = i2s_clk_name
[CLK_I2S_RCLK_PSR
];
1315 priv
->clk_data
.clk_num
= 2;
1318 priv
->clk_table
[CLK_I2S_CDCLK
] = clk_register_gate(dev
,
1319 i2s_clk_name
[CLK_I2S_CDCLK
], p_names
[0],
1320 CLK_SET_RATE_PARENT
,
1321 priv
->addr
+ I2SMOD
, reg_info
->cdclkcon_off
,
1322 CLK_GATE_SET_TO_DISABLE
, &priv
->lock
);
1324 priv
->clk_data
.clk_num
+= 1;
1325 priv
->clk_data
.clks
= priv
->clk_table
;
1327 ret
= of_clk_add_provider(dev
->of_node
, of_clk_src_onecell_get
,
1330 dev_err(dev
, "failed to add clock provider: %d\n", ret
);
1331 i2s_unregister_clocks(priv
);
1337 /* Create platform device for the secondary PCM */
1338 static int i2s_create_secondary_device(struct samsung_i2s_priv
*priv
)
1340 struct platform_device
*pdev_sec
;
1341 const char *devname
;
1344 devname
= devm_kasprintf(&priv
->pdev
->dev
, GFP_KERNEL
, "%s-sec",
1345 dev_name(&priv
->pdev
->dev
));
1349 pdev_sec
= platform_device_alloc(devname
, -1);
1353 pdev_sec
->driver_override
= kstrdup("samsung-i2s", GFP_KERNEL
);
1355 ret
= platform_device_add(pdev_sec
);
1357 platform_device_put(pdev_sec
);
1361 ret
= device_attach(&pdev_sec
->dev
);
1363 platform_device_unregister(priv
->pdev_sec
);
1364 dev_info(&pdev_sec
->dev
, "device_attach() failed\n");
1368 priv
->pdev_sec
= pdev_sec
;
1373 static void i2s_delete_secondary_device(struct samsung_i2s_priv
*priv
)
1375 platform_device_unregister(priv
->pdev_sec
);
1376 priv
->pdev_sec
= NULL
;
1379 static int samsung_i2s_probe(struct platform_device
*pdev
)
1381 struct i2s_dai
*pri_dai
, *sec_dai
= NULL
;
1382 struct s3c_audio_pdata
*i2s_pdata
= pdev
->dev
.platform_data
;
1383 u32 regs_base
, idma_addr
= 0;
1384 struct device_node
*np
= pdev
->dev
.of_node
;
1385 const struct samsung_i2s_dai_data
*i2s_dai_data
;
1386 const struct platform_device_id
*id
;
1387 struct samsung_i2s_priv
*priv
;
1388 struct resource
*res
;
1391 if (IS_ENABLED(CONFIG_OF
) && pdev
->dev
.of_node
) {
1392 i2s_dai_data
= of_device_get_match_data(&pdev
->dev
);
1394 id
= platform_get_device_id(pdev
);
1396 /* Nothing to do if it is the secondary device probe */
1400 i2s_dai_data
= (struct samsung_i2s_dai_data
*)id
->driver_data
;
1403 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
1408 priv
->quirks
= i2s_dai_data
->quirks
;
1411 dev_err(&pdev
->dev
, "Missing platform data\n");
1414 priv
->quirks
= i2s_pdata
->type
.quirks
;
1417 num_dais
= (priv
->quirks
& QUIRK_SEC_DAI
) ? 2 : 1;
1419 priv
->variant_regs
= i2s_dai_data
->i2s_variant_regs
;
1421 ret
= i2s_alloc_dais(priv
, i2s_dai_data
, num_dais
);
1425 pri_dai
= &priv
->dai
[SAMSUNG_I2S_ID_PRIMARY
- 1];
1427 spin_lock_init(&priv
->lock
);
1428 spin_lock_init(&priv
->pcm_lock
);
1431 pri_dai
->dma_playback
.filter_data
= i2s_pdata
->dma_playback
;
1432 pri_dai
->dma_capture
.filter_data
= i2s_pdata
->dma_capture
;
1433 pri_dai
->filter
= i2s_pdata
->dma_filter
;
1435 idma_addr
= i2s_pdata
->type
.idma_addr
;
1437 if (of_property_read_u32(np
, "samsung,idma-addr",
1439 if (priv
->quirks
& QUIRK_SUPPORTS_IDMA
) {
1440 dev_info(&pdev
->dev
, "idma address is not"\
1446 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1447 priv
->addr
= devm_ioremap_resource(&pdev
->dev
, res
);
1448 if (IS_ERR(priv
->addr
))
1449 return PTR_ERR(priv
->addr
);
1451 regs_base
= res
->start
;
1453 priv
->clk
= devm_clk_get(&pdev
->dev
, "iis");
1454 if (IS_ERR(priv
->clk
)) {
1455 dev_err(&pdev
->dev
, "Failed to get iis clock\n");
1456 return PTR_ERR(priv
->clk
);
1459 ret
= clk_prepare_enable(priv
->clk
);
1461 dev_err(&pdev
->dev
, "failed to enable clock: %d\n", ret
);
1464 pri_dai
->dma_playback
.addr
= regs_base
+ I2STXD
;
1465 pri_dai
->dma_capture
.addr
= regs_base
+ I2SRXD
;
1466 pri_dai
->dma_playback
.chan_name
= "tx";
1467 pri_dai
->dma_capture
.chan_name
= "rx";
1468 pri_dai
->dma_playback
.addr_width
= 4;
1469 pri_dai
->dma_capture
.addr_width
= 4;
1470 pri_dai
->priv
= priv
;
1472 if (priv
->quirks
& QUIRK_PRI_6CHAN
)
1473 pri_dai
->drv
->playback
.channels_max
= 6;
1475 ret
= samsung_asoc_dma_platform_register(&pdev
->dev
, pri_dai
->filter
,
1478 goto err_disable_clk
;
1480 if (priv
->quirks
& QUIRK_SEC_DAI
) {
1481 sec_dai
= &priv
->dai
[SAMSUNG_I2S_ID_SECONDARY
- 1];
1483 sec_dai
->dma_playback
.addr
= regs_base
+ I2STXDS
;
1484 sec_dai
->dma_playback
.chan_name
= "tx-sec";
1487 sec_dai
->dma_playback
.filter_data
= i2s_pdata
->dma_play_sec
;
1488 sec_dai
->filter
= i2s_pdata
->dma_filter
;
1491 sec_dai
->dma_playback
.addr_width
= 4;
1492 sec_dai
->idma_playback
.addr
= idma_addr
;
1493 sec_dai
->pri_dai
= pri_dai
;
1494 sec_dai
->priv
= priv
;
1495 pri_dai
->sec_dai
= sec_dai
;
1497 ret
= i2s_create_secondary_device(priv
);
1499 goto err_disable_clk
;
1501 ret
= samsung_asoc_dma_platform_register(&priv
->pdev_sec
->dev
,
1502 sec_dai
->filter
, "tx-sec", NULL
,
1509 if (i2s_pdata
&& i2s_pdata
->cfg_gpio
&& i2s_pdata
->cfg_gpio(pdev
)) {
1510 dev_err(&pdev
->dev
, "Unable to configure gpio\n");
1515 dev_set_drvdata(&pdev
->dev
, priv
);
1517 ret
= devm_snd_soc_register_component(&pdev
->dev
,
1518 &samsung_i2s_component
,
1519 priv
->dai_drv
, num_dais
);
1523 pm_runtime_set_active(&pdev
->dev
);
1524 pm_runtime_enable(&pdev
->dev
);
1526 ret
= i2s_register_clock_provider(priv
);
1528 goto err_disable_pm
;
1530 priv
->op_clk
= clk_get_parent(priv
->clk_table
[CLK_I2S_RCLK_SRC
]);
1535 pm_runtime_disable(&pdev
->dev
);
1537 i2s_delete_secondary_device(priv
);
1539 clk_disable_unprepare(priv
->clk
);
1543 static int samsung_i2s_remove(struct platform_device
*pdev
)
1545 struct samsung_i2s_priv
*priv
= dev_get_drvdata(&pdev
->dev
);
1547 /* The secondary device has no driver data assigned */
1551 pm_runtime_get_sync(&pdev
->dev
);
1552 pm_runtime_disable(&pdev
->dev
);
1554 i2s_unregister_clock_provider(priv
);
1555 i2s_delete_secondary_device(priv
);
1556 clk_disable_unprepare(priv
->clk
);
1558 pm_runtime_put_noidle(&pdev
->dev
);
1563 static const struct samsung_i2s_variant_regs i2sv3_regs
= {
1577 static const struct samsung_i2s_variant_regs i2sv6_regs
= {
1591 static const struct samsung_i2s_variant_regs i2sv7_regs
= {
1605 static const struct samsung_i2s_variant_regs i2sv5_i2s1_regs
= {
1619 static const struct samsung_i2s_dai_data i2sv3_dai_type
= {
1620 .quirks
= QUIRK_NO_MUXPSR
,
1621 .pcm_rates
= SNDRV_PCM_RATE_8000_96000
,
1622 .i2s_variant_regs
= &i2sv3_regs
,
1625 static const struct samsung_i2s_dai_data i2sv5_dai_type
= {
1626 .quirks
= QUIRK_PRI_6CHAN
| QUIRK_SEC_DAI
| QUIRK_NEED_RSTCLR
|
1627 QUIRK_SUPPORTS_IDMA
,
1628 .pcm_rates
= SNDRV_PCM_RATE_8000_96000
,
1629 .i2s_variant_regs
= &i2sv3_regs
,
1632 static const struct samsung_i2s_dai_data i2sv6_dai_type
= {
1633 .quirks
= QUIRK_PRI_6CHAN
| QUIRK_SEC_DAI
| QUIRK_NEED_RSTCLR
|
1634 QUIRK_SUPPORTS_TDM
| QUIRK_SUPPORTS_IDMA
,
1635 .pcm_rates
= SNDRV_PCM_RATE_8000_96000
,
1636 .i2s_variant_regs
= &i2sv6_regs
,
1639 static const struct samsung_i2s_dai_data i2sv7_dai_type
= {
1640 .quirks
= QUIRK_PRI_6CHAN
| QUIRK_SEC_DAI
| QUIRK_NEED_RSTCLR
|
1642 .pcm_rates
= SNDRV_PCM_RATE_8000_192000
,
1643 .i2s_variant_regs
= &i2sv7_regs
,
1646 static const struct samsung_i2s_dai_data i2sv5_dai_type_i2s1
= {
1647 .quirks
= QUIRK_PRI_6CHAN
| QUIRK_NEED_RSTCLR
,
1648 .pcm_rates
= SNDRV_PCM_RATE_8000_96000
,
1649 .i2s_variant_regs
= &i2sv5_i2s1_regs
,
1652 static const struct platform_device_id samsung_i2s_driver_ids
[] = {
1654 .name
= "samsung-i2s",
1655 .driver_data
= (kernel_ulong_t
)&i2sv3_dai_type
,
1659 MODULE_DEVICE_TABLE(platform
, samsung_i2s_driver_ids
);
1662 static const struct of_device_id exynos_i2s_match
[] = {
1664 .compatible
= "samsung,s3c6410-i2s",
1665 .data
= &i2sv3_dai_type
,
1667 .compatible
= "samsung,s5pv210-i2s",
1668 .data
= &i2sv5_dai_type
,
1670 .compatible
= "samsung,exynos5420-i2s",
1671 .data
= &i2sv6_dai_type
,
1673 .compatible
= "samsung,exynos7-i2s",
1674 .data
= &i2sv7_dai_type
,
1676 .compatible
= "samsung,exynos7-i2s1",
1677 .data
= &i2sv5_dai_type_i2s1
,
1681 MODULE_DEVICE_TABLE(of
, exynos_i2s_match
);
1684 static const struct dev_pm_ops samsung_i2s_pm
= {
1685 SET_RUNTIME_PM_OPS(i2s_runtime_suspend
,
1686 i2s_runtime_resume
, NULL
)
1687 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend
,
1688 pm_runtime_force_resume
)
1691 static struct platform_driver samsung_i2s_driver
= {
1692 .probe
= samsung_i2s_probe
,
1693 .remove
= samsung_i2s_remove
,
1694 .id_table
= samsung_i2s_driver_ids
,
1696 .name
= "samsung-i2s",
1697 .of_match_table
= of_match_ptr(exynos_i2s_match
),
1698 .pm
= &samsung_i2s_pm
,
1702 module_platform_driver(samsung_i2s_driver
);
1704 /* Module information */
1705 MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
1706 MODULE_DESCRIPTION("Samsung I2S Interface");
1707 MODULE_ALIAS("platform:samsung-i2s");
1708 MODULE_LICENSE("GPL");