alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: "Nicolò Veronese" <nicveronese@gmail.com>
To: broonie@kernel.org, alsa-devel@alsa-project.org
Cc: "Nicolò Veronese" <nicveronese@gmail.com>
Subject: [PATCH 1/2] ASoC: add generic simple-amplifier support
Date: Mon, 25 Jun 2018 13:06:16 +0200	[thread overview]
Message-ID: <1529924777-21136-1-git-send-email-nicveronese@gmail.com> (raw)

Many boards have speaker amplifier attached on an analog output.
Most of them are only managed by a mute or shutdown GPIO.
In order to reduce duplicate driver, this patch adds generic/simple-amplifier.

Signed-off-by: Nicolò Veronese <nicveronese@gmail.com>
---
 sound/soc/generic/Kconfig            |   5 ++
 sound/soc/generic/Makefile           |   2 +
 sound/soc/generic/simple-amplifier.c | 109 +++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+)
 create mode 100644 sound/soc/generic/simple-amplifier.c

diff --git a/sound/soc/generic/Kconfig b/sound/soc/generic/Kconfig
index c954be0..ace17c3a 100644
--- a/sound/soc/generic/Kconfig
+++ b/sound/soc/generic/Kconfig
@@ -7,6 +7,11 @@ config SND_SIMPLE_CARD
 	help
 	  This option enables generic simple sound card support
 
+config SND_SIMPLE_AMPLIFIER
+	tristate "ASoC Simple Amplifier support"
+	help
+	  This option enables generic simple amplifier support
+
 config SND_SIMPLE_SCU_CARD
 	tristate "ASoC Simple SCU sound card support"
 	depends on OF
diff --git a/sound/soc/generic/Makefile b/sound/soc/generic/Makefile
index 9dec293..805a746 100644
--- a/sound/soc/generic/Makefile
+++ b/sound/soc/generic/Makefile
@@ -1,12 +1,14 @@
 # SPDX-License-Identifier: GPL-2.0
 snd-soc-simple-card-utils-objs	:= simple-card-utils.o
 snd-soc-simple-card-objs	:= simple-card.o
+snd-soc-simple-amplifier-objs		:= simple-amplifier.o
 snd-soc-simple-scu-card-objs	:= simple-scu-card.o
 snd-soc-audio-graph-card-objs	:= audio-graph-card.o
 snd-soc-audio-graph-scu-card-objs	:= audio-graph-scu-card.o
 
 obj-$(CONFIG_SND_SIMPLE_CARD_UTILS)	+= snd-soc-simple-card-utils.o
 obj-$(CONFIG_SND_SIMPLE_CARD)		+= snd-soc-simple-card.o
+obj-$(CONFIG_SND_SIMPLE_AMPLIFIER)		+= snd-soc-simple-amplifier.o
 obj-$(CONFIG_SND_SIMPLE_SCU_CARD)	+= snd-soc-simple-scu-card.o
 obj-$(CONFIG_SND_AUDIO_GRAPH_CARD)	+= snd-soc-audio-graph-card.o
 obj-$(CONFIG_SND_AUDIO_GRAPH_SCU_CARD)	+= snd-soc-audio-graph-scu-card.o
