All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda/cs8409: Set PMSG_ON earlier inside cs8409 driver
@ 2021-11-28 11:55 ` Vitaly Rodionov
  0 siblings, 0 replies; 4+ messages in thread
From: Vitaly Rodionov @ 2021-11-28 11:55 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela, Stefan Binding, Vitaly Rodionov,
	Lucas Tanure
  Cc: patches, alsa-devel, linux-kernel

From: Stefan Binding <sbinding@opensource.cirrus.com>

For cs8409, it is required to run Jack Detect on resume.
Jack Detect on cs8409+cs42l42 requires an interrupt from
cs42l42 to be sent to cs8409 which is propogated to the driver
via an unsolicited event.
However, the hda_codec drops unsolicited events if the power_state
is not set to PMSG_ON. Which is set at the end of the resume call.
This means there is a race condition between setting power_state
to PMSG_ON and receiving the interrupt.
To solve this, we can add an API to set the power_state earlier
and call that before we start Jack Detect.
This does not cause issues, since we know inside our driver that
we are already initialized, and ready to handle the unsolicited
events.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
---
 sound/pci/hda/hda_local.h    | 8 ++++++++
 sound/pci/hda/patch_cs8409.c | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 4662a47add7e..96f78daf90f0 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -439,6 +439,14 @@ int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
 #define for_each_hda_codec_node(nid, codec) \
 	for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
 
+/* Set the codec power_state flag to indicate to allow unsol event handling;
+ * see hda_codec_unsol_event() in hda_bind.c.  Calling this might confuse the
+ * state tracking, so use with care.
+ */
+static inline void snd_hda_codec_allow_unsol_events(struct hda_codec *codec) {
+	codec->core.dev.power.power_state = PMSG_ON;
+}
+
 /*
  * get widget capabilities
  */
diff --git a/sound/pci/hda/patch_cs8409.c b/sound/pci/hda/patch_cs8409.c
index 31ff11ab868e..039b9f2f8e94 100644
--- a/sound/pci/hda/patch_cs8409.c
+++ b/sound/pci/hda/patch_cs8409.c
@@ -750,6 +750,11 @@ static void cs42l42_resume(struct sub_codec *cs42l42)
 	if (cs42l42->full_scale_vol)
 		cs8409_i2c_write(cs42l42, 0x2001, 0x01);
 
+	/* we have to explicitly allow unsol event handling even during the
+	 * resume phase so that the jack event is processed properly
+	 */
+	snd_hda_codec_allow_unsol_events(cs42l42->codec);
+
 	cs42l42_enable_jack_detect(cs42l42);
 }
 
-- 
2.25.1


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

* [PATCH] ALSA: hda/cs8409: Set PMSG_ON earlier inside cs8409 driver
@ 2021-11-28 11:55 ` Vitaly Rodionov
  0 siblings, 0 replies; 4+ messages in thread
From: Vitaly Rodionov @ 2021-11-28 11:55 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela, Stefan Binding, Vitaly Rodionov,
	Lucas Tanure
  Cc: alsa-devel, patches, linux-kernel

From: Stefan Binding <sbinding@opensource.cirrus.com>

For cs8409, it is required to run Jack Detect on resume.
Jack Detect on cs8409+cs42l42 requires an interrupt from
cs42l42 to be sent to cs8409 which is propogated to the driver
via an unsolicited event.
However, the hda_codec drops unsolicited events if the power_state
is not set to PMSG_ON. Which is set at the end of the resume call.
This means there is a race condition between setting power_state
to PMSG_ON and receiving the interrupt.
To solve this, we can add an API to set the power_state earlier
and call that before we start Jack Detect.
This does not cause issues, since we know inside our driver that
we are already initialized, and ready to handle the unsolicited
events.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
---
 sound/pci/hda/hda_local.h    | 8 ++++++++
 sound/pci/hda/patch_cs8409.c | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 4662a47add7e..96f78daf90f0 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -439,6 +439,14 @@ int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
 #define for_each_hda_codec_node(nid, codec) \
 	for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
 
+/* Set the codec power_state flag to indicate to allow unsol event handling;
+ * see hda_codec_unsol_event() in hda_bind.c.  Calling this might confuse the
+ * state tracking, so use with care.
+ */
+static inline void snd_hda_codec_allow_unsol_events(struct hda_codec *codec) {
+	codec->core.dev.power.power_state = PMSG_ON;
+}
+
 /*
  * get widget capabilities
  */
diff --git a/sound/pci/hda/patch_cs8409.c b/sound/pci/hda/patch_cs8409.c
index 31ff11ab868e..039b9f2f8e94 100644
--- a/sound/pci/hda/patch_cs8409.c
+++ b/sound/pci/hda/patch_cs8409.c
@@ -750,6 +750,11 @@ static void cs42l42_resume(struct sub_codec *cs42l42)
 	if (cs42l42->full_scale_vol)
 		cs8409_i2c_write(cs42l42, 0x2001, 0x01);
 
+	/* we have to explicitly allow unsol event handling even during the
+	 * resume phase so that the jack event is processed properly
+	 */
+	snd_hda_codec_allow_unsol_events(cs42l42->codec);
+
 	cs42l42_enable_jack_detect(cs42l42);
 }
 
-- 
2.25.1


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

* Re: [PATCH] ALSA: hda/cs8409: Set PMSG_ON earlier inside cs8409 driver
  2021-11-28 11:55 ` Vitaly Rodionov
@ 2021-11-29  8:36   ` Takashi Iwai
  -1 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-11-29  8:36 UTC (permalink / raw)
  To: Vitaly Rodionov
  Cc: Takashi Iwai, Jaroslav Kysela, Stefan Binding, Lucas Tanure,
	alsa-devel, patches, linux-kernel

On Sun, 28 Nov 2021 12:55:58 +0100,
Vitaly Rodionov wrote:
> 
> From: Stefan Binding <sbinding@opensource.cirrus.com>
> 
> For cs8409, it is required to run Jack Detect on resume.
> Jack Detect on cs8409+cs42l42 requires an interrupt from
> cs42l42 to be sent to cs8409 which is propogated to the driver
> via an unsolicited event.
> However, the hda_codec drops unsolicited events if the power_state
> is not set to PMSG_ON. Which is set at the end of the resume call.
> This means there is a race condition between setting power_state
> to PMSG_ON and receiving the interrupt.
> To solve this, we can add an API to set the power_state earlier
> and call that before we start Jack Detect.
> This does not cause issues, since we know inside our driver that
> we are already initialized, and ready to handle the unsolicited
> events.
> 
> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
> Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>

Applied now with a minor coding style fix (and addition of
Cc-to-stable).


thanks,

Takashi

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

* Re: [PATCH] ALSA: hda/cs8409: Set PMSG_ON earlier inside cs8409 driver
@ 2021-11-29  8:36   ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-11-29  8:36 UTC (permalink / raw)
  To: Vitaly Rodionov
  Cc: Stefan Binding, Lucas Tanure, patches, alsa-devel, Takashi Iwai,
	linux-kernel

On Sun, 28 Nov 2021 12:55:58 +0100,
Vitaly Rodionov wrote:
> 
> From: Stefan Binding <sbinding@opensource.cirrus.com>
> 
> For cs8409, it is required to run Jack Detect on resume.
> Jack Detect on cs8409+cs42l42 requires an interrupt from
> cs42l42 to be sent to cs8409 which is propogated to the driver
> via an unsolicited event.
> However, the hda_codec drops unsolicited events if the power_state
> is not set to PMSG_ON. Which is set at the end of the resume call.
> This means there is a race condition between setting power_state
> to PMSG_ON and receiving the interrupt.
> To solve this, we can add an API to set the power_state earlier
> and call that before we start Jack Detect.
> This does not cause issues, since we know inside our driver that
> we are already initialized, and ready to handle the unsolicited
> events.
> 
> Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
> Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>

Applied now with a minor coding style fix (and addition of
Cc-to-stable).


thanks,

Takashi

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

end of thread, other threads:[~2021-11-29  8:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-28 11:55 [PATCH] ALSA: hda/cs8409: Set PMSG_ON earlier inside cs8409 driver Vitaly Rodionov
2021-11-28 11:55 ` Vitaly Rodionov
2021-11-29  8:36 ` Takashi Iwai
2021-11-29  8:36   ` 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.