Skip to contentSkip to conversation

ASoC: rt715:add micmute led state control supports

PATCH Superseded Perry Yuan 7 participants 14 messages Jan 12, 2021 – Feb 14, 2021

Subsystems (4)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Perry Yuan

author
#0 lore raw

PATCH v3 3/3 ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
 sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
 sound/soc/codecs/rt715-sdca.h |  1 +
 sound/soc/codecs/rt715.c      | 14 ++++++++++++++
 sound/soc/codecs/rt715.h      |  1 +
 4 files changed, 32 insertions(+)
sound/soc/codecs/rt715-sdca.c +16 -0
index b43ac8559e45..861a0d2a8957 100644
@@ -12,6 +12,7 @@
 #include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/leds.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm.h>
 #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol,
 	unsigned int max = mc->max;
 	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
 	val = snd_soc_component_read(component, mc->reg);
 	if (val < 0)
 		return -EINVAL;
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol)
 {
 	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 = snd_soc_component_get_drvdata(component);
 	struct soc_mixer_control *mc =
 		(struct soc_mixer_control *)kcontrol->private_value;
 	unsigned int val, val2, loop_cnt = 2, i;
@@ -268,6 +271,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
 	unsigned int reg2 = mc->rreg;
 	unsigned int reg = mc->reg;
 	unsigned int max = mc->max;
+	unsigned int val0, val1;
 	int err;
 
 	val = ucontrol->value.integer.value[0];
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
 			return err;
 	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
 	return 0;
 }
 
sound/soc/codecs/rt715-sdca.h +1 -0
index 840c237895dd..f8988ab88f80 100644
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
 	int l_is_unmute;
 	int r_is_unmute;
 	int hw_sdw_ver;
+	bool micmute_led;
 };
 
 struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +14 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
+#include <linux/leds.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm.h>
 #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,
 		RT715_SET_GAIN_MIX_ADC2_L};
 	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
 	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
 	if (strstr(ucontrol->id.name, "Main Capture Switch") ||
 		strstr(ucontrol->id.name, "Main Capture Volume"))
@@ -95,6 +97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,
 	else
 		loop_cnt = 1;
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
 	for (j = 0; j < loop_cnt; j++) {
 		/* Can't use update bit function, so read the original value first */
 		if (loop_cnt == 1) {
sound/soc/codecs/rt715.h +1 -0
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
 	struct sdw_bus_params params;
 	bool hw_init;
 	bool first_hw_init;
+	bool micmute_led;
 };
 
 struct sdw_stream_data {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 143 lines

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Tuesday, January 12, 2021 11:18
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yuan, Perry; Limonciello, Mario
Subject: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
 sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
 sound/soc/codecs/rt715-sdca.h |  1 +
 sound/soc/codecs/rt715.c      | 14 ++++++++++++++
 sound/soc/codecs/rt715.h      |  1 +
 4 files changed, 32 insertions(+)
sound/soc/codecs/rt715-sdca.c +2 -0
index b43ac8559e45..861a0d2a8957 100644
@@ -12,6 +12,7 @@
 #include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/leds.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm.h>
 #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol
 *kcontrol,
 	unsigned int max = mc->max;
 	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
 	val = snd_soc_component_read(component, mc->reg);
 	if (val < 0)
sound/soc/codecs/rt715-sdca.c +1 -0
 		return -EINVAL;
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
 	struct snd_ctl_elem_value *ucontrol)
 {
 	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 =
 snd_soc_component_get_drvdata(component);
 	struct soc_mixer_control *mc =
sound/soc/codecs/rt715-sdca.c +1 -0
 		(struct soc_mixer_control *)kcontrol->private_value;
 	unsigned int val, val2, loop_cnt = 2, i;
@@ -268,6 +271,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
 	unsigned int reg2 = mc->rreg;
 	unsigned int reg = mc->reg;
 	unsigned int max = mc->max;
+	unsigned int val0, val1;
 	int err;
 
sound/soc/codecs/rt715-sdca.c +12 -0
 	val = ucontrol->value.integer.value[0];
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
 			return err;
 	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
 >value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
 	return 0;

}

sound/soc/codecs/rt715-sdca.h +1 -0
index 840c237895dd..f8988ab88f80 100644
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
 	int l_is_unmute;
 	int r_is_unmute;
 	int hw_sdw_ver;
+	bool micmute_led;
 };
 
 struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +2 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
+#include <linux/leds.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm.h>
 #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
 		RT715_SET_GAIN_MIX_ADC2_L};
 	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
 	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
 	if (strstr(ucontrol->id.name, "Main Capture Switch") ||
sound/soc/codecs/rt715.c +3 -0
 		strstr(ucontrol->id.name, "Main Capture Volume"))
@@ -95,6 +97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
 	else
 		loop_cnt = 1;
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 113

