14 #include <linux/slab.h>
17 #include <linux/module.h>
30 #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
58 #define DAI_OPENED (1 << 0)
59 #define DAI_MANAGER (1 << 1)
77 static inline bool is_secondary(
struct i2s_dai *i2s)
79 return i2s->
pri_dai ?
true :
false;
83 static inline bool is_slave(
struct i2s_dai *i2s)
89 static inline bool tx_active(
struct i2s_dai *i2s)
98 if (is_secondary(i2s))
103 return active ?
true :
false;
107 static inline bool other_tx_active(
struct i2s_dai *i2s)
111 return tx_active(other);
115 static inline bool any_tx_active(
struct i2s_dai *i2s)
117 return tx_active(i2s) || other_tx_active(i2s);
121 static inline bool rx_active(
struct i2s_dai *i2s)
130 return active ?
true :
false;
134 static inline bool other_rx_active(
struct i2s_dai *i2s)
138 return rx_active(other);
142 static inline bool any_rx_active(
struct i2s_dai *i2s)
144 return rx_active(i2s) || other_rx_active(i2s);
148 static inline bool other_active(
struct i2s_dai *i2s)
150 return other_rx_active(i2s) || other_tx_active(i2s);
154 static inline bool this_active(
struct i2s_dai *i2s)
156 return tx_active(i2s) || rx_active(i2s);
160 static inline bool any_active(
struct i2s_dai *i2s)
162 return this_active(i2s) || other_active(i2s);
167 return snd_soc_dai_get_drvdata(dai);
170 static inline bool is_opened(
struct i2s_dai *i2s)
178 static inline bool is_manager(
struct i2s_dai *i2s)
187 static inline unsigned get_rfs(
struct i2s_dai *i2s)
200 static inline void set_rfs(
struct i2s_dai *i2s,
unsigned rfs)
225 static inline unsigned get_bfs(
struct i2s_dai *i2s)
238 static inline void set_bfs(
struct i2s_dai *i2s,
unsigned bfs)
266 static inline int get_blc(
struct i2s_dai *i2s)
270 blc = (blc >> 13) & 0x3;
280 static void i2s_txctrl(
struct i2s_dai *i2s,
int on)
290 if (is_secondary(i2s)) {
298 if (any_rx_active(i2s))
303 if (is_secondary(i2s)) {
311 if (other_tx_active(i2s)) {
318 if (any_rx_active(i2s))
329 static void i2s_rxctrl(
struct i2s_dai *i2s,
int on)
339 if (any_tx_active(i2s))
347 if (any_tx_active(i2s))
358 static inline void i2s_fifo(
struct i2s_dai *i2s,
u32 flush)
366 if (is_secondary(i2s))
383 int clk_id,
unsigned int rfs,
int dir)
385 struct i2s_dai *i2s = to_info(dai);
395 if ((rfs && other->
rfs && (other->
rfs != rfs)) ||
400 && (mod & MOD_CDCLKCON))))) {
402 "%s:%d Other DAI busy\n", __func__, __LINE__);
409 mod &= ~MOD_CDCLKCON;
422 if (!any_active(i2s)) {
425 (!clk_id && (mod & MOD_IMS_SYSMUX))) {
445 }
else if ((!clk_id && (mod & MOD_IMS_SYSMUX))
446 || (clk_id && !(mod & MOD_IMS_SYSMUX))) {
448 "%s:%d Other DAI busy\n", __func__, __LINE__);
458 mod &= ~MOD_IMS_SYSMUX;
464 dev_err(&i2s->
pdev->dev,
"We don't serve that!\n");
476 struct i2s_dai *i2s = to_info(dai);
494 dev_err(&i2s->
pdev->dev,
"Format not supported\n");
512 dev_err(&i2s->
pdev->dev,
"Polarity not supported\n");
527 dev_err(&i2s->
pdev->dev,
"master/slave format not supported\n");
531 if (any_active(i2s) &&
535 "%s:%d Other DAI busy\n", __func__, __LINE__);
549 struct i2s_dai *i2s = to_info(dai);
552 if (!is_secondary(i2s))
575 dev_err(&i2s->
pdev->dev,
"%d channels not supported\n",
580 if (is_secondary(i2s))
590 if (is_secondary(i2s))
598 if (is_secondary(i2s))
606 if (is_secondary(i2s))
614 dev_err(&i2s->
pdev->dev,
"Format(%d) not supported\n",
621 snd_soc_dai_set_dma_data(dai, substream,
624 snd_soc_dai_set_dma_data(dai, substream,
636 struct i2s_dai *i2s = to_info(dai);
644 if (is_manager(other))
652 spin_unlock_irqrestore(&lock, flags);
660 struct i2s_dai *i2s = to_info(dai);
669 if (is_opened(other))
676 spin_unlock_irqrestore(&lock, flags);
679 if (!is_opened(other))
684 static int config_setup(
struct i2s_dai *i2s)
706 if ((rfs == 256 || rfs == 512) && (blc == 24)) {
708 "%d-RFS not supported for 24-blc\n", rfs);
713 if (bfs == 16 || bfs == 32)
720 if (any_active(i2s) && (get_rfs(i2s) != rfs || get_bfs(i2s) != bfs)) {
722 "%s:%d Other DAI busy\n", __func__, __LINE__);
737 "RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
758 if (config_setup(i2s)) {
793 struct i2s_dai *i2s = to_info(dai);
798 if ((any_active(i2s) && div && (get_bfs(i2s) != div))
799 || (other && other->
bfs && (other->
bfs != div))) {
801 "%s:%d Other DAI busy\n", __func__, __LINE__);
808 "Invalid clock divider(%d)\n", div_id);
818 struct i2s_dai *i2s = to_info(dai);
824 else if (is_secondary(i2s))
835 struct i2s_dai *i2s = to_info(dai);
848 struct i2s_dai *i2s = to_info(dai);
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);
868 if (other && other->
clk)
873 dev_err(&i2s->
pdev->dev,
"cannot ioremap registers\n");
878 if (IS_ERR(i2s->
clk)) {
879 dev_err(&i2s->
pdev->dev,
"failed to get i2s_clock\n");
895 i2s->
sec_dai->idma_playback.dma_addr);
908 if (!is_opened(other))
915 static int samsung_i2s_dai_remove(
struct snd_soc_dai *dai)
917 struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
920 if (!other || !other->
clk) {
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)
982 i2s->
pdev = platform_device_register_resndata(
NULL,
985 if (IS_ERR(i2s->
pdev))
997 u32 dma_pl_chan, dma_cp_chan, dma_pl_sec_chan;
1002 u32 regs_base, quirks;
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");
1021 dev_err(&pdev->
dev,
"Unable to get I2S-TX dma resource\n");
1024 dma_pl_chan = res->
start;
1028 dev_err(&pdev->
dev,
"Unable to get I2S-RX dma resource\n");
1031 dma_cp_chan = res->
start;
1035 dma_pl_sec_chan = res->
start;
1037 dma_pl_sec_chan = 0;
1041 dev_err(&pdev->
dev,
"Unable to get I2S SFR address\n");
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");
1073 pri_dai->
base = regs_base;
1074 pri_dai->
quirks = quirks;
1080 sec_dai = i2s_alloc_dai(pdev,
true);
1082 dev_err(&pdev->
dev,
"Unable to alloc I2S_sec\n");
1090 sec_dai->
dma_playback.channel = dma_pl_sec_chan ? : -1;
1093 sec_dai->
base = regs_base;
1094 sec_dai->
quirks = quirks;
1101 dev_err(&pdev->
dev,
"Unable to configure gpio\n");
1129 pm_runtime_disable(&pdev->
dev);
1144 .probe = samsung_i2s_probe,
1147 .name =
"samsung-i2s",