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

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

Version: ~ [ linux-5.10-rc5 ] ~ [ linux-5.9.10 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.79 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.159 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.208 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.245 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.245 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ 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.5 ] ~ [ 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         int err;
 73 
 74         priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
 75         if (priv == NULL)
 76                 return -ENOMEM;
 77         platform_set_drvdata(pdev, priv);
 78 
 79         priv->gpiod_enable = devm_gpiod_get_optional(dev, "enable",
 80                                                      GPIOD_OUT_LOW);
 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);
 85                 return err;
 86         }
 87 
 88         return devm_snd_soc_register_component(dev,
 89                                                &simple_amp_component_driver,
 90                                                NULL, 0);
 91 }
 92 
 93 #ifdef CONFIG_OF
 94 static const struct of_device_id simple_amp_ids[] = {
 95         { .compatible = "dioo,dio2125", },
 96         { .compatible = "simple-audio-amplifier", },
 97         { }
 98 };
 99 MODULE_DEVICE_TABLE(of, simple_amp_ids);
100 #endif
101 
102 static struct platform_driver simple_amp_driver = {
103         .driver = {
104                 .name = DRV_NAME,
105                 .of_match_table = of_match_ptr(simple_amp_ids),
106         },
107         .probe = simple_amp_probe,
108 };
109 
110 module_platform_driver(simple_amp_driver);
111 
112 MODULE_DESCRIPTION("ASoC Simple Audio Amplifier driver");
113 MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
114 MODULE_LICENSE("GPL");
115 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp