All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolin Chen <nicoleotsuka@gmail.com>
To: timur@tabi.org, broonie@kernel.org, mail@maciej.szmigiero.name
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	alsa-devel@alsa-project.org, lgirdwood@gmail.com,
	fabio.estevam@nxp.com, caleb@crome.org,
	arnaud.mouiche@invoxia.com, lukma@denx.de, kernel@pengutronix.de
Subject: [PATCH v3 14/17] ASoC: fsl_ssi: Clean up _fsl_ssi_set_dai_fmt()
Date: Sun, 14 Jan 2018 20:21:24 -0800	[thread overview]
Message-ID: <1515990087-11598-15-git-send-email-nicoleotsuka@gmail.com> (raw)
In-Reply-To: <1515990087-11598-1-git-send-email-nicoleotsuka@gmail.com>

The _fsl_ssi_set_dai_fmt() is a helper function being called from
fsl_ssi_set_dai_fmt() as an ASoC operation and fsl_ssi_hw_init()
mainly for AC97 format initialization.

This patch cleans the _fsl_ssi_set_dai_fmt() in following ways:
* Removing *dev pointer in the parameters as it's included in the
  *ssi pointer of struct fsl_ssi.
* Using regmap_update_bits() instead of regmap_read() with masking
  the value manually.
* Removing TXBIT0 configurations since this bit is set to 1 as its
  reset value and there is no use case so far to unset it. And it
  is safe to remove since regmap_update_bits() won't touch it.
* Moving baudclk check to the switch-case routine to skip the I2S
  master check. And moving SxCCR.DC settings after baudclk check.
* Adding format settings for SND_SOC_DAIFMT_AC97 like others.

Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
Tested-by: Caleb Crome <caleb@crome.org>
---
Changelog
v3
 * Put CBM_CFS behind the baudclk check to keep the same program
   flow as before

 sound/soc/fsl/fsl_ssi.c | 73 ++++++++++++++++++++++---------------------------
 1 file changed, 33 insertions(+), 40 deletions(-)

diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index ebb3eb9..9ff6734 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -860,42 +860,28 @@ static int fsl_ssi_hw_free(struct snd_pcm_substream *substream,
 	return 0;
 }
 
-static int _fsl_ssi_set_dai_fmt(struct device *dev,
-				struct fsl_ssi *ssi, unsigned int fmt)
+static int _fsl_ssi_set_dai_fmt(struct fsl_ssi *ssi, unsigned int fmt)
 {
-	struct regmap *regs = ssi->regs;
-	u32 strcr = 0, stcr, srcr, scr, mask;
+	u32 strcr = 0, scr = 0, stcr, srcr, mask;
 
 	ssi->dai_fmt = fmt;
 
-	if (fsl_ssi_is_i2s_master(ssi) && IS_ERR(ssi->baudclk)) {
-		dev_err(dev, "missing baudclk for master mode\n");
-		return -EINVAL;
-	}
-
-	regmap_read(regs, REG_SSI_SCR, &scr);
-	scr &= ~(SSI_SCR_SYN | SSI_SCR_I2S_MODE_MASK);
 	/* Synchronize frame sync clock for TE to avoid data slipping */
 	scr |= SSI_SCR_SYNC_TX_FS;
 
-	mask = SSI_STCR_TXBIT0 | SSI_STCR_TFDIR | SSI_STCR_TXDIR |
-	       SSI_STCR_TSCKP | SSI_STCR_TFSI | SSI_STCR_TFSL | SSI_STCR_TEFS;
-	regmap_read(regs, REG_SSI_STCR, &stcr);
-	regmap_read(regs, REG_SSI_SRCR, &srcr);
-	stcr &= ~mask;
-	srcr &= ~mask;
-
 	/* Use Network mode as default */
 	ssi->i2s_net = SSI_SCR_NET;
 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_I2S:
-		regmap_update_bits(regs, REG_SSI_STCCR,
-				   SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(2));
-		regmap_update_bits(regs, REG_SSI_SRCCR,
-				   SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(2));
 		switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
-		case SND_SOC_DAIFMT_CBM_CFS:
 		case SND_SOC_DAIFMT_CBS_CFS:
+			if (IS_ERR(ssi->baudclk)) {
+				dev_err(ssi->dev,
+					"missing baudclk for master mode\n");
+				return -EINVAL;
+			}
+			/* fall through */
+		case SND_SOC_DAIFMT_CBM_CFS:
 			ssi->i2s_net |= SSI_SCR_I2S_MODE_MASTER;
 			break;
 		case SND_SOC_DAIFMT_CBM_CFM:
@@ -905,30 +891,34 @@ static int _fsl_ssi_set_dai_fmt(struct device *dev,
 			return -EINVAL;
 		}
 
+		regmap_update_bits(ssi->regs, REG_SSI_STCCR,
+				   SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(2));
+		regmap_update_bits(ssi->regs, REG_SSI_SRCCR,
+				   SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(2));
+
 		/* Data on rising edge of bclk, frame low, 1clk before data */
-		strcr |= SSI_STCR_TFSI | SSI_STCR_TSCKP |
-			 SSI_STCR_TXBIT0 | SSI_STCR_TEFS;
+		strcr |= SSI_STCR_TFSI | SSI_STCR_TSCKP | SSI_STCR_TEFS;
 		break;
 	case SND_SOC_DAIFMT_LEFT_J:
 		/* Data on rising edge of bclk, frame high */
-		strcr |= SSI_STCR_TXBIT0 | SSI_STCR_TSCKP;
+		strcr |= SSI_STCR_TSCKP;
 		break;
 	case SND_SOC_DAIFMT_DSP_A:
 		/* Data on rising edge of bclk, frame high, 1clk before data */
-		strcr |= SSI_STCR_TFSL | SSI_STCR_TSCKP |
-			 SSI_STCR_TXBIT0 | SSI_STCR_TEFS;
+		strcr |= SSI_STCR_TFSL | SSI_STCR_TSCKP | SSI_STCR_TEFS;
 		break;
 	case SND_SOC_DAIFMT_DSP_B:
 		/* Data on rising edge of bclk, frame high */
-		strcr |= SSI_STCR_TFSL | SSI_STCR_TSCKP | SSI_STCR_TXBIT0;
+		strcr |= SSI_STCR_TFSL | SSI_STCR_TSCKP;
 		break;
 	case SND_SOC_DAIFMT_AC97:
 		/* Data on falling edge of bclk, frame high, 1clk before data */
-		ssi->i2s_net |= SSI_SCR_I2S_MODE_NORMAL;
+		strcr |= SSI_STCR_TEFS;
 		break;
 	default:
 		return -EINVAL;
 	}
