Merge tag 'gcc-plugins-v5.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / sound / soc / codecs / simple-amplifier.c
CommitLineData
85825d5e
JB
1/*
2 * Copyright (c) 2017 BayLibre, SAS.
3 * Author: Jerome Brunet <jbrunet@baylibre.com>
4 *
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.
8 *
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.
13 *
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.
18 */
19
20#include <linux/gpio/consumer.h>
21#include <linux/module.h>
6debd01a 22#include <linux/regulator/consumer.h>
85825d5e
JB
23#include <sound/soc.h>
24
8d881bb6 25#define DRV_NAME "simple-amplifier"
85825d5e 26
8d881bb6 27struct simple_amp {
85825d5e
JB
28 struct gpio_desc *gpiod_enable;
29};
30
31static int drv_event(struct snd_soc_dapm_widget *w,
32 struct snd_kcontrol *control, int event)
33{
34 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
8d881bb6 35 struct simple_amp *priv = snd_soc_component_get_drvdata(c);
85825d5e
JB
36 int val;
37
38 switch (event) {
39 case SND_SOC_DAPM_POST_PMU:
40 val = 1;
41 break;
42 case SND_SOC_DAPM_PRE_PMD:
43 val = 0;
44 break;
45 default:
46 WARN(1, "Unexpected event");
47 return -EINVAL;
48 }
49
ea2a2ad1 50 gpiod_set_value_cansleep(priv->gpiod_enable, val);
85825d5e
JB
51
52 return 0;
53}
54
8d881bb6 55static const struct snd_soc_dapm_widget simple_amp_dapm_widgets[] = {
85825d5e
JB
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"),
6debd01a 62 SND_SOC_DAPM_REGULATOR_SUPPLY("VCC", 20, 0),
85825d5e
JB
63};
64
8d881bb6 65static const struct snd_soc_dapm_route simple_amp_dapm_routes[] = {
85825d5e
JB
66 { "DRV", NULL, "INL" },
67 { "DRV", NULL, "INR" },
6debd01a
VK
68 { "OUTL", NULL, "VCC" },
69 { "OUTR", NULL, "VCC" },
85825d5e
JB
70 { "OUTL", NULL, "DRV" },
71 { "OUTR", NULL, "DRV" },
72};
73
8d881bb6
JB
74static 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),
85825d5e
JB
79};
80
8d881bb6 81static int simple_amp_probe(struct platform_device *pdev)
85825d5e
JB
82{
83 struct device *dev = &pdev->dev;
8d881bb6 84 struct simple_amp *priv;
85825d5e
JB
85 int err;
86
87 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
88 if (priv == NULL)
89 return -ENOMEM;
90 platform_set_drvdata(pdev, priv);
91
2944d29d
MJ
92 priv->gpiod_enable = devm_gpiod_get_optional(dev, "enable",
93 GPIOD_OUT_LOW);
85825d5e
JB
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);
98 return err;
99 }
100
8d881bb6
JB
101 return devm_snd_soc_register_component(dev,
102 &simple_amp_component_driver,
85825d5e
JB
103 NULL, 0);
104}
105
106#ifdef CONFIG_OF
8d881bb6 107static const struct of_device_id simple_amp_ids[] = {
85825d5e 108 { .compatible = "dioo,dio2125", },
8ed237e8 109 { .compatible = "simple-audio-amplifier", },
85825d5e
JB
110 { }
111};
8d881bb6 112MODULE_DEVICE_TABLE(of, simple_amp_ids);
85825d5e
JB
113#endif
114
8d881bb6 115static struct platform_driver simple_amp_driver = {
85825d5e
JB
116 .driver = {
117 .name = DRV_NAME,
8d881bb6 118 .of_match_table = of_match_ptr(simple_amp_ids),
85825d5e 119 },
8d881bb6 120 .probe = simple_amp_probe,
85825d5e
JB
121};
122
8d881bb6 123module_platform_driver(simple_amp_driver);
85825d5e 124
8d881bb6 125MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver");
85825d5e
JB
126MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
127MODULE_LICENSE("GPL");