Skip to content

Commit

Permalink
ASoC: sgtl5000: Do a sanity check on SYS_MCLK
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Fabio Estevam authored and Mark Brown committed Oct 3, 2014
1 parent fa558d0 commit 6f4d2b3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sound/soc/codecs/sgtl5000.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,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);
Expand All @@ -1468,6 +1469,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;
Expand Down

0 comments on commit 6f4d2b3

Please sign in to comment.