Quoted 10 lines
sound/soc/codecs/rt715.c +9 -0
+		if (ucontrol->value.integer.value[0] || ucontrol-
 >value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

You might have missed my other comment on v2 feedback, but is there a reason to keep it behind a compile time flag for dell privacy module? In practice any other future led backend provider should work too. Another way to think about it - if dell privacy wasn't enabled would this cause a problem to run this code? I think it would just be a no-op.

Quoted 18 lines
sound/soc/codecs/rt715.c +0 -0
 	for (j = 0; j < loop_cnt; j++) {

/* Can't use update bit function, so read the original value first
*/

sound/soc/codecs/rt715.c +0 -0
 		if (loop_cnt == 1) {
sound/soc/codecs/rt715.h +1 -1
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
 	struct sdw_bus_params params;
 	bool hw_init;
 	bool first_hw_init;
+	bool micmute_led;
 };
 
 struct sdw_stream_data {
--

2.25.1

#2 lore raw
Quoted 174 lines · Mario
Quoted 143 lines

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Tuesday, January 12, 2021 11:18
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yuan, Perry; Limonciello, Mario
Subject: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
  sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
  sound/soc/codecs/rt715-sdca.h |  1 +
  sound/soc/codecs/rt715.c      | 14 ++++++++++++++
  sound/soc/codecs/rt715.h      |  1 +
  4 files changed, 32 insertions(+)
sound/soc/codecs/rt715-sdca.c +2 -0
index b43ac8559e45..861a0d2a8957 100644
@@ -12,6 +12,7 @@
  #include <linux/version.h>
  #include <linux/kernel.h>
  #include <linux/init.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)

return -EINVAL;

sound/soc/codecs/rt715-sdca.c +1 -0
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 =
 snd_soc_component_get_drvdata(component);
  	struct soc_mixer_control *mc =
  		(struct soc_mixer_control *)kcontrol->private_value;
  	unsigned int val, val2, loop_cnt = 2, i;
sound/soc/codecs/rt715-sdca.c +1 -0
@@ -268,6 +271,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int reg2 = mc->rreg;
  	unsigned int reg = mc->reg;
  	unsigned int max = mc->max;
+	unsigned int val0, val1;
  	int err;
 
  	val = ucontrol->value.integer.value[0];
sound/soc/codecs/rt715-sdca.c +12 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
  	return 0;
  }
sound/soc/codecs/rt715-sdca.h +1 -0
index 840c237895dd..f8988ab88f80 100644
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
  	int l_is_unmute;
  	int r_is_unmute;
  	int hw_sdw_ver;
+	bool micmute_led;
  };
 
  struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +2 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/i2c.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  		RT715_SET_GAIN_MIX_ADC2_L};
  	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
  	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
  	if (strstr(ucontrol->id.name, "Main Capture Switch") ||

strstr(ucontrol->id.name, "Main Capture Volume"))

sound/soc/codecs/rt715.c +3 -0
@@ -95,6 +97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  	else
  		loop_cnt = 1;
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 113

Quoted 10 lines
sound/soc/codecs/rt715.c +9 -0
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

You might have missed my other comment on v2 feedback, but is there a reason to keep it behind a compile time flag for dell privacy module? In practice any other future led backend provider should work too. Another way to think about it - if dell privacy wasn't enabled would this cause a problem to run this code? I think it would just be a no-op.

Quoted 15 lines
sound/soc/codecs/rt715.c +0 -0
  	for (j = 0; j < loop_cnt; j++) {

/* Can't use update bit function, so read the original value first
*/
if (loop_cnt == 1) {

sound/soc/codecs/rt715.h +1 -0
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
  	struct sdw_bus_params params;
  	bool hw_init;
  	bool first_hw_init;
+	bool micmute_led;
  };
 
Quoted 3 lines
Quoted 3 lines
sound/soc/codecs/rt715.h +0 -1
  struct sdw_stream_data {
--

2.25.1

Pierre Louis suggested to just set the mic mute led state unconditionally . It is more common interface to allow other platforms to change micmute led. The discussion result is from "[PATCH v2 2/2] ASoC: rt715:add Mic Mute LED control support"

Here is the change compared to V3 ,the CONFIG_DELL_PRIVACY will be removed

-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
- /* dell privacy LED trigger state changed by muted/unmute switch */
+ /* MicMute LED state changed by muted/unmute switch */

        if (mc->invert) {
                if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
                        rt715->micmute_led = LED_OFF;
sound/soc/codecs/rt715.c +1 -3
index b4e480744c94..60bb3d98103e 100644
@@ -97,8 +97,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,
        else
                loop_cnt = 1;
 
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* Micmute LED state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
        if (mc->invert) {
                if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
                        rt715->micmute_led = LED_OFF;
@@ -107,7 +106,6 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,
                }
                ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
        }
-#endif
 
#3 lore raw
Quoted 209 lines
Quoted 174 lines
Quoted 143 lines

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Tuesday, January 12, 2021 11:18
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yuan, Perry; Limonciello, Mario
Subject: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
  sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
  sound/soc/codecs/rt715-sdca.h |  1 +
  sound/soc/codecs/rt715.c      | 14 ++++++++++++++
  sound/soc/codecs/rt715.h      |  1 +
  4 files changed, 32 insertions(+)
sound/soc/codecs/rt715-sdca.c +2 -0
index b43ac8559e45..861a0d2a8957 100644
@@ -12,6 +12,7 @@
  #include <linux/version.h>
  #include <linux/kernel.h>
  #include <linux/init.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)

return -EINVAL;

sound/soc/codecs/rt715-sdca.c +1 -0
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 =
 snd_soc_component_get_drvdata(component);
  	struct soc_mixer_control *mc =
  		(struct soc_mixer_control *)kcontrol->private_value;
  	unsigned int val, val2, loop_cnt = 2, i;
sound/soc/codecs/rt715-sdca.c +1 -0
@@ -268,6 +271,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int reg2 = mc->rreg;
  	unsigned int reg = mc->reg;
  	unsigned int max = mc->max;
+	unsigned int val0, val1;
  	int err;
 
  	val = ucontrol->value.integer.value[0];
sound/soc/codecs/rt715-sdca.c +12 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
  	return 0;
  }
sound/soc/codecs/rt715-sdca.h +1 -0
index 840c237895dd..f8988ab88f80 100644
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
  	int l_is_unmute;
  	int r_is_unmute;
  	int hw_sdw_ver;
+	bool micmute_led;
  };
 
  struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +2 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/i2c.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  		RT715_SET_GAIN_MIX_ADC2_L};
  	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
  	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
  	if (strstr(ucontrol->id.name, "Main Capture Switch") ||

strstr(ucontrol->id.name, "Main Capture Volume"))

