2 * ALSA SoC Synopsys I2S Audio Layer
4 * sound/soc/dwc/designware_i2s.c
6 * Copyright (C) 2010 ST Microelectronics
7 * Rajeev Kumar <rajeevkumar.linux@gmail.com>
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
14 #include <linux/clk.h>
15 #include <linux/device.h>
16 #include <linux/init.h>
18 #include <linux/interrupt.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/pm_runtime.h>
22 #include <sound/designware_i2s.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/dmaengine_pcm.h>
27 #include <linux/mfd/syscon.h>
28 #include <linux/regmap.h>
29 #include <linux/reset.h>
30 #include "i2srx-master.h"
32 static inline void i2s_write_reg(void __iomem *io_base, int reg, u32 val)
34 writel(val, io_base + reg);
37 static inline u32 i2s_read_reg(void __iomem *io_base, int reg)
39 return readl(io_base + reg);
42 static inline void i2s_disable_channels(struct dw_i2s_dev *dev, u32 stream)
46 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
47 for (i = 0; i < 4; i++)
48 i2s_write_reg(dev->i2s_base, TER(i), 0);
50 for (i = 0; i < 4; i++)
51 i2s_write_reg(dev->i2s_base, RER(i), 0);
55 static inline void i2s_clear_irqs(struct dw_i2s_dev *dev, u32 stream)
59 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
60 for (i = 0; i < 4; i++)
61 i2s_read_reg(dev->i2s_base, TOR(i));
63 for (i = 0; i < 4; i++)
64 i2s_read_reg(dev->i2s_base, ROR(i));
68 static inline void i2s_disable_irqs(struct dw_i2s_dev *dev, u32 stream,
73 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
74 for (i = 0; i < (chan_nr / 2); i++) {
75 irq = i2s_read_reg(dev->i2s_base, IMR(i));
76 i2s_write_reg(dev->i2s_base, IMR(i), irq | 0x30);
79 for (i = 0; i < (chan_nr / 2); i++) {
80 irq = i2s_read_reg(dev->i2s_base, IMR(i));
81 i2s_write_reg(dev->i2s_base, IMR(i), irq | 0x03);
86 static inline void i2s_enable_irqs(struct dw_i2s_dev *dev, u32 stream,
91 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
92 for (i = 0; i < (chan_nr / 2); i++) {
93 irq = i2s_read_reg(dev->i2s_base, IMR(i));
94 i2s_write_reg(dev->i2s_base, IMR(i), irq & ~0x30);
97 for (i = 0; i < (chan_nr / 2); i++) {
98 irq = i2s_read_reg(dev->i2s_base, IMR(i));
99 i2s_write_reg(dev->i2s_base, IMR(i), irq & ~0x03);
104 static irqreturn_t i2s_irq_handler(int irq, void *dev_id)
106 struct dw_i2s_dev *dev = dev_id;
107 bool irq_valid = false;
111 for (i = 0; i < 4; i++)
112 isr[i] = i2s_read_reg(dev->i2s_base, ISR(i));
114 i2s_clear_irqs(dev, SNDRV_PCM_STREAM_PLAYBACK);
115 i2s_clear_irqs(dev, SNDRV_PCM_STREAM_CAPTURE);
117 for (i = 0; i < 4; i++) {
119 * Check if TX fifo is empty. If empty fill FIFO with samples
120 * NOTE: Only two channels supported
122 if ((isr[i] & ISR_TXFE) && (i == 0) && dev->use_pio) {
128 * Data available. Retrieve samples from FIFO
129 * NOTE: Only two channels supported
131 if ((isr[i] & ISR_RXDA) && (i == 0) && dev->use_pio) {
136 /* Error Handling: TX */
137 if (isr[i] & ISR_TXFO) {
138 dev_err(dev->dev, "TX overrun (ch_id=%d)\n", i);
142 /* Error Handling: TX */
143 if (isr[i] & ISR_RXFO) {
144 dev_err(dev->dev, "RX overrun (ch_id=%d)\n", i);
155 static void i2s_start(struct dw_i2s_dev *dev,
156 struct snd_pcm_substream *substream)
158 struct i2s_clk_config_data *config = &dev->config;
160 i2s_write_reg(dev->i2s_base, IER, 1);
161 i2s_enable_irqs(dev, substream->stream, config->chan_nr);
163 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
164 i2s_write_reg(dev->i2s_base, ITER, 1);
166 i2s_write_reg(dev->i2s_base, IRER, 1);
168 i2s_write_reg(dev->i2s_base, CER, 1);
172 static void i2s_stop(struct dw_i2s_dev *dev,
173 struct snd_pcm_substream *substream)
176 i2s_clear_irqs(dev, substream->stream);
177 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
178 i2s_write_reg(dev->i2s_base, ITER, 0);
180 i2s_write_reg(dev->i2s_base, IRER, 0);
182 i2s_disable_irqs(dev, substream->stream, 8);
185 i2s_write_reg(dev->i2s_base, CER, 0);
186 i2s_write_reg(dev->i2s_base, IER, 0);
190 static void dw_i2s_config(struct dw_i2s_dev *dev, int stream)
193 struct i2s_clk_config_data *config = &dev->config;
196 i2s_disable_channels(dev, stream);
198 for (ch_reg = 0; ch_reg < (config->chan_nr / 2); ch_reg++) {
199 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
200 i2s_write_reg(dev->i2s_base, TCR(ch_reg),
201 dev->xfer_resolution);
202 i2s_write_reg(dev->i2s_base, TFCR(ch_reg),
204 i2s_write_reg(dev->i2s_base, TER(ch_reg), 1);
206 i2s_write_reg(dev->i2s_base, RCR(ch_reg),
207 dev->xfer_resolution);
208 i2s_write_reg(dev->i2s_base, RFCR(ch_reg),
210 i2s_write_reg(dev->i2s_base, RER(ch_reg), 1);
216 static int dw_i2s_hw_params(struct snd_pcm_substream *substream,
217 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
219 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
220 struct i2s_clk_config_data *config = &dev->config;
222 unsigned int bclk_rate;
223 union dw_i2s_snd_dma_data *dma_data = NULL;
225 switch (params_format(params)) {
226 case SNDRV_PCM_FORMAT_S16_LE:
227 config->data_width = 16;
229 dev->xfer_resolution = 0x02;
230 dev->capture_dma_data.dt.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
233 /* There is a issue with hardware while using 24-bit */
235 case SNDRV_PCM_FORMAT_S24_LE:
236 config->data_width = 24;
238 dev->xfer_resolution = 0x04;
239 dev->capture_dma_data.dt.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
243 case SNDRV_PCM_FORMAT_S32_LE:
244 config->data_width = 32;
246 dev->xfer_resolution = 0x05;
247 dev->capture_dma_data.dt.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
251 dev_err(dev->dev, "designware-i2s: unsupported PCM fmt");
255 switch (params_rate(params)) {
266 dev_err(dai->dev, "%d rate not supported\n",
267 params_rate(params));
271 config->chan_nr = params_channels(params);
273 switch (config->chan_nr) {
274 case EIGHT_CHANNEL_SUPPORT:
275 case SIX_CHANNEL_SUPPORT:
276 case FOUR_CHANNEL_SUPPORT:
277 case TWO_CHANNEL_SUPPORT:
280 dev_err(dev->dev, "channel not supported\n");
284 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
285 dma_data = &dev->capture_dma_data;
286 snd_soc_dai_set_dma_data(dai, substream, (void *)dma_data);
288 dw_i2s_config(dev, substream->stream);
290 i2s_write_reg(dev->i2s_base, CCR, dev->ccr);
292 config->sample_rate = params_rate(params);
295 if (dev->capability & DW_I2S_MASTER) {
296 if (dev->i2s_clk_cfg) {
297 ret = dev->i2s_clk_cfg(config);
299 dev_err(dev->dev, "runtime audio clk config fail\n");
303 ret = clk_set_rate(dev->clk_i2srx_bclk_mst, bclk_rate);
305 dev_err(dev->dev, "Can't set i2s bclk: %d\n", ret);
313 static int dw_i2s_prepare(struct snd_pcm_substream *substream,
314 struct snd_soc_dai *dai)
316 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
318 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
319 i2s_write_reg(dev->i2s_base, TXFFR, 1);
321 i2s_write_reg(dev->i2s_base, RXFFR, 1);
326 static int dw_i2s_trigger(struct snd_pcm_substream *substream,
327 int cmd, struct snd_soc_dai *dai)
329 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
333 case SNDRV_PCM_TRIGGER_START:
334 case SNDRV_PCM_TRIGGER_RESUME:
335 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
337 i2s_start(dev, substream);
340 case SNDRV_PCM_TRIGGER_STOP:
341 case SNDRV_PCM_TRIGGER_SUSPEND:
342 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
344 i2s_stop(dev, substream);
353 static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
355 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
358 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
359 case SND_SOC_DAIFMT_CBM_CFM:
360 if (dev->capability & DW_I2S_SLAVE)
365 case SND_SOC_DAIFMT_CBS_CFS:
366 if (dev->capability & DW_I2S_MASTER)
371 case SND_SOC_DAIFMT_CBM_CFS:
372 case SND_SOC_DAIFMT_CBS_CFM:
376 dev_dbg(dev->dev, "dwc : Invalid master/slave format\n");
383 static const struct snd_soc_dai_ops dw_i2s_dai_ops = {
384 .hw_params = dw_i2s_hw_params,
385 .prepare = dw_i2s_prepare,
386 .trigger = dw_i2s_trigger,
387 .set_fmt = dw_i2s_set_fmt,
391 static int dw_i2s_runtime_suspend(struct device *dev)
393 struct dw_i2s_dev *dw_dev = dev_get_drvdata(dev);
395 if (dw_dev->capability & DW_I2S_MASTER) {
396 clk_disable_unprepare(dw_dev->clk_i2srx_lrck);
397 clk_disable_unprepare(dw_dev->clk_i2srx_bclk);
403 static int dw_i2s_runtime_resume(struct device *dev)
405 struct dw_i2s_dev *dw_dev = dev_get_drvdata(dev);
408 if (dw_dev->capability & DW_I2S_MASTER) {
409 ret = clk_prepare_enable(dw_dev->clk_i2srx_bclk);
411 dev_err(dw_dev->dev, "Failed to enable clk_i2srx_3ch_bclk\n");
415 ret = clk_prepare_enable(dw_dev->clk_i2srx_lrck);
417 dev_err(dw_dev->dev, "Failed to enable clk_i2srx_3ch_lrck\n");
425 static int dw_i2s_suspend(struct snd_soc_component *component)
427 struct dw_i2s_dev *dev = snd_soc_component_get_drvdata(component);
429 if (dev->capability & DW_I2S_MASTER) {
430 clk_disable_unprepare(dev->clk_i2srx_lrck);
431 clk_disable_unprepare(dev->clk_i2srx_bclk);
437 static int dw_i2s_resume(struct snd_soc_component *component)
439 struct dw_i2s_dev *dev = snd_soc_component_get_drvdata(component);
440 struct snd_soc_dai *dai;
444 if (dev->capability & DW_I2S_MASTER) {
445 ret = clk_prepare_enable(dev->clk_i2srx_bclk);
447 dev_err(dev->dev, "Failed to enable clk_i2srx_3ch_bclk\n");
451 ret = clk_prepare_enable(dev->clk_i2srx_lrck);
453 dev_err(dev->dev, "Failed to enable clk_i2srx_3ch_lrck\n");
458 for_each_component_dais(component, dai) {
459 for_each_pcm_streams(stream)
460 if (snd_soc_dai_stream_active(dai, stream))
461 dw_i2s_config(dev, stream);
468 #define dw_i2s_suspend NULL
469 #define dw_i2s_resume NULL
472 static const struct snd_soc_component_driver dw_i2s_component = {
474 .suspend = dw_i2s_suspend,
475 .resume = dw_i2s_resume,
478 static int dw_i2srx_clk_init(struct platform_device *pdev, struct dw_i2s_dev *dev)
482 static struct clk_bulk_data clks[] = {
484 { .id = "i2srx_apb" },
485 { .id = "i2srx_bclk_mst" },
486 { .id = "i2srx_lrck_mst" },
487 { .id = "i2srx_bclk" },
488 { .id = "i2srx_lrck" },
491 ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(clks), clks);
493 dev_err(&pdev->dev, "%s: failed to get i2srx clocks\n", __func__);
497 dev->clk_apb0 = clks[0].clk;
498 dev->clk_i2srx_apb = clks[1].clk;
499 dev->clk_i2srx_bclk_mst = clks[2].clk;
500 dev->clk_i2srx_lrck_mst = clks[3].clk;
501 dev->clk_i2srx_bclk = clks[4].clk;
502 dev->clk_i2srx_lrck = clks[5].clk;
504 dev->rst_i2srx_apb = devm_reset_control_get_exclusive(&pdev->dev, "rst_apb_rx");
505 if (IS_ERR(dev->rst_i2srx_apb)) {
506 dev_err(&pdev->dev, "failed to get apb_i2srx reset control\n");
507 ret = PTR_ERR(dev->rst_i2srx_apb);
511 dev->rst_i2srx_bclk = devm_reset_control_get_exclusive(&pdev->dev, "rst_bclk_rx");
512 if (IS_ERR(dev->rst_i2srx_bclk)) {
513 dev_err(&pdev->dev, "failed to get i2s bclk rx reset control\n");
514 ret = PTR_ERR(dev->rst_i2srx_bclk);
518 reset_control_assert(dev->rst_i2srx_apb);
519 reset_control_assert(dev->rst_i2srx_bclk);
521 ret = clk_prepare_enable(dev->clk_apb0);
523 dev_err(&pdev->dev, "failed to prepare enable clk_apb0\n");
527 ret = clk_prepare_enable(dev->clk_i2srx_apb);
529 dev_err(&pdev->dev, "failed to prepare enable clk_i2srx_apb\n");
530 goto err_dis_i2srx_apb;
533 ret = clk_prepare_enable(dev->clk_i2srx_bclk_mst);
535 dev_err(&pdev->dev, "failed to prepare enable clk_i2srx_3ch_bclk_mst\n");
536 goto err_dis_bclk_mst;
539 ret = clk_prepare_enable(dev->clk_i2srx_lrck_mst);
541 dev_err(&pdev->dev, "failed to prepare enable clk_i2srx_3ch_lrck_mst\n");
542 goto err_dis_lrck_mst;
545 ret = clk_prepare_enable(dev->clk_i2srx_bclk);
547 dev_err(&pdev->dev, "failed to prepare enable clk_i2srx_3ch_bclk\n");
551 ret = clk_prepare_enable(dev->clk_i2srx_lrck);
553 dev_err(&pdev->dev, "failed to prepare enable clk_i2srx_3ch_lrck\n");
557 reset_control_deassert(dev->rst_i2srx_apb);
558 reset_control_deassert(dev->rst_i2srx_bclk);
560 regmap_update_bits(dev->syscon_base, dev->syscon_offset_18,
561 I2SRX_3CH_ADC_MASK, I2SRX_3CH_ADC_EN);
565 clk_disable_unprepare(dev->clk_apb0);
567 clk_disable_unprepare(dev->clk_i2srx_apb);
569 clk_disable_unprepare(dev->clk_i2srx_bclk_mst);
571 clk_disable_unprepare(dev->clk_i2srx_lrck_mst);
573 clk_disable_unprepare(dev->clk_i2srx_bclk);
579 * The following tables allow a direct lookup of various parameters
580 * defined in the I2S block's configuration in terms of sound system
581 * parameters. Each table is sized to the number of entries possible
582 * according to the number of configuration bits describing an I2S
586 /* Maximum bit resolution of a channel - not uniformly spaced */
587 static const u32 fifo_width[COMP_MAX_WORDSIZE] = {
588 12, 16, 20, 24, 32, 0, 0, 0
591 /* Width of (DMA) bus */
592 static const u32 bus_widths[COMP_MAX_DATA_WIDTH] = {
593 DMA_SLAVE_BUSWIDTH_1_BYTE,
594 DMA_SLAVE_BUSWIDTH_2_BYTES,
595 DMA_SLAVE_BUSWIDTH_4_BYTES,
596 DMA_SLAVE_BUSWIDTH_UNDEFINED
599 /* PCM format to support channel resolution */
600 static const u32 formats[COMP_MAX_WORDSIZE] = {
601 SNDRV_PCM_FMTBIT_S16_LE,
602 SNDRV_PCM_FMTBIT_S16_LE,
603 SNDRV_PCM_FMTBIT_S24_LE,
604 SNDRV_PCM_FMTBIT_S24_LE,
605 SNDRV_PCM_FMTBIT_S32_LE,
611 #define SF_IIS_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
612 SNDRV_PCM_FMTBIT_S32_LE)
614 static int dw_configure_dai(struct dw_i2s_dev *dev,
615 struct snd_soc_dai_driver *dw_i2s_dai,
619 * Read component parameter registers to extract
620 * the I2S block's configuration.
622 u32 comp1 = i2s_read_reg(dev->i2s_base, dev->i2s_reg_comp1);
623 u32 comp2 = i2s_read_reg(dev->i2s_base, dev->i2s_reg_comp2);
624 u32 fifo_depth = 1 << (1 + COMP1_FIFO_DEPTH_GLOBAL(comp1));
627 if (dev->capability & DWC_I2S_RECORD &&
628 dev->quirks & DW_I2S_QUIRK_COMP_PARAM1)
629 comp1 = comp1 & ~BIT(5);
631 if (dev->capability & DWC_I2S_PLAY &&
632 dev->quirks & DW_I2S_QUIRK_COMP_PARAM1)
633 comp1 = comp1 & ~BIT(6);
635 if (COMP1_TX_ENABLED(comp1)) {
636 dev_dbg(dev->dev, " designware: play supported\n");
637 idx = COMP1_TX_WORDSIZE_0(comp1);
638 if (WARN_ON(idx >= ARRAY_SIZE(formats)))
640 if (dev->quirks & DW_I2S_QUIRK_16BIT_IDX_OVERRIDE)
642 dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM;
643 dw_i2s_dai->playback.channels_max =
644 1 << (COMP1_TX_CHANNELS(comp1) + 1);
645 dw_i2s_dai->playback.formats = formats[idx];
646 dw_i2s_dai->playback.rates = rates;
649 if (COMP1_RX_ENABLED(comp1)) {
650 dev_dbg(dev->dev, "designware: record supported\n");
651 idx = COMP2_RX_WORDSIZE_0(comp2);
652 if (WARN_ON(idx >= ARRAY_SIZE(formats)))
654 if (dev->quirks & DW_I2S_QUIRK_16BIT_IDX_OVERRIDE)
656 dw_i2s_dai->capture.channels_min = MIN_CHANNEL_NUM;
657 dw_i2s_dai->capture.channels_max =
658 1 << (COMP1_RX_CHANNELS(comp1) + 1);
659 dw_i2s_dai->capture.formats = SF_IIS_FORMATS;
660 dw_i2s_dai->capture.rates = rates;
663 dev_dbg(dev->dev, "designware: i2s master mode supported\n");
664 dev->capability |= DW_I2S_MASTER;
665 dev->fifo_th = fifo_depth / 2;
669 static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev,
670 struct snd_soc_dai_driver *dw_i2s_dai,
671 struct resource *res)
673 u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
674 u32 comp2 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_2);
675 u32 fifo_depth = 1 << (1 + COMP1_FIFO_DEPTH_GLOBAL(comp1));
676 u32 idx = COMP1_APB_DATA_WIDTH(comp1);
680 if (WARN_ON(idx >= ARRAY_SIZE(bus_widths)))
683 ret = dw_configure_dai(dev, dw_i2s_dai, SNDRV_PCM_RATE_8000_192000);
687 if (COMP1_TX_ENABLED(comp1)) {
688 idx2 = COMP1_TX_WORDSIZE_0(comp1);
690 dev->capability |= DWC_I2S_PLAY;
691 dev->play_dma_data.dt.addr = res->start + I2S_TXDMA;
692 dev->play_dma_data.dt.addr_width = bus_widths[idx];
693 dev->play_dma_data.dt.fifo_size = fifo_depth *
694 (fifo_width[idx2]) >> 8;
695 dev->play_dma_data.dt.maxburst = 16;
697 if (COMP1_RX_ENABLED(comp1)) {
698 idx2 = COMP2_RX_WORDSIZE_0(comp2);
700 /* force change to 1 */
703 dev->capability |= DWC_I2S_RECORD;
704 dev->capture_dma_data.dt.addr = res->start + I2S_RXDMA;
705 dev->capture_dma_data.dt.addr_width = bus_widths[idx];
706 dev->capture_dma_data.dt.fifo_size = fifo_depth *
707 (fifo_width[idx2] >> 8);
708 dev->capture_dma_data.dt.maxburst = 16;
715 static int dw_i2s_dai_probe(struct snd_soc_dai *dai)
717 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
719 snd_soc_dai_init_dma_data(dai, &dev->play_dma_data, &dev->capture_dma_data);
723 static int dw_i2s_probe(struct platform_device *pdev)
725 const struct i2s_platform_data *pdata = pdev->dev.platform_data;
726 struct device_node *np = pdev->dev.of_node;
727 struct of_phandle_args args;
728 struct dw_i2s_dev *dev;
729 struct resource *res;
731 struct snd_soc_dai_driver *dw_i2s_dai;
734 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
738 dw_i2s_dai = devm_kzalloc(&pdev->dev, sizeof(*dw_i2s_dai), GFP_KERNEL);
743 dw_i2s_dai->ops = &dw_i2s_dai_ops;
744 dw_i2s_dai->probe = dw_i2s_dai_probe;
746 dev->i2s_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
747 if (IS_ERR(dev->i2s_base))
748 return PTR_ERR(dev->i2s_base);
750 dev->dev = &pdev->dev;
752 ret = of_parse_phandle_with_fixed_args(dev->dev->of_node,
753 "starfive,sys-syscon", 2, 0, &args);
755 dev_err(dev->dev, "Failed to parse starfive,sys-syscon\n");
759 dev->syscon_base = syscon_node_to_regmap(args.np);
760 of_node_put(args.np);
761 if (IS_ERR(dev->syscon_base))
762 return PTR_ERR(dev->syscon_base);
764 dev->syscon_offset_18 = args.args[0];
765 dev->syscon_offset_34 = args.args[1];
767 irq = platform_get_irq_optional(pdev, 0);
769 ret = devm_request_irq(&pdev->dev, irq, i2s_irq_handler, 0,
772 dev_err(&pdev->dev, "failed to request irq\n");
777 if (of_device_is_compatible(np, "starfive,jh7110-i2srx-master")) {
778 /* config i2s data source: PDM */
779 regmap_update_bits(dev->syscon_base, dev->syscon_offset_34,
780 AUDIO_SDIN_MUX_MASK, I2SRX_DATA_SRC_PDM);
782 ret = dw_i2srx_clk_init(pdev, dev);
784 goto err_clk_disable;
787 dev->i2s_reg_comp1 = I2S_COMP_PARAM_1;
788 dev->i2s_reg_comp2 = I2S_COMP_PARAM_2;
790 clk_id = "i2srx_bclk";
791 ret = dw_configure_dai_by_dt(dev, dw_i2s_dai, res);
795 if (dev->capability & DW_I2S_MASTER) {
797 dev->i2s_clk_cfg = pdata->i2s_clk_cfg;
798 if (!dev->i2s_clk_cfg) {
799 dev_err(&pdev->dev, "no clock configure method\n");
805 dev_set_drvdata(&pdev->dev, dev);
806 ret = devm_snd_soc_register_component(&pdev->dev, &dw_i2s_component,
809 dev_err(&pdev->dev, "not able to register dai\n");
810 goto err_clk_disable;
815 ret = dw_pcm_register(pdev);
818 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL,
820 dev->use_pio = false;
824 dev_err(&pdev->dev, "could not register pcm: %d\n",
826 goto err_clk_disable;
830 pm_runtime_enable(&pdev->dev);
834 if (dev->capability & DW_I2S_MASTER)
835 clk_disable_unprepare(dev->clk_i2srx_bclk_mst);
839 static int dw_i2s_remove(struct platform_device *pdev)
841 struct dw_i2s_dev *dev = dev_get_drvdata(&pdev->dev);
843 if (dev->capability & DW_I2S_MASTER)
844 clk_disable_unprepare(dev->clk_i2srx_bclk_mst);
846 pm_runtime_disable(&pdev->dev);
851 static const struct of_device_id dw_i2s_of_match[] = {
852 { .compatible = "starfive,jh7110-i2srx-master", },
856 MODULE_DEVICE_TABLE(of, dw_i2s_of_match);
859 static const struct dev_pm_ops dwc_pm_ops = {
860 SET_RUNTIME_PM_OPS(dw_i2s_runtime_suspend, dw_i2s_runtime_resume, NULL)
863 static struct platform_driver dw_i2s_driver = {
864 .probe = dw_i2s_probe,
865 .remove = dw_i2s_remove,
867 .name = "i2srx-master",
868 .of_match_table = of_match_ptr(dw_i2s_of_match),
873 module_platform_driver(dw_i2s_driver);
875 MODULE_AUTHOR("Rajeev Kumar <rajeevkumar.linux@gmail.com>");
876 MODULE_AUTHOR("Walker Chen <walker.chen@starfivetech.com>");
877 MODULE_DESCRIPTION("DESIGNWARE I2S SoC Interface");
878 MODULE_LICENSE("GPL");
879 MODULE_ALIAS("platform:designware_i2s");