ASoC: sgtl5000: Do a sanity check on SYS_MCLK
diff mbox

Message ID 1412282165-1500-1-git-send-email-festevam@gmail.com
State Accepted
Commit 6f4d2b3177ee3352e70c90f327e2dea3809c263e
Headers show

Commit Message

Fabio Estevam Oct. 2, 2014, 8:36 p.m. UTC
From: Fabio Estevam <fabio.estevam@freescale.com>

According to the sgtl5000 datasheet the valid range for SYS_MCLK is from 8 to
27 MHz.

Add a sanity check prior to enabling SYS_MCLK.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 sound/soc/codecs/sgtl5000.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Mark Brown Oct. 3, 2014, 10:21 a.m. UTC | #1
On Thu, Oct 02, 2014 at 05:36:05PM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> According to the sgtl5000 datasheet the valid range for SYS_MCLK is from 8 to
> 27 MHz.

Applied, thanks.

Patch
diff mbox

diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index a604a22..1470437 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -1414,6 +1414,7 @@  static int sgtl5000_i2c_probe(struct i2c_client *client,
 {
 	struct sgtl5000_priv *sgtl5000;
 	int ret, reg, rev;
+	unsigned int mclk;
 
 	sgtl5000 = devm_kzalloc(&client->dev, sizeof(struct sgtl5000_priv),
 								GFP_KERNEL);
@@ -1437,6 +1438,14 @@  static int sgtl5000_i2c_probe(struct i2c_client *client,
 		return ret;
 	}
 
+	/* SGTL5000 SYS_MCLK should be between 8 and 27 MHz */
+	mclk = clk_get_rate(sgtl5000->mclk);
+	if (mclk < 8000000 || mclk > 27000000) {
+		dev_err(&client->dev, "Invalid SYS_CLK frequency: %u.%03uMHz\n",
+			mclk / 1000000, mclk / 1000 % 1000);
+		return -EINVAL;
+	}
+
 	ret = clk_prepare_enable(sgtl5000->mclk);
 	if (ret)
 		return ret;