+
 	scr |= ssi->i2s_net;
 
 	/* DAI clock inversion */
@@ -962,20 +952,17 @@ static int _fsl_ssi_set_dai_fmt(struct device *dev,
 		break;
 	case SND_SOC_DAIFMT_CBM_CFM:
 		/* Input bit or frame sync clocks */
-		scr &= ~SSI_SCR_SYS_CLK_EN;
 		break;
 	case SND_SOC_DAIFMT_CBM_CFS:
 		/* Input bit clock but output frame sync clock */
-		strcr &= ~SSI_STCR_TXDIR;
 		strcr |= SSI_STCR_TFDIR;
-		scr &= ~SSI_SCR_SYS_CLK_EN;
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	stcr |= strcr;
-	srcr |= strcr;
+	stcr = strcr;
+	srcr = strcr;
 
 	/* Set SYN mode and clear RXDIR bit when using SYN or AC97 mode */
 	if (ssi->cpu_dai_drv.symmetric_rates || fsl_ssi_is_ac97(ssi)) {
@@ -983,9 +970,15 @@ static int _fsl_ssi_set_dai_fmt(struct device *dev,
 		scr |= SSI_SCR_SYN;
 	}
 
-	regmap_write(regs, REG_SSI_STCR, stcr);
-	regmap_write(regs, REG_SSI_SRCR, srcr);
-	regmap_write(regs, REG_SSI_SCR, scr);
+	mask = SSI_STCR_TFDIR | SSI_STCR_TXDIR | SSI_STCR_TSCKP |
+	       SSI_STCR_TFSI | SSI_STCR_TFSL | SSI_STCR_TEFS;
+
+	regmap_update_bits(ssi->regs, REG_SSI_STCR, mask, stcr);
+	regmap_update_bits(ssi->regs, REG_SSI_SRCR, mask, srcr);
+
+	mask = SSI_SCR_SYNC_TX_FS | SSI_SCR_I2S_MODE_MASK |
+	       SSI_SCR_SYS_CLK_EN | SSI_SCR_SYN;
+	regmap_update_bits(ssi->regs, REG_SSI_SCR, mask, scr);
 
 	return 0;
 }
@@ -1001,7 +994,7 @@ static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 	if (fsl_ssi_is_ac97(ssi))
 		return 0;
 
-	return _fsl_ssi_set_dai_fmt(dai->dev, ssi, fmt);
+	return _fsl_ssi_set_dai_fmt(ssi, fmt);
 }
 
 /**
@@ -1254,7 +1247,7 @@ static int fsl_ssi_hw_init(struct fsl_ssi *ssi)
 
 	/* AC97 should start earlier to communicate with CODECs */
 	if (fsl_ssi_is_ac97(ssi)) {
-		_fsl_ssi_set_dai_fmt(ssi->dev, ssi, ssi->dai_fmt);
+		_fsl_ssi_set_dai_fmt(ssi, ssi->dai_fmt);
 		fsl_ssi_setup_ac97(ssi);
 	}
 
-- 
2.7.4

  parent reply	other threads:[~2018-01-15  4:23 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15  4:21 [PATCH v3 00/17] ASoC: fsl_ssi: Clean up - program flow level Nicolin Chen
2018-01-15  4:21 ` Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 01/17] ASoC: fsl_ssi: Redefine RX and TX macros Nicolin Chen
2018-01-15  4:21   ` Nicolin Chen
2018-02-22 13:17   ` Applied "ASoC: fsl_ssi: Redefine RX and TX macros" to the asoc tree Mark Brown
2018-02-22 13:17     ` Mark Brown
2018-01-15  4:21 ` [PATCH v3 02/17] ASoC: fsl_ssi: Keep ssi->i2s_net updated Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 03/17] ASoC: fsl_ssi: Clean up set_dai_tdm_slot() Nicolin Chen
2018-01-15  4:21   ` Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 04/17] ASoC: fsl_ssi: Maintain a mask of active streams Nicolin Chen
2018-01-15  4:21   ` Nicolin Chen
2018-02-22 13:17   ` Applied "ASoC: fsl_ssi: Maintain a mask of active streams" to the asoc tree Mark Brown
2018-02-22 13:17     ` Mark Brown
2018-01-15  4:21 ` [PATCH v3 05/17] ASoC: fsl_ssi: Rename fsl_ssi_disable_val macro Nicolin Chen
2018-01-15  4:21   ` Nicolin Chen
2018-02-22 13:16   ` Applied "ASoC: fsl_ssi: Rename fsl_ssi_disable_val macro" to the asoc tree Mark Brown
2018-02-22 13:16     ` Mark Brown
2018-01-15  4:21 ` [PATCH v3 06/17] ASoC: fsl_ssi: Clear FIFO directly in fsl_ssi_config() Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 07/17] ASoC: fsl_ssi: Clean up helper functions of trigger() Nicolin Chen
2018-01-15  4:21   ` Nicolin Chen
2018-02-22 13:16   ` Applied "ASoC: fsl_ssi: Clean up helper functions of trigger()" to the asoc tree Mark Brown
2018-02-22 13:16     ` Mark Brown
2018-01-15  4:21 ` [PATCH v3 08/17] ASoC: fsl_ssi: Add DAIFMT define for AC97 Nicolin Chen
2018-01-15  4:21   ` Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 09/17] ASoC: fsl_ssi: Clean up fsl_ssi_setup_regvals() Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 10/17] ASoC: fsl_ssi: Set xFEN0 and xFEN1 together Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 11/17] ASoC: fsl_ssi: Use snd_soc_init_dma_data instead Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 12/17] ASoC: fsl_ssi: Move one-time configurations to probe() Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 13/17] ASoC: fsl_ssi: Setup AC97 in fsl_ssi_hw_init() Nicolin Chen
2018-01-15  4:21 ` Nicolin Chen [this message]
2018-01-15 21:16   ` [PATCH v3 14/17] ASoC: fsl_ssi: Clean up _fsl_ssi_set_dai_fmt() Maciej S. Szmigiero
2018-01-15 21:16     ` Maciej S. Szmigiero
2018-01-15 21:40     ` Nicolin Chen
2018-01-15 21:40       ` Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 15/17] ASoC: fsl_ssi: Add bool synchronous to mark synchronous mode Nicolin Chen
2018-02-22 13:16   ` Applied "ASoC: fsl_ssi: Add bool synchronous to mark synchronous mode" to the asoc tree Mark Brown
2018-02-22 13:16     ` Mark Brown
2018-01-15  4:21 ` [PATCH v3 16/17] ASoC: fsl_ssi: Move DT related code to a separate probe() Nicolin Chen
2018-01-15 21:16   ` Maciej S. Szmigiero
2018-01-15 21:16     ` Maciej S. Szmigiero
2018-01-15 21:32     ` Nicolin Chen
2018-01-15 21:32       ` Nicolin Chen
2018-01-15  4:21 ` [PATCH v3 17/17] ASoC: fsl_ssi: Use ssi->streams instead of reading register Nicolin Chen
2018-01-15 18:35 ` [PATCH v3 00/17] ASoC: fsl_ssi: Clean up - program flow level Caleb Crome
2018-01-15 18:35   ` Caleb Crome

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=1515990087-11598-15-git-send-email-nicoleotsuka@gmail.com \
    --to=nicoleotsuka@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnaud.mouiche@invoxia.com \
    --cc=broonie@kernel.org \
    --cc=caleb@crome.org \
    --cc=fabio.estevam@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lukma@denx.de \
    --cc=mail@maciej.szmigiero.name \
    --cc=timur@tabi.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.