0001
0002
0003
0004
0005
0006
0007 #include <linux/gpio/consumer.h>
0008 #include <linux/module.h>
0009 #include <linux/regulator/consumer.h>
0010 #include <sound/soc.h>
0011
0012 #define DRV_NAME "simple-amplifier"
0013
0014 struct simple_amp {
0015 struct gpio_desc *gpiod_enable;
0016 };
0017
0018 static int drv_event(struct snd_soc_dapm_widget *w,
0019 struct snd_kcontrol *control, int event)
0020 {
0021 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
0022 struct simple_amp *priv = snd_soc_component_get_drvdata(c);
0023 int val;
0024
0025 switch (event) {
0026 case SND_SOC_DAPM_POST_PMU:
0027 val = 1;
0028 break;
0029 case SND_SOC_DAPM_PRE_PMD:
0030 val = 0;
0031 break;
0032 default:
0033 WARN(1, "Unexpected event");
0034 return -EINVAL;
0035 }
0036
0037 gpiod_set_value_cansleep(priv->gpiod_enable, val);
0038
0039 return 0;
0040 }
0041
0042 static const struct snd_soc_dapm_widget simple_amp_dapm_widgets[] = {
0043 SND_SOC_DAPM_INPUT("INL"),
0044 SND_SOC_DAPM_INPUT("INR"),
0045 SND_SOC_DAPM_OUT_DRV_E("DRV", SND_SOC_NOPM, 0, 0, NULL, 0, drv_event,
0046 (SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)),
0047 SND_SOC_DAPM_OUTPUT("OUTL"),
0048 SND_SOC_DAPM_OUTPUT("OUTR"),
0049 SND_SOC_DAPM_REGULATOR_SUPPLY("VCC", 20, 0),
0050 };
0051
0052 static const struct snd_soc_dapm_route simple_amp_dapm_routes[] = {
0053 { "DRV", NULL, "INL" },
0054 { "DRV", NULL, "INR" },
0055 { "OUTL", NULL, "VCC" },
0056 { "OUTR", NULL, "VCC" },
0057 { "OUTL", NULL, "DRV" },
0058 { "OUTR", NULL, "DRV" },
0059 };
0060
0061 static const struct snd_soc_component_driver simple_amp_component_driver = {
0062 .dapm_widgets = simple_amp_dapm_widgets,
0063 .num_dapm_widgets = ARRAY_SIZE(simple_amp_dapm_widgets),
0064 .dapm_routes = simple_amp_dapm_routes,
0065 .num_dapm_routes = ARRAY_SIZE(simple_amp_dapm_routes),
0066 };
0067
0068 static int simple_amp_probe(struct platform_device *pdev)
0069 {
0070 struct device *dev = &pdev->dev;
0071 struct simple_amp *priv;
0072
0073 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0074 if (priv == NULL)
0075 return -ENOMEM;
0076 platform_set_drvdata(pdev, priv);
0077
0078 priv->gpiod_enable = devm_gpiod_get_optional(dev, "enable",
0079 GPIOD_OUT_LOW);
0080 if (IS_ERR(priv->gpiod_enable))
0081 return dev_err_probe(dev, PTR_ERR(priv->gpiod_enable),
0082 "Failed to get 'enable' gpio");
0083
0084 return devm_snd_soc_register_component(dev,
0085 &simple_amp_component_driver,
0086 NULL, 0);
0087 }
0088
0089 #ifdef CONFIG_OF
0090 static const struct of_device_id simple_amp_ids[] = {
0091 { .compatible = "dioo,dio2125", },
0092 { .compatible = "simple-audio-amplifier", },
0093 { }
0094 };
0095 MODULE_DEVICE_TABLE(of, simple_amp_ids);
0096 #endif
0097
0098 static struct platform_driver simple_amp_driver = {
0099 .driver = {
0100 .name = DRV_NAME,
0101 .of_match_table = of_match_ptr(simple_amp_ids),
0102 },
0103 .probe = simple_amp_probe,
0104 };
0105
0106 module_platform_driver(simple_amp_driver);
0107
0108 MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver");
0109 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
0110 MODULE_LICENSE("GPL");