diff options
author | Xiaotan Luo <lxt@rock-chips.com> | 2019-03-11 19:11:47 -0700 |
---|---|---|
committer | Tao Huang <huangtao@rock-chips.com> | 2019-03-19 14:49:16 +0800 |
commit | 2b120ce738cabff4a865d0d0b6273fcb6e64df53 (patch) | |
tree | 4537d9c090f80554dc3df1f24a4e154f0f4cf753 | |
parent | f3ef7216c26889a81cf6f4cc3f710ab3668fa3f8 (diff) |
ASoC: codec: dummy-codec: add setting mclk
Many devices require MCLK to work, So add mclk
Change-Id: I666e46c8968330afd81506d0c64769b59ad0837d
Signed-off-by: Xiaotan Luo <lxt@rock-chips.com>
-rw-r--r-- | sound/soc/codecs/dummy-codec.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sound/soc/codecs/dummy-codec.c b/sound/soc/codecs/dummy-codec.c index 276179744324..354251ced4bd 100644 --- a/sound/soc/codecs/dummy-codec.c +++ b/sound/soc/codecs/dummy-codec.c @@ -14,6 +14,7 @@ * */ +#include <linux/clk.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/slab.h> @@ -23,6 +24,37 @@ #include <sound/pcm.h> #include <sound/initval.h> +struct dummy_codec_priv { + struct snd_soc_codec *codec; + struct clk *mclk; +}; + +static int dummy_codec_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_codec *codec = dai->codec; + struct dummy_codec_priv *dummy_codec = snd_soc_codec_get_drvdata(codec); + + if (!IS_ERR(dummy_codec->mclk)) + clk_prepare_enable(dummy_codec->mclk); + return 0; +} + +static void dummy_codec_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct snd_soc_codec *codec = dai->codec; + struct dummy_codec_priv *dummy_codec = snd_soc_codec_get_drvdata(codec); + + if (!IS_ERR(dummy_codec->mclk)) + clk_disable_unprepare(dummy_codec->mclk); +} + +static struct snd_soc_dai_ops dummy_codec_dai_ops = { + .startup = dummy_codec_startup, + .shutdown = dummy_codec_shutdown, +}; + struct snd_soc_dai_driver dummy_dai = { .name = "dummy_codec", .playback = { @@ -45,12 +77,33 @@ struct snd_soc_dai_driver dummy_dai = { SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE), }, + .ops = &dummy_codec_dai_ops, }; static struct snd_soc_codec_driver soc_dummy_codec; static int rockchip_dummy_codec_probe(struct platform_device *pdev) { + struct dummy_codec_priv *codec_priv; + + codec_priv = devm_kzalloc(&pdev->dev, sizeof(*codec_priv), + GFP_KERNEL); + if (!codec_priv) + return -ENOMEM; + platform_set_drvdata(pdev, codec_priv); + + codec_priv->mclk = devm_clk_get(&pdev->dev, "mclk"); + if (IS_ERR(codec_priv->mclk)) { + /* some devices may not need mclk,so warnnig */ + dev_warn(&pdev->dev, "Unable to get mclk\n"); + if (PTR_ERR(codec_priv->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + else if (PTR_ERR(codec_priv->mclk) != -ENOENT) + return -EINVAL; + } else { + dev_info(&pdev->dev, "get mclk success\n"); + } + return snd_soc_register_codec(&pdev->dev, &soc_dummy_codec, &dummy_dai, 1); } |