Commit f7c0e14f authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: ak4613: tidyup ak4613_interface

ak4613 driver is assuming symmetric format.
Thus, we don't need to have asymmetric table for judging the
iface at .hw_param.

This patch cleanup ak4613_interface for it.
This is prepare for TDM support.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87ee2cp9lz.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 3407e36d
...@@ -78,14 +78,10 @@ ...@@ -78,14 +78,10 @@
/* OCTRL */ /* OCTRL */
#define OCTRL_MASK (0x3F) #define OCTRL_MASK (0x3F)
struct ak4613_formats { struct ak4613_interface {
unsigned int width; unsigned int width;
unsigned int fmt; unsigned int fmt;
}; u8 dif;
struct ak4613_interface {
struct ak4613_formats capture;
struct ak4613_formats playback;
}; };
struct ak4613_priv { struct ak4613_priv {
...@@ -137,13 +133,22 @@ static const struct reg_default ak4613_reg[] = { ...@@ -137,13 +133,22 @@ static const struct reg_default ak4613_reg[] = {
{ 0x14, 0x00 }, { 0x15, 0x00 }, { 0x16, 0x00 }, { 0x14, 0x00 }, { 0x15, 0x00 }, { 0x16, 0x00 },
}; };
#define AUDIO_IFACE_TO_VAL(fmts) ((fmts - ak4613_iface) << 3) /*
#define AUDIO_IFACE(b, fmt) { b, SND_SOC_DAIFMT_##fmt } * CTRL1 register
* see
* Table 11/12/13/14
*/
#define AUDIO_IFACE(_val, _width, _fmt) \
{ \
.dif = (_val << 3), \
.width = _width, \
.fmt = SND_SOC_DAIFMT_##_fmt,\
}
static const struct ak4613_interface ak4613_iface[] = { static const struct ak4613_interface ak4613_iface[] = {
/* capture */ /* playback */ /* It doesn't support asymmetric format */
/* [0] - [2] are not supported */
[3] = { AUDIO_IFACE(24, LEFT_J), AUDIO_IFACE(24, LEFT_J) }, AUDIO_IFACE(0x03, 24, LEFT_J),
[4] = { AUDIO_IFACE(24, I2S), AUDIO_IFACE(24, I2S) }, AUDIO_IFACE(0x04, 24, I2S),
}; };
static const struct regmap_config ak4613_regmap_cfg = { static const struct regmap_config ak4613_regmap_cfg = {
...@@ -344,20 +349,13 @@ static int ak4613_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) ...@@ -344,20 +349,13 @@ static int ak4613_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
} }
static bool ak4613_dai_fmt_matching(const struct ak4613_interface *iface, static bool ak4613_dai_fmt_matching(const struct ak4613_interface *iface,
int is_play,
unsigned int fmt, unsigned int width) unsigned int fmt, unsigned int width)
{ {
const struct ak4613_formats *fmts; if ((iface->fmt == fmt) &&
(iface->width == width))
fmts = (is_play) ? &iface->playback : &iface->capture; return true;
if (fmts->fmt != fmt) return false;
return false;
if (fmts->width != width)
return false;
return true;
} }
static int ak4613_dai_hw_params(struct snd_pcm_substream *substream, static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
...@@ -371,9 +369,8 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream, ...@@ -371,9 +369,8 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
unsigned int width = params_width(params); unsigned int width = params_width(params);
unsigned int fmt = priv->fmt; unsigned int fmt = priv->fmt;
unsigned int rate; unsigned int rate;
int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
int i, ret; int i, ret;
u8 fmt_ctrl, ctrl2; u8 ctrl2;
rate = params_rate(params); rate = params_rate(params);
switch (rate) { switch (rate) {
...@@ -401,18 +398,16 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream, ...@@ -401,18 +398,16 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
* *
* It doesn't support TDM at this point * It doesn't support TDM at this point
*/ */
fmt_ctrl = NO_FMT;
ret = -EINVAL; ret = -EINVAL;
iface = NULL; iface = NULL;
mutex_lock(&priv->lock); mutex_lock(&priv->lock);
if (priv->iface) { if (priv->iface) {
if (ak4613_dai_fmt_matching(priv->iface, is_play, fmt, width)) if (ak4613_dai_fmt_matching(priv->iface, fmt, width))
iface = priv->iface; iface = priv->iface;
} else { } else {
for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) { for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) {
if (!ak4613_dai_fmt_matching(ak4613_iface + i, if (!ak4613_dai_fmt_matching(ak4613_iface + i,
is_play,
fmt, width)) fmt, width))
continue; continue;
iface = ak4613_iface + i; iface = ak4613_iface + i;
...@@ -430,9 +425,7 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream, ...@@ -430,9 +425,7 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
if (ret < 0) if (ret < 0)
goto hw_params_end; goto hw_params_end;
fmt_ctrl = AUDIO_IFACE_TO_VAL(iface); snd_soc_component_update_bits(component, CTRL1, FMT_MASK, iface->dif);
snd_soc_component_update_bits(component, CTRL1, FMT_MASK, fmt_ctrl);
snd_soc_component_update_bits(component, CTRL2, DFS_MASK, ctrl2); snd_soc_component_update_bits(component, CTRL2, DFS_MASK, ctrl2);
snd_soc_component_update_bits(component, ICTRL, ICTRL_MASK, priv->ic); snd_soc_component_update_bits(component, ICTRL, ICTRL_MASK, priv->ic);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment