17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/slab.h>
36 #define JZ_REG_AIC_CONF 0x00
37 #define JZ_REG_AIC_CTRL 0x04
38 #define JZ_REG_AIC_I2S_FMT 0x10
39 #define JZ_REG_AIC_FIFO_STATUS 0x14
40 #define JZ_REG_AIC_I2S_STATUS 0x1c
41 #define JZ_REG_AIC_CLK_DIV 0x30
42 #define JZ_REG_AIC_FIFO 0x34
44 #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_MASK (0xf << 12)
45 #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_MASK (0xf << 8)
46 #define JZ_AIC_CONF_OVERFLOW_PLAY_LAST BIT(6)
47 #define JZ_AIC_CONF_INTERNAL_CODEC BIT(5)
48 #define JZ_AIC_CONF_I2S BIT(4)
49 #define JZ_AIC_CONF_RESET BIT(3)
50 #define JZ_AIC_CONF_BIT_CLK_MASTER BIT(2)
51 #define JZ_AIC_CONF_SYNC_CLK_MASTER BIT(1)
52 #define JZ_AIC_CONF_ENABLE BIT(0)
54 #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 12
55 #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 8
57 #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_MASK (0x7 << 19)
58 #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK (0x7 << 16)
59 #define JZ_AIC_CTRL_ENABLE_RX_DMA BIT(15)
60 #define JZ_AIC_CTRL_ENABLE_TX_DMA BIT(14)
61 #define JZ_AIC_CTRL_MONO_TO_STEREO BIT(11)
62 #define JZ_AIC_CTRL_SWITCH_ENDIANNESS BIT(10)
63 #define JZ_AIC_CTRL_SIGNED_TO_UNSIGNED BIT(9)
64 #define JZ_AIC_CTRL_FLUSH BIT(8)
65 #define JZ_AIC_CTRL_ENABLE_ROR_INT BIT(6)
66 #define JZ_AIC_CTRL_ENABLE_TUR_INT BIT(5)
67 #define JZ_AIC_CTRL_ENABLE_RFS_INT BIT(4)
68 #define JZ_AIC_CTRL_ENABLE_TFS_INT BIT(3)
69 #define JZ_AIC_CTRL_ENABLE_LOOPBACK BIT(2)
70 #define JZ_AIC_CTRL_ENABLE_PLAYBACK BIT(1)
71 #define JZ_AIC_CTRL_ENABLE_CAPTURE BIT(0)
73 #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_OFFSET 19
74 #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET 16
76 #define JZ_AIC_I2S_FMT_DISABLE_BIT_CLK BIT(12)
77 #define JZ_AIC_I2S_FMT_ENABLE_SYS_CLK BIT(4)
78 #define JZ_AIC_I2S_FMT_MSB BIT(0)
80 #define JZ_AIC_I2S_STATUS_BUSY BIT(2)
82 #define JZ_AIC_CLK_DIV_MASK 0xf
102 static inline void jz4740_i2s_write(
const struct jz4740_i2s *i2s,
111 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
133 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
149 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
181 static int jz4740_i2s_set_fmt(
struct snd_soc_dai *dai,
unsigned int fmt)
183 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
235 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
248 case SNDRV_PCM_FORMAT_S16:
277 snd_soc_dai_set_dma_data(dai, substream, pcm_config);
282 static int jz4740_i2s_set_sysclk(
struct snd_soc_dai *dai,
int clk_id,
283 unsigned int freq,
int dir)
285 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
307 static int jz4740_i2s_suspend(
struct snd_soc_dai *dai)
309 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
325 static int jz4740_i2s_resume(
struct snd_soc_dai *dai)
327 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
343 static void jz4740_i2c_init_pcm_config(
struct jz4740_i2s *i2s)
366 static int jz4740_i2s_dai_probe(
struct snd_soc_dai *dai)
368 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
373 jz4740_i2c_init_pcm_config(i2s);
387 static int jz4740_i2s_dai_remove(
struct snd_soc_dai *dai)
389 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
396 .startup = jz4740_i2s_startup,
397 .shutdown = jz4740_i2s_shutdown,
398 .trigger = jz4740_i2s_trigger,
399 .hw_params = jz4740_i2s_hw_params,
400 .set_fmt = jz4740_i2s_set_fmt,
401 .set_sysclk = jz4740_i2s_set_sysclk,
404 #define JZ4740_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
405 SNDRV_PCM_FMTBIT_S16_LE)
408 .probe = jz4740_i2s_dai_probe,
409 .remove = jz4740_i2s_dai_remove,
422 .symmetric_rates = 1,
423 .ops = &jz4740_i2s_dai_ops,
424 .suspend = jz4740_i2s_suspend,
425 .resume = jz4740_i2s_resume,
454 goto err_release_mem_region;
468 goto err_clk_put_aic;
471 platform_set_drvdata(pdev, i2s);
475 dev_err(&pdev->
dev,
"Failed to register DAI\n");
476 goto err_clk_put_i2s;
487 err_release_mem_region:
497 struct jz4740_i2s *i2s = platform_get_drvdata(pdev);
507 platform_set_drvdata(pdev,
NULL);
514 .probe = jz4740_i2s_dev_probe,
517 .name =
"jz4740-i2s",