#include <linux/reset.h>
#include <linux/slab.h>
#include <linux/pm_runtime.h>
-#include <sound/designware_i2s.h>
+#include <sound/designware_i2s.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
i2s_write_reg(dev->i2s_base, CER, 1);
}
-static void i2s_stop(struct dw_i2s_dev *dev,
- struct snd_pcm_substream *substream)
+static void i2s_pause(struct dw_i2s_dev *dev, struct snd_pcm_substream *substream)
{
i2s_clear_irqs(dev, substream->stream);
- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
- i2s_write_reg(dev->i2s_base, ITER, 0);
- else
- i2s_write_reg(dev->i2s_base, IRER, 0);
if (dev->use_pio || dev->is_jh7110)
i2s_disable_irqs(dev, substream->stream, 8);
if (!dev->active) {
i2s_write_reg(dev->i2s_base, CER, 0);
- i2s_write_reg(dev->i2s_base, IER, 0);
+ /* Keep the device enabled until the shutdown - do not clear IER */
}
}
-static int dw_i2s_startup(struct snd_pcm_substream *substream,
- struct snd_soc_dai *cpu_dai)
+static void i2s_stop(struct dw_i2s_dev *dev, struct snd_pcm_substream *substream)
{
- struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
-
- if (dev->is_jh7110) {
- struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
- struct snd_soc_dai_link *dai_link = rtd->dai_link;
-
- dai_link->trigger_stop = SND_SOC_TRIGGER_ORDER_LDC;
- }
+ i2s_clear_irqs(dev, substream->stream);
- return 0;
+ i2s_disable_irqs(dev, substream->stream, 8);
}
static void dw_i2s_config(struct dw_i2s_dev *dev, int stream)
return 0;
}
+static int dw_i2s_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *cpu_dai)
+{
+ struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
+ union dw_i2s_snd_dma_data *dma_data = NULL;
+ u32 dmacr;
+
+ dev_dbg(dev->dev, "%s(%s)\n", __func__, substream->name);
+ if (!(dev->capability & DWC_I2S_RECORD) &&
+ substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ return -EINVAL;
+
+ if (!(dev->capability & DWC_I2S_PLAY) &&
+ substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+ return -EINVAL;
+
+ dw_i2s_config(dev, substream->stream);
+ dmacr = i2s_read_reg(dev->i2s_base, I2S_DMACR);
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+ dma_data = &dev->play_dma_data;
+ else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
+ dma_data = &dev->capture_dma_data;
+
+ snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)dma_data);
+ i2s_write_reg(dev->i2s_base, I2S_DMACR, dmacr);
+
+ if (dev->is_jh7110) {
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
+ struct snd_soc_dai_link *dai_link = rtd->dai_link;
+
+ dai_link->trigger_stop = SND_SOC_TRIGGER_ORDER_LDC;
+ }
+
+ return 0;
+}
+
+static void dw_i2s_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
+
+ dev_dbg(dev->dev, "%s(%s)\n", __func__, substream->name);
+ i2s_disable_channels(dev, substream->stream);
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+ i2s_write_reg(dev->i2s_base, ITER, 0);
+ else
+ i2s_write_reg(dev->i2s_base, IRER, 0);
+
+ i2s_disable_irqs(dev, substream->stream, 8);
+
+ if (!dev->active) {
+ i2s_write_reg(dev->i2s_base, CER, 0);
+ i2s_write_reg(dev->i2s_base, IER, 0);
+ }
+}
+
static int dw_i2s_prepare(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
i2s_start(dev, substream);
break;
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ dev->active--;
+ i2s_pause(dev, substream);
+ break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
- case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
dev->active--;
i2s_stop(dev, substream);
break;
static const struct snd_soc_dai_ops dw_i2s_dai_ops = {
.probe = dw_i2s_dai_probe,
.startup = dw_i2s_startup,
+ .shutdown = dw_i2s_shutdown,
.hw_params = dw_i2s_hw_params,
.prepare = dw_i2s_prepare,
.trigger = dw_i2s_trigger,