All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO
@ 2020-04-30  8:32 ` Kai-Heng Feng
  0 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30  8:32 UTC (permalink / raw)
  To: tiwai
  Cc: Kai-Heng Feng, Jaroslav Kysela, Kailang Yang, Hui Wang,
	Jian-Hong Pan, Tomas Espeleta, Thomas Hebb,
	Michał Mirosław, moderated list:SOUND, open list

Currently mute LED and micmute LED share the same GPIO polarity.

So split the polarity for mute and micmute, in case they have different
polarities.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index c16f63957c5a..3150a61befc5 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -81,6 +81,7 @@ struct alc_spec {
 
 	/* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
 	int mute_led_polarity;
+	int micmute_led_polarity;
 	hda_nid_t mute_led_nid;
 	hda_nid_t cap_mute_led_nid;
 
@@ -4075,11 +4076,9 @@ static void alc269_fixup_hp_mute_led_mic3(struct hda_codec *codec,
 
 /* update LED status via GPIO */
 static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask,
-				bool enabled)
+				int polarity, bool enabled)
 {
-	struct alc_spec *spec = codec->spec;
-
-	if (spec->mute_led_polarity)
+	if (polarity)
 		enabled = !enabled;
 	alc_update_gpio_data(codec, mask, !enabled); /* muted -> LED on */
 }
@@ -4090,7 +4089,8 @@ static void alc_fixup_gpio_mute_hook(void *private_data, int enabled)
 	struct hda_codec *codec = private_data;
 	struct alc_spec *spec = codec->spec;
 
-	alc_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled);
+	alc_update_gpio_led(codec, spec->gpio_mute_led_mask,
+			    spec->mute_led_polarity, enabled);
 }
 
 /* turn on/off mic-mute LED via GPIO per capture hook */
@@ -4099,6 +4099,7 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
 	struct alc_spec *spec = codec->spec;
 
 	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
+			    spec->micmute_led_polarity,
 			    spec->gen.micmute_led.led_value);
 }
 
@@ -5795,7 +5796,8 @@ static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec,
 
 	snd_hda_gen_hp_automute(codec, jack);
 	/* mute_led_polarity is set to 0, so we pass inverted value here */
-	alc_update_gpio_led(codec, 0x10, !spec->gen.hp_jack_present);
+	alc_update_gpio_led(codec, 0x10, spec->mute_led_polarity,
+			    !spec->gen.hp_jack_present);
 }
 
 /* Manage GPIOs for HP EliteBook Folio 9480m.
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 1/3] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO
@ 2020-04-30  8:32 ` Kai-Heng Feng
  0 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30  8:32 UTC (permalink / raw)
  To: tiwai
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, Thomas Hebb,
	open list, Hui Wang, Kai-Heng Feng, Jian-Hong Pan,
	Michał Mirosław

Currently mute LED and micmute LED share the same GPIO polarity.

So split the polarity for mute and micmute, in case they have different
polarities.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index c16f63957c5a..3150a61befc5 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -81,6 +81,7 @@ struct alc_spec {
 
 	/* mute LED for HP laptops, see alc269_fixup_mic_mute_hook() */
 	int mute_led_polarity;
+	int micmute_led_polarity;
 	hda_nid_t mute_led_nid;
 	hda_nid_t cap_mute_led_nid;
 
@@ -4075,11 +4076,9 @@ static void alc269_fixup_hp_mute_led_mic3(struct hda_codec *codec,
 
 /* update LED status via GPIO */
 static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask,
-				bool enabled)
+				int polarity, bool enabled)
 {
-	struct alc_spec *spec = codec->spec;
-
-	if (spec->mute_led_polarity)
+	if (polarity)
 		enabled = !enabled;
 	alc_update_gpio_data(codec, mask, !enabled); /* muted -> LED on */
 }
@@ -4090,7 +4089,8 @@ static void alc_fixup_gpio_mute_hook(void *private_data, int enabled)
 	struct hda_codec *codec = private_data;
 	struct alc_spec *spec = codec->spec;
 
-	alc_update_gpio_led(codec, spec->gpio_mute_led_mask, enabled);
+	alc_update_gpio_led(codec, spec->gpio_mute_led_mask,
+			    spec->mute_led_polarity, enabled);
 }
 
 /* turn on/off mic-mute LED via GPIO per capture hook */
