Commit 6dd567dc authored by Katsuhiro Suzuki's avatar Katsuhiro Suzuki Committed by Mark Brown

ASoC: es8316: add clock control of MCLK

This patch introduce clock property for MCLK master freq control.
Driver will set rate of MCLK master if set_sysclk is called and
changing sysclk by board driver.

[Modified slightly to apply without an earlier patch in the series due
to context diffs -- broonie]
Signed-off-by: default avatarKatsuhiro Suzuki <katsuhiro@katsuster.net>
Link: https://lore.kernel.org/r/20190903165322.20791-2-katsuhiro@katsuster.netSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 3a3edd6f
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/clk.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
...@@ -33,6 +34,7 @@ static const unsigned int supported_mclk_lrck_ratios[] = { ...@@ -33,6 +34,7 @@ static const unsigned int supported_mclk_lrck_ratios[] = {
struct es8316_priv { struct es8316_priv {
struct mutex lock; struct mutex lock;
struct clk *mclk;
struct regmap *regmap; struct regmap *regmap;
struct snd_soc_component *component; struct snd_soc_component *component;
struct snd_soc_jack *jack; struct snd_soc_jack *jack;
...@@ -360,7 +362,7 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, ...@@ -360,7 +362,7 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai,
{ {
struct snd_soc_component *component = codec_dai->component; struct snd_soc_component *component = codec_dai->component;
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
int i; int i, ret;
int count = 0; int count = 0;
es8316->sysclk = freq; es8316->sysclk = freq;
...@@ -368,6 +370,12 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, ...@@ -368,6 +370,12 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai,
if (freq == 0) if (freq == 0)
return 0; return 0;
if (es8316->mclk) {
ret = clk_set_rate(es8316->mclk, freq);
if (ret)
return ret;
}
/* Limit supported sample rates to ones that can be autodetected /* Limit supported sample rates to ones that can be autodetected
* by the codec running in slave mode. * by the codec running in slave mode.
*/ */
...@@ -697,9 +705,26 @@ static int es8316_set_jack(struct snd_soc_component *component, ...@@ -697,9 +705,26 @@ static int es8316_set_jack(struct snd_soc_component *component,
static int es8316_probe(struct snd_soc_component *component) static int es8316_probe(struct snd_soc_component *component)
{ {
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
int ret;
es8316->component = component; es8316->component = component;
es8316->mclk = devm_clk_get(component->dev, "mclk");
if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER)
return -EPROBE_DEFER;
if (IS_ERR(es8316->mclk)) {
dev_err(component->dev, "clock is invalid, ignored\n");
es8316->mclk = NULL;
}
if (es8316->mclk) {
ret = clk_prepare_enable(es8316->mclk);
if (ret) {
dev_err(component->dev, "unable to enable clock\n");
return ret;
}
}
/* Reset codec and enable current state machine */ /* Reset codec and enable current state machine */
snd_soc_component_write(component, ES8316_RESET, 0x3f); snd_soc_component_write(component, ES8316_RESET, 0x3f);
usleep_range(5000, 5500); usleep_range(5000, 5500);
...@@ -722,8 +747,17 @@ static int es8316_probe(struct snd_soc_component *component) ...@@ -722,8 +747,17 @@ static int es8316_probe(struct snd_soc_component *component)
return 0; return 0;
} }
static void es8316_remove(struct snd_soc_component *component)
{
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
if (es8316->mclk)
clk_disable_unprepare(es8316->mclk);
}
static const struct snd_soc_component_driver soc_component_dev_es8316 = { static const struct snd_soc_component_driver soc_component_dev_es8316 = {
.probe = es8316_probe, .probe = es8316_probe,
.remove = es8316_remove,
.set_jack = es8316_set_jack, .set_jack = es8316_set_jack,
.controls = es8316_snd_controls, .controls = es8316_snd_controls,
.num_controls = ARRAY_SIZE(es8316_snd_controls), .num_controls = ARRAY_SIZE(es8316_snd_controls),
......
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