mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sylwester Nawrocki <s.nawrocki@samsung.com>
To: broonie@kernel.org
Cc: lgirdwood@gmail.com, krzk@kernel.org, sbkim73@samsung.com,
	m.szyprowski@samsung.com, b.zolnierkie@samsung.com,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	linux-samsung-soc@vger.kernel.org,
	Sylwester Nawrocki <s.nawrocki@samsung.com>
Subject: [PATCH 07/22] ASoC: samsung: i2s: Move clk supplier data to common driver data structure
Date: Thu, 07 Feb 2019 18:00:15 +0100	[thread overview]
Message-ID: <20190207170028.720-8-s.nawrocki@samsung.com> (raw)
In-Reply-To: <20190207170028.720-1-s.nawrocki@samsung.com>

Having the clocks provider data in struct samsung_i2s_priv, i.e. per the I2S
controller instance, rather than per CPU DAI better models the hardware and
simplifies the code a little. The clock provider is common for both DAIs.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
---
 sound/soc/samsung/i2s.c | 68 ++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 35 deletions(-)

diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index 994dcd4b01fb..978614673ffb 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -99,9 +99,7 @@ struct i2s_dai {
 
 	spinlock_t *lock;
 
-	/* Below fields are only valid if this is the primary FIFO */
-	struct clk *clk_table[3];
-	struct clk_onecell_data clk_data;
+	struct samsung_i2s_priv *priv;
 };
 
 /* Lock for cross i/f checks */
@@ -118,6 +116,10 @@ struct samsung_i2s_priv {
 	struct i2s_dai *dai;
 	struct snd_soc_dai_driver *dai_drv;
 	int num_dais;
+
+	/* The clock provider's data */
+	struct clk *clk_table[3];
+	struct clk_onecell_data clk_data;
 };
 
 struct i2s_dai *samsung_i2s_get_pri_dai(struct device *dev)
@@ -625,11 +627,10 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
 	return ret;
 }
 
-static int i2s_set_fmt(struct snd_soc_dai *dai,
-	unsigned int fmt)
+static int i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 {
+	struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai);
 	struct i2s_dai *i2s = to_info(dai);
-	struct i2s_dai *other = get_other_dai(i2s);
 	int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave;
 	u32 mod, tmp = 0;
 	unsigned long flags;
@@ -687,8 +688,7 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
 		 * CLK_I2S_RCLK_SRC clock is not exposed so we ensure any
 		 * clock configuration assigned in DT is not overwritten.
 		 */
-		if (i2s->rclk_srcrate == 0 && i2s->clk_data.clks == NULL &&
-		    other->clk_data.clks == NULL)
+		if (i2s->rclk_srcrate == 0 && priv->clk_data.clks == NULL)
 			i2s_set_sysclk(dai, SAMSUNG_I2S_RCLKSRC_0,
 							0, SND_SOC_CLOCK_IN);
 		break;
@@ -725,8 +725,8 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
 static int i2s_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
 {
+	struct samsung_i2s_priv *priv = snd_soc_dai_get_drvdata(dai);
 	struct i2s_dai *i2s = to_info(dai);
-	struct i2s_dai *other = get_other_dai(i2s);
 	u32 mod, mask = 0, val = 0;
 	struct clk *rclksrc;
 	unsigned long flags;
@@ -811,10 +811,7 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
 
 	i2s->frmclk = params_rate(params);
 
-	rclksrc = i2s->clk_table[CLK_I2S_RCLK_SRC];
-	if (!rclksrc || IS_ERR(rclksrc))
-		rclksrc = other->clk_table[CLK_I2S_RCLK_SRC];
-
+	rclksrc = priv->clk_table[CLK_I2S_RCLK_SRC];
 	if (rclksrc && !IS_ERR(rclksrc))
 		i2s->rclk_srcrate = clk_get_rate(rclksrc);
 
@@ -1221,31 +1218,30 @@ static int i2s_runtime_resume(struct device *dev)
 }
 #endif /* CONFIG_PM */
 