sound/soc/codecs/rt715.c +3 -0
@@ -95,6 +97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  	else
  		loop_cnt = 1;
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 113

Quoted 10 lines
sound/soc/codecs/rt715.c +9 -0
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

You might have missed my other comment on v2 feedback, but is there a reason to keep it behind a compile time flag for dell privacy module? In practice any other future led backend provider should work too. Another way to think about it - if dell privacy wasn't enabled would this cause a problem to run this code? I think it would just be a no-op.

Quoted 15 lines
sound/soc/codecs/rt715.c +0 -0
  	for (j = 0; j < loop_cnt; j++) {

/* Can't use update bit function, so read the original value first
*/
if (loop_cnt == 1) {

sound/soc/codecs/rt715.h +1 -0
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
  	struct sdw_bus_params params;
  	bool hw_init;
  	bool first_hw_init;
+	bool micmute_led;
  };
 
Quoted 3 lines
Quoted 3 lines
sound/soc/codecs/rt715.h +0 -1
  struct sdw_stream_data {
--

2.25.1

Pierre Louis suggested to just set the mic mute led state unconditionally . It is more common interface to allow other platforms to change micmute led. The discussion result is from "[PATCH v2 2/2] ASoC: rt715:add Mic Mute LED control support"

Here is the change compared to V3 ,the CONFIG_DELL_PRIVACY will be removed

sound/soc/codecs/rt715.c +1 -2
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* dell privacy LED trigger state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

                         rt715->micmute_led = LED_OFF;
sound/soc/codecs/rt715.c +1 -2
index b4e480744c94..60bb3d98103e 100644
@@ -97,8 +97,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
         else
                 loop_cnt = 1;
 
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* Micmute LED state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

                         rt715->micmute_led = LED_OFF;

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 111

Quoted 5 lines
sound/soc/codecs/rt715.c +0 -1
@@ -107,7 +106,6 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
                 }
                 ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
         }
-#endif

I'm not sure which thread, but I believe there was still also another suggestion that this should be made more "generic" and to work for all codecs. So that when we have lets say a hypothetical rt717 we don't need the same in that module.

#4 lore raw

Hi,

Quoted 207 lines · Mario
Quoted 207 lines
Quoted 174 lines
Quoted 143 lines

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Tuesday, January 12, 2021 11:18
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yuan, Perry; Limonciello, Mario
Subject: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
  sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
  sound/soc/codecs/rt715-sdca.h |  1 +
  sound/soc/codecs/rt715.c      | 14 ++++++++++++++
  sound/soc/codecs/rt715.h      |  1 +
  4 files changed, 32 insertions(+)
sound/soc/codecs/rt715-sdca.c +2 -0
index b43ac8559e45..861a0d2a8957 100644
@@ -12,6 +12,7 @@
  #include <linux/version.h>
  #include <linux/kernel.h>
  #include <linux/init.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)

return -EINVAL;

sound/soc/codecs/rt715-sdca.c +1 -0
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 =
 snd_soc_component_get_drvdata(component);
  	struct soc_mixer_control *mc =
  		(struct soc_mixer_control *)kcontrol->private_value;
  	unsigned int val, val2, loop_cnt = 2, i;
sound/soc/codecs/rt715-sdca.c +1 -0
@@ -268,6 +271,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int reg2 = mc->rreg;
  	unsigned int reg = mc->reg;
  	unsigned int max = mc->max;
+	unsigned int val0, val1;
  	int err;
 
  	val = ucontrol->value.integer.value[0];
sound/soc/codecs/rt715-sdca.c +12 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
  	return 0;
  }
sound/soc/codecs/rt715-sdca.h +1 -0
index 840c237895dd..f8988ab88f80 100644
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
  	int l_is_unmute;
  	int r_is_unmute;
  	int hw_sdw_ver;
+	bool micmute_led;
  };
 
  struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +2 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/i2c.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  		RT715_SET_GAIN_MIX_ADC2_L};
  	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
  	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
  	if (strstr(ucontrol->id.name, "Main Capture Switch") ||

strstr(ucontrol->id.name, "Main Capture Volume"))

sound/soc/codecs/rt715.c +3 -0
@@ -95,6 +97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  	else
  		loop_cnt = 1;
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 113

Quoted 10 lines
sound/soc/codecs/rt715.c +9 -0
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

You might have missed my other comment on v2 feedback, but is there a reason to keep it behind a compile time flag for dell privacy module? In practice any other future led backend provider should work too. Another way to think about it - if dell privacy wasn't enabled would this cause a problem to run this code? I think it would just be a no-op.

