• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #define DRV_NAME "dio2125"
25 
26 struct dio2125 {
27 	struct gpio_desc *gpiod_enable;
28 };
29 
drv_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * control,int event)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);
34 	struct dio2125 *priv = snd_soc_component_get_drvdata(c);
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 
49 	gpiod_set_value_cansleep(priv->gpiod_enable, val);
50 
51 	return 0;
52 }
53 
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"),
61 };
62 
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" },
68 };
69 
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),
75 };
76 
dio2125_probe(struct platform_device * pdev)77 static int dio2125_probe(struct platform_device *pdev)
78 {
79 	struct device *dev = &pdev->dev;
80 	struct dio2125 *priv;
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 
96 	return devm_snd_soc_register_component(dev, &dio2125_component_driver,
97 					       NULL, 0);
98 }
99 
100 #ifdef CONFIG_OF
101 static const struct of_device_id dio2125_ids[] = {
102 	{ .compatible = "dioo,dio2125", },
103 	{ }
104 };
105 MODULE_DEVICE_TABLE(of, dio2125_ids);
106 #endif
107 
108 static struct platform_driver dio2125_driver = {
109 	.driver = {
110 		.name = DRV_NAME,
111 		.of_match_table = of_match_ptr(dio2125_ids),
112 	},
113 	.probe = dio2125_probe,
114 };
115 
116 module_platform_driver(dio2125_driver);
117 
118 MODULE_DESCRIPTION("ASoC DIO2125 output driver");
119 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
120 MODULE_LICENSE("GPL");
121