2022-04-11 15:26:51

by Mohan Kumar

[permalink] [raw]
Subject: [PATCH 0/2] Add support for HDA Jack poll in suspend state

This series is to add HDA jack polling support to update the Jack mixer control
status properly even during runtime suspended state, as unsol event won't be
triggered during D3 state.

Mohan Kumar (2):
ALSA: hda: Jack detection poll in suspend state
ALSA: hda/tegra: Enable Jack poll for tegra

include/sound/hda_codec.h | 3 +++
sound/pci/hda/hda_codec.c | 11 ++++++++++-
sound/pci/hda/hda_tegra.c | 2 ++
3 files changed, 15 insertions(+), 1 deletion(-)

--
2.17.1


2022-04-11 22:07:05

by Mohan Kumar

[permalink] [raw]
Subject: [PATCH 2/2] ALSA: hda/tegra: Enable Jack poll for tegra

Enable HDA Jack polling for the tegra platforms as Jack detection
logic doesn't work when the HDACODEC in runtime suspended state as
unsol event won't be triggered during D3 state. This will help the
userspace audio setting controls to correctly show available audio
devices in gui.

Signed-off-by: Mohan Kumar <[email protected]>
---
sound/pci/hda/hda_tegra.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c
index 2347d0304f93..7debb2c76aa6 100644
--- a/sound/pci/hda/hda_tegra.c
+++ b/sound/pci/hda/hda_tegra.c
@@ -420,6 +420,7 @@ static int hda_tegra_create(struct snd_card *card,
chip->driver_caps = driver_caps;
chip->driver_type = driver_caps & 0xff;
chip->dev_index = 0;
+ chip->jackpoll_interval = msecs_to_jiffies(5000);
INIT_LIST_HEAD(&chip->pcm_list);

chip->codec_probe_mask = -1;
@@ -436,6 +437,7 @@ static int hda_tegra_create(struct snd_card *card,
chip->bus.core.sync_write = 0;
chip->bus.core.needs_damn_long_delay = 1;
chip->bus.core.aligned_mmio = 1;
+ chip->bus.jackpoll_in_suspend = 1;

err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
--
2.17.1

2022-04-11 22:09:14

by Mohan Kumar

[permalink] [raw]
Subject: [PATCH 1/2] ALSA: hda: Jack detection poll in suspend state

HDA Jack detection logic doesn't work when the HDACODEC
in runtime suspended state as unsol event won't be triggered
during D3 state. As pulseaudio server in userspace rely on the
jack mixer control status to show the audio devices in gui and
any display sink device hotplug event during D3 state will never
updates the jack status which will result in no audio device option
available in userspace settings.

The possible option available to resolve this issue is to run Jack
polling worker thread even after codec suspend state. The choice can
be made based on compromise between power saving or Jack detection in
suspend state.

Signed-off-by: Mohan Kumar <[email protected]>
---
include/sound/hda_codec.h | 3 +++
sound/pci/hda/hda_codec.c | 11 ++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
index 77426ff58338..b7be300b6b18 100644
--- a/include/sound/hda_codec.h
+++ b/include/sound/hda_codec.h
@@ -59,6 +59,9 @@ struct hda_bus {
unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
unsigned int bus_probing :1; /* during probing process */
unsigned int keep_power:1; /* keep power up for notification */
+ unsigned int jackpoll_in_suspend:1; /* keep jack polling during
+ * runtime suspend
+ */

int primary_dig_out_type; /* primary digital out PCM type */
unsigned int mixer_assigned; /* codec addr for mixer name */
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 5cbac315dbe1..7579a6982f47 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -2935,7 +2935,9 @@ static int hda_codec_runtime_suspend(struct device *dev)
if (!codec->card)
return 0;

- cancel_delayed_work_sync(&codec->jackpoll_work);
+ if (!codec->bus->jackpoll_in_suspend)
+ cancel_delayed_work_sync(&codec->jackpoll_work);
+
state = hda_call_codec_suspend(codec);
if (codec->link_down_at_suspend ||
(codec_has_clkstop(codec) && codec_has_epss(codec) &&
@@ -2984,6 +2986,9 @@ static void hda_codec_pm_complete(struct device *dev)

static int hda_codec_pm_suspend(struct device *dev)
{
+ struct hda_codec *codec = dev_to_hda_codec(dev);
+
+ cancel_delayed_work_sync(&codec->jackpoll_work);
dev->power.power_state = PMSG_SUSPEND;
return pm_runtime_force_suspend(dev);
}
@@ -2996,6 +3001,9 @@ static int hda_codec_pm_resume(struct device *dev)

static int hda_codec_pm_freeze(struct device *dev)
{
+ struct hda_codec *codec = dev_to_hda_codec(dev);
+
+ cancel_delayed_work_sync(&codec->jackpoll_work);
dev->power.power_state = PMSG_FREEZE;
return pm_runtime_force_suspend(dev);
}
@@ -3038,6 +3046,7 @@ void snd_hda_codec_shutdown(struct hda_codec *codec)
if (!codec->registered)
return;

+ cancel_delayed_work_sync(&codec->jackpoll_work);
list_for_each_entry(cpcm, &codec->pcm_list_head, list)
snd_pcm_suspend_all(cpcm->pcm);

--
2.17.1

2022-04-12 21:55:53

by Takashi Iwai

[permalink] [raw]
Subject: Re: [PATCH 0/2] Add support for HDA Jack poll in suspend state

On Mon, 11 Apr 2022 09:32:08 +0200,
Mohan Kumar wrote:
>
> This series is to add HDA jack polling support to update the Jack mixer control
> status properly even during runtime suspended state, as unsol event won't be
> triggered during D3 state.
>
> Mohan Kumar (2):
> ALSA: hda: Jack detection poll in suspend state
> ALSA: hda/tegra: Enable Jack poll for tegra

Applied both patches now to for-next branch.


thanks,

Takashi