2024-04-08 06:17:21

by Bard Liao

[permalink] [raw]
Subject: [PATCH 0/2] soundwire: intel_ace2x: fix wakeup handling for LunarLake

For LunarLake, the SoundWire in-band wake detection is reported with
the HDAudio WAKE_EN/WAKE_STS registers.

Pierre-Louis Bossart (2):
soundwire: intel_ace2x: fix wakeup handling
soundwire: intel_ace2x: simplify check_wake()

drivers/soundwire/intel_ace2x.c | 43 +++++++++++++++++++++------------
1 file changed, 27 insertions(+), 16 deletions(-)

--
2.34.1



2024-04-08 06:17:46

by Bard Liao

[permalink] [raw]
Subject: [PATCH 2/2] soundwire: intel_ace2x: simplify check_wake()

From: Pierre-Louis Bossart <[email protected]>

Since LunarLake, we use the HDadio WAKEEN/WAKESTS to detect wakes for
SoundWire codecs. This patch follows the HDaudio example and
simplifies the behavior on wake-up by unconditionally waking up all
links.

This behavior makes a lot of sense when removing the jack, which may
signal that the user wants to start rendering audio using the local
amplifiers. Resuming all links helps make sure the amplifiers are
ready to be used. Worst case, the pm_runtime suspend would kick-in
after several seconds of inactivity.

Closes: https://github.com/thesofproject/linux/issues/4687
Co-developed-by: Bard Liao <[email protected]>
Signed-off-by: Bard Liao <[email protected]>
Signed-off-by: Pierre-Louis Bossart <[email protected]>
Reviewed-by: Keqiao Zhang <[email protected]>
---
drivers/soundwire/intel_ace2x.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c
index f26d4e5c2c7a..4910cab22273 100644
--- a/drivers/soundwire/intel_ace2x.c
+++ b/drivers/soundwire/intel_ace2x.c
@@ -51,22 +51,12 @@ static void intel_shim_vs_set_clock_source(struct sdw_intel *sdw, u32 source)

static int intel_shim_check_wake(struct sdw_intel *sdw)
{
- u16 lsdiid = 0;
- u16 wake_sts;
- int ret;
-
- /* find out which bits are set in LSDIID for this sublink */
- ret = hdac_bus_eml_sdw_get_lsdiid_unlocked(sdw->link_res->hbus, sdw->instance, &lsdiid);
- if (ret < 0)
- return ret;
-
/*
- * we need to use the global HDaudio WAKEEN/STS to be able to detect
- * wakes in low-power modes
+ * We follow the HDaudio example and resume unconditionally
+ * without checking the WAKESTS bit for that specific link
*/
- wake_sts = snd_hdac_chip_readw(sdw->link_res->hbus, STATESTS);

- return wake_sts & lsdiid;
+ return 1;
}

static void intel_shim_wake(struct sdw_intel *sdw, bool wake_enable)
--
2.34.1


2024-04-08 09:28:07

by Bard Liao

[permalink] [raw]
Subject: [PATCH 1/2] soundwire: intel_ace2x: fix wakeup handling

From: Pierre-Louis Bossart <[email protected]>

The initial programming sequence only worked in the case where the
OFLEN bit is set, i.e. the DSP handles the SoundWire interface. In the
Linux integration, the interface is owned by the host. This disconnect
leads to wake-ups being routed to the DSP and not to the host.

The suggested update is to rely on the global HDAudio WAKEEN/STATESTS
registers, with the SDI bits used to program the wakeups and check the
status.

Note that there is no way to know which peripheral generated a
wake-up. When the hardware detects a change, it sets all the bits
corresponding to LSDIIDx. The LSDIIDx information can be used to
figure out on which link the wakeup happened, but for further details
the software will have to check the status of each peripheral.

Signed-off-by: Pierre-Louis Bossart <[email protected]>
Reviewed-by: Rander Wang <[email protected]>
Signed-off-by: Bard Liao <[email protected]>
---
drivers/soundwire/intel_ace2x.c | 49 +++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 14 deletions(-)

diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c
index 43a348db83bf..f26d4e5c2c7a 100644
--- a/drivers/soundwire/intel_ace2x.c
+++ b/drivers/soundwire/intel_ace2x.c
@@ -10,8 +10,10 @@
#include <linux/soundwire/sdw_registers.h>
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_intel.h>
-#include <sound/pcm_params.h>
+#include <sound/hdaudio.h>
#include <sound/hda-mlink.h>
+#include <sound/hda_register.h>
+#include <sound/pcm_params.h>
#include "cadence_master.h"
#include "bus.h"
#include "intel.h"
@@ -49,37 +51,56 @@ static void intel_shim_vs_set_clock_source(struct sdw_intel *sdw, u32 source)

static int intel_shim_check_wake(struct sdw_intel *sdw)
{
- void __iomem *shim_vs;
+ u16 lsdiid = 0;
u16 wake_sts;
+ int ret;

- shim_vs = sdw->link_res->shim_vs;
- wake_sts = intel_readw(shim_vs, SDW_SHIM2_INTEL_VS_WAKESTS);
+ /* find out which bits are set in LSDIID for this sublink */
+ ret = hdac_bus_eml_sdw_get_lsdiid_unlocked(sdw->link_res->hbus, sdw->instance, &lsdiid);
+ if (ret < 0)
+ return ret;

- return wake_sts & SDW_SHIM2_INTEL_VS_WAKEEN_PWS;
+ /*
+ * we need to use the global HDaudio WAKEEN/STS to be able to detect
+ * wakes in low-power modes
+ */
+ wake_sts = snd_hdac_chip_readw(sdw->link_res->hbus, STATESTS);
+
+ return wake_sts & lsdiid;
}

static void intel_shim_wake(struct sdw_intel *sdw, bool wake_enable)
{
- void __iomem *shim_vs = sdw->link_res->shim_vs;
+ u16 lsdiid = 0;
u16 wake_en;
u16 wake_sts;
+ int ret;

- wake_en = intel_readw(shim_vs, SDW_SHIM2_INTEL_VS_WAKEEN);
+ mutex_lock(sdw->link_res->shim_lock);
+
+ ret = hdac_bus_eml_sdw_get_lsdiid_unlocked(sdw->link_res->hbus, sdw->instance, &lsdiid);
+ if (ret < 0)
+ goto unlock;
+
+ wake_en = snd_hdac_chip_readw(sdw->link_res->hbus, WAKEEN);

if (wake_enable) {
/* Enable the wakeup */
- wake_en |= SDW_SHIM2_INTEL_VS_WAKEEN_PWE;
- intel_writew(shim_vs, SDW_SHIM2_INTEL_VS_WAKEEN, wake_en);
+ wake_en |= lsdiid;
+
+ snd_hdac_chip_writew(sdw->link_res->hbus, WAKEEN, wake_en);
} else {
/* Disable the wake up interrupt */
- wake_en &= ~SDW_SHIM2_INTEL_VS_WAKEEN_PWE;
- intel_writew(shim_vs, SDW_SHIM2_INTEL_VS_WAKEEN, wake_en);
+ wake_en &= ~lsdiid;
+ snd_hdac_chip_writew(sdw->link_res->hbus, WAKEEN, wake_en);

/* Clear wake status (W1C) */
- wake_sts = intel_readw(shim_vs, SDW_SHIM2_INTEL_VS_WAKESTS);
- wake_sts |= SDW_SHIM2_INTEL_VS_WAKEEN_PWS;
- intel_writew(shim_vs, SDW_SHIM2_INTEL_VS_WAKESTS, wake_sts);
+ wake_sts = snd_hdac_chip_readw(sdw->link_res->hbus, STATESTS);
+ wake_sts |= lsdiid;
+ snd_hdac_chip_writew(sdw->link_res->hbus, STATESTS, wake_sts);
}
+unlock:
+ mutex_unlock(sdw->link_res->shim_lock);
}

static int intel_link_power_up(struct sdw_intel *sdw)
--
2.34.1