summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/dummy-codec.c
blob: 35756c7533570728dea747c906353ea32227aab0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// SPDX-License-Identifier: GPL-2.0
//
// dummy_codec.c  --  dummy audio codec for rockchip
//
// Copyright (C) 2018 Fuzhou Rockchip Electronics Co., Ltd

#include <linux/clk.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <sound/soc.h>
#include <sound/pcm.h>
#include <sound/initval.h>

struct dummy_codec_priv {
	struct snd_soc_component *component;
	struct clk *mclk;
};

static int dummy_codec_startup(struct snd_pcm_substream *substream,
			       struct snd_soc_dai *dai)
{
	struct dummy_codec_priv *dcp = snd_soc_component_get_drvdata(dai->component);

	if (!IS_ERR(dcp->mclk))
		clk_prepare_enable(dcp->mclk);

	return 0;
}

static void dummy_codec_shutdown(struct snd_pcm_substream *substream,
				 struct snd_soc_dai *dai)
{
	struct dummy_codec_priv *dcp = snd_soc_component_get_drvdata(dai->component);

	if (!IS_ERR(dcp->mclk))
		clk_disable_unprepare(dcp->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 = {
		.stream_name = "Dummy Playback",
		.channels_min = 2,
		.channels_max = 384,
		.rates = SNDRV_PCM_RATE_8000_192000,
		.formats = (SNDRV_PCM_FMTBIT_S16_LE |
			    SNDRV_PCM_FMTBIT_S20_3LE |
			    SNDRV_PCM_FMTBIT_S24_LE |
			    SNDRV_PCM_FMTBIT_S32_LE),
	},
	.capture = {
		.stream_name = "Dummy Capture",
		.channels_min = 2,
		.channels_max = 384,
		.rates = SNDRV_PCM_RATE_8000_192000,
		.formats = (SNDRV_PCM_FMTBIT_S16_LE |
			    SNDRV_PCM_FMTBIT_S20_3LE |
			    SNDRV_PCM_FMTBIT_S24_LE |
			    SNDRV_PCM_FMTBIT_S32_LE),
	},
	.ops = &dummy_codec_dai_ops,
};

static const struct snd_soc_component_driver soc_dummy_codec;

static int rockchip_dummy_codec_probe(struct platform_device *pdev)
{
	struct dummy_codec_priv *dcp;

	dcp = devm_kzalloc(&pdev->dev, sizeof(*dcp), GFP_KERNEL);
	if (!dcp)
		return -ENOMEM;

	platform_set_drvdata(pdev, dcp);

	/* optional mclk, if needs, assign mclk in dts node */
	dcp->mclk = devm_clk_get(&pdev->dev, "mclk");
	if (IS_ERR(dcp->mclk)) {
		if (PTR_ERR(dcp->mclk) == -EPROBE_DEFER)
			return -EPROBE_DEFER;
		else if (PTR_ERR(dcp->mclk) != -ENOENT)
			return -EINVAL;
	}

	return devm_snd_soc_register_component(&pdev->dev, &soc_dummy_codec,
					       &dummy_dai, 1);
}

static const struct of_device_id rockchip_dummy_codec_of_match[] = {
	{ .compatible = "rockchip,dummy-codec", },
	{},
};
MODULE_DEVICE_TABLE(of, rockchip_dummy_codec_of_match);

static struct platform_driver rockchip_dummy_codec_driver = {
	.driver = {
		.name = "dummy_codec",
		.of_match_table = of_match_ptr(rockchip_dummy_codec_of_match),
	},
	.probe = rockchip_dummy_codec_probe,
};

module_platform_driver(rockchip_dummy_codec_driver);

MODULE_AUTHOR("Sugar <sugar.zhang@rock-chips.com>");
MODULE_DESCRIPTION("Rockchip Dummy Codec Driver");
MODULE_LICENSE("GPL v2");