@@ -4099,6 +4099,7 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
 	struct alc_spec *spec = codec->spec;
 
 	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
+			    spec->micmute_led_polarity,
 			    spec->gen.micmute_led.led_value);
 }
 
@@ -5795,7 +5796,8 @@ static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec,
 
 	snd_hda_gen_hp_automute(codec, jack);
 	/* mute_led_polarity is set to 0, so we pass inverted value here */
-	alc_update_gpio_led(codec, 0x10, !spec->gen.hp_jack_present);
+	alc_update_gpio_led(codec, 0x10, spec->mute_led_polarity,
+			    !spec->gen.hp_jack_present);
 }
 
 /* Manage GPIOs for HP EliteBook Folio 9480m.
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/3] ALSA: hda/realtek - Enable micmute LED on and HP system
  2020-04-30  8:32 ` Kai-Heng Feng
@ 2020-04-30  8:32   ` Kai-Heng Feng
  -1 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30  8:32 UTC (permalink / raw)
  To: tiwai
  Cc: Kai-Heng Feng, Jaroslav Kysela, Kailang Yang, Hui Wang,
	Jian-Hong Pan, Tomas Espeleta, Thomas Hebb,
	Michał Mirosław, moderated list:SOUND, open list

Though the system uses DMIC, headset mic still uses the HDA, let's use
GPIO 0x1 to control the micmute LED.

The micmute LED GPIO has a different polarity to the mute LED GPIO, we
can use the newly added micmute_led_polarity to indicate that.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 3150a61befc5..6f164ccddde3 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4134,7 +4134,11 @@ static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
 static void alc285_fixup_hp_gpio_led(struct hda_codec *codec,
 				const struct hda_fixup *fix, int action)
 {
-	alc_fixup_hp_gpio_led(codec, action, 0x04, 0x00);
+	struct alc_spec *spec = codec->spec;
+
+	spec->micmute_led_polarity = 1;
+
+	alc_fixup_hp_gpio_led(codec, action, 0x04, 0x01);
 }
 
 static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/3] ALSA: hda/realtek - Enable micmute LED on and HP system
@ 2020-04-30  8:32   ` Kai-Heng Feng
  0 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30  8:32 UTC (permalink / raw)
  To: tiwai
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, Thomas Hebb,
	open list, Hui Wang, Kai-Heng Feng, Jian-Hong Pan,
	Michał Mirosław

Though the system uses DMIC, headset mic still uses the HDA, let's use
GPIO 0x1 to control the micmute LED.

The micmute LED GPIO has a different polarity to the mute LED GPIO, we
can use the newly added micmute_led_polarity to indicate that.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 3150a61befc5..6f164ccddde3 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4134,7 +4134,11 @@ static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
 static void alc285_fixup_hp_gpio_led(struct hda_codec *codec,
 				const struct hda_fixup *fix, int action)
 {
-	alc_fixup_hp_gpio_led(codec, action, 0x04, 0x00);
+	struct alc_spec *spec = codec->spec;
+
+	spec->micmute_led_polarity = 1;
+
+	alc_fixup_hp_gpio_led(codec, action, 0x04, 0x01);
 }
 
 static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
  2020-04-30  8:32 ` Kai-Heng Feng
@ 2020-04-30  8:32   ` Kai-Heng Feng
  -1 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30  8:32 UTC (permalink / raw)
  To: tiwai
  Cc: Kai-Heng Feng, Jaroslav Kysela, Kailang Yang, Hui Wang,
	Jian-Hong Pan, Tomas Espeleta, Thomas Hebb,
	Michał Mirosław, moderated list:SOUND, open list

Currently DMIC controls micmute LED via "audio mute LED trigger".

However, unlike Dell and Lenovo platforms, HP platforms don't provide a
way to control micmute LED via ACPI, it's controlled by HDA codec
instead.

So let's register an LED class for micmute so other subsystems like DMIC
can facilitate the codec-controlled LED.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6f164ccddde3..82eb7624bbba 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -17,6 +17,7 @@
 #include <linux/dmi.h>
 #include <linux/module.h>
 #include <linux/input.h>
+#include <linux/leds.h>
 #include <sound/core.h>
 #include <sound/jack.h>
 #include <sound/hda_codec.h>
@@ -4103,6 +4104,24 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
 			    spec->gen.micmute_led.led_value);
 }
 
+static int micmute_led_set(struct led_classdev *led_cdev,
+			   enum led_brightness brightness)
+{
+	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
+	struct alc_spec *spec = codec->spec;
+
+	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
+			    spec->micmute_led_polarity, !!brightness);
+	return 0;
+}
+
+static struct led_classdev micmute_led_cdev = {
+	.name = "hda::micmute",
+	.max_brightness = 1,
+	.brightness_set_blocking = micmute_led_set,
+	.default_trigger = "audio-micmute",
+};
+
 /* setup mute and mic-mute GPIO bits, add hooks appropriately */
 static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  int action,
