Skip to contentSkip to conversation

ASoC: Add ADAV80x codec driver

PATCH In review Lars-Peter Clausen 3 participants 8 messages Jun 22, 2011 – Jun 23, 2011

Subsystems (3)
lore
Share & tools
lore
author maintainer
#3 lore raw

PATCH 4/4 Blackfin: bf537: Stamp: Register adav801 codec and ASoC machine driver

In reply to Lars-Peter Clausen

There is already an entry in the spi device table for the codec, but the modalias was wrong. Also the config symbol name for the codec is wrong, so this is fixed as well.

---
 arch/blackfin/mach-bf537/boards/stamp.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
arch/blackfin/mach-bf537/boards/stamp.c +16 -3
index 5d30566..198018e 100644
@@ -1000,9 +1000,9 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
 	},
 #endif
 
-#if defined(CONFIG_SND_BF5XX_SOC_ADAV80X) || defined(CONFIG_SND_BF5XX_SOC_ADAV80X_MODULE)
+#if defined(CONFIG_SND_SOC_ADAV80X) || defined(CONFIG_SND_SOC_ADV80X_MODULE)
 	{
-		.modalias = "adav80x",
+		.modalias = "adav801",
 		.max_speed_hz = 3125000,     /* max spi clock (SCK) speed in HZ */
 		.bus_num = 0,
 		.chip_select = 1,
@@ -2118,7 +2118,7 @@ static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
 	},
 #endif
 
-#if defined(CONFIG_SND_BF5XX_SOC_ADAV80X) || defined(CONFIG_SND_BF5XX_SOC_ADAV80X_MODULE)
+#if defined(CONFIG_SND_SOC_ADAV80X) || defined(CONFIG_SND_SOC_ADAV80X_MODULE)
 	{
 		I2C_BOARD_INFO("adav803", 0x10),
 	},
@@ -2553,6 +2553,14 @@ static struct platform_device bfin_ad73311_codec_device = {
 };
 #endif
 
