~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/codecs/simple-amplifier.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright (c) 2017 BayLibre, SAS.
  4  * Author: Jerome Brunet <jbrunet@baylibre.com>
  5  */
  6 
  7 #include <linux/gpio/consumer.h>
  8 #include <linux/module.h>
  9 #include <linux/regulator/consumer.h>
 10 #include <sound/soc.h>
 11 
 12 #define DRV_NAME "simple-amplifier"
 13 
 14 struct simple_amp {
 15         struct gpio_desc *gpiod_enable;
 16 };
 17 
 18 static int drv_event(struct snd_soc_dapm_widget *w,
 19                      struct snd_kcontrol *control, int event)
 20 {
 21         struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
 22         struct simple_amp *priv = snd_soc_component_get_drvdata(c);
 23         int val;
 24 
 25         switch (event) {
 26         case SND_SOC_DAPM_POST_PMU:
 27                 val = 1;
 28                 break;
 29         case SND_SOC_DAPM_PRE_PMD:
 30                 val = 0;
 31                 break;
 32         default:
 33                 WARN(1, "Unexpected event");
 34                 return -EINVAL;
 35         }
 36 
 37         gpiod_set_value_cansleep(priv->gpiod_enable, val);
 38 
 39         return 0;
 40 }
 41 
 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),
 50 };
 51 
 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" },
 59 };
 60 
 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),
 66 };
 67 
 68 static int simple_amp_probe(struct platform_device *pdev)
 69 {
 70         struct device *dev = &pdev->dev;
 71         struct simple_amp *priv;
 72 
 73         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 74         if (priv == NULL)
 75                 return -ENOMEM;
 76         platform_set_drvdata(pdev, priv);
 77 
 78         priv->gpiod_enable = devm_gpiod_get_optional(dev, "enable",
 79                                                      GPIOD_OUT_LOW);
 80         if (IS_ERR(priv->gpiod_enable))
 81                 return dev_err_probe(dev, PTR_ERR(priv->gpiod_enable),
 82                                      "Failed to get 'enable' gpio");
 83 
 84         return devm_snd_soc_register_component(dev,
 85                                                &simple_amp_component_driver,
 86                                                NULL, 0);
 87 }
 88 
 89 #ifdef CONFIG_OF
 90 static const struct of_device_id simple_amp_ids[] = {
 91         { .compatible = "dioo,dio2125", },
 92         { .compatible = "simple-audio-amplifier", },
 93         { }
 94 };
 95 MODULE_DEVICE_TABLE(of, simple_amp_ids);
 96 #endif
 97 
 98 static struct platform_driver simple_amp_driver = {
 99         .driver = {
100                 .name = DRV_NAME,
101                 .of_match_table = of_match_ptr(simple_amp_ids),
102         },
103         .probe = simple_amp_probe,
104 };
105 
106 module_platform_driver(simple_amp_driver);
107 
108 MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver");
109 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
110 MODULE_LICENSE("GPL");
111 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php