Skip to contentSkip to conversation

Convert wm8xxx codec drivers to use snd_soc_write/snd_soc_cache_sync

PATCH Applied Axel Lin 2 participants 12 messages Oct 7, 2011 – Oct 10, 2011

Subsystems (3)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

v3 cover Convert wm8xxx codec drivers to use snd_soc_write/snd_soc_cache_sync

This serial converts the wm8xxx codec drivers to use snd_soc_cache_sync. I don't have these hardware, but I assume Mark has all these hardware. These patches are UNTESTED. I'd appreciate if someone can test it. (Current code is broken anyway, thus we need convert to use new API. )

v3: use snd_soc_cache_sync to replace customized xxxx_sync_cache() calls.
Drop wm8990 patch in v2, which is already merged.
I also change the subject line back to be the same as v1. ( we are using snd_soc_cache_sync now, not snd_soc_write )

v2: For 7, 9 CODECs that are write only, convert to using cache_bypass + snd_soc_write
v2 also includes wm8990 that I had sent separately.

Axel Lin (10):
ASoC: wm8510: Convert to snd_soc_cache_sync
ASoC: wm8711: Convert to snd_soc_cache_sync
ASoC: wm8731: Convert to snd_soc_cache_sync
ASoC: wm8750: Convert to snd_soc_cache_sync
ASoC: wm8776: Convert to snd_soc_cache_sync
ASoC: wm8940: Convert to snd_soc_cache_sync
ASoC: wm8960: Convert to snd_soc_cache_sync
ASoC: wm8971: Convert to snd_soc_cache_sync
ASoC: wm8974: Convert to snd_soc_cache_sync
ASoC: wm8988: Convert to snd_soc_cache_sync

 sound/soc/codecs/wm8510.c |   13 +----------
 sound/soc/codecs/wm8711.c |   15 ++-----------
 sound/soc/codecs/wm8731.c |   15 +------------
 sound/soc/codecs/wm8750.c |   16 +-------------
 sound/soc/codecs/wm8776.c |   16 +-------------
 sound/soc/codecs/wm8940.c |   46 +++++++++++++++++++++-----------------------
 sound/soc/codecs/wm8960.c |   14 +++---------
 sound/soc/codecs/wm8971.c |   15 ++-----------
 sound/soc/codecs/wm8974.c |   13 +----------
 sound/soc/codecs/wm8988.c |   17 +--------------
 10 files changed, 44 insertions(+), 136 deletions(-)
Signature · 1 line
1.7.4.1
author
#1 lore raw

PATCH v3 1/10 ASoC: wm8510: Convert to snd_soc_cache_sync

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8510.c |   13 ++-----------
 1 files changed, 2 insertions(+), 11 deletions(-)
sound/soc/codecs/wm8510.c +2 -11
index 55a4c83..07c9cc7 100644
@@ -480,6 +480,8 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
 		power1 |= WM8510_POWER1_BIASEN | WM8510_POWER1_BUFIOEN;
 
 		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			snd_soc_cache_sync(codec);
+
 			/* Initial cap charge at VMID 5k */
 			snd_soc_write(codec, WM8510_POWER1, power1 | 0x3);
 			mdelay(100);
@@ -541,18 +543,7 @@ static int wm8510_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8510_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8510_reg); i++) {
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
 	wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
 	return 0;
 }
 
Signature · 1 line
1.7.4.1
Applied
#2 lore raw

Re: [PATCH v3 01/10] ASoC: wm8510: Convert to snd_soc_cache_sync

Quoted 3 lines · Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

Applied all, thanks.

author
#3 lore raw

PATCH v3 2/10 ASoC: wm8711: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8711.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)
sound/soc/codecs/wm8711.c +3 -12
index 7475428..8d0347c 100644
@@ -287,7 +287,6 @@ static int wm8711_set_dai_fmt(struct snd_soc_dai *codec_dai,
 	return 0;
 }
 
-
 static int wm8711_set_bias_level(struct snd_soc_codec *codec,
 	enum snd_soc_bias_level level)
 {
@@ -300,6 +299,9 @@ static int wm8711_set_bias_level(struct snd_soc_codec *codec,
 	case SND_SOC_BIAS_PREPARE:
 		break;
 	case SND_SOC_BIAS_STANDBY:
+		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
+			snd_soc_cache_sync(codec);
+
 		snd_soc_write(codec, WM8711_PWR, reg | 0x0040);
 		break;
 	case SND_SOC_BIAS_OFF:
@@ -346,18 +348,7 @@ static int wm8711_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8711_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8711_reg); i++) {
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
 	wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
 	return 0;
 }
 
Signature · 1 line
1.7.4.1
author
#4 lore raw

PATCH v3 3/10 ASoC: wm8731: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8731.c |   15 ++-------------
 1 files changed, 2 insertions(+), 13 deletions(-)