+#if defined(CONFIG_SND_SOC_BFIN_EVAL_ADAV80X) || \
+	defined(CONFIG_SND_SOC_BFIN_EVAL_ADAV80X_MODULE)
+static struct platform_device bfin_eval_adav801_device = {
+	.name = "bfin-eval-adav801",
+	.id = -1,
+};
+#endif
+
 #if defined(CONFIG_SND_BF5XX_SOC_I2S) || defined(CONFIG_SND_BF5XX_SOC_I2S_MODULE)
 static struct platform_device bfin_i2s = {
 	.name = "bfin-i2s",
@@ -2833,6 +2841,11 @@ static struct platform_device *stamp_devices[] __initdata = {
 	defined(CONFIG_SND_SOC_BFIN_EVAL_ADAU1701_MODULE)
 	&bf5xx_adau1701_device,
 #endif
+
+#if defined(CONFIG_SND_SOC_BFIN_EVAL_ADAV80X) || \
+	defined(CONFIG_SND_SOC_BFIN_EVAL_ADAV80X_MODULE)
+	&bfin_eval_adav801_device,
+#endif
 };
 
 static int __init net2272_init(void)
Signature · 1 line
1.7.2.5

Lars-Peter Clausen

author maintainer
#0 lore raw

PATCH 1/4 ASoC: Add ADAV80x codec driver

This patch adds support for the Analog Devices ADAV801 and ADAV803 audio codec.

---
 sound/soc/codecs/Kconfig   |    4 +
 sound/soc/codecs/Makefile  |    2 +
 sound/soc/codecs/adav80x.c |  846 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/adav80x.h |   23 ++
 4 files changed, 875 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/adav80x.c
 create mode 100644 sound/soc/codecs/adav80x.h
sound/soc/codecs/Kconfig +4 -0
index 2998e65..ff43405 100644
@@ -17,6 +17,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI
 	select SND_SOC_AD1980 if SND_SOC_AC97_BUS
 	select SND_SOC_AD73311
+	select SND_SOC_ADAV80X
 	select SND_SOC_ADS117X
 	select SND_SOC_AK4104 if SPI_MASTER
 	select SND_SOC_AK4535 if I2C
@@ -137,6 +138,9 @@ config SND_SOC_ADAU1701
 	select SIGMA
 	tristate
 
+config SND_SOC_ADAV80X
+	tristate
+
 config SND_SOC_ADS117X
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 51cd3d4..4957431 100644
@@ -5,6 +5,7 @@ snd-soc-ad193x-objs := ad193x.o
 snd-soc-ad1980-objs := ad1980.o
 snd-soc-ad73311-objs := ad73311.o
 snd-soc-adau1701-objs := adau1701.o
+snd-soc-adav80x-objs := adav80x.o
 snd-soc-ads117x-objs := ads117x.o
 snd-soc-ak4104-objs := ak4104.o
 snd-soc-ak4535-objs := ak4535.o
@@ -99,6 +100,7 @@ obj-$(CONFIG_SND_SOC_AD193X)	+= snd-soc-ad193x.o
 obj-$(CONFIG_SND_SOC_AD1980)	+= snd-soc-ad1980.o
 obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
 obj-$(CONFIG_SND_SOC_ADAU1701)  += snd-soc-adau1701.o
+obj-$(CONFIG_SND_SOC_ADAV80X)  += snd-soc-adav80x.o
 obj-$(CONFIG_SND_SOC_ADS117X)	+= snd-soc-ads117x.o
 obj-$(CONFIG_SND_SOC_AK4104)	+= snd-soc-ak4104.o
 obj-$(CONFIG_SND_SOC_AK4535)	+= snd-soc-ak4535.o
sound/soc/codecs/adav80x.c new file +846 -0

846 lines not on this page · raw message

sound/soc/codecs/adav80x.h new file +23 -0
new file mode 100644
index 0000000..fab23cd
@@ -0,0 +1,23 @@
+/*
+ * header file for ADAV80X parts
+ *
+ * Copyright 2011 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef _ADAV80X_H
+#define _ADAV80X_H
+
+enum adav80x_pll_src {
+	ADAV80X_PLL_SRC_XIN,
+	ADAV80X_PLL_SRC_XTAL,
+	ADAV80X_PLL_SRC_MCLKI,
+};
+
+enum adav80x_pll {
+	ADAV80X_PLL1 = 0,
+	ADAV80X_PLL2 = 1,
+};
+
+#endif
Signature · 1 line
1.7.2.5
author maintainer
#1 lore raw

PATCH 2/4 ASoC: Blackfin: Add machine driver for EVAL-ADAV80X boards

Add a machine driver to support the EVAL-ADAV801 and EVAL-ADAV803 boards connected to a Analog Devices BF5XX evaluation board.

---
 sound/soc/blackfin/Kconfig             |   13 +++
 sound/soc/blackfin/Makefile            |    2 +
 sound/soc/blackfin/bfin-eval-adav80x.c |  151 ++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/blackfin/bfin-eval-adav80x.c
sound/soc/blackfin/Kconfig +13 -0
index fa6a6d2..fe9d548 100644
@@ -27,6 +27,19 @@ config SND_SOC_BFIN_EVAL_ADAU1701
 	  board connected to one of the Blackfin evaluation boards like the
 	  BF5XX-STAMP or BF5XX-EZKIT.
 
+config SND_SOC_BFIN_EVAL_ADAV80X
+	tristate "Support for the EVAL-ADAV80X boards on Blackfin eval boards"
+	depends on SND_BF5XX_I2S && (SPI_MASTER || I2C)
+	select SND_BF5XX_SOC_I2S
+	select SND_SOC_ADAV80X
+	help
+	  Say Y if you want to add support for the Analog Devices EVAL-ADAV801 or
+	  EVAL-ADAV803 board connected to one of the Blackfin evaluation boards
+	  like the BF5XX-STAMP or BF5XX-EZKIT.
+
+	  Note: This driver assumes that the ADAV80X digital record and playback
+	  interfaces are connected to the first SPORT port on the BF5XX board.
+
 config SND_BF5XX_SOC_AD73311
 	tristate "SoC AD73311 Audio support for Blackfin"
 	depends on SND_BF5XX_I2S
sound/soc/blackfin/Makefile +2 -0
index f01bff6..6018bf5 100644
@@ -22,6 +22,7 @@ snd-ssm2602-objs := bf5xx-ssm2602.o
 snd-ad73311-objs := bf5xx-ad73311.o
 snd-ad193x-objs := bf5xx-ad193x.o
 snd-soc-bfin-eval-adau1701-objs := bfin-eval-adau1701.o
+snd-soc-bfin-eval-adav80x-objs := bfin-eval-adav80x.o
 
 obj-$(CONFIG_SND_BF5XX_SOC_AD1836) += snd-ad1836.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD1980) += snd-ad1980.o
@@ -29,3 +30,4 @@ obj-$(CONFIG_SND_BF5XX_SOC_SSM2602) += snd-ssm2602.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD73311) += snd-ad73311.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD193X) += snd-ad193x.o
 obj-$(CONFIG_SND_SOC_BFIN_EVAL_ADAU1701) += snd-soc-bfin-eval-adau1701.o
+obj-$(CONFIG_SND_SOC_BFIN_EVAL_ADAV80X) += snd-soc-bfin-eval-adav80x.o
sound/soc/blackfin/bfin-eval-adav80x.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
1.7.2.5
author maintainer
#2 lore raw

PATCH 3/4 ASoC: Add adav* drivers to the Analog Devices file patterns

In reply to Lars-Peter Clausen
---
 MAINTAINERS |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
MAINTAINERS +1 -0
index a26e9ec..4f7665c 100644
@@ -534,6 +534,7 @@ L:	[email protected] (moderated for non-subscribers)
 W:	http://wiki.analog.com/
 S:	Supported
 F:	sound/soc/codecs/adau*
+F:	sound/soc/codecs/adav*
 F:	sound/soc/codecs/ad1*
 F:	sound/soc/codecs/ssm*
 
Signature · 1 line
1.7.2.5
#5 lore raw
In reply to Lars-Peter Clausen

sound/soc/codecs/adav80x.c

Quoted 3 lines · Lars-Peter Clausen
sound/soc/codecs/adav80x.c new file +0 -0
new file mode 100644
index 0000000..d2f3d08

This needs adding to MAINTAINERS.

sound/soc/codecs/adav80x.c line 163

Quoted 5 lines
sound/soc/codecs/adav80x.c new file +5 -0
+static const struct soc_enum adav80x_mux_enum[] = {
+	ADAV80X_MUX_ENUM(ADAV80X_DPATH_CTRL1, 0),
+	ADAV80X_MUX_ENUM(ADAV80X_DPATH_CTRL1, 3),
+	ADAV80X_MUX_ENUM(ADAV80X_DPATH_CTRL2, 3),
+};

No, don't use arrays...

sound/soc/codecs/adav80x.c line 169

Quoted 5 lines
sound/soc/codecs/adav80x.c new file +5 -0
+static const struct snd_kcontrol_new adav80x_mux_ctrl[] = {
+	SOC_DAPM_VALUE_ENUM("Route", adav80x_mux_enum[0]),
+	SOC_DAPM_VALUE_ENUM("Route", adav80x_mux_enum[1]),
+	SOC_DAPM_VALUE_ENUM("Route", adav80x_mux_enum[2]),
+};

...since referencing them is so error prone...

sound/soc/codecs/adav80x.c line 172

Quoted 2 lines
sound/soc/codecs/adav80x.c new file +2 -0
+#define ADAV80X_MUX(name, num) \
+	SND_SOC_DAPM_VALUE_MUX(name, SND_SOC_NOPM, 0, 0, &adav80x_mux_ctrl[num])

...and illegible due to the magic numbers.

Quoted 5 lines
sound/soc/codecs/adav80x.c new file +5 -0
+	if (adav80x->deemph) {
+		switch (adav80x->rate) {
+		case 0:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_NONE;
+			break;

sound/soc/codecs/adav80x.c line 241

Quoted 10 lines
sound/soc/codecs/adav80x.c new file +10 -0
+		case 32000:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_32;
+			break;
+		case 44100:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_44;
+			break;
+		case 48000:
+		default:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_48;
+			break;

Really? I'd have expected a check for the closest matching rate (which would get 32k for most low rates) or a requirement for an exact match.

Quoted 10 lines
sound/soc/codecs/adav80x.c new file +9 -0
+	if (freq_out) {
 
+	} else	{
+		if (adav80x->clk_src == new_src)
+			return 0;
+
+		adav80x->clk_src = new_src;
+
+		if (new_src == ADAV80X_CLK_XIN) {
+			/* DAC, ADC, ICLK clock source - XIN */

sound/soc/codecs/adav80x.c line 573

Quoted 10 lines
sound/soc/codecs/adav80x.c new file +10 -0
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL1, 0x00);
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL2, 0x00);
+		} else {
+			/* DAC, ADC, ICLK clock source - MCLKI */
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL1, 0x25);
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL2, 0x01);
+		}
+
+		pll_ctrl1 |= ADAV80X_PLL_CTRL1_PLL1PD;
+		snd_soc_write(codec, ADAV80X_PLL_CTRL1, pll_ctrl1);

