xref: /linux/sound/soc/codecs/dmic.c (revision 29685e207b37ad7f415e4bf21320076c025f3df1)
1a710770eSDavid Lambert /*
2a710770eSDavid Lambert  * dmic.c  --  SoC audio for Generic Digital MICs
3a710770eSDavid Lambert  *
4a710770eSDavid Lambert  * Author: Liam Girdwood <lrg@slimlogic.co.uk>
5a710770eSDavid Lambert  *
6a710770eSDavid Lambert  * This program is free software; you can redistribute it and/or
7a710770eSDavid Lambert  * modify it under the terms of the GNU General Public License
8a710770eSDavid Lambert  * version 2 as published by the Free Software Foundation.
9a710770eSDavid Lambert  *
10a710770eSDavid Lambert  * This program is distributed in the hope that it will be useful, but
11a710770eSDavid Lambert  * WITHOUT ANY WARRANTY; without even the implied warranty of
12a710770eSDavid Lambert  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13a710770eSDavid Lambert  * General Public License for more details.
14a710770eSDavid Lambert  *
15a710770eSDavid Lambert  * You should have received a copy of the GNU General Public License
16a710770eSDavid Lambert  * along with this program; if not, write to the Free Software
17a710770eSDavid Lambert  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18a710770eSDavid Lambert  * 02110-1301 USA
19a710770eSDavid Lambert  *
20a710770eSDavid Lambert  */
21a710770eSDavid Lambert 
22a710770eSDavid Lambert #include <linux/platform_device.h>
23a710770eSDavid Lambert #include <linux/slab.h>
24da155d5bSPaul Gortmaker #include <linux/module.h>
25a710770eSDavid Lambert #include <sound/core.h>
26a710770eSDavid Lambert #include <sound/pcm.h>
27a710770eSDavid Lambert #include <sound/soc.h>
28a710770eSDavid Lambert #include <sound/soc-dapm.h>
29a710770eSDavid Lambert 
30a710770eSDavid Lambert static struct snd_soc_dai_driver dmic_dai = {
31a710770eSDavid Lambert 	.name = "dmic-hifi",
32a710770eSDavid Lambert 	.capture = {
33a710770eSDavid Lambert 		.stream_name = "Capture",
34a710770eSDavid Lambert 		.channels_min = 1,
35a710770eSDavid Lambert 		.channels_max = 8,
36a710770eSDavid Lambert 		.rates = SNDRV_PCM_RATE_CONTINUOUS,
37a710770eSDavid Lambert 		.formats = SNDRV_PCM_FMTBIT_S32_LE
38a710770eSDavid Lambert 			| SNDRV_PCM_FMTBIT_S24_LE
39a710770eSDavid Lambert 			| SNDRV_PCM_FMTBIT_S16_LE,
40a710770eSDavid Lambert 	},
41a710770eSDavid Lambert };
42a710770eSDavid Lambert 
43d5e4b0adSMisael Lopez Cruz static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = {
44d5e4b0adSMisael Lopez Cruz 	SND_SOC_DAPM_AIF_OUT("DMIC AIF", "Capture", 0,
45d5e4b0adSMisael Lopez Cruz 			     SND_SOC_NOPM, 0, 0),
46d5e4b0adSMisael Lopez Cruz 	SND_SOC_DAPM_INPUT("DMic"),
47d5e4b0adSMisael Lopez Cruz };
48d5e4b0adSMisael Lopez Cruz 
49d5e4b0adSMisael Lopez Cruz static const struct snd_soc_dapm_route intercon[] = {
50d5e4b0adSMisael Lopez Cruz 	{"DMIC AIF", NULL, "DMic"},
51d5e4b0adSMisael Lopez Cruz };
52d5e4b0adSMisael Lopez Cruz 
53d5e4b0adSMisael Lopez Cruz static struct snd_soc_codec_driver soc_dmic = {
54a73b8e89SKuninori Morimoto 	.component_driver = {
55a85f9da7SLars-Peter Clausen 		.dapm_widgets		= dmic_dapm_widgets,
56a85f9da7SLars-Peter Clausen 		.num_dapm_widgets	= ARRAY_SIZE(dmic_dapm_widgets),
57a85f9da7SLars-Peter Clausen 		.dapm_routes		= intercon,
58a85f9da7SLars-Peter Clausen 		.num_dapm_routes	= ARRAY_SIZE(intercon),
59a73b8e89SKuninori Morimoto 	},
60d5e4b0adSMisael Lopez Cruz };
61a710770eSDavid Lambert 
627a79e94eSBill Pemberton static int dmic_dev_probe(struct platform_device *pdev)
63a710770eSDavid Lambert {
64a710770eSDavid Lambert 	return snd_soc_register_codec(&pdev->dev,
65a710770eSDavid Lambert 			&soc_dmic, &dmic_dai, 1);
66a710770eSDavid Lambert }
67a710770eSDavid Lambert 
687a79e94eSBill Pemberton static int dmic_dev_remove(struct platform_device *pdev)
69a710770eSDavid Lambert {
70a710770eSDavid Lambert 	snd_soc_unregister_codec(&pdev->dev);
71a710770eSDavid Lambert 	return 0;
72a710770eSDavid Lambert }
73a710770eSDavid Lambert 
74a710770eSDavid Lambert MODULE_ALIAS("platform:dmic-codec");
75a710770eSDavid Lambert 
76*29685e20SArnaud Pouliquen static const struct of_device_id dmic_dev_match[] = {
77*29685e20SArnaud Pouliquen 	{.compatible = "dmic-codec"},
78*29685e20SArnaud Pouliquen 	{}
79*29685e20SArnaud Pouliquen };
80*29685e20SArnaud Pouliquen 
81a710770eSDavid Lambert static struct platform_driver dmic_driver = {
82a710770eSDavid Lambert 	.driver = {
83a710770eSDavid Lambert 		.name = "dmic-codec",
84*29685e20SArnaud Pouliquen 		.of_match_table = dmic_dev_match,
85a710770eSDavid Lambert 	},
86a710770eSDavid Lambert 	.probe = dmic_dev_probe,
877a79e94eSBill Pemberton 	.remove = dmic_dev_remove,
88a710770eSDavid Lambert };
89a710770eSDavid Lambert 
905bbcc3c0SMark Brown module_platform_driver(dmic_driver);
91a710770eSDavid Lambert 
92a710770eSDavid Lambert MODULE_DESCRIPTION("Generic DMIC driver");
93a710770eSDavid Lambert MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
94a710770eSDavid Lambert MODULE_LICENSE("GPL");
95