Commit c89e652e authored by David Rau's avatar David Rau Committed by Mark Brown

ASoC: da7213: Add support for mono, set frame width to 32 when possible

This adds the DAI mono mode support and set the frame width to 32
Signed-off-by: default avatarPiotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>
Tested-by: default avatarDavid Rau <David.Rau.opensource@dm.renesas.com>
Signed-off-by: default avatarDavid Rau <David.Rau.opensource@dm.renesas.com>
Link: https://lore.kernel.org/r/20221214044058.6289-1-David.Rau.opensource@dm.renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 3f58ff6b
...@@ -1157,13 +1157,31 @@ static int da7213_hw_params(struct snd_pcm_substream *substream, ...@@ -1157,13 +1157,31 @@ static int da7213_hw_params(struct snd_pcm_substream *substream,
{ {
struct snd_soc_component *component = dai->component; struct snd_soc_component *component = dai->component;
struct da7213_priv *da7213 = snd_soc_component_get_drvdata(component); struct da7213_priv *da7213 = snd_soc_component_get_drvdata(component);
u8 dai_clk_mode = DA7213_DAI_BCLKS_PER_WCLK_64;
u8 dai_ctrl = 0; u8 dai_ctrl = 0;
u8 fs; u8 fs;
/* Set channels */
switch (params_channels(params)) {
case 1:
if (da7213->fmt != DA7213_DAI_FORMAT_DSP) {
dev_err(component->dev, "Mono supported only in DSP mode\n");
return -EINVAL;
}
dai_ctrl |= DA7213_DAI_MONO_MODE_EN;
break;
case 2:
dai_ctrl &= ~(DA7213_DAI_MONO_MODE_EN);
break;
default:
return -EINVAL;
}
/* Set DAI format */ /* Set DAI format */
switch (params_width(params)) { switch (params_width(params)) {
case 16: case 16:
dai_ctrl |= DA7213_DAI_WORD_LENGTH_S16_LE; dai_ctrl |= DA7213_DAI_WORD_LENGTH_S16_LE;
dai_clk_mode = DA7213_DAI_BCLKS_PER_WCLK_32; /* 32bit for 1ch and 2ch */
break; break;
case 20: case 20:
dai_ctrl |= DA7213_DAI_WORD_LENGTH_S20_LE; dai_ctrl |= DA7213_DAI_WORD_LENGTH_S20_LE;
...@@ -1224,8 +1242,11 @@ static int da7213_hw_params(struct snd_pcm_substream *substream, ...@@ -1224,8 +1242,11 @@ static int da7213_hw_params(struct snd_pcm_substream *substream,
return -EINVAL; return -EINVAL;
} }
snd_soc_component_update_bits(component, DA7213_DAI_CTRL, DA7213_DAI_WORD_LENGTH_MASK, snd_soc_component_update_bits(component, DA7213_DAI_CLK_MODE,
dai_ctrl); DA7213_DAI_BCLKS_PER_WCLK_MASK, dai_clk_mode);
snd_soc_component_update_bits(component, DA7213_DAI_CTRL,
DA7213_DAI_WORD_LENGTH_MASK | DA7213_DAI_MONO_MODE_MASK, dai_ctrl);
snd_soc_component_write(component, DA7213_SR, fs); snd_soc_component_write(component, DA7213_SR, fs);
return 0; return 0;
...@@ -1300,19 +1321,24 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) ...@@ -1300,19 +1321,24 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S: case SND_SOC_DAIFMT_I2S:
dai_ctrl |= DA7213_DAI_FORMAT_I2S_MODE; dai_ctrl |= DA7213_DAI_FORMAT_I2S_MODE;
da7213->fmt = DA7213_DAI_FORMAT_I2S_MODE;
break; break;
case SND_SOC_DAIFMT_LEFT_J: case SND_SOC_DAIFMT_LEFT_J:
dai_ctrl |= DA7213_DAI_FORMAT_LEFT_J; dai_ctrl |= DA7213_DAI_FORMAT_LEFT_J;
da7213->fmt = DA7213_DAI_FORMAT_LEFT_J;
break; break;
case SND_SOC_DAIFMT_RIGHT_J: case SND_SOC_DAIFMT_RIGHT_J:
dai_ctrl |= DA7213_DAI_FORMAT_RIGHT_J; dai_ctrl |= DA7213_DAI_FORMAT_RIGHT_J;
da7213->fmt = DA7213_DAI_FORMAT_RIGHT_J;
break; break;
case SND_SOC_DAI_FORMAT_DSP_A: /* L data MSB after FRM LRC */ case SND_SOC_DAI_FORMAT_DSP_A: /* L data MSB after FRM LRC */
dai_ctrl |= DA7213_DAI_FORMAT_DSP; dai_ctrl |= DA7213_DAI_FORMAT_DSP;
dai_offset = 1; dai_offset = 1;
da7213->fmt = DA7213_DAI_FORMAT_DSP;
break; break;
case SND_SOC_DAI_FORMAT_DSP_B: /* L data MSB during FRM LRC */ case SND_SOC_DAI_FORMAT_DSP_B: /* L data MSB during FRM LRC */
dai_ctrl |= DA7213_DAI_FORMAT_DSP; dai_ctrl |= DA7213_DAI_FORMAT_DSP;
da7213->fmt = DA7213_DAI_FORMAT_DSP;
break; break;
default: default:
return -EINVAL; return -EINVAL;
......
...@@ -195,6 +195,8 @@ ...@@ -195,6 +195,8 @@
#define DA7213_DAI_WORD_LENGTH_S24_LE (0x2 << 2) #define DA7213_DAI_WORD_LENGTH_S24_LE (0x2 << 2)
#define DA7213_DAI_WORD_LENGTH_S32_LE (0x3 << 2) #define DA7213_DAI_WORD_LENGTH_S32_LE (0x3 << 2)
#define DA7213_DAI_WORD_LENGTH_MASK (0x3 << 2) #define DA7213_DAI_WORD_LENGTH_MASK (0x3 << 2)
#define DA7213_DAI_MONO_MODE_EN (0x1 << 4)
#define DA7213_DAI_MONO_MODE_MASK (0x1 << 4)
#define DA7213_DAI_EN_SHIFT 7 #define DA7213_DAI_EN_SHIFT 7
/* DA7213_DIG_ROUTING_DAI = 0x21 */ /* DA7213_DIG_ROUTING_DAI = 0x21 */
...@@ -542,6 +544,7 @@ struct da7213_priv { ...@@ -542,6 +544,7 @@ struct da7213_priv {
bool alc_en; bool alc_en;
bool fixed_clk_auto_pll; bool fixed_clk_auto_pll;
struct da7213_platform_data *pdata; struct da7213_platform_data *pdata;
int fmt;
}; };
#endif /* _DA7213_H */ #endif /* _DA7213_H */
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