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 #include #include #include @@ -23,6 +24,37 @@ #include #include +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); }