2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-05-31 11:49:14 +00:00
|
|
|
/*
|
|
|
|
* kirkwood-i2s.c
|
|
|
|
*
|
|
|
|
* (c) 2010 Arnaud Patard <apatard@mandriva.com>
|
2010-09-09 12:10:33 +00:00
|
|
|
* (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
|
2010-05-31 11:49:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mbus.h>
|
|
|
|
#include <linux/delay.h>
|
2012-03-09 08:56:41 +00:00
|
|
|
#include <linux/clk.h>
|
2010-05-31 11:49:14 +00:00
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
2012-08-24 13:21:54 +00:00
|
|
|
#include <linux/platform_data/asoc-kirkwood.h>
|
2013-08-14 10:27:33 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
#include "kirkwood.h"
|
|
|
|
|
|
|
|
#define KIRKWOOD_I2S_FORMATS \
|
|
|
|
(SNDRV_PCM_FMTBIT_S16_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S32_LE)
|
|
|
|
|
2013-11-26 09:41:40 +00:00
|
|
|
#define KIRKWOOD_SPDIF_FORMATS \
|
|
|
|
(SNDRV_PCM_FMTBIT_S16_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE)
|
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
|
|
|
|
unsigned int fmt)
|
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-05-31 11:49:14 +00:00
|
|
|
unsigned long mask;
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
|
|
|
mask = KIRKWOOD_I2S_CTL_RJ;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
mask = KIRKWOOD_I2S_CTL_LJ;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
mask = KIRKWOOD_I2S_CTL_I2S;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set same format for playback and record
|
|
|
|
* This avoids some troubles.
|
|
|
|
*/
|
|
|
|
value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL);
|
|
|
|
value &= ~KIRKWOOD_I2S_CTL_JUST_MASK;
|
|
|
|
value |= mask;
|
|
|
|
writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL);
|
|
|
|
|
|
|
|
value = readl(priv->io+KIRKWOOD_I2S_RECCTL);
|
|
|
|
value &= ~KIRKWOOD_I2S_CTL_JUST_MASK;
|
|
|
|
value |= mask;
|
|
|
|
writel(value, priv->io+KIRKWOOD_I2S_RECCTL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate)
|
|
|
|
{
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
value = KIRKWOOD_DCO_CTL_OFFSET_0;
|
|
|
|
switch (rate) {
|
|
|
|
default:
|
|
|
|
case 44100:
|
|
|
|
value |= KIRKWOOD_DCO_CTL_FREQ_11;
|
|
|
|
break;
|
|
|
|
case 48000:
|
|
|
|
value |= KIRKWOOD_DCO_CTL_FREQ_12;
|
|
|
|
break;
|
|
|
|
case 96000:
|
|
|
|
value |= KIRKWOOD_DCO_CTL_FREQ_24;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writel(value, io + KIRKWOOD_DCO_CTL);
|
|
|
|
|
|
|
|
/* wait for dco locked */
|
|
|
|
do {
|
|
|
|
cpu_relax();
|
|
|
|
value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
|
2012-11-20 12:18:32 +00:00
|
|
|
value &= KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK;
|
2010-05-31 11:49:14 +00:00
|
|
|
} while (value == 0);
|
|
|
|
}
|
|
|
|
|
2012-11-20 12:20:34 +00:00
|
|
|
static void kirkwood_set_rate(struct snd_soc_dai *dai,
|
|
|
|
struct kirkwood_dma_data *priv, unsigned long rate)
|
|
|
|
{
|
|
|
|
uint32_t clks_ctrl;
|
|
|
|
|
2013-10-18 18:34:52 +00:00
|
|
|
if (IS_ERR(priv->extclk)) {
|
2013-07-16 06:47:47 +00:00
|
|
|
/* use internal dco for the supported rates
|
|
|
|
* defined in kirkwood_i2s_dai */
|
2012-11-20 12:20:34 +00:00
|
|
|
dev_dbg(dai->dev, "%s: dco set rate = %lu\n",
|
|
|
|
__func__, rate);
|
|
|
|
kirkwood_set_dco(priv->io, rate);
|
|
|
|
|
|
|
|
clks_ctrl = KIRKWOOD_MCLK_SOURCE_DCO;
|
2013-07-16 06:47:47 +00:00
|
|
|
} else {
|
|
|
|
/* use the external clock for the other rates
|
|
|
|
* defined in kirkwood_i2s_dai_extclk */
|
2012-11-20 12:20:34 +00:00
|
|
|
dev_dbg(dai->dev, "%s: extclk set rate = %lu -> %lu\n",
|
|
|
|
__func__, rate, 256 * rate);
|
|
|
|
clk_set_rate(priv->extclk, 256 * rate);
|
|
|
|
|
|
|
|
clks_ctrl = KIRKWOOD_MCLK_SOURCE_EXTCLK;
|
|
|
|
}
|
|
|
|
writel(clks_ctrl, priv->io + KIRKWOOD_CLOCKS_CTRL);
|
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int kirkwood_i2s_startup(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
|
|
|
struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
|
|
|
|
|
|
|
|
snd_soc_dai_set_dma_data(dai, substream, priv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
|
2012-11-20 12:19:53 +00:00
|
|
|
uint32_t ctl_play, ctl_rec;
|
|
|
|
unsigned int i2s_reg;
|
|
|
|
unsigned long i2s_value;
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
i2s_reg = KIRKWOOD_I2S_PLAYCTL;
|
|
|
|
} else {
|
|
|
|
i2s_reg = KIRKWOOD_I2S_RECCTL;
|
|
|
|
}
|
|
|
|
|
2012-11-20 12:20:34 +00:00
|
|
|
kirkwood_set_rate(dai, priv, params_rate(params));
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
i2s_value = readl(priv->io+i2s_reg);
|
|
|
|
i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Size settings in play/rec i2s control regs and play/rec control
|
|
|
|
* regs must be the same.
|
|
|
|
*/
|
|
|
|
switch (params_format(params)) {
|
|
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
|
|
|
i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16;
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C |
|
2013-10-21 08:50:49 +00:00
|
|
|
KIRKWOOD_PLAYCTL_I2S_EN |
|
|
|
|
KIRKWOOD_PLAYCTL_SPDIF_EN;
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C |
|
2013-10-21 08:50:49 +00:00
|
|
|
KIRKWOOD_RECCTL_I2S_EN |
|
|
|
|
KIRKWOOD_RECCTL_SPDIF_EN;
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* doesn't work... S20_3LE != kirkwood 20bit format ?
|
|
|
|
*
|
|
|
|
case SNDRV_PCM_FORMAT_S20_3LE:
|
|
|
|
i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20;
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_play = KIRKWOOD_PLAYCTL_SIZE_20 |
|
|
|
|
KIRKWOOD_PLAYCTL_I2S_EN;
|
|
|
|
ctl_rec = KIRKWOOD_RECCTL_SIZE_20 |
|
|
|
|
KIRKWOOD_RECCTL_I2S_EN;
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
*/
|
|
|
|
case SNDRV_PCM_FORMAT_S24_LE:
|
|
|
|
i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24;
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 |
|
2013-10-21 08:50:49 +00:00
|
|
|
KIRKWOOD_PLAYCTL_I2S_EN |
|
|
|
|
KIRKWOOD_PLAYCTL_SPDIF_EN;
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_rec = KIRKWOOD_RECCTL_SIZE_24 |
|
2013-10-21 08:50:49 +00:00
|
|
|
KIRKWOOD_RECCTL_I2S_EN |
|
|
|
|
KIRKWOOD_RECCTL_SPDIF_EN;
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
|
|
|
i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32;
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_play = KIRKWOOD_PLAYCTL_SIZE_32 |
|
|
|
|
KIRKWOOD_PLAYCTL_I2S_EN;
|
|
|
|
ctl_rec = KIRKWOOD_RECCTL_SIZE_32 |
|
|
|
|
KIRKWOOD_RECCTL_I2S_EN;
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-07-11 21:28:31 +00:00
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
if (params_channels(params) == 1)
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_play |= KIRKWOOD_PLAYCTL_MONO_BOTH;
|
2010-07-11 21:28:31 +00:00
|
|
|
else
|
2012-11-20 12:19:53 +00:00
|
|
|
ctl_play |= KIRKWOOD_PLAYCTL_MONO_OFF;
|
|
|
|
|
|
|
|
priv->ctl_play &= ~(KIRKWOOD_PLAYCTL_MONO_MASK |
|
2013-08-04 19:26:03 +00:00
|
|
|
KIRKWOOD_PLAYCTL_ENABLE_MASK |
|
2012-11-20 12:19:53 +00:00
|
|
|
KIRKWOOD_PLAYCTL_SIZE_MASK);
|
|
|
|
priv->ctl_play |= ctl_play;
|
|
|
|
} else {
|
2014-06-26 14:23:00 +00:00
|
|
|
priv->ctl_rec &= ~(KIRKWOOD_RECCTL_ENABLE_MASK |
|
|
|
|
KIRKWOOD_RECCTL_SIZE_MASK);
|
2012-11-20 12:19:53 +00:00
|
|
|
priv->ctl_rec |= ctl_rec;
|
2010-07-11 21:28:31 +00:00
|
|
|
}
|
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(i2s_value, priv->io+i2s_reg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-26 14:23:05 +00:00
|
|
|
static unsigned kirkwood_i2s_play_mute(unsigned ctl)
|
|
|
|
{
|
|
|
|
if (!(ctl & KIRKWOOD_PLAYCTL_I2S_EN))
|
|
|
|
ctl |= KIRKWOOD_PLAYCTL_I2S_MUTE;
|
|
|
|
if (!(ctl & KIRKWOOD_PLAYCTL_SPDIF_EN))
|
|
|
|
ctl |= KIRKWOOD_PLAYCTL_SPDIF_MUTE;
|
|
|
|
return ctl;
|
|
|
|
}
|
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream,
|
|
|
|
int cmd, struct snd_soc_dai *dai)
|
|
|
|
{
|
2014-06-26 14:23:20 +00:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2010-03-17 20:15:21 +00:00
|
|
|
struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
|
2012-11-20 12:18:52 +00:00
|
|
|
uint32_t ctl, value;
|
|
|
|
|
|
|
|
ctl = readl(priv->io + KIRKWOOD_PLAYCTL);
|
2014-06-26 14:23:10 +00:00
|
|
|
if ((ctl & KIRKWOOD_PLAYCTL_ENABLE_MASK) == 0) {
|
2012-11-20 12:18:52 +00:00
|
|
|
unsigned timeout = 5000;
|
|
|
|
/*
|
|
|
|
* The Armada510 spec says that if we enter pause mode, the
|
|
|
|
* busy bit must be read back as clear _twice_. Make sure
|
|
|
|
* we respect that otherwise we get DMA underruns.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
value = ctl;
|
|
|
|
ctl = readl(priv->io + KIRKWOOD_PLAYCTL);
|
|
|
|
if (!((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY))
|
|
|
|
break;
|
|
|
|
udelay(1);
|
|
|
|
} while (timeout--);
|
|
|
|
|
|
|
|
if ((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY)
|
|
|
|
dev_notice(dai->dev, "timed out waiting for busy to deassert: %08x\n",
|
|
|
|
ctl);
|
|
|
|
}
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2012-11-20 12:19:53 +00:00
|
|
|
/* configure */
|
|
|
|
ctl = priv->ctl_play;
|
2013-11-25 19:19:05 +00:00
|
|
|
if (dai->id == 0)
|
|
|
|
ctl &= ~KIRKWOOD_PLAYCTL_SPDIF_EN; /* i2s */
|
|
|
|
else
|
|
|
|
ctl &= ~KIRKWOOD_PLAYCTL_I2S_EN; /* spdif */
|
2014-06-26 14:23:05 +00:00
|
|
|
ctl = kirkwood_i2s_play_mute(ctl);
|
2013-08-04 19:26:03 +00:00
|
|
|
value = ctl & ~KIRKWOOD_PLAYCTL_ENABLE_MASK;
|
2012-11-20 12:19:53 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_PLAYCTL);
|
|
|
|
|
|
|
|
/* enable interrupts */
|
2014-06-26 14:23:20 +00:00
|
|
|
if (!runtime->no_period_wakeup) {
|
|
|
|
value = readl(priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES;
|
|
|
|
writel(value, priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
}
|
2010-05-31 11:49:14 +00:00
|
|
|
|
2012-11-20 12:19:53 +00:00
|
|
|
/* enable playback */
|
2012-11-20 12:18:52 +00:00
|
|
|
writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
/* stop audio, disable interrupts */
|
2013-10-21 08:50:49 +00:00
|
|
|
ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
|
|
|
|
KIRKWOOD_PLAYCTL_SPDIF_MUTE;
|
2012-11-20 12:18:52 +00:00
|
|
|
writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
value = readl(priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES;
|
|
|
|
writel(value, priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
|
|
|
|
/* disable all playbacks */
|
2013-08-04 19:26:03 +00:00
|
|
|
ctl &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK;
|
2012-11-20 12:18:52 +00:00
|
|
|
writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2013-10-21 08:50:49 +00:00
|
|
|
ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
|
|
|
|
KIRKWOOD_PLAYCTL_SPDIF_MUTE;
|
2012-11-20 12:18:52 +00:00
|
|
|
writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
2013-10-21 08:50:49 +00:00
|
|
|
ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
|
|
|
|
KIRKWOOD_PLAYCTL_SPDIF_MUTE);
|
2014-06-26 14:23:05 +00:00
|
|
|
ctl = kirkwood_i2s_play_mute(ctl);
|
2012-11-20 12:18:52 +00:00
|
|
|
writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream,
|
|
|
|
int cmd, struct snd_soc_dai *dai)
|
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
|
2012-11-20 12:19:53 +00:00
|
|
|
uint32_t ctl, value;
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
value = readl(priv->io + KIRKWOOD_RECCTL);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2012-11-20 12:19:53 +00:00
|
|
|
/* configure */
|
|
|
|
ctl = priv->ctl_rec;
|
2013-10-21 08:50:49 +00:00
|
|
|
if (dai->id == 0)
|
|
|
|
ctl &= ~KIRKWOOD_RECCTL_SPDIF_EN; /* i2s */
|
|
|
|
else
|
|
|
|
ctl &= ~KIRKWOOD_RECCTL_I2S_EN; /* spdif */
|
|
|
|
|
2014-06-26 14:22:55 +00:00
|
|
|
value = ctl & ~KIRKWOOD_RECCTL_ENABLE_MASK;
|
2012-11-20 12:19:53 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_RECCTL);
|
|
|
|
|
|
|
|
/* enable interrupts */
|
2010-05-31 11:49:14 +00:00
|
|
|
value = readl(priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
value |= KIRKWOOD_INT_CAUSE_REC_BYTES;
|
|
|
|
writel(value, priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
|
2012-11-20 12:19:53 +00:00
|
|
|
/* enable record */
|
|
|
|
writel(ctl, priv->io + KIRKWOOD_RECCTL);
|
2010-05-31 11:49:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
/* stop audio, disable interrupts */
|
|
|
|
value = readl(priv->io + KIRKWOOD_RECCTL);
|
2010-07-11 21:28:32 +00:00
|
|
|
value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE;
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_RECCTL);
|
|
|
|
|
|
|
|
value = readl(priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES;
|
|
|
|
writel(value, priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
|
|
|
|
/* disable all records */
|
|
|
|
value = readl(priv->io + KIRKWOOD_RECCTL);
|
2014-06-26 14:22:55 +00:00
|
|
|
value &= ~KIRKWOOD_RECCTL_ENABLE_MASK;
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_RECCTL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
value = readl(priv->io + KIRKWOOD_RECCTL);
|
2010-07-11 21:28:32 +00:00
|
|
|
value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE;
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_RECCTL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
value = readl(priv->io + KIRKWOOD_RECCTL);
|
2010-07-11 21:28:32 +00:00
|
|
|
value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE);
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_RECCTL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
return kirkwood_i2s_play_trigger(substream, cmd, dai);
|
|
|
|
else
|
|
|
|
return kirkwood_i2s_rec_trigger(substream, cmd, dai);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-21 08:50:49 +00:00
|
|
|
static int kirkwood_i2s_init(struct kirkwood_dma_data *priv)
|
2010-05-31 11:49:14 +00:00
|
|
|
{
|
|
|
|
unsigned long value;
|
|
|
|
unsigned int reg_data;
|
|
|
|
|
|
|
|
/* put system in a "safe" state : */
|
|
|
|
/* disable audio interrupts */
|
|
|
|
writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE);
|
|
|
|
writel(0, priv->io + KIRKWOOD_INT_MASK);
|
|
|
|
|
|
|
|
reg_data = readl(priv->io + 0x1200);
|
|
|
|
reg_data &= (~(0x333FF8));
|
|
|
|
reg_data |= 0x111D18;
|
|
|
|
writel(reg_data, priv->io + 0x1200);
|
|
|
|
|
|
|
|
msleep(500);
|
|
|
|
|
|
|
|
reg_data = readl(priv->io + 0x1200);
|
|
|
|
reg_data &= (~(0x333FF8));
|
|
|
|
reg_data |= 0x111D18;
|
|
|
|
writel(reg_data, priv->io + 0x1200);
|
|
|
|
|
|
|
|
/* disable playback/record */
|
|
|
|
value = readl(priv->io + KIRKWOOD_PLAYCTL);
|
2013-08-04 19:26:03 +00:00
|
|
|
value &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK;
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_PLAYCTL);
|
|
|
|
|
|
|
|
value = readl(priv->io + KIRKWOOD_RECCTL);
|
2014-06-26 14:22:55 +00:00
|
|
|
value &= ~KIRKWOOD_RECCTL_ENABLE_MASK;
|
2010-05-31 11:49:14 +00:00
|
|
|
writel(value, priv->io + KIRKWOOD_RECCTL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-23 10:40:40 +00:00
|
|
|
static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = {
|
2010-03-17 20:15:21 +00:00
|
|
|
.startup = kirkwood_i2s_startup,
|
2010-05-31 11:49:14 +00:00
|
|
|
.trigger = kirkwood_i2s_trigger,
|
|
|
|
.hw_params = kirkwood_i2s_hw_params,
|
|
|
|
.set_fmt = kirkwood_i2s_set_fmt,
|
|
|
|
};
|
|
|
|
|
2013-10-21 08:50:49 +00:00
|
|
|
static struct snd_soc_dai_driver kirkwood_i2s_dai[2] = {
|
|
|
|
{
|
|
|
|
.name = "i2s",
|
|
|
|
.id = 0,
|
|
|
|
.playback = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
|
|
|
|
SNDRV_PCM_RATE_96000,
|
|
|
|
.formats = KIRKWOOD_I2S_FORMATS,
|
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
|
|
|
|
SNDRV_PCM_RATE_96000,
|
|
|
|
.formats = KIRKWOOD_I2S_FORMATS,
|
|
|
|
},
|
|
|
|
.ops = &kirkwood_i2s_dai_ops,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "spdif",
|
|
|
|
.id = 1,
|
2010-05-31 11:49:14 +00:00
|
|
|
.playback = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2013-07-16 09:47:10 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
|
|
|
|
SNDRV_PCM_RATE_96000,
|
2013-11-26 09:41:40 +00:00
|
|
|
.formats = KIRKWOOD_SPDIF_FORMATS,
|
2012-11-20 12:20:34 +00:00
|
|
|
},
|
2010-05-31 11:49:14 +00:00
|
|
|
.capture = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2013-07-16 09:47:10 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
|
|
|
|
SNDRV_PCM_RATE_96000,
|
2013-11-26 09:41:40 +00:00
|
|
|
.formats = KIRKWOOD_SPDIF_FORMATS,
|
2012-11-20 12:20:34 +00:00
|
|
|
},
|
|
|
|
.ops = &kirkwood_i2s_dai_ops,
|
2013-10-21 08:50:49 +00:00
|
|
|
},
|
2012-11-20 12:20:34 +00:00
|
|
|
};
|
|
|
|
|
2013-10-21 08:50:49 +00:00
|
|
|
static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk[2] = {
|
|
|
|
{
|
|
|
|
.name = "i2s",
|
|
|
|
.id = 0,
|
|
|
|
.playback = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2013-11-27 20:10:24 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 5512,
|
|
|
|
.rate_max = 192000,
|
2013-10-21 08:50:49 +00:00
|
|
|
.formats = KIRKWOOD_I2S_FORMATS,
|
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2013-11-27 20:10:24 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 5512,
|
|
|
|
.rate_max = 192000,
|
2013-10-21 08:50:49 +00:00
|
|
|
.formats = KIRKWOOD_I2S_FORMATS,
|
|
|
|
},
|
|
|
|
.ops = &kirkwood_i2s_dai_ops,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "spdif",
|
|
|
|
.id = 1,
|
2012-11-20 12:20:34 +00:00
|
|
|
.playback = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2013-11-27 20:10:24 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 5512,
|
|
|
|
.rate_max = 192000,
|
2013-11-26 09:41:40 +00:00
|
|
|
.formats = KIRKWOOD_SPDIF_FORMATS,
|
2012-11-20 12:20:34 +00:00
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
2013-11-27 20:10:24 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 5512,
|
|
|
|
.rate_max = 192000,
|
2013-11-26 09:41:40 +00:00
|
|
|
.formats = KIRKWOOD_SPDIF_FORMATS,
|
2012-11-20 12:20:34 +00:00
|
|
|
},
|
2010-05-31 11:49:14 +00:00
|
|
|
.ops = &kirkwood_i2s_dai_ops,
|
2013-10-21 08:50:49 +00:00
|
|
|
},
|
2010-05-31 11:49:14 +00:00
|
|
|
};
|
|
|
|
|
2012-12-07 14:26:26 +00:00
|
|
|
static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
|
2010-05-31 11:49:14 +00:00
|
|
|
{
|
2012-11-20 12:20:34 +00:00
|
|
|
struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data;
|
2013-10-21 08:50:49 +00:00
|
|
|
struct snd_soc_dai_driver *soc_dai = kirkwood_i2s_dai;
|
2010-03-17 20:15:21 +00:00
|
|
|
struct kirkwood_dma_data *priv;
|
2013-08-14 10:27:33 +00:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2010-05-31 11:49:14 +00:00
|
|
|
int err;
|
|
|
|
|
2012-11-20 12:19:33 +00:00
|
|
|
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
2017-08-11 07:35:33 +00:00
|
|
|
if (!priv)
|
2012-11-20 12:19:33 +00:00
|
|
|
return -ENOMEM;
|
2017-08-11 07:35:33 +00:00
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
dev_set_drvdata(&pdev->dev, priv);
|
2010-05-31 11:49:14 +00:00
|
|
|
|
2019-07-27 15:07:17 +00:00
|
|
|
priv->io = devm_platform_ioremap_resource(pdev, 0);
|
2013-01-21 10:09:26 +00:00
|
|
|
if (IS_ERR(priv->io))
|
|
|
|
return PTR_ERR(priv->io);
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
priv->irq = platform_get_irq(pdev, 0);
|
2019-07-30 18:15:49 +00:00
|
|
|
if (priv->irq < 0)
|
2017-06-30 21:46:33 +00:00
|
|
|
return priv->irq;
|
2010-05-31 11:49:14 +00:00
|
|
|
|
2013-08-14 10:27:33 +00:00
|
|
|
if (np) {
|
|
|
|
priv->burst = 128; /* might be 32 or 128 */
|
|
|
|
} else if (data) {
|
|
|
|
priv->burst = data->burst;
|
|
|
|
} else {
|
|
|
|
dev_err(&pdev->dev, "no DT nor platform data ?!\n");
|
2012-11-20 12:19:33 +00:00
|
|
|
return -EINVAL;
|
2010-05-31 11:49:14 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 10:27:33 +00:00
|
|
|
priv->clk = devm_clk_get(&pdev->dev, np ? "internal" : NULL);
|
2012-03-09 08:56:41 +00:00
|
|
|
if (IS_ERR(priv->clk)) {
|
|
|
|
dev_err(&pdev->dev, "no clock\n");
|
2012-11-20 12:19:33 +00:00
|
|
|
return PTR_ERR(priv->clk);
|
2012-03-09 08:56:41 +00:00
|
|
|
}
|
2012-11-20 12:19:33 +00:00
|
|
|
|
2013-07-15 15:41:14 +00:00
|
|
|
priv->extclk = devm_clk_get(&pdev->dev, "extclk");
|
2013-09-21 10:00:36 +00:00
|
|
|
if (IS_ERR(priv->extclk)) {
|
|
|
|
if (PTR_ERR(priv->extclk) == -EPROBE_DEFER)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
} else {
|
2015-02-25 14:53:38 +00:00
|
|
|
if (clk_is_match(priv->extclk, priv->clk)) {
|
2013-08-04 19:23:03 +00:00
|
|
|
devm_clk_put(&pdev->dev, priv->extclk);
|
2012-11-20 12:19:53 +00:00
|
|
|
priv->extclk = ERR_PTR(-EINVAL);
|
|
|
|
} else {
|
|
|
|
dev_info(&pdev->dev, "found external clock\n");
|
|
|
|
clk_prepare_enable(priv->extclk);
|
2013-10-24 15:55:18 +00:00
|
|
|
soc_dai = kirkwood_i2s_dai_extclk;
|
2012-11-20 12:19:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-23 13:46:44 +00:00
|
|
|
err = clk_prepare_enable(priv->clk);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2012-11-20 12:19:53 +00:00
|
|
|
/* Some sensible defaults - this reflects the powerup values */
|
|
|
|
priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24;
|
|
|
|
priv->ctl_rec = KIRKWOOD_RECCTL_SIZE_24;
|
|
|
|
|
|
|
|
/* Select the burst size */
|
2013-08-14 10:27:33 +00:00
|
|
|
if (priv->burst == 32) {
|
2012-11-20 12:19:53 +00:00
|
|
|
priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_32;
|
|
|
|
priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_32;
|
|
|
|
} else {
|
|
|
|
priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_128;
|
|
|
|
priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_128;
|
|
|
|
}
|
|
|
|
|
2019-10-23 13:46:49 +00:00
|
|
|
err = snd_soc_register_component(&pdev->dev, &kirkwood_soc_component,
|
2013-10-21 08:50:49 +00:00
|
|
|
soc_dai, 2);
|
2013-08-04 19:27:03 +00:00
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "snd_soc_register_component failed\n");
|
|
|
|
goto err_component;
|
|
|
|
}
|
2012-07-18 22:04:09 +00:00
|
|
|
|
2013-10-21 08:50:49 +00:00
|
|
|
kirkwood_i2s_init(priv);
|
|
|
|
|
2013-08-04 19:27:03 +00:00
|
|
|
return 0;
|
2018-01-29 02:48:03 +00:00
|
|
|
|
2013-08-04 19:27:03 +00:00
|
|
|
err_component:
|
2013-07-15 15:41:14 +00:00
|
|
|
if (!IS_ERR(priv->extclk))
|
2012-11-20 12:20:34 +00:00
|
|
|
clk_disable_unprepare(priv->extclk);
|
2012-07-18 22:04:09 +00:00
|
|
|
clk_disable_unprepare(priv->clk);
|
2012-11-20 12:19:33 +00:00
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:26:26 +00:00
|
|
|
static int kirkwood_i2s_dev_remove(struct platform_device *pdev)
|
2010-05-31 11:49:14 +00:00
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
|
|
|
|
|
2019-10-23 13:46:49 +00:00
|
|
|
snd_soc_unregister_component(&pdev->dev);
|
2013-07-15 15:41:14 +00:00
|
|
|
if (!IS_ERR(priv->extclk))
|
2012-11-20 12:20:34 +00:00
|
|
|
clk_disable_unprepare(priv->extclk);
|
2012-03-09 08:56:41 +00:00
|
|
|
clk_disable_unprepare(priv->clk);
|
2010-03-17 20:15:21 +00:00
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-14 10:27:33 +00:00
|
|
|
#ifdef CONFIG_OF
|
2015-03-18 16:48:58 +00:00
|
|
|
static const struct of_device_id mvebu_audio_of_match[] = {
|
ASoC: kirkwood: change the compatible string of the kirkwood-i2s driver
The compatible string of the kirkwood-i2s driver was chosen as
"marvell,mvebu-audio". Using such a compatible string is not a good
idea, since "mvebu" is the name of a large family of SOCs, in which
new, unknown SOCs will be coming in the future. It is therefore
impossible to know what will be evolutions of this hardware block in
the next generations of the SOCs. For this reason, the recommandation
for compatible strings of on-SOCs devices has always been to use the
name of the oldest SOC that has the hardware block. New SOCs that have
an exactly compatible hardware block can reference it using the same
compatible string. See [1], [2] and [3] for various cases were this
suggestion was made, including from Rob Herring, a Device Tree binding
maintainer.
As an example, there are already small differences between current
generations:
* On Kirkwood, only one interrupt is used for audio.
* On Dove, two interrupts are used, one for audio data and one for
error reporting.
In the near future, I'll be adding audio support to Armada 370, which
allows has the same hardware block (but maybe with minor variants).
Therefore, this patch changes the driver to accept
"marvell,kirkwood-audio" and "marvell,dove-audio" as compatible
strings instead of the too-generic "marvell,mvebu-audio". The reason
for the two different compatible strings is the difference in the
number of interrupts used by the two SOCs for audio.
This Device Tree binding has never been part of a Linux kernel stable
release so far, so it can be changed now without breaking backward
compatibility.
[1] http://lists.infradead.org/pipermail/linux-mtd/2012-March/040417.html
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2013-April/161065.html
[3] http://lists.infradead.org/pipermail/linux-arm-kernel/2012-March/087702.html
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-09-05 12:56:31 +00:00
|
|
|
{ .compatible = "marvell,kirkwood-audio" },
|
|
|
|
{ .compatible = "marvell,dove-audio" },
|
2014-01-30 17:14:06 +00:00
|
|
|
{ .compatible = "marvell,armada370-audio" },
|
2013-08-14 10:27:33 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, mvebu_audio_of_match);
|
|
|
|
#endif
|
|
|
|
|
2010-05-31 11:49:14 +00:00
|
|
|
static struct platform_driver kirkwood_i2s_driver = {
|
|
|
|
.probe = kirkwood_i2s_dev_probe,
|
2012-12-07 14:26:26 +00:00
|
|
|
.remove = kirkwood_i2s_dev_remove,
|
2010-05-31 11:49:14 +00:00
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
2013-08-14 10:27:33 +00:00
|
|
|
.of_match_table = of_match_ptr(mvebu_audio_of_match),
|
2010-05-31 11:49:14 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-24 03:43:09 +00:00
|
|
|
module_platform_driver(kirkwood_i2s_driver);
|
2010-05-31 11:49:14 +00:00
|
|
|
|
|
|
|
/* Module information */
|
2010-09-09 12:10:33 +00:00
|
|
|
MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>");
|
2010-05-31 11:49:14 +00:00
|
|
|
MODULE_DESCRIPTION("Kirkwood I2S SoC Interface");
|
|
|
|
MODULE_LICENSE("GPL");
|
2013-08-04 19:27:03 +00:00
|
|
|
MODULE_ALIAS("platform:mvebu-audio");
|