mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda/realtek: Serialize setting GPIO LED
@ 2020-07-01  5:21 Kai-Heng Feng
  2020-07-01  6:46 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Kai-Heng Feng @ 2020-07-01  5:21 UTC (permalink / raw)
  To: tiwai
  Cc: anthony.won, Kai-Heng Feng, Jaroslav Kysela, Libin Yang,
	Kai Vehmanen, Gustavo A. R. Silva, Ranjani Sridharan,
	Pierre-Louis Bossart, Kailang Yang, Hui Wang, Jian-Hong Pan,
	Tomas Espeleta, Thomas Hebb, Michał Mirosław,
	moderated list:SOUND, open list

If a system has two GPIO controlled LED, one for mute and another one
for micmute, and both of them are on before system suspend, sometimes
one of them won't be turned off by system suspend.

The codec doesn't seem to be able to control multiple GPIO LEDs at the
same time, so introduce a new mutex to serialize setting the LED, to
prevent the issue from happening.

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

diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
index d16a4229209b..3a1792bbb7ac 100644
--- a/include/sound/hda_codec.h
+++ b/include/sound/hda_codec.h
@@ -206,6 +206,7 @@ struct hda_codec {
 
 	struct mutex spdif_mutex;
 	struct mutex control_mutex;
+	struct mutex led_mutex;
 	struct snd_array spdif_out;
 	unsigned int spdif_in_enable;	/* SPDIF input enable? */
 	const hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 7e3ae4534df9..ec477cd8afed 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -946,6 +946,7 @@ int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card,
 	codec->addr = codec_addr;
 	mutex_init(&codec->spdif_mutex);
 	mutex_init(&codec->control_mutex);
+	mutex_init(&codec->led_mutex);
 	snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
 	snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
 	snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 53e0eef8b042..96dac365fbb8 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4101,7 +4101,10 @@ static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask,
 {
 	if (polarity)
 		enabled = !enabled;
+
+	mutex_lock(&codec->led_mutex);
 	alc_update_gpio_data(codec, mask, !enabled); /* muted -> LED on */
+	mutex_unlock(&codec->led_mutex);
 }
 
 /* turn on/off mute LED via GPIO per vmaster hook */
-- 
2.17.1


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

* Re: [PATCH] ALSA: hda/realtek: Serialize setting GPIO LED
  2020-07-01  5:21 [PATCH] ALSA: hda/realtek: Serialize setting GPIO LED Kai-Heng Feng
@ 2020-07-01  6:46 ` Takashi Iwai
  2020-07-01  8:00   ` Kai-Heng Feng
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2020-07-01  6:46 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: tiwai, anthony.won, Jaroslav Kysela, Libin Yang, Kai Vehmanen,
	Gustavo A. R. Silva, Ranjani Sridharan, Pierre-Louis Bossart,
	Kailang Yang, Hui Wang, Jian-Hong Pan, Tomas Espeleta,
	Thomas Hebb, Michał Mirosław, moderated list:SOUND,
	open list

On Wed, 01 Jul 2020 07:21:35 +0200,
Kai-Heng Feng wrote:
> 
> If a system has two GPIO controlled LED, one for mute and another one
> for micmute, and both of them are on before system suspend, sometimes
> one of them won't be turned off by system suspend.
> 
> The codec doesn't seem to be able to control multiple GPIO LEDs at the
> same time, so introduce a new mutex to serialize setting the LED, to
> prevent the issue from happening.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>  include/sound/hda_codec.h     | 1 +
>  sound/pci/hda/hda_codec.c     | 1 +
>  sound/pci/hda/patch_realtek.c | 3 +++
>  3 files changed, 5 insertions(+)
> 
> diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
> index d16a4229209b..3a1792bbb7ac 100644
> --- a/include/sound/hda_codec.h
> +++ b/include/sound/hda_codec.h
> @@ -206,6 +206,7 @@ struct hda_codec {
>  
>  	struct mutex spdif_mutex;
>  	struct mutex control_mutex;
> +	struct mutex led_mutex;

Since it's only for Realtek codec, can it be better in alc_spec
instead?


thanks,

Takashi

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

* Re: [PATCH] ALSA: hda/realtek: Serialize setting GPIO LED
  2020-07-01  6:46 ` Takashi Iwai
@ 2020-07-01  8:00   ` Kai-Heng Feng
  0 siblings, 0 replies; 3+ messages in thread
From: Kai-Heng Feng @ 2020-07-01  8:00 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: tiwai, anthony.won, Jaroslav Kysela, Libin Yang, Kai Vehmanen,
	Gustavo A. R. Silva, Ranjani Sridharan, Pierre-Louis Bossart,
	Kailang Yang, Hui Wang, Jian-Hong Pan, Tomas Espeleta,
	Thomas Hebb, Michał Mirosław, moderated list:SOUND,
	open list



> On Jul 1, 2020, at 14:46, Takashi Iwai <tiwai@suse.de> wrote:
> 
> On Wed, 01 Jul 2020 07:21:35 +0200,
> Kai-Heng Feng wrote:
>> 
>> If a system has two GPIO controlled LED, one for mute and another one
>> for micmute, and both of them are on before system suspend, sometimes
>> one of them won't be turned off by system suspend.
>> 
>> The codec doesn't seem to be able to control multiple GPIO LEDs at the
>> same time, so introduce a new mutex to serialize setting the LED, to
>> prevent the issue from happening.
>> 
>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>> ---
>> include/sound/hda_codec.h     | 1 +
>> sound/pci/hda/hda_codec.c     | 1 +
>> sound/pci/hda/patch_realtek.c | 3 +++
>> 3 files changed, 5 insertions(+)
>> 
>> diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
>> index d16a4229209b..3a1792bbb7ac 100644
>> --- a/include/sound/hda_codec.h
>> +++ b/include/sound/hda_codec.h
>> @@ -206,6 +206,7 @@ struct hda_codec {
>> 
>> 	struct mutex spdif_mutex;
>> 	struct mutex control_mutex;
>> +	struct mutex led_mutex;
> 
> Since it's only for Realtek codec, can it be better in alc_spec
> instead?

Ok, I found that the mutex just papers over the real issue.

The root cause is that led_set_brightness_nopm() use schedule_work() but the work queue doesn't gets flushed.
I'll fix it there properly.

Kai-Heng

> 
> 
> thanks,
> 
> Takashi


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01  5:21 [PATCH] ALSA: hda/realtek: Serialize setting GPIO LED Kai-Heng Feng
2020-07-01  6:46 ` Takashi Iwai
2020-07-01  8:00   ` Kai-Heng Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®