Commit 98b664e2 authored by Markus Pargmann's avatar Markus Pargmann Committed by Mark Brown

ASoC: tlv320aic32x4: Support for master clock

Add support for a master clock passed through DT. The master clock of
the codec is only active when the codec is in use.
Signed-off-by: default avatarMarkus Pargmann <mpa@pengutronix.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 4d16700d
...@@ -8,6 +8,8 @@ Required properties: ...@@ -8,6 +8,8 @@ Required properties:
Optional properties: Optional properties:
- reset-gpios: Reset-GPIO phandle with args as described in gpio/gpio.txt - reset-gpios: Reset-GPIO phandle with args as described in gpio/gpio.txt
- clocks/clock-names: Clock named 'mclk' for the master clock of the codec.
See clock/clock-bindings.txt for information about the detailed format.
Example: Example:
...@@ -15,4 +17,6 @@ Example: ...@@ -15,4 +17,6 @@ Example:
codec: tlv320aic32x4@18 { codec: tlv320aic32x4@18 {
compatible = "ti,tlv320aic32x4"; compatible = "ti,tlv320aic32x4";
reg = <0x18>; reg = <0x18>;
clocks = <&clks 201>;
clock-names = "mclk";
}; };
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/clk.h>
#include <sound/tlv320aic32x4.h> #include <sound/tlv320aic32x4.h>
#include <sound/core.h> #include <sound/core.h>
...@@ -67,6 +68,7 @@ struct aic32x4_priv { ...@@ -67,6 +68,7 @@ struct aic32x4_priv {
u32 micpga_routing; u32 micpga_routing;
bool swapdacs; bool swapdacs;
int rstn_gpio; int rstn_gpio;
struct clk *mclk;
}; };
/* 0dB min, 0.5dB steps */ /* 0dB min, 0.5dB steps */
...@@ -487,8 +489,18 @@ static int aic32x4_mute(struct snd_soc_dai *dai, int mute) ...@@ -487,8 +489,18 @@ static int aic32x4_mute(struct snd_soc_dai *dai, int mute)
static int aic32x4_set_bias_level(struct snd_soc_codec *codec, static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
enum snd_soc_bias_level level) enum snd_soc_bias_level level)
{ {
struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
int ret;
switch (level) { switch (level) {
case SND_SOC_BIAS_ON: case SND_SOC_BIAS_ON:
/* Switch on master clock */
ret = clk_prepare_enable(aic32x4->mclk);
if (ret) {
dev_err(codec->dev, "Failed to enable master clock\n");
return ret;
}
/* Switch on PLL */ /* Switch on PLL */
snd_soc_update_bits(codec, AIC32X4_PLLPR, snd_soc_update_bits(codec, AIC32X4_PLLPR,
AIC32X4_PLLEN, AIC32X4_PLLEN); AIC32X4_PLLEN, AIC32X4_PLLEN);
...@@ -539,6 +551,9 @@ static int aic32x4_set_bias_level(struct snd_soc_codec *codec, ...@@ -539,6 +551,9 @@ static int aic32x4_set_bias_level(struct snd_soc_codec *codec,
/* Switch off BCLK_N Divider */ /* Switch off BCLK_N Divider */
snd_soc_update_bits(codec, AIC32X4_BCLKN, snd_soc_update_bits(codec, AIC32X4_BCLKN,
AIC32X4_BCLKEN, 0); AIC32X4_BCLKEN, 0);
/* Switch off master clock */
clk_disable_unprepare(aic32x4->mclk);
break; break;
case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_OFF:
break; break;
...@@ -717,6 +732,12 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c, ...@@ -717,6 +732,12 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
aic32x4->rstn_gpio = -1; aic32x4->rstn_gpio = -1;
} }
aic32x4->mclk = devm_clk_get(&i2c->dev, "mclk");
if (IS_ERR(aic32x4->mclk)) {
dev_err(&i2c->dev, "Failed getting the mclk. The current implementation does not support the usage of this codec without mclk\n");
return PTR_ERR(aic32x4->mclk);
}
if (gpio_is_valid(aic32x4->rstn_gpio)) { if (gpio_is_valid(aic32x4->rstn_gpio)) {
ret = devm_gpio_request_one(&i2c->dev, aic32x4->rstn_gpio, ret = devm_gpio_request_one(&i2c->dev, aic32x4->rstn_gpio,
GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn"); GPIOF_OUT_INIT_LOW, "tlv320aic32x4 rstn");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment