ASoC: wm8974: add support enable/disable external mclk on runtime

Signed-off-by: Xing Zheng <zhengxing@rock-chips.com>
Change-Id: I6711bf6ca1406036eafe3755e9595414bfedcb3f
This commit is contained in:
Xing Zheng
2020-08-07 09:36:13 +08:00
committed by Tao Huang
parent ecbee1c72a
commit ff74b915f2

View File

@@ -7,6 +7,7 @@
* Author: Liam Girdwood <Liam.Girdwood@wolfsonmicro.com>
*/
#include <linux/clk.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
@@ -27,6 +28,7 @@
struct wm8974_priv {
unsigned int mclk;
unsigned int fs;
struct clk *mclk_in;
};
static const struct reg_default wm8974_reg_defaults[] = {
@@ -617,8 +619,10 @@ static int wm8974_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct snd_soc_component *component = dai->component;
struct wm8974_priv *priv = snd_soc_component_get_drvdata(component);
u16 power1 = snd_soc_component_read(component, WM8974_POWER1);
clk_prepare_enable(priv->mclk_in);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
power1 |= 0x10;
snd_soc_component_write(component, WM8974_POWER1, power1);
@@ -631,12 +635,14 @@ static void wm8974_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct snd_soc_component *component = dai->component;
struct wm8974_priv *priv = snd_soc_component_get_drvdata(component);
u16 power1 = snd_soc_component_read(component, WM8974_POWER1);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
power1 &= ~0x10;
snd_soc_component_write(component, WM8974_POWER1, power1);
}
clk_disable_unprepare(priv->mclk_in);
}
#define WM8974_RATES (SNDRV_PCM_RATE_8000_48000)
@@ -730,6 +736,10 @@ static int wm8974_i2c_probe(struct i2c_client *i2c,
if (IS_ERR(regmap))
return PTR_ERR(regmap);
priv->mclk_in = devm_clk_get(&i2c->dev, "mclk");
if (IS_ERR(priv->mclk_in))
return PTR_ERR(priv->mclk_in);
ret = devm_snd_soc_register_component(&i2c->dev,
&soc_component_dev_wm8974, &wm8974_dai, 1);