All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Mark Brown <broonie@kernel.org>, Takashi Iwai <tiwai@suse.com>,
	Jaroslav Kysela <perex@perex.cz>,
	Liam Girdwood <lgirdwood@gmail.com>, Agneli <poczt@protonmail.ch>,
	Rob Herring <robh+dt@kernel.org>
Cc: linux-tegra@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: [PATCH v3 10/20] ASoC: tegra20: spdif: Reset hardware
Date: Thu,  2 Dec 2021 19:23:31 +0300	[thread overview]
Message-ID: <20211202162341.1791-11-digetx@gmail.com> (raw)
In-Reply-To: <20211202162341.1791-1-digetx@gmail.com>

Reset S/PDIF controller on runtime PM suspend/resume to ensure that we
always have a consistent hardware state.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 sound/soc/tegra/tegra20_spdif.c | 32 ++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra20_spdif.h |  1 +
 2 files changed, 33 insertions(+)

diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
index 7dd263721c2c..bc45a0a8afab 100644
--- a/sound/soc/tegra/tegra20_spdif.c
+++ b/sound/soc/tegra/tegra20_spdif.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -14,6 +15,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
+#include <linux/reset.h>
 #include <linux/slab.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -27,6 +29,8 @@ static __maybe_unused int tegra20_spdif_runtime_suspend(struct device *dev)
 {
 	struct tegra20_spdif *spdif = dev_get_drvdata(dev);
 
+	regcache_cache_only(spdif->regmap, true);
+
 	clk_disable_unprepare(spdif->clk_spdif_out);
 
 	return 0;
@@ -37,13 +41,35 @@ static __maybe_unused int tegra20_spdif_runtime_resume(struct device *dev)
 	struct tegra20_spdif *spdif = dev_get_drvdata(dev);
 	int ret;
 
+	ret = reset_control_assert(spdif->reset);
+	if (ret)
+		return ret;
+
 	ret = clk_prepare_enable(spdif->clk_spdif_out);
 	if (ret) {
 		dev_err(dev, "clk_enable failed: %d\n", ret);
 		return ret;
 	}
 
+	usleep_range(10, 100);
+
+	ret = reset_control_deassert(spdif->reset);
+	if (ret)
+		goto disable_clocks;
+
+	regcache_cache_only(spdif->regmap, false);
+	regcache_mark_dirty(spdif->regmap);
+
+	ret = regcache_sync(spdif->regmap);
+	if (ret)
+		goto disable_clocks;
+
 	return 0;
+
+disable_clocks:
+	clk_disable_unprepare(spdif->clk_spdif_out);
+
+	return ret;
 }
 
 static int tegra20_spdif_hw_params(struct snd_pcm_substream *substream,
@@ -268,6 +294,12 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
 
 	dev_set_drvdata(&pdev->dev, spdif);
 
+	spdif->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(spdif->reset)) {
+		dev_err(&pdev->dev, "Can't retrieve spdif reset\n");
+		return PTR_ERR(spdif->reset);
+	}
+
 	spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "out");
 	if (IS_ERR(spdif->clk_spdif_out)) {
 		dev_err(&pdev->dev, "Could not retrieve spdif clock\n");
diff --git a/sound/soc/tegra/tegra20_spdif.h b/sound/soc/tegra/tegra20_spdif.h
index 1973ffc2d5c7..ff4b79e2052f 100644
--- a/sound/soc/tegra/tegra20_spdif.h
+++ b/sound/soc/tegra/tegra20_spdif.h
@@ -451,6 +451,7 @@ struct tegra20_spdif {
 	struct snd_dmaengine_dai_dma_data capture_dma_data;
 	struct snd_dmaengine_dai_dma_data playback_dma_data;
 	struct regmap *regmap;
+	struct reset_control *reset;
 };
 
 #endif
-- 
2.33.1


WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Osipenko <digetx@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Mark Brown <broonie@kernel.org>, Takashi Iwai <tiwai@suse.com>,
	Jaroslav Kysela <perex@perex.cz>,
	Liam Girdwood <lgirdwood@gmail.com>, Agneli <poczt@protonmail.ch>,
	Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org,
	Arnd Bergmann <arnd@arndb.de>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-tegra@vger.kernel.org
Subject: [PATCH v3 10/20] ASoC: tegra20: spdif: Reset hardware
Date: Thu,  2 Dec 2021 19:23:31 +0300	[thread overview]
Message-ID: <20211202162341.1791-11-digetx@gmail.com> (raw)
In-Reply-To: <20211202162341.1791-1-digetx@gmail.com>

Reset S/PDIF controller on runtime PM suspend/resume to ensure that we
always have a consistent hardware state.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 sound/soc/tegra/tegra20_spdif.c | 32 ++++++++++++++++++++++++++++++++
 sound/soc/tegra/tegra20_spdif.h |  1 +
 2 files changed, 33 insertions(+)

diff --git a/sound/soc/tegra/tegra20_spdif.c b/sound/soc/tegra/tegra20_spdif.c
index 7dd263721c2c..bc45a0a8afab 100644
--- a/sound/soc/tegra/tegra20_spdif.c
+++ b/sound/soc/tegra/tegra20_spdif.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/clk.h>
+#include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -14,6 +15,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
+#include <linux/reset.h>
 #include <linux/slab.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -27,6 +29,8 @@ static __maybe_unused int tegra20_spdif_runtime_suspend(struct device *dev)
 {
 	struct tegra20_spdif *spdif = dev_get_drvdata(dev);
 
+	regcache_cache_only(spdif->regmap, true);
+
 	clk_disable_unprepare(spdif->clk_spdif_out);
 
 	return 0;
@@ -37,13 +41,35 @@ static __maybe_unused int tegra20_spdif_runtime_resume(struct device *dev)
 	struct tegra20_spdif *spdif = dev_get_drvdata(dev);
 	int ret;
 
+	ret = reset_control_assert(spdif->reset);
+	if (ret)
+		return ret;
+
 	ret = clk_prepare_enable(spdif->clk_spdif_out);
 	if (ret) {
 		dev_err(dev, "clk_enable failed: %d\n", ret);
 		return ret;
 	}
 
+	usleep_range(10, 100);
+
+	ret = reset_control_deassert(spdif->reset);
+	if (ret)
+		goto disable_clocks;
+
+	regcache_cache_only(spdif->regmap, false);
+	regcache_mark_dirty(spdif->regmap);
+
+	ret = regcache_sync(spdif->regmap);
+	if (ret)
+		goto disable_clocks;
+
 	return 0;
+
+disable_clocks:
+	clk_disable_unprepare(spdif->clk_spdif_out);
+
+	return ret;
 }
 
 static int tegra20_spdif_hw_params(struct snd_pcm_substream *substream,
@@ -268,6 +294,12 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
 
 	dev_set_drvdata(&pdev->dev, spdif);
 
+	spdif->reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(spdif->reset)) {
+		dev_err(&pdev->dev, "Can't retrieve spdif reset\n");
+		return PTR_ERR(spdif->reset);
+	}
+
 	spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "out");
 	if (IS_ERR(spdif->clk_spdif_out)) {
 		dev_err(&pdev->dev, "Could not retrieve spdif clock\n");
diff --git a/sound/soc/tegra/tegra20_spdif.h b/sound/soc/tegra/tegra20_spdif.h
index 1973ffc2d5c7..ff4b79e2052f 100644
--- a/sound/soc/tegra/tegra20_spdif.h
+++ b/sound/soc/tegra/tegra20_spdif.h
@@ -451,6 +451,7 @@ struct tegra20_spdif {
 	struct snd_dmaengine_dai_dma_data capture_dma_data;
 	struct snd_dmaengine_dai_dma_data playback_dma_data;
 	struct regmap *regmap;
+	struct reset_control *reset;
 };
 
 #endif
-- 
2.33.1


  parent reply	other threads:[~2021-12-02 16:26 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-02 16:23 [PATCH v3 00/20] Support HDMI audio on NVIDIA Tegra20 Dmitry Osipenko
2021-12-02 16:23 ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 01/20] ASoC: dt-bindings: Add binding for Tegra20 S/PDIF Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 02/20] ASoC: dt-bindings: tegra20-i2s: Convert to schema Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 03/20] ASoC: dt-bindings: tegra20-i2s: Document new nvidia,fixed-parent-rate property Dmitry Osipenko
2021-12-02 16:23   ` [PATCH v3 03/20] ASoC: dt-bindings: tegra20-i2s: Document new nvidia, fixed-parent-rate property Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 04/20] dt-bindings: host1x: Document optional HDMI sound-dai-cells Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 05/20] ASoC: tegra20: spdif: Set FIFO trigger level Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 06/20] ASoC: tegra20-spdif: stop setting slave_id Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 07/20] ASoC: tegra20: spdif: Support device-tree Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 08/20] ASoC: tegra20: spdif: Improve driver's code Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 09/20] ASoC: tegra20: spdif: Use more resource-managed helpers Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` Dmitry Osipenko [this message]
2021-12-02 16:23   ` [PATCH v3 10/20] ASoC: tegra20: spdif: Reset hardware Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 11/20] ASoC: tegra20: spdif: Support system suspend Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 12/20] ASoC: tegra20: spdif: Filter out unsupported rates Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 13/20] ASoC: tegra20: i2s: " Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 14/20] drm/tegra: hdmi: Unwind tegra_hdmi_init() errors Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 15/20] drm/tegra: hdmi: Register audio CODEC on Tegra20 Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 16/20] ARM: tegra_defconfig: Enable S/PDIF driver Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 17/20] ARM: tegra: Add S/PDIF node to Tegra20 device-tree Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 18/20] ARM: tegra: Add HDMI audio graph " Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 19/20] ARM: tegra: acer-a500: Enable S/PDIF and HDMI audio Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko
2021-12-02 16:23 ` [PATCH v3 20/20] ARM: tegra: paz00: " Dmitry Osipenko
2021-12-02 16:23   ` Dmitry Osipenko

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=20211202162341.1791-11-digetx@gmail.com \
    --to=digetx@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jonathanh@nvidia.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=poczt@protonmail.ch \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.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.