[alsa-devel] [PATCH 3/4] ASoC: imx-sgtl5000: Do a sanity check on the codec clock
Fabio Estevam
festevam at gmail.com
Thu Apr 18 01:55:20 CEST 2013
From: Fabio Estevam <fabio.estevam at 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 at 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
More information about the Alsa-devel
mailing list