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 <jassisinghbrar@gmail.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>
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)
33 /* Platform device for this DAI */
34 struct platform_device *pdev;
37 /* Physical base address of SFRs */
39 /* Rate of RCLK source clock */
40 unsigned long rclk_srcrate;
44 * Specifically requested RCLK,BCLK by MACHINE Driver.
45 * 0 indicates CPU driver is free to choose any value.
48 /* I2S Controller's core clock */
50 /* Clock for generating I2S signals */
52 /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
53 struct i2s_dai *pri_dai;
54 /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
55 struct i2s_dai *sec_dai;
56 #define DAI_OPENED (1 << 0) /* Dai is opened */
57 #define DAI_MANAGER (1 << 1) /* Dai is the manager */
59 /* Driver for this DAI */
60 struct snd_soc_dai_driver i2s_dai_drv;
62 struct s3c_dma_params dma_playback;
63 struct s3c_dma_params dma_capture;
64 struct s3c_dma_params idma_playback;
71 /* Lock for cross i/f checks */
72 static DEFINE_SPINLOCK(lock);
74 /* If this is the 'overlay' stereo DAI */
75 static inline bool is_secondary(struct i2s_dai *i2s)
77 return i2s->pri_dai ? true : false;
80 /* If operating in SoC-Slave mode */
81 static inline bool is_slave(struct i2s_dai *i2s)
83 return (readl(i2s->addr + I2SMOD) & MOD_SLAVE) ? true : false;
86 /* If this interface of the controller is transmitting data */
87 static inline bool tx_active(struct i2s_dai *i2s)
94 active = readl(i2s->addr + I2SCON);
96 if (is_secondary(i2s))
97 active &= CON_TXSDMA_ACTIVE;
99 active &= CON_TXDMA_ACTIVE;
101 return active ? true : false;
104 /* If the other interface of the controller is transmitting data */
105 static inline bool other_tx_active(struct i2s_dai *i2s)
107 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
109 return tx_active(other);
112 /* If any interface of the controller is transmitting data */
113 static inline bool any_tx_active(struct i2s_dai *i2s)
115 return tx_active(i2s) || other_tx_active(i2s);
118 /* If this interface of the controller is receiving data */
119 static inline bool rx_active(struct i2s_dai *i2s)
126 active = readl(i2s->addr + I2SCON) & CON_RXDMA_ACTIVE;
128 return active ? true : false;
131 /* If the other interface of the controller is receiving data */
132 static inline bool other_rx_active(struct i2s_dai *i2s)
134 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
136 return rx_active(other);
139 /* If any interface of the controller is receiving data */
140 static inline bool any_rx_active(struct i2s_dai *i2s)
142 return rx_active(i2s) || other_rx_active(i2s);
145 /* If the other DAI is transmitting or receiving data */
146 static inline bool other_active(struct i2s_dai *i2s)
148 return other_rx_active(i2s) || other_tx_active(i2s);
151 /* If this DAI is transmitting or receiving data */
152 static inline bool this_active(struct i2s_dai *i2s)
154 return tx_active(i2s) || rx_active(i2s);
157 /* If the controller is active anyway */
158 static inline bool any_active(struct i2s_dai *i2s)
160 return this_active(i2s) || other_active(i2s);
163 static inline struct i2s_dai *to_info(struct snd_soc_dai *dai)
165 return snd_soc_dai_get_drvdata(dai);
168 static inline bool is_opened(struct i2s_dai *i2s)
170 if (i2s && (i2s->mode & DAI_OPENED))
176 static inline bool is_manager(struct i2s_dai *i2s)
178 if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
184 /* Read RCLK of I2S (in multiples of LRCLK) */
185 static inline unsigned get_rfs(struct i2s_dai *i2s)
187 u32 rfs = (readl(i2s->addr + I2SMOD) >> 3) & 0x3;
197 /* Write RCLK of I2S (in multiples of LRCLK) */
198 static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
200 u32 mod = readl(i2s->addr + I2SMOD);
202 mod &= ~MOD_RCLK_MASK;
206 mod |= MOD_RCLK_768FS;
209 mod |= MOD_RCLK_512FS;
212 mod |= MOD_RCLK_384FS;
215 mod |= MOD_RCLK_256FS;
219 writel(mod, i2s->addr + I2SMOD);
222 /* Read Bit-Clock of I2S (in multiples of LRCLK) */
223 static inline unsigned get_bfs(struct i2s_dai *i2s)
225 u32 bfs = (readl(i2s->addr + I2SMOD) >> 1) & 0x3;
235 /* Write Bit-Clock of I2S (in multiples of LRCLK) */
236 static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
238 u32 mod = readl(i2s->addr + I2SMOD);
240 mod &= ~MOD_BCLK_MASK;
244 mod |= MOD_BCLK_48FS;
247 mod |= MOD_BCLK_32FS;
250 mod |= MOD_BCLK_24FS;
253 mod |= MOD_BCLK_16FS;
256 dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n");
260 writel(mod, i2s->addr + I2SMOD);
264 static inline int get_blc(struct i2s_dai *i2s)
266 int blc = readl(i2s->addr + I2SMOD);
268 blc = (blc >> 13) & 0x3;
277 /* TX Channel Control */
278 static void i2s_txctrl(struct i2s_dai *i2s, int on)
280 void __iomem *addr = i2s->addr;
281 u32 con = readl(addr + I2SCON);
282 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
286 con &= ~CON_TXCH_PAUSE;
288 if (is_secondary(i2s)) {
289 con |= CON_TXSDMA_ACTIVE;
290 con &= ~CON_TXSDMA_PAUSE;
292 con |= CON_TXDMA_ACTIVE;
293 con &= ~CON_TXDMA_PAUSE;
296 if (any_rx_active(i2s))
301 if (is_secondary(i2s)) {
302 con |= CON_TXSDMA_PAUSE;
303 con &= ~CON_TXSDMA_ACTIVE;
305 con |= CON_TXDMA_PAUSE;
306 con &= ~CON_TXDMA_ACTIVE;
309 if (other_tx_active(i2s)) {
310 writel(con, addr + I2SCON);
314 con |= CON_TXCH_PAUSE;
316 if (any_rx_active(i2s))
322 writel(mod, addr + I2SMOD);
323 writel(con, addr + I2SCON);
326 /* RX Channel Control */
327 static void i2s_rxctrl(struct i2s_dai *i2s, int on)
329 void __iomem *addr = i2s->addr;
330 u32 con = readl(addr + I2SCON);
331 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
334 con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
335 con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
337 if (any_tx_active(i2s))
342 con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
343 con &= ~CON_RXDMA_ACTIVE;
345 if (any_tx_active(i2s))
351 writel(mod, addr + I2SMOD);
352 writel(con, addr + I2SCON);
355 /* Flush FIFO of an interface */
356 static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush)
364 if (is_secondary(i2s))
365 fic = i2s->addr + I2SFICS;
367 fic = i2s->addr + I2SFIC;
370 writel(readl(fic) | flush, fic);
373 val = msecs_to_loops(1) / 1000; /* 1 usec */
377 writel(readl(fic) & ~flush, fic);
380 static int i2s_set_sysclk(struct snd_soc_dai *dai,
381 int clk_id, unsigned int rfs, int dir)
383 struct i2s_dai *i2s = to_info(dai);
384 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
385 u32 mod = readl(i2s->addr + I2SMOD);
388 case SAMSUNG_I2S_CDCLK:
389 /* Shouldn't matter in GATING(CLOCK_IN) mode */
390 if (dir == SND_SOC_CLOCK_IN)
393 if ((rfs && other->rfs && (other->rfs != rfs)) ||
395 (((dir == SND_SOC_CLOCK_IN)
396 && !(mod & MOD_CDCLKCON)) ||
397 ((dir == SND_SOC_CLOCK_OUT)
398 && (mod & MOD_CDCLKCON))))) {
399 dev_err(&i2s->pdev->dev,
400 "%s:%d Other DAI busy\n", __func__, __LINE__);
404 if (dir == SND_SOC_CLOCK_IN)
407 mod &= ~MOD_CDCLKCON;
412 case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
413 case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
414 if ((i2s->quirks & QUIRK_NO_MUXPSR)
415 || (clk_id == SAMSUNG_I2S_RCLKSRC_0))
420 if (!any_active(i2s)) {
422 if ((clk_id && !(mod & MOD_IMS_SYSMUX)) ||
423 (!clk_id && (mod & MOD_IMS_SYSMUX))) {
424 clk_disable_unprepare(i2s->op_clk);
425 clk_put(i2s->op_clk);
428 clk_get_rate(i2s->op_clk);
434 i2s->op_clk = clk_get(&i2s->pdev->dev,
437 i2s->op_clk = clk_get(&i2s->pdev->dev,
439 clk_prepare_enable(i2s->op_clk);
440 i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
442 /* Over-ride the other's */
444 other->op_clk = i2s->op_clk;
445 other->rclk_srcrate = i2s->rclk_srcrate;
447 } else if ((!clk_id && (mod & MOD_IMS_SYSMUX))
448 || (clk_id && !(mod & MOD_IMS_SYSMUX))) {
449 dev_err(&i2s->pdev->dev,
450 "%s:%d Other DAI busy\n", __func__, __LINE__);
453 /* Call can't be on the active DAI */
454 i2s->op_clk = other->op_clk;
455 i2s->rclk_srcrate = other->rclk_srcrate;
460 mod &= ~MOD_IMS_SYSMUX;
462 mod |= MOD_IMS_SYSMUX;
466 dev_err(&i2s->pdev->dev, "We don't serve that!\n");
470 writel(mod, i2s->addr + I2SMOD);
475 static int i2s_set_fmt(struct snd_soc_dai *dai,
478 struct i2s_dai *i2s = to_info(dai);
479 u32 mod = readl(i2s->addr + I2SMOD);
482 /* Format is priority */
483 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
484 case SND_SOC_DAIFMT_RIGHT_J:
488 case SND_SOC_DAIFMT_LEFT_J:
492 case SND_SOC_DAIFMT_I2S:
496 dev_err(&i2s->pdev->dev, "Format not supported\n");
501 * INV flag is relative to the FORMAT flag - if set it simply
502 * flips the polarity specified by the Standard
504 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
505 case SND_SOC_DAIFMT_NB_NF:
507 case SND_SOC_DAIFMT_NB_IF:
508 if (tmp & MOD_LR_RLOW)
514 dev_err(&i2s->pdev->dev, "Polarity not supported\n");
518 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
519 case SND_SOC_DAIFMT_CBM_CFM:
522 case SND_SOC_DAIFMT_CBS_CFS:
523 /* Set default source clock in Master mode */
524 if (i2s->rclk_srcrate == 0)
525 i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
526 0, SND_SOC_CLOCK_IN);
529 dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
533 if (any_active(i2s) &&
534 ((mod & (MOD_SDF_MASK | MOD_LR_RLOW
535 | MOD_SLAVE)) != tmp)) {
536 dev_err(&i2s->pdev->dev,
537 "%s:%d Other DAI busy\n", __func__, __LINE__);
541 mod &= ~(MOD_SDF_MASK | MOD_LR_RLOW | MOD_SLAVE);
543 writel(mod, i2s->addr + I2SMOD);
548 static int i2s_hw_params(struct snd_pcm_substream *substream,
549 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
551 struct i2s_dai *i2s = to_info(dai);
552 u32 mod = readl(i2s->addr + I2SMOD);
554 if (!is_secondary(i2s))
555 mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
557 switch (params_channels(params)) {
564 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
565 i2s->dma_playback.dma_size = 4;
567 i2s->dma_capture.dma_size = 4;
570 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
571 i2s->dma_playback.dma_size = 2;
573 i2s->dma_capture.dma_size = 2;
577 dev_err(&i2s->pdev->dev, "%d channels not supported\n",
578 params_channels(params));
582 if (is_secondary(i2s))
583 mod &= ~MOD_BLCS_MASK;
585 mod &= ~MOD_BLCP_MASK;
588 mod &= ~MOD_BLC_MASK;
590 switch (params_format(params)) {
591 case SNDRV_PCM_FORMAT_S8:
592 if (is_secondary(i2s))
593 mod |= MOD_BLCS_8BIT;
595 mod |= MOD_BLCP_8BIT;
599 case SNDRV_PCM_FORMAT_S16_LE:
600 if (is_secondary(i2s))
601 mod |= MOD_BLCS_16BIT;
603 mod |= MOD_BLCP_16BIT;
605 mod |= MOD_BLC_16BIT;
607 case SNDRV_PCM_FORMAT_S24_LE:
608 if (is_secondary(i2s))
609 mod |= MOD_BLCS_24BIT;
611 mod |= MOD_BLCP_24BIT;
613 mod |= MOD_BLC_24BIT;
616 dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
617 params_format(params));
620 writel(mod, i2s->addr + I2SMOD);
622 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
623 snd_soc_dai_set_dma_data(dai, substream,
624 (void *)&i2s->dma_playback);
626 snd_soc_dai_set_dma_data(dai, substream,
627 (void *)&i2s->dma_capture);
629 i2s->frmclk = params_rate(params);
634 /* We set constraints on the substream acc to the version of I2S */
635 static int i2s_startup(struct snd_pcm_substream *substream,
636 struct snd_soc_dai *dai)
638 struct i2s_dai *i2s = to_info(dai);
639 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
642 spin_lock_irqsave(&lock, flags);
644 i2s->mode |= DAI_OPENED;
646 if (is_manager(other))
647 i2s->mode &= ~DAI_MANAGER;
649 i2s->mode |= DAI_MANAGER;
651 /* Enforce set_sysclk in Master mode */
652 i2s->rclk_srcrate = 0;
654 spin_unlock_irqrestore(&lock, flags);
659 static void i2s_shutdown(struct snd_pcm_substream *substream,
660 struct snd_soc_dai *dai)
662 struct i2s_dai *i2s = to_info(dai);
663 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
666 spin_lock_irqsave(&lock, flags);
668 i2s->mode &= ~DAI_OPENED;
669 i2s->mode &= ~DAI_MANAGER;
671 if (is_opened(other))
672 other->mode |= DAI_MANAGER;
674 /* Reset any constraint on RFS and BFS */
678 spin_unlock_irqrestore(&lock, flags);
680 /* Gate CDCLK by default */
681 if (!is_opened(other))
682 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
683 0, SND_SOC_CLOCK_IN);
686 static int config_setup(struct i2s_dai *i2s)
688 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
689 unsigned rfs, bfs, blc;
699 /* Select least possible multiple(2) if no constraint set */
708 if ((rfs == 256 || rfs == 512) && (blc == 24)) {
709 dev_err(&i2s->pdev->dev,
710 "%d-RFS not supported for 24-blc\n", rfs);
715 if (bfs == 16 || bfs == 32)
721 /* If already setup and running */
722 if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
723 dev_err(&i2s->pdev->dev,
724 "%s:%d Other DAI busy\n", __func__, __LINE__);
728 /* Don't bother RFS, BFS & PSR in Slave mode */
735 if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
736 psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
737 writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
738 dev_dbg(&i2s->pdev->dev,
739 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
740 i2s->rclk_srcrate, psr, rfs, bfs);
746 static int i2s_trigger(struct snd_pcm_substream *substream,
747 int cmd, struct snd_soc_dai *dai)
749 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
750 struct snd_soc_pcm_runtime *rtd = substream->private_data;
751 struct i2s_dai *i2s = to_info(rtd->cpu_dai);
755 case SNDRV_PCM_TRIGGER_START:
756 case SNDRV_PCM_TRIGGER_RESUME:
757 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
758 local_irq_save(flags);
760 if (config_setup(i2s)) {
761 local_irq_restore(flags);
770 local_irq_restore(flags);
772 case SNDRV_PCM_TRIGGER_STOP:
773 case SNDRV_PCM_TRIGGER_SUSPEND:
774 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
775 local_irq_save(flags);
779 i2s_fifo(i2s, FIC_RXFLUSH);
782 i2s_fifo(i2s, FIC_TXFLUSH);
785 local_irq_restore(flags);
792 static int i2s_set_clkdiv(struct snd_soc_dai *dai,
795 struct i2s_dai *i2s = to_info(dai);
796 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
799 case SAMSUNG_I2S_DIV_BCLK:
800 if ((any_active(i2s) && div && (get_bfs(i2s) != div))
801 || (other && other->bfs && (other->bfs != div))) {
802 dev_err(&i2s->pdev->dev,
803 "%s:%d Other DAI busy\n", __func__, __LINE__);
809 dev_err(&i2s->pdev->dev,
810 "Invalid clock divider(%d)\n", div_id);
817 static snd_pcm_sframes_t
818 i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
820 struct i2s_dai *i2s = to_info(dai);
821 u32 reg = readl(i2s->addr + I2SFIC);
822 snd_pcm_sframes_t delay;
824 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
825 delay = FIC_RXCOUNT(reg);
826 else if (is_secondary(i2s))
827 delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
829 delay = FIC_TXCOUNT(reg);
835 static int i2s_suspend(struct snd_soc_dai *dai)
837 struct i2s_dai *i2s = to_info(dai);
840 i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
841 i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
842 i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
848 static int i2s_resume(struct snd_soc_dai *dai)
850 struct i2s_dai *i2s = to_info(dai);
853 writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
854 writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
855 writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
861 #define i2s_suspend NULL
862 #define i2s_resume NULL
865 static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
867 struct i2s_dai *i2s = to_info(dai);
868 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
870 if (other && other->clk) /* If this is probe on secondary */
873 i2s->addr = ioremap(i2s->base, 0x100);
874 if (i2s->addr == NULL) {
875 dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
879 i2s->clk = clk_get(&i2s->pdev->dev, "iis");
880 if (IS_ERR(i2s->clk)) {
881 dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
885 clk_prepare_enable(i2s->clk);
888 other->addr = i2s->addr;
889 other->clk = i2s->clk;
892 if (i2s->quirks & QUIRK_NEED_RSTCLR)
893 writel(CON_RSTCLR, i2s->addr + I2SCON);
895 if (i2s->quirks & QUIRK_SEC_DAI)
896 idma_reg_addr_init(i2s->addr,
897 i2s->sec_dai->idma_playback.dma_addr);
900 /* Reset any constraint on RFS and BFS */
905 i2s_fifo(i2s, FIC_TXFLUSH);
906 i2s_fifo(other, FIC_TXFLUSH);
907 i2s_fifo(i2s, FIC_RXFLUSH);
909 /* Gate CDCLK by default */
910 if (!is_opened(other))
911 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
912 0, SND_SOC_CLOCK_IN);
917 static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
919 struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
920 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
922 if (!other || !other->clk) {
924 if (i2s->quirks & QUIRK_NEED_RSTCLR)
925 writel(0, i2s->addr + I2SCON);
927 clk_disable_unprepare(i2s->clk);
938 static const struct snd_soc_dai_ops samsung_i2s_dai_ops = {
939 .trigger = i2s_trigger,
940 .hw_params = i2s_hw_params,
941 .set_fmt = i2s_set_fmt,
942 .set_clkdiv = i2s_set_clkdiv,
943 .set_sysclk = i2s_set_sysclk,
944 .startup = i2s_startup,
945 .shutdown = i2s_shutdown,
949 #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
951 #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
952 SNDRV_PCM_FMTBIT_S16_LE | \
953 SNDRV_PCM_FMTBIT_S24_LE)
955 static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
959 i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL);
966 i2s->i2s_dai_drv.symmetric_rates = 1;
967 i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
968 i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
969 i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
970 i2s->i2s_dai_drv.suspend = i2s_suspend;
971 i2s->i2s_dai_drv.resume = i2s_resume;
972 i2s->i2s_dai_drv.playback.channels_min = 2;
973 i2s->i2s_dai_drv.playback.channels_max = 2;
974 i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
975 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
978 i2s->i2s_dai_drv.capture.channels_min = 1;
979 i2s->i2s_dai_drv.capture.channels_max = 2;
980 i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
981 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
982 } else { /* Create a new platform_device for Secondary */
983 i2s->pdev = platform_device_register_resndata(NULL,
984 pdev->name, pdev->id + SAMSUNG_I2S_SECOFF,
986 if (IS_ERR(i2s->pdev))
990 /* Pre-assign snd_soc_dai_set_drvdata */
991 dev_set_drvdata(&i2s->pdev->dev, i2s);
996 static int samsung_i2s_probe(struct platform_device *pdev)
998 u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan;
999 struct i2s_dai *pri_dai, *sec_dai = NULL;
1000 struct s3c_audio_pdata *i2s_pdata;
1001 struct samsung_i2s *i2s_cfg;
1002 struct resource *res;
1003 u32 regs_base, quirks;
1006 /* Call during Seconday interface registration */
1007 if (pdev->id >= SAMSUNG_I2S_SECOFF) {
1008 sec_dai = dev_get_drvdata(&pdev->dev);
1009 snd_soc_register_dai(&sec_dai->pdev->dev,
1010 &sec_dai->i2s_dai_drv);
1011 asoc_dma_platform_register(&pdev->dev);
1015 i2s_pdata = pdev->dev.platform_data;
1016 if (i2s_pdata == NULL) {
1017 dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
1021 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1023 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
1026 dma_pl_chan = res->start;
1028 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1030 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
1033 dma_cp_chan = res->start;
1035 res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
1037 dma_pl_sec_chan = res->start;
1039 dma_pl_sec_chan = 0;
1041 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1043 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
1047 if (!request_mem_region(res->start, resource_size(res),
1049 dev_err(&pdev->dev, "Unable to request SFR region\n");
1052 regs_base = res->start;
1054 i2s_cfg = &i2s_pdata->type.i2s;
1055 quirks = i2s_cfg->quirks;
1057 pri_dai = i2s_alloc_dai(pdev, false);
1059 dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
1064 pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
1065 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
1066 pri_dai->dma_playback.client =
1067 (struct s3c2410_dma_client *)&pri_dai->dma_playback;
1068 pri_dai->dma_capture.client =
1069 (struct s3c2410_dma_client *)&pri_dai->dma_capture;
1070 pri_dai->dma_playback.channel = dma_pl_chan;
1071 pri_dai->dma_capture.channel = dma_cp_chan;
1072 pri_dai->dma_playback.dma_size = 4;
1073 pri_dai->dma_capture.dma_size = 4;
1074 pri_dai->base = regs_base;
1075 pri_dai->quirks = quirks;
1077 if (quirks & QUIRK_PRI_6CHAN)
1078 pri_dai->i2s_dai_drv.playback.channels_max = 6;
1080 if (quirks & QUIRK_SEC_DAI) {
1081 sec_dai = i2s_alloc_dai(pdev, true);
1083 dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
1087 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
1088 sec_dai->dma_playback.client =
1089 (struct s3c2410_dma_client *)&sec_dai->dma_playback;
1090 /* Use iDMA always if SysDMA not provided */
1091 sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1;
1092 sec_dai->dma_playback.dma_size = 4;
1093 sec_dai->base = regs_base;
1094 sec_dai->quirks = quirks;
1095 sec_dai->idma_playback.dma_addr = i2s_cfg->idma_addr;
1096 sec_dai->pri_dai = pri_dai;
1097 pri_dai->sec_dai = sec_dai;
1100 if (i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
1101 dev_err(&pdev->dev, "Unable to configure gpio\n");
1106 snd_soc_register_dai(&pri_dai->pdev->dev, &pri_dai->i2s_dai_drv);
1108 pm_runtime_enable(&pdev->dev);
1110 asoc_dma_platform_register(&pdev->dev);
1114 release_mem_region(regs_base, resource_size(res));
1119 static int samsung_i2s_remove(struct platform_device *pdev)
1121 struct i2s_dai *i2s, *other;
1122 struct resource *res;
1124 i2s = dev_get_drvdata(&pdev->dev);
1125 other = i2s->pri_dai ? : i2s->sec_dai;
1128 other->pri_dai = NULL;
1129 other->sec_dai = NULL;
1131 pm_runtime_disable(&pdev->dev);
1132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1134 release_mem_region(res->start, resource_size(res));
1137 i2s->pri_dai = NULL;
1138 i2s->sec_dai = NULL;
1140 asoc_dma_platform_unregister(&pdev->dev);
1141 snd_soc_unregister_dai(&pdev->dev);
1146 static struct platform_driver samsung_i2s_driver = {
1147 .probe = samsung_i2s_probe,
1148 .remove = samsung_i2s_remove,
1150 .name = "samsung-i2s",
1151 .owner = THIS_MODULE,
1155 module_platform_driver(samsung_i2s_driver);
1157 /* Module information */
1158 MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
1159 MODULE_DESCRIPTION("Samsung I2S Interface");
1160 MODULE_ALIAS("platform:samsung-i2s");
1161 MODULE_LICENSE("GPL");