linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support
@ 2020-06-17  4:58 Kai-Heng Feng
  2020-06-17  4:58 ` [PATCH v2 2/2] ALSA: hda/realtek: Add mute LED and micmute LED support for HP systems Kai-Heng Feng
  2020-06-17  9:05 ` [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support Takashi Iwai
  0 siblings, 2 replies; 3+ messages in thread
From: Kai-Heng Feng @ 2020-06-17  4:58 UTC (permalink / raw)
  To: tiwai
  Cc: Kai-Heng Feng, Jaroslav Kysela, Hui Wang, Pierre-Louis Bossart,
	Wenwen Wang, Michał Mirosław, Kailang Yang,
	Jian-Hong Pan, Tomas Espeleta, Thomas Hebb, moderated list:SOUND,
	open list

Currently, HDA codec LED class can only used by by GPIO controlled LED.
However, there are some new systems that control LED via COEF instead of
GPIO.

In order to support those systems, create a new helper that can be
facilitated by both COEF controlled and GPIO controlled LED, and use
generic call_micmute_led_update() to control both case.

In addition to that, add LED_CORE_SUSPENDRESUME flag since some systems
don't restore the LED properly after suspend.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Prevent platforms like Dell, Lenovoe and Huawei create double LED
   class devices.

 sound/pci/hda/hda_generic.c   |  3 ++-
 sound/pci/hda/hda_generic.h   |  1 +
 sound/pci/hda/patch_realtek.c | 29 ++++++++++++++++-------------
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index f4e9d9445e18..9c3f1990c621 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -3897,7 +3897,7 @@ enum {
 	MICMUTE_LED_FOLLOW_MUTE,
 };
 
-static void call_micmute_led_update(struct hda_codec *codec)
+void call_micmute_led_update(struct hda_codec *codec)
 {
 	struct hda_gen_spec *spec = codec->spec;
 	unsigned int val;
@@ -3924,6 +3924,7 @@ static void call_micmute_led_update(struct hda_codec *codec)
 	if (spec->micmute_led.update)
 		spec->micmute_led.update(codec);
 }
+EXPORT_SYMBOL_GPL(call_micmute_led_update);
 
 static void update_micmute_led(struct hda_codec *codec,
 			       struct snd_kcontrol *kcontrol,
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index fb9f1a90238b..9f08a9ee9112 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -353,6 +353,7 @@ unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
 void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on);
 int snd_hda_gen_fix_pin_power(struct hda_codec *codec, hda_nid_t pin);
 
+void call_micmute_led_update(struct hda_codec *codec);
 int snd_hda_gen_add_micmute_led(struct hda_codec *codec,
 				void (*hook)(struct hda_codec *));
 void snd_hda_gen_fixup_micmute_led(struct hda_codec *codec,
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6d73f8beadb6..9691af8241cf 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4114,10 +4114,10 @@ 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;
+	struct hda_gen_spec *spec = codec->spec;
 
-	alc_update_gpio_led(codec, spec->gpio_mic_led_mask,
-			    spec->micmute_led_polarity, !!brightness);
+	spec->micmute_led.led_mode = !brightness;
+	call_micmute_led_update(codec);
 	return 0;
 }
 
@@ -4126,7 +4126,17 @@ static struct led_classdev micmute_led_cdev = {
 	.max_brightness = 1,
 	.brightness_set_blocking = micmute_led_set,
 	.default_trigger = "audio-micmute",
+	.flags = LED_CORE_SUSPENDRESUME,
 };
+
+static void alc_register_micmute_led(struct hda_codec *codec)
+{
+		micmute_led_cdev.brightness = ledtrig_audio_get(LED_AUDIO_MICMUTE);
+		if (devm_led_classdev_register(&codec->core.dev, &micmute_led_cdev))
+			codec_warn(codec, "failed to register micmute LED\n");
+}
+#else
+static inline void alc_register_micmute_led(struct hda_codec *codec) {}
 #endif
 
 /* setup mute and mic-mute GPIO bits, add hooks appropriately */
@@ -4136,9 +4146,6 @@ static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
 				  unsigned int micmute_mask)
 {
 	struct alc_spec *spec = codec->spec;
-#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_AUDIO)
-	int err;
-#endif
 
 	alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
 
@@ -4151,13 +4158,7 @@ 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
+		alc_register_micmute_led(codec);
 	}
 }
 
