2 * Copyright (c) 2017 BayLibre, SAS.
3 * Author: Jerome Brunet <jbrunet@baylibre.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * The full GNU General Public License is included in this distribution
17 * in the file called COPYING.
20 #include <linux/gpio/consumer.h>
21 #include <linux/module.h>
22 #include <linux/regulator/consumer.h>
23 #include <sound/soc.h>
25 #define DRV_NAME "simple-amplifier"
28 struct gpio_desc *gpiod_enable;
31 static int drv_event(struct snd_soc_dapm_widget *w,
32 struct snd_kcontrol *control, int event)
34 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
35 struct simple_amp *priv = snd_soc_component_get_drvdata(c);
39 case SND_SOC_DAPM_POST_PMU:
42 case SND_SOC_DAPM_PRE_PMD:
46 WARN(1, "Unexpected event");
50 gpiod_set_value_cansleep(priv->gpiod_enable, val);
55 static const struct snd_soc_dapm_widget simple_amp_dapm_widgets[] = {
56 SND_SOC_DAPM_INPUT("INL"),
57 SND_SOC_DAPM_INPUT("INR"),
58 SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM, 0, 0, NULL, 0, drv_event,
59 (SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)),
60 SND_SOC_DAPM_OUTPUT("OUTL"),
61 SND_SOC_DAPM_OUTPUT("OUTR"),
62 SND_SOC_DAPM_REGULATOR_SUPPLY("VCC", 20, 0),
65 static const struct snd_soc_dapm_route simple_amp_dapm_routes[] = {
66 { "DRV", NULL, "INL" },
67 { "DRV", NULL, "INR" },
68 { "OUTL", NULL, "VCC" },
69 { "OUTR", NULL, "VCC" },
70 { "OUTL", NULL, "DRV" },
71 { "OUTR", NULL, "DRV" },
74 static const struct snd_soc_component_driver simple_amp_component_driver = {
75 .dapm_widgets = simple_amp_dapm_widgets,
76 .num_dapm_widgets = ARRAY_SIZE(simple_amp_dapm_widgets),
77 .dapm_routes = simple_amp_dapm_routes,
78 .num_dapm_routes = ARRAY_SIZE(simple_amp_dapm_routes),
81 static int simple_amp_probe(struct platform_device *pdev)
83 struct device *dev = &pdev->dev;
84 struct simple_amp *priv;
87 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
90 platform_set_drvdata(pdev, priv);
92 priv->gpiod_enable = devm_gpiod_get_optional(dev, "enable",
94 if (IS_ERR(priv->gpiod_enable)) {
95 err = PTR_ERR(priv->gpiod_enable);
96 if (err != -EPROBE_DEFER)
97 dev_err(dev, "Failed to get 'enable' gpio: %d", err);
101 return devm_snd_soc_register_component(dev,
102 &simple_amp_component_driver,
107 static const struct of_device_id simple_amp_ids[] = {
108 { .compatible = "dioo,dio2125", },
109 { .compatible = "simple-audio-amplifier", },
112 MODULE_DEVICE_TABLE(of, simple_amp_ids);
115 static struct platform_driver simple_amp_driver = {
118 .of_match_table = of_match_ptr(simple_amp_ids),
120 .probe = simple_amp_probe,
123 module_platform_driver(simple_amp_driver);
125 MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver");
126 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
127 MODULE_LICENSE("GPL");