@@ -4110,6 +4129,7 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  unsigned int micmute_mask)
 {
 	struct alc_spec *spec = codec->spec;
+	int err;
 
 	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
 
@@ -4122,6 +4142,11 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 	if (micmute_mask) {
 		spec->gpio_mic_led_mask = micmute_mask;
 		snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
+
+		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
+		err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
+		if (err)
+			codec_warn(codec, "failed to register micmute LED\n");
 	}
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
@ 2020-04-30  8:32   ` Kai-Heng Feng
  0 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30  8:32 UTC (permalink / raw)
  To: tiwai
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, Thomas Hebb,
	open list, Hui Wang, Kai-Heng Feng, Jian-Hong Pan,
	Michał Mirosław

Currently DMIC controls micmute LED via "audio mute LED trigger".

However, unlike Dell and Lenovo platforms, HP platforms don't provide a
way to control micmute LED via ACPI, it's controlled by HDA codec
instead.

So let's register an LED class for micmute so other subsystems like DMIC
can facilitate the codec-controlled LED.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6f164ccddde3..82eb7624bbba 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -17,6 +17,7 @@
 #include <linux/dmi.h>
 #include <linux/module.h>
 #include <linux/input.h>
+#include <linux/leds.h>
 #include <sound/core.h>
 #include <sound/jack.h>
 #include <sound/hda_codec.h>
@@ -4103,6 +4104,24 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
 			    spec->gen.micmute_led.led_value);
 }
 
+static int micmute_led_set(struct led_classdev *led_cdev,
+			   enum led_brightness brightness)
+{
+	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
+	struct alc_spec *spec = codec->spec;
+
+	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
+			    spec->micmute_led_polarity, !!brightness);
+	return 0;
+}
+
+static struct led_classdev micmute_led_cdev = {
+	.name = "hda::micmute",
+	.max_brightness = 1,
+	.brightness_set_blocking = micmute_led_set,
+	.default_trigger = "audio-micmute",
+};
+
 /* setup mute and mic-mute GPIO bits, add hooks appropriately */
 static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  int action,
@@ -4110,6 +4129,7 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  unsigned int micmute_mask)
 {
 	struct alc_spec *spec = codec->spec;
+	int err;
 
 	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
 
@@ -4122,6 +4142,11 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 	if (micmute_mask) {
 		spec->gpio_mic_led_mask = micmute_mask;
 		snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
+
+		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
+		err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
+		if (err)
+			codec_warn(codec, "failed to register micmute LED\n");
 	}
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
  2020-04-30  8:32   ` Kai-Heng Feng
@ 2020-04-30 11:26     ` Takashi Iwai
  -1 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 11:26 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: tiwai, Jaroslav Kysela, Kailang Yang, Hui Wang, Jian-Hong Pan,
	Tomas Espeleta, Thomas Hebb, Michał Mirosław,
	moderated list:SOUND, open list

On Thu, 30 Apr 2020 10:32:53 +0200,
Kai-Heng Feng wrote:
> 
> Currently DMIC controls micmute LED via "audio mute LED trigger".
> 
> However, unlike Dell and Lenovo platforms, HP platforms don't provide a
> way to control micmute LED via ACPI, it's controlled by HDA codec
> instead.
> 
> So let's register an LED class for micmute so other subsystems like DMIC
> can facilitate the codec-controlled LED.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

I guess this requires the Kconfig change to select CONFIG_LEDS_*
or make the code conditionally built.  So far the latter strategy is
taken for the code in hda_generic.c.


thanks,

Takashi

> ---
>  sound/pci/hda/patch_realtek.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index 6f164ccddde3..82eb7624bbba 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -17,6 +17,7 @@
>  #include <linux/dmi.h>
>  #include <linux/module.h>
>  #include <linux/input.h>
> +#include <linux/leds.h>
>  #include <sound/core.h>
>  #include <sound/jack.h>
>  #include <sound/hda_codec.h>
> @@ -4103,6 +4104,24 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
>  			    spec->gen.micmute_led.led_value);
>  }
>  
> +static int micmute_led_set(struct led_classdev *led_cdev,
> +			   enum led_brightness brightness)
> +{
> +	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
> +	struct alc_spec *spec = codec->spec;
> +
> +	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
> +			    spec->micmute_led_polarity, !!brightness);
> +	return 0;
> +}
> +
> +static struct led_classdev micmute_led_cdev = {
> +	.name = "hda::micmute",
> +	.max_brightness = 1,
> +	.brightness_set_blocking = micmute_led_set,
> +	.default_trigger = "audio-micmute",
> +};
> +
>  /* setup mute and mic-mute GPIO bits, add hooks appropriately */
>  static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
>  				  int action,
> @@ -4110,6 +4129,7 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
>  				  unsigned int micmute_mask)
>  {
>  	struct alc_spec *spec = codec->spec;
> +	int err;
>  
>  	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
>  
> @@ -4122,6 +4142,11 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
>  	if (micmute_mask) {
>  		spec->gpio_mic_led_mask = micmute_mask;
>  		snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
> +
> +		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
> +		err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
> +		if (err)
> +			codec_warn(codec, "failed to register micmute LED\n");
>  	}
>  }
>  
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
@ 2020-04-30 11:26     ` Takashi Iwai
  0 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 11:26 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, open list,
	tiwai, Hui Wang, Thomas Hebb, Jian-Hong Pan,
	Michał Mirosław

On Thu, 30 Apr 2020 10:32:53 +0200,
Kai-Heng Feng wrote:
> 
> Currently DMIC controls micmute LED via "audio mute LED trigger".
> 
> However, unlike Dell and Lenovo platforms, HP platforms don't provide a
> way to control micmute LED via ACPI, it's controlled by HDA codec
> instead.
> 
> So let's register an LED class for micmute so other subsystems like DMIC
> can facilitate the codec-controlled LED.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

I guess this requires the Kconfig change to select CONFIG_LEDS_*
or make the code conditionally built.  So far the latter strategy is
taken for the code in hda_generic.c.


thanks,

Takashi

> ---
>  sound/pci/hda/patch_realtek.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index 6f164ccddde3..82eb7624bbba 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -17,6 +17,7 @@
>  #include <linux/dmi.h>
>  #include <linux/module.h>
>  #include <linux/input.h>
> +#include <linux/leds.h>
>  #include <sound/core.h>
>  #include <sound/jack.h>
>  #include <sound/hda_codec.h>
> @@ -4103,6 +4104,24 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
>  			    spec->gen.micmute_led.led_value);
>  }
>  
> +static int micmute_led_set(struct led_classdev *led_cdev,
> +			   enum led_brightness brightness)
> +{
> +	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
> +	struct alc_spec *spec = codec->spec;
> +
> +	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
> +			    spec->micmute_led_polarity, !!brightness);
> +	return 0;
> +}
> +
> +static struct led_classdev micmute_led_cdev = {
> +	.name = "hda::micmute",
> +	.max_brightness = 1,
> +	.brightness_set_blocking = micmute_led_set,
> +	.default_trigger = "audio-micmute",
> +};
> +
>  /* setup mute and mic-mute GPIO bits, add hooks appropriately */
>  static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
>  				  int action,
> @@ -4110,6 +4129,7 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
>  				  unsigned int micmute_mask)
>  {
>  	struct alc_spec *spec = codec->spec;
> +	int err;
>  
>  	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
>  
> @@ -4122,6 +4142,11 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
>  	if (micmute_mask) {
>  		spec->gpio_mic_led_mask = micmute_mask;
>  		snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
> +
> +		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
> +		err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
> +		if (err)
> +			codec_warn(codec, "failed to register micmute LED\n");
>  	}
>  }
>  
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v2 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
  2020-04-30  8:32   ` Kai-Heng Feng
@ 2020-04-30 13:52     ` Kai-Heng Feng
  -1 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30 13:52 UTC (permalink / raw)
  To: tiwai
  Cc: Kai-Heng Feng, Jaroslav Kysela, Kailang Yang, Hui Wang,
	Jian-Hong Pan, Tomas Espeleta, Thomas Hebb,
	Michał Mirosław, moderated list:SOUND, open list

Currently DMIC controls micmute LED via "audio mute LED trigger".

However, unlike Dell and Lenovo platforms, HP platforms don't provide a
way to control micmute LED via ACPI, it's controlled by HDA codec
instead.

So let's register an LED class for micmute so other subsystems like DMIC
can facilitate the codec-controlled LED.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Only compile the code when CONFIG_LEDS_TRIGGER_AUDIO is reachable.

 sound/pci/hda/patch_realtek.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6f164ccddde3..eae672cb6118 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -17,6 +17,7 @@
 #include <linux/dmi.h>
 #include <linux/module.h>
 #include <linux/input.h>
+#include <linux/leds.h>
 #include <sound/core.h>
 #include <sound/jack.h>
 #include <sound/hda_codec.h>
@@ -4103,6 +4104,26 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
 			    spec->gen.micmute_led.led_value);
 }
 
+#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
+static int micmute_led_set(struct led_classdev *led_cdev,
+			   enum led_brightness brightness)
+{
+	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
+	struct alc_spec *spec = codec->spec;
+
+	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
+			    spec->micmute_led_polarity, !!brightness);
+	return 0;
+}
+
+static struct led_classdev micmute_led_cdev = {
+	.name = "hda::micmute",
+	.max_brightness = 1,
+	.brightness_set_blocking = micmute_led_set,
+	.default_trigger = "audio-micmute",
+};
+#endif
+
 /* setup mute and mic-mute GPIO bits, add hooks appropriately */
 static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  int action,
@@ -4110,6 +4131,7 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  unsigned int micmute_mask)
 {
 	struct alc_spec *spec = codec->spec;
+	int err;
 
 	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
 
@@ -4122,6 +4144,13 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 	if (micmute_mask) {
 		spec->gpio_mic_led_mask = micmute_mask;
 		snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
+
+#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
+		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
+		err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
+		if (err)
+			codec_warn(codec, "failed to register micmute LED\n");
+#endif
 	}
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v2 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
@ 2020-04-30 13:52     ` Kai-Heng Feng
  0 siblings, 0 replies; 17+ messages in thread
From: Kai-Heng Feng @ 2020-04-30 13:52 UTC (permalink / raw)
  To: tiwai
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, Thomas Hebb,
	open list, Hui Wang, Kai-Heng Feng, Jian-Hong Pan,
	Michał Mirosław

Currently DMIC controls micmute LED via "audio mute LED trigger".

However, unlike Dell and Lenovo platforms, HP platforms don't provide a
way to control micmute LED via ACPI, it's controlled by HDA codec
instead.

So let's register an LED class for micmute so other subsystems like DMIC
can facilitate the codec-controlled LED.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Only compile the code when CONFIG_LEDS_TRIGGER_AUDIO is reachable.

 sound/pci/hda/patch_realtek.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6f164ccddde3..eae672cb6118 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -17,6 +17,7 @@
 #include <linux/dmi.h>
 #include <linux/module.h>
 #include <linux/input.h>
+#include <linux/leds.h>
 #include <sound/core.h>
 #include <sound/jack.h>
 #include <sound/hda_codec.h>
@@ -4103,6 +4104,26 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
 			    spec->gen.micmute_led.led_value);
 }
 
+#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
+static int micmute_led_set(struct led_classdev *led_cdev,
+			   enum led_brightness brightness)
+{
+	struct hda_codec *codec = dev_to_hda_codec(led_cdev->dev->parent);
+	struct alc_spec *spec = codec->spec;
+
+	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
+			    spec->micmute_led_polarity, !!brightness);
+	return 0;
+}
+
+static struct led_classdev micmute_led_cdev = {
+	.name = "hda::micmute",
+	.max_brightness = 1,
+	.brightness_set_blocking = micmute_led_set,
+	.default_trigger = "audio-micmute",
+};
+#endif
+
 /* setup mute and mic-mute GPIO bits, add hooks appropriately */
 static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  int action,
@@ -4110,6 +4131,7 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  unsigned int micmute_mask)
 {
 	struct alc_spec *spec = codec->spec;
+	int err;
 
 	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
 
@@ -4122,6 +4144,13 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 	if (micmute_mask) {
 		spec->gpio_mic_led_mask = micmute_mask;
 		snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
+
+#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
+		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
+		err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
+		if (err)
+			codec_warn(codec, "failed to register micmute LED\n");
+#endif
 	}
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO
  2020-04-30  8:32 ` Kai-Heng Feng
@ 2020-04-30 17:21   ` Takashi Iwai
  -1 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 17:21 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: tiwai, Jaroslav Kysela, Kailang Yang, Hui Wang, Jian-Hong Pan,
	Tomas Espeleta, Thomas Hebb, Michał Mirosław,
	moderated list:SOUND, open list

On Thu, 30 Apr 2020 10:32:51 +0200,
Kai-Heng Feng wrote:
> 
> Currently mute LED and micmute LED share the same GPIO polarity.
> 
> So split the polarity for mute and micmute, in case they have different
> polarities.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/3] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO
@ 2020-04-30 17:21   ` Takashi Iwai
  0 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 17:21 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, open list,
	tiwai, Hui Wang, Thomas Hebb, Jian-Hong Pan,
	Michał Mirosław

On Thu, 30 Apr 2020 10:32:51 +0200,
Kai-Heng Feng wrote:
> 
> Currently mute LED and micmute LED share the same GPIO polarity.
> 
> So split the polarity for mute and micmute, in case they have different
> polarities.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] ALSA: hda/realtek - Enable micmute LED on and HP system
  2020-04-30  8:32   ` Kai-Heng Feng
@ 2020-04-30 17:22     ` Takashi Iwai
  -1 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 17:22 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: tiwai, Jaroslav Kysela, Kailang Yang, Hui Wang, Jian-Hong Pan,
	Tomas Espeleta, Thomas Hebb, Michał Mirosław,
	moderated list:SOUND, open list