Quoted 15 lines
sound/soc/codecs/rt715.c +0 -0
  	for (j = 0; j < loop_cnt; j++) {

/* Can't use update bit function, so read the original value first
*/
if (loop_cnt == 1) {

sound/soc/codecs/rt715.h +1 -0
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
  	struct sdw_bus_params params;
  	bool hw_init;
  	bool first_hw_init;
+	bool micmute_led;
  };
 
Quoted 3 lines
Quoted 3 lines
sound/soc/codecs/rt715.h +0 -1
  struct sdw_stream_data {
--

2.25.1

Pierre Louis suggested to just set the mic mute led state unconditionally . It is more common interface to allow other platforms to change micmute led. The discussion result is from "[PATCH v2 2/2] ASoC: rt715:add Mic Mute LED control support"

Here is the change compared to V3 ,the CONFIG_DELL_PRIVACY will be removed

sound/soc/codecs/rt715.c +1 -2
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* dell privacy LED trigger state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

                         rt715->micmute_led = LED_OFF;
sound/soc/codecs/rt715.c +1 -2
index b4e480744c94..60bb3d98103e 100644
@@ -97,8 +97,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
         else
                 loop_cnt = 1;
 
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* Micmute LED state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

Quoted 11 lines

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 111

Quoted 7 lines
                         rt715->micmute_led = LED_OFF;
sound/soc/codecs/rt715.c +0 -1
@@ -107,7 +106,6 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
                 }
                 ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
         }
-#endif

I'm not sure which thread, but I believe there was still also another suggestion that this should be made more "generic" and to work for all codecs. So that when we have lets say a hypothetical rt717 we don't need the same in that module.

Right:

Quoted 16 lines · Jaroslav Kysela

Dne 12. 01. 21 v 18:18 Perry Yuan napsal(a):

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol

Quoted 11 lines
sound/soc/codecs/rt715.c +11 -0
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif

[removing lkml and x86-platform lists]

Quoted 7 lines

Looking to this code, perhaps, it may be a good idea to move the LED trigger handling from the low-level drivers and do it in the top-level control code (sound/core/control.c). Adding a new flag SNDRV_CTL_ELEM_ACCESS_MIC_LED may be an option and we can nicely handle the situation for multiple microphones (OR operation). The motivation is to remove the duplicated code.

The same situation is for the playback LED.

I believe that this is an excellent suggestion and that this is the way to go.

Regards,

Hans

#5 lore raw
Quoted 249 lines · Hans de Goede

Hi,

Quoted 207 lines · Mario
Quoted 207 lines
Quoted 174 lines
Quoted 143 lines

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Tuesday, January 12, 2021 11:18
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yuan, Perry; Limonciello, Mario
Subject: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
  sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
  sound/soc/codecs/rt715-sdca.h |  1 +
  sound/soc/codecs/rt715.c      | 14 ++++++++++++++
  sound/soc/codecs/rt715.h      |  1 +
  4 files changed, 32 insertions(+)
sound/soc/codecs/rt715-sdca.c +2 -0
index b43ac8559e45..861a0d2a8957 100644
@@ -12,6 +12,7 @@
  #include <linux/version.h>
  #include <linux/kernel.h>
  #include <linux/init.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)

return -EINVAL;

sound/soc/codecs/rt715-sdca.c +1 -0
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 =
 snd_soc_component_get_drvdata(component);
  	struct soc_mixer_control *mc =
  		(struct soc_mixer_control *)kcontrol->private_value;
  	unsigned int val, val2, loop_cnt = 2, i;
sound/soc/codecs/rt715-sdca.c +1 -0
@@ -268,6 +271,7 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  	unsigned int reg2 = mc->rreg;
  	unsigned int reg = mc->reg;
  	unsigned int max = mc->max;
+	unsigned int val0, val1;
  	int err;
 
  	val = ucontrol->value.integer.value[0];
sound/soc/codecs/rt715-sdca.c +12 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol
 *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+
  	return 0;
  }
sound/soc/codecs/rt715-sdca.h +1 -0
index 840c237895dd..f8988ab88f80 100644
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
  	int l_is_unmute;
  	int r_is_unmute;
  	int hw_sdw_ver;
+	bool micmute_led;
  };
 
  struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +2 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/i2c.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  		RT715_SET_GAIN_MIX_ADC2_L};
  	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
  	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
  	if (strstr(ucontrol->id.name, "Main Capture Switch") ||

strstr(ucontrol->id.name, "Main Capture Volume"))

sound/soc/codecs/rt715.c +3 -0
@@ -95,6 +97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
  	else
  		loop_cnt = 1;
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 113