-static void i2s_unregister_clocks(struct i2s_dai *i2s)
+static void i2s_unregister_clocks(struct samsung_i2s_priv *priv)
 {
 	int i;
 
-	for (i = 0; i < i2s->clk_data.clk_num; i++) {
-		if (!IS_ERR(i2s->clk_table[i]))
-			clk_unregister(i2s->clk_table[i]);
+	for (i = 0; i < priv->clk_data.clk_num; i++) {
+		if (!IS_ERR(priv->clk_table[i]))
+			clk_unregister(priv->clk_table[i]);
 	}
 }
 
-static void i2s_unregister_clock_provider(struct platform_device *pdev)
+static void i2s_unregister_clock_provider(struct samsung_i2s_priv *priv)
 {
-	struct i2s_dai *i2s = samsung_i2s_get_pri_dai(&pdev->dev);
-
-	of_clk_del_provider(pdev->dev.of_node);
-	i2s_unregister_clocks(i2s);
+	of_clk_del_provider(priv->pdev->dev.of_node);
+	i2s_unregister_clocks(priv);
 }
 
-static int i2s_register_clock_provider(struct platform_device *pdev)
+
+static int i2s_register_clock_provider(struct samsung_i2s_priv *priv)
 {
 
 	const char * const i2s_clk_desc[] = { "cdclk", "rclk_src", "prescaler" };
 	const char *clk_name[2] = { "i2s_opclk0", "i2s_opclk1" };
 	const char *p_names[2] = { NULL };
-	struct device *dev = &pdev->dev;
+	struct device *dev = &priv->pdev->dev;
 	struct i2s_dai *i2s = samsung_i2s_get_pri_dai(dev);
 	const struct samsung_i2s_variant_regs *reg_info = i2s->variant_regs;
 	const char *i2s_clk_name[ARRAY_SIZE(i2s_clk_desc)];
@@ -1277,37 +1273,37 @@ static int i2s_register_clock_provider(struct platform_device *pdev)
 		u32 val = readl(i2s->addr + I2SPSR);
 		writel(val | PSR_PSREN, i2s->addr + I2SPSR);
 
-		i2s->clk_table[CLK_I2S_RCLK_SRC] = clk_register_mux(dev,
+		priv->clk_table[CLK_I2S_RCLK_SRC] = clk_register_mux(dev,
 				i2s_clk_name[CLK_I2S_RCLK_SRC], p_names,
 				ARRAY_SIZE(p_names),
 				CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT,
 				i2s->addr + I2SMOD, reg_info->rclksrc_off,
 				1, 0, i2s->lock);
 
-		i2s->clk_table[CLK_I2S_RCLK_PSR] = clk_register_divider(dev,
+		priv->clk_table[CLK_I2S_RCLK_PSR] = clk_register_divider(dev,
 				i2s_clk_name[CLK_I2S_RCLK_PSR],
 				i2s_clk_name[CLK_I2S_RCLK_SRC],
 				CLK_SET_RATE_PARENT,
 				i2s->addr + I2SPSR, 8, 6, 0, i2s->lock);
 
 		p_names[0] = i2s_clk_name[CLK_I2S_RCLK_PSR];
-		i2s->clk_data.clk_num = 2;
+		priv->clk_data.clk_num = 2;
 	}
 
-	i2s->clk_table[CLK_I2S_CDCLK] = clk_register_gate(dev,
+	priv->clk_table[CLK_I2S_CDCLK] = clk_register_gate(dev,
 				i2s_clk_name[CLK_I2S_CDCLK], p_names[0],
 				CLK_SET_RATE_PARENT,
 				i2s->addr + I2SMOD, reg_info->cdclkcon_off,
 				CLK_GATE_SET_TO_DISABLE, i2s->lock);
 
-	i2s->clk_data.clk_num += 1;
-	i2s->clk_data.clks = i2s->clk_table;
+	priv->clk_data.clk_num += 1;
+	priv->clk_data.clks = priv->clk_table;
 
 	ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
-				  &i2s->clk_data);
+				  &priv->clk_data);
 	if (ret < 0) {
 		dev_err(dev, "failed to add clock provider: %d\n", ret);
-		i2s_unregister_clocks(i2s);
+		i2s_unregister_clocks(priv);
 	}
 
 	return ret;
@@ -1426,6 +1422,7 @@ static int samsung_i2s_probe(struct platform_device *pdev)
 	pri_dai->dma_capture.addr_width = 4;
 	pri_dai->quirks = quirks;
 	pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs;
+	pri_dai->priv = priv;
 
 	if (quirks & QUIRK_PRI_6CHAN)
 		pri_dai->drv->playback.channels_max = 6;
@@ -1454,6 +1451,7 @@ static int samsung_i2s_probe(struct platform_device *pdev)
 		sec_dai->quirks = quirks;
 		sec_dai->idma_playback.addr = idma_addr;
 		sec_dai->pri_dai = pri_dai;
+		sec_dai->priv = priv;
 		pri_dai->sec_dai = sec_dai;
 
 		ret = i2s_create_secondary_device(priv);
@@ -1485,11 +1483,11 @@ static int samsung_i2s_probe(struct platform_device *pdev)
 	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
-	ret = i2s_register_clock_provider(pdev);
+	ret = i2s_register_clock_provider(priv);
 	if (ret < 0)
 		goto err_disable_pm;
 
-	pri_dai->op_clk = clk_get_parent(pri_dai->clk_table[CLK_I2S_RCLK_SRC]);
+	pri_dai->op_clk = clk_get_parent(priv->clk_table[CLK_I2S_RCLK_SRC]);
 
 	return 0;
 
@@ -1512,7 +1510,7 @@ static int samsung_i2s_remove(struct platform_device *pdev)
 	pm_runtime_get_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
-	i2s_unregister_clock_provider(pdev);
+	i2s_unregister_clock_provider(priv);
 	clk_disable_unprepare(pri_dai->clk);
 	pm_runtime_put_noidle(&pdev->dev);
 	i2s_delete_secondary_device(priv);
-- 
2.20.1


  parent reply	other threads:[~2019-02-07 17:01 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190207170044epcas2p3d00762663b971845bc86db84af7d3b23@epcas2p3.samsung.com>
2019-02-07 17:00 ` [PATCH 00/22] ASoC: dmaengine updates, secondary CPU DAI for Odroid boards Sylwester Nawrocki
     [not found]   ` <CGME20190207170047epcas1p42d7ec4acfd976871c676efa5aecb33bc@epcas1p4.samsung.com>
2019-02-07 17:00     ` [PATCH 01/22] ASoC: dmaengine: Improve of_node test in dmaengine_pcm_request_chan_of() Sylwester Nawrocki
2019-02-11 13:29       ` Krzysztof Kozlowski
2019-02-12 16:58       ` Applied "ASoC: dmaengine: Improve of_node test in dmaengine_pcm_request_chan_of()" to the asoc tree Mark Brown
     [not found]   ` <CGME20190207170051epcas1p37a1acaef52cffb01af00c8d34dd9b1dd@epcas1p3.samsung.com>
2019-02-07 17:00     ` [PATCH 02/22] ASoC: dmaengine: Extend use of chan_names provided in custom DMA config Sylwester Nawrocki
2019-02-11 13:31       ` Krzysztof Kozlowski
2019-02-12 16:58       ` Applied "ASoC: dmaengine: Extend use of chan_names provided in custom DMA config" to the asoc tree Mark Brown
     [not found]   ` <CGME20190207170054epcas1p1e61320d308bc5be30187919f3360f501@epcas1p1.samsung.com>
2019-02-07 17:00     ` [PATCH 03/22] ASoC: samsung: dmaengine: Allow to specify custom DMA device Sylwester Nawrocki
2019-02-11 13:31       ` Krzysztof Kozlowski
2019-02-12 16:58       ` Applied "ASoC: samsung: dmaengine: Allow to specify custom DMA device" to the asoc tree Mark Brown
     [not found]   ` <CGME20190207170058epcas1p4e2fadf4aae2ece3c47c0750a094a4fbb@epcas1p4.samsung.com>
2019-02-07 17:00     ` [PATCH 04/22] ASoC: samsung: i2s: Fix prescaler setting for the secondary DAI Sylwester Nawrocki
2019-02-11 13:37       ` Krzysztof Kozlowski
2019-02-11 14:32         ` Sylwester Nawrocki
2019-02-11 15:03           ` Krzysztof Kozlowski
2019-02-12 16:58       ` Applied "ASoC: samsung: i2s: Fix prescaler setting for the secondary DAI" to the asoc tree Mark Brown
     [not found]   ` <CGME20190207170102epcas1p445f2a5d8e70bc3a6e42424034c2eb34a@epcas1p4.samsung.com>
2019-02-07 17:00     ` [PATCH 05/22] ASoC: samsung: i2s: Convert to single component with multiple DAIs Sylwester Nawrocki
2019-02-11 13:38       ` Krzysztof Kozlowski
2019-02-12 16:58       ` Applied "ASoC: samsung: i2s: Convert to single component with multiple DAIs" to the asoc tree Mark Brown
     [not found]   ` <CGME20190207170105epcas1p3d4a1da9ae268f8e95b32fb499e5a1dad@epcas1p3.samsung.com>
2019-02-07 17:00     ` [PATCH 06/22] ASoC: samsung: i2s: Restore support for the secondary PCM Sylwester Nawrocki
2019-02-11 13:41       ` Krzysztof Kozlowski
2019-02-11 14:50         ` Sylwester Nawrocki
     [not found]   ` <CGME20190207170109epcas1p20929934c01ae67a05cd6a56f13ed8486@epcas1p2.samsung.com>
2019-02-07 17:00     ` Sylwester Nawrocki [this message]
2019-02-11 13:41       ` [PATCH 07/22] ASoC: samsung: i2s: Move clk supplier data to common driver data structure Krzysztof Kozlowski
     [not found]   ` <CGME20190207170112epcas1p31ed740ef43d8a3eb71ca7245fba1bc3d@epcas1p3.samsung.com>
2019-02-07 17:00     ` [PATCH 08/22] ASoC: samsung: i2s: Add widgets and routes for DPCM support Sylwester Nawrocki
2019-02-11 13:42       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170116epcas2p1e0768a74062c8af83842ddb59309850f@epcas2p1.samsung.com>
2019-02-07 17:00     ` [PATCH 09/22] ASoC: samsung: i2s: Move core clk to the driver common data structure Sylwester Nawrocki
2019-02-11 13:44       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170120epcas1p211e1582a6124d6b7d0e33db6c0017480@epcas1p2.samsung.com>
2019-02-07 17:00     ` [PATCH 10/22] ASoC: samsung: i2s: Move opclk data to common driver " Sylwester Nawrocki
2019-02-11 13:44       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170123epcas1p2fae464ba7f102d841548c5a523cc6660@epcas1p2.samsung.com>
2019-02-07 17:00     ` [PATCH 11/22] ASoC: samsung: i2s: Move registers cache " Sylwester Nawrocki
2019-02-11 13:45       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170127epcas2p31da340c3f63e75e7bcb5c9c864a42173@epcas2p3.samsung.com>
2019-02-07 17:00     ` [PATCH 12/22] ASoC: samsung: i2s: Move SFR pointer " Sylwester Nawrocki
2019-02-11 13:46       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170130epcas1p4809b7a8dc797ced2982dc3b305a0991b@epcas1p4.samsung.com>
2019-02-07 17:00     ` [PATCH 13/22] ASoC: samsung: i2s: Drop spinlock pointer from i2s_dai " Sylwester Nawrocki
2019-02-11 13:47       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170134epcas2p1a22a5c2f680f33fe562fa22f3aec9e6a@epcas2p1.samsung.com>
2019-02-07 17:00     ` [PATCH 14/22] ASoC: samsung: i2s: Move IP variant data to common driver " Sylwester Nawrocki
2019-02-11 13:48       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170138epcas2p31134b2beee877922d27fab5c79fdc7b1@epcas2p3.samsung.com>
2019-02-07 17:00     ` [PATCH 15/22] ASoC: samsung: i2s: Move quirks " Sylwester Nawrocki
2019-02-11 13:49       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170141epcas1p29a038bfd0df69df10e916ea8a695a85b@epcas1p2.samsung.com>
2019-02-07 17:00     ` [PATCH 16/22] ASoC: samsung: i2s: Get rid of a static spinlock Sylwester Nawrocki
2019-02-11 13:51       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170145epcas1p465da0715aa629b525c17d263c1b49a68@epcas1p4.samsung.com>
2019-02-07 17:00     ` [PATCH 17/22] ASoC: samsung: odroid: Add support for secondary CPU DAI Sylwester Nawrocki
2019-02-11 13:57       ` Krzysztof Kozlowski
2019-02-11 15:19         ` Sylwester Nawrocki
2019-02-11 15:34           ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170148epcas2p2e0f4a1e154cb8cd52d257978a669e84c@epcas2p2.samsung.com>
2019-02-07 17:00     ` [PATCH 18/22] ASoC: samsung: Specify DMA channel names through custom DMA config Sylwester Nawrocki
2019-02-11 13:58       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170152epcas1p254264a82287a54dc2452f5e73daab13d@epcas1p2.samsung.com>
2019-02-07 17:00     ` [PATCH 19/22] ASoC: samsung: Drop DAI DMA data chan_name assignments Sylwester Nawrocki
2019-02-11 14:03       ` Krzysztof Kozlowski
     [not found]   ` <CGME20190207170155epcas1p42ba30c540d35290c010b5bfa4645e3b1@epcas1p4.samsung.com>
2019-02-07 17:00     ` [PATCH 20/22] ASoC: dmaengine: Remove unused SND_DMAENGINE_PCM_FLAG_CUSTOM_CHANNEL_NAME flag Sylwester Nawrocki
2019-02-11 14:04       ` Krzysztof Kozlowski
2019-02-12 16:40   ` [PATCH 00/22] ASoC: dmaengine updates, secondary CPU DAI for Odroid boards Mark Brown
2019-02-12 18:17     ` Sylwester Nawrocki

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=20190207170028.720-8-s.nawrocki@samsung.com \
    --to=s.nawrocki@samsung.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=broonie@kernel.org \
    --cc=krzk@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=sbkim73@samsung.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 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®