Skip to contentSkip to conversation

ASoC: Correct typo in SOC_VALUE_ENUM_SINGLE macro

PATCH Superseded Charles Keepax 2 participants 8 messages Apr 30, 2015 – May 1, 2015

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/5 ASoC: Correct typo in SOC_VALUE_ENUM_SINGLE macro

xnitmes is clearly intended to be xnitems, but all other macros just refer to this as xitems, so change it to that.

---

Changes since v1:
- Use first entry of values array as off value for the mux

Thanks,
Charles

 include/sound/soc.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/sound/soc.h +2 -2
index a73d855..45cfd69 100644
@@ -190,8 +190,8 @@
 #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xitems, xtexts, xvalues) \
 {	.reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
 	.mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
-#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xnitmes, xtexts, xvalues) \
-	SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xnitmes, xtexts, xvalues)
+#define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
+	SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
 #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
 	SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
 #define SOC_ENUM(xname, xenum) \
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH v2 2/5 ASoC: dapm: Remove local OOM error message

The memory subsystem is pretty chatty on failure no need to have local OOM messages as well.

---
 sound/soc/soc-dapm.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
sound/soc/soc-dapm.c +1 -5
index 79b9478..beb48b6 100644
@@ -310,12 +310,8 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 	struct soc_mixer_control *mc;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data) {
-		dev_err(widget->dapm->dev,
-				"ASoC: can't allocate kcontrol data for %s\n",
-				widget->name);
+	if (!data)
 		return -ENOMEM;
-	}
 
 	INIT_LIST_HEAD(&data->paths);
 
Signature · 1 line
1.7.2.5
#2 lore raw

PATCH v2 3/5 ASoC: dapm: Append "Autodisable" to autodisable widget names

In reply to Charles Keepax

This makes it a little easier to follow what is happening in debugfs. Additionally is also useful in facilitating work to add autodisable muxes because the control name is already used for the mux widget and thus shouldn't be reused for the autodisable widget.

---
 sound/soc/soc-dapm.c |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)
sound/soc/soc-dapm.c +19 -3
index beb48b6..e557018 100644
@@ -308,11 +308,19 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 {
 	struct dapm_kcontrol_data *data;
 	struct soc_mixer_control *mc;
+	const char *name;
+	int ret;
 
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
+	name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name, "Autodisable");
+	if (!name) {
+		ret = -ENOMEM;
+		goto err_data;
+	}
+
 	INIT_LIST_HEAD(&data->paths);
 
 	switch (widget->id) {
@@ -334,15 +342,15 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 				template.off_val = 0;
 			template.on_val = template.off_val;
 			template.id = snd_soc_dapm_kcontrol;
-			template.name = kcontrol->id.name;
+			template.name = name;
 
 			data->value = template.on_val;
 
 			data->widget = snd_soc_dapm_new_control(widget->dapm,
 				&template);
 			if (!data->widget) {
-				kfree(data);
-				return -ENOMEM;
+				ret = -ENOMEM;
+				goto err_name;
 			}
 		}
 		break;
@@ -353,11 +361,19 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
 	kcontrol->private_data = data;
 
 	return 0;
+
+err_name:
+	kfree(name);
+err_data:
+	kfree(data);
+	return ret;
 }
 
 static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
 {
 	struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
+	if (data->widget)
+		kfree(data->widget->name);
 	kfree(data->wlist);
 	kfree(data);
 }
Signature · 1 line
1.7.2.5
#3 lore raw

Re: [PATCH v2 3/5] ASoC: dapm: Append "Autodisable" to autodisable widget names

Quoted 6 lines · Charles Keepax
sound/soc/soc-dapm.c +0 -0
index beb48b6..e557018 100644
@@ -308,11 +308,19 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
  {

sound/soc/soc-dapm.c static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget, · line 318

Quoted 10 lines
sound/soc/soc-dapm.c +3 -0
  	struct dapm_kcontrol_data *data;
  	struct soc_mixer_control *mc;
+	const char *name;
+	int ret;
 
  	data = kzalloc(sizeof(*data), GFP_KERNEL);
  	if (!data)
  		return -ENOMEM;
 
+	name = kasprintf(GFP_KERNEL, "%s %s", kcontrol->id.name, "Autodisable");

We should only allocate the name if we create a widget, otherwise we are going to leak the memory.

Quoted 7 lines
sound/soc/soc-dapm.c +5 -0
+	if (!name) {
+		ret = -ENOMEM;
+		goto err_data;
+	}
+
  	INIT_LIST_HEAD(&data->paths);
 
#4 lore raw

PATCH v2 4/5 ASoC: dapm: Add support for autodisable mux controls

In reply to Charles Keepax

Commit 57295073b6ac ("ASoC: dapm: Implement mixer input auto-disable") added support for autodisable controls, controls whose values are only written to the hardware when their respective widgets are powered up. But it only added support for controls based on the mixer abstraction.

This patch add support for mux controls (DAPM controls based on the enum abstraction) to be auto-disabled as well. As each mux can only have a single control, there is no need to tie the autodisable widget to the inputs (as is done for the mixer controls) it can be tided directly to the mux widget itself.

Note that it is assumed that the first entry in a autodisable mux control will always represent the off state for the mux and is what the mux will be set to whilst it is disabled.

---
 include/sound/soc.h  |   10 ++++++++
 sound/soc/soc-dapm.c |   62 +++++++++++++++++++++++++++++++++++++------------
 2 files changed, 57 insertions(+), 15 deletions(-)
include/sound/soc.h +10 -0
index 45cfd69..28b8ae6 100644
@@ -192,6 +192,10 @@
 	.mask = xmask, .items = xitems, .texts = xtexts, .values = xvalues}
 #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
 	SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xitems, xtexts, xvalues)
+#define SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, xshift, xmask, xitems, xtexts, xvalues) \
+{	.reg = xreg, .shift_l = xshift, .shift_r = xshift, \
+	.mask = xmask, .items = xitems, .texts = xtexts, \
+	.values = xvalues, .autodisable = 1}
 #define SOC_ENUM_SINGLE_VIRT(xitems, xtexts) \
 	SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, xitems, xtexts)
 #define SOC_ENUM(xname, xenum) \
@@ -312,6 +316,11 @@
 							ARRAY_SIZE(xtexts), xtexts, xvalues)
 #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
 	SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
+
+#define SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
+	const struct soc_enum name = SOC_VALUE_ENUM_SINGLE_AUTODISABLE(xreg, \
+		xshift, xmask, ARRAY_SIZE(xtexts), xtexts, xvalues)
+
 #define SOC_ENUM_SINGLE_VIRT_DECL(name, xtexts) \
 	const struct soc_enum name = SOC_ENUM_SINGLE_VIRT(ARRAY_SIZE(xtexts), xtexts)
 