Quoted 10 lines
sound/soc/codecs/rt715.c +9 -0
+		if (ucontrol->value.integer.value[0] || ucontrol-
 > value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

You might have missed my other comment on v2 feedback, but is there a reason to keep it behind a compile time flag for dell privacy module? In practice any other future led backend provider should work too. Another way to think about it - if dell privacy wasn't enabled would this cause a problem to run this code? I think it would just be a no-op.

Quoted 15 lines
sound/soc/codecs/rt715.c +0 -0
  	for (j = 0; j < loop_cnt; j++) {

/* Can't use update bit function, so read the original value first
*/
if (loop_cnt == 1) {

sound/soc/codecs/rt715.h +1 -0
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
  	struct sdw_bus_params params;
  	bool hw_init;
  	bool first_hw_init;
+	bool micmute_led;
  };
 
Quoted 3 lines
Quoted 3 lines
sound/soc/codecs/rt715.h +0 -1
  struct sdw_stream_data {
--

2.25.1

Pierre Louis suggested to just set the mic mute led state unconditionally . It is more common interface to allow other platforms to change micmute led. The discussion result is from "[PATCH v2 2/2] ASoC: rt715:add Mic Mute LED control support"

Here is the change compared to V3 ,the CONFIG_DELL_PRIVACY will be removed

sound/soc/codecs/rt715.c +1 -2
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* dell privacy LED trigger state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

                         rt715->micmute_led = LED_OFF;
sound/soc/codecs/rt715.c +1 -2
index b4e480744c94..60bb3d98103e 100644
@@ -97,8 +97,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
         else
                 loop_cnt = 1;
 
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* Micmute LED state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

Quoted 11 lines

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 111

Quoted 7 lines
                         rt715->micmute_led = LED_OFF;
sound/soc/codecs/rt715.c +0 -1
@@ -107,7 +106,6 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
 *kcontrol,
                 }
                 ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
         }
-#endif

I'm not sure which thread, but I believe there was still also another suggestion that this should be made more "generic" and to work for all codecs. So that when we have lets say a hypothetical rt717 we don't need the same in that module.

Right:

Quoted 22 lines · Jaroslav Kysela

Dne 12. 01. 21 v 18:18 Perry Yuan napsal(a):

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol

Quoted 11 lines
sound/soc/codecs/rt715.c +11 -0
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif

[removing lkml and x86-platform lists]

Looking to this code, perhaps, it may be a good idea to move the LED trigger handling from the low-level drivers and do it in the top-level control code (sound/core/control.c). Adding a new flag SNDRV_CTL_ELEM_ACCESS_MIC_LED may be an option and we can nicely handle the situation for multiple microphones (OR operation). The motivation is to remove the duplicated code.

Quoted 3 lines
Quoted 1 line

The same situation is for the playback LED.

I believe that this is an excellent suggestion and that this is the way to go.

Well, I'm not thrilled by moving in that high level.

If you put it to the core, the control core (i.e. the main snd module) will need the dependency on the LEDS stuff. Such an dependency mess is what we'd like to avoid in general.

At most, yet more helper module that depends on the leds, but OTOH, we don't want yet more module, either...

BTW, there is always some crazy request. For example, HD-audio code has the mute-LED mode to flip the LED meaning; i.e. turn LED on at unmuted so that user can see explicitly that it's being recorded. It makes sense from the security POV.

Just to keep such a possibility in mind.

Takashi

#6 lore raw
In reply to Limonciello, Mario
Quoted 235 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Wednesday, January 20, 2021 12:33 AM
To: Perry Yuan; Yuan, Perry; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

Quoted 150 lines
Quoted 94 lines
Quoted 94 lines

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Tuesday, January 12, 2021 11:18
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Yuan, Perry; Limonciello, Mario
Subject: [PATCH v3 3/3] ASoC: rt715:add micmute led state control supports

From: Perry Yuan <[email protected]>

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

--------
v2 -> v3
* simplify the patch to reuse some val value
* add more detail to the commit info

v1 -> v2:
* fix some format issue
--------

---
  sound/soc/codecs/rt715-sdca.c | 16 ++++++++++++++++
  sound/soc/codecs/rt715-sdca.h |  1 +
  sound/soc/codecs/rt715.c      | 14 ++++++++++++++
  sound/soc/codecs/rt715.h      |  1 +
  4 files changed, 32 insertions(+)
(quoted diff) +0 -0

b/sound/soc/codecs/rt715-sdca.c index b43ac8559e45..861a0d2a8957 100644

sound/soc/codecs/rt715-sdca.c +2 -0
@@ -12,6 +12,7 @@
  #include <linux/version.h>
  #include <linux/kernel.h>
  #include <linux/init.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct
 snd_kcontrol *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)

return -EINVAL;

sound/soc/codecs/rt715-sdca.c +1 -0
@@ -261,6 +263,7 @@ static int rt715_sdca_put_volsw(struct
 snd_kcontrol *kcontrol,
  	struct snd_ctl_elem_value *ucontrol)
  {
  	struct snd_soc_component *component =
 snd_kcontrol_chip(kcontrol);
+	struct rt715_sdca_priv *rt715 =
 snd_soc_component_get_drvdata(component);

struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
unsigned int val, val2, loop_cnt = 2, i; @@ -268,6 +271,7 @@
static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
unsigned int reg2 = mc->rreg;
unsigned int reg = mc->reg;
unsigned int max = mc->max;

sound/soc/codecs/rt715-sdca.c +1 -0
+	unsigned int val0, val1;
  	int err;
 
  	val = ucontrol->value.integer.value[0]; @@ -287,6 +291,18 @@

static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
return err;
}

sound/soc/codecs/rt715-sdca.c +4 -0
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 6 lines

sound/soc/codecs/rt715-sdca.c

Quoted 6 lines
Quoted 1 line

value.integer.value[1]) {

sound/soc/codecs/rt715-sdca.c +5 -0
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715-

micmute_led);

Quoted 49 lines
Quoted 49 lines
sound/soc/codecs/rt715-sdca.c +3 -0
+	}
+#endif
+
  	return 0;
  }
