Commit 541ccdc1 authored by Adam Thomson's avatar Adam Thomson Committed by Mark Brown

ASoC: da7219: Update TDM usage to be more flexible

The previous implementatation was restrictive with regards to
BCLK rates for slave mode where the driver would not allow rates
the codec couldn't provide itself as clock master. The codec
is able to automatically determine and handle whatever rate is
provided so this restriction isn't necessary for slave mode. The
code was also flawed with regards to setting of the frame offset
as using rx_mask to explicitly set the offset has the knock on
effect of impacting the min and max channels for the codec, in
soc_pcm_hw_params() through the call to
soc_pcm_codec_params_fixup().

With this update, the driver now only limits frame size if codec
is clock master, and dynamically determines the BCLK offset
relating to WCLK using the tx_mask for slot offset along with the
slot width provided.
Signed-off-by: default avatarAdam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 9fd72954
...@@ -1391,8 +1391,10 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, ...@@ -1391,8 +1391,10 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai,
{ {
struct snd_soc_component *component = dai->component; struct snd_soc_component *component = dai->component;
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component); struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
u8 dai_bclks_per_wclk; unsigned int ch_mask;
__le16 offset; u8 dai_bclks_per_wclk, slot_offset;
u16 offset;
__le16 dai_offset;
u32 frame_size; u32 frame_size;
/* No channels enabled so disable TDM */ /* No channels enabled so disable TDM */
...@@ -1405,20 +1407,30 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, ...@@ -1405,20 +1407,30 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai,
} }
/* Check we have valid slots */ /* Check we have valid slots */
if (fls(tx_mask) > DA7219_DAI_TDM_MAX_SLOTS) { slot_offset = ffs(tx_mask) - 1;
dev_err(component->dev, "Invalid number of slots, max = %d\n", ch_mask = (tx_mask >> slot_offset);
if (fls(ch_mask) > DA7219_DAI_TDM_MAX_SLOTS) {
dev_err(component->dev,
"Invalid number of slots, max = %d\n",
DA7219_DAI_TDM_MAX_SLOTS); DA7219_DAI_TDM_MAX_SLOTS);
return -EINVAL; return -EINVAL;
} }
/* Check we have a valid offset given */ /*
if (rx_mask > DA7219_DAI_OFFSET_MAX) { * Ensure we have a valid offset into the frame, based on slot width
dev_err(component->dev, "Invalid slot offset, max = %d\n", * and slot offset of first slot we're interested in.
DA7219_DAI_OFFSET_MAX); */
offset = slot_offset * slot_width;
if (offset > DA7219_DAI_OFFSET_MAX) {
dev_err(component->dev, "Invalid frame offset %d\n", offset);
return -EINVAL; return -EINVAL;
} }
/* Calculate & validate frame size based on slot info provided. */ /*
* If we're master, calculate & validate frame size based on slot info
* provided as we have a limited set of rates available.
*/
if (da7219->master) {
frame_size = slots * slot_width; frame_size = slots * slot_width;
switch (frame_size) { switch (frame_size) {
case 32: case 32:
...@@ -1434,22 +1446,24 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai, ...@@ -1434,22 +1446,24 @@ static int da7219_set_dai_tdm_slot(struct snd_soc_dai *dai,
dai_bclks_per_wclk = DA7219_DAI_BCLKS_PER_WCLK_256; dai_bclks_per_wclk = DA7219_DAI_BCLKS_PER_WCLK_256;
break; break;
default: default:
dev_err(component->dev, "Invalid frame size %d\n", frame_size); dev_err(component->dev, "Invalid frame size %d\n",
frame_size);
return -EINVAL; return -EINVAL;
} }
snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE, snd_soc_component_update_bits(component, DA7219_DAI_CLK_MODE,
DA7219_DAI_BCLKS_PER_WCLK_MASK, DA7219_DAI_BCLKS_PER_WCLK_MASK,
dai_bclks_per_wclk); dai_bclks_per_wclk);
}
offset = cpu_to_le16(rx_mask); dai_offset = cpu_to_le16(offset);
regmap_bulk_write(da7219->regmap, DA7219_DAI_OFFSET_LOWER, regmap_bulk_write(da7219->regmap, DA7219_DAI_OFFSET_LOWER,
&offset, sizeof(offset)); &dai_offset, sizeof(dai_offset));
snd_soc_component_update_bits(component, DA7219_DAI_TDM_CTRL, snd_soc_component_update_bits(component, DA7219_DAI_TDM_CTRL,
DA7219_DAI_TDM_CH_EN_MASK | DA7219_DAI_TDM_CH_EN_MASK |
DA7219_DAI_TDM_MODE_EN_MASK, DA7219_DAI_TDM_MODE_EN_MASK,
(tx_mask << DA7219_DAI_TDM_CH_EN_SHIFT) | (ch_mask << DA7219_DAI_TDM_CH_EN_SHIFT) |
DA7219_DAI_TDM_MODE_EN_MASK); DA7219_DAI_TDM_MODE_EN_MASK);
da7219->tdm_en = true; da7219->tdm_en = true;
......
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