dmic.c (a180ba45b1cf630b3bd5912ce235b2ee16606b8e) dmic.c (23c7159a799f3364720b3d250f57bc8e26b17287)
1/*
2 * dmic.c -- SoC audio for Generic Digital MICs
3 *
4 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.

--- 5 unchanged lines hidden (view full) ---

14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
1/*
2 * dmic.c -- SoC audio for Generic Digital MICs
3 *
4 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.

--- 5 unchanged lines hidden (view full) ---

14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/gpio.h>
23#include <linux/gpio/consumer.h>
22#include <linux/platform_device.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26#include <linux/module.h>
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31
32static int dmic_daiops_trigger(struct snd_pcm_substream *substream,
33 int cmd, struct snd_soc_dai *dai)
34{
35 struct gpio_desc *dmic_en = snd_soc_dai_get_drvdata(dai);
36
37 if (!dmic_en)
38 return 0;
39
40 switch (cmd) {
41 case SNDRV_PCM_TRIGGER_START:
42 case SNDRV_PCM_TRIGGER_RESUME:
43 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
44 gpiod_set_value(dmic_en, 1);
45 break;
46 case SNDRV_PCM_TRIGGER_STOP:
47 case SNDRV_PCM_TRIGGER_SUSPEND:
48 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
49 gpiod_set_value(dmic_en, 0);
50 break;
51 }
52
53 return 0;
54}
55
56static const struct snd_soc_dai_ops dmic_dai_ops = {
57 .trigger = dmic_daiops_trigger,
58};
59
30static struct snd_soc_dai_driver dmic_dai = {
31 .name = "dmic-hifi",
32 .capture = {
33 .stream_name = "Capture",
34 .channels_min = 1,
35 .channels_max = 8,
36 .rates = SNDRV_PCM_RATE_CONTINUOUS,
37 .formats = SNDRV_PCM_FMTBIT_S32_LE
38 | SNDRV_PCM_FMTBIT_S24_LE
39 | SNDRV_PCM_FMTBIT_S16_LE,
40 },
60static struct snd_soc_dai_driver dmic_dai = {
61 .name = "dmic-hifi",
62 .capture = {
63 .stream_name = "Capture",
64 .channels_min = 1,
65 .channels_max = 8,
66 .rates = SNDRV_PCM_RATE_CONTINUOUS,
67 .formats = SNDRV_PCM_FMTBIT_S32_LE
68 | SNDRV_PCM_FMTBIT_S24_LE
69 | SNDRV_PCM_FMTBIT_S16_LE,
70 },
71 .ops = &dmic_dai_ops,
41};
42
72};
73
74static int dmic_codec_probe(struct snd_soc_codec *codec)
75{
76 struct gpio_desc *dmic_en;
77
78 dmic_en = devm_gpiod_get_optional(codec->dev,
79 "dmicen", GPIOD_OUT_LOW);
80 if (IS_ERR(dmic_en))
81 return PTR_ERR(dmic_en);
82
83 snd_soc_codec_set_drvdata(codec, dmic_en);
84
85 return 0;
86}
87
43static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = {
44 SND_SOC_DAPM_AIF_OUT("DMIC AIF", "Capture", 0,
45 SND_SOC_NOPM, 0, 0),
46 SND_SOC_DAPM_INPUT("DMic"),
47};
48
49static const struct snd_soc_dapm_route intercon[] = {
50 {"DMIC AIF", NULL, "DMic"},
51};
52
53static const struct snd_soc_codec_driver soc_dmic = {
88static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = {
89 SND_SOC_DAPM_AIF_OUT("DMIC AIF", "Capture", 0,
90 SND_SOC_NOPM, 0, 0),
91 SND_SOC_DAPM_INPUT("DMic"),
92};
93
94static const struct snd_soc_dapm_route intercon[] = {
95 {"DMIC AIF", NULL, "DMic"},
96};
97
98static const struct snd_soc_codec_driver soc_dmic = {
99 .probe = dmic_codec_probe,
54 .component_driver = {
55 .dapm_widgets = dmic_dapm_widgets,
56 .num_dapm_widgets = ARRAY_SIZE(dmic_dapm_widgets),
57 .dapm_routes = intercon,
58 .num_dapm_routes = ARRAY_SIZE(intercon),
59 },
60};
61

--- 6 unchanged lines hidden (view full) ---

68static int dmic_dev_remove(struct platform_device *pdev)
69{
70 snd_soc_unregister_codec(&pdev->dev);
71 return 0;
72}
73
74MODULE_ALIAS("platform:dmic-codec");
75
100 .component_driver = {
101 .dapm_widgets = dmic_dapm_widgets,
102 .num_dapm_widgets = ARRAY_SIZE(dmic_dapm_widgets),
103 .dapm_routes = intercon,
104 .num_dapm_routes = ARRAY_SIZE(intercon),
105 },
106};
107

--- 6 unchanged lines hidden (view full) ---

114static int dmic_dev_remove(struct platform_device *pdev)
115{
116 snd_soc_unregister_codec(&pdev->dev);
117 return 0;
118}
119
120MODULE_ALIAS("platform:dmic-codec");
121
122static const struct of_device_id dmic_dev_match[] = {
123 {.compatible = "dmic-codec"},
124 {}
125};
126
76static struct platform_driver dmic_driver = {
77 .driver = {
78 .name = "dmic-codec",
127static struct platform_driver dmic_driver = {
128 .driver = {
129 .name = "dmic-codec",
130 .of_match_table = dmic_dev_match,
79 },
80 .probe = dmic_dev_probe,
81 .remove = dmic_dev_remove,
82};
83
84module_platform_driver(dmic_driver);
85
86MODULE_DESCRIPTION("Generic DMIC driver");
87MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
88MODULE_LICENSE("GPL");
131 },
132 .probe = dmic_dev_probe,
133 .remove = dmic_dev_remove,
134};
135
136module_platform_driver(dmic_driver);
137
138MODULE_DESCRIPTION("Generic DMIC driver");
139MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
140MODULE_LICENSE("GPL");