2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2025-01-23 22:25:40 +08:00

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: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87ee2cp9lz.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2022-04-05 02:06:17 +00:00 committed by Mark Brown
parent 3407e36dc7
commit f7c0e14f57
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -78,14 +78,10 @@
/* OCTRL */
#define OCTRL_MASK (0x3F)
struct ak4613_formats {
struct ak4613_interface {
unsigned int width;
unsigned int fmt;
};
struct ak4613_interface {
struct ak4613_formats capture;
struct ak4613_formats playback;
u8 dif;
};
struct ak4613_priv {
@ -137,13 +133,22 @@ static const struct reg_default ak4613_reg[] = {
{ 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[] = {
/* capture */ /* playback */
/* [0] - [2] are not supported */
[3] = { AUDIO_IFACE(24, LEFT_J), AUDIO_IFACE(24, LEFT_J) },
[4] = { AUDIO_IFACE(24, I2S), AUDIO_IFACE(24, I2S) },
/* It doesn't support asymmetric format */
AUDIO_IFACE(0x03, 24, LEFT_J),
AUDIO_IFACE(0x04, 24, I2S),
};
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)
}
static bool ak4613_dai_fmt_matching(const struct ak4613_interface *iface,
int is_play,
unsigned int fmt, unsigned int width)
{
const struct ak4613_formats *fmts;
if ((iface->fmt == fmt) &&
(iface->width == width))
return true;
fmts = (is_play) ? &iface->playback : &iface->capture;
if (fmts->fmt != fmt)
return false;
if (fmts->width != width)
return false;
return true;
return false;
}
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 fmt = priv->fmt;
unsigned int rate;
int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
int i, ret;
u8 fmt_ctrl, ctrl2;
u8 ctrl2;
rate = params_rate(params);
switch (rate) {
@ -401,18 +398,16 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
*
* It doesn't support TDM at this point
*/
fmt_ctrl = NO_FMT;
ret = -EINVAL;
iface = NULL;
mutex_lock(&priv->lock);
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;
} else {
for (i = ARRAY_SIZE(ak4613_iface) - 1; i >= 0; i--) {
if (!ak4613_dai_fmt_matching(ak4613_iface + i,
is_play,
fmt, width))
continue;
iface = ak4613_iface + i;
@ -430,9 +425,7 @@ static int ak4613_dai_hw_params(struct snd_pcm_substream *substream,
if (ret < 0)
goto hw_params_end;
fmt_ctrl = AUDIO_IFACE_TO_VAL(iface);
snd_soc_component_update_bits(component, CTRL1, FMT_MASK, fmt_ctrl);
snd_soc_component_update_bits(component, CTRL1, FMT_MASK, iface->dif);
snd_soc_component_update_bits(component, CTRL2, DFS_MASK, ctrl2);
snd_soc_component_update_bits(component, ICTRL, ICTRL_MASK, priv->ic);