* [PATCH 1/1] ASoC: codecs: add SN622x SDCA SoundWire codec support
2026-11-30 8:12 [PATCH 0/1] ASoC: codecs: add SN622x SDCA SoundWire codec support Qianghua Wang
@ 2026-11-30 8:12 ` Qianghua Wang
2026-11-30 8:37 ` sashiko-bot
` (2 more replies)
2026-11-30 12:00 ` [PATCH 0/1] " Mark Brown
1 sibling, 3 replies; 6+ messages in thread
From: Qianghua Wang @ 2026-11-30 8:12 UTC (permalink / raw)
To: Mark Brown
Cc: linux-sound, alsa-devel, Liam Girdwood, Jaroslav Kysela,
Takashi Iwai, Cezary Rojewski, Peter Ujfalusi, Bard Liao,
Kai Vehmanen, Pierre-Louis Bossart, bo liu, Qianghua Wang
Add the snd-soc-sn622x-sdca driver for Senary SN6220 and SN6224 SDCA
devices on SoundWire (speaker amplifier + DMIC; no headset jack; HP/SPK
mux is board-level).
- codec_info and DAPM hooks in sdw_utils (part_id 0x184c/0x6220 and
0x1850/0x6224; same dual-encoding model as field SN624x boards).
- Panther Lake and Nova Lake ACPI SoundWire machine tables using dummy
topology plus function topologies (aligned with SN624x).
- Mixer control "Vendor Reg Address write 1" for tinymix (fixed 0x01 write).
Signed-off-by: Qianghua Wang <qianghua.wang@senarytech.com>
---
MAINTAINERS | 1 +
sound/soc/codecs/Kconfig | 12 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/sn622x-sdca-sdw.c | 3034 +++++++++++++++++
sound/soc/codecs/sn622x-sdca.h | 83 +
.../intel/common/soc-acpi-intel-nvl-match.c | 79 +
.../intel/common/soc-acpi-intel-ptl-match.c | 120 +
sound/soc/sdw_utils/soc_sdw_senary_sdca.c | 9 +-
sound/soc/sdw_utils/soc_sdw_utils.c | 159 +
9 files changed, 3497 insertions(+), 2 deletions(-)
create mode 100644 sound/soc/codecs/sn622x-sdca-sdw.c
create mode 100644 sound/soc/codecs/sn622x-sdca.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 93abbb315..4bdb99ce8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30952,6 +30952,7 @@ M: qianghua.wang <qianghua.wang@senarytech.com>
S: Maintained
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
F: sound/hda/codecs/senarytech.c
+F: sound/soc/codecs/sn622x*
F: sound/soc/codecs/sn624x*
F: sound/soc/sdw_utils/soc_sdw_senary*
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index ba59dabee..6664011bf 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -257,6 +257,7 @@ config SND_SOC_ALL_CODECS
imply SND_SOC_SIMPLE_MUX
imply SND_SOC_SMA1303
imply SND_SOC_SMA1307
+ imply SND_SOC_SN622X_SDCA_SDW
imply SND_SOC_SN624X_SDCA_SDW
imply SND_SOC_SPDIF
imply SND_SOC_SRC4XXX_I2C
@@ -2113,6 +2114,17 @@ config SND_SOC_SMA1307
If you are using a system with an SMA1307 amplifier connected
via I2C, enable this option.
+config SND_SOC_SN622X_SDCA_SDW
+ tristate "Senary SN622X SDCA Codec - SDW"
+ depends on SND_SOC_SDCA
+ depends on SOUNDWIRE
+ select REGMAP_SOUNDWIRE
+ select REGMAP_SOUNDWIRE_MBQ
+ help
+ SoundWire SDCA driver for Senary SN622X (e.g. SN6220, SN6224).
+ Speaker playback and DMIC capture only. Headphone plug and the
+ analog switch between speaker and headphone are done in hardware.
+
config SND_SOC_SN624X_SDCA_SDW
tristate "Senary SN624x SDCA Codec - SDW"
depends on SND_SOC_SDCA
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 3826f9e4f..6bbce032c 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -303,6 +303,7 @@ snd-soc-sigmadsp-regmap-y := sigmadsp-regmap.o
snd-soc-si476x-y := si476x.o
snd-soc-sma1303-y := sma1303.o
snd-soc-sma1307-y := sma1307.o
+snd-soc-sn622x-sdca-y := sn622x-sdca-sdw.o
snd-soc-sn624x-sdca-y := sn624x-sdca-sdw.o
snd-soc-spdif-tx-y := spdif_transmitter.o
snd-soc-spdif-rx-y := spdif_receiver.o
@@ -748,6 +749,7 @@ obj-$(CONFIG_SND_SOC_SIGMADSP_REGMAP) += snd-soc-sigmadsp-regmap.o
obj-$(CONFIG_SND_SOC_SI476X) += snd-soc-si476x.o
obj-$(CONFIG_SND_SOC_SMA1303) += snd-soc-sma1303.o
obj-$(CONFIG_SND_SOC_SMA1307) += snd-soc-sma1307.o
+obj-$(CONFIG_SND_SOC_SN622X_SDCA_SDW) += snd-soc-sn622x-sdca.o
obj-$(CONFIG_SND_SOC_SN624X_SDCA_SDW) += snd-soc-sn624x-sdca.o
obj-$(CONFIG_SND_SOC_SPDIF) += snd-soc-spdif-rx.o snd-soc-spdif-tx.o
obj-$(CONFIG_SND_SOC_SRC4XXX) += snd-soc-src4xxx.o
diff --git a/sound/soc/codecs/sn622x-sdca-sdw.c b/sound/soc/codecs/sn622x-sdca-sdw.c
new file mode 100644
index 000000000..0fcf4845e
--- /dev/null
+++ b/sound/soc/codecs/sn622x-sdca-sdw.c
@@ -0,0 +1,3034 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// sn622x-sdw-sdca.c -- Senary SN622X SDCA ALSA SoC SoundWire audio driver
+//
+// Copyright(c) 2025 Senary Semiconductor Corp.
+//
+
+#include <linux/atomic.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/find.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/jiffies.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/soundwire/sdw.h>
+#include <linux/soundwire/sdw_registers.h>
+#include <linux/soundwire/sdw_type.h>
+
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include "sn622x-sdca.h"
+
+/* Paged SCP after attach; keep short to avoid stalling io_init / diag */
+#define SN622X_PAGED_QUICK_MS 2000U
+/*
+ * Probe-time optional SDCA peek: sdw_slave -> drv->probe runs before sdw_bus_probe
+ * sets slave->probed / tail update_status; holding here for tens of seconds only
+ * delays card bring-up without helping MIPI attach (enumeration is async). Keep short.
+ */
+#define SN622X_PROBE_PAGED_MS 500U
+/*
+ * Long poll for paged SCP when dev_num may lag (resume after unattach).
+ * hw_params uses SN622X_PAGED_QUICK_MS for diag; probe uses SN622X_PROBE_PAGED_MS.
+ */
+#define SN622X_INIT_WAIT_MS 30000U
+#define SN622X_PWR_D0 0
+#define SN622X_PWR_D3 3
+#define SN622X_MUTE_ON 1
+
+/*
+ * Trace helper: load with trace=1 or:
+ * echo 1 > /sys/module/snd_soc_sn622x_sdca/parameters/trace
+ * For finer logs without trace=1, enable dynamic_debug on this file.
+ */
+static bool sn622x_trace;
+module_param_named(trace, sn622x_trace, bool, 0644);
+MODULE_PARM_DESC(trace,
+ "extra dev_info for probe / SDW status (default off)");
+
+/* Register dump in hw_params (PWR/ch/rate/vol/mute); independent of trace=1 */
+static bool sn622x_codec_diag = true;
+module_param_named(codec_diag, sn622x_codec_diag, bool, 0644);
+MODULE_PARM_DESC(codec_diag,
+ "log codec regs in hw_params (default on; echo 0 to disable spam)");
+
+static bool sn622x_mask_sdca_irqs = true;
+module_param_named(mask_sdca_irqs, sn622x_mask_sdca_irqs, bool, 0644);
+MODULE_PARM_DESC(mask_sdca_irqs,
+ "mask SDCA INTMASK1-4 (write 0); default Y per working PoC for speaker PWR/MUTE");
+
+struct sn622x_sdca_priv;
+
+static void sn622x_sdca_sdca_irq_mask_all(struct sn622x_sdca_priv *sn622x);
+#define SN622X_DBG(dev, fmt, ...) dev_dbg(dev, "sn622x: " fmt, ##__VA_ARGS__)
+#define SN622X_TRC(dev, fmt, ...) do { \
+ if (sn622x_trace) \
+ dev_info(dev, "sn622x: " fmt, ##__VA_ARGS__); \
+} while (0)
+
+/* Reg 0x2124: vendor power/mode latch; once per boot avoids dmesg spam */
+static atomic_t sn622x_power_mode_logged =
+ ATOMIC_INIT(0);
+
+static void sn622x_log_power_mode_once(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ unsigned int pm;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap)
+ return;
+ if (atomic_xchg(&sn622x_power_mode_logged, 1) != 0)
+ return;
+
+ ret = regmap_read_bypassed(sn622x->regmap, 0x00002124, &pm);
+ if (ret < 0)
+ dev_err(dev, "sn622x: power_mode read failed reg 0x2124 (%d)\n", ret);
+ else
+ dev_info(dev,
+ "sn622x: power_mode=0x%x (reg 0x2124; e.g. 0xf powered)\n",
+ pm);
+}
+
+/*
+ * Vendor/SDCA control windows (regmap 32-bit addr, 8-bit read per access).
+ * Decoding matches OEM sheet; masks may need tuning per silicon rev.
+ */
+/*
+ * SN6220 speaker path — HP/SPK mux is external to this driver.
+ * sn6220.txt swaps PDE read/write vs DMIC/sn624x jack pattern.
+ * SN6224 accepts D0/D3 only at 0x40400188 (speaker PDE write).
+ */
+#define SN622X_REG_PWR_STATE 0x40400188u /* actual: 0=D0 3=D3 */
+#define SN622X_REG_PWR_STATE_WRITE 0x40400188u /* write D0/D3 here */
+#define SN622X_REG_PWR_STATE_REQ 0x40480180u /* doc "write"; no-op on SN6224 */
+#define SN622X_REG_RATE_SEL 0x40480080u /* 1=48k 2=96k 3=192k */
+#define SN622X_REG_CH_ENABLE_A 0x00000120u
+#define SN622X_REG_CH_ENABLE_B 0x00000130u
+#define SN622X_REG_VOL_PRIM 0x40400811u
+#define SN622X_REG_VOL_SECOND 0x40402811u
+#define SN622X_REG_CHR_VOL_PRIM 0x40400812u
+#define SN622X_REG_CHR_VOL_SECOND 0x40402812u
+#define SN622X_REG_MUTE 0x40400809u
+#define SN622X_REG_RIGHT_MUTE 0x4040080au
+/* Windows Speakers play: PRIM=0x00, SECOND=0xfa (read PRIM then SECOND). */
+#define SN622X_SPK_VOL_PRIM_DEFAULT 0x00u
+#define SN622X_SPK_VOL_SECOND_DEFAULT 0xfau
+/* Right (CHR) volume — same defaults; idle often leaves SECOND=0xb0 → R silent. */
+#define SN622X_SPK_CHR_VOL_PRIM_DEFAULT 0x00u
+#define SN622X_SPK_CHR_VOL_SECOND_DEFAULT 0xfau
+
+
+
+#define SN622X_REG_SPEAKER_FUN_STATUS_CTL 0x40480000
+#define SN622X_FUN_NEEDS_INIT BIT(5)
+#define SN622X_FUN_HAS_BEEN_RESET BIT(6)
+
+#define SN622X_REG_DMIC_CAP_VOL_INT 0x40802a11u
+#define SN622X_REG_DMIC_CAP_VOL_FRAC 0x40800a11u
+#define SN622X_REG_DMIC_CAP_CHR_VOL_INT 0x40802a12u
+#define SN622X_REG_DMIC_CAP_CHR_VOL_FRAC 0x40800a12u
+#define SN622X_REG_DMIC_CAP_MUTE 0x40800a09u /* 0=unmute, 1=mute */
+#define SN622X_REG_DMIC_CAP_CHR_MUTE 0x40800a0au /* 0=unmute, 1=mute */
+#define SN622X_REG_DMIC_CAP_RATE_SEL 0x40880100u /* 1=48k 2=96k 3=192k */
+/*
+ * sn6220.txt: DMIC 读 0x40880180 / 写 0x40800188.
+ * Actual power only reaches D0 after SoundWire port 3 is transporting.
+ */
+#define SN622X_REG_DMIC_CAP_PWR_STATE 0x40880180u /* actual: 0=D0 3=D3 */
+#define SN622X_REG_DMIC_CAP_PWR_STATE_WRITE 0x40800188u /* sn6220.txt write */
+#define SN622X_REG_DMIC_CAP_CH_ENABLE_A 0x00000320u /* low bits: 0x3=both */
+#define SN622X_REG_DMIC_CAP_CH_ENABLE_B 0x00000330u
+#define SN622X_REG_DMIC_MFPU_BYPASS 0x40800408u /* func2 ent0x08 MFPU113 Bypass: 1=raw passthrough */
+#define SN622X_REG_DMIC_MFPU_ALGO_ENABLE 0x40800428u /* func2 ent0x08 MFPU113 Algorithm_Enable */
+
+#define SN622X_REG_DMIC_FUN_STATUS_CTL 0x40880000
+
+/* sdw_slave.status: 0=UNATTACHED, 1=ATTACHED, ... (include/linux/soundwire/sdw.h) */
+static const char *sn622x_slave_status_sym(enum sdw_slave_status s)
+{
+ switch (s) {
+ case SDW_SLAVE_UNATTACHED:
+ return "UNATTACHED";
+ case SDW_SLAVE_ATTACHED:
+ return "ATTACHED";
+ case SDW_SLAVE_ALERT:
+ return "ALERT";
+ case SDW_SLAVE_RESERVED:
+ return "RESERVED";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+/*
+ * SoftAmp must be ATTACHED before any paged vendor/SDCA write. Sticky
+ * dev_num alone is not enough: after UNATTACH, writes return -ENODATA and
+ * GNOME/PipeWire retry storms bus (BUSCLOCK_SCALE) until SoftAmp never
+ * reattaches.
+ */
+static bool sn622x_slave_attached(struct sdw_slave *slave)
+{
+ return slave && slave->status == SDW_SLAVE_ATTACHED;
+}
+
+/*
+ * Paged SCP needs non-zero dev_num. Never wait on initialization_complete from
+ * update_status -> io_init -> uaj_apply (that completion is signaled only after
+ * update_status returns — would deadlock). Use wait_sd_init=false there.
+ * @timeout_ms: total poll budget; SN622X_INIT_WAIT_MS for resume;
+ * SN622X_PROBE_PAGED_MS or SN622X_PAGED_QUICK_MS for probe / diag.
+ */
+static int sn622x_sdw_prepare_paged_access(struct device *dev, struct sdw_slave *slave,
+ bool wait_sd_init, unsigned int timeout_ms)
+{
+ unsigned long deadline = jiffies + msecs_to_jiffies(timeout_ms);
+
+ if (!slave)
+ return -EINVAL;
+
+ /* Fail fast when SoftAmp is off the bus — do not wait 30s. */
+ if (slave->status == SDW_SLAVE_UNATTACHED)
+ return -ENODEV;
+
+ if (slave->dev_num_sticky && !slave->dev_num) {
+ slave->dev_num = slave->dev_num_sticky;
+ SN622X_DBG(dev,
+ "sync dev_num from dev_num_sticky=%u for paged SCP\n",
+ slave->dev_num_sticky);
+ }
+
+ for (;;) {
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
+
+ if (slave->status == SDW_SLAVE_UNATTACHED)
+ return -ENODEV;
+
+ if (slave->dev_num) {
+ if (sn622x)
+ sn622x->last_dev_num = slave->dev_num;
+ return 0;
+ }
+
+ /*
+ * Do not spin while bus is servicing ALERT/DevID: codec IRQ handler
+ * must not hammer SDCA/DP0 in that window (see interrupt_callback).
+ */
+ if (slave->status == SDW_SLAVE_ALERT) {
+ if (sn622x && sn622x->last_dev_num) {
+ slave->dev_num = sn622x->last_dev_num;
+ SN622X_DBG(dev,
+ "restore dev_num=%u after ALERT for paged SCP\n",
+ sn622x->last_dev_num);
+ return 0;
+ }
+ return -EAGAIN;
+ }
+
+ if (slave->dev_num_sticky) {
+ slave->dev_num = slave->dev_num_sticky;
+ SN622X_DBG(dev,
+ "sync dev_num from dev_num_sticky=%u for paged SCP\n",
+ slave->dev_num_sticky);
+ return 0;
+ }
+ if (!time_before(jiffies, deadline))
+ break;
+ if (wait_sd_init)
+ wait_for_completion_timeout(&slave->initialization_complete,
+ msecs_to_jiffies(25));
+ wait_for_completion_timeout(&slave->enumeration_complete,
+ msecs_to_jiffies(25));
+ usleep_range(500, 1500);
+ }
+
+ dev_warn(dev,
+ "sn622x: no SDW logical dev# after %u ms (dev_num=%u dev_num_sticky=%u status=%s=%d): firmware/silicon DEVID must match for sdw_program_device_num; paged SCP then needs non-zero dev_num (else sdw_fill_msg returns -EINVAL \"Invalid device for paging\"). ACPI id: mfg=0x%04x part=0x%04x class=0x%02x unique=0x%02x sdw_version=0x%x — check dmesg: DEVID read / Assign dev_num / Slave Entry not found\n",
+ timeout_ms, slave->dev_num, slave->dev_num_sticky,
+ sn622x_slave_status_sym(slave->status), slave->status,
+ slave->id.mfg_id, slave->id.part_id, slave->id.class_id,
+ slave->id.unique_id, slave->id.sdw_version);
+ return -ENODEV;
+}
+
+static const char *sn622x_pwr_state_str(unsigned int v)
+{
+ switch (v & 0x3u) {
+ case 0:
+ return "D0";
+ case 3:
+ return "D3";
+ default:
+ return "other";
+ }
+}
+
+/*
+ * Vendor PWR latch: write 0 to SN622X_REG_PWR_STATE_WRITE to request D0.
+ * Called from io_init on first ATTACH (codec power-up).
+ */
+static int sn622x_pwr_request_d0(struct device *dev, struct sn622x_sdca_priv *sn622x)
+{
+ struct reg_sequence pw = REG_SEQ0(SN622X_REG_PWR_STATE_WRITE, 0);
+ unsigned int v;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return -ENODEV;
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, true,
+ SN622X_INIT_WAIT_MS);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: io_init: PWR D0 write skipped (paging not ready, %d)\n",
+ ret);
+ return ret;
+ }
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &pw, 1);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: io_init: PWR write 0x%x=0 failed (%d)\n",
+ SN622X_REG_PWR_STATE_WRITE, ret);
+ return ret;
+ }
+
+ usleep_range(1000, 1500);
+
+ ret = regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE, &v);
+ if (ret < 0)
+ dev_dbg(dev,
+ "sn622x: io_init: PWR state read after D0 request failed (%d)\n",
+ ret);
+ else
+ dev_warn(dev,
+ "sn622x: io_init: PWR D0 requested, power_state[0x%x]=0x%x (%s)\n",
+ SN622X_REG_PWR_STATE, v, sn622x_pwr_state_str(v));
+
+ return 0;
+}
+
+static int sn622x_speaker_pwr_request_d3(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ struct reg_sequence pw = REG_SEQ0(SN622X_REG_PWR_STATE_WRITE,
+ SN622X_PWR_D3);
+ unsigned int v = 0xff;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return -ENODEV;
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS);
+ if (ret < 0)
+ return ret;
+
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE,
+ &v) == 0 &&
+ (v & 0xffu) == SN622X_PWR_D3)
+ return 0;
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &pw, 1);
+ if (ret < 0) {
+ dev_warn(dev, "sn622x: speaker: PWR D3 write failed (%d)\n", ret);
+ return ret;
+ }
+ usleep_range(2000, 3000);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE, &v);
+ dev_info(dev,
+ "sn622x: speaker: PWR D3 for SoftMic, power_state[0x%x]=0x%x (%s)\n",
+ SN622X_REG_PWR_STATE, v, sn622x_pwr_state_str(v));
+ return (v & 0xffu) == SN622X_PWR_D3 ? 0 : -EIO;
+}
+
+static int sn622x_speaker_pwr_request_d0(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ struct reg_sequence pw = REG_SEQ0(SN622X_REG_PWR_STATE_WRITE, 0);
+ unsigned int v;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return -ENODEV;
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: speaker: PWR D0 write skipped (paging not ready, %d)\n",
+ ret);
+ return ret;
+ }
+
+ /*
+ * Rewriting PDE while it is already D0 drops the slave mid-call.
+ * 0x40480180 stays 0 across a D3 request, so it cannot be the check:
+ * SoftMic parks Speakers via 0x40400188=3 and this early-out then
+ * refused to bring them back.
+ */
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE, &v) == 0 &&
+ (v & 0xffu) == SN622X_PWR_D0)
+ return 0;
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &pw, 1);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: speaker: PWR write 0x%x=0 failed (%d)\n",
+ SN622X_REG_PWR_STATE_WRITE, ret);
+ return ret;
+ }
+
+ usleep_range(1000, 1500);
+
+ ret = regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE, &v);
+ if (ret < 0)
+ dev_dbg(dev,
+ "sn622x: speaker: PWR state read after D0 request failed (%d)\n",
+ ret);
+ else
+ dev_info(dev,
+ "sn622x: speaker: PWR D0 requested, power_state[0x%x]=0x%x (%s)\n",
+ SN622X_REG_PWR_STATE, v, sn622x_pwr_state_str(v));
+
+ return 0;
+}
+
+/*
+ * SoftAmp FUN STATUS 0x40480000: bit5=needs-init, bit6=been-reset.
+ * While set, CHEN 0x120/0x130 does not stick. Only ACK 0x61 (same as old
+ * jack path clear). Do NOT batch charge-pump here — that raced attach and
+ * knocked SoftAmp UNATTACHED (GNOME Test then hangs on -ETIMEDOUT).
+ */
+/* Returns 1 if FUN was ACKed just now. */
+static int sn622x_speaker_fun_ack_if_needed(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ struct reg_sequence clear_status =
+ REG_SEQ0(SN622X_REG_SPEAKER_FUN_STATUS_CTL, 0x61);
+ unsigned int st = 0;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return 0;
+ if (sn622x->slave->status != SDW_SLAVE_ATTACHED)
+ return 0;
+
+ ret = regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_SPEAKER_FUN_STATUS_CTL, &st);
+ if (ret < 0)
+ return 0;
+ if (!(st & (SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET)))
+ return 0;
+
+ dev_info(dev, "sn622x: SPEAKER FUN STATUS 0x%x — ACK 0x61\n", st);
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &clear_status, 1);
+ if (ret < 0) {
+ dev_warn(dev, "sn622x: SPEAKER FUN ACK failed (%d)\n", ret);
+ return 0;
+ }
+ usleep_range(1000, 1500);
+ if (regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_SPEAKER_FUN_STATUS_CTL, &st) == 0)
+ dev_info(dev, "sn622x: SPEAKER FUN STATUS after clear=0x%x\n",
+ st);
+ return 1;
+}
+
+static int sn622x_dmic_cap_pwr_request_d0(struct device *dev,
+ struct sn622x_sdca_priv *sn622x);
+
+/* Park SoftMic Cap (SoftMic-only teardown / Speakers reclaim). Unused in duplex. */
+static void __maybe_unused sn622x_softmic_cap_park(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ static const struct reg_sequence softmic_off[] = {
+ REG_SEQ0(SN622X_REG_DMIC_CAP_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CH_ENABLE_B, 0),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_PWR_STATE_WRITE, SN622X_PWR_D3),
+ };
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return;
+ if (!sn622x_slave_attached(sn622x->slave))
+ return;
+ if (sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS) < 0)
+ return;
+ regmap_multi_reg_write_bypassed(sn622x->regmap, softmic_off,
+ ARRAY_SIZE(softmic_off));
+ sn622x->dmic_route_latched = false;
+ usleep_range(1000, 1500);
+ dev_info(dev, "sn622x: SoftMic Cap parked for Speakers\n");
+}
+
+static void sn622x_speaker_playback_prepare(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ static const struct reg_sequence spk_ramp[] = {
+ REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_VOL_SECOND, SN622X_SPK_VOL_SECOND_DEFAULT),
+ REG_SEQ0(SN622X_REG_VOL_PRIM, SN622X_SPK_VOL_PRIM_DEFAULT),
+ REG_SEQ0(SN622X_REG_CHR_VOL_SECOND, SN622X_SPK_CHR_VOL_SECOND_DEFAULT),
+ REG_SEQ0(SN622X_REG_CHR_VOL_PRIM, SN622X_SPK_CHR_VOL_PRIM_DEFAULT),
+ };
+ static const struct reg_sequence spk_on[] = {
+ REG_SEQ0(SN622X_REG_MUTE, 0),
+ REG_SEQ0(SN622X_REG_RIGHT_MUTE, 0),
+ /* Match Windows L volume; CHR = R (was 0xb0 → right silent). */
+ REG_SEQ0(SN622X_REG_VOL_SECOND, SN622X_SPK_VOL_SECOND_DEFAULT),
+ REG_SEQ0(SN622X_REG_VOL_PRIM, SN622X_SPK_VOL_PRIM_DEFAULT),
+ REG_SEQ0(SN622X_REG_CHR_VOL_SECOND, SN622X_SPK_CHR_VOL_SECOND_DEFAULT),
+ REG_SEQ0(SN622X_REG_CHR_VOL_PRIM, SN622X_SPK_CHR_VOL_PRIM_DEFAULT),
+ /* sn6220.txt: 0x120 或 0x130,只写其中一个(Windows:0x130) */
+ REG_SEQ0(SN622X_REG_CH_ENABLE_B, 0x03),
+ };
+ unsigned int chen_a = 0xff, chen_b = 0xff;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return;
+
+ /* Serialize with SoftMic prepare so a call can open both paths. */
+ mutex_lock(&sn622x->path_lock);
+
+ if (sn622x->slave->status != SDW_SLAVE_ATTACHED) {
+ dev_dbg(dev, "sn622x: speaker prepare: skip (not ATTACHED)\n");
+ goto out_unlock;
+ }
+
+ /*
+ * Always allow Speakers prepare even if SoftMic is open. Blocking
+ * Speakers here left playback dead when SoftMic stayed "active"
+ * (Audacity kill / SoftAmp flap). SoftMic prepare only parks Speakers
+ * D3 when Speakers PCM is not open.
+ */
+ if (sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS) < 0) {
+ dev_dbg(dev, "sn622x: speaker prepare: paging not ready\n");
+ goto out_unlock;
+ }
+
+ /*
+ * SoftMic-only → Speakers: Cap was D0. Do not park SoftMic while
+ * SoftMic PCM is still open — duplex keeps both ports at 48k/16-bit.
+ * SoftMic-only teardown restores Speakers via SoftMic hw_free.
+ */
+
+ /* FUN must be ACKed before CHEN latches (clock resume → 0x63) */
+ sn622x_speaker_fun_ack_if_needed(dev, sn622x);
+
+ /* sn6220.txt: 1=48k. Keep Speakers at 48k for duplex bus budget. */
+ {
+ unsigned int rate = 0xff;
+ struct reg_sequence rate48 =
+ REG_SEQ0(SN622X_REG_RATE_SEL, 0x01);
+
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_RATE_SEL,
+ &rate) == 0 &&
+ (rate & 0xffu) != 0x01u) {
+ if (regmap_multi_reg_write_bypassed(sn622x->regmap,
+ &rate48, 1) == 0)
+ dev_info(dev,
+ "sn622x: speaker prepare: rate 0x%x->0x1 (48k)\n",
+ rate & 0xffu);
+ }
+ }
+
+ /*
+ * Charge pump 0x2086. After reboot it often sits at 0x9a; Speakers
+ * then show CHEN=0x3 / unmute / PDE D0 but stay silent. 0x0b is the
+ * value that restores analog output. Do NOT batch this in io_init —
+ * that UNATTACHed SoftAmp at attach. Writing 0x0b clears CHEN, so
+ * unmute/CHEN below must run after.
+ */
+ {
+ unsigned int pump = 0xff;
+ struct reg_sequence pump_on = REG_SEQ0(0x00002086u, 0x0b);
+
+ if (regmap_read_bypassed(sn622x->regmap, 0x00002086u, &pump) == 0 &&
+ (pump & 0xffu) != 0x0bu) {
+ if (regmap_multi_reg_write_bypassed(sn622x->regmap,
+ &pump_on, 1) == 0) {
+ dev_info(dev,
+ "sn622x: speaker prepare: charge pump 0x2086 0x%x->0x0b\n",
+ pump & 0xffu);
+ usleep_range(1000, 1500);
+ }
+ }
+ }
+
+ /* Always re-latch D0; PipeWire may keep PCM open across plays */
+ sn622x_speaker_pwr_request_d0(dev, sn622x);
+
+ /*
+ * Videos pause leaves MUTE=1 via hw_free; resume must unmute again.
+ * If already unmuted (PAUSE without hw_free), skip the mute-ramp so
+ * pause/continue does not click or race SoftAmp off the bus.
+ */
+ {
+ unsigned int mute = 0xff;
+
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_MUTE,
+ &mute) == 0 &&
+ (mute & 0xffu)) {
+ usleep_range(SN622X_ROUTE_BEFORE_ACTIVE_US_MIN,
+ SN622X_ROUTE_BEFORE_ACTIVE_US_MAX);
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap,
+ spk_ramp,
+ ARRAY_SIZE(spk_ramp));
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: speaker prepare: ramp failed (%d)\n",
+ ret);
+ goto out_unlock;
+ }
+ usleep_range(SN622X_ROUTE_AFTER_MUTE_US_MIN,
+ SN622X_ROUTE_AFTER_MUTE_US_MAX);
+ }
+ }
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, spk_on,
+ ARRAY_SIZE(spk_on));
+ if (ret < 0) {
+ dev_warn(dev, "sn622x: speaker prepare: unmute/CHEN failed (%d)\n",
+ ret);
+ goto out_unlock;
+ }
+
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_CH_ENABLE_A, &chen_a);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_CH_ENABLE_B, &chen_b);
+ dev_info(dev,
+ "sn622x: speaker prepare: D0 + unmute + CHEN=0x%x/0x%x\n",
+ chen_a & 0xffu, chen_b & 0xffu);
+ if ((chen_b & 0x3u) != 0x3u)
+ dev_warn(dev,
+ "sn622x: speaker prepare: CHEN 0x130 did not latch 0x3 (silent risk)\n");
+
+ /*
+ * Do not rewrite CHEN after the port is transporting — that write
+ * UNATTACHed SoftAmp ~1–2s into PipeWire/Audacity play.
+ */
+
+out_unlock:
+ mutex_unlock(&sn622x->path_lock);
+}
+
+static int sn622x_dmic_cap_pwr_request_d0(struct device *dev,
+ struct sn622x_sdca_priv *sn622x)
+{
+ struct reg_sequence pw = REG_SEQ0(SN622X_REG_DMIC_CAP_PWR_STATE_WRITE, 0);
+ unsigned int v = 0xff;
+ int ret, attempt;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return -ENODEV;
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, true,
+ SN622X_INIT_WAIT_MS);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: dmic Cap PWR D0 write skipped (paging not ready, %d)\n",
+ ret);
+ return ret;
+ }
+
+ /* Same rule as speaker: do not rewrite PDE once capture is already D0. */
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_PWR_STATE,
+ &v) == 0 &&
+ (v & 0xffu) == SN622X_PWR_D0)
+ return 0;
+
+ for (attempt = 0; attempt < 5; attempt++) {
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &pw, 1);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: dmic Cap PWR write D0 failed (%d)\n",
+ ret);
+ return ret;
+ }
+
+ usleep_range(2000, 3000);
+
+ ret = regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_PWR_STATE, &v);
+ if (ret < 0) {
+ dev_dbg(dev,
+ "sn622x: dmic Cap PWR state read after D0 failed (%d)\n",
+ ret);
+ continue;
+ }
+ if ((v & 0xffu) == SN622X_PWR_D0)
+ break;
+ }
+
+ dev_info(dev,
+ "sn622x: dmic Cap PWR D0 requested, power_state[0x%x]=0x%x (%s)%s\n",
+ SN622X_REG_DMIC_CAP_PWR_STATE, v, sn622x_pwr_state_str(v),
+ (v & 0xffu) == SN622X_PWR_D0 ? "" : " (still not D0)");
+
+ return (v & 0xffu) == SN622X_PWR_D0 ? 0 : -EIO;
+}
+
+static int sn622x_hw_params_port(struct snd_soc_dai *dai,
+ struct snd_pcm_substream *substream)
+{
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ if (dai->id == SN622X_DAI_SPEAKER)
+ return SN622X_PORT_SPEAKER_PLAYBACK;
+ } else {
+ if (dai->id == SN622X_DAI_DMIC)
+ return SN622X_PORT_DMIC_CAPTURE;
+ }
+ return -EINVAL;
+}
+
+/*
+ * Per SDW data port: mute then request D3 on the matching vendor PWR latch.
+ * Mirrors sn622x_*_pwr_request_d0() / hw_params unmute+D0, low 2 bits 3 = D3.
+ */
+static void sn622x_port_teardown_d3_mute(struct device *dev,
+ struct sn622x_sdca_priv *sn622x,
+ int port, bool route_switch)
+{
+ /*
+ * Mute only. Speaker PDE (0x40400188) and SoftMic PDE (0x40800188)
+ * stay independent so a call can play and record at once. Writing
+ * speaker D3 while the mic port is open NACKs and drops the slave.
+ */
+ static const struct reg_sequence spk_teardown[] = {
+ REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_RIGHT_MUTE, SN622X_MUTE_ON),
+ };
+ /*
+ * SoftMic: mute only. Writing PDE D3 on every Audacity stop races the
+ * next SoftMic prepare/restore and knocks SoftAmp UNATTACHED after a
+ * few record cycles ("jack/mic 多录几次崩溃").
+ */
+ static const struct reg_sequence dmic_cap_teardown[] = {
+ REG_SEQ0(SN622X_REG_DMIC_CAP_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_MUTE, SN622X_MUTE_ON),
+ };
+ const struct reg_sequence *seq;
+ size_t seq_len;
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return;
+
+ mutex_lock(&sn622x->path_lock);
+
+ if (!sn622x_slave_attached(sn622x->slave)) {
+ dev_dbg(dev, "sn622x: hw_free: port %d D3/mute skipped (not ATTACHED)\n",
+ port);
+ goto out_unlock;
+ }
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS);
+ if (ret < 0) {
+ dev_dbg(dev, "sn622x: hw_free: port %d D3/mute skipped (paging %d)\n",
+ port, ret);
+ goto out_unlock;
+ }
+
+ /* Active ports on SN6220: speaker playback + DMIC capture only */
+ switch (port) {
+ case SN622X_PORT_SPEAKER_PLAYBACK:
+ seq = spk_teardown;
+ seq_len = ARRAY_SIZE(spk_teardown);
+ break;
+ case SN622X_PORT_DMIC_CAPTURE:
+ seq = dmic_cap_teardown;
+ seq_len = ARRAY_SIZE(dmic_cap_teardown);
+ break;
+ default:
+ dev_warn(dev, "sn622x: hw_free: unknown port %d\n", port);
+ goto out_unlock;
+ }
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, seq, seq_len);
+ if (ret < 0) {
+ dev_warn(dev, "sn622x: port %d teardown failed (%d)%s\n", port, ret,
+ route_switch ? " (route)" : "");
+ } else if (port == SN622X_PORT_DMIC_CAPTURE) {
+ dev_info(dev, "sn622x: port %d muted (SoftMic PDE left alone)%s\n",
+ port, route_switch ? " (route switch)" : "");
+ } else {
+ dev_info(dev, "sn622x: port %d muted (speaker PDE left alone)%s\n",
+ port, route_switch ? " (route switch)" : "");
+ }
+
+ usleep_range(1000, 1500);
+
+out_unlock:
+ mutex_unlock(&sn622x->path_lock);
+}
+
+static const char *sn622x_rate_sel_str(unsigned int v)
+{
+ switch (v & 0xffu) {
+ case 1:
+ return "48k";
+ case 2:
+ return "96k";
+ case 3:
+ return "192k";
+ default:
+ return "?";
+ }
+}
+
+static void sn622x_hw_params_speaker_playback(struct snd_soc_dai *dai,
+ struct snd_pcm_substream *substream,
+ struct sn622x_sdca_priv *sn622x)
+{
+ struct device *dev = dai->dev;
+ unsigned int v, vlo, vhi;
+ int r, rlo, rhi;
+ bool paged_ok;
+
+ if (!sn622x_codec_diag || !sn622x->regmap)
+ return;
+
+ if (sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+
+ if (sn622x->slave)
+ dev_info(dev,
+ "sn622x: diag: prelude hw_init=%d first_hw_init=%d sdw_status=%s(%d) dev_num=%u dev_num_sticky=%u card_instantiated=%d (paged poll %ums; next lines show paging/reads)\n",
+ sn622x->hw_init, sn622x->first_hw_init,
+ sn622x_slave_status_sym(sn622x->slave->status),
+ sn622x->slave->status,
+ sn622x->slave->dev_num, sn622x->slave->dev_num_sticky,
+ dai->component->card &&
+ snd_soc_card_is_instantiated(dai->component->card),
+ SN622X_PAGED_QUICK_MS);
+
+ paged_ok = sn622x->slave &&
+ sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS) == 0;
+
+ if (paged_ok) {
+ /*
+ * Do not request speaker D0 from diag. Rewriting PDE here on
+ * every PipeWire open resets FUN to 0x63 and the port start
+ * then drops SoftAmp. Speaker prepare owns the D0 transition.
+ */
+
+ /*
+ * This kernel has no regmap_write_bypassed(); use multi write (cf. PWR diag).
+ * Order: unmute, VOL_SECOND=0xfa, VOL_PRIM=0 (Windows Speakers).
+ */
+ {
+ const struct reg_sequence mute_vol[] = {
+ REG_SEQ0(SN622X_REG_MUTE, 0),
+ REG_SEQ0(SN622X_REG_RIGHT_MUTE, 0),
+ REG_SEQ0(SN622X_REG_VOL_SECOND,
+ SN622X_SPK_VOL_SECOND_DEFAULT),
+ REG_SEQ0(SN622X_REG_VOL_PRIM,
+ SN622X_SPK_VOL_PRIM_DEFAULT),
+ REG_SEQ0(SN622X_REG_CHR_VOL_SECOND,
+ SN622X_SPK_CHR_VOL_SECOND_DEFAULT),
+ REG_SEQ0(SN622X_REG_CHR_VOL_PRIM,
+ SN622X_SPK_CHR_VOL_PRIM_DEFAULT),
+ };
+
+ r = regmap_multi_reg_write_bypassed(sn622x->regmap, mute_vol,
+ ARRAY_SIZE(mute_vol));
+ if (r < 0)
+ dev_info(dev,
+ "sn622x: diag: write MUTE/VOL_SECOND/VOL_PRIM err %d\n",
+ r);
+ else
+ dev_info(dev,
+ "sn622x: diag: write MUTE=0 VOL_SECOND=0xfa VOL_PRIM=0 ok\n");
+ }
+
+ r = regmap_read_bypassed(sn622x->regmap, SN622X_REG_RATE_SEL, &v);
+ if (r < 0)
+ dev_info(dev, "sn622x: diag: read RATE 0x%x err %d\n",
+ SN622X_REG_RATE_SEL, r);
+ else
+ dev_info(dev,
+ "sn622x: diag: sample_rate_sel[0x%x]=0x%x (%s; 1=48k 2=96k 3=192k)\n",
+ SN622X_REG_RATE_SEL, v & 0xffu,
+ sn622x_rate_sel_str(v));
+
+ rlo = regmap_read_bypassed(sn622x->regmap, SN622X_REG_VOL_PRIM,
+ &vlo);
+ rhi = regmap_read_bypassed(sn622x->regmap, SN622X_REG_VOL_SECOND,
+ &vhi);
+ if (rlo < 0 || rhi < 0)
+ dev_info(dev,
+ "sn622x: diag: volume read err prim=%d second=%d\n",
+ rlo, rhi);
+ else
+ dev_info(dev,
+ "sn622x: diag: volume [0x%x]=0x%x [0x%x]=0x%x\n",
+ SN622X_REG_VOL_PRIM, vlo & 0xffu,
+ SN622X_REG_VOL_SECOND, vhi & 0xffu);
+ rlo = regmap_read_bypassed(sn622x->regmap, SN622X_REG_CHR_VOL_PRIM,
+ &vlo);
+ rhi = regmap_read_bypassed(sn622x->regmap, SN622X_REG_CHR_VOL_SECOND,
+ &vhi);
+ if (rlo < 0 || rhi < 0)
+ dev_info(dev,
+ "sn622x: diag: volume read err prim=%d second=%d\n",
+ rlo, rhi);
+ else
+ dev_info(dev,
+ "sn622x: diag: volume [0x%x]=0x%x [0x%x]=0x%x\n",
+ SN622X_REG_CHR_VOL_PRIM, vlo & 0xffu,
+ SN622X_REG_CHR_VOL_SECOND, vhi & 0xffu);
+
+ r = regmap_read_bypassed(sn622x->regmap, SN622X_REG_MUTE, &v);
+ if (r < 0)
+ dev_info(dev, "sn622x: diag: read MUTE 0x%x err %d\n",
+ SN622X_REG_MUTE, r);
+ else
+ dev_info(dev,
+ "sn622x: diag: mute[0x%x]=0x%x (%s)\n",
+ SN622X_REG_MUTE, v & 0xffu,
+ (v & 0xffu) ? "muted" : "not muted");
+ }
+ r = -ENODEV;
+ v = 0;
+
+ /*
+ * sdw_nread_no_pm() needs a programmed logical dev# for these vendor/SCP
+ * windows; same as paged SDCA above. Reading without dev_num hits
+ * sdw_fill_msg() -EINVAL ("Invalid device for paging") and spams dmesg
+ * while PWR/RATE were already skipped — not a topology tplg defect.
+ */
+ if (paged_ok) {
+ r = regmap_read_bypassed(sn622x->regmap, SN622X_REG_CH_ENABLE_A, &v);
+ if (r < 0)
+ dev_info(dev, "sn622x: diag: read CHEN 0x%x err %d\n",
+ SN622X_REG_CH_ENABLE_A, r);
+ else
+ dev_info(dev,
+ "sn622x: diag: channelEnable[0x%x]=0x%x (bits0-1: 0x3 = both)\n",
+ SN622X_REG_CH_ENABLE_A, v & 0xffu);
+
+ r = regmap_read_bypassed(sn622x->regmap, SN622X_REG_CH_ENABLE_B, &v);
+ if (r < 0)
+ dev_info(dev, "sn622x: diag: read CHEN 0x%x err %d\n",
+ SN622X_REG_CH_ENABLE_B, r);
+ else
+ dev_info(dev,
+ "sn622x: diag: channelEnable[0x%x]=0x%x (bits0-1: 0x3 = both)\n",
+ SN622X_REG_CH_ENABLE_B, v & 0xffu);
+ } else {
+ dev_info(dev,
+ "sn622x: diag: read CHEN 0x%x/0x%x skipped (no SDW dev_num for paging)\n",
+ SN622X_REG_CH_ENABLE_A, SN622X_REG_CH_ENABLE_B);
+ }
+
+ if (!paged_ok)
+ dev_info(dev,
+ "sn622x: diag: hint: paging not ready (dev_num) — fix enumeration/ACPI before vendor/SDCA reads will succeed\n");
+
+ dev_info(dev,
+ "sn622x: diag: dai=\"%s\" id=%d stream=%s (codec_diag=0 to silence)\n",
+ dai->name, dai->id, snd_pcm_stream_str(substream));
+}
+
+static int sn622x_dmic_init_table(struct device *dev,
+ struct sn622x_sdca_priv *sn622x);
+
+/*
+ * SoftMic analog bring-up: once per SoftAmp ATTACH. Repeating the full init
+ * table on every PipeWire/GNOME capture open (Settings keeps Mic live) races
+ * Speakers and knocks SoftAmp UNATTACHED → BUSCLOCK_SCALE -61 storm.
+ */
+static void sn622x_restore_dmic_analog(struct device *dev,
+ struct sn622x_sdca_priv *sn622x,
+ const char *why)
+{
+ struct reg_sequence clear_dmic =
+ REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL, 0x61);
+ int ret;
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return;
+ if (!sn622x_slave_attached(sn622x->slave)) {
+ dev_dbg(dev, "sn622x: restore dmic skip (%s): not ATTACHED\n",
+ why ? why : "?");
+ return;
+ }
+ if (sn622x->dmic_analog_restored) {
+ dev_dbg(dev, "sn622x: restore dmic skip (%s): already done\n",
+ why ? why : "?");
+ return;
+ }
+
+ dev_info(dev, "sn622x: restore dmic analog (%s)\n", why ? why : "?");
+
+ ret = sn622x_dmic_init_table(dev, sn622x);
+ if (ret < 0) {
+ dev_warn(dev, "sn622x: restore dmic: init table failed (%d)\n",
+ ret);
+ return;
+ }
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: restore dmic: paging not ready for FUN clear (%d)\n",
+ ret);
+ return;
+ }
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &clear_dmic, 1);
+ if (ret < 0) {
+ dev_warn(dev, "sn622x: restore dmic: FUN STATUS clear failed (%d)\n",
+ ret);
+ return;
+ }
+ usleep_range(1000, 1500);
+ sn622x->dmic_analog_restored = true;
+}
+
+/*
+ * After sdw_stream_add_slave: re-init analog (sn624x dmic_pmu), re-latch D0,
+ * then match working Windows SoftMic capture values (same EVK):
+ * 0x320=0, 0x330=0x3, rate_sel=3, vol int=0xfb / frac=0x4d, unmute.
+ */
+static void sn622x_dmic_capture_prepare(struct device *dev,
+ struct sn622x_sdca_priv *sn622x,
+ unsigned int pcm_rate,
+ bool bringup)
+{
+ unsigned int mute = 0xff, chen_a = 0xff, chen_b = 0xff, pwr = 0xff;
+ unsigned int rate = 0xff, vol_int = 0xff, vol_frac = 0xff;
+ int r;
+ const struct reg_sequence cap_on[] = {
+ REG_SEQ0(0x00002126u, 0x18),
+ REG_SEQ0(0x00002127u, 0x01),
+ REG_SEQ0(0x000020f3u, 0x30),
+ /* 1=48k (sn6220.txt). 0x3=192k overloaded duplex SoftAmp. */
+ REG_SEQ0(SN622X_REG_DMIC_CAP_RATE_SEL, 0x01),
+ /* Windows SoftMic dump: int then frac (sn6220.txt write order) */
+ REG_SEQ0(SN622X_REG_DMIC_CAP_VOL_INT, 0xfb),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_VOL_FRAC, 0x4d),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL_INT, 0xfb),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL_FRAC, 0x4d),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_MUTE, 0),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_MUTE, 0),
+ /*
+ * sn6220.txt: 0x320 或 0x330。只写其中一个 0x3(Windows:0x330)。
+ * 两个都写、或录音时完全不写,读回来都是 0(通道关)。
+ */
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CH_ENABLE_B, 0x03),
+ };
+
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return;
+
+ mutex_lock(&sn622x->path_lock);
+
+ if (!sn622x_slave_attached(sn622x->slave)) {
+ dev_dbg(dev, "sn622x: dmic prepare: skip (not ATTACHED)\n");
+ goto out_unlock;
+ }
+
+ if (sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS) < 0) {
+ dev_dbg(dev, "sn622x: dmic prepare: paging not ready\n");
+ goto out_unlock;
+ }
+
+ /*
+ * SoftMic-only: mute Speakers and park Speakers PDE in D3.
+ * Duplex (playback_active): leave Speakers alone — both ports stay
+ * at 48 kHz / 16-bit so SoftAmp can keep both streams.
+ */
+ if (!sn622x->playback_active) {
+ static const struct reg_sequence spk_mute_on[] = {
+ REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_RIGHT_MUTE, SN622X_MUTE_ON),
+ };
+ unsigned int spk_pwr = 0xff;
+
+ regmap_multi_reg_write_bypassed(sn622x->regmap, spk_mute_on,
+ ARRAY_SIZE(spk_mute_on));
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_PWR_STATE,
+ &spk_pwr) == 0 &&
+ (spk_pwr & 0xffu) != SN622X_PWR_D3)
+ sn622x_speaker_pwr_request_d3(dev, sn622x);
+ sn622x->spk_parked_for_dmic = true;
+ } else {
+ dev_info(dev,
+ "sn622x: dmic prepare: duplex — leave Speakers, SoftMic 48k/16\n");
+ }
+
+ /* SoftMic FUN 0x63 leaves capture near-silent even with CHEN=0x3. */
+ {
+ unsigned int st = 0;
+ struct reg_sequence clear_dmic =
+ REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL, 0x61);
+
+ if (regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_FUN_STATUS_CTL,
+ &st) == 0 &&
+ (st & (SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET))) {
+ dev_info(dev,
+ "sn622x: dmic prepare: SoftMic FUN 0x%x — ACK 0x61\n",
+ st);
+ regmap_multi_reg_write_bypassed(sn622x->regmap,
+ &clear_dmic, 1);
+ usleep_range(1000, 1500);
+ }
+ }
+
+ /*
+ * SoftMic init table whenever analog was lost — not only hw_params
+ * bringup. HP insert flaps SoftAmp mid-record; settle calls prepare
+ * with bringup=false and must still restore SoftMic analog.
+ */
+ if (bringup || !sn622x->dmic_analog_restored)
+ sn622x_restore_dmic_analog(dev, sn622x,
+ bringup ? "dmic_pmu" : "dmic_recover");
+
+ if (!sn622x_slave_attached(sn622x->slave))
+ goto out_unlock;
+
+ /*
+ * SoftMic Cap PDE. If Speakers PCM is still open, mute Speakers only
+ * around the SoftMic PDE write (leave Speakers PDE D0 so playback can
+ * resume). Do not write Speakers unmute here — Speakers prepare owns
+ * that after SoftMic ends / on next play.
+ */
+ {
+ bool muted_spk = false;
+ static const struct reg_sequence spk_mute_on[] = {
+ REG_SEQ0(SN622X_REG_MUTE, SN622X_MUTE_ON),
+ REG_SEQ0(SN622X_REG_RIGHT_MUTE, SN622X_MUTE_ON),
+ };
+
+ if (sn622x->playback_active &&
+ sn622x_slave_attached(sn622x->slave)) {
+ unsigned int spk_mute = 0;
+
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_MUTE,
+ &spk_mute) == 0 &&
+ (spk_mute & 0xffu) == 0) {
+ regmap_multi_reg_write_bypassed(sn622x->regmap,
+ spk_mute_on,
+ ARRAY_SIZE(spk_mute_on));
+ muted_spk = true;
+ }
+ }
+
+ r = sn622x_dmic_cap_pwr_request_d0(dev, sn622x);
+ if (r < 0)
+ dev_warn(dev,
+ "sn622x: dmic prepare: PWR D0 failed (%d)\n",
+ r);
+
+ /* Keep Speakers muted while SoftMic is capturing if Speakers PCM open */
+ (void)muted_spk;
+ }
+
+ /*
+ * SoftMic analog+rate/vol once while Cap may still be D3 (safe). Do
+ * NOT rewrite 0x2126 after Cap is already D0 — that chased SoftAmp
+ * into an UNATTACH loop and killed Speakers playback.
+ */
+ if (!sn622x->dmic_cap_cfg_done &&
+ sn622x_slave_attached(sn622x->slave)) {
+ static const struct reg_sequence cap_cfg[] = {
+ REG_SEQ0(0x00002126u, 0x18),
+ REG_SEQ0(0x00002127u, 0x01),
+ REG_SEQ0(0x000020f3u, 0x30),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_RATE_SEL, 0x01),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_VOL_INT, 0xfb),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_VOL_FRAC, 0x4d),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL_INT, 0xfb),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL_FRAC, 0x4d),
+ };
+
+ r = regmap_multi_reg_write_bypassed(sn622x->regmap, cap_cfg,
+ ARRAY_SIZE(cap_cfg));
+ if (r < 0)
+ dev_warn(dev,
+ "sn622x: dmic prepare: SoftMic cap_cfg failed (%d)\n",
+ r);
+ else {
+ sn622x->dmic_cap_cfg_done = true;
+ dev_info(dev,
+ "sn622x: dmic prepare: SoftMic analog+rate/vol latched\n");
+ }
+ }
+
+ /*
+ * Do not unmute/CHEN SoftMic while Cap PDE is still D3 — that sequence
+ * drops SoftAmp (UNATTACH). Retry after SoftMic port is transporting
+ * (trigger + dmic_on_work).
+ */
+ pwr = 0xff;
+ if (regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_PWR_STATE,
+ &pwr) ||
+ (pwr & 0xffu) != SN622X_PWR_D0) {
+ dev_info(dev,
+ "sn622x: dmic prepare: SoftMic still D3 — defer CHEN (pb=%u)\n",
+ sn622x->playback_active ? 1 : 0);
+ sn622x->dmic_route_latched = false;
+ if (sn622x->dmic_active)
+ mod_delayed_work(system_wq, &sn622x->dmic_on_work,
+ msecs_to_jiffies(150));
+ goto out_unlock;
+ }
+
+ /*
+ * Cap D0: unmute + CHEN only. Rewriting 0x2126 here UNATTACHes SoftAmp.
+ * Duplex keeps Speakers PDE D0; SoftMic CHEN still runs at 48k/16-bit.
+ */
+ if (!bringup || sn622x->playback_active || sn622x->dmic_analog_restored) {
+ static const struct reg_sequence light_on[] = {
+ REG_SEQ0(SN622X_REG_DMIC_CAP_RATE_SEL, 0x01),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_VOL_INT, 0xfb),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_VOL_FRAC, 0x4d),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL_INT, 0xfb),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_VOL_FRAC, 0x4d),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_MUTE, 0),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CHR_MUTE, 0),
+ REG_SEQ0(SN622X_REG_DMIC_CAP_CH_ENABLE_B, 0x03),
+ };
+
+ if (sn622x_slave_attached(sn622x->slave)) {
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_MUTE, &mute);
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_CH_ENABLE_B,
+ &chen_b);
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_VOL_INT,
+ &vol_int);
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_VOL_FRAC,
+ &vol_frac);
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_RATE_SEL,
+ &rate);
+ if (sn622x->dmic_cap_cfg_done &&
+ (mute & 0xffu) == 0 &&
+ (chen_b & 0x3u) == 0x3u &&
+ (vol_int & 0xffu) == 0xfb &&
+ (vol_frac & 0xffu) == 0x4d &&
+ (rate & 0xffu) == 0x01u) {
+ sn622x->dmic_route_latched = true;
+ dev_dbg(dev,
+ "sn622x: dmic prepare: SoftMic already healthy\n");
+ goto out_unlock;
+ }
+
+ r = regmap_multi_reg_write_bypassed(sn622x->regmap,
+ light_on,
+ ARRAY_SIZE(light_on));
+ if (r < 0) {
+ dev_warn(dev,
+ "sn622x: dmic prepare: light latch failed (%d)\n",
+ r);
+ sn622x->dmic_route_latched = false;
+ } else {
+ sn622x->dmic_route_latched = true;
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_MUTE,
+ &mute);
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_CH_ENABLE_B,
+ &chen_b);
+ regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_CAP_RATE_SEL,
+ &rate);
+ dev_info(dev,
+ "sn622x: dmic prepare: light SoftMic latch pcm_rate=%u pb=%u mute=0x%x chenB=0x%x rate=0x%x\n",
+ pcm_rate,
+ sn622x->playback_active ? 1 : 0,
+ mute & 0xffu, chen_b & 0xffu,
+ rate & 0xffu);
+ }
+ }
+ goto out_unlock;
+ }
+
+ usleep_range(SN622X_ROUTE_BEFORE_ACTIVE_US_MIN,
+ SN622X_ROUTE_BEFORE_ACTIVE_US_MAX);
+
+ if (!sn622x_slave_attached(sn622x->slave))
+ goto out_unlock;
+
+ r = regmap_multi_reg_write_bypassed(sn622x->regmap, cap_on,
+ ARRAY_SIZE(cap_on));
+ if (r < 0) {
+ dev_warn(dev, "sn622x: dmic prepare: unmute/vol failed (%d)\n",
+ r);
+ goto out_unlock;
+ }
+
+ usleep_range(SN622X_ROUTE_AFTER_MUTE_US_MIN, SN622X_ROUTE_AFTER_MUTE_US_MAX);
+
+ if (!sn622x_slave_attached(sn622x->slave))
+ goto out_unlock;
+
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_PWR_STATE, &pwr);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_MUTE, &mute);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_CH_ENABLE_A,
+ &chen_a);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_CH_ENABLE_B,
+ &chen_b);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_RATE_SEL, &rate);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_VOL_INT, &vol_int);
+ regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_CAP_VOL_FRAC, &vol_frac);
+ sn622x->dmic_route_latched = true;
+ dev_info(dev,
+ "sn622x: dmic prepare: win SoftMic match pcm_rate=%u "
+ "(pwr=0x%x mute=0x%x chen=0x%x/0x%x rate=0x%x vol=0x%x/0x%x)\n",
+ pcm_rate, pwr & 0xffu, mute & 0xffu, chen_a & 0xffu,
+ chen_b & 0xffu, rate & 0xffu, vol_int & 0xffu, vol_frac & 0xffu);
+
+out_unlock:
+ mutex_unlock(&sn622x->path_lock);
+}
+
+static void sn622x_hw_params_dmic_capture(struct snd_soc_dai *dai,
+ struct snd_pcm_substream *substream,
+ struct sn622x_sdca_priv *sn622x)
+{
+ /* Rate/CHEN applied in sn622x_dmic_capture_prepare after stream add */
+ dev_dbg(dai->dev, "sn622x: dmic_cap: hw_params pre-stream (prepare after add)\n");
+}
+static const char *sn622x_status_str(enum sdw_slave_status status)
+{
+ switch (status) {
+ case SDW_SLAVE_UNATTACHED:
+ return "UNATTACHED";
+ case SDW_SLAVE_ATTACHED:
+ return "ATTACHED";
+ case SDW_SLAVE_ALERT:
+ return "ALERT";
+ case SDW_SLAVE_RESERVED:
+ return "RESERVED";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static bool sn622x_sdca_readable_register(struct device *dev, unsigned int reg)
+{
+ return true;
+}
+
+static bool sn622x_sdca_volatile_register(struct device *dev, unsigned int reg)
+{
+ return true;
+}
+
+static bool sn622x_sdca_mbq_readable_register(struct device *dev, unsigned int reg)
+{
+ return true;
+}
+
+static bool sn622x_sdca_mbq_volatile_register(struct device *dev, unsigned int reg)
+{
+ return false;
+}
+
+static const struct reg_default sn622x_sdca_reg_defaults[] = {
+ {}
+};
+
+static const struct regmap_config sn622x_sdca_regmap = {
+ .reg_bits = 32,
+ .val_bits = 8,
+ .readable_reg = sn622x_sdca_readable_register,
+ .volatile_reg = sn622x_sdca_volatile_register,
+ .max_register = 0xffffffff,
+ .reg_defaults = sn622x_sdca_reg_defaults,
+ .num_reg_defaults = ARRAY_SIZE(sn622x_sdca_reg_defaults),
+ /*
+ * MAPLE + regcache_cache_only(true) in sn622x_sdca_init() defers bus I/O
+ * until io_init(); plain regmap_read before then returns -EBUSY. A prior
+ * out-of-tree PoC used REGCACHE_NONE here so probe-time regmap_read worked.
+ */
+ .cache_type = REGCACHE_MAPLE,
+ .use_single_read = true,
+ .use_single_write = true,
+};
+
+static const struct regmap_config sn622x_sdca_mbq_regmap = {
+ .name = "sdw-mbq",
+ .reg_bits = 32,
+ .val_bits = 16,
+ .readable_reg = sn622x_sdca_mbq_readable_register,
+ .volatile_reg = sn622x_sdca_mbq_volatile_register,
+ .max_register = 0x41000312,
+ .reg_defaults = sn622x_sdca_reg_defaults,
+ .num_reg_defaults = ARRAY_SIZE(sn622x_sdca_reg_defaults),
+ .cache_type = REGCACHE_MAPLE,
+ .use_single_read = true,
+ .use_single_write = true,
+};
+
+static void sn622x_sdca_sdca_irq_mask_all(struct sn622x_sdca_priv *sn622x)
+{
+ if (!sn622x->slave)
+ return;
+
+ sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK1, 0);
+ sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK2, 0);
+ sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK3, 0);
+ sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INTMASK4, 0);
+ SN622X_DBG(&sn622x->slave->dev,
+ "SDCA INTMASK1-4 = 0 (all SDCA sources masked)\n");
+}
+
+static int sn622x_dmic_init_table(struct device *dev, struct sn622x_sdca_priv *sn622x)
+{
+ int ret;
+ unsigned int v;
+ const struct reg_sequence dmic_init_table[] = {
+ REG_SEQ0(0x00002041, 0x00),
+ /* Skip PPU11 0x40880380 — SoftAmp NACKs it and drops the bus */
+ REG_SEQ0(0x00002105, 0x66),
+ REG_SEQ0(0x00002107, 0x26),
+ REG_SEQ0(0x00002109, 0x62),
+ REG_SEQ0(0x40800a09, 0x00),
+ REG_SEQ0(0x40800a0a, 0x00),
+ REG_SEQ0(0x40802a11, 0x00),
+ REG_SEQ0(0x40800a11, 0x00),
+ REG_SEQ0(0x40802a12, 0x00),
+ REG_SEQ0(0x40800a12, 0x00),
+ REG_SEQ0(0x40802a13, 0x00),
+ REG_SEQ0(0x40800a13, 0x00),
+ REG_SEQ0(0x40802a14, 0x00),
+ REG_SEQ0(0x40800a14, 0x00),
+ REG_SEQ0(0x408029d8, 0x0c),
+ REG_SEQ0(0x408009d8, 0x00),
+ REG_SEQ0(0x408029d9, 0x0c),
+ REG_SEQ0(0x408009d9, 0x00),
+ REG_SEQ0(0x00002140, 0x18),
+ REG_SEQ0(0x00002045, 0x01),
+ };
+ if (!sn622x || !sn622x->regmap || !sn622x->slave)
+ return -ENODEV;
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, true,
+ SN622X_INIT_WAIT_MS);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: io_init: PWR D0 write skipped (paging not ready, %d)\n",
+ ret);
+ return ret;
+ }
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, dmic_init_table, ARRAY_SIZE(dmic_init_table));
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: io_init: DMIC FUN STATUS CTL write 0x%x=0 failed (%d)\n",
+ SN622X_REG_DMIC_FUN_STATUS_CTL, ret);
+ return ret;
+ }
+
+ usleep_range(1000, 1500);
+
+ for (size_t i = 0; i < ARRAY_SIZE(dmic_init_table); i++) {
+ ret = regmap_read_bypassed(sn622x->regmap, dmic_init_table[i].reg,
+ &v);
+ dev_dbg(dev, "sn622x: dmic init[0x%x]=0x%x err=%d\n",
+ dmic_init_table[i].reg, v, ret);
+ }
+
+ return 0;
+}
+
+static int sn622x_sdca_io_init(struct device *dev, struct sdw_slave *slave)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(dev);
+ int ret;
+ unsigned int dmic_func_status;
+ if (sn622x->hw_init) {
+ SN622X_DBG(dev, "io_init: skip (hw_init already true)\n");
+ return 0;
+ }
+
+ mutex_lock(&sn622x->path_lock);
+ if (sn622x->hw_init) {
+ mutex_unlock(&sn622x->path_lock);
+ return 0;
+ }
+ /*
+ * Reattach while Speakers or SoftMic PCM is open: do not touch the
+ * bus. Reading FUN / ACK here UNATTACHes SoftAmp again, settle calls
+ * io_init, and the GNOME test tone never stays up.
+ */
+ if (sn622x->first_hw_init &&
+ (sn622x->playback_active || sn622x->dmic_active)) {
+ dev_info(dev,
+ "sn622x: io_init: stream open — skip bus access\n");
+ sn622x->hw_init = true;
+ mutex_unlock(&sn622x->path_lock);
+ return 0;
+ }
+ /*
+ * SoftMic stream already open (HP insert flaps SoftAmp mid-record).
+ * Skip Speakers PDE (avoids UNATTACH loop) but must re-enable paging
+ * and ACK SoftMic FUN — otherwise Cap stays quiet until SoftMic is
+ * stopped and reopened. SoftMic prepare (settle) restores analog/CHEN.
+ */
+ if (sn622x->dmic_active) {
+ dev_info(dev,
+ "sn622x: io_init: SoftMic active — FUN ACK for recover\n");
+ sn622x->disable_irq = false;
+ if (sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+ regcache_cache_only(sn622x->regmap, false);
+ regcache_cache_only(sn622x->mbq_regmap, false);
+ pm_runtime_get_noresume(dev);
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, true,
+ SN622X_INIT_WAIT_MS);
+ if (ret == 0) {
+ ret = regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_FUN_STATUS_CTL,
+ &dmic_func_status);
+ if (ret == 0) {
+ dev_info(dev,
+ "sn622x: io_init: SoftMic recover DMIC FUN[0x%x]=0x%x\n",
+ SN622X_REG_DMIC_FUN_STATUS_CTL,
+ dmic_func_status);
+ if (dmic_func_status &
+ (SN622X_FUN_NEEDS_INIT |
+ SN622X_FUN_HAS_BEEN_RESET)) {
+ struct reg_sequence clear_dmic =
+ REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL,
+ 0x61);
+
+ ret = regmap_multi_reg_write_bypassed(
+ sn622x->regmap, &clear_dmic, 1);
+ if (ret < 0)
+ dev_warn(dev,
+ "sn622x: io_init: SoftMic FUN ACK failed (%d)\n",
+ ret);
+ else
+ usleep_range(1000, 1500);
+ }
+ }
+ }
+
+ pm_runtime_set_active(dev);
+ sn622x->hw_init = true;
+ sn622x->first_hw_init = true;
+ pm_runtime_put_autosuspend(dev);
+ mutex_unlock(&sn622x->path_lock);
+ return 0;
+ }
+
+ SN622X_TRC(dev, "io_init: start (first hardware bring-up)\n");
+ sn622x->disable_irq = false;
+
+ if (sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+
+ regcache_cache_only(sn622x->regmap, false);
+ regcache_cache_only(sn622x->mbq_regmap, false);
+
+ pm_runtime_get_noresume(dev);
+
+ /*
+ * Speaker PDE write on a re-ATTACH is what keeps SoftAmp in the
+ * UNATTACH loop (FUN already 0x3). Only the first bring-up requests D0.
+ */
+ if (!sn622x->first_hw_init) {
+ ret = sn622x_pwr_request_d0(dev, sn622x);
+ if (ret < 0)
+ SN622X_DBG(dev, "io_init: PWR D0 request failed (%d), continuing\n",
+ ret);
+ } else {
+ dev_info(dev, "sn622x: io_init: reattach, skip speaker PDE write\n");
+ }
+
+ ret = sn622x_sdw_prepare_paged_access(dev, sn622x->slave, true,
+ SN622X_INIT_WAIT_MS);
+ if (ret < 0) {
+ dev_warn(dev,
+ "sn622x: io_init: paging not ready for FUN STATUS (%d)\n",
+ ret);
+ } else {
+ unsigned int spk_func_status;
+
+ ret = regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_SPEAKER_FUN_STATUS_CTL,
+ &spk_func_status);
+ if (ret < 0) {
+ dev_dbg(dev,
+ "sn622x: io_init: SPEAKER FUN STATUS read failed (%d)\n",
+ ret);
+ } else {
+ dev_info(dev,
+ "sn622x: io_init: SPEAKER FUN STATUS[0x%x]=0x%x\n",
+ SN622X_REG_SPEAKER_FUN_STATUS_CTL, spk_func_status);
+ /*
+ * ACK only (no charge-pump batch). Settle briefly so a
+ * concurrent BE probe does not race SoftAmp off the bus.
+ */
+ if (spk_func_status & (SN622X_FUN_NEEDS_INIT |
+ SN622X_FUN_HAS_BEEN_RESET)) {
+ usleep_range(5000, 8000);
+ if (sn622x->slave->status == SDW_SLAVE_ATTACHED)
+ sn622x_speaker_fun_ack_if_needed(dev,
+ sn622x);
+ }
+ }
+
+ ret = regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_DMIC_FUN_STATUS_CTL,
+ &dmic_func_status);
+ if (ret < 0) {
+ dev_dbg(dev,
+ "sn622x: io_init: DMIC FUN STATUS read failed (%d)\n",
+ ret);
+ } else {
+ dev_info(dev,
+ "sn622x: io_init: DMIC FUN STATUS[0x%x]=0x%x\n",
+ SN622X_REG_DMIC_FUN_STATUS_CTL, dmic_func_status);
+
+ /*
+ * Light FUN ACK only (no heavy init table). Table runs
+ * once in SoftMic prepare. Without ACK, SoftMic PDE
+ * stays D3; with full table here SoftAmp races Speakers.
+ */
+ if (dmic_func_status & (SN622X_FUN_NEEDS_INIT |
+ SN622X_FUN_HAS_BEEN_RESET)) {
+ struct reg_sequence clear_dmic =
+ REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL,
+ 0x61);
+
+ dev_info(dev,
+ "sn622x: io_init: DMIC FUN STATUS 0x%x — ACK 0x61 (table deferred)\n",
+ dmic_func_status);
+ if (sn622x->slave->status == SDW_SLAVE_ATTACHED) {
+ ret = regmap_multi_reg_write_bypassed(
+ sn622x->regmap, &clear_dmic, 1);
+ if (ret < 0)
+ dev_warn(dev,
+ "sn622x: io_init: DMIC FUN ACK failed (%d)\n",
+ ret);
+ else
+ usleep_range(1000, 1500);
+ }
+ }
+ }
+ }
+
+ pm_runtime_set_active(dev);
+
+ sn622x->hw_init = true;
+ sn622x->first_hw_init = true;
+
+ pm_runtime_put_autosuspend(dev);
+
+ sn622x_log_power_mode_once(dev, sn622x);
+
+ SN622X_DBG(dev, "io_init: complete (hw_init set)\n");
+ SN622X_TRC(dev, "io_init: done (speaker + DMIC only)\n");
+ mutex_unlock(&sn622x->path_lock);
+ return 0;
+}
+
+/*
+ * Headphone insert is an external mux (sn6220.txt 0x2025 is status only).
+ * The insert glitches the SoundWire link. Running io_init on every reattach
+ * writes speaker PDE and keeps SoftAmp UNATTACHED, so the next DMIC open fails.
+ * Wait until the link has been quiet, then bring the chip up once. If SoftMic
+ * is still open, re-latch it without touching the headphone path.
+ */
+static void sn622x_pm_recover(struct device *dev)
+{
+ int err = dev->power.runtime_error;
+
+ if (!err)
+ return;
+
+ /*
+ * runtime_error makes every later pm_runtime_get return -EINVAL.
+ * PipeWire then retries Speaker/Mic open and the desktop audio UI stalls.
+ */
+ dev_info(dev, "sn622x: clear sticky runtime PM error %d\n", err);
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+ pm_runtime_enable(dev);
+}
+
+static void sn622x_settle_work(struct work_struct *work)
+{
+ struct sn622x_sdca_priv *sn622x =
+ container_of(work, struct sn622x_sdca_priv, settle_work.work);
+ struct device *dev;
+
+ if (!sn622x->slave || !sn622x_slave_attached(sn622x->slave))
+ return;
+
+ dev = &sn622x->slave->dev;
+ sn622x_pm_recover(dev);
+ if (!sn622x->hw_init) {
+ dev_info(dev, "sn622x: settle: io_init after bus flap\n");
+ sn622x_sdca_io_init(dev, sn622x->slave);
+ }
+ /*
+ * Do not re-run speaker prepare here. Videos pause/resume already
+ * triggers prepare; settle rewriting Speakers chased SoftAmp into an
+ * UNATTACH loop and left resume silent. SoftMic-only streams may still
+ * need a light re-latch after a brief flap.
+ */
+ /*
+ * SoftMic still open after SoftAmp flap (e.g. HP insert). Do NOT
+ * re-latch SoftMic while Speakers PCM is open — SoftMic CHEN with
+ * Speakers transporting UNATTACHes SoftAmp in a loop and kills
+ * Speakers (GNOME Settings keeps SoftMic+Speakers open together).
+ * SoftMic-only recover: Cap PDE + light CHEN when Speakers idle.
+ */
+ if (sn622x->dmic_active && !sn622x->playback_active &&
+ sn622x_slave_attached(sn622x->slave)) {
+ dev_info(dev, "sn622x: settle: SoftMic still open — re-latch\n");
+ sn622x_dmic_capture_prepare(dev, sn622x, sn622x->dmic_rate,
+ false);
+ mod_delayed_work(system_wq, &sn622x->dmic_on_work,
+ msecs_to_jiffies(150));
+ }
+ /*
+ * Do not re-run speaker prepare while Speakers PCM stays open.
+ * That re-latch UNATTACHes SoftAmp, settle runs again, and the UI
+ * test tone never stays on the bus.
+ */
+}
+
+static int sn622x_sdca_update_status(struct sdw_slave *slave,
+ enum sdw_slave_status status)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
+
+ SN622X_DBG(&slave->dev, "update_status: %s hw_init=%d dev_num=%u\n",
+ sn622x_status_str(status), sn622x->hw_init, slave->dev_num);
+ SN622X_TRC(&slave->dev, "SDW status=%s (hw_init=%d)\n",
+ sn622x_status_str(status), sn622x->hw_init);
+
+ if (status == SDW_SLAVE_UNATTACHED) {
+ unsigned long prev_unattach = sn622x->last_unattach_jiffies;
+
+ sn622x->hw_init = false;
+ sn622x->last_unattach_jiffies = jiffies;
+ /*
+ * Cap CHEN is lost on flap. Do NOT clear dmic_cap_cfg_done /
+ * dmic_analog_restored here — settle SoftMic re-writing
+ * 0x2126/init table every flap chased SoftAmp into a permanent
+ * UNATTACH loop and killed Speakers. SoftMic recover only
+ * re-latches unmute/CHEN (and Cap PDE) after reattach.
+ */
+ sn622x->dmic_route_latched = false;
+ if (prev_unattach &&
+ time_before(jiffies,
+ prev_unattach + msecs_to_jiffies(2000)))
+ sn622x->unattach_storm++;
+ else
+ sn622x->unattach_storm = 1;
+ /*
+ * SoftMic recover that keeps UNATTACHing SoftAmp: stop SoftMic
+ * path so Speakers can work again (GNOME test-sound / Speakers).
+ */
+ if (sn622x->dmic_active && sn622x->unattach_storm >= 5) {
+ dev_warn(&slave->dev,
+ "sn622x: SoftAmp flap storm — abort SoftMic recover (Speakers first)\n");
+ sn622x->dmic_active = false;
+ sn622x->dmic_recover_until = 0;
+ cancel_delayed_work(&sn622x->dmic_on_work);
+ } else if (sn622x->dmic_active) {
+ sn622x->dmic_recover_until = jiffies + 2 * HZ;
+ }
+ mod_delayed_work(system_wq, &sn622x->settle_work,
+ msecs_to_jiffies(400));
+ SN622X_TRC(&slave->dev, "slave UNATTACHED: cleared hw_init\n");
+ }
+
+ if (status == SDW_SLAVE_ATTACHED) {
+ if (sn622x->unattach_storm &&
+ time_after(jiffies, sn622x->last_unattach_jiffies +
+ msecs_to_jiffies(3000)))
+ sn622x->unattach_storm = 0;
+ if (sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+ }
+
+ if (status != SDW_SLAVE_ATTACHED)
+ return 0;
+
+ if (sn622x->hw_init) {
+ dev_dbg(&slave->dev,
+ "sn622x: update_status ATTACHED: io_init already done\n");
+ return 0;
+ }
+
+ if (sn622x->first_hw_init &&
+ time_before(jiffies, sn622x->last_unattach_jiffies +
+ msecs_to_jiffies(400))) {
+ dev_info(&slave->dev,
+ "sn622x: bus flap — defer io_init until link is quiet\n");
+ mod_delayed_work(system_wq, &sn622x->settle_work,
+ msecs_to_jiffies(400));
+ return 0;
+ }
+
+ sn622x_pm_recover(&slave->dev);
+ dev_notice(&slave->dev, "sn622x: update_status ATTACHED -> io_init()\n");
+
+ SN622X_TRC(&slave->dev, "calling io_init from ATTACHED\n");
+ return sn622x_sdca_io_init(&slave->dev, slave);
+}
+
+static int sn622x_sdca_read_prop(struct sdw_slave *slave)
+{
+ struct sdw_slave_prop *prop = &slave->prop;
+ struct sdw_dpn_prop *dpn;
+ unsigned long addr;
+ unsigned int bit;
+ int nval;
+ int i, j;
+
+ sdw_slave_read_lane_mapping(slave);
+ prop->scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
+ prop->quirks = SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY;
+ prop->paging_support = true;
+ prop->use_domain_irq = true;
+ /*
+ * This link enumerates the amp as dev_num 1. Intel only programs
+ * wake SDI for dev_num >= 6, so claiming wake makes every clock
+ * restart bail out ("invalid dev_num 1") and the next PipeWire
+ * open drops SoftAmp. Playback does not need bus wake.
+ */
+ prop->wake_capable = false;
+
+ /* SN6220: speaker playback (port1) + DMIC capture (port3) only */
+ prop->source_ports = BIT(SN622X_PORT_DMIC_CAPTURE);
+ prop->sink_ports = BIT(SN622X_PORT_SPEAKER_PLAYBACK);
+
+ nval = hweight32(prop->source_ports);
+ prop->src_dpn_prop = devm_kcalloc(&slave->dev, nval,
+ sizeof(*prop->src_dpn_prop), GFP_KERNEL);
+ if (!prop->src_dpn_prop)
+ return -ENOMEM;
+ i = 0;
+ dpn = prop->src_dpn_prop;
+ addr = prop->source_ports;
+ for_each_set_bit(bit, &addr, 32) {
+ dpn[i].num = bit;
+ dpn[i].type = SDW_DPN_FULL;
+ dpn[i].simple_ch_prep_sm = true;
+ dpn[i].ch_prep_timeout = 10;
+ i++;
+ }
+ nval = hweight32(prop->sink_ports);
+ prop->sink_dpn_prop = devm_kcalloc(&slave->dev, nval,
+ sizeof(*prop->sink_dpn_prop), GFP_KERNEL);
+ if (!prop->sink_dpn_prop)
+ return -ENOMEM;
+ j = 0;
+ dpn = prop->sink_dpn_prop;
+ addr = prop->sink_ports;
+ for_each_set_bit(bit, &addr, 32) {
+ dpn[j].num = bit;
+ dpn[j].type = SDW_DPN_FULL;
+ dpn[j].simple_ch_prep_sm = true;
+ dpn[j].ch_prep_timeout = 10;
+ j++;
+ }
+ prop->clk_stop_timeout = 900;
+ /*
+ * Use MIPI simple clock-stop: avoids sdw_bus_wait_for_clk_prep_deprep()
+ * on SDW_BROADCAST_DEV_NUM (15). Kernel logs "slave:15" for that wait,
+ * not a second physical device — SN622X is typically dev_num 6 on LNL.
+ */
+ prop->simple_clk_stop_capable = true;
+ /*
+ * SN6224: DPN_LaneCtrl writes return -ENODATA
+ * (Command Ignored) and block prepare. Skip lane programming until
+ * DisCo/ACPI provides a valid lane map for this silicon.
+ */
+ prop->lane_control_support = false;
+ SN622X_DBG(&slave->dev,
+ "read_prop: src_ports=0x%x sink_ports=0x%x lane irq paging\n",
+ prop->source_ports, prop->sink_ports);
+ SN622X_TRC(&slave->dev, "read_prop: slave properties filled\n");
+
+ return 0;
+}
+
+/* PoC: clear DP0 sticky bits so bus alert handler can finish (DevNum assign). */
+static int sn622x_clear_dp0_int(struct sdw_slave *slave)
+{
+ int status, status2, ret, count = 0;
+ u8 clear, impl_int_mask;
+
+ status = sdw_read_no_pm(slave, SDW_DP0_INT);
+ if (status < 0)
+ return status;
+
+ do {
+ clear = status & ~(SDW_DP0_INTERRUPTS | SDW_DP0_SDCA_CASCADE);
+
+ if (status & SDW_DP0_INT_TEST_FAIL)
+ clear |= SDW_DP0_INT_TEST_FAIL;
+
+ if (status & SDW_DP0_INT_PORT_READY) {
+ complete(&slave->port_ready[0]);
+ clear |= SDW_DP0_INT_PORT_READY;
+ }
+
+ if (status & SDW_DP0_INT_BRA_FAILURE)
+ clear |= SDW_DP0_INT_BRA_FAILURE;
+
+ impl_int_mask = SDW_DP0_INT_IMPDEF1 | SDW_DP0_INT_IMPDEF2 |
+ SDW_DP0_INT_IMPDEF3;
+ if (status & impl_int_mask)
+ clear |= impl_int_mask;
+
+ ret = sdw_write_no_pm(slave, SDW_DP0_INT, clear);
+ if (ret < 0)
+ return ret;
+
+ status2 = sdw_read_no_pm(slave, SDW_DP0_INT);
+ if (status2 < 0)
+ return status2;
+ status &= status2;
+ count++;
+ } while ((status & SDW_DP0_INTERRUPTS) && count < 8);
+
+ return 0;
+}
+
+/*
+ * Clear SDCA INT1/2 and DP0 cascade. Pending IRQs block clock-stop prepare
+ * (SDW_SCP_STAT CLK_STP_NF never clears -> -ETIMEDOUT on slave:15).
+ */
+static int sn622x_sdca_flush_pending_irqs(struct sn622x_sdca_priv *sn622x,
+ struct device *dev)
+{
+ int ret, stat = 0;
+ int count = 0;
+ const int retry = 3;
+ unsigned int sdca_cascade, scp_sdca_stat1, scp_sdca_stat2 = 0;
+
+ if (!sn622x || !sn622x->slave)
+ return 0;
+
+ ret = sdw_read_no_pm(sn622x->slave, SDW_SCP_SDCA_INT1);
+ if (ret < 0)
+ return ret;
+ sn622x->scp_sdca_stat1 = ret;
+
+ ret = sdw_read_no_pm(sn622x->slave, SDW_SCP_SDCA_INT2);
+ if (ret < 0)
+ return ret;
+ sn622x->scp_sdca_stat2 = ret;
+
+ do {
+ ret = sdw_read_no_pm(sn622x->slave, SDW_SCP_SDCA_INT1);
+ if (ret < 0)
+ return ret;
+ if (ret & SDW_SCP_SDCA_INTMASK_SDCA_0) {
+ ret = sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INT1,
+ SDW_SCP_SDCA_INTMASK_SDCA_0);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = sdw_read_no_pm(sn622x->slave, SDW_SCP_SDCA_INT2);
+ if (ret < 0)
+ return ret;
+ if (ret & SDW_SCP_SDCA_INTMASK_SDCA_8) {
+ ret = sdw_write_no_pm(sn622x->slave, SDW_SCP_SDCA_INT2,
+ SDW_SCP_SDCA_INTMASK_SDCA_8);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = sn622x_clear_dp0_int(sn622x->slave);
+ if (ret < 0)
+ return ret;
+
+ ret = sdw_read_no_pm(sn622x->slave, SDW_DP0_INT);
+ if (ret < 0)
+ return ret;
+ sdca_cascade = ret & SDW_DP0_SDCA_CASCADE;
+
+ ret = sdw_read_no_pm(sn622x->slave, SDW_SCP_SDCA_INT1);
+ if (ret < 0)
+ return ret;
+ scp_sdca_stat1 = ret & SDW_SCP_SDCA_INTMASK_SDCA_0;
+
+ ret = sdw_read_no_pm(sn622x->slave, SDW_SCP_SDCA_INT2);
+ if (ret < 0)
+ return ret;
+ scp_sdca_stat2 = ret & SDW_SCP_SDCA_INTMASK_SDCA_8;
+
+ stat = scp_sdca_stat1 || scp_sdca_stat2 || sdca_cascade;
+ count++;
+ } while (stat != 0 && count < retry);
+
+ if (stat && dev)
+ dev_warn(dev,
+ "sn622x: SDCA IRQ flush incomplete (stat=%u)\n", stat);
+
+ return stat ? -EBUSY : 0;
+}
+
+static int sn622x_sdca_clk_stop(struct sdw_slave *slave,
+ enum sdw_clk_stop_mode mode,
+ enum sdw_clk_stop_type type)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
+
+ if (!sn622x)
+ return 0;
+
+ switch (type) {
+ case SDW_CLK_PRE_PREPARE:
+ sn622x_pwr_request_d0(&slave->dev, sn622x);
+ mutex_lock(&sn622x->disable_irq_lock);
+ sn622x_sdca_flush_pending_irqs(sn622x, &slave->dev);
+ mutex_unlock(&sn622x->disable_irq_lock);
+ dev_info(&slave->dev, "sn622x: clk_stop PRE_PREPARE done\n");
+ break;
+ case SDW_CLK_POST_DEPREPARE:
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int sn622x_sdca_interrupt_callback(struct sdw_slave *slave,
+ struct sdw_slave_intr_status *status)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
+ int ret;
+
+ if (!sn622x)
+ return 0;
+
+ /*
+ * bus.c sdw_handle_slave_alerts() expects the codec to clear SDCA INT1/2
+ * when DP0 SDCA_CASCADE is set. Skipping INT clear leaves stat!=0 ->
+ * "Reached MAX_RETRY on alert read" and dev_num never assigned.
+ */
+
+ SN622X_DBG(&slave->dev,
+ "irq: control_port=%#x sdca_cascade=%u disable_irq=%d\n",
+ status->control_port, status->sdca_cascade, sn622x->disable_irq);
+
+ mutex_lock(&sn622x->disable_irq_lock);
+
+ ret = sn622x_sdca_flush_pending_irqs(sn622x, &slave->dev);
+ if (ret < 0 && ret != -EBUSY)
+ goto io_error;
+
+ SN622X_DBG(&slave->dev, "irq: INT1=0x%x INT2=0x%x\n",
+ sn622x->scp_sdca_stat1, sn622x->scp_sdca_stat2);
+
+ mutex_unlock(&sn622x->disable_irq_lock);
+ return 0;
+
+io_error:
+ mutex_unlock(&sn622x->disable_irq_lock);
+ dev_err_ratelimited(&slave->dev, "%s: IO error (%d)\n", __func__, ret);
+ return ret;
+}
+
+static const struct sdw_slave_ops sn622x_sdca_slave_ops = {
+ .read_prop = sn622x_sdca_read_prop,
+ .interrupt_callback = sn622x_sdca_interrupt_callback,
+ .update_status = sn622x_sdca_update_status,
+ .clk_stop = sn622x_sdca_clk_stop,
+};
+
+static int sn622x_sdca_probe(struct snd_soc_component *component)
+{
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ int ret;
+
+ sn622x->component = component;
+
+ /*
+ * Card bind often races SoftAmp enumeration. SCP/Vendor reads on
+ * Slave 0 while UNATTACHED NACK the bus and can prevent DEVID assign
+ * for the whole boot. Touch the wire only when ATTACHED.
+ */
+ if (sn622x_slave_attached(sn622x->slave) && sn622x->slave->dev_num) {
+ int ret1, ret2, ret3, ret4, ret5;
+
+ ret = sdw_read_no_pm(sn622x->slave, 0x50);
+ ret1 = sdw_read_no_pm(sn622x->slave, 0x51);
+ ret2 = sdw_read_no_pm(sn622x->slave, 0x52);
+ ret3 = sdw_read_no_pm(sn622x->slave, 0x53);
+ ret4 = sdw_read_no_pm(sn622x->slave, 0x54);
+ ret5 = sdw_read_no_pm(sn622x->slave, 0x55);
+ dev_info(component->dev,
+ "sn622x_sdca_probe: SDW SCP 0x50-0x55: %x/%x/%x/%x/%x/%x\n",
+ ret, ret1, ret2, ret3, ret4, ret5);
+
+ if (sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+
+ if (sn622x_sdw_prepare_paged_access(component->dev,
+ sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS) == 0) {
+ int r_pwr;
+ unsigned int pwr = 0xffff;
+
+ r_pwr = regmap_read_bypassed(sn622x->regmap,
+ SN622X_REG_PWR_STATE, &pwr);
+ dev_info(component->dev,
+ "sn622x_sdca_probe: speaker PWR[0x%x] ret=%d val=0x%x\n",
+ SN622X_REG_PWR_STATE, r_pwr, pwr);
+ }
+ } else {
+ dev_info(component->dev,
+ "sn622x_sdca_probe: SoftAmp not ATTACHED yet — skip SCP/PWR (avoid DEVID race)\n");
+ }
+
+ SN622X_TRC(component->dev, "ASoC component probe (snd_soc)\n");
+ SN622X_DBG(component->dev, "component_probe: first_hw_init=%d\n",
+ sn622x->first_hw_init);
+
+ if (!sn622x->first_hw_init)
+ return 0;
+
+ ret = pm_runtime_resume(component->dev);
+ if (ret < 0 && ret != -EACCES)
+ return ret;
+
+ return 0;
+}
+
+static int sn622x_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_component *component = dai->component;
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ struct sdw_stream_config stream_config;
+ struct sdw_port_config port_config;
+ enum sdw_data_direction direction;
+ struct sdw_stream_runtime *sdw_stream;
+ unsigned int ch = params_channels(params);
+ int port;
+ int ret;
+ bool got_pm = false;
+
+ sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
+ if (!sdw_stream) {
+ dev_warn(dai->dev,
+ "sn622x: hw_params: no SDW stream (set_stream not run yet?)\n");
+ return -EINVAL;
+ }
+ if (!sn622x->slave) {
+ dev_warn(dai->dev, "sn622x: hw_params: slave NULL\n");
+ return -EINVAL;
+ }
+ /*
+ * PipeWire opens Speakers/Mic at login before SoftAmp enumerates.
+ * Fail fast — do not poll 2s or program ports while UNATTACHED
+ * (that NACKs Slave 0 and blocks DEVID for the whole boot).
+ */
+ /*
+ * -EAGAIN makes PipeWire retry the open forever and gnome-control-center
+ * / Audacity block on the Pulse stream. -ENODEV fails the node once.
+ */
+ if (!sn622x_slave_attached(sn622x->slave)) {
+ dev_err_ratelimited(dai->dev,
+ "sn622x: hw_params: SoftAmp UNATTACHED\n");
+ return -ENODEV;
+ }
+
+ dev_info(dai->dev,
+ "sn622x: hw_params: entered dai=%s id=%d stream=%s\n",
+ dai->name, dai->id, snd_pcm_stream_str(substream));
+
+ /*
+ * Resume before diag/stream: runtime suspend leaves regcache_cache_only(true);
+ * bypassed reads still behave better with an active runtime count.
+ */
+ ret = pm_runtime_resume_and_get(component->dev);
+ if (ret < 0 && ret != -EACCES) {
+ dev_err(dai->dev,
+ "sn622x: hw_params: pm_runtime_resume_and_get failed (%d)\n",
+ ret);
+ return ret;
+ }
+ if (ret == 0)
+ got_pm = true;
+
+ if (sn622x->hw_init)
+ sn622x_log_power_mode_once(dai->dev, sn622x);
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ direction = SDW_DATA_DIR_RX;
+ if (dai->id == SN622X_DAI_SPEAKER) {
+ /*
+ * SN6220: single amp path (regs from sn6220.txt).
+ * External HW muxes HP vs speaker — no jack DAI.
+ */
+ sn622x_hw_params_speaker_playback(dai, substream, sn622x);
+ port = SN622X_PORT_SPEAKER_PLAYBACK;
+ } else {
+ ret = -EINVAL;
+ goto out;
+ }
+ } else {
+ direction = SDW_DATA_DIR_TX;
+ if (dai->id == SN622X_DAI_DMIC) {
+ port = SN622X_PORT_DMIC_CAPTURE;
+ sn622x_hw_params_dmic_capture(dai, substream, sn622x);
+ } else {
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
+ /*
+ * SoftMic/Speakers rate regs stay at 48 kHz. SOF still opens as
+ * S24_LE often — accept it so Audacity is not stuck on -EINVAL.
+ * Prefer 16-bit on the SoundWire port when the host asks for S16.
+ */
+ if (params_rate(params) != 48000) {
+ dev_info(dai->dev,
+ "sn622x: hw_params: need 48 kHz (got %u)\n",
+ params_rate(params));
+ ret = -EINVAL;
+ goto out;
+ }
+
+ stream_config.frame_rate = 48000;
+ stream_config.ch_count = ch;
+ stream_config.bps = snd_pcm_format_width(params_format(params));
+ if (stream_config.bps > 16 &&
+ params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
+ stream_config.bps = 16;
+ stream_config.direction = direction;
+ port_config.ch_mask = GENMASK(ch - 1, 0);
+ port_config.num = port;
+
+ dev_info(dai->dev,
+ "sn622x: hw_params: %s dai=\"%s\" id=%d format=0x%x rate=%u Hz ch=%u "
+ "bits=%u phys_bits=%u frame_bits=%u period=%u periods=%u buf=%u "
+ "sdw port=%d dir=%s fr=%u ch_count=%u bps=%u ch_mask=0x%x\n",
+ snd_pcm_stream_str(substream), dai->name, dai->id,
+ params_format(params),
+ params_rate(params), ch,
+ snd_pcm_format_width(params_format(params)),
+ params_physical_width(params), params_width(params),
+ params_period_size(params), params_periods(params),
+ params_buffer_size(params),
+ port, direction == SDW_DATA_DIR_RX ? "RX(host->codec)" : "TX(codec->host)",
+ stream_config.frame_rate, stream_config.ch_count, stream_config.bps,
+ port_config.ch_mask);
+
+ ret = sdw_stream_add_slave(sn622x->slave, &stream_config,
+ &port_config, 1, sdw_stream);
+
+ if (ret) {
+ dev_err(dai->dev, "%s: sdw_stream_add_slave port %d failed: %d\n",
+ __func__, port, ret);
+ goto out;
+ }
+
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+ dai->id == SN622X_DAI_SPEAKER) {
+ sn622x->playback_active |= SN622X_PB_ACTIVE_SPK;
+ /* D0 + unmute + CHEN=0x3 (external HP/SPK mux uses same path) */
+ sn622x_speaker_playback_prepare(dai->dev, sn622x);
+ } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
+ dai->id == SN622X_DAI_DMIC) {
+ /*
+ * Audacity opens this PCM while scanning devices, then
+ * closes it without TRIGGER_START. Parking Speakers in D3
+ * on that probe makes the next solo playback UNATTACH.
+ * SoftMic registers run from TRIGGER_START / dmic_on_work.
+ */
+ sn622x->dmic_route_latched = false;
+ sn622x->dmic_rate = params_rate(params);
+ dev_info(dai->dev,
+ "sn622x: capture port %d ready — SoftMic setup waits for trigger\n",
+ port);
+ }
+out:
+ if (got_pm) {
+ pm_runtime_mark_last_busy(component->dev);
+ pm_runtime_put_autosuspend(component->dev);
+ }
+ return ret;
+}
+
+static int sn622x_sdca_pcm_hw_free(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_component *component = dai->component;
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ struct sdw_stream_runtime *sdw_stream =
+ snd_soc_dai_get_dma_data(dai, substream);
+ int port;
+ bool got_pm = false;
+ int ret;
+
+ if (!sn622x->slave)
+ return -EINVAL;
+
+ port = sn622x_hw_params_port(dai, substream);
+ if (port < 0)
+ return port;
+
+ ret = pm_runtime_resume_and_get(component->dev);
+ if (ret < 0 && ret != -EACCES)
+ return ret;
+ if (ret == 0)
+ got_pm = true;
+
+
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
+ dai->id == SN622X_DAI_DMIC) {
+ sn622x->dmic_active = false;
+ sn622x->dmic_route_latched = false;
+ sn622x->dmic_recover_until = 0;
+ cancel_delayed_work_sync(&sn622x->dmic_on_work);
+ }
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
+ dai->id == SN622X_DAI_SPEAKER) {
+ sn622x->playback_active &= ~SN622X_PB_ACTIVE_SPK;
+ cancel_delayed_work_sync(&sn622x->spk_chen_work);
+ }
+
+ sdw_stream_remove_slave(sn622x->slave, sdw_stream);
+
+ sn622x_port_teardown_d3_mute(dai->dev, sn622x, port, false);
+
+ /*
+ * SoftMic parked Speakers in D3 — restore Speakers (D0 + charge
+ * pump + CHEN). Skip if SoftMic never parked Speakers (e.g. refused
+ * while Speakers were already open).
+ */
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
+ dai->id == SN622X_DAI_DMIC &&
+ sn622x->spk_parked_for_dmic &&
+ sn622x_slave_attached(sn622x->slave)) {
+ sn622x->spk_parked_for_dmic = false;
+ sn622x_speaker_playback_prepare(dai->dev, sn622x);
+ }
+
+ if (got_pm) {
+ pm_runtime_mark_last_busy(component->dev);
+ pm_runtime_put_autosuspend(component->dev);
+ }
+ return 0;
+}
+
+static int sn622x_sdca_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
+ int direction)
+{
+ snd_soc_dai_dma_data_set(dai, direction, sdw_stream);
+ return 0;
+}
+
+static void sn622x_sdca_shutdown(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ snd_soc_dai_set_dma_data(dai, substream, NULL);
+}
+
+/*
+ * Speaker + DMIC only. Headphone insert and the HP/speaker analog mux are
+ * outside this driver (see sn6220.txt). Card widgets "Speaker" and "DMIC"
+ * connect to the prefixed endpoints "sn622x SPK" and "sn622x DMIC".
+ */
+/*
+ * SoftMic DAPM is a passthrough. REG widgets that write MUTE/PDE on every
+ * stream start/stop raced SoftMic prepare and SoftAmp after a few Audacity
+ * record cycles. Power/mute/CHEN are owned by sn622x_dmic_capture_prepare().
+ */
+static const struct snd_soc_dapm_widget sn622x_sdca_dapm_widgets[] = {
+ SND_SOC_DAPM_AIF_IN("SPK RX", "Speaker Playback", 0, SND_SOC_NOPM, 0, 0),
+ SND_SOC_DAPM_AIF_OUT("DMIC TX", "DMic Capture", 0, SND_SOC_NOPM, 0, 0),
+ SND_SOC_DAPM_OUTPUT("SPK"),
+ SND_SOC_DAPM_INPUT("DMIC"),
+};
+
+static const struct snd_soc_dapm_route sn622x_sdca_audio_map[] = {
+ { "SPK", NULL, "SPK RX" },
+ { "DMIC TX", NULL, "DMIC" },
+};
+
+static int sn622x_sdca_trigger(struct snd_pcm_substream *substream, int cmd,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_component *component = dai->component;
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ bool got_pm = false;
+ int ret;
+
+ /*
+ * hw_params already latched Speakers and queued spk_chen_work.
+ * Writing CHEN again from TRIGGER_START, as the port is enabled,
+ * flaps SoftAmp. SoftMic still retries PDE after the port is moving.
+ */
+ if (cmd != SNDRV_PCM_TRIGGER_START &&
+ cmd != SNDRV_PCM_TRIGGER_RESUME &&
+ cmd != SNDRV_PCM_TRIGGER_PAUSE_RELEASE)
+ return 0;
+
+ ret = pm_runtime_resume_and_get(component->dev);
+ if (ret < 0 && ret != -EACCES)
+ return ret;
+ if (ret == 0)
+ got_pm = true;
+
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
+ dai->id == SN622X_DAI_DMIC) {
+ sn622x->dmic_rate = substream->runtime->rate;
+ sn622x->dmic_active = true;
+ sn622x_dmic_capture_prepare(dai->dev, sn622x, sn622x->dmic_rate,
+ false);
+ schedule_delayed_work(&sn622x->dmic_on_work,
+ msecs_to_jiffies(200));
+ }
+
+ if (got_pm) {
+ pm_runtime_mark_last_busy(component->dev);
+ pm_runtime_put_autosuspend(component->dev);
+ }
+ return 0;
+}
+
+static const struct snd_soc_dai_ops sn622x_sdca_ops = {
+ .hw_params = sn622x_sdca_pcm_hw_params,
+ .hw_free = sn622x_sdca_pcm_hw_free,
+ .trigger = sn622x_sdca_trigger,
+ .set_stream = sn622x_sdca_set_sdw_stream,
+ .shutdown = sn622x_sdca_shutdown,
+};
+
+static struct snd_soc_dai_driver sn622x_sdca_dai[] = {
+ {
+ .name = "sn622x-sdca-aif",
+ .id = SN622X_DAI_SPEAKER,
+ .playback = {
+ .stream_name = "Speaker Playback",
+ .channels_min = 1,
+ .channels_max = 2,
+ .rates = SN622X_STEREO_RATES,
+ .formats = SN622X_FORMATS,
+ },
+ .ops = &sn622x_sdca_ops,
+ },
+ {
+ .name = "sn622x-sdca-aif2",
+ .id = SN622X_DAI_DMIC,
+ .capture = {
+ .stream_name = "DMic Capture",
+ .channels_min = 1,
+ .channels_max = 4,
+ .rates = SN622X_STEREO_RATES,
+ .formats = SN622X_FORMATS,
+ },
+ .ops = &sn622x_sdca_ops,
+ },
+};
+
+static int sn622x_pwr_state_pm_get(struct snd_soc_component *component, bool *got_pm)
+{
+ int ret;
+
+ *got_pm = false;
+ ret = pm_runtime_resume_and_get(component->dev);
+ if (ret < 0 && ret != -EACCES)
+ return ret;
+ if (ret == 0)
+ *got_pm = true;
+ return 0;
+}
+
+static void sn622x_pwr_state_pm_put(struct snd_soc_component *component, bool got_pm)
+{
+ if (got_pm) {
+ pm_runtime_mark_last_busy(component->dev);
+ pm_runtime_put_autosuspend(component->dev);
+ }
+}
+
+/* Vendor Reg Address: value[1] 0=read 1=write; legacy 2-arg cset addr val => write */
+#define SN622X_VENDOR_REG_RW_READ 0
+#define SN622X_VENDOR_REG_RW_WRITE 1
+
+/*
+ * Card exposes these as "sn622x Vendor Reg …" (component name prefix).
+ *
+ * Vendor Reg Addr (count=1): cache only.
+ * amixer -c0 cset name='sn622x Vendor Reg Addr' 0x40400418
+ *
+ * Vendor Reg Address (count=3): [reg_addr, rw, data]
+ * read HW: amixer -c0 cset name='sn622x Vendor Reg Address' 0x40400418,0,0
+ * (then: dmesg | grep 'Vendor Reg Address read')
+ * write HW: amixer -c0 cset name='sn622x Vendor Reg Address' 0x40400418,1,6
+ * legacy write (2 numbers): amixer -c0 cset name='sn622x Vendor Reg Address' 0x40400418,6
+ * (rw omitted: value[1]=6, value[2]=0 -> treated as write data)
+ * amixer cget only returns the last cached tuple — no SoftAmp bus I/O.
+ *
+ * Vendor Reg Address write 1 (count=1): data byte 1 cannot be passed through
+ * the 3-value control (tinymix treats 1 as the write flag, then .get() clears
+ * it before the data slot is applied). The only integer is the register address;
+ * .put always writes 0x01.
+ * tinymix set "sn622x Vendor Reg Address write 1" 0x40400418
+ */
+static int sn622x_vendor_reg_cache_info(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 1;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 0xffffffff;
+ return 0;
+}
+
+static int sn622x_vendor_reg_cache_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+
+ if (!component || !sn622x)
+ return -ENODEV;
+
+ ucontrol->value.integer.value[0] = sn622x->vendor_reg_addr;
+ return 0;
+}
+
+static int sn622x_vendor_reg_cache_put(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ u32 addr = (u32)ucontrol->value.integer.value[0];
+
+ if (!component || !sn622x)
+ return -ENODEV;
+ if (!addr)
+ return -EINVAL;
+
+ sn622x->vendor_reg_addr = addr;
+ dev_dbg(component->dev, "sn622x: vendor_reg_addr cache set to 0x%08x\n", addr);
+ return 0;
+}
+
+static int sn622x_vendor_reg_addr_info(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ uinfo->count = 3;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = 0xffffffff;
+ return 0;
+}
+
+static int sn622x_vendor_reg_hw_access(struct snd_soc_component *component,
+ struct sn622x_sdca_priv *sn622x,
+ u32 addr, bool write, unsigned int wval,
+ unsigned int *rval)
+{
+ bool got_pm;
+ int ret;
+
+ ret = sn622x_pwr_state_pm_get(component, &got_pm);
+ if (ret < 0)
+ return ret;
+
+ if (sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+
+ ret = sn622x_sdw_prepare_paged_access(component->dev, sn622x->slave,
+ false, SN622X_PAGED_QUICK_MS);
+ if (ret < 0)
+ goto out_pm;
+
+ if (write) {
+ struct reg_sequence wr = REG_SEQ0(addr, wval & 0xffu);
+
+ ret = regmap_multi_reg_write_bypassed(sn622x->regmap, &wr, 1);
+ } else {
+ ret = regmap_read_bypassed(sn622x->regmap, addr, rval);
+ }
+
+out_pm:
+ sn622x_pwr_state_pm_put(component, got_pm);
+ return ret;
+}
+
+static int sn622x_vendor_reg_addr_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ u32 addr = (u32)ucontrol->value.integer.value[0];
+
+ if (!component || !sn622x)
+ return -ENODEV;
+
+ if (!addr)
+ addr = sn622x->vendor_reg_addr;
+
+ /*
+ * No SCP access here: amixer cset always snd_ctl_elem_read() before write.
+ * A failing bus read in .get() makes cset abort with "Cannot read the given
+ * element". Hardware read/write is done only in .put (cset).
+ */
+ ucontrol->value.integer.value[0] = addr;
+ ucontrol->value.integer.value[1] = SN622X_VENDOR_REG_RW_READ;
+ ucontrol->value.integer.value[2] = 0;
+ return 0;
+}
+
+static int sn622x_vendor_reg_addr_put(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ u32 addr = (u32)ucontrol->value.integer.value[0];
+ unsigned int rw = ucontrol->value.integer.value[1];
+ unsigned int data = ucontrol->value.integer.value[2] & 0xffu;
+ unsigned int rval = 0;
+ bool do_write;
+ int ret;
+
+ if (!component || !sn622x || !sn622x->regmap || !sn622x->slave) {
+ pr_err("sn622x: Vendor Reg Address cset: driver not ready\n");
+ return -ENODEV;
+ }
+ if (!sn622x_slave_attached(sn622x->slave)) {
+ dev_warn_ratelimited(component->dev,
+ "sn622x: Vendor Reg Address: SoftAmp not ATTACHED\n");
+ return -ENODEV;
+ }
+
+ if (!addr) {
+ dev_err(component->dev,
+ "sn622x: Vendor Reg Address cset: reg addr must be non-zero\n");
+ return -EINVAL;
+ }
+
+ sn622x->vendor_reg_addr = addr;
+
+ if (rw == SN622X_VENDOR_REG_RW_READ) {
+ do_write = false;
+ } else if (rw == SN622X_VENDOR_REG_RW_WRITE) {
+ do_write = true;
+ } else {
+ /* Legacy: amixer cset name='...' <addr>,<value> (only two numbers). */
+ do_write = true;
+ data = rw & 0xffu;
+ }
+
+ dev_info(component->dev,
+ "sn622x: Vendor Reg Address cset: addr=0x%08x rw=%u data=0x%x (%s)\n",
+ addr, rw, data, do_write ? "write" : "read");
+
+ ret = sn622x_vendor_reg_hw_access(component, sn622x, addr, do_write,
+ data, &rval);
+ if (ret < 0) {
+ dev_err(component->dev,
+ "sn622x: Vendor Reg Address %s addr=0x%08x failed (%d)\n",
+ do_write ? "write" : "read", addr, ret);
+ return ret;
+ }
+
+ if (do_write)
+ dev_info(component->dev,
+ "sn622x: Vendor Reg Address write addr=0x%08x val=0x%x ok\n",
+ addr, data);
+ else
+ dev_info(component->dev,
+ "sn622x: Vendor Reg Address read addr=0x%08x val=0x%x ok\n",
+ addr, rval & 0xffu);
+
+ return 0;
+}
+
+/* tinymix sets one integer: the address. Always writes 0x01 there. */
+static int sn622x_vendor_reg_write1_put(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct sn622x_sdca_priv *sn622x = snd_soc_component_get_drvdata(component);
+ u32 addr = (u32)ucontrol->value.integer.value[0];
+ unsigned int rval = 0;
+ int ret;
+
+ if (!component || !sn622x || !sn622x->regmap || !sn622x->slave) {
+ pr_err("sn622x: Vendor Reg Address write 1: driver not ready\n");
+ return -ENODEV;
+ }
+ if (!sn622x_slave_attached(sn622x->slave)) {
+ dev_warn_ratelimited(component->dev,
+ "sn622x: Vendor Reg Address write 1: SoftAmp not ATTACHED\n");
+ return -ENODEV;
+ }
+ if (!addr) {
+ dev_err(component->dev,
+ "sn622x: Vendor Reg Address write 1: reg addr must be non-zero\n");
+ return -EINVAL;
+ }
+
+ sn622x->vendor_reg_addr = addr;
+ dev_info(component->dev,
+ "sn622x: Vendor Reg Address write 1: addr=0x%08x data=0x1 (write)\n",
+ addr);
+
+ ret = sn622x_vendor_reg_hw_access(component, sn622x, addr, true, 1, &rval);
+ if (ret < 0) {
+ dev_err(component->dev,
+ "sn622x: Vendor Reg Address write 1 addr=0x%08x failed (%d)\n",
+ addr, ret);
+ return ret;
+ }
+
+ dev_info(component->dev,
+ "sn622x: Vendor Reg Address write addr=0x%08x val=0x1 ok\n",
+ addr);
+ return 0;
+}
+
+static const struct snd_kcontrol_new sn622x_sdca_controls[] = {
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Vendor Reg Addr",
+ .info = sn622x_vendor_reg_cache_info,
+ .get = sn622x_vendor_reg_cache_get,
+ .put = sn622x_vendor_reg_cache_put,
+ },
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Vendor Reg Address",
+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+ .info = sn622x_vendor_reg_addr_info,
+ .get = sn622x_vendor_reg_addr_get,
+ .put = sn622x_vendor_reg_addr_put,
+ },
+ {
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ .name = "Vendor Reg Address write 1",
+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
+ .info = sn622x_vendor_reg_cache_info,
+ .get = sn622x_vendor_reg_cache_get,
+ .put = sn622x_vendor_reg_write1_put,
+ },
+};
+
+static const struct snd_soc_component_driver soc_sdca_dev_sn622x = {
+ .probe = sn622x_sdca_probe,
+ .controls = sn622x_sdca_controls,
+ .num_controls = ARRAY_SIZE(sn622x_sdca_controls),
+ .dapm_widgets = sn622x_sdca_dapm_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(sn622x_sdca_dapm_widgets),
+ .dapm_routes = sn622x_sdca_audio_map,
+ .num_dapm_routes = ARRAY_SIZE(sn622x_sdca_audio_map),
+ /* SN6220: no jack detect — HP path switched externally */
+ .set_jack = NULL,
+ .endianness = 1,
+};
+
+static void sn622x_spk_chen_work(struct work_struct *work)
+{
+ /* Kept for cancel/init; Speakers CHEN is only written in prepare. */
+ (void)work;
+}
+
+static void sn622x_dmic_on_work(struct work_struct *work)
+{
+ struct sn622x_sdca_priv *sn622x =
+ container_of(work, struct sn622x_sdca_priv, dmic_on_work.work);
+ struct device *dev;
+ bool got_pm = false;
+ bool need_retry;
+ int ret;
+
+ if (!sn622x->slave || !sn622x->dmic_active)
+ return;
+
+ dev = &sn622x->slave->dev;
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret < 0 && ret != -EACCES)
+ return;
+ if (ret == 0)
+ got_pm = true;
+
+ /*
+ * SoftMic Cap PDE often stays D3 until the capture port is moving.
+ * After HP insert SoftAmp flaps mid-record: keep verifying SoftMic
+ * health for dmic_recover_until even if a prior latch looked OK.
+ */
+ need_retry = sn622x->dmic_active &&
+ (!sn622x->dmic_route_latched ||
+ time_before(jiffies, sn622x->dmic_recover_until));
+
+ if (need_retry && sn622x_slave_attached(sn622x->slave)) {
+ if (sn622x_sdw_prepare_paged_access(dev, sn622x->slave, false,
+ SN622X_PAGED_QUICK_MS) == 0)
+ sn622x_dmic_capture_prepare(dev, sn622x,
+ sn622x->dmic_rate, false);
+ if (sn622x->dmic_active &&
+ (!sn622x->dmic_route_latched ||
+ time_before(jiffies, sn622x->dmic_recover_until)))
+ mod_delayed_work(system_wq, &sn622x->dmic_on_work,
+ msecs_to_jiffies(150));
+ }
+
+ if (got_pm) {
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
+ }
+}
+
+int sn622x_sdca_init(struct device *dev, struct regmap *regmap,
+ struct regmap *mbq_regmap, struct sdw_slave *slave)
+{
+ struct sn622x_sdca_priv *sn622x;
+ int ret;
+
+ sn622x = devm_kzalloc(dev, sizeof(*sn622x), GFP_KERNEL);
+ if (!sn622x)
+ return -ENOMEM;
+
+ dev_set_drvdata(dev, sn622x);
+ sn622x->slave = slave;
+ sn622x->regmap = regmap;
+ sn622x->mbq_regmap = mbq_regmap;
+ sn622x->vendor_reg_addr = SN622X_REG_PWR_STATE;
+
+ mutex_init(&sn622x->disable_irq_lock);
+ mutex_init(&sn622x->path_lock);
+ INIT_DELAYED_WORK(&sn622x->dmic_on_work, sn622x_dmic_on_work);
+ INIT_DELAYED_WORK(&sn622x->spk_chen_work, sn622x_spk_chen_work);
+ INIT_DELAYED_WORK(&sn622x->settle_work, sn622x_settle_work);
+
+ regcache_cache_only(sn622x->regmap, true);
+ regcache_cache_only(sn622x->mbq_regmap, true);
+
+ ret = devm_snd_soc_register_component(dev,
+ &soc_sdca_dev_sn622x, sn622x_sdca_dai,
+ ARRAY_SIZE(sn622x_sdca_dai));
+ if (ret < 0)
+ return ret;
+
+ pm_runtime_set_autosuspend_delay(dev, 3000);
+ pm_runtime_use_autosuspend(dev);
+ pm_runtime_mark_last_busy(dev);
+ /*
+ * Fresh probe: disable_depth is already 1. Only disable when a previous
+ * instance left runtime_error set, then enable exactly once.
+ */
+ if (dev->power.runtime_error)
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+ pm_runtime_enable(dev);
+
+ SN622X_TRC(dev, "snd_soc_register_component OK (DAI sn622x-sdca-aif)\n");
+ return 0;
+}
+
+static int sn622x_sdca_sdw_probe(struct sdw_slave *slave,
+ const struct sdw_device_id *id)
+{
+ struct regmap *regmap, *mbq_regmap;
+ int ret;
+
+ SN622X_TRC(&slave->dev,
+ "SoundWire probe: mfg=0x%x part=0x%x sdw_version=%u class=%u\n",
+ id->mfg_id, id->part_id, id->sdw_version, id->class_id);
+ SN622X_DBG(&slave->dev, "sdw_probe: dev_num=%u status=%s\n",
+ slave->dev_num, sn622x_status_str(slave->status));
+
+ /*
+ * read_prop runs once at slave add; force again on driver bind so a
+ * module reload picks up lane_control_support=false without reboot.
+ */
+ slave->prop.lane_control_support = false;
+
+ mbq_regmap = devm_regmap_init_sdw_mbq(slave, &sn622x_sdca_mbq_regmap);
+ if (IS_ERR(mbq_regmap)) {
+ dev_err(&slave->dev, "sn622x: devm_regmap_init_sdw_mbq failed (%ld)\n",
+ PTR_ERR(mbq_regmap));
+ return PTR_ERR(mbq_regmap);
+ }
+
+ regmap = devm_regmap_init_sdw(slave, &sn622x_sdca_regmap);
+ if (IS_ERR(regmap)) {
+ dev_err(&slave->dev, "sn622x: devm_regmap_init_sdw failed (%ld)\n",
+ PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
+ ret = sn622x_sdca_init(&slave->dev, regmap, mbq_regmap, slave);
+ if (ret < 0)
+ dev_err(&slave->dev, "sn622x: sn622x_sdca_init failed (%d)\n", ret);
+ else {
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
+
+ if (sn622x && sn622x_mask_sdca_irqs)
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+ SN622X_TRC(&slave->dev, "SoundWire probe finished OK\n");
+ }
+
+ return ret;
+}
+
+static void sn622x_sdca_sdw_remove(struct sdw_slave *slave)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(&slave->dev);
+
+ SN622X_TRC(&slave->dev, "SoundWire driver remove\n");
+ sn622x->dmic_active = false;
+ cancel_delayed_work_sync(&sn622x->dmic_on_work);
+ cancel_delayed_work_sync(&sn622x->spk_chen_work);
+ cancel_delayed_work_sync(&sn622x->settle_work);
+ if (sn622x->first_hw_init)
+ pm_runtime_disable(&slave->dev);
+ mutex_destroy(&sn622x->disable_irq_lock);
+}
+
+static const struct sdw_device_id sn622x_sdca_id[] = {
+ /*
+ * SN6220: 0x184c and 0x6220. SN6224: 0x1850 and 0x6224.
+ * 0x6220/0x6224 follow SN624x (0x6244) part_id naming; not 0x1864 (SN624x).
+ */
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x184c, 0x3, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x184c, 0x0, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x6220, 0x3, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x6220, 0x0, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x1850, 0x3, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x1850, 0x0, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x6224, 0x3, 0x1, 0),
+ SDW_SLAVE_ENTRY_EXT(0x0496, 0x6224, 0x0, 0x1, 0),
+ {},
+};
+MODULE_DEVICE_TABLE(sdw, sn622x_sdca_id);
+
+static int sn622x_sdca_dev_suspend(struct device *dev)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(dev);
+
+ if (!sn622x->first_hw_init)
+ return 0;
+
+ SN622X_DBG(dev, "runtime suspend\n");
+
+ regcache_cache_only(sn622x->regmap, true);
+ regcache_cache_only(sn622x->mbq_regmap, true);
+
+ return 0;
+}
+
+static int sn622x_sdca_dev_system_suspend(struct device *dev)
+{
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(dev);
+
+ if (!sn622x->first_hw_init)
+ return 0;
+
+ SN622X_DBG(dev, "system suspend: mask SDCA IRQs\n");
+ mutex_lock(&sn622x->disable_irq_lock);
+ sn622x->disable_irq = true;
+ sn622x_sdca_sdca_irq_mask_all(sn622x);
+ mutex_unlock(&sn622x->disable_irq_lock);
+
+ return sn622x_sdca_dev_suspend(dev);
+}
+
+static int sn622x_sdca_dev_resume(struct device *dev)
+{
+ struct sdw_slave *slave = dev_to_sdw_dev(dev);
+ struct sn622x_sdca_priv *sn622x = dev_get_drvdata(dev);
+ unsigned long time;
+
+ if (!sn622x->first_hw_init)
+ return 0;
+
+ SN622X_DBG(dev, "resume: unattach_request=%u status=%s\n",
+ slave->unattach_request, sn622x_status_str(slave->status));
+ /*
+ * A failed runtime resume is stored as runtime_error. Later PCM opens
+ * then get -EINVAL forever, and PipeWire retries until Audacity and
+ * GNOME Sound Settings hang. If the link is down, leave the device
+ * resumed in cache-only mode instead of failing.
+ */
+ if (slave->unattach_request && !sn622x_slave_attached(slave)) {
+ time = wait_for_completion_timeout(&slave->initialization_complete,
+ msecs_to_jiffies(500));
+ if (!time)
+ dev_info(dev,
+ "sn622x: resume: SoftAmp not attached — skip sync\n");
+ } else if (slave->unattach_request) {
+ time = wait_for_completion_timeout(&slave->initialization_complete,
+ msecs_to_jiffies(1500));
+ if (!time)
+ dev_info(dev, "sn622x: resume: init still pending\n");
+ }
+
+ mutex_lock(&sn622x->disable_irq_lock);
+ sn622x->disable_irq = false;
+ mutex_unlock(&sn622x->disable_irq_lock);
+
+ slave->unattach_request = 0;
+ if (!sn622x_slave_attached(slave))
+ return 0;
+
+ /*
+ * Playback/prepare use regmap_*_bypassed(), so the maple cache is not
+ * the device. Syncing it on resume writes stale defaults over a live
+ * SoftAmp and the next PipeWire open (after the 3s autosuspend) drops
+ * the link. Leave the cache inactive and let prepare program the amp.
+ */
+ regcache_cache_only(sn622x->regmap, false);
+ regcache_cache_only(sn622x->mbq_regmap, false);
+
+ return 0;
+}
+
+static const struct dev_pm_ops sn622x_sdca_pm = {
+ SYSTEM_SLEEP_PM_OPS(sn622x_sdca_dev_system_suspend, sn622x_sdca_dev_resume)
+ RUNTIME_PM_OPS(sn622x_sdca_dev_suspend, sn622x_sdca_dev_resume, NULL)
+};
+
+static struct sdw_driver sn622x_sdca_sdw_driver = {
+ .driver = {
+ .name = "sn622x-sdca",
+ .pm = pm_ptr(&sn622x_sdca_pm),
+ },
+ .probe = sn622x_sdca_sdw_probe,
+ .remove = sn622x_sdca_sdw_remove,
+ .ops = &sn622x_sdca_slave_ops,
+ .id_table = sn622x_sdca_id,
+};
+module_sdw_driver(sn622x_sdca_sdw_driver);
+
+MODULE_DESCRIPTION("ASoC SN622X SDCA SoundWire driver speaker+DMIC (no jack detect; HP mux external)");
+MODULE_AUTHOR("Senary Semiconductor Corp.");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/sn622x-sdca.h b/sound/soc/codecs/sn622x-sdca.h
new file mode 100644
index 000000000..8aac4ba8f
--- /dev/null
+++ b/sound/soc/codecs/sn622x-sdca.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * sn622x-sdca.h -- SN622X (SN6220) SDCA ALSA SoC audio driver header
+ * SN6220: speaker + SoftMic/DMIC only. No jack detect; HP mux is external.
+ *
+ * Copyright(c) 2025 Senary Semiconductor Corp.
+ */
+
+#ifndef __SN622X_SDCA_H__
+#define __SN622X_SDCA_H__
+
+#include <linux/bits.h>
+#include <linux/mutex.h>
+#include <linux/soundwire/sdw.h>
+#include <linux/workqueue.h>
+#include <sound/soc.h>
+
+struct sn622x_sdca_priv {
+ struct regmap *regmap;
+ struct regmap *mbq_regmap;
+ struct snd_soc_component *component;
+ struct sdw_slave *slave;
+ bool hw_init;
+ bool first_hw_init;
+ struct delayed_work dmic_on_work;
+ struct delayed_work spk_chen_work; /* rewrite CHEN after stream is up */
+ struct delayed_work settle_work; /* one io_init after a jack/bus flap */
+ unsigned long last_unattach_jiffies;
+ unsigned int dmic_rate;
+ bool dmic_active;
+ bool dmic_route_latched; /* SoftMic PDE D0 + unmute/CHEN applied this capture */
+ bool dmic_cap_cfg_done; /* SoftMic rate/vol written since last SoftAmp ATTACH */
+ bool dmic_analog_restored; /* SoftMic init table done (keep across brief UNATTACH) */
+ bool spk_parked_for_dmic; /* SoftMic muted+D3 Speakers; restore on SoftMic hw_free */
+ unsigned long dmic_recover_until; /* jiffies: SoftMic health retries after flap */
+ unsigned int unattach_storm; /* consecutive SoftAmp flaps; abort SoftMic recover */
+ struct mutex path_lock; /* SoftMic/speaker prepare vs teardown vs io_init */
+ struct mutex disable_irq_lock;
+ bool disable_irq;
+ unsigned int playback_active; /* SN622X_PB_ACTIVE_* while PCM open */
+ unsigned int scp_sdca_stat1;
+ unsigned int scp_sdca_stat2;
+ u8 last_dev_num; /* restore after transient ALERT drops dev_num */
+ unsigned int vendor_reg_addr;
+};
+
+/*
+ * SoundWire data port numbers (SN6220: speaker port 1, DMIC/SoftMic port 3).
+ */
+#define SN622X_PORT_SPEAKER_PLAYBACK 1
+#define SN622X_PORT_DMIC_CAPTURE 3
+
+/* Order matches sn622x_sdca_dai[] .id — speaker + dmic only */
+enum sn622x_dai_id {
+ SN622X_DAI_SPEAKER = 0,
+ SN622X_DAI_DMIC = 1,
+};
+
+/* playback_active bits (set in hw_params, cleared in hw_free) */
+#define SN622X_PB_ACTIVE_SPK BIT(0)
+
+/* µs settle times for path prepare */
+#define SN622X_ROUTE_AFTER_MUTE_US_MIN 5000
+#define SN622X_ROUTE_AFTER_MUTE_US_MAX 8000
+#define SN622X_ROUTE_AFTER_D3_US_MIN 10000
+#define SN622X_ROUTE_AFTER_D3_US_MAX 15000
+#define SN622X_ROUTE_BEFORE_ACTIVE_US_MIN 10000
+#define SN622X_ROUTE_BEFORE_ACTIVE_US_MAX 15000
+#define SN622X_UAJ_DMIC_PPU11 0x40880380 // = 0x30
+
+/*
+ * Rate locked to 48 kHz (SoftMic RATE_SEL=1, Speakers RATE_SEL=1).
+ * Formats must still include S24_LE: SOF opens Speakers/Mic as S24 and
+ * rejecting it hangs Audacity / PipeWire. Prefer S16 when the host asks.
+ */
+#define SN622X_STEREO_RATES SNDRV_PCM_RATE_48000
+#define SN622X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
+ SNDRV_PCM_FMTBIT_S24_LE)
+
+int sn622x_sdca_init(struct device *dev, struct regmap *regmap,
+ struct regmap *mbq_regmap, struct sdw_slave *slave);
+
+#endif /* __SN622X_SDCA_H__ */
diff --git a/sound/soc/intel/common/soc-acpi-intel-nvl-match.c b/sound/soc/intel/common/soc-acpi-intel-nvl-match.c
index 4a67f6b72..4f0b4aa5d 100644
--- a/sound/soc/intel/common/soc-acpi-intel-nvl-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-nvl-match.c
@@ -9,6 +9,7 @@
#include <sound/soc-acpi.h>
#include <sound/soc-acpi-intel-match.h>
#include <sound/soc-acpi-intel-ssp-common.h>
+#include "sof-function-topology-lib.h"
#include "soc-acpi-intel-sdw-mockup-match.h"
static const struct snd_soc_acpi_codecs nvl_essx_83x6 = {
@@ -66,6 +67,56 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_nvl_machines[] = {
};
EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_nvl_machines);
+/*
+ * Senary SN622x on NVL: speaker + DMIC (headphone mux external).
+ * Same SDW part_id rules as PTL/codec_info (0x184c/0x6220, 0x1850/0x6224).
+ * Codec on SoundWire link 0, _ADR version nibble 0x3 (like SN624x on MTL).
+ */
+static const struct snd_soc_acpi_endpoint sn622x_endpoints[] = {
+ {
+ .num = 0,
+ .aggregated = 0,
+ .group_position = 0,
+ .group_id = 0,
+ },
+ {
+ .num = 1,
+ .aggregated = 0,
+ .group_position = 0,
+ .group_id = 0,
+ },
+};
+
+#define NVL_SN622X_SINGLE_ADR(_sym, _adr) \
+static const struct snd_soc_acpi_adr_device _sym[] = { \
+ { \
+ .adr = (_adr), \
+ .num_endpoints = ARRAY_SIZE(sn622x_endpoints), \
+ .endpoints = sn622x_endpoints, \
+ .name_prefix = "sn622x", \
+ }, \
+}
+
+#define NVL_SN622X_LINK(_sym, _adr_arr) \
+static const struct snd_soc_acpi_link_adr _sym[] = { \
+ { \
+ .mask = BIT(0), \
+ .num_adr = ARRAY_SIZE(_adr_arr), \
+ .adr_d = _adr_arr, \
+ }, \
+ {} \
+}
+
+NVL_SN622X_SINGLE_ADR(nvl_sn6220_184c_adr, 0x0000300496184c01ull);
+NVL_SN622X_SINGLE_ADR(nvl_sn6220_6220_adr, 0x0000300496622001ull);
+NVL_SN622X_SINGLE_ADR(nvl_sn6224_1850_adr, 0x0000300496185001ull);
+NVL_SN622X_SINGLE_ADR(nvl_sn6224_6224_adr, 0x0000300496622401ull);
+
+NVL_SN622X_LINK(nvl_link_sn6220_184c, nvl_sn6220_184c_adr);
+NVL_SN622X_LINK(nvl_link_sn6220_6220, nvl_sn6220_6220_adr);
+NVL_SN622X_LINK(nvl_link_sn6224_1850, nvl_sn6224_1850_adr);
+NVL_SN622X_LINK(nvl_link_sn6224_6224, nvl_sn6224_6224_adr);
+
/* this table is used when there is no I2S codec present */
struct snd_soc_acpi_mach snd_soc_acpi_intel_nvl_sdw_machines[] = {
/* mockup tests need to be first */
@@ -87,6 +138,34 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_nvl_sdw_machines[] = {
.drv_name = "sof_sdw",
.sof_tplg_filename = "sof-nvl-rt715-rt711-rt1308-mono.tplg",
},
+ {
+ .link_mask = BIT(0),
+ .links = nvl_link_sn6220_184c,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-nvl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
+ {
+ .link_mask = BIT(0),
+ .links = nvl_link_sn6220_6220,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-nvl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
+ {
+ .link_mask = BIT(0),
+ .links = nvl_link_sn6224_1850,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-nvl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
+ {
+ .link_mask = BIT(0),
+ .links = nvl_link_sn6224_6224,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-nvl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
{},
};
EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_nvl_sdw_machines);
diff --git a/sound/soc/intel/common/soc-acpi-intel-ptl-match.c b/sound/soc/intel/common/soc-acpi-intel-ptl-match.c
index 467709def..5276e46ac 100644
--- a/sound/soc/intel/common/soc-acpi-intel-ptl-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-ptl-match.c
@@ -503,6 +503,98 @@ SN624X_PTL_LINK(ptl_link_sn6244, sn6244_single_adr);
SN624X_PTL_LINK(ptl_link_sn6245, sn6245_single_adr);
SN624X_PTL_LINK(ptl_link_sn6247, sn6247_single_adr);
+/* Senary SN622x: speaker + DMIC. Headphone mux is external. */
+static const struct snd_soc_acpi_endpoint sn622x_endpoints[] = {
+ {
+ .num = 0,
+ .aggregated = 0,
+ .group_position = 0,
+ .group_id = 0,
+ },
+ {
+ .num = 1,
+ .aggregated = 0,
+ .group_position = 0,
+ .group_id = 0,
+ },
+};
+
+/* SN6220, part_id 0x184c, link 3 */
+static const struct snd_soc_acpi_adr_device sn622x_l3_184c_adr[] = {
+ {
+ .adr = 0x0003300496184c01ull,
+ .num_endpoints = ARRAY_SIZE(sn622x_endpoints),
+ .endpoints = sn622x_endpoints,
+ .name_prefix = "sn622x",
+ },
+};
+
+static const struct snd_soc_acpi_link_adr link_sn622x_l3_184c[] = {
+ {
+ .mask = BIT(3),
+ .num_adr = ARRAY_SIZE(sn622x_l3_184c_adr),
+ .adr_d = sn622x_l3_184c_adr,
+ },
+ {}
+};
+
+/* SN6220, part_id 0x6220 (SN624x-style), link 3 */
+static const struct snd_soc_acpi_adr_device sn622x_l3_6220_adr[] = {
+ {
+ .adr = 0x0003300496622001ull,
+ .num_endpoints = ARRAY_SIZE(sn622x_endpoints),
+ .endpoints = sn622x_endpoints,
+ .name_prefix = "sn622x",
+ },
+};
+
+static const struct snd_soc_acpi_link_adr link_sn622x_l3_6220[] = {
+ {
+ .mask = BIT(3),
+ .num_adr = ARRAY_SIZE(sn622x_l3_6220_adr),
+ .adr_d = sn622x_l3_6220_adr,
+ },
+ {}
+};
+
+/* SN6224, part_id 0x1850, link 2 */
+static const struct snd_soc_acpi_adr_device sn622x_l2_1850_adr[] = {
+ {
+ .adr = 0x0002300496185001ull,
+ .num_endpoints = ARRAY_SIZE(sn622x_endpoints),
+ .endpoints = sn622x_endpoints,
+ .name_prefix = "sn622x",
+ },
+};
+
+static const struct snd_soc_acpi_link_adr link_sn622x_l2_1850[] = {
+ {
+ .mask = BIT(2),
+ .num_adr = ARRAY_SIZE(sn622x_l2_1850_adr),
+ .adr_d = sn622x_l2_1850_adr,
+ },
+ {}
+};
+
+/* SN6224, part_id 0x6224, link 3 */
+static const struct snd_soc_acpi_adr_device sn622x_l3_6224_adr[] = {
+ {
+ .adr = 0x0003300496622401ull,
+ .num_endpoints = ARRAY_SIZE(sn622x_endpoints),
+ .endpoints = sn622x_endpoints,
+ .name_prefix = "sn622x",
+ },
+};
+
+static const struct snd_soc_acpi_link_adr link_sn622x_l3_6224[] = {
+ {
+ .mask = BIT(3),
+ .num_adr = ARRAY_SIZE(sn622x_l3_6224_adr),
+ .adr_d = sn622x_l3_6224_adr,
+ },
+ {}
+};
+
struct snd_soc_acpi_mach snd_soc_acpi_intel_ptl_sdw_machines[] = {
/* Order Priority: mockup > most links > most bit link-mask > alphabetical */
{
@@ -597,6 +689,34 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_ptl_sdw_machines[] = {
.sof_tplg_filename = "sof-ptl-rt712-l3-rt1320-l3.tplg",
},
+ {
+ .link_mask = BIT(2),
+ .links = link_sn622x_l2_1850,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-ptl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
+ {
+ .link_mask = BIT(3),
+ .links = link_sn622x_l3_184c,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-ptl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
+ {
+ .link_mask = BIT(3),
+ .links = link_sn622x_l3_6220,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-ptl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
+ {
+ .link_mask = BIT(3),
+ .links = link_sn622x_l3_6224,
+ .drv_name = "sof_sdw",
+ .sof_tplg_filename = "sof-ptl-dummy.tplg",
+ .get_function_tplg_files = sof_sdw_get_tplg_files,
+ },
{
.link_mask = BIT(3),
.links = ptl_link_sn6242,
diff --git a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
index 0adde845a..9c51d8588 100644
--- a/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
+++ b/sound/soc/sdw_utils/soc_sdw_senary_sdca.c
@@ -22,6 +22,10 @@ static const struct snd_soc_dapm_route sn624x_spk_map_bare[] = {
{ "Speaker", NULL, "SPK" },
};
+static const struct snd_soc_dapm_route sn622x_spk_map[] = {
+ { "Speaker", NULL, "sn622x SPK" },
+};
+
/* Structure to map codec names to respective route arrays and sizes */
struct codec_route_map {
const char *codec_name;
@@ -31,6 +35,7 @@ struct codec_route_map {
/* Codec route maps array */
static const struct codec_route_map codec_routes[] = {
+ { "sn622x", sn622x_spk_map, ARRAY_SIZE(sn622x_spk_map) },
{ "sn624x", sn624x_spk_map, ARRAY_SIZE(sn624x_spk_map) },
};
@@ -60,10 +65,10 @@ int asoc_sdw_senary_sdca_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct sn
/*
* No name_prefix means the codec widgets were created as "SPK",
- * not "sn624x SPK". DAI name is still sn624x-sdca-aif2.
+ * not "<prefix> SPK" (e.g. sn624x SPK / sn622x SPK).
*/
if (!dai->component->name_prefix) {
- dev_warn(rtd->dev, "sn624x spk: component %s has no name_prefix\n",
+ dev_warn(rtd->dev, "senary spk: component %s has no name_prefix\n",
dai->component->name);
routes = sn624x_spk_map_bare;
nroutes = ARRAY_SIZE(sn624x_spk_map_bare);
diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c
index fefc4d7f5..d3a1277f6 100644
--- a/sound/soc/sdw_utils/soc_sdw_utils.c
+++ b/sound/soc/sdw_utils/soc_sdw_utils.c
@@ -1700,6 +1700,165 @@ struct asoc_sdw_codec_info codec_info_list[] = {
},
.dai_num = 3,
},
+ /*
+ * Senary SN622x: speaker amp + DMIC only (no UAJ jack).
+ * SN6220 and SN6224 share topology; only SoundWire part_id differs.
+ *
+ * Silicone/ACPI may report either encoding (both observed in the field):
+ * SN624x-style part digits: SN6220 -> 0x6220, SN6224 -> 0x6224
+ * (same rule as SN6244 part_id 0x6244 in the table above).
+ * Decimal-as-value: SN6220 -> 0x184c (6220), SN6224 -> 0x1850 (6224).
+ * One row per (vendor_id, part_id) pair — asoc_sdw_find_codec_info_part()
+ * matches exactly. Do not use 0x1864 (6244 decimal, SN624x).
+ */
+ /* SN6220, part_id 0x184c */
+ {
+ .vendor_id = 0x0496,
+ .part_id = 0x184c,
+ .name_prefix = "sn622x",
+ .ignore_internal_dmic = true,
+ .dais = {
+ {
+ .direction = {true, false},
+ .dai_name = "sn622x-sdca-aif",
+ .component_name = "sn622x",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID},
+ .init = asoc_sdw_senary_amp_init,
+ .exit = asoc_sdw_senary_amp_exit,
+ .rtd_init = asoc_sdw_senary_sdca_spk_rtd_init,
+ .controls = generic_spk_controls,
+ .num_controls = ARRAY_SIZE(generic_spk_controls),
+ .widgets = generic_spk_widgets,
+ .num_widgets = ARRAY_SIZE(generic_spk_widgets),
+ .quirk = SOC_SDW_CODEC_SPKR,
+ .quirk_exclude = true,
+ },
+ {
+ .direction = {false, true},
+ .dai_name = "sn622x-sdca-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_senary_dmic_rtd_init,
+ .widgets = generic_dmic_widgets,
+ .num_widgets = ARRAY_SIZE(generic_dmic_widgets),
+ .quirk = SOC_SDW_CODEC_MIC,
+ .quirk_exclude = true,
+ },
+ },
+ .dai_num = 2,
+ },
+ /* SN6220, part_id 0x6220 */
+ {
+ .vendor_id = 0x0496,
+ .part_id = 0x6220,
+ .name_prefix = "sn622x",
+ .ignore_internal_dmic = true,
+ .dais = {
+ {
+ .direction = {true, false},
+ .dai_name = "sn622x-sdca-aif",
+ .component_name = "sn622x",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID},
+ .init = asoc_sdw_senary_amp_init,
+ .exit = asoc_sdw_senary_amp_exit,
+ .rtd_init = asoc_sdw_senary_sdca_spk_rtd_init,
+ .controls = generic_spk_controls,
+ .num_controls = ARRAY_SIZE(generic_spk_controls),
+ .widgets = generic_spk_widgets,
+ .num_widgets = ARRAY_SIZE(generic_spk_widgets),
+ .quirk = SOC_SDW_CODEC_SPKR,
+ .quirk_exclude = true,
+ },
+ {
+ .direction = {false, true},
+ .dai_name = "sn622x-sdca-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_senary_dmic_rtd_init,
+ .widgets = generic_dmic_widgets,
+ .num_widgets = ARRAY_SIZE(generic_dmic_widgets),
+ .quirk = SOC_SDW_CODEC_MIC,
+ .quirk_exclude = true,
+ },
+ },
+ .dai_num = 2,
+ },
+ /* SN6224, part_id 0x1850 */
+ {
+ .vendor_id = 0x0496,
+ .part_id = 0x1850,
+ .name_prefix = "sn622x",
+ .ignore_internal_dmic = true,
+ .dais = {
+ {
+ .direction = {true, false},
+ .dai_name = "sn622x-sdca-aif",
+ .component_name = "sn622x",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID},
+ .init = asoc_sdw_senary_amp_init,
+ .exit = asoc_sdw_senary_amp_exit,
+ .rtd_init = asoc_sdw_senary_sdca_spk_rtd_init,
+ .controls = generic_spk_controls,
+ .num_controls = ARRAY_SIZE(generic_spk_controls),
+ .widgets = generic_spk_widgets,
+ .num_widgets = ARRAY_SIZE(generic_spk_widgets),
+ .quirk = SOC_SDW_CODEC_SPKR,
+ .quirk_exclude = true,
+ },
+ {
+ .direction = {false, true},
+ .dai_name = "sn622x-sdca-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_senary_dmic_rtd_init,
+ .widgets = generic_dmic_widgets,
+ .num_widgets = ARRAY_SIZE(generic_dmic_widgets),
+ .quirk = SOC_SDW_CODEC_MIC,
+ .quirk_exclude = true,
+ },
+ },
+ .dai_num = 2,
+ },
+ /* SN6224, part_id 0x6224 */
+ {
+ .vendor_id = 0x0496,
+ .part_id = 0x6224,
+ .name_prefix = "sn622x",
+ .ignore_internal_dmic = true,
+ .dais = {
+ {
+ .direction = {true, false},
+ .dai_name = "sn622x-sdca-aif",
+ .component_name = "sn622x",
+ .dai_type = SOC_SDW_DAI_TYPE_AMP,
+ .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_UNUSED_DAI_ID},
+ .init = asoc_sdw_senary_amp_init,
+ .exit = asoc_sdw_senary_amp_exit,
+ .rtd_init = asoc_sdw_senary_sdca_spk_rtd_init,
+ .controls = generic_spk_controls,
+ .num_controls = ARRAY_SIZE(generic_spk_controls),
+ .widgets = generic_spk_widgets,
+ .num_widgets = ARRAY_SIZE(generic_spk_widgets),
+ .quirk = SOC_SDW_CODEC_SPKR,
+ .quirk_exclude = true,
+ },
+ {
+ .direction = {false, true},
+ .dai_name = "sn622x-sdca-aif2",
+ .dai_type = SOC_SDW_DAI_TYPE_MIC,
+ .dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
+ .rtd_init = asoc_sdw_senary_dmic_rtd_init,
+ .widgets = generic_dmic_widgets,
+ .num_widgets = ARRAY_SIZE(generic_dmic_widgets),
+ .quirk = SOC_SDW_CODEC_MIC,
+ .quirk_exclude = true,
+ },
+ },
+ .dai_num = 2,
+ },
};
EXPORT_SYMBOL_NS(codec_info_list, "SND_SOC_SDW_UTILS");
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread