All of lore.kernel.org
 help / color / mirror / Atom feed
From: Padmanabhan Rajanbabu <p.rajanbabu@samsung.com>
To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, s.nawrocki@samsung.com,
	perex@perex.cz, tiwai@suse.com, pankaj.dubey@samsung.com,
	alim.akhtar@samsung.com, rcsekar@samsung.com,
	aswani.reddy@samsung.com
Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	Padmanabhan Rajanbabu <p.rajanbabu@samsung.com>
Subject: [PATCH 2/6] ASoC: samsung: i2s: configure PSR from sound card
Date: Fri, 14 Oct 2022 15:51:47 +0530	[thread overview]
Message-ID: <20221014102151.108539-3-p.rajanbabu@samsung.com> (raw)
In-Reply-To: <20221014102151.108539-1-p.rajanbabu@samsung.com>

Currently the prescaler value in samsung I2S dai is calculated by
dividing the peripheral input clock frequency with frame clock
frequency and root clock frequency divider. This prescaler value is
used to divide the input clock to generate root clock (RCLK) from which
frame clock is generated for I2S communication.

However for the platforms which does not have a dedicated audio PLL as
an input clock source, the prescaler divider will not generate accurate
root clock frequency, which inturn affects sampling frequency also.

To overcome this scenario, support has been added to let the sound card
identify right prescaler divider value and configure the prescaler (PSR)
divider directly the from the sound card to achieve near accurate sample
frequencies

Signed-off-by: Padmanabhan Rajanbabu <p.rajanbabu@samsung.com>
---
 sound/soc/samsung/i2s-regs.h |  2 ++
 sound/soc/samsung/i2s.c      | 36 ++++++++++++++++++++++++++++++++----
 sound/soc/samsung/i2s.h      |  1 +
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/sound/soc/samsung/i2s-regs.h b/sound/soc/samsung/i2s-regs.h
index cb2be4a3b70b..e2581dc73df2 100644
--- a/sound/soc/samsung/i2s-regs.h
+++ b/sound/soc/samsung/i2s-regs.h
@@ -132,6 +132,8 @@
 #define EXYNOS7_MOD_RCLK_192FS	7
 
 #define PSR_PSREN		(1 << 15)
+#define PSR_PSVAL_SHIFT		8
+#define PSR_PSVAL_MASK		0x3f
 
 #define FIC_TX2COUNT(x)		(((x) >>  24) & 0xf)
 #define FIC_TX1COUNT(x)		(((x) >>  16) & 0xf)
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index fb806b0af6ab..a96286b27f1d 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -59,10 +59,10 @@ struct i2s_dai {
 	/* Frame clock */
 	unsigned frmclk;
 	/*
-	 * Specifically requested RCLK, BCLK by machine driver.
+	 * Specifically requested RCLK, BCLK and PSR by machine driver.
 	 * 0 indicates CPU driver is free to choose any value.
 	 */
-	unsigned rfs, bfs;
+	unsigned int rfs, bfs, psr;
 	/* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
 	struct i2s_dai *pri_dai;
 	/* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
@@ -389,6 +389,17 @@ static inline int get_blc(struct i2s_dai *i2s)
 	}
 }
 
+static inline unsigned int get_psval(struct i2s_dai *i2s)
+{
+	struct samsung_i2s_priv *priv = i2s->priv;
+	u32 psr;
+
+	psr = readl(priv->addr + I2SPSR) >> PSR_PSVAL_SHIFT;
+	psr &= PSR_PSVAL_MASK;
+
+	return (psr + 1);
+}
+
 /* TX channel control */
 static void i2s_txctrl(struct i2s_dai *i2s, int on)
 {
@@ -994,7 +1005,11 @@ static int config_setup(struct i2s_dai *i2s)
 		return 0;
 
 	if (!(priv->quirks & QUIRK_NO_MUXPSR)) {
-		psr = priv->rclk_srcrate / i2s->frmclk / rfs;
+		if (i2s->psr)
+			psr = i2s->psr;
+		else
+			psr = priv->rclk_srcrate / i2s->frmclk / rfs;
+
 		writel(((psr - 1) << 8) | PSR_PSREN, priv->addr + I2SPSR);
 		dev_dbg(&i2s->pdev->dev,
 			"RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
@@ -1072,6 +1087,18 @@ static int i2s_set_clkdiv(struct snd_soc_dai *dai,
 		i2s->bfs = div;
 		pm_runtime_put(dai->dev);
 		break;
+	case SAMSUNG_I2S_DIV_RCLK:
+		pm_runtime_get_sync(dai->dev);
+		if ((any_active(i2s) && div && (get_psval(i2s) != div))
+			|| (other && other->psr && (other->psr != div))) {
+			pm_runtime_put(dai->dev);
+			dev_err(&i2s->pdev->dev,
+				"%s:%d Other DAI busy\n", __func__, __LINE__);
+			return -EAGAIN;
+		}
+		i2s->psr = div;
+		pm_runtime_put(dai->dev);
+		break;
 	default:
 		dev_err(&i2s->pdev->dev,
 			"Invalid clock divider(%d)\n", div_id);
@@ -1140,9 +1167,10 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
 					   other->idma_playback.addr);
 	}
 
-	/* Reset any constraint on RFS and BFS */
+	/* Reset any constraint on RFS, BFS and PSR*/
 	i2s->rfs = 0;
 	i2s->bfs = 0;
+	i2s->psr = 0;
 
 	spin_lock_irqsave(&priv->lock, flags);
 	i2s_txctrl(i2s, 0);
diff --git a/sound/soc/samsung/i2s.h b/sound/soc/samsung/i2s.h
index 78b475ef98d9..e783d33fdfac 100644
--- a/sound/soc/samsung/i2s.h
+++ b/sound/soc/samsung/i2s.h
@@ -13,6 +13,7 @@
 #define SAMSUNG_I2S_DAI_SEC    "samsung-i2s-sec"
 
 #define SAMSUNG_I2S_DIV_BCLK		1
+#define SAMSUNG_I2S_DIV_RCLK		2
 
 #define SAMSUNG_I2S_RCLKSRC_0		0
 #define SAMSUNG_I2S_RCLKSRC_1		1
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: Padmanabhan Rajanbabu <p.rajanbabu@samsung.com>
To: lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, s.nawrocki@samsung.com,
	perex@perex.cz, tiwai@suse.com, pankaj.dubey@samsung.com,
	alim.akhtar@samsung.com, rcsekar@samsung.com,
	aswani.reddy@samsung.com
Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org,
	linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Padmanabhan Rajanbabu <p.rajanbabu@samsung.com>
Subject: [PATCH 2/6] ASoC: samsung: i2s: configure PSR from sound card
Date: Fri, 14 Oct 2022 15:51:47 +0530	[thread overview]
Message-ID: <20221014102151.108539-3-p.rajanbabu@samsung.com> (raw)
In-Reply-To: <20221014102151.108539-1-p.rajanbabu@samsung.com>

Currently the prescaler value in samsung I2S dai is calculated by
dividing the peripheral input clock frequency with frame clock
frequency and root clock frequency divider. This prescaler value is
used to divide the input clock to generate root clock (RCLK) from which
frame clock is generated for I2S communication.

However for the platforms which does not have a dedicated audio PLL as
an input clock source, the prescaler divider will not generate accurate
root clock frequency, which inturn affects sampling frequency also.

To overcome this scenario, support has been added to let the sound card
identify right prescaler divider value and configure the prescaler (PSR)
divider directly the from the sound card to achieve near accurate sample
frequencies

Signed-off-by: Padmanabhan Rajanbabu <p.rajanbabu@samsung.com>
---
 sound/soc/samsung/i2s-regs.h |  2 ++
 sound/soc/samsung/i2s.c      | 36 ++++++++++++++++++++++++++++++++----
 sound/soc/samsung/i2s.h      |  1 +
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/sound/soc/samsung/i2s-regs.h b/sound/soc/samsung/i2s-regs.h
index cb2be4a3b70b..e2581dc73df2 100644
--- a/sound/soc/samsung/i2s-regs.h
+++ b/sound/soc/samsung/i2s-regs.h
@@ -132,6 +132,8 @@
 #define EXYNOS7_MOD_RCLK_192FS	7
 
 #define PSR_PSREN		(1 << 15)
+#define PSR_PSVAL_SHIFT		8
+#define PSR_PSVAL_MASK		0x3f
 
 #define FIC_TX2COUNT(x)		(((x) >>  24) & 0xf)
 #define FIC_TX1COUNT(x)		(((x) >>  16) & 0xf)
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index fb806b0af6ab..a96286b27f1d 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -59,10 +59,10 @@ struct i2s_dai {
 	/* Frame clock */
 	unsigned frmclk;
 	/*
-	 * Specifically requested RCLK, BCLK by machine driver.
+	 * Specifically requested RCLK, BCLK and PSR by machine driver.
 	 * 0 indicates CPU driver is free to choose any value.
 	 */
-	unsigned rfs, bfs;
+	unsigned int rfs, bfs, psr;
 	/* Pointer to the Primary_Fifo if this is Sec_Fifo, NULL otherwise */
 	struct i2s_dai *pri_dai;
 	/* Pointer to the Secondary_Fifo if it has one, NULL otherwise */
@@ -389,6 +389,17 @@ static inline int get_blc(struct i2s_dai *i2s)
 	}
 }
 
+static inline unsigned int get_psval(struct i2s_dai *i2s)
+{
+	struct samsung_i2s_priv *priv = i2s->priv;
+	u32 psr;
+
+	psr = readl(priv->addr + I2SPSR) >> PSR_PSVAL_SHIFT;
+	psr &= PSR_PSVAL_MASK;
+
+	return (psr + 1);
+}
+
 /* TX channel control */
 static void i2s_txctrl(struct i2s_dai *i2s, int on)
 {
@@ -994,7 +1005,11 @@ static int config_setup(struct i2s_dai *i2s)
 		return 0;
 
 	if (!(priv->quirks & QUIRK_NO_MUXPSR)) {
-		psr = priv->rclk_srcrate / i2s->frmclk / rfs;
+		if (i2s->psr)
+			psr = i2s->psr;
+		else
+			psr = priv->rclk_srcrate / i2s->frmclk / rfs;
+
 		writel(((psr - 1) << 8) | PSR_PSREN, priv->addr + I2SPSR);
 		dev_dbg(&i2s->pdev->dev,
 			"RCLK_SRC=%luHz PSR=%u, RCLK=%dfs, BCLK=%dfs\n",
@@ -1072,6 +1087,18 @@ static int i2s_set_clkdiv(struct snd_soc_dai *dai,
 		i2s->bfs = div;
 		pm_runtime_put(dai->dev);
 		break;
+	case SAMSUNG_I2S_DIV_RCLK:
+		pm_runtime_get_sync(dai->dev);
+		if ((any_active(i2s) && div && (get_psval(i2s) != div))
+			|| (other && other->psr && (other->psr != div))) {
+			pm_runtime_put(dai->dev);
+			dev_err(&i2s->pdev->dev,
+				"%s:%d Other DAI busy\n", __func__, __LINE__);
+			return -EAGAIN;
+		}
+		i2s->psr = div;
+		pm_runtime_put(dai->dev);
+		break;
 	default:
 		dev_err(&i2s->pdev->dev,
 			"Invalid clock divider(%d)\n", div_id);
@@ -1140,9 +1167,10 @@ static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
 					   other->idma_playback.addr);
 	}
 
-	/* Reset any constraint on RFS and BFS */
+	/* Reset any constraint on RFS, BFS and PSR*/
 	i2s->rfs = 0;
 	i2s->bfs = 0;
+	i2s->psr = 0;
 
 	spin_lock_irqsave(&priv->lock, flags);
 	i2s_txctrl(i2s, 0);
diff --git a/sound/soc/samsung/i2s.h b/sound/soc/samsung/i2s.h
index 78b475ef98d9..e783d33fdfac 100644
--- a/sound/soc/samsung/i2s.h
+++ b/sound/soc/samsung/i2s.h
@@ -13,6 +13,7 @@
 #define SAMSUNG_I2S_DAI_SEC    "samsung-i2s-sec"
 
 #define SAMSUNG_I2S_DIV_BCLK		1
+#define SAMSUNG_I2S_DIV_RCLK		2
 
 #define SAMSUNG_I2S_RCLKSRC_0		0
 #define SAMSUNG_I2S_RCLKSRC_1		1
-- 
2.17.1


  parent reply	other threads:[~2022-10-14 11:10 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20221014104843epcas5p47f6daaad2e67e0c9eedd68c2256c025b@epcas5p4.samsung.com>
2022-10-14 10:21 ` [PATCH 0/6] ASoC: samsung: fsd: audio support for FSD SoC Padmanabhan Rajanbabu
2022-10-14 10:21   ` Padmanabhan Rajanbabu
     [not found]   ` <CGME20221014104850epcas5p1a707b9d407a0947c3519077cf7fca5ff@epcas5p1.samsung.com>
2022-10-14 10:21     ` [PATCH 1/6] ASoC: samsung: i2s: TDM Support for CPU DAI driver Padmanabhan Rajanbabu
2022-10-14 10:21       ` Padmanabhan Rajanbabu
     [not found]   ` <CGME20221014104857epcas5p2a275a1d606ca066227228d13bcf5b120@epcas5p2.samsung.com>
2022-10-14 10:21     ` Padmanabhan Rajanbabu [this message]
2022-10-14 10:21       ` [PATCH 2/6] ASoC: samsung: i2s: configure PSR from sound card Padmanabhan Rajanbabu
2022-10-14 12:02       ` Mark Brown
2022-10-14 12:02         ` Mark Brown
2022-10-21  8:00         ` Padmanabhan Rajanbabu
2022-10-21  8:00           ` Padmanabhan Rajanbabu
2022-10-21 11:53           ` Mark Brown
2022-10-21 11:53             ` Mark Brown
2022-11-08  5:23             ` Padmanabhan Rajanbabu
2022-11-08  5:23               ` Padmanabhan Rajanbabu
2022-11-09 17:38               ` Mark Brown
2022-11-09 17:38                 ` Mark Brown
2023-01-03  4:55                 ` Padmanabhan Rajanbabu
2023-01-03  4:55                   ` Padmanabhan Rajanbabu
2022-10-23 13:12           ` Krzysztof Kozlowski
2022-10-23 13:12             ` Krzysztof Kozlowski
     [not found]   ` <CGME20221014104901epcas5p1a61ea81c3b1640bd8a064633c0b1e40d@epcas5p1.samsung.com>
2022-10-14 10:21     ` [PATCH 3/6] dt-bindings: sound: Add sound card bindings for Tesla FSD Padmanabhan Rajanbabu
2022-10-14 10:21       ` Padmanabhan Rajanbabu
2022-10-14 15:13       ` Rob Herring
2022-10-14 15:13         ` Rob Herring
2022-10-21  8:44         ` Padmanabhan Rajanbabu
2022-10-21  8:44           ` Padmanabhan Rajanbabu
2022-10-22 16:48           ` Krzysztof Kozlowski
2022-10-22 16:48             ` Krzysztof Kozlowski
2022-11-08  5:33             ` Padmanabhan Rajanbabu
2022-11-08  5:33               ` Padmanabhan Rajanbabu
2022-11-08 10:36               ` Krzysztof Kozlowski
2022-11-08 10:36                 ` Krzysztof Kozlowski
     [not found]   ` <CGME20221014104904epcas5p4f458182cc9ac9c223d9a25566f3dd300@epcas5p4.samsung.com>
2022-10-14 10:21     ` [PATCH 4/6] ASoC: samsung: fsd: Add FSD soundcard driver Padmanabhan Rajanbabu
2022-10-14 10:21       ` Padmanabhan Rajanbabu
2022-10-14 12:23       ` Mark Brown
2022-10-14 12:23         ` Mark Brown
2022-10-21  8:09         ` Padmanabhan Rajanbabu
2022-10-21  8:09           ` Padmanabhan Rajanbabu
2022-10-16 15:18       ` Krzysztof Kozlowski
2022-10-16 15:18         ` Krzysztof Kozlowski
2022-10-21  9:04         ` Padmanabhan Rajanbabu
2022-10-21  9:04           ` Padmanabhan Rajanbabu
     [not found]   ` <CGME20221014104911epcas5p394100ff6ed53be32c4d64c7e23e48833@epcas5p3.samsung.com>
2022-10-14 10:21     ` [PATCH 5/6] arm64: dts: fsd: Add I2S DAI node for Tesla FSD Padmanabhan Rajanbabu
2022-10-14 10:21       ` Padmanabhan Rajanbabu
2022-10-14 13:24       ` Alim Akhtar
2022-10-14 13:24         ` Alim Akhtar
2022-10-21  8:09         ` Padmanabhan Rajanbabu
2022-10-21  8:09           ` Padmanabhan Rajanbabu
2022-10-16 15:14       ` Krzysztof Kozlowski
2022-10-16 15:14         ` Krzysztof Kozlowski
2022-10-21  8:49         ` Padmanabhan Rajanbabu
2022-10-21  8:49           ` Padmanabhan Rajanbabu
2022-10-21 13:01           ` Krzysztof Kozlowski
2022-10-21 13:01             ` Krzysztof Kozlowski
2022-11-08  5:26             ` Padmanabhan Rajanbabu
2022-11-08  5:26               ` Padmanabhan Rajanbabu
     [not found]   ` <CGME20221014104915epcas5p12414b87ea127b2d5bf521556bf841b00@epcas5p1.samsung.com>
2022-10-14 10:21     ` [PATCH 6/6] arm64: dts: fsd: Add sound card " Padmanabhan Rajanbabu
2022-10-14 10:21       ` Padmanabhan Rajanbabu
2022-10-14 13:29       ` Alim Akhtar
2022-10-14 13:29         ` Alim Akhtar
2022-10-21  8:12         ` Padmanabhan Rajanbabu
2022-10-21  8:12           ` Padmanabhan Rajanbabu
2022-10-21 12:53           ` Krzysztof Kozlowski
2022-10-21 12:53             ` Krzysztof Kozlowski
2022-11-08  5:25             ` Padmanabhan Rajanbabu
2022-11-08  5:25               ` Padmanabhan Rajanbabu

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=20221014102151.108539-3-p.rajanbabu@samsung.com \
    --to=p.rajanbabu@samsung.com \
    --cc=alim.akhtar@samsung.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=aswani.reddy@samsung.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=pankaj.dubey@samsung.com \
    --cc=perex@perex.cz \
    --cc=rcsekar@samsung.com \
    --cc=robh+dt@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=tiwai@suse.com \
    /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.