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 <sound/soc.h>
24 #define DRV_NAME "dio2125"
27 struct gpio_desc
*gpiod_enable
;
30 static int drv_event(struct snd_soc_dapm_widget
*w
,
31 struct snd_kcontrol
*control
, int event
)
33 struct snd_soc_component
*c
= snd_soc_dapm_to_component(w
->dapm
);
34 struct dio2125
*priv
= snd_soc_component_get_drvdata(c
);
38 case SND_SOC_DAPM_POST_PMU
:
41 case SND_SOC_DAPM_PRE_PMD
:
45 WARN(1, "Unexpected event");
49 gpiod_set_value_cansleep(priv
->gpiod_enable
, val
);
54 static const struct snd_soc_dapm_widget dio2125_dapm_widgets
[] = {
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"),
63 static const struct snd_soc_dapm_route dio2125_dapm_routes
[] = {
64 { "DRV", NULL
, "INL" },
65 { "DRV", NULL
, "INR" },
66 { "OUTL", NULL
, "DRV" },
67 { "OUTR", NULL
, "DRV" },
70 static const struct snd_soc_component_driver dio2125_component_driver
= {
71 .dapm_widgets
= dio2125_dapm_widgets
,
72 .num_dapm_widgets
= ARRAY_SIZE(dio2125_dapm_widgets
),
73 .dapm_routes
= dio2125_dapm_routes
,
74 .num_dapm_routes
= ARRAY_SIZE(dio2125_dapm_routes
),
77 static int dio2125_probe(struct platform_device
*pdev
)
79 struct device
*dev
= &pdev
->dev
;
83 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
86 platform_set_drvdata(pdev
, priv
);
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
);
96 return devm_snd_soc_register_component(dev
, &dio2125_component_driver
,
101 static const struct of_device_id dio2125_ids
[] = {
102 { .compatible
= "dioo,dio2125", },
105 MODULE_DEVICE_TABLE(of
, dio2125_ids
);
108 static struct platform_driver dio2125_driver
= {
111 .of_match_table
= of_match_ptr(dio2125_ids
),
113 .probe
= dio2125_probe
,
116 module_platform_driver(dio2125_driver
);
118 MODULE_DESCRIPTION("ASoC DIO2125 output driver");
119 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
120 MODULE_LICENSE("GPL");