Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Fabio Estevam <festevam@gmail.com>
To: broonie@kernel.org
Cc: Fabio Estevam <fabio.estevam@freescale.com>,
	alsa-devel@alsa-project.org, matt@genesi-usa.com,
	mfuzzey@gmail.com, kernel@pengutronix.de, shawn.guo@linaro.org
Subject: [PATCH 3/4] ASoC: imx-sgtl5000: Do a sanity check on the codec clock
Date: Wed, 17 Apr 2013 20:55:20 -0300	[thread overview]
Message-ID: <1366242921-16376-3-git-send-email-festevam@gmail.com> (raw)
In-Reply-To: <1366242921-16376-1-git-send-email-festevam@gmail.com>

From: Fabio Estevam <fabio.estevam@freescale.com>

Only turn on the codec clock if it is within the valid range.

Also, disable the codec clock on the clk_fail path.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 sound/soc/fsl/imx-sgtl5000.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
index 9c286e6..18af815 100644
--- a/sound/soc/fsl/imx-sgtl5000.c
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -56,6 +56,15 @@ static const struct snd_soc_dapm_widget imx_sgtl5000_dapm_widgets[] = {
 	SND_SOC_DAPM_SPK("Ext Spk", NULL),
 };
 
+static int sgtl5000_is_valid_sysclk(int freq)
+{
+
+	if (freq < 8000000 || freq > 27000000)
+		return -EINVAL;
+	else
+		return 0;
+}
+
 static int imx_sgtl5000_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -135,9 +144,13 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
 		goto fail;
 	}
 
-	data->clk_frequency = clk_get_rate(data->codec_clk);
-	clk_prepare_enable(data->codec_clk);
+	data->clk_frequency = clk_get_rate(data->codec_clk);
+	ret = sgtl5000_is_valid_sysclk(data->clk_frequency);
+	if (ret)
+		goto fail;
 
+	clk_prepare_enable(data->codec_clk);
+
 	data->dai.name = "HiFi";
 	data->dai.stream_name = "HiFi";
 	data->dai.codec_dai_name = "sgtl5000";
@@ -172,6 +185,7 @@ static int imx_sgtl5000_probe(struct platform_device *pdev)
 	return 0;
 
 clk_fail:
+	clk_disable_unprepare(data->codec_clk);
 	clk_put(data->codec_clk);
 fail:
 	if (ssi_np)
-- 
1.7.9.5

  parent reply	other threads:[~2013-04-17 23:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-17 23:55 [PATCH 1/4] ASoC: imx-sgtl5000: Do not enter the error path on success Fabio Estevam
2013-04-17 23:55 ` [RFC 2/4] ASoC: imx-sgtl5000: Let the code clock be a mandatory binding Fabio Estevam
2013-04-18  3:36   ` Shawn Guo
2013-04-18  3:56     ` Fabio Estevam
2013-04-18  6:41       ` Shawn Guo
2013-04-19  3:54         ` Fabio Estevam
2013-04-17 23:55 ` Fabio Estevam [this message]
2013-04-17 23:55 ` [PATCH 4/4] ASoC: imx-sgtl5000: Convert to devm_clk_get() Fabio Estevam
2013-04-18  1:29 ` [PATCH 1/4] ASoC: imx-sgtl5000: Do not enter the error path on success Shawn Guo
2013-04-18  1:38   ` Shawn Guo
2013-04-18  2:06     ` Fabio Estevam

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=1366242921-16376-3-git-send-email-festevam@gmail.com \
    --to=festevam@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=fabio.estevam@freescale.com \
    --cc=kernel@pengutronix.de \
    --cc=matt@genesi-usa.com \
    --cc=mfuzzey@gmail.com \
    --cc=shawn.guo@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox