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>
This commit is contained in:
Xiaotan Luo
2019-03-11 19:11:47 -07:00
committed by Sugar Zhang
parent 47986340e4
commit ce779a4fc4

View File

@@ -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);
}