On Thu, 30 Apr 2020 10:32:52 +0200,
Kai-Heng Feng wrote:
> 
> Though the system uses DMIC, headset mic still uses the HDA, let's use
> GPIO 0x1 to control the micmute LED.
> 
> The micmute LED GPIO has a different polarity to the mute LED GPIO, we
> can use the newly added micmute_led_polarity to indicate that.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] ALSA: hda/realtek - Enable micmute LED on and HP system
@ 2020-04-30 17:22     ` Takashi Iwai
  0 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 17:22 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, open list,
	tiwai, Hui Wang, Thomas Hebb, Jian-Hong Pan,
	Michał Mirosław

On Thu, 30 Apr 2020 10:32:52 +0200,
Kai-Heng Feng wrote:
> 
> Though the system uses DMIC, headset mic still uses the HDA, let's use
> GPIO 0x1 to control the micmute LED.
> 
> The micmute LED GPIO has a different polarity to the mute LED GPIO, we
> can use the newly added micmute_led_polarity to indicate that.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
  2020-04-30 13:52     ` Kai-Heng Feng
@ 2020-04-30 17:22       ` Takashi Iwai
  -1 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 17:22 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: tiwai, Jaroslav Kysela, Kailang Yang, Hui Wang, Jian-Hong Pan,
	Tomas Espeleta, Thomas Hebb, Michał Mirosław,
	moderated list:SOUND, open list

On Thu, 30 Apr 2020 15:52:07 +0200,
Kai-Heng Feng wrote:
> 
> Currently DMIC controls micmute LED via "audio mute LED trigger".
> 
> However, unlike Dell and Lenovo platforms, HP platforms don't provide a
> way to control micmute LED via ACPI, it's controlled by HDA codec
> instead.
> 
> So let's register an LED class for micmute so other subsystems like DMIC
> can facilitate the codec-controlled LED.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v2:
>  - Only compile the code when CONFIG_LEDS_TRIGGER_AUDIO is reachable.

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v2 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
@ 2020-04-30 17:22       ` Takashi Iwai
  0 siblings, 0 replies; 17+ messages in thread