(quoted diff) +0 -0

b/sound/soc/codecs/rt715-sdca.h index 840c237895dd..f8988ab88f80 100644

sound/soc/codecs/rt715-sdca.h +1 -0
@@ -31,6 +31,7 @@ struct rt715_sdca_priv {
  	int l_is_unmute;
  	int r_is_unmute;
  	int hw_sdw_ver;
+	bool micmute_led;
  };
 
  struct rt715_sdw_stream_data {
sound/soc/codecs/rt715.c +2 -0
index cdcba70146da..b4e480744c94 100644
@@ -13,6 +13,7 @@
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/i2c.h>
+#include <linux/leds.h>
  #include <linux/pm_runtime.h>
  #include <linux/pm.h>
  #include <linux/soundwire/sdw.h>
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct
 snd_kcontrol *kcontrol,
  		RT715_SET_GAIN_MIX_ADC2_L};
  	unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
  	unsigned int read_ll, read_rl, i, j, loop_cnt;
+	unsigned int val0, val1;
 
  	if (strstr(ucontrol->id.name, "Main Capture Switch") ||

strstr(ucontrol->id.name, "Main Capture Volume")) @@ -95,6
+97,18 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,
else
loop_cnt = 1;

sound/soc/codecs/rt715.c +4 -0
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* Micmute LED state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 15 lines
Quoted 6 lines

sound/soc/codecs/rt715.c

Quoted 6 lines
Quoted 1 line

value.integer.value[1]) {

sound/soc/codecs/rt715.c +5 -0
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715-

micmute_led);

Quoted 8 lines

sound/soc/codecs/rt715.c

Quoted 3 lines
sound/soc/codecs/rt715.c +3 -0
+	}
+#endif
+

You might have missed my other comment on v2 feedback, but is there a reason to keep it behind a compile time flag for dell privacy module? In practice any other future led backend provider should work too. Another way to think about it - if dell privacy wasn't enabled would this cause a problem to run this code? I think it would just

be a no-op.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