What's this doing? Setting the PLL output to zero means stop the PLL.

sound/soc/codecs/adav80x.c line 613

Quoted 13 lines
sound/soc/codecs/adav80x.c new file +13 -0
+/* Enforce the same sample rate on all audio interfaces */
+static int adav80x_dai_startup(struct snd_pcm_substream *substream,
+	struct snd_soc_dai *dai)
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
+
+	if (!codec->active || !adav80x->rate)
+		return 0;
+
+	return snd_pcm_hw_constraint_minmax(substream->runtime,
+			SNDRV_PCM_HW_PARAM_RATE, adav80x->rate, adav80x->rate);
+}

This means playback and capture should always run at the same rate so...

sound/soc/codecs/adav80x.c

Quoted 2 lines
sound/soc/codecs/adav80x.c new file +2 -0
+static struct snd_soc_dai_driver adav80x_dais[] = {
+	{

...the DAI should flag symmetric_rates, even if only for completeness.

sound/soc/codecs/adav80x.c line 710

Quoted 4 lines
sound/soc/codecs/adav80x.c new file +4 -0
+static int adav80x_resume(struct snd_soc_codec *codec)
+{
+	return adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+}

This doesn't appear to restore the register cache, nor does set_bias_level().

author maintainer
#6 lore raw
Quoted 7 lines · Mark Brown

sound/soc/codecs/adav80x.c

Quoted 3 lines · Lars-Peter Clausen
sound/soc/codecs/adav80x.c new file +0 -0
new file mode 100644
index 0000000..d2f3d08

This needs adding to MAINTAINERS.

Done in patch 3 of this series, but I can merge it into this one.

Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/adav80x.c new file +10 -0
+	if (adav80x->deemph) {
+		switch (adav80x->rate) {
+		case 0:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_NONE;
+			break;
+		case 32000:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_32;
+			break;
+		case 44100:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_44;
Quoted 8 lines

sound/soc/codecs/adav80x.c line 241

Quoted 5 lines
sound/soc/codecs/adav80x.c new file +5 -0
+			break;
+		case 48000:
+		default:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_48;
+			break;

Really? I'd have expected a check for the closest matching rate (which would get 32k for most low rates) or a requirement for an exact match.

Since the codec supports 32k, 44.1k, 48k, 64k, 48.2k and 96k this will select the closest match.

Quoted 15 lines
Quoted 15 lines
sound/soc/codecs/adav80x.c new file +13 -0
+	if (freq_out) {
 
+	} else	{
+		if (adav80x->clk_src == new_src)
+			return 0;
+
+		adav80x->clk_src = new_src;
+
+		if (new_src == ADAV80X_CLK_XIN) {
+			/* DAC, ADC, ICLK clock source - XIN */
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL1, 0x00);
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL2, 0x00);
+		} else {
+			/* DAC, ADC, ICLK clock source - MCLKI */
Quoted 8 lines

sound/soc/codecs/adav80x.c line 573

Quoted 6 lines
sound/soc/codecs/adav80x.c new file +6 -0
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL1, 0x25);
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL2, 0x01);
+		}
+
+		pll_ctrl1 |= ADAV80X_PLL_CTRL1_PLL1PD;
+		snd_soc_write(codec, ADAV80X_PLL_CTRL1, pll_ctrl1);

What's this doing? Setting the PLL output to zero means stop the PLL.

That's exactly what's it doing. Switching to an external clock and powering the PLL down. Or what do you mean?

Quoted 17 lines
Quoted 4 lines
sound/soc/codecs/adav80x.c new file +3 -0
+/* Enforce the same sample rate on all audio interfaces */
+static int adav80x_dai_startup(struct snd_pcm_substream *substream,
+	struct snd_soc_dai *dai)

sound/soc/codecs/adav80x.c line 613

Quoted 10 lines
sound/soc/codecs/adav80x.c new file +10 -0
+{
+	struct snd_soc_codec *codec = dai->codec;
+	struct adav80x *adav80x = snd_soc_codec_get_drvdata(codec);
+
+	if (!codec->active || !adav80x->rate)
+		return 0;
+
+	return snd_pcm_hw_constraint_minmax(substream->runtime,
+			SNDRV_PCM_HW_PARAM_RATE, adav80x->rate, adav80x->rate);
+}

This means playback and capture should always run at the same rate so...

Quoted 4 lines

sound/soc/codecs/adav80x.c

Quoted 2 lines
sound/soc/codecs/adav80x.c new file +2 -0
+static struct snd_soc_dai_driver adav80x_dais[] = {
+	{

...the DAI should flag symmetric_rates, even if only for completeness.

I had it there first, but removed it since it would mean doing the same work twice.

Quoted 8 lines

sound/soc/codecs/adav80x.c line 710

Quoted 5 lines
sound/soc/codecs/adav80x.c new file +4 -0
+static int adav80x_resume(struct snd_soc_codec *codec)
+{
+	return adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+}

This doesn't appear to restore the register cache, nor does set_bias_level().

The register contents is not lost unless we'd cut external power, but I could add restoring for completeness.

#7 lore raw
Quoted 21 lines · Lars-Peter Clausen
Quoted 10 lines · Mark Brown
Quoted 10 lines
sound/soc/codecs/adav80x.c new file +10 -0
+	if (adav80x->deemph) {
+		switch (adav80x->rate) {
+		case 0:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_NONE;
+			break;
+		case 32000:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_32;
+			break;
+		case 44100:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_44;
Quoted 8 lines

sound/soc/codecs/adav80x.c line 241

Quoted 5 lines
sound/soc/codecs/adav80x.c new file +5 -0
+			break;
+		case 48000:
+		default:
+			val = ADAV80X_DAC_CTRL2_DEEMPH_48;
+			break;

Really? I'd have expected a check for the closest matching rate (which would get 32k for most low rates) or a requirement for an exact match.

Quoted 2 lines

Since the codec supports 32k, 44.1k, 48k, 64k, 48.2k and 96k this will select the closest match.

It'd be better to write the code to say that.

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
sound/soc/codecs/adav80x.c new file +12 -0
+	} else	{
+		if (adav80x->clk_src == new_src)
+			return 0;
+
+		adav80x->clk_src = new_src;
+
+		if (new_src == ADAV80X_CLK_XIN) {
+			/* DAC, ADC, ICLK clock source - XIN */
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL1, 0x00);
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL2, 0x00);
+		} else {
+			/* DAC, ADC, ICLK clock source - MCLKI */
Quoted 8 lines

sound/soc/codecs/adav80x.c line 573

Quoted 6 lines
sound/soc/codecs/adav80x.c new file +6 -0
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL1, 0x25);
+			snd_soc_write(codec, ADAV80X_ICLK_CTRL2, 0x01);
+		}
+
+		pll_ctrl1 |= ADAV80X_PLL_CTRL1_PLL1PD;
+		snd_soc_write(codec, ADAV80X_PLL_CTRL1, pll_ctrl1);

What's this doing? Setting the PLL output to zero means stop the PLL.

Quoted 2 lines

That's exactly what's it doing. Switching to an external clock and powering the PLL down. Or what do you mean?

It really doesn't look like that - if it were just stopping the PLL it'd not need to look at the clock source selection. Perhaps some of this should be in set_sysclk()?

Quoted 10 lines
Quoted 7 lines

sound/soc/codecs/adav80x.c line 710

Quoted 4 lines
sound/soc/codecs/adav80x.c new file +4 -0
+static int adav80x_resume(struct snd_soc_codec *codec)
+{
+	return adav80x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+}

This doesn't appear to restore the register cache, nor does set_bias_level().

The register contents is not lost unless we'd cut external power, but I could add restoring for completeness.

Cutting external power is the sort of thing that one would expect to happen over suspend on most systems, especially power sensitive ones.