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 <plat/audio.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 /* Array of clock names for op_clk */
54 /* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
55 struct i2s_dai *pri_dai;
56 /* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
57 struct i2s_dai *sec_dai;
58 #define DAI_OPENED (1 << 0) /* Dai is opened */
59 #define DAI_MANAGER (1 << 1) /* Dai is the manager */
61 /* Driver for this DAI */
62 struct snd_soc_dai_driver i2s_dai_drv;
64 struct s3c_dma_params dma_playback;
65 struct s3c_dma_params dma_capture;
66 struct s3c_dma_params idma_playback;
73 /* Lock for cross i/f checks */
74 static DEFINE_SPINLOCK(lock);
76 /* If this is the 'overlay' stereo DAI */
77 static inline bool is_secondary(struct i2s_dai *i2s)
79 return i2s->pri_dai ? true : false;
82 /* If operating in SoC-Slave mode */
83 static inline bool is_slave(struct i2s_dai *i2s)
85 return (readl(i2s->addr + I2SMOD) & MOD_SLAVE) ? true : false;
88 /* If this interface of the controller is transmitting data */
89 static inline bool tx_active(struct i2s_dai *i2s)
96 active = readl(i2s->addr + I2SCON);
98 if (is_secondary(i2s))
99 active &= CON_TXSDMA_ACTIVE;
101 active &= CON_TXDMA_ACTIVE;
103 return active ? true : false;
106 /* If the other interface of the controller is transmitting data */
107 static inline bool other_tx_active(struct i2s_dai *i2s)
109 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
111 return tx_active(other);
114 /* If any interface of the controller is transmitting data */
115 static inline bool any_tx_active(struct i2s_dai *i2s)
117 return tx_active(i2s) || other_tx_active(i2s);
120 /* If this interface of the controller is receiving data */
121 static inline bool rx_active(struct i2s_dai *i2s)
128 active = readl(i2s->addr + I2SCON) & CON_RXDMA_ACTIVE;
130 return active ? true : false;
133 /* If the other interface of the controller is receiving data */
134 static inline bool other_rx_active(struct i2s_dai *i2s)
136 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
138 return rx_active(other);
141 /* If any interface of the controller is receiving data */
142 static inline bool any_rx_active(struct i2s_dai *i2s)
144 return rx_active(i2s) || other_rx_active(i2s);
147 /* If the other DAI is transmitting or receiving data */
148 static inline bool other_active(struct i2s_dai *i2s)
150 return other_rx_active(i2s) || other_tx_active(i2s);
153 /* If this DAI is transmitting or receiving data */
154 static inline bool this_active(struct i2s_dai *i2s)
156 return tx_active(i2s) || rx_active(i2s);
159 /* If the controller is active anyway */
160 static inline bool any_active(struct i2s_dai *i2s)
162 return this_active(i2s) || other_active(i2s);
165 static inline struct i2s_dai *to_info(struct snd_soc_dai *dai)
167 return snd_soc_dai_get_drvdata(dai);
170 static inline bool is_opened(struct i2s_dai *i2s)
172 if (i2s && (i2s->mode & DAI_OPENED))
178 static inline bool is_manager(struct i2s_dai *i2s)
180 if (is_opened(i2s) && (i2s->mode & DAI_MANAGER))
186 /* Read RCLK of I2S (in multiples of LRCLK) */
187 static inline unsigned get_rfs(struct i2s_dai *i2s)
189 u32 rfs = (readl(i2s->addr + I2SMOD) >> 3) & 0x3;
199 /* Write RCLK of I2S (in multiples of LRCLK) */
200 static inline void set_rfs(struct i2s_dai *i2s, unsigned rfs)
202 u32 mod = readl(i2s->addr + I2SMOD);
204 mod &= ~MOD_RCLK_MASK;
208 mod |= MOD_RCLK_768FS;
211 mod |= MOD_RCLK_512FS;
214 mod |= MOD_RCLK_384FS;
217 mod |= MOD_RCLK_256FS;
221 writel(mod, i2s->addr + I2SMOD);
224 /* Read Bit-Clock of I2S (in multiples of LRCLK) */
225 static inline unsigned get_bfs(struct i2s_dai *i2s)
227 u32 bfs = (readl(i2s->addr + I2SMOD) >> 1) & 0x3;
237 /* Write Bit-Clock of I2S (in multiples of LRCLK) */
238 static inline void set_bfs(struct i2s_dai *i2s, unsigned bfs)
240 u32 mod = readl(i2s->addr + I2SMOD);
242 mod &= ~MOD_BCLK_MASK;
246 mod |= MOD_BCLK_48FS;
249 mod |= MOD_BCLK_32FS;
252 mod |= MOD_BCLK_24FS;
255 mod |= MOD_BCLK_16FS;
258 dev_err(&i2s->pdev->dev, "Wrong BCLK Divider!\n");
262 writel(mod, i2s->addr + I2SMOD);
266 static inline int get_blc(struct i2s_dai *i2s)
268 int blc = readl(i2s->addr + I2SMOD);
270 blc = (blc >> 13) & 0x3;
279 /* TX Channel Control */
280 static void i2s_txctrl(struct i2s_dai *i2s, int on)
282 void __iomem *addr = i2s->addr;
283 u32 con = readl(addr + I2SCON);
284 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
288 con &= ~CON_TXCH_PAUSE;
290 if (is_secondary(i2s)) {
291 con |= CON_TXSDMA_ACTIVE;
292 con &= ~CON_TXSDMA_PAUSE;
294 con |= CON_TXDMA_ACTIVE;
295 con &= ~CON_TXDMA_PAUSE;
298 if (any_rx_active(i2s))
303 if (is_secondary(i2s)) {
304 con |= CON_TXSDMA_PAUSE;
305 con &= ~CON_TXSDMA_ACTIVE;
307 con |= CON_TXDMA_PAUSE;
308 con &= ~CON_TXDMA_ACTIVE;
311 if (other_tx_active(i2s)) {
312 writel(con, addr + I2SCON);
316 con |= CON_TXCH_PAUSE;
318 if (any_rx_active(i2s))
324 writel(mod, addr + I2SMOD);
325 writel(con, addr + I2SCON);
328 /* RX Channel Control */
329 static void i2s_rxctrl(struct i2s_dai *i2s, int on)
331 void __iomem *addr = i2s->addr;
332 u32 con = readl(addr + I2SCON);
333 u32 mod = readl(addr + I2SMOD) & ~MOD_MASK;
336 con |= CON_RXDMA_ACTIVE | CON_ACTIVE;
337 con &= ~(CON_RXDMA_PAUSE | CON_RXCH_PAUSE);
339 if (any_tx_active(i2s))
344 con |= CON_RXDMA_PAUSE | CON_RXCH_PAUSE;
345 con &= ~CON_RXDMA_ACTIVE;
347 if (any_tx_active(i2s))
353 writel(mod, addr + I2SMOD);
354 writel(con, addr + I2SCON);
357 /* Flush FIFO of an interface */
358 static inline void i2s_fifo(struct i2s_dai *i2s, u32 flush)
366 if (is_secondary(i2s))
367 fic = i2s->addr + I2SFICS;
369 fic = i2s->addr + I2SFIC;
372 writel(readl(fic) | flush, fic);
375 val = msecs_to_loops(1) / 1000; /* 1 usec */
379 writel(readl(fic) & ~flush, fic);
382 static int i2s_set_sysclk(struct snd_soc_dai *dai,
383 int clk_id, unsigned int rfs, int dir)
385 struct i2s_dai *i2s = to_info(dai);
386 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
387 u32 mod = readl(i2s->addr + I2SMOD);
390 case SAMSUNG_I2S_CDCLK:
391 /* Shouldn't matter in GATING(CLOCK_IN) mode */
392 if (dir == SND_SOC_CLOCK_IN)
395 if ((rfs && other->rfs && (other->rfs != rfs)) ||
397 (((dir == SND_SOC_CLOCK_IN)
398 && !(mod & MOD_CDCLKCON)) ||
399 ((dir == SND_SOC_CLOCK_OUT)
400 && (mod & MOD_CDCLKCON))))) {
401 dev_err(&i2s->pdev->dev,
402 "%s:%d Other DAI busy\n", __func__, __LINE__);
406 if (dir == SND_SOC_CLOCK_IN)
409 mod &= ~MOD_CDCLKCON;
414 case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
415 case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
416 if ((i2s->quirks & QUIRK_NO_MUXPSR)
417 || (clk_id == SAMSUNG_I2S_RCLKSRC_0))
422 if (!any_active(i2s)) {
424 if ((clk_id && !(mod & MOD_IMS_SYSMUX)) ||
425 (!clk_id && (mod & MOD_IMS_SYSMUX))) {
426 clk_disable(i2s->op_clk);
427 clk_put(i2s->op_clk);
430 clk_get_rate(i2s->op_clk);
435 i2s->op_clk = clk_get(&i2s->pdev->dev,
436 i2s->src_clk[clk_id]);
437 clk_enable(i2s->op_clk);
438 i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
440 /* Over-ride the other's */
442 other->op_clk = i2s->op_clk;
443 other->rclk_srcrate = i2s->rclk_srcrate;
445 } else if ((!clk_id && (mod & MOD_IMS_SYSMUX))
446 || (clk_id && !(mod & MOD_IMS_SYSMUX))) {
447 dev_err(&i2s->pdev->dev,
448 "%s:%d Other DAI busy\n", __func__, __LINE__);
451 /* Call can't be on the active DAI */
452 i2s->op_clk = other->op_clk;
453 i2s->rclk_srcrate = other->rclk_srcrate;
458 mod &= ~MOD_IMS_SYSMUX;
460 mod |= MOD_IMS_SYSMUX;
464 dev_err(&i2s->pdev->dev, "We don't serve that!\n");
468 writel(mod, i2s->addr + I2SMOD);
473 static int i2s_set_fmt(struct snd_soc_dai *dai,
476 struct i2s_dai *i2s = to_info(dai);
477 u32 mod = readl(i2s->addr + I2SMOD);
480 /* Format is priority */
481 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
482 case SND_SOC_DAIFMT_RIGHT_J:
486 case SND_SOC_DAIFMT_LEFT_J:
490 case SND_SOC_DAIFMT_I2S:
494 dev_err(&i2s->pdev->dev, "Format not supported\n");
499 * INV flag is relative to the FORMAT flag - if set it simply
500 * flips the polarity specified by the Standard
502 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
503 case SND_SOC_DAIFMT_NB_NF:
505 case SND_SOC_DAIFMT_NB_IF:
506 if (tmp & MOD_LR_RLOW)
512 dev_err(&i2s->pdev->dev, "Polarity not supported\n");
516 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
517 case SND_SOC_DAIFMT_CBM_CFM:
520 case SND_SOC_DAIFMT_CBS_CFS:
521 /* Set default source clock in Master mode */
522 if (i2s->rclk_srcrate == 0)
523 i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
524 0, SND_SOC_CLOCK_IN);
527 dev_err(&i2s->pdev->dev, "master/slave format not supported\n");
531 if (any_active(i2s) &&
532 ((mod & (MOD_SDF_MASK | MOD_LR_RLOW
533 | MOD_SLAVE)) != tmp)) {
534 dev_err(&i2s->pdev->dev,
535 "%s:%d Other DAI busy\n", __func__, __LINE__);
539 mod &= ~(MOD_SDF_MASK | MOD_LR_RLOW | MOD_SLAVE);
541 writel(mod, i2s->addr + I2SMOD);
546 static int i2s_hw_params(struct snd_pcm_substream *substream,
547 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
549 struct i2s_dai *i2s = to_info(dai);
550 u32 mod = readl(i2s->addr + I2SMOD);
552 if (!is_secondary(i2s))
553 mod &= ~(MOD_DC2_EN | MOD_DC1_EN);
555 switch (params_channels(params)) {
562 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
563 i2s->dma_playback.dma_size = 4;
565 i2s->dma_capture.dma_size = 4;
568 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
569 i2s->dma_playback.dma_size = 2;
571 i2s->dma_capture.dma_size = 2;
575 dev_err(&i2s->pdev->dev, "%d channels not supported\n",
576 params_channels(params));
580 if (is_secondary(i2s))
581 mod &= ~MOD_BLCS_MASK;
583 mod &= ~MOD_BLCP_MASK;
586 mod &= ~MOD_BLC_MASK;
588 switch (params_format(params)) {
589 case SNDRV_PCM_FORMAT_S8:
590 if (is_secondary(i2s))
591 mod |= MOD_BLCS_8BIT;
593 mod |= MOD_BLCP_8BIT;
597 case SNDRV_PCM_FORMAT_S16_LE:
598 if (is_secondary(i2s))
599 mod |= MOD_BLCS_16BIT;
601 mod |= MOD_BLCP_16BIT;
603 mod |= MOD_BLC_16BIT;
605 case SNDRV_PCM_FORMAT_S24_LE:
606 if (is_secondary(i2s))
607 mod |= MOD_BLCS_24BIT;
609 mod |= MOD_BLCP_24BIT;
611 mod |= MOD_BLC_24BIT;
614 dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
615 params_format(params));
618 writel(mod, i2s->addr + I2SMOD);
620 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
621 snd_soc_dai_set_dma_data(dai, substream,
622 (void *)&i2s->dma_playback);
624 snd_soc_dai_set_dma_data(dai, substream,
625 (void *)&i2s->dma_capture);
627 i2s->frmclk = params_rate(params);
632 /* We set constraints on the substream acc to the version of I2S */
633 static int i2s_startup(struct snd_pcm_substream *substream,
634 struct snd_soc_dai *dai)
636 struct i2s_dai *i2s = to_info(dai);
637 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
640 spin_lock_irqsave(&lock, flags);
642 i2s->mode |= DAI_OPENED;
644 if (is_manager(other))
645 i2s->mode &= ~DAI_MANAGER;
647 i2s->mode |= DAI_MANAGER;
649 /* Enforce set_sysclk in Master mode */
650 i2s->rclk_srcrate = 0;
652 spin_unlock_irqrestore(&lock, flags);
657 static void i2s_shutdown(struct snd_pcm_substream *substream,
658 struct snd_soc_dai *dai)
660 struct i2s_dai *i2s = to_info(dai);
661 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
664 spin_lock_irqsave(&lock, flags);
666 i2s->mode &= ~DAI_OPENED;
667 i2s->mode &= ~DAI_MANAGER;
669 if (is_opened(other))
670 other->mode |= DAI_MANAGER;
672 /* Reset any constraint on RFS and BFS */
676 spin_unlock_irqrestore(&lock, flags);
678 /* Gate CDCLK by default */
679 if (!is_opened(other))
680 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
681 0, SND_SOC_CLOCK_IN);
684 static int config_setup(struct i2s_dai *i2s)
686 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
687 unsigned rfs, bfs, blc;
697 /* Select least possible multiple(2) if no constraint set */
706 if ((rfs == 256 || rfs == 512) && (blc == 24)) {
707 dev_err(&i2s->pdev->dev,
708 "%d-RFS not supported for 24-blc\n", rfs);
713 if (bfs == 16 || bfs == 32)
719 /* If already setup and running */
720 if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
721 dev_err(&i2s->pdev->dev,
722 "%s:%d Other DAI busy\n", __func__, __LINE__);
726 /* Don't bother RFS, BFS & PSR in Slave mode */
733 if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
734 psr = i2s->rclk_srcrate / i2s->frmclk / rfs;
735 writel(((psr - 1) << 8) | PSR_PSREN, i2s->addr + I2SPSR);
736 dev_dbg(&i2s->pdev->dev,
737 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
738 i2s->rclk_srcrate, psr, rfs, bfs);
744 static int i2s_trigger(struct snd_pcm_substream *substream,
745 int cmd, struct snd_soc_dai *dai)
747 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
748 struct snd_soc_pcm_runtime *rtd = substream->private_data;
749 struct i2s_dai *i2s = to_info(rtd->cpu_dai);
753 case SNDRV_PCM_TRIGGER_START:
754 case SNDRV_PCM_TRIGGER_RESUME:
755 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
756 local_irq_save(flags);
758 if (config_setup(i2s)) {
759 local_irq_restore(flags);
768 local_irq_restore(flags);
770 case SNDRV_PCM_TRIGGER_STOP:
771 case SNDRV_PCM_TRIGGER_SUSPEND:
772 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
773 local_irq_save(flags);
777 i2s_fifo(i2s, FIC_RXFLUSH);
780 i2s_fifo(i2s, FIC_TXFLUSH);
783 local_irq_restore(flags);
790 static int i2s_set_clkdiv(struct snd_soc_dai *dai,
793 struct i2s_dai *i2s = to_info(dai);
794 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
797 case SAMSUNG_I2S_DIV_BCLK:
798 if ((any_active(i2s) && div && (get_bfs(i2s) != div))
799 || (other && other->bfs && (other->bfs != div))) {
800 dev_err(&i2s->pdev->dev,
801 "%s:%d Other DAI busy\n", __func__, __LINE__);
807 dev_err(&i2s->pdev->dev,
808 "Invalid clock divider(%d)\n", div_id);
815 static snd_pcm_sframes_t
816 i2s_delay(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
818 struct i2s_dai *i2s = to_info(dai);
819 u32 reg = readl(i2s->addr + I2SFIC);
820 snd_pcm_sframes_t delay;
822 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
823 delay = FIC_RXCOUNT(reg);
824 else if (is_secondary(i2s))
825 delay = FICS_TXCOUNT(readl(i2s->addr + I2SFICS));
827 delay = FIC_TXCOUNT(reg);
833 static int i2s_suspend(struct snd_soc_dai *dai)
835 struct i2s_dai *i2s = to_info(dai);
838 i2s->suspend_i2smod = readl(i2s->addr + I2SMOD);
839 i2s->suspend_i2scon = readl(i2s->addr + I2SCON);
840 i2s->suspend_i2spsr = readl(i2s->addr + I2SPSR);
846 static int i2s_resume(struct snd_soc_dai *dai)
848 struct i2s_dai *i2s = to_info(dai);
851 writel(i2s->suspend_i2scon, i2s->addr + I2SCON);
852 writel(i2s->suspend_i2smod, i2s->addr + I2SMOD);
853 writel(i2s->suspend_i2spsr, i2s->addr + I2SPSR);
859 #define i2s_suspend NULL
860 #define i2s_resume NULL
863 static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
865 struct i2s_dai *i2s = to_info(dai);
866 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
868 if (other && other->clk) /* If this is probe on secondary */
871 i2s->addr = ioremap(i2s->base, 0x100);
872 if (i2s->addr == NULL) {
873 dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
877 i2s->clk = clk_get(&i2s->pdev->dev, "iis");
878 if (IS_ERR(i2s->clk)) {
879 dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
883 clk_enable(i2s->clk);
886 other->addr = i2s->addr;
887 other->clk = i2s->clk;
890 if (i2s->quirks & QUIRK_NEED_RSTCLR)
891 writel(CON_RSTCLR, i2s->addr + I2SCON);
893 if (i2s->quirks & QUIRK_SEC_DAI)
894 idma_reg_addr_init(i2s->addr,
895 i2s->sec_dai->idma_playback.dma_addr);
898 /* Reset any constraint on RFS and BFS */
903 i2s_fifo(i2s, FIC_TXFLUSH);
904 i2s_fifo(other, FIC_TXFLUSH);
905 i2s_fifo(i2s, FIC_RXFLUSH);
907 /* Gate CDCLK by default */
908 if (!is_opened(other))
909 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
910 0, SND_SOC_CLOCK_IN);
915 static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
917 struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
918 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
920 if (!other || !other->clk) {
922 if (i2s->quirks & QUIRK_NEED_RSTCLR)
923 writel(0, i2s->addr + I2SCON);
925 clk_disable(i2s->clk);
936 static const struct snd_soc_dai_ops samsung_i2s_dai_ops = {
937 .trigger = i2s_trigger,
938 .hw_params = i2s_hw_params,
939 .set_fmt = i2s_set_fmt,
940 .set_clkdiv = i2s_set_clkdiv,
941 .set_sysclk = i2s_set_sysclk,
942 .startup = i2s_startup,
943 .shutdown = i2s_shutdown,
947 #define SAMSUNG_I2S_RATES SNDRV_PCM_RATE_8000_96000
949 #define SAMSUNG_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
950 SNDRV_PCM_FMTBIT_S16_LE | \
951 SNDRV_PCM_FMTBIT_S24_LE)
954 struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev, bool sec)
958 i2s = devm_kzalloc(&pdev->dev, sizeof(struct i2s_dai), GFP_KERNEL);
965 i2s->i2s_dai_drv.symmetric_rates = 1;
966 i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
967 i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
968 i2s->i2s_dai_drv.ops = &samsung_i2s_dai_ops;
969 i2s->i2s_dai_drv.suspend = i2s_suspend;
970 i2s->i2s_dai_drv.resume = i2s_resume;
971 i2s->i2s_dai_drv.playback.channels_min = 2;
972 i2s->i2s_dai_drv.playback.channels_max = 2;
973 i2s->i2s_dai_drv.playback.rates = SAMSUNG_I2S_RATES;
974 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
977 i2s->i2s_dai_drv.capture.channels_min = 1;
978 i2s->i2s_dai_drv.capture.channels_max = 2;
979 i2s->i2s_dai_drv.capture.rates = SAMSUNG_I2S_RATES;
980 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
981 } else { /* Create a new platform_device for Secondary */
982 i2s->pdev = platform_device_register_resndata(NULL,
983 pdev->name, pdev->id + SAMSUNG_I2S_SECOFF,
985 if (IS_ERR(i2s->pdev))
989 /* Pre-assign snd_soc_dai_set_drvdata */
990 dev_set_drvdata(&i2s->pdev->dev, i2s);
995 static __devinit int samsung_i2s_probe(struct platform_device *pdev)
997 u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan;
998 struct i2s_dai *pri_dai, *sec_dai = NULL;
999 struct s3c_audio_pdata *i2s_pdata;
1000 struct samsung_i2s *i2s_cfg;
1001 struct resource *res;
1002 u32 regs_base, quirks;
1005 /* Call during Seconday interface registration */
1006 if (pdev->id >= SAMSUNG_I2S_SECOFF) {
1007 sec_dai = dev_get_drvdata(&pdev->dev);
1008 snd_soc_register_dai(&sec_dai->pdev->dev,
1009 &sec_dai->i2s_dai_drv);
1013 i2s_pdata = pdev->dev.platform_data;
1014 if (i2s_pdata == NULL) {
1015 dev_err(&pdev->dev, "Can't work without s3c_audio_pdata\n");
1019 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1021 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
1024 dma_pl_chan = res->start;
1026 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1028 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
1031 dma_cp_chan = res->start;
1033 res = platform_get_resource(pdev, IORESOURCE_DMA, 2);
1035 dma_pl_sec_chan = res->start;
1037 dma_pl_sec_chan = 0;
1039 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1041 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
1045 if (!request_mem_region(res->start, resource_size(res),
1047 dev_err(&pdev->dev, "Unable to request SFR region\n");
1050 regs_base = res->start;
1052 i2s_cfg = &i2s_pdata->type.i2s;
1053 quirks = i2s_cfg->quirks;
1055 pri_dai = i2s_alloc_dai(pdev, false);
1057 dev_err(&pdev->dev, "Unable to alloc I2S_pri\n");
1062 pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
1063 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
1064 pri_dai->dma_playback.client =
1065 (struct s3c2410_dma_client *)&pri_dai->dma_playback;
1066 pri_dai->dma_capture.client =
1067 (struct s3c2410_dma_client *)&pri_dai->dma_capture;
1068 pri_dai->dma_playback.channel = dma_pl_chan;
1069 pri_dai->dma_capture.channel = dma_cp_chan;
1070 pri_dai->src_clk = i2s_cfg->src_clk;
1071 pri_dai->dma_playback.dma_size = 4;
1072 pri_dai->dma_capture.dma_size = 4;
1073 pri_dai->base = regs_base;
1074 pri_dai->quirks = quirks;
1076 if (quirks & QUIRK_PRI_6CHAN)
1077 pri_dai->i2s_dai_drv.playback.channels_max = 6;
1079 if (quirks & QUIRK_SEC_DAI) {
1080 sec_dai = i2s_alloc_dai(pdev, true);
1082 dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
1086 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
1087 sec_dai->dma_playback.client =
1088 (struct s3c2410_dma_client *)&sec_dai->dma_playback;
1089 /* Use iDMA always if SysDMA not provided */
1090 sec_dai->dma_playback.channel = dma_pl_sec_chan ? : -1;
1091 sec_dai->src_clk = i2s_cfg->src_clk;
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);
1112 release_mem_region(regs_base, resource_size(res));
1117 static __devexit int samsung_i2s_remove(struct platform_device *pdev)
1119 struct i2s_dai *i2s, *other;
1120 struct resource *res;
1122 i2s = dev_get_drvdata(&pdev->dev);
1123 other = i2s->pri_dai ? : i2s->sec_dai;
1126 other->pri_dai = NULL;
1127 other->sec_dai = NULL;
1129 pm_runtime_disable(&pdev->dev);
1130 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1132 release_mem_region(res->start, resource_size(res));
1135 i2s->pri_dai = NULL;
1136 i2s->sec_dai = NULL;
1138 snd_soc_unregister_dai(&pdev->dev);
1143 static struct platform_driver samsung_i2s_driver = {
1144 .probe = samsung_i2s_probe,
1145 .remove = __devexit_p(samsung_i2s_remove),
1147 .name = "samsung-i2s",
1148 .owner = THIS_MODULE,
1152 module_platform_driver(samsung_i2s_driver);
1154 /* Module information */
1155 MODULE_AUTHOR("Jaswinder Singh, <jassisinghbrar@gmail.com>");
1156 MODULE_DESCRIPTION("Samsung I2S Interface");
1157 MODULE_ALIAS("platform:samsung-i2s");
1158 MODULE_LICENSE("GPL");