dmic.c (7057bb975dab827997e0ca9dd92cafef0856b0cc) dmic.c (05c9b302eda71083840392d74ce62dd1e1f30621)
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/delay.h>
22#include <linux/gpio.h>
23#include <linux/gpio/consumer.h>
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
23#include <linux/gpio.h>
24#include <linux/gpio/consumer.h>
25#include <linux/platform_device.h>
26#include <linux/slab.h>
27#include <linux/module.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32
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);
33struct dmic {
34 struct gpio_desc *gpio_en;
35 int wakeup_delay;
36};
36
37
37 if (!dmic_en)
38 return 0;
38static int dmic_aif_event(struct snd_soc_dapm_widget *w,
39 struct snd_kcontrol *kcontrol, int event) {
40 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
41 struct dmic *dmic = snd_soc_codec_get_drvdata(codec);
39
42
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);
43 switch (event) {
44 case SND_SOC_DAPM_POST_PMU:
45 if (dmic->gpio_en)
46 gpiod_set_value(dmic->gpio_en, 1);
47
48 if (dmic->wakeup_delay)
49 msleep(dmic->wakeup_delay);
45 break;
50 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);
51 case SND_SOC_DAPM_POST_PMD:
52 if (dmic->gpio_en)
53 gpiod_set_value(dmic->gpio_en, 0);
50 break;
51 }
52
53 return 0;
54}
55
54 break;
55 }
56
57 return 0;
58}
59
56static const struct snd_soc_dai_ops dmic_dai_ops = {
57 .trigger = dmic_daiops_trigger,
58};
59
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 },
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,
72};
73
71};
72
74static int dmic_codec_probe(struct snd_soc_codec *codec)
73static int dmic_component_probe(struct snd_soc_component *component)
75{
74{
76 struct gpio_desc *dmic_en;
75 struct dmic *dmic;
77
76
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);
77 dmic = devm_kzalloc(component->dev, sizeof(*dmic), GFP_KERNEL);
78 if (!dmic)
79 return -ENOMEM;
82
80
83 snd_soc_codec_set_drvdata(codec, dmic_en);
81 dmic->gpio_en = devm_gpiod_get_optional(component->dev,
82 "dmicen", GPIOD_OUT_LOW);
83 if (IS_ERR(dmic->gpio_en))
84 return PTR_ERR(dmic->gpio_en);
84
85
86 device_property_read_u32(component->dev, "wakeup-delay-ms",
87 &dmic->wakeup_delay);
88
89 snd_soc_component_set_drvdata(component, dmic);
90
85 return 0;
86}
87
88static const struct snd_soc_dapm_widget dmic_dapm_widgets[] = {
91 return 0;
92}
93
94static 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),
95 SND_SOC_DAPM_AIF_OUT_E("DMIC AIF", "Capture", 0,
96 SND_SOC_NOPM, 0, 0, dmic_aif_event,
97 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
91 SND_SOC_DAPM_INPUT("DMic"),
92};
93
94static const struct snd_soc_dapm_route intercon[] = {
95 {"DMIC AIF", NULL, "DMic"},
96};
97
98 SND_SOC_DAPM_INPUT("DMic"),
99};
100
101static const struct snd_soc_dapm_route intercon[] = {
102 {"DMIC AIF", NULL, "DMic"},
103};
104
98static const struct snd_soc_codec_driver soc_dmic = {
99 .probe = dmic_codec_probe,
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 },
105static const struct snd_soc_component_driver soc_dmic = {
106 .probe = dmic_component_probe,
107 .dapm_widgets = dmic_dapm_widgets,
108 .num_dapm_widgets = ARRAY_SIZE(dmic_dapm_widgets),
109 .dapm_routes = intercon,
110 .num_dapm_routes = ARRAY_SIZE(intercon),
111 .idle_bias_on = 1,
112 .use_pmdown_time = 1,
113 .endianness = 1,
114 .non_legacy_dai_naming = 1,
106};
107
108static int dmic_dev_probe(struct platform_device *pdev)
109{
110 int err;
111 u32 chans;
112 struct snd_soc_dai_driver *dai_drv = &dmic_dai;
113

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

124 if (!dai_drv)
125 return -ENOMEM;
126
127 memcpy(dai_drv, &dmic_dai, sizeof(*dai_drv));
128 dai_drv->capture.channels_max = chans;
129 }
130 }
131
115};
116
117static int dmic_dev_probe(struct platform_device *pdev)
118{
119 int err;
120 u32 chans;
121 struct snd_soc_dai_driver *dai_drv = &dmic_dai;
122

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

133 if (!dai_drv)
134 return -ENOMEM;
135
136 memcpy(dai_drv, &dmic_dai, sizeof(*dai_drv));
137 dai_drv->capture.channels_max = chans;
138 }
139 }
140
132 return snd_soc_register_codec(&pdev->dev,
141 return devm_snd_soc_register_component(&pdev->dev,
133 &soc_dmic, dai_drv, 1);
134}
135
142 &soc_dmic, dai_drv, 1);
143}
144
136static int dmic_dev_remove(struct platform_device *pdev)
137{
138 snd_soc_unregister_codec(&pdev->dev);
139 return 0;
140}
141
142MODULE_ALIAS("platform:dmic-codec");
143
144static const struct of_device_id dmic_dev_match[] = {
145 {.compatible = "dmic-codec"},
146 {}
147};
148
149static struct platform_driver dmic_driver = {
150 .driver = {
151 .name = "dmic-codec",
152 .of_match_table = dmic_dev_match,
153 },
154 .probe = dmic_dev_probe,
145MODULE_ALIAS("platform:dmic-codec");
146
147static const struct of_device_id dmic_dev_match[] = {
148 {.compatible = "dmic-codec"},
149 {}
150};
151
152static struct platform_driver dmic_driver = {
153 .driver = {
154 .name = "dmic-codec",
155 .of_match_table = dmic_dev_match,
156 },
157 .probe = dmic_dev_probe,
155 .remove = dmic_dev_remove,
156};
157
158module_platform_driver(dmic_driver);
159
160MODULE_DESCRIPTION("Generic DMIC driver");
161MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
162MODULE_LICENSE("GPL");
158};
159
160module_platform_driver(dmic_driver);
161
162MODULE_DESCRIPTION("Generic DMIC driver");
163MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
164MODULE_LICENSE("GPL");