diff --git a/sound/soc/generic/simple-amplifier.c b/sound/soc/generic/simple-amplifier.c
new file mode 100644
index 0000000..e135a43
--- /dev/null
+++ b/sound/soc/generic/simple-amplifier.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+// ALSA SoC simple amplifier driver
+//
+// Copyright 2018
+// Author:  Nicolò Veronese <nicveronese@gmail.com>
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regulator/consumer.h>
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+/* This struct is used to save the context */
+struct simple_amp_data {
+	struct device *dev;
+	struct regmap *regmap;
+	struct gpio_desc *power_gpio;
+};
+
+static int simple_amp_power_event(struct snd_soc_dapm_widget *widget,
+				 struct snd_kcontrol *kctrl, int event)
+{
+	struct snd_soc_component *c = snd_soc_dapm_to_component(widget->dapm);
+	struct simple_amp_data *data = snd_soc_component_get_drvdata(c);
+
+	/* Shutdown GPIO */
+    if (data->power_gpio)
+        gpiod_set_value_cansleep(data->power_gpio, SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
+static const struct snd_soc_dapm_widget simple_amp_dapm_widgets[] = {
+	SND_SOC_DAPM_INPUT("LEFT AMP IN"),
+	SND_SOC_DAPM_INPUT("RIGHT AMP IN"),
+
+	SND_SOC_DAPM_OUTPUT("SPK LEFT"),
+	SND_SOC_DAPM_OUTPUT("SPK RIGHT"),
+
+	SND_SOC_DAPM_REGULATOR_SUPPLY("VCC", 20, 0),
+	SND_SOC_DAPM_SPK("MUTE", simple_amp_power_event),
+};
+
+static const struct snd_soc_dapm_route simple_amp_dapm_routes[] = {
+	{ "MUTE", NULL, "LEFT AMP IN" },
+	{ "MUTE", NULL, "RIGHT AMP IN" },
+
+	{ "SPK LEFT", NULL, "VCC" },
+	{ "SPK RIGHT", NULL, "VCC" },
+
+	{ "SPK LEFT", NULL, "MUTE" },
+	{ "SPK RIGHT", NULL, "MUTE" },
+};
+
+static const struct snd_soc_component_driver simple_amp_component_driver = {
+	.name = "simple-amplifier",
+	.dapm_widgets = simple_amp_dapm_widgets,
+	.num_dapm_widgets = ARRAY_SIZE(simple_amp_dapm_widgets),
+	.dapm_routes = simple_amp_dapm_routes,
+	.num_dapm_routes = ARRAY_SIZE(simple_amp_dapm_routes),
+};
+
+static int asoc_simple_amp_probe(struct platform_device *pdev)
+{
+	struct simple_amp_data *data;
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+	data->dev = &pdev->dev;
+	platform_set_drvdata(pdev, data);
+
+	if(of_property_read_bool(pdev->dev.of_node,"shutdown-gpios")) {
+		data->power_gpio = devm_gpiod_get_optional(&pdev->dev, "shutdown", GPIOD_OUT_LOW);
+
+		if (IS_ERR(data->power_gpio)) {
+			ret = PTR_ERR(data->power_gpio);
+			dev_err(&pdev->dev, "Failed to get shutdown gpio: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return devm_snd_soc_register_component(dev,
+			&simple_amp_component_driver, NULL, 0);
+}
+
+static const struct of_device_id asoc_simple_of_match[] = {
+	{ .compatible = "simple-audio-amplifier", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, asoc_simple_of_match);
+
+static struct platform_driver asoc_simple_amp = {
+	.driver = {
+		.name = "asoc-simple-amplifier",
+		.of_match_table = of_match_ptr(asoc_simple_of_match),
+	},
+	.probe = asoc_simple_amp_probe,
+};
+
+module_platform_driver(asoc_simple_amp);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("ASoC Simple Amplifier");
+MODULE_AUTHOR("Nicolò Veronese <nicveronese@gmail.com>");
-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

             reply	other threads:[~2018-06-25 11:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-25 11:06 Nicolò Veronese [this message]
2018-06-25 11:06 ` [PATCH 2/2] ASoC: simple-amplifier: add dt-bindings Nicolò Veronese
2018-06-25 11:21 ` [PATCH 1/2] ASoC: add generic simple-amplifier support Mark Brown
2018-06-25 11:31   ` Jerome Brunet
2018-06-25 11:44     ` Mark Brown
2018-06-25 11:50       ` Jerome Brunet
2018-06-25 12:07         ` Nicolò Veronese
2018-06-25 12:12           ` Jerome Brunet
2018-06-25 12:28     ` Chen-Yu Tsai
2018-06-25 12:39       ` Mark Brown
2018-06-26  3:20         ` Chen-Yu Tsai
2018-06-26 11:28           ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1529924777-21136-1-git-send-email-nicveronese@gmail.com \
    --to=nicveronese@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).