From: Takashi Iwai @ 2020-04-30 17:22 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: moderated list:SOUND, Kailang Yang, Tomas Espeleta, open list,
	tiwai, Hui Wang, Thomas Hebb, Jian-Hong Pan,
	Michał Mirosław

On Thu, 30 Apr 2020 15:52:07 +0200,
Kai-Heng Feng wrote:
> 
> Currently DMIC controls micmute LED via "audio mute LED trigger".
> 
> However, unlike Dell and Lenovo platforms, HP platforms don't provide a
> way to control micmute LED via ACPI, it's controlled by HDA codec
> instead.
> 
> So let's register an LED class for micmute so other subsystems like DMIC
> can facilitate the codec-controlled LED.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v2:
>  - Only compile the code when CONFIG_LEDS_TRIGGER_AUDIO is reachable.

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] ALSA: hda/realtek - Add LED class support for micmute LED
  2020-04-30  8:32   ` Kai-Heng Feng
                     ` (2 preceding siblings ...)
  (?)
@ 2020-05-01  8:11   ` kbuild test robot
  -1 siblings, 0 replies; 17+ messages in thread
From: kbuild test robot @ 2020-05-01  8:11 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2537 bytes --]

Hi Kai-Heng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on sound/for-next]
[also build test ERROR on v5.7-rc3 next-20200430]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Kai-Heng-Feng/ALSA-hda-realtek-Introduce-polarity-for-micmute-LED-GPIO/20200430-191811
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: i386-randconfig-e002-20200430 (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   ld: sound/pci/hda/patch_realtek.o: in function `alc_fixup_hp_gpio_led':
>> sound/pci/hda/patch_realtek.c:4146: undefined reference to `ledtrig_audio_get'
   ld: sound/pci/hda/patch_realtek.o: in function `devm_led_classdev_register':
>> include/linux/leds.h:193: undefined reference to `devm_led_classdev_register_ext'

vim +4146 sound/pci/hda/patch_realtek.c

  4124	
  4125	/* setup mute and mic-mute GPIO bits, add hooks appropriately */
  4126	static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
  4127					  int action,
  4128					  unsigned int mute_mask,
  4129					  unsigned int micmute_mask)
  4130	{
  4131		struct alc_spec *spec = codec->spec;
  4132		int err;
  4133	
  4134		alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
  4135	
  4136		if (action != HDA_FIXUP_ACT_PRE_PROBE)
  4137			return;
  4138		if (mute_mask) {
  4139			spec->gpio_mute_led_mask = mute_mask;
  4140			spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
  4141		}
  4142		if (micmute_mask) {
  4143			spec->gpio_mic_led_mask = micmute_mask;
  4144			snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
  4145	
> 4146			micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
  4147			err = devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev);
  4148			if (err)
  4149				codec_warn(codec, "failed to register micmute LED\n");
  4150		}
  4151	}
  4152	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 34763 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-05-01  8:11 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-30  8:32 [PATCH 1/3] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO Kai-Heng Feng
2020-04-30  8:32 ` Kai-Heng Feng
2020-04-30  8:32 ` [PATCH 2/3] ALSA: hda/realtek - Enable micmute LED on and HP system Kai-Heng Feng
2020-04-30  8:32   ` Kai-Heng Feng
2020-04-30 17:22   ` Takashi Iwai
2020-04-30 17:22     ` Takashi Iwai
2020-04-30  8:32 ` [PATCH 3/3] ALSA: hda/realtek - Add LED class support for micmute LED Kai-Heng Feng
2020-04-30  8:32   ` Kai-Heng Feng
2020-04-30 11:26   ` Takashi Iwai
2020-04-30 11:26     ` Takashi Iwai
2020-04-30 13:52   ` [PATCH v2 " Kai-Heng Feng
2020-04-30 13:52     ` Kai-Heng Feng
2020-04-30 17:22     ` Takashi Iwai
2020-04-30 17:22       ` Takashi Iwai
2020-05-01  8:11   ` [PATCH " kbuild test robot
2020-04-30 17:21 ` [PATCH 1/3] ALSA: hda/realtek - Introduce polarity for micmute LED GPIO Takashi Iwai
2020-04-30 17:21   ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.