All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@nvidia.com>
To: broonie@opensource.wolfsonmicro.com, lrg@slimlogic.co.uk
Cc: linux-tegra@vger.kernel.org, alsa-devel@alsa-project.org,
	Stephen Warren <swarren@nvidia.com>
Subject: [PATCH v3 4/4] ASoC: tegra: Harmony: Support the internal speaker
Date: Thu, 20 Jan 2011 13:52:11 -0700	[thread overview]
Message-ID: <1295556731-25165-5-git-send-email-swarren@nvidia.com> (raw)
In-Reply-To: <1295556731-25165-1-git-send-email-swarren@nvidia.com>
In-Reply-To: <1295393859-3396-1-git-send-email-swarren@wwwdotorg.org>

Add DAPM widget definitions, and code to control the speaker amplifier
GPIO to the Harmony machine driver. Currently, this path is always enabled,
while playback is active, since jack detection isn't yet implemented.

The driver initialization path has been reworked a little, and a new
driver/device introduced, in order to allow platform data to be passed in,
currently containing just the speaker enable GPIO ID.

The GPIO is only requested during _init, since that's the first time it is
guaranteed that the WM8903 module is loaded, probed, and hence has exported
its GPIO chip.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 sound/soc/tegra/harmony.c |   87 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 76 insertions(+), 11 deletions(-)

diff --git a/sound/soc/tegra/harmony.c b/sound/soc/tegra/harmony.c
index b160b71..e424997 100644
--- a/sound/soc/tegra/harmony.c
+++ b/sound/soc/tegra/harmony.c
@@ -2,7 +2,7 @@
  * harmony.c - Harmony machine ASoC driver
  *
  * Author: Stephen Warren <swarren@nvidia.com>
- * Copyright (C) 2010 - NVIDIA, Inc.
+ * Copyright (C) 2010-2011 - NVIDIA, Inc.
  *
  * Based on code copyright/by:
  *
@@ -29,7 +29,14 @@
  */
 
 #include <asm/mach-types.h>
+
+#include <linux/gpio.h>
 #include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <mach/harmony_audio.h>
+
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -40,9 +47,12 @@
 #include "tegra_pcm.h"
 #include "tegra_asoc_utils.h"
 
-#define PREFIX "ASoC Harmony: "
+#define DRV_NAME "tegra-snd-harmony"
+#define PREFIX DRV_NAME ": "
 
+static struct harmony_audio_platform_data *pdata;
 static struct platform_device *harmony_snd_device;
+static int gpio_spkr_en_requested;
 
 static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,
 					struct snd_pcm_hw_params *params)
@@ -107,7 +117,17 @@ static struct snd_soc_ops harmony_asoc_ops = {
 	.hw_params = harmony_asoc_hw_params,
 };
 
+static int harmony_event_int_spk(struct snd_soc_dapm_widget *w,
+					struct snd_kcontrol *k, int event)
+{
+	gpio_set_value_cansleep(pdata->gpio_spkr_en,
+				!!SND_SOC_DAPM_EVENT_ON(event));
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = {
+	SND_SOC_DAPM_SPK("Int Spk", harmony_event_int_spk),
 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
 	SND_SOC_DAPM_MIC("Mic Jack", NULL),
 };
@@ -115,6 +135,10 @@ static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = {
 static const struct snd_soc_dapm_route harmony_audio_map[] = {
 	{"Headphone Jack", NULL, "HPOUTR"},
 	{"Headphone Jack", NULL, "HPOUTL"},
+	{"Int Spk", NULL, "ROP"},
+	{"Int Spk", NULL, "RON"},
+	{"Int Spk", NULL, "LOP"},
+	{"Int Spk", NULL, "LON"},
 	{"Mic Bias", NULL, "Mic Jack"},
 	{"IN1L", NULL, "Mic Bias"},
 };
@@ -123,6 +147,7 @@ static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_soc_codec *codec = rtd->codec;
 	struct snd_soc_dapm_context *dapm = &codec->dapm;
+	int ret;
 
 	snd_soc_dapm_new_controls(dapm, harmony_dapm_widgets,
 					ARRAY_SIZE(harmony_dapm_widgets));
@@ -131,9 +156,19 @@ static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd)
 				ARRAY_SIZE(harmony_audio_map));
 
 	snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
+	snd_soc_dapm_enable_pin(dapm, "Int Spk");
 	snd_soc_dapm_enable_pin(dapm, "Mic Jack");
 	snd_soc_dapm_sync(dapm);
 
+	ret = gpio_request(pdata->gpio_spkr_en, "spkr_en");
+	if (ret) {
+		pr_err(PREFIX "cannot get spkr_en gpio\n");
+		return ret;
+	}
+	gpio_spkr_en_requested = 1;
+
+	gpio_direction_output(pdata->gpio_spkr_en, 0);
+
 	return 0;
 }
 
@@ -154,13 +189,19 @@ static struct snd_soc_card snd_soc_harmony = {
 	.num_links = 1,
 };
 
-static int __init harmony_soc_modinit(void)
+static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev)
 {
 	int ret;
 
-	if (!machine_is_harmony()) {
-		pr_err(PREFIX "Not running on Tegra Harmony!\n");
-		return -ENODEV;
+	if (pdev->id != 0) {
+		dev_err(&pdev->dev, "ID %d out of range\n", pdev->id);
+		return -EINVAL;
+	}
+
+	pdata = pdev->dev.platform_data;
+	if (!pdata) {
+		dev_err(&pdev->dev, "no platform data supplied\n");
+		return -EINVAL;
 	}
 
 	ret = tegra_asoc_utils_init();
@@ -173,7 +214,7 @@ static int __init harmony_soc_modinit(void)
 	 */
 	harmony_snd_device = platform_device_alloc("soc-audio", -1);
 	if (harmony_snd_device == NULL) {
-		pr_err(PREFIX "platform_device_alloc failed\n");
+		dev_err(&pdev->dev, "platform_device_alloc failed\n");
 		ret = -ENOMEM;
 		goto err_clock_utils;
 	}
@@ -182,7 +223,7 @@ static int __init harmony_soc_modinit(void)
 
 	ret = platform_device_add(harmony_snd_device);
 	if (ret) {
-		pr_err(PREFIX "platform_device_add failed (%d)\n",
+		dev_err(&pdev->dev, "platform_device_add failed (%d)\n",
 			ret);
 		goto err_device_put;
 	}
@@ -195,15 +236,39 @@ err_clock_utils:
 	tegra_asoc_utils_fini();
 	return ret;
 }
-module_init(harmony_soc_modinit);
 
-static void __exit harmony_soc_modexit(void)
+static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev)
 {
 	platform_device_unregister(harmony_snd_device);
 
+	if (gpio_spkr_en_requested)
+		gpio_free(pdata->gpio_spkr_en);
+
 	tegra_asoc_utils_fini();
+
+	return 0;
+}
+
+static struct platform_driver tegra_snd_harmony_driver = {
+	.driver = {
+		.name = DRV_NAME,
+		.owner = THIS_MODULE,
+	},
+	.probe = tegra_snd_harmony_probe,
+	.remove = __devexit_p(tegra_snd_harmony_remove),
+};
+
+static int __init snd_tegra_harmony_init(void)
+{
+	return platform_driver_register(&tegra_snd_harmony_driver);
+}
+module_init(snd_tegra_harmony_init);
+
+static void __exit snd_tegra_harmony_exit(void)
+{
+	platform_driver_unregister(&tegra_snd_harmony_driver);
 }
-module_exit(harmony_soc_modexit);
+module_exit(snd_tegra_harmony_exit);
 
 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
 MODULE_DESCRIPTION("Harmony machine ASoC driver");
-- 
1.7.1

      parent reply	other threads:[~2011-01-20 20:52 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1295393859-3396-1-git-send-email-swarren@wwwdotorg.org>
     [not found] ` <1295393859-3396-2-git-send-email-swarren@wwwdotorg.org>
2011-01-19  0:21   ` [PATCH 1/3] ASoC: WM8903: Add wm8903_set_gpio Mark Brown
2011-01-19  0:25 ` [PATCH 0/3] Tegra: Add internal speaker support Mark Brown
2011-01-19  0:29   ` Stephen Warren
     [not found]     ` <AANLkTi=m585PZum2NQUOqq1PiqP84LuT-qCruzaO7x7t@mail.gmail.com>
2011-01-19 11:30       ` Mark Brown
2011-01-19 12:47 ` Liam Girdwood
2011-01-19 20:50 ` [PATCH v2 0/4] Tegra: Harmony: " Stephen Warren
2011-01-20 10:04   ` Liam Girdwood
2011-01-19 20:50 ` [PATCH v2 1/4] ASoC: WM8903: Expose GPIOs through gpiolib Stephen Warren
2011-01-20 11:53   ` Mark Brown
2011-01-20 17:23     ` Stephen Warren
2011-01-20 20:33       ` Mark Brown
2011-01-19 20:50 ` [PATCH v2 2/4] ARM: tegra: Add Harmony sound platform data type Stephen Warren
2011-01-19 20:50 ` [PATCH v2 3/4] ARM: tegra: Platform data fixes for ASoC driver updates Stephen Warren
2011-01-19 20:50 ` [PATCH v2 4/4] ASoC: tegra: Harmony: Support the internal speaker Stephen Warren
2011-01-20 11:58   ` Mark Brown
2011-01-25 20:29   ` Mark Brown
2011-01-26  3:46     ` Stephen Warren
2011-01-26 11:00       ` Mark Brown
2011-01-20 20:52 ` [PATCH v3 0/4] Tegra: Harmony: Add internal speaker support Stephen Warren
2011-01-20 20:52 ` [PATCH v3 1/4] ASoC: WM8903: Expose GPIOs through gpiolib Stephen Warren
2011-01-21 12:05   ` Mark Brown
2011-01-20 20:52 ` [PATCH v3 2/4] ARM: tegra: Add Harmony sound platform data type Stephen Warren
2011-01-21 18:43   ` Colin Cross
2011-01-21 22:35     ` Stephen Warren
2011-01-21 22:41       ` Colin Cross
2011-01-21 23:41         ` Mark Brown
2011-01-21 23:49           ` Stephen Warren
2011-01-22  5:14             ` Olof Johansson
2011-01-22  5:34               ` Stephen Warren
2011-01-22  5:40                 ` Olof Johansson
2011-01-20 20:52 ` [PATCH v3 3/4] ARM: tegra: Platform data fixes for ASoC driver updates Stephen Warren
2011-01-20 21:22   ` Mark Brown
2011-01-20 22:15     ` Liam Girdwood
2011-01-21 17:45     ` Stephen Warren
2011-01-21 17:50       ` Mark Brown
2011-01-21 18:06         ` Stephen Warren
2011-01-21 18:11           ` Mark Brown
2011-01-21 18:22             ` Stephen Warren
2011-01-21 18:27               ` Mark Brown
2011-01-21 18:36                 ` Stephen Warren
2011-01-21 18:39                   ` Mark Brown
2011-01-21 18:51                     ` Stephen Warren
2011-01-21 18:57                       ` Mark Brown
2011-01-21 22:41                         ` Stephen Warren
2011-01-20 20:52 ` Stephen Warren [this message]

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=1295556731-25165-5-git-send-email-swarren@nvidia.com \
    --to=swarren@nvidia.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linux-tegra@vger.kernel.org \
    --cc=lrg@slimlogic.co.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.