@@ -4305,6 +4306,7 @@ static void alc285_fixup_hp_coef_micmute_led(struct hda_codec *codec,
 		spec->mic_led_coefbit_on = 1<<13;
 		spec->mic_led_coefbit_off = 0;
 		snd_hda_gen_add_micmute_led(codec, alc_hp_cap_micmute_update);
+		alc_register_micmute_led(codec);
 	}
 }
 
@@ -4319,6 +4321,7 @@ static void alc236_fixup_hp_coef_micmute_led(struct hda_codec *codec,
 		spec->mic_led_coefbit_on = 2<<2;
 		spec->mic_led_coefbit_off = 1<<2;
 		snd_hda_gen_add_micmute_led(codec, alc_hp_cap_micmute_update);
+		alc_register_micmute_led(codec);
 	}
 }
 
-- 
2.17.1


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

* [PATCH v2 2/2] ALSA: hda/realtek: Add mute LED and micmute LED support for HP systems
  2020-06-17  4:58 [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support Kai-Heng Feng
@ 2020-06-17  4:58 ` Kai-Heng Feng
  2020-06-17  9:05 ` [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Kai-Heng Feng @ 2020-06-17  4:58 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

There are two more HP systems control mute LED from HDA codec and need
to expose micmute led class so SoF can control micmute LED.

Add quirks to support them.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Wording.

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

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 9691af8241cf..ff259eb9c740 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -7473,6 +7473,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
 	SND_PCI_QUIRK(0x103c, 0x83b9, "HP Spectre x360", ALC269_FIXUP_HP_MUTE_LED_MIC3),
 	SND_PCI_QUIRK(0x103c, 0x8497, "HP Envy x360", ALC269_FIXUP_HP_MUTE_LED_MIC3),
 	SND_PCI_QUIRK(0x103c, 0x84e7, "HP Pavilion 15", ALC269_FIXUP_HP_MUTE_LED_MIC3),
+	SND_PCI_QUIRK(0x103c, 0x869d, "HP", ALC236_FIXUP_HP_MUTE_LED),
+	SND_PCI_QUIRK(0x103c, 0x8729, "HP", ALC285_FIXUP_HP_GPIO_LED),
 	SND_PCI_QUIRK(0x103c, 0x8736, "HP", ALC285_FIXUP_HP_GPIO_LED),
 	SND_PCI_QUIRK(0x103c, 0x877a, "HP", ALC285_FIXUP_HP_MUTE_LED),
 	SND_PCI_QUIRK(0x103c, 0x877d, "HP", ALC236_FIXUP_HP_MUTE_LED),
-- 
2.17.1


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

* Re: [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support
  2020-06-17  4:58 [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support Kai-Heng Feng
  2020-06-17  4:58 ` [PATCH v2 2/2] ALSA: hda/realtek: Add mute LED and micmute LED support for HP systems Kai-Heng Feng
@ 2020-06-17  9:05 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2020-06-17  9:05 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: tiwai, Jaroslav Kysela, Hui Wang, Pierre-Louis Bossart,
	Wenwen Wang, Michał Mirosław, Kailang Yang,
	Jian-Hong Pan, Tomas Espeleta, Thomas Hebb, moderated list:SOUND,
	open list

On Wed, 17 Jun 2020 06:58:24 +0200,
Kai-Heng Feng wrote:
> 
> Currently, HDA codec LED class can only used by by GPIO controlled LED.

A typo and missing verb :)

> However, there are some new systems that control LED via COEF instead of
> GPIO.
> 
> In order to support those systems, create a new helper that can be
> facilitated by both COEF controlled and GPIO controlled LED, and use
> generic call_micmute_led_update() to control both case.

An exported symbol should have the proper prefix (snd_hda_gen_xxx).


thanks,

Takashi

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

end of thread, other threads:[~2020-06-17  9:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17  4:58 [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support Kai-Heng Feng
2020-06-17  4:58 ` [PATCH v2 2/2] ALSA: hda/realtek: Add mute LED and micmute LED support for HP systems Kai-Heng Feng
2020-06-17  9:05 ` [PATCH v2 1/2] ALSA: hda/realtek: Add COEF controlled micmute LED support Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).