Commit | Line | Data |
---|---|---|
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> | |
22 | #include <sound/soc.h> | |
23 | ||
8d881bb6 | 24 | #define DRV_NAME "simple-amplifier" |
85825d5e | 25 | |
8d881bb6 | 26 | struct simple_amp { |
85825d5e JB |
27 | struct gpio_desc *gpiod_enable; |
28 | }; | |
29 | ||
30 | static int drv_event(struct snd_soc_dapm_widget *w, | |
31 | struct snd_kcontrol *control, int event) | |
32 | { | |
33 | struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm); | |
8d881bb6 | 34 | struct simple_amp *priv = snd_soc_component_get_drvdata(c); |
85825d5e JB |
35 | int val; |
36 | ||
37 | switch (event) { | |
38 | case SND_SOC_DAPM_POST_PMU: | |
39 | val = 1; | |
40 | break; | |
41 | case SND_SOC_DAPM_PRE_PMD: | |
42 | val = 0; | |
43 | break; | |
44 | default: | |
45 | WARN(1, "Unexpected event"); | |
46 | return -EINVAL; | |
47 | } | |
48 | ||
ea2a2ad1 | 49 | gpiod_set_value_cansleep(priv->gpiod_enable, val); |
85825d5e JB |
50 | |
51 | return 0; | |
52 | } | |
53 | ||
8d881bb6 | 54 | static const struct snd_soc_dapm_widget simple_amp_dapm_widgets[] = { |
85825d5e JB |
55 | SND_SOC_DAPM_INPUT("INL"), |
56 | SND_SOC_DAPM_INPUT("INR"), | |
57 | SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM, 0, 0, NULL, 0, drv_event, | |
58 | (SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)), | |
59 | SND_SOC_DAPM_OUTPUT("OUTL"), | |
60 | SND_SOC_DAPM_OUTPUT("OUTR"), | |
61 | }; | |
62 | ||
8d881bb6 | 63 | static const struct snd_soc_dapm_route simple_amp_dapm_routes[] = { |
85825d5e JB |
64 | { "DRV", NULL, "INL" }, |
65 | { "DRV", NULL, "INR" }, | |
66 | { "OUTL", NULL, "DRV" }, | |
67 | { "OUTR", NULL, "DRV" }, | |
68 | }; | |
69 | ||
8d881bb6 JB |
70 | static const struct snd_soc_component_driver simple_amp_component_driver = { |
71 | .dapm_widgets = simple_amp_dapm_widgets, | |
72 | .num_dapm_widgets = ARRAY_SIZE(simple_amp_dapm_widgets), | |
73 | .dapm_routes = simple_amp_dapm_routes, | |
74 | .num_dapm_routes = ARRAY_SIZE(simple_amp_dapm_routes), | |
85825d5e JB |
75 | }; |
76 | ||
8d881bb6 | 77 | static int simple_amp_probe(struct platform_device *pdev) |
85825d5e JB |
78 | { |
79 | struct device *dev = &pdev->dev; | |
8d881bb6 | 80 | struct simple_amp *priv; |
85825d5e JB |
81 | int err; |
82 | ||
83 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | |
84 | if (priv == NULL) | |
85 | return -ENOMEM; | |
86 | platform_set_drvdata(pdev, priv); | |
87 | ||
88 | priv->gpiod_enable = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); | |
89 | if (IS_ERR(priv->gpiod_enable)) { | |
90 | err = PTR_ERR(priv->gpiod_enable); | |
91 | if (err != -EPROBE_DEFER) | |
92 | dev_err(dev, "Failed to get 'enable' gpio: %d", err); | |
93 | return err; | |
94 | } | |
95 | ||
8d881bb6 JB |
96 | return devm_snd_soc_register_component(dev, |
97 | &simple_amp_component_driver, | |
85825d5e JB |
98 | NULL, 0); |
99 | } | |
100 | ||
101 | #ifdef CONFIG_OF | |
8d881bb6 | 102 | static const struct of_device_id simple_amp_ids[] = { |
85825d5e | 103 | { .compatible = "dioo,dio2125", }, |
8ed237e8 | 104 | { .compatible = "simple-audio-amplifier", }, |
85825d5e JB |
105 | { } |
106 | }; | |
8d881bb6 | 107 | MODULE_DEVICE_TABLE(of, simple_amp_ids); |
85825d5e JB |
108 | #endif |
109 | ||
8d881bb6 | 110 | static struct platform_driver simple_amp_driver = { |
85825d5e JB |
111 | .driver = { |
112 | .name = DRV_NAME, | |
8d881bb6 | 113 | .of_match_table = of_match_ptr(simple_amp_ids), |
85825d5e | 114 | }, |
8d881bb6 | 115 | .probe = simple_amp_probe, |
85825d5e JB |
116 | }; |
117 | ||
8d881bb6 | 118 | module_platform_driver(simple_amp_driver); |
85825d5e | 119 | |
8d881bb6 | 120 | MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver"); |
85825d5e JB |
121 | MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>"); |
122 | MODULE_LICENSE("GPL"); |