Skip to contentSkip to conversation

ASoC: Initial audio support for Speyside on Cragganmore 6410

PATCH In review Mark Brown 3 participants 10 messages Apr 13, 2011

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/8 ASoC: Initial audio support for Speyside on Cragganmore 6410

This is minimal code required to get audio out of the Speyside audio subsystem on the Wolfson Cragganmore 6410 reference platform. It sets up the link between the CPU and AIF1 of the WM8915 on the system, enabling audio playback via the headphone and speaker outputs of the device (which require no further configuration except runtime). It allows verification of basic functionality of the system.

---
 sound/soc/samsung/Kconfig    |    6 ++
 sound/soc/samsung/Makefile   |    2 +
 sound/soc/samsung/speyside.c |  123 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/samsung/speyside.c
sound/soc/samsung/Kconfig +6 -0
index b8c7a2e..726af2e 100644
@@ -170,3 +170,9 @@ config SND_SOC_SMDK_WM8580_PCM
 	select SND_SAMSUNG_PCM
 	help
 	  Say Y if you want to add support for SoC audio on the SMDK.
+
+config SND_SOC_SPEYSIDE
+	tristate "Audio support for Wolfson Speyside"
+	depends on SND_SOC_SAMSUNG && MACH_WLF_CRAGG_6410
+	select SND_SAMSUNG_I2S
+	select SND_SOC_WM8915
sound/soc/samsung/Makefile +2 -0
index 6c598fc..683843a 100644
@@ -35,6 +35,7 @@ snd-soc-s3c64xx-smartq-wm8987-objs := smartq_wm8987.o
 snd-soc-goni-wm8994-objs := goni_wm8994.o
 snd-soc-smdk-spdif-objs := smdk_spdif.o
 snd-soc-smdk-wm8580pcm-objs := smdk_wm8580pcm.o
+snd-soc-speyside-objs := speyside.o
 
 obj-$(CONFIG_SND_SOC_SAMSUNG_JIVE_WM8750) += snd-soc-jive-wm8750.o
 obj-$(CONFIG_SND_SOC_SAMSUNG_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
@@ -53,3 +54,4 @@ obj-$(CONFIG_SND_SOC_SMARTQ) += snd-soc-s3c64xx-smartq-wm8987.o
 obj-$(CONFIG_SND_SOC_SAMSUNG_SMDK_SPDIF) += snd-soc-smdk-spdif.o
 obj-$(CONFIG_SND_SOC_GONI_AQUILA_WM8994) += snd-soc-goni-wm8994.o
 obj-$(CONFIG_SND_SOC_SMDK_WM8580_PCM) += snd-soc-smdk-wm8580pcm.o
+obj-$(CONFIG_SND_SOC_SPEYSIDE) += snd-soc-speyside.o
sound/soc/samsung/speyside.c new file +123 -0

123 lines not on this page · raw message

Signature · 1 line
1.7.4.1
author
#1 lore raw

PATCH 2/8 ASoC: Add basic widgets for WM8915 Speyside

Provide widgets for the basic widgets connected directly to the WM8915 on Speyside - the headphones, speaker, digital and analogue microphones. For the outputs this is just documentation, for the inputs this ensures that the relevant microphone biases are enabled when they are in use.

---
 sound/soc/samsung/speyside.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
sound/soc/samsung/speyside.c +28 -0
index f6dcee7b..6ec44a3 100644
@@ -63,10 +63,38 @@ static struct snd_soc_dai_link speyside_dai[] = {
 	},
 };
 
+static struct snd_soc_dapm_widget widgets[] = {
+	SND_SOC_DAPM_HP("Headphone", NULL),
+
+	SND_SOC_DAPM_SPK("Main Speaker", NULL),
+
+	SND_SOC_DAPM_MIC("Main AMIC", NULL),
+	SND_SOC_DAPM_MIC("Main DMIC", NULL),
+};
+
+static struct snd_soc_dapm_route audio_paths[] = {
+	{ "IN1LP", NULL, "MICB2" },
+	{ "MICB2", NULL, "Main AMIC" },
+
+	{ "DMIC1DAT", NULL, "MICB1" },
+	{ "DMIC2DAT", NULL, "MICB1" },
+	{ "MICB1", NULL, "Main DMIC" },
+
+	{ "Headphone", NULL, "HPOUT1L" },
+	{ "Headphone", NULL, "HPOUT1R" },
+
+	{ "Main Speaker", NULL, "SPKDAT" },
+};
+
 static struct snd_soc_card speyside = {
 	.name = "Speyside",
 	.dai_link = speyside_dai,
 	.num_links = ARRAY_SIZE(speyside_dai),
+
+	.dapm_widgets = widgets,
+	.num_dapm_widgets = ARRAY_SIZE(widgets),
+	.dapm_routes = audio_paths,
+	.num_dapm_routes = ARRAY_SIZE(audio_paths),
 };
 
 static __devinit int speyside_probe(struct platform_device *pdev)
