2019-08-29 17:34:02

by Katsuhiro Suzuki

[permalink] [raw]
Subject: [PATCH 2/3] 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.

Signed-off-by: Katsuhiro Suzuki <[email protected]>
---
sound/soc/codecs/es8316.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 229808fa627c..9ed564eac202 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -9,6 +9,7 @@

#include <linux/module.h>
#include <linux/acpi.h>
+#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/mod_devicetable.h>
@@ -33,6 +34,7 @@ static const unsigned int supported_mclk_lrck_ratios[] = {

struct es8316_priv {
struct mutex lock;
+ struct clk *mclk;
struct regmap *regmap;
struct snd_soc_component *component;
struct snd_soc_jack *jack;
@@ -363,12 +365,19 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai,
{
struct snd_soc_component *component = codec_dai->component;
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
+ int ret;

es8316->sysclk = freq;

if (freq == 0)
return 0;

+ if (es8316->mclk) {
+ ret = clk_set_rate(es8316->mclk, freq);
+ if (ret)
+ return ret;
+ }
+
return 0;
}

@@ -693,9 +702,20 @@ static int es8316_set_jack(struct snd_soc_component *component,
static int es8316_probe(struct snd_soc_component *component)
{
struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component);
+ int ret;

es8316->component = component;

+ es8316->mclk = devm_clk_get(component->dev, "mclk");
+ if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
+ if (es8316->mclk) {
+ ret = clk_prepare_enable(es8316->mclk);
+ if (ret)
+ return ret;
+ }
+
/* Reset codec and enable current state machine */
snd_soc_component_write(component, ES8316_RESET, 0x3f);
usleep_range(5000, 5500);
--
2.23.0.rc1


2019-08-30 11:20:59

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 2/3] ASoC: es8316: Add clock control of MCLK

On Fri, Aug 30, 2019 at 02:32:04AM +0900, Katsuhiro Suzuki wrote:

> + es8316->mclk = devm_clk_get(component->dev, "mclk");
> + if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;

If we don't get a clock it'd be nice to at least log that in case
there's something wrong with the clock driver so that people have more
of a hint as to why things might be breaking.

> +
> + if (es8316->mclk) {
> + ret = clk_prepare_enable(es8316->mclk);
> + if (ret)
> + return ret;
> + }
> +

There's nothing that disables the clock on remove.

Otherwise this looks good.


Attachments:
(No filename) (600.00 B)
signature.asc (499.00 B)
Download all attachments

2019-08-31 11:22:50

by Katsuhiro Suzuki

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/3] ASoC: es8316: Add clock control of MCLK

Hello Mark,

On 2019/08/30 20:18, Mark Brown wrote:
> On Fri, Aug 30, 2019 at 02:32:04AM +0900, Katsuhiro Suzuki wrote:
>
>> + es8316->mclk = devm_clk_get(component->dev, "mclk");
>> + if (PTR_ERR(es8316->mclk) == -EPROBE_DEFER)
>> + return -EPROBE_DEFER;
>
> If we don't get a clock it'd be nice to at least log that in case
> there's something wrong with the clock driver so that people have more
> of a hint as to why things might be breaking.
>

OK, to change more user friendly.


>> +
>> + if (es8316->mclk) {
>> + ret = clk_prepare_enable(es8316->mclk);
>> + if (ret)
>> + return ret;
>> + }
>> +
>
> There's nothing that disables the clock on remove.
>
> Otherwise this looks good.
>
Thank you for reviewing. I'll fix it and send V2 patch set.


>
> _______________________________________________
> Alsa-devel mailing list
> [email protected]
> https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
>

Best Regards,
Katsuhiro Suzuki