for (j = 0; j < loop_cnt; j++) {
/* Can't use update bit function, so read the original value
first */
if (loop_cnt == 1) {

sound/soc/codecs/rt715.h +1 -0
index 009a8266f606..57c9af041181 100644
@@ -22,6 +22,7 @@ struct rt715_priv {
  	struct sdw_bus_params params;
  	bool hw_init;
  	bool first_hw_init;
+	bool micmute_led;
  };
 
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
sound/soc/codecs/rt715.h +0 -1
  struct sdw_stream_data {
--

2.25.1

Pierre Louis suggested to just set the mic mute led state unconditionally . It is more common interface to allow other platforms to change micmute

led.

Quoted 28 lines

The discussion result is from "[PATCH v2 2/2] ASoC: rt715:add Mic Mute LED control support"

Here is the change compared to V3 ,the CONFIG_DELL_PRIVACY will be removed

sound/soc/codecs/rt715.c +1 -2
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* dell privacy LED trigger state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

                         rt715->micmute_led = LED_OFF; diff --git

a/sound/soc/codecs/rt715.c b/sound/soc/codecs/rt715.c index b4e480744c94..60bb3d98103e 100644

sound/soc/codecs/rt715.c +1 -2
@@ -97,8 +97,7 @@ static int rt715_set_amp_gain_put(struct
 snd_kcontrol *kcontrol,
         else
                 loop_cnt = 1;
 
-#if IS_ENABLED(CONFIG_DELL_PRIVACY)
-       /* Micmute LED state changed by muted/unmute switch */
+       /* MicMute LED state changed by muted/unmute switch */
         if (mc->invert) {
                 if (ucontrol->value.integer.value[0] || ucontrol-
Quoted 1 line

value.integer.value[1]) {

Quoted 7 lines
                         rt715->micmute_led = LED_OFF; @@ -107,7
+106,6 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol
*kcontrol,
                 }
                 ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
         }

-#endif

Quoted 4 lines

I'm not sure which thread, but I believe there was still also another suggestion that this should be made more "generic" and to work for all codecs. So that when we have lets say a hypothetical rt717 we don't need the same in that module.

Hi Mario.
Jaroslav suggested me to move this part code to generic control layer. I will adjust this patch and do some testing for the new patch.

Perry.

maintainer
#7 lore raw
In reply to Perry Yuan
Quoted 11 lines · Perry Yuan

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

It feels like there's an abstraction problem here with this being hard coded in a specific CODEC driver.

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol, · line 251

Quoted 9 lines

#include <linux/soundwire/sdw.h>

sound/soc/codecs/rt715-sdca.c +1 -0
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol,
 	unsigned int max = mc->max;
 	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
 	val = snd_soc_component_read(component, mc->reg);
 	if (val < 0)
 		return -EINVAL;

This shouldn't be in the patch.

Quoted 6 lines
sound/soc/codecs/rt715-sdca.c +2 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
 			return err;
 	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 305

Quoted 10 lines
sound/soc/codecs/rt715-sdca.c +10 -0
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

This doesn't look good. There's nothing Dell specific here, and nothing about this is conditional on any sort of runtime detection of Dell systems, it's not obvious why this is conditional on DELL_PRIVACY or why we only report the state if the control is inverted.

I'm also not convinced that it's a good idea to set the mute LED if only one channel in a stereo microphone is muted, that seems likely to lead to surprising behaviour for users.

TBH I don't understand why this isn't being done in generic code.

Review static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 306

Quoted 1 line
(quoted diff) +1 -0
+	bool micmute_led;

What is this for, it never seems to be read except for in the function where it's set?

#8 lore raw

Hi Mark,
Thanks for your review feedback.

Quoted 9 lines · Mark Brown
Quoted 6 lines · Perry Yuan

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

Quoted 8 lines
Quoted 4 lines

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

It feels like there's an abstraction problem here with this being hard coded in a specific CODEC driver.

I will remove the CONFIG_DELL_PRIVACY ,because other vendors and other platforms maybe need to set their Mic mute led state when they enable soundwire and sof driver for audio function. We can avoid hardcode in codec driver, indeed it is need for this new
soundwire & sof architecture of alsa.

Quoted 11 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol, · line 251

Quoted 9 lines
  #include <linux/soundwire/sdw.h>
sound/soc/codecs/rt715-sdca.c +1 -0
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)
  		return -EINVAL;

This shouldn't be in the patch.

It is my mistake to leave the debug line here.
will be removed in next V4 .

Quoted 14 lines
Quoted 14 lines
sound/soc/codecs/rt715-sdca.c +9 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
Quoted 8 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 305

Quoted 3 lines
sound/soc/codecs/rt715-sdca.c +3 -0
+	}
+#endif
+

This doesn't look good. There's nothing Dell specific here, and nothing about this is conditional on any sort of runtime detection of Dell systems, it's not obvious why this is conditional on DELL_PRIVACY or why we only report the state if the control is inverted.

I will remove the CONFIG_DELL_PRIVACY for the mic mute led operation is not only needed for dell platforms but also other Vendors all need to set micmute led necessaryily.

Quoted 5 lines

I'm also not convinced that it's a good idea to set the mute LED if only one channel in a stereo microphone is muted, that seems likely to lead to surprising behaviour for users.

At first, i just want to handle val0 == 1 && val1 == 1 and val0 == 0 && val1 == 0 only. Intel suggested i need to cover all about other cases, the mute led should be off if any channel of mic is on. So i change the led state when any one channel is muted or unmuted.

Quoted 7 lines

TBH I don't understand why this isn't being done in generic code.

Review static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 306

Quoted 1 line
(quoted diff) +1 -0
+	bool micmute_led;

What is this for, it never seems to be read except for in the function where it's set?

Do you mean i can use a local micmute_led var in the function?

maintainer
#9 lore raw
Quoted 8 lines · Perry Yuan
Quoted 4 lines · Mark Brown

Review

Quoted 1 line
(quoted diff) +1 -0
+	bool micmute_led;

What is this for, it never seems to be read except for in the function where it's set?

Do you mean i can use a local micmute_led var in the function?

Yes.

#10 lore raw
In reply to Mark Brown

Hi Mark:
Thanks for your review.

Quoted 22 lines · Mark Brown
Quoted 11 lines · Perry Yuan

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

It feels like there's an abstraction problem here with this being hard coded in a specific CODEC driver.

Quoted 5 lines
  #include <linux/soundwire/sdw.h>
sound/soc/codecs/rt715-sdca.c +0 -0
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
Quoted 6 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol, · line 251

Quoted 4 lines
sound/soc/codecs/rt715-sdca.c +1 -0
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)
  		return -EINVAL;

This shouldn't be in the patch.

Removed in V4, I forget to clear this debug code

Quoted 14 lines
Quoted 14 lines
sound/soc/codecs/rt715-sdca.c +9 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
Quoted 9 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 305

Quoted 3 lines
sound/soc/codecs/rt715-sdca.c +3 -0
+	}
+#endif
+

This doesn't look good. There's nothing Dell specific here, and nothing about this is conditional on any sort of runtime detection of Dell systems, it's not obvious why this is conditional on DELL_PRIVACY or why we only report the state if the control is inverted.

I will remove the CONFIG_DELL_PRIVACY from V4 patch and allow it to run if CONFIG_DELL_PRIVACY is not set, the result will be a no-op.

Quoted 4 lines

I'm also not convinced that it's a good idea to set the mute LED if only one channel in a stereo microphone is muted, that seems likely to lead to surprising behaviour for users.

https://github.com/thesofproject/linux/pull/2660#discussion_r555480210
There is a discussion for the channel mute changing behavior. If the anyone of value[0] or value[1] is 1, it means mic is NOT muted The muted state will be LED_ON state need to set.

Quoted 7 lines

TBH I don't understand why this isn't being done in generic code.

Review static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 306

Quoted 1 line
(quoted diff) +1 -0
+	bool micmute_led;

What is this for, it never seems to be read except for in the function where it's set?

I have moved this part code to the local definition of rt715_set_amp_gain_put and removed from rt715_priv. new code will be like this in V4.

@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,

                RT715_SET_GAIN_MIX_ADC2_L};
        unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
        unsigned int read_ll, read_rl, i, j, loop_cnt;

+ bool micmute_led;

#11 lore raw
In reply to Mark Brown

Hi Mark:
Thanks for your review.

Quoted 22 lines · Mark Brown
Quoted 11 lines · Perry Yuan

Some new Dell system is going to support audio internal micphone privacy setting from hardware level with micmute led state changing When micmute hotkey pressed by user, soft mute will need to be enabled firstly in case of pop noise, and codec driver need to react to mic mute event to EC(embedded controller) notifying that SW mute is completed Then EC will do the hardware mute physically within the timeout reached

