mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxim Kochetkov <fido_max@inbox.ru>
To: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Benjamin Mugnier" <benjamin.mugnier@foss.st.com>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Claudiu Beznea" <claudiu.beznea@microchip.com>,
	"Charles Keepax" <ckeepax@opensource.cirrus.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] ASoC: codecs: max98090: Allow dsp_a mode
Date: Wed, 21 Jun 2023 22:57:18 +0300	[thread overview]
Message-ID: <08fb24b9-ab7d-da27-5ab7-e1d3270c8b43@inbox.ru> (raw)
In-Reply-To: <c054b036-d5fd-482b-adc4-913edbcd007c@sirena.org.uk>



On 21.06.2023 17:35, Mark Brown wrote:
> To repeat:
> 
>>>> I'm saying there should be some interlock between these two settings, if
>>>> nothing else setting DSP A mode should force TDM mode with automatically
>>>> configured slot sizes.

Ok. How about that:
---
  sound/soc/codecs/max98090.c | 52 ++++++++++++++++++++-----------------
  sound/soc/codecs/max98090.h |  2 ++
  2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 142083b13ac3..c30305269514 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -1582,7 +1582,7 @@ static int max98090_dai_set_fmt(struct snd_soc_dai *codec_dai,
  	struct snd_soc_component *component = codec_dai->component;
  	struct max98090_priv *max98090 = snd_soc_component_get_drvdata(component);
  	struct max98090_cdata *cdata;
-	u8 regval;
+	u8 regval, tdm_regval;

  	max98090->dai_fmt = fmt;
  	cdata = &max98090->dai[0];
@@ -1591,6 +1591,7 @@ static int max98090_dai_set_fmt(struct snd_soc_dai *codec_dai,
  		cdata->fmt = fmt;

  		regval = 0;
+		tdm_regval = 0;
  		switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
  		case SND_SOC_DAIFMT_CBC_CFC:
  			/* Set to consumer mode PLL - MAS mode off */
@@ -1636,7 +1637,8 @@ static int max98090_dai_set_fmt(struct snd_soc_dai *codec_dai,
  			regval |= M98090_RJ_MASK;
  			break;
  		case SND_SOC_DAIFMT_DSP_A:
-			/* Not supported mode */
+			tdm_regval |= M98090_TDM_MASK;
+			break;
  		default:
  			dev_err(component->dev, "DAI format unsupported");
  			return -EINVAL;
@@ -1665,11 +1667,20 @@ static int max98090_dai_set_fmt(struct snd_soc_dai *codec_dai,
  		 * seen for the case of TDM mode. The remaining cases have
  		 * normal logic.
  		 */
-		if (max98090->tdm_slots > 1)
+		if (tdm_regval)
  			regval ^= M98090_BCI_MASK;

  		snd_soc_component_write(component,
  			M98090_REG_INTERFACE_FORMAT, regval);
+
+		regval = 0;
+		if (tdm_regval)
+			regval = max98090->tdm_lslot << M98090_TDM_SLOTL_SHIFT |
+				 max98090->tdm_rslot << M98090_TDM_SLOTR_SHIFT |
+				 0 << M98090_TDM_SLOTDLY_SHIFT;
+
+		snd_soc_component_write(component, M98090_REG_TDM_FORMAT, regval);
+		snd_soc_component_write(component, M98090_REG_TDM_CONTROL, tdm_regval);
  	}

  	return 0;
@@ -1680,33 +1691,23 @@ static int max98090_set_tdm_slot(struct snd_soc_dai *codec_dai,
  {
  	struct snd_soc_component *component = codec_dai->component;
  	struct max98090_priv *max98090 = snd_soc_component_get_drvdata(component);
-	struct max98090_cdata *cdata;
-	cdata = &max98090->dai[0];

  	if (slots < 0 || slots > 4)
  		return -EINVAL;

-	max98090->tdm_slots = slots;
-	max98090->tdm_width = slot_width;
+	if (slot_width != 16)
+		return -EINVAL;

-	if (max98090->tdm_slots > 1) {
-		/* SLOTL SLOTR SLOTDLY */
-		snd_soc_component_write(component, M98090_REG_TDM_FORMAT,
-			0 << M98090_TDM_SLOTL_SHIFT |
-			1 << M98090_TDM_SLOTR_SHIFT |
-			0 << M98090_TDM_SLOTDLY_SHIFT);
-
-		/* FSW TDM */
-		snd_soc_component_update_bits(component, M98090_REG_TDM_CONTROL,
-			M98090_TDM_MASK,
-			M98090_TDM_MASK);
-	}
+	if (rx_mask != tx_mask)
+		return -EINVAL;

-	/*
-	 * Normally advisable to set TDM first, but this permits either order
-	 */
-	cdata->fmt = 0;
-	max98090_dai_set_fmt(codec_dai, max98090->dai_fmt);
+	if (!rx_mask)
+		return -EINVAL;
+
+	max98090->tdm_slots = slots;
+	max98090->tdm_width = slot_width;
+	max98090->tdm_lslot = ffs(rx_mask) - 1;
+	max98090->tdm_rslot = fls(rx_mask) - 1;

  	return 0;
  }
@@ -2411,6 +2412,9 @@ static int max98090_probe(struct snd_soc_component *component)
  	max98090->pa1en = 0;
  	max98090->pa2en = 0;

+	max98090->tdm_lslot = 0;
+	max98090->tdm_rslot = 1;
+
  	ret = snd_soc_component_read(component, M98090_REG_REVISION_ID);
  	if (ret < 0) {
  		dev_err(component->dev, "Failed to read device revision: %d\n",
diff --git a/sound/soc/codecs/max98090.h b/sound/soc/codecs/max98090.h
index a197114b0dad..2d2971acd150 100644
--- a/sound/soc/codecs/max98090.h
+++ b/sound/soc/codecs/max98090.h
@@ -1534,6 +1534,8 @@ struct max98090_priv {
  	unsigned int dai_fmt;
  	int tdm_slots;
  	int tdm_width;
+	int tdm_lslot;
+	int tdm_rslot;
  	u8 lin_state;
  	unsigned int pa1en;
  	unsigned int pa2en;
-- 
2.40.1

  reply	other threads:[~2023-06-21 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 11:53 Maxim Kochetkov
2023-06-21 12:26 ` Mark Brown
2023-06-21 13:02   ` Maxim Kochetkov
2023-06-21 13:18     ` Mark Brown
2023-06-21 13:55       ` Maxim Kochetkov
2023-06-21 14:01         ` Mark Brown
2023-06-21 14:28           ` Maxim Kochetkov
2023-06-21 14:35             ` Mark Brown
2023-06-21 19:57               ` Maxim Kochetkov [this message]
2023-06-21 20:46                 ` Mark Brown
2023-06-22  6:30                   ` Maxim Kochetkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08fb24b9-ab7d-da27-5ab7-e1d3270c8b43@inbox.ru \
    --to=fido_max@inbox.ru \
    --cc=alsa-devel@alsa-project.org \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=broonie@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®