1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2017 BayLibre, SAS.
4 * Author: Jerome Brunet <jbrunet@baylibre.com>
7 #include <linux/gpio/consumer.h>
8 #include <linux/module.h>
9 #include <linux/regulator/consumer.h>
10 #include <sound/soc.h>
12 #define DRV_NAME "simple-amplifier"
15 struct gpio_desc
*gpiod_enable
;
18 static int drv_event(struct snd_soc_dapm_widget
*w
,
19 struct snd_kcontrol
*control
, int event
)
21 struct snd_soc_component
*c
= snd_soc_dapm_to_component(w
->dapm
);
22 struct simple_amp
*priv
= snd_soc_component_get_drvdata(c
);
26 case SND_SOC_DAPM_POST_PMU
:
29 case SND_SOC_DAPM_PRE_PMD
:
33 WARN(1, "Unexpected event");
37 gpiod_set_value_cansleep(priv
->gpiod_enable
, val
);
42 static const struct snd_soc_dapm_widget simple_amp_dapm_widgets
[] = {
43 SND_SOC_DAPM_INPUT("INL"),
44 SND_SOC_DAPM_INPUT("INR"),
45 SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM
, 0, 0, NULL
, 0, drv_event
,
46 (SND_SOC_DAPM_POST_PMU
| SND_SOC_DAPM_PRE_PMD
)),
47 SND_SOC_DAPM_OUTPUT("OUTL"),
48 SND_SOC_DAPM_OUTPUT("OUTR"),
49 SND_SOC_DAPM_REGULATOR_SUPPLY("VCC", 20, 0),
52 static const struct snd_soc_dapm_route simple_amp_dapm_routes
[] = {
53 { "DRV", NULL
, "INL" },
54 { "DRV", NULL
, "INR" },
55 { "OUTL", NULL
, "VCC" },
56 { "OUTR", NULL
, "VCC" },
57 { "OUTL", NULL
, "DRV" },
58 { "OUTR", NULL
, "DRV" },
61 static const struct snd_soc_component_driver simple_amp_component_driver
= {
62 .dapm_widgets
= simple_amp_dapm_widgets
,
63 .num_dapm_widgets
= ARRAY_SIZE(simple_amp_dapm_widgets
),
64 .dapm_routes
= simple_amp_dapm_routes
,
65 .num_dapm_routes
= ARRAY_SIZE(simple_amp_dapm_routes
),
68 static int simple_amp_probe(struct platform_device
*pdev
)
70 struct device
*dev
= &pdev
->dev
;
71 struct simple_amp
*priv
;
74 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
77 platform_set_drvdata(pdev
, priv
);
79 priv
->gpiod_enable
= devm_gpiod_get_optional(dev
, "enable",
81 if (IS_ERR(priv
->gpiod_enable
)) {
82 err
= PTR_ERR(priv
->gpiod_enable
);
83 if (err
!= -EPROBE_DEFER
)
84 dev_err(dev
, "Failed to get 'enable' gpio: %d", err
);
88 return devm_snd_soc_register_component(dev
,
89 &simple_amp_component_driver
,
94 static const struct of_device_id simple_amp_ids
[] = {
95 { .compatible
= "dioo,dio2125", },
96 { .compatible
= "simple-audio-amplifier", },
99 MODULE_DEVICE_TABLE(of
, simple_amp_ids
);
102 static struct platform_driver simple_amp_driver
= {
105 .of_match_table
= of_match_ptr(simple_amp_ids
),
107 .probe
= simple_amp_probe
,
110 module_platform_driver(simple_amp_driver
);
112 MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver");
113 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
114 MODULE_LICENSE("GPL");