@@ -1200,6 +1209,7 @@ struct soc_enum {
 	unsigned int mask;
 	const char * const *texts;
 	const unsigned int *values;
+	unsigned int autodisable:1;
 };
 
 /**
sound/soc/soc-dapm.c +47 -15

118 lines not on this page · raw message

Signature · 1 line
1.7.2.5
#5 lore raw

Re: [PATCH v2 4/5] ASoC: dapm: Add support for autodisable mux controls

On 04/30/2015 06:38 PM, Charles Keepax wrote:
[...]

Quoted 5 lines
sound/soc/soc-dapm.c +1 -0
@@ -354,6 +355,34 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
  			}
  		}
  		break;
+	case snd_soc_dapm_mux:

sound/soc/soc-dapm.c static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget, · line 368

Quoted 10 lines
sound/soc/soc-dapm.c +10 -0
+		e = (struct soc_enum *)kcontrol->private_value;
+
+		if (e->autodisable) {
+			struct snd_soc_dapm_widget template;
+
+			memset(&template, 0, sizeof(template));
+			template.reg = e->reg;
+			template.mask = e->mask << e->shift_l;
+			template.shift = e->shift_l;
+			template.off_val = e->values[0];

I think we should handle the case where e->values is NULL. In which case off_val should just be 0.

Quoted 4 lines
sound/soc/soc-dapm.c +4 -0
+			template.on_val = template.off_val;
+			template.id = snd_soc_dapm_kcontrol;
+			template.name = name;
+

[...]

sound/soc/soc-dapm.c int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, · line 3041

Quoted 11 lines
sound/soc/soc-dapm.c +2 -2
@@ -3002,10 +3034,10 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
 
  	mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
 
+	change = dapm_kcontrol_set_value(kcontrol, val);
+
  	if (e->reg != SND_SOC_NOPM)
  		change = soc_dapm_test_bits(dapm, e->reg, mask, val);
-	else
-		change = dapm_kcontrol_set_value(kcontrol, val);
 

This probably needs the same logic as in snd_soc_dapm_put_volsw() to correctly handle the case where the hardware state and the software state might be out of sync.

sound/soc/soc-dapm.c int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, · line 3043

Quoted 3 lines
sound/soc/soc-dapm.c +0 -0
  	if (change) {
  		if (e->reg != SND_SOC_NOPM) {

/

#6 lore raw

Re: [PATCH v2 4/5] ASoC: dapm: Add support for autodisable mux controls

Quoted 12 lines · Lars-Peter Clausen

On 04/30/2015 06:38 PM, Charles Keepax wrote:
[...]

Quoted 10 lines
sound/soc/soc-dapm.c +6 -0
@@ -354,6 +355,34 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
  			}
  		}
  		break;
+	case snd_soc_dapm_mux:
+		e = (struct soc_enum *)kcontrol->private_value;
+
+		if (e->autodisable) {
+			struct snd_soc_dapm_widget template;
+
Quoted 8 lines

sound/soc/soc-dapm.c static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget, · line 368

Quoted 5 lines
sound/soc/soc-dapm.c +5 -0
+			memset(&template, 0, sizeof(template));
+			template.reg = e->reg;
+			template.mask = e->mask << e->shift_l;
+			template.shift = e->shift_l;
+			template.off_val = e->values[0];

I think we should handle the case where e->values is NULL. In which case off_val should just be 0.

Ooops yeah sorry got a bit over keen there.

Quoted 11 lines
Quoted 5 lines
sound/soc/soc-dapm.c +4 -0
+			template.on_val = template.off_val;
+			template.id = snd_soc_dapm_kcontrol;
+			template.name = name;
+

[...]

Quoted 4 lines
sound/soc/soc-dapm.c +0 -0
@@ -3002,10 +3034,10 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
 
  	mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
 
Quoted 11 lines

sound/soc/soc-dapm.c int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, · line 3041

Quoted 7 lines
sound/soc/soc-dapm.c +2 -2
+	change = dapm_kcontrol_set_value(kcontrol, val);
+
  	if (e->reg != SND_SOC_NOPM)
  		change = soc_dapm_test_bits(dapm, e->reg, mask, val);
-	else
-		change = dapm_kcontrol_set_value(kcontrol, val);
 

This probably needs the same logic as in snd_soc_dapm_put_volsw() to correctly handle the case where the hardware state and the software state might be out of sync.

Yeah makes sense.

Quoted 5 lines

sound/soc/soc-dapm.c int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, · line 3043

Quoted 4 lines
sound/soc/soc-dapm.c +0 -0
  	if (change) {
  		if (e->reg != SND_SOC_NOPM) {

/

I will send out a new spin shortly.

Thanks,
Charles

#7 lore raw

PATCH v2 5/5 ASoC: arizona: Use auto disable muxes for routing

In reply to Charles Keepax

The mixer core on the Arizona devices is powered up whenever any routing is non-zero. This patch saves a little power and avoids a few difficult corner cases (around the mixer core being powered whilst there is no clock available), by using the autodisable mux functionality to only write out the settings for the muxes when they are powered up.

---
 sound/soc/codecs/arizona.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/arizona.h +2 -2
index 11ff899..bacc296 100644
@@ -107,8 +107,8 @@ extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
 			     arizona_mixer_tlv)
 
 #define ARIZONA_MUX_ENUM_DECL(name, reg) \
-	SOC_VALUE_ENUM_SINGLE_DECL(name, reg, 0, 0xff,			\
-				   arizona_mixer_texts, arizona_mixer_values)
+	SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL( \
+		name, reg, 0, 0xff, arizona_mixer_texts, arizona_mixer_values)
 
 #define ARIZONA_MUX_CTL_DECL(name) \
 	const struct snd_kcontrol_new name##_mux =	\
Signature · 1 line
1.7.2.5