This patch allow codec rt715 driver to ack EC when micmute key pressed through this micphone led control interface like hda_generic provided ACPI method defined in dell-privacy micmute led trigger will be called for notifying the EC that software mute has been completed

It feels like there's an abstraction problem here with this being hard coded in a specific CODEC driver.

Quoted 5 lines
  #include <linux/soundwire/sdw.h>
sound/soc/codecs/rt715-sdca.c +0 -0
@@ -244,6 +245,7 @@ static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol,
  	unsigned int max = mc->max;
  	int val;
 
Quoted 6 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_get_volsw(struct snd_kcontrol *kcontrol, · line 251

Quoted 4 lines
sound/soc/codecs/rt715-sdca.c +1 -0
+	pr_err("++++++rt715_sdca_get_volsw++\n");
  	val = snd_soc_component_read(component, mc->reg);
  	if (val < 0)
  		return -EINVAL;

This shouldn't be in the patch.

Removed in V4, I forget to clear this debug code

Quoted 14 lines
Quoted 14 lines
sound/soc/codecs/rt715-sdca.c +9 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
  			return err;
  	}
 
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
Quoted 9 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 305

Quoted 3 lines
sound/soc/codecs/rt715-sdca.c +3 -0
+	}
+#endif
+

This doesn't look good. There's nothing Dell specific here, and nothing about this is conditional on any sort of runtime detection of Dell systems, it's not obvious why this is conditional on DELL_PRIVACY or why we only report the state if the control is inverted.

I will remove the CONFIG_DELL_PRIVACY from V4 patch and allow it to run if CONFIG_DELL_PRIVACY is not set, the result will be a no-op.

Quoted 4 lines

I'm also not convinced that it's a good idea to set the mute LED if only one channel in a stereo microphone is muted, that seems likely to lead to surprising behaviour for users.

https://github.com/thesofproject/linux/pull/2660#discussion_r555480210
There is a discussion for the channel mute changing behavior. If the anyone of value[0] or value[1] is 1, it means mic is NOT muted The muted state will be LED_ON state need to set.

Quoted 7 lines

TBH I don't understand why this isn't being done in generic code.

Review static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 306

Quoted 1 line
(quoted diff) +1 -0
+	bool micmute_led;

What is this for, it never seems to be read except for in the function where it's set?

I have moved this part code to the local definition of rt715_set_amp_gain_put and removed from rt715_priv. new code will be like this in V4.

@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol *kcontrol,

                RT715_SET_GAIN_MIX_ADC2_L};
        unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
        unsigned int read_ll, read_rl, i, j, loop_cnt;

+ bool micmute_led;

maintainer
#12 lore raw

Dne 14. 02. 21 v 7:43 Perry Yuan napsal(a):

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/rt715-sdca.c +0 -0
@@ -287,6 +291,18 @@ static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol,
  			return err;
  	}
 
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/rt715-sdca.c +4 -0
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
Quoted 8 lines

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 305

Quoted 8 lines
sound/soc/codecs/rt715-sdca.c +8 -0
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif
+

My question is, how do we know that the rt715 codec has connected internal microphone to this input? I believe that this should be covered in the machine specific code (runtime check), not in the codec code. #if CONFIG is not sufficient here.

sound/soc/codecs/rt715.c static int rt715_set_amp_gain_put(struct snd_kcontrol · line 94

Quoted 11 lines

I have moved this part code to the local definition of rt715_set_amp_gain_put and removed from rt715_priv. new code will be like this in V4.

sound/soc/codecs/rt715.c +1 -0
@@ -88,6 +89,7 @@ static int rt715_set_amp_gain_put(struct snd_kcontrol 
 *kcontrol,
                 RT715_SET_GAIN_MIX_ADC2_L};
         unsigned int addr_h, addr_l, val_h, val_ll, val_lr;
         unsigned int read_ll, read_rl, i, j, loop_cnt;
+       bool micmute_led;
 

The whole LED trigger mechanism for the sound is covered in my LED generic code : https://lore.kernel.org/alsa-devel/[email protected]/

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
maintainer
#13 lore raw
In reply to Perry Yuan

Dne 12. 01. 21 v 18:18 Perry Yuan napsal(a):

sound/soc/codecs/rt715-sdca.c static int rt715_sdca_put_volsw(struct snd_kcontrol *kcontrol, · line 304

Quoted 11 lines
sound/soc/codecs/rt715-sdca.c +11 -0
+#if IS_ENABLED(CONFIG_DELL_PRIVACY)
+	/* dell privacy LED trigger state changed by muted/unmute switch */
+	if (mc->invert) {
+		if (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) {
+			rt715->micmute_led = LED_OFF;
+		} else {
+			rt715->micmute_led = LED_ON;
+		}
+		ledtrig_audio_set(LED_AUDIO_MICMUTE, rt715->micmute_led);
+	}
+#endif

[removing lkml and x86-platform lists]

Looking to this code, perhaps, it may be a good idea to move the LED trigger handling from the low-level drivers and do it in the top-level control code (sound/core/control.c). Adding a new flag SNDRV_CTL_ELEM_ACCESS_MIC_LED may be an option and we can nicely handle the situation for multiple microphones (OR operation). The motivation is to remove the duplicated code.

The same situation is for the playback LED.

Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.