sound/soc/codecs/wm8731.c +2 -13
index f76b6fc..7e5ec03 100644
@@ -427,9 +427,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
 				 enum snd_soc_bias_level level)
 {
 	struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
-	int i, ret;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
+	int ret;
 	u16 reg;
 
 	switch (level) {
@@ -444,16 +442,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
 			if (ret != 0)
 				return ret;
 
-			/* Sync reg_cache with the hardware */
-			for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
-				if (cache[i] == wm8731_reg[i])
-					continue;
-
-				data[0] = (i << 1) | ((cache[i] >> 8)
-						      & 0x0001);
-				data[1] = cache[i] & 0x00ff;
-				codec->hw_write(codec->control_data, data, 2);
-			}
+			snd_soc_cache_sync(codec);
 		}
 
 		/* Clear PWROFF, gate CLKOUT, everything else as-is */
Signature · 1 line
1.7.4.1
author
#5 lore raw

PATCH v3 4/10 ASoC: wm8750: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8750.c |   16 ++--------------
 1 files changed, 2 insertions(+), 14 deletions(-)
sound/soc/codecs/wm8750.c +2 -14
index 862c520..ca75a81 100644
@@ -616,6 +616,8 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
 		break;
 	case SND_SOC_BIAS_STANDBY:
 		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			snd_soc_cache_sync(codec);
+
 			/* Set VMID to 5k */
 			snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
 
@@ -673,21 +675,7 @@ static int wm8750_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8750_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8750_reg); i++) {
-		if (i == WM8750_RESET)
-			continue;
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
-
 	wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
 	return 0;
 }
 
Signature · 1 line
1.7.4.1
author
#6 lore raw

PATCH v3 5/10 ASoC: wm8776: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8776.c |   16 ++--------------
 1 files changed, 2 insertions(+), 14 deletions(-)
sound/soc/codecs/wm8776.c +2 -14
index 00d8846..bfdc523 100644
@@ -308,6 +308,8 @@ static int wm8776_set_bias_level(struct snd_soc_codec *codec,
 		break;
 	case SND_SOC_BIAS_STANDBY:
 		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			snd_soc_cache_sync(codec);
+
 			/* Disable the global powerdown; DAPM does the rest */
 			snd_soc_update_bits(codec, WM8776_PWRDOWN, 1, 0);
 		}
@@ -379,21 +381,7 @@ static int wm8776_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8776_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8776_reg); i++) {
-		if (cache[i] == wm8776_reg[i])
-			continue;
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
-
 	wm8776_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
 	return 0;
 }
 #else
Signature · 1 line
1.7.4.1
author
#7 lore raw

PATCH v3 6/10 ASoC: wm8940: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8940.c |   46 +++++++++++++++++++++-----------------------
 1 files changed, 22 insertions(+), 24 deletions(-)
sound/soc/codecs/wm8940.c +22 -24
index 7e0f54c..a4abfdf 100644
@@ -45,6 +45,17 @@ struct wm8940_priv {
 	enum snd_soc_control_type control_type;
 };
 
+static int wm8940_volatile_register(struct snd_soc_codec *codec,
+				    unsigned int reg)
+{
+	switch (reg) {
+	case WM8940_SOFTRESET:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
 static u16 wm8940_reg_defaults[] = {
 	0x8940, /* Soft Reset */
 	0x0000, /* Power 1 */
@@ -459,6 +470,14 @@ static int wm8940_set_bias_level(struct snd_soc_codec *codec,
 		ret = snd_soc_write(codec, WM8940_POWER1, pwr_reg | 0x1);
 		break;
 	case SND_SOC_BIAS_STANDBY:
+		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			ret = snd_soc_cache_sync(codec);
+			if (ret < 0) {
+				dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
+				return ret;
+			}
+		}
+
 		/* ensure bufioen and biasen */
 		pwr_reg |= (1 << 2) | (1 << 3);
 		/* set vmid to 300k for standby */
@@ -659,30 +678,8 @@ static int wm8940_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8940_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	int ret;
-	u8 data[3];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware
-	 * Could use auto incremented writes to speed this up
-	 */
-	for (i = 0; i < ARRAY_SIZE(wm8940_reg_defaults); i++) {
-		data[0] = i;
-		data[1] = (cache[i] & 0xFF00) >> 8;
-		data[2] = cache[i] & 0x00FF;
-		ret = codec->hw_write(codec->control_data, data, 3);
-		if (ret < 0)
-			goto error_ret;
-		else if (ret != 3) {
-			ret = -EIO;
-			goto error_ret;
-		}
-	}
-	ret = wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
-error_ret:
-	return ret;
+	wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+	return 0;
 }
 
 static int wm8940_probe(struct snd_soc_codec *codec)
@@ -742,6 +739,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8940 = {
 	.reg_cache_size = ARRAY_SIZE(wm8940_reg_defaults),
 	.reg_word_size = sizeof(u16),
 	.reg_cache_default = wm8940_reg_defaults,
+	.volatile_register = wm8940_volatile_register,
 };
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
Signature · 1 line
1.7.4.1
author
#8 lore raw

PATCH v3 7/10 ASoC: wm8960: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8960.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)
sound/soc/codecs/wm8960.c +5 -10
index 831c20f..2df253c 100644
@@ -574,6 +574,8 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
 
 	case SND_SOC_BIAS_STANDBY:
 		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			snd_soc_cache_sync(codec);
+
 			/* Enable anti-pop features */
 			snd_soc_write(codec, WM8960_APOP1,
 				      WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -676,6 +678,9 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
 					    WM8960_VREF | WM8960_VMID_MASK, 0);
 			break;
 
+		case SND_SOC_BIAS_OFF:
+			snd_soc_cache_sync(codec);
+			break;
 		default:
 			break;
 		}
@@ -901,16 +906,6 @@ static int wm8960_suspend(struct snd_soc_codec *codec, pm_message_t state)
 static int wm8960_resume(struct snd_soc_codec *codec)
 {
 	struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8960_reg); i++) {
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
 
 	wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 	return 0;
Signature · 1 line
1.7.4.1
author
#9 lore raw

PATCH v3 8/10 ASoC: wm8971: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8971.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)
sound/soc/codecs/wm8971.c +3 -12
index 08ea6f8..b444b29 100644
@@ -546,6 +546,9 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
 	case SND_SOC_BIAS_PREPARE:
 		break;
 	case SND_SOC_BIAS_STANDBY:
+		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
+			snd_soc_cache_sync(codec);
+
 		/* mute dac and set vmid to 500k, enable VREF */
 		snd_soc_write(codec, WM8971_PWR1, pwr_reg | 0x0140);
 		break;
@@ -605,20 +608,8 @@ static int wm8971_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8971_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
 	u16 reg;
 
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8971_reg); i++) {
-		if (i == WM8971_RESET)
-			continue;
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
-
 	wm8971_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
 	/* charge wm8971 caps */
Signature · 1 line
1.7.4.1
author
#10 lore raw

PATCH v3 9/10 ASoC: wm8974: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8974.c |   13 ++-----------
 1 files changed, 2 insertions(+), 11 deletions(-)
sound/soc/codecs/wm8974.c +2 -11
index 8e3bfc1..9352f1e 100644
@@ -530,6 +530,8 @@ static int wm8974_set_bias_level(struct snd_soc_codec *codec,
 		power1 |= WM8974_POWER1_BIASEN | WM8974_POWER1_BUFIOEN;
 
 		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			snd_soc_cache_sync(codec);
+
 			/* Initial cap charge at VMID 5k */
 			snd_soc_write(codec, WM8974_POWER1, power1 | 0x3);
 			mdelay(100);
@@ -589,18 +591,7 @@ static int wm8974_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8974_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < ARRAY_SIZE(wm8974_reg); i++) {
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
 	wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
 	return 0;
 }
 
Signature · 1 line
1.7.4.1
author
#11 lore raw

PATCH v3 10/10 ASoC: wm8988: Convert to snd_soc_cache_sync

In reply to Axel Lin

Convert to snd_soc_cache_sync for sync reg_cache with the hardware.

---
 sound/soc/codecs/wm8988.c |   17 ++---------------
 1 files changed, 2 insertions(+), 15 deletions(-)
sound/soc/codecs/wm8988.c +2 -15
index 1c6f8bf..2e9eba7 100644
@@ -55,7 +55,6 @@ struct wm8988_priv {
 	struct snd_pcm_hw_constraint_list *sysclk_constraints;
 };
 
-
 #define wm8988_reset(c)	snd_soc_write(c, WM8988_RESET, 0)
 
 /*
@@ -676,6 +675,8 @@ static int wm8988_set_bias_level(struct snd_soc_codec *codec,
 
 	case SND_SOC_BIAS_STANDBY:
 		if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
+			snd_soc_cache_sync(codec);
+
 			/* VREF, VMID=2x5k */
 			snd_soc_write(codec, WM8988_PWR1, pwr_reg | 0x1c1);
 
@@ -736,21 +737,7 @@ static int wm8988_suspend(struct snd_soc_codec *codec, pm_message_t state)
 
 static int wm8988_resume(struct snd_soc_codec *codec)
 {
-	int i;
-	u8 data[2];
-	u16 *cache = codec->reg_cache;
-
-	/* Sync reg_cache with the hardware */
-	for (i = 0; i < WM8988_NUM_REG; i++) {
-		if (i == WM8988_RESET)
-			continue;
-		data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-		data[1] = cache[i] & 0x00ff;
-		codec->hw_write(codec->control_data, data, 2);
-	}
-
 	wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
 	return 0;
 }
 
Signature · 1 line
1.7.4.1