Signature · 1 line
1.7.4.1
author
#2 lore raw

PATCH 3/8 ASoC: Optimise clock management for WM8915 Speyside

In reply to Mark Brown

Dynamically enable and disable the FLL on the WM8915, configuring the system clock to 256fs for 48kHz when the device is active but reverting to using the input 32.768kHz clock directly at other times to support features such as jack detection with minimal power consumption.

---
 sound/soc/samsung/speyside.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
sound/soc/samsung/speyside.c +37 -0
index 6ec44a3..1e51750 100644
@@ -14,6 +14,33 @@
 
 #include "../codecs/wm8915.h"
 
+static int speyside_set_bias_level(struct snd_soc_card *card,
+				   enum snd_soc_bias_level level)
+{
+	struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
+	int ret;
+
+	switch (level) {
+	case SND_SOC_BIAS_STANDBY:
+		ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
+					     32768, SND_SOC_CLOCK_IN);
+		if (ret < 0)
+			return ret;
+
+		ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
+					  0, 0, 0);
+		if (ret < 0) {
+			pr_err("Failed to stop FLL\n");
+			return ret;
+		}
+
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 static int speyside_hw_params(struct snd_pcm_substream *substream,
 			      struct snd_pcm_hw_params *params)
 {
@@ -51,6 +78,13 @@ static struct snd_soc_ops speyside_ops = {
 	.hw_params = speyside_hw_params,
 };
 
+static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_dai *dai = rtd->codec_dai;
+
+	return snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
+}
+
 static struct snd_soc_dai_link speyside_dai[] = {
 	{
 		.name = "CPU",
@@ -59,6 +93,7 @@ static struct snd_soc_dai_link speyside_dai[] = {
 		.codec_dai_name = "wm8915-aif1",
 		.platform_name = "samsung-audio",
 		.codec_name = "wm8915.1-001a",
+		.init = speyside_wm8915_init,
 		.ops = &speyside_ops,
 	},
 };
@@ -91,6 +126,8 @@ static struct snd_soc_card speyside = {
 	.dai_link = speyside_dai,
 	.num_links = ARRAY_SIZE(speyside_dai),
 
+	.set_bias_level = speyside_set_bias_level,
+
 	.dapm_widgets = widgets,
 	.num_dapm_widgets = ARRAY_SIZE(widgets),
 	.dapm_routes = audio_paths,
Signature · 1 line
1.7.4.1
author
#3 lore raw

PATCH 4/8 ASoC: Support the sub speaker driver on Speyside

In reply to Mark Brown

Speyside includes a WM9081 configured as an external speaker driver taking an analogue input from HPOUT2 on the WM8915 on the system. Add support for this to the driver, using a prefix of "Sub" for the WM9081 controls to ensure we avoid collisions with controls on the WM8915.

---
 sound/soc/samsung/Kconfig    |    1 +
 sound/soc/samsung/speyside.c |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
sound/soc/samsung/Kconfig +1 -0
index 726af2e..459566b 100644
@@ -176,3 +176,4 @@ config SND_SOC_SPEYSIDE
 	depends on SND_SOC_SAMSUNG && MACH_WLF_CRAGG_6410
 	select SND_SAMSUNG_I2S
 	select SND_SOC_WM8915
+	select SND_SOC_WM9081
sound/soc/samsung/speyside.c +34 -0
index 1e51750..0adaf7f 100644
@@ -13,6 +13,7 @@
 #include <sound/soc-dapm.h>
 
 #include "../codecs/wm8915.h"
+#include "../codecs/wm9081.h"
 
 static int speyside_set_bias_level(struct snd_soc_card *card,
 				   enum snd_soc_bias_level level)
@@ -98,6 +99,30 @@ static struct snd_soc_dai_link speyside_dai[] = {
 	},
 };
 
+static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
+{
+	snd_soc_dapm_nc_pin(dapm, "LINEOUT");
+
+	/* At any time the WM9081 is active it will have this clock */
+	return snd_soc_codec_set_sysclk(dapm->codec, WM9081_SYSCLK_MCLK,
+					48000 * 256, 0);
+}
+
+static struct snd_soc_aux_dev speyside_aux_dev[] = {
+	{
+		.name = "wm9081",
+		.codec_name = "wm9081.1-006c",
+		.init = speyside_wm9081_init,
+	},
+};
+
+static struct snd_soc_codec_conf speyside_codec_conf[] = {
+	{
+		.dev_name = "wm9081.1-006c",
+		.name_prefix = "Sub",
+	},
+};
+
 static struct snd_soc_dapm_widget widgets[] = {
 	SND_SOC_DAPM_HP("Headphone", NULL),
 
@@ -118,6 +143,11 @@ static struct snd_soc_dapm_route audio_paths[] = {
 	{ "Headphone", NULL, "HPOUT1L" },
 	{ "Headphone", NULL, "HPOUT1R" },
 
+	{ "Sub IN1", NULL, "HPOUT2L" },
+	{ "Sub IN2", NULL, "HPOUT2R" },
+
+	{ "Main Speaker", NULL, "Sub SPKN" },
+	{ "Main Speaker", NULL, "Sub SPKP" },
 	{ "Main Speaker", NULL, "SPKDAT" },
 };
 
@@ -125,6 +155,10 @@ static struct snd_soc_card speyside = {
 	.name = "Speyside",
 	.dai_link = speyside_dai,
 	.num_links = ARRAY_SIZE(speyside_dai),
+	.aux_dev = speyside_aux_dev,
+	.num_aux_devs = ARRAY_SIZE(speyside_aux_dev),
+	.codec_conf = speyside_codec_conf,
+	.num_configs = ARRAY_SIZE(speyside_codec_conf),
 
 	.set_bias_level = speyside_set_bias_level,
 
Signature · 1 line
1.7.4.1
author
#4 lore raw

PATCH 5/8 ASoC: Add Speyside headset jack detection support

In reply to Mark Brown

Speyside makes use of support the WM8915 has for detecting the polarity of the microphone and ground connections on headsets, using a GPIO to control the polarity of the ground connection and switching between the two microphone bias supplies available on the device in order to do so. As a result of this the detection support is more involved than for most other CODECs, using a callback to configure the current polarity of the jack and translate this into the board-specific connections required for the current scenario.

On Android some additional work is required to hook this up to the application layer as the Android HeadsetObserver monitors a custom drivers/switch API rather than the standard Linux APIs. This can be done by either updating HeadsetObserver or modifying the ALSA core to report via drivers/switch as well.

---
 sound/soc/samsung/speyside.c |   78 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 77 insertions(+), 1 deletions(-)
sound/soc/samsung/speyside.c +77 -1
index 0adaf7f..612a39e 100644
@@ -11,10 +11,14 @@
 
 #include <sound/soc.h>
 #include <sound/soc-dapm.h>
+#include <sound/jack.h>
+#include <linux/gpio.h>
 
 #include "../codecs/wm8915.h"
 #include "../codecs/wm9081.h"
 
+#define WM8915_HPSEL_GPIO 214
+
 static int speyside_set_bias_level(struct snd_soc_card *card,
 				   enum snd_soc_bias_level level)
 {
@@ -79,11 +83,74 @@ static struct snd_soc_ops speyside_ops = {
 	.hw_params = speyside_hw_params,
 };
 
+static struct snd_soc_jack speyside_headset;
+
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin speyside_headset_pins[] = {
+	{
+		.pin = "Headset Mic",
+		.mask = SND_JACK_MICROPHONE,
+	},
+	{
+		.pin = "Headphone",
+		.mask = SND_JACK_HEADPHONE,
+	},
+};
+
+/* Default the headphone selection to active high */
+static int speyside_jack_polarity;
+
+static int speyside_get_micbias(struct snd_soc_dapm_widget *source,
+				struct snd_soc_dapm_widget *sink)
+{
+	if (speyside_jack_polarity && (strcmp(source->name, "MICB1") == 0))
+		return 1;
+	if (!speyside_jack_polarity && (strcmp(source->name, "MICB2") == 0))
+		return 1;
+
+	return 0;
+}
+
+static void speyside_set_polarity(struct snd_soc_codec *codec,
+				  int polarity)
+{
+	speyside_jack_polarity = !polarity;
+	gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
+
+	/* Re-run DAPM to make sure we're using the correct mic bias */
+	snd_soc_dapm_sync(&codec->dapm);
+}
+
 static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_soc_dai *dai = rtd->codec_dai;
+	struct snd_soc_codec *codec = rtd->codec;
+	int ret;
+
+	ret = snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
+	if (ret < 0)
+		return ret;
+
+	ret = gpio_request(WM8915_HPSEL_GPIO, "HP_SEL");
+	if (ret != 0)
+		pr_err("Failed to request HP_SEL GPIO: %d\n", ret);
+	gpio_direction_output(WM8915_HPSEL_GPIO, speyside_jack_polarity);
 
-	return snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
+	ret = snd_soc_jack_new(codec, "Headset",
+			       SND_JACK_HEADSET | SND_JACK_BTN_0,
+			       &speyside_headset);
+	if (ret)
+		return ret;
+
+	ret = snd_soc_jack_add_pins(&speyside_headset,
+				    ARRAY_SIZE(speyside_headset_pins),
+				    speyside_headset_pins);
+	if (ret)
+		return ret;
+
+	wm8915_detect(codec, &speyside_headset, speyside_set_polarity);
+
+	return 0;
 }
 
 static struct snd_soc_dai_link speyside_dai[] = {
@@ -125,6 +192,7 @@ static struct snd_soc_codec_conf speyside_codec_conf[] = {
 
 static struct snd_soc_dapm_widget widgets[] = {
 	SND_SOC_DAPM_HP("Headphone", NULL),
+	SND_SOC_DAPM_MIC("Headset Mic", NULL),
 
 	SND_SOC_DAPM_SPK("Main Speaker", NULL),
 
@@ -133,7 +201,15 @@ static struct snd_soc_dapm_widget widgets[] = {
 };
 
 static struct snd_soc_dapm_route audio_paths[] = {
+	{ "IN1RN", NULL, "MICB1" },
+	{ "IN1RP", NULL, "MICB1" },
+	{ "IN1RN", NULL, "MICB2" },
+	{ "IN1RP", NULL, "MICB2" },
+	{ "MICB1", NULL, "Headset Mic", speyside_get_micbias },
+	{ "MICB2", NULL, "Headset Mic", speyside_get_micbias },
+
 	{ "IN1LP", NULL, "MICB2" },
+	{ "IN1RN", NULL, "MICB1" },
 	{ "MICB2", NULL, "Main AMIC" },
 
 	{ "DMIC1DAT", NULL, "MICB1" },
Signature · 1 line
1.7.4.1
author
#5 lore raw

PATCH 6/8 ASoC: Add pin switches for fixed analogue inputs and outputs on Speyside

In reply to Mark Brown

Pin switches enable direct control of the DAPM state from userspace, enabling simple enabling and disabling of the path. This is especially useful for outputs such as the speaker which are composed of several physical devices as it allows them to be controlled as a group.

---
 sound/soc/samsung/speyside.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
sound/soc/samsung/speyside.c +8 -0
index 612a39e..e171a32 100644
@@ -190,6 +190,12 @@ static struct snd_soc_codec_conf speyside_codec_conf[] = {
 	},
 };
 
+static const struct snd_kcontrol_new controls[] = {
+	SOC_DAPM_PIN_SWITCH("Main Speaker"),
+	SOC_DAPM_PIN_SWITCH("Main DMIC"),
+	SOC_DAPM_PIN_SWITCH("Main AMIC"),
+};
+
 static struct snd_soc_dapm_widget widgets[] = {
 	SND_SOC_DAPM_HP("Headphone", NULL),
 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
@@ -238,6 +244,8 @@ static struct snd_soc_card speyside = {
 
 	.set_bias_level = speyside_set_bias_level,
 
+	.controls = controls,
+	.num_controls = ARRAY_SIZE(controls),
 	.dapm_widgets = widgets,
 	.num_dapm_widgets = ARRAY_SIZE(widgets),
 	.dapm_routes = audio_paths,
Signature · 1 line
1.7.4.1
author
#6 lore raw

PATCH 7/8 ASoC: Add stub baseband link on Speyside

In reply to Mark Brown

Demonstrate the connection of a baseband to the system. We add a DAI for the link to the baseband. This will become visible to the application layer - audio should be started from the application layer using an application such as this:

http://opensource.wolfsonmicro.com/~gg/bluetooth-pcm/bluetooth_pcm.c

which starts up audio as for CPU based playback and record up to the point where data is streamed.

Due to non-availability of baseband simulation hardware we reuse the configuration for the CPU link with the CODEC acting as clock master, allowing signals to be observed with a scope. A more standard system would have separate configuration for the baseband with its own ops structure and operations. Normally the baseband would be clock master as the baseband audio will be synchronised to the external telephony network.

---
 sound/soc/samsung/speyside.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
sound/soc/samsung/speyside.c +11 -0
index e171a32..a0c14a8 100644
@@ -164,6 +164,15 @@ static struct snd_soc_dai_link speyside_dai[] = {
 		.init = speyside_wm8915_init,
 		.ops = &speyside_ops,
 	},
+	{
+		.name = "Baseband",
+		.stream_name = "Baseband",
+		.cpu_dai_name = "wm8915-aif2",
+		.codec_dai_name = "wm1250-ev1",
+		.codec_name = "wm1250-ev1.1-0027",
+		.platform_name = "samsung-audio",
+		.ops = &speyside_ops,
+	},
 };
 
 static int speyside_wm9081_init(struct snd_soc_dapm_context *dapm)
@@ -194,6 +203,8 @@ static const struct snd_kcontrol_new controls[] = {
 	SOC_DAPM_PIN_SWITCH("Main Speaker"),
 	SOC_DAPM_PIN_SWITCH("Main DMIC"),
 	SOC_DAPM_PIN_SWITCH("Main AMIC"),
+	SOC_DAPM_PIN_SWITCH("WM1250 Input"),
+	SOC_DAPM_PIN_SWITCH("WM1250 Output"),
 };
 
 static struct snd_soc_dapm_widget widgets[] = {
Signature · 1 line
1.7.4.1
author
#7 lore raw

PATCH 8/8 ASoC: Mark Speyside widgets as ignoring suspend

In reply to Mark Brown

Allow audio paths through the Speyside system to be kept active while the system is suspended (for example, when on a voice call) by marking all the external widgets and the DAI link to the WM1250-EV1 baseband module as ignoring suspend.

---
 sound/soc/samsung/speyside.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
sound/soc/samsung/speyside.c +16 -0
index a0c14a8..337855a 100644
@@ -153,6 +153,19 @@ static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
 	return 0;
 }
 
+static int speyside_late_probe(struct snd_soc_card *card)
+{
+	snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
+	snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
+	snd_soc_dapm_ignore_suspend(&card->dapm, "Main AMIC");
+	snd_soc_dapm_ignore_suspend(&card->dapm, "Main DMIC");
+	snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
+	snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Output");
+	snd_soc_dapm_ignore_suspend(&card->dapm, "WM1250 Input");
+
+	return 0;
+}
+
 static struct snd_soc_dai_link speyside_dai[] = {
 	{
 		.name = "CPU",
@@ -172,6 +185,7 @@ static struct snd_soc_dai_link speyside_dai[] = {
 		.codec_name = "wm1250-ev1.1-0027",
 		.platform_name = "samsung-audio",
 		.ops = &speyside_ops,
+		.ignore_suspend = 1,
 	},
 };
 
@@ -261,6 +275,8 @@ static struct snd_soc_card speyside = {
 	.num_dapm_widgets = ARRAY_SIZE(widgets),
 	.dapm_routes = audio_paths,
 	.num_dapm_routes = ARRAY_SIZE(audio_paths),
+
+	.late_probe = speyside_late_probe,
 };
 
 static __devinit int speyside_probe(struct platform_device *pdev)
Signature · 1 line
1.7.4.1
Acked-by on v1 1/8
#8 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown

This is minimal code required to get audio out of the Speyside audio subsystem on the Wolfson Cragganmore 6410 reference platform. It sets up the link between the CPU and AIF1 of the WM8915 on the system, enabling audio playback via the headphone and speaker outputs of the device (which require no further configuration except runtime). It allows verification of basic functionality of the system.

All

Acked-by on v1 1/8
#9 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown

This is minimal code required to get audio out of the Speyside audio subsystem on the Wolfson Cragganmore 6410 reference platform.  It sets up the link between the CPU and AIF1 of the WM8915 on the system, enabling audio playback via the headphone and speaker outputs of the device (which require no further configuration except runtime).  It allows verification of basic functionality of the system.

All

Thanks
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel