Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Qianghua Wang" <qianghua.wang@senarytech.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v2 1/3] ASoC: codecs: add SN622x SDCA SoundWire codec support
Date: Tue, 01 Dec 2026 03:23:02 +0000	[thread overview]
Message-ID: <sashiko-outbox-242426@kernel.org> (raw)
In-Reply-To: <20261201025636.60506-2-qianghua.wang@senarytech.com>

Thank you for your contribution! Sashiko AI review found 16 potential
issues to consider:
- [High] ASoC: sn622x: broken MBQ sizing in sn622x_sdca_mbq_size() and
  volume write order
- [High] ASoC: sn622x: unreachable dmic_active branch and skipped init
  in sn622x_sdca_io_init()
- [High] ASoC: sn622x: dmic_analog_restored and dmic_cap_cfg_done never
  cleared on reset
- [High] ASoC: sn622x: broken runtime PM lifecycle in sn622x_sdca_init()
  and io_init()
- [High] ASoC: sn622x: sn622x_sdca_dev_resume() leaves regmap in
  cache-only mode
- [High] ASoC: sn622x: unguarded sdw_write_no_pm() in probe and system
  suspend
- [Medium] ASoC: sn622x: sn622x_clear_dp0_int() duplicates bus core DP0
  interrupt handling
- [Medium] ASoC: sn622x: missing stream rollback on error in
  sn622x_sdca_pcm_hw_params()
- [Medium] ASoC: sn622x: skipped cleanup on runtime PM error in
  sn622x_sdca_pcm_hw_free()
- [Medium] ASoC: sn622x: missing sn622x_sdca_disco_omits_mic() guards in
  prop and init
- [Medium] ASoC: sn622x: broken bus_recover_work cancellation and state
  sync on unattach
- [Medium] ASoC: sn622x: uncanceled bus_recover_work races with system
  suspend
- [Medium] ASoC: sn622x: sn622x_sdca_dev_resume() returns 0 with regmap
  left cache-only
- [Medium] ASoC: sn622x: repeated and unbounded polling in
  sn622x_dmic_needs_recover()
- [Medium] ASoC: sn622x: missing cleanup on regmap_write() error in
  hw_params
- [Low] ASoC: sn622x: dead S16_LE bps check in
  sn622x_sdca_pcm_hw_params() and unused definitions
--

commit 460bd275ece026483bbb20b3f6335f1bd2ea73c2
Author: Qianghua Wang <qianghua.wang@senarytech.com>

ASoC: codecs: add SN622x SDCA SoundWire codec support

This commit adds the snd-soc-sn622x-sdca SoundWire codec driver for Senary
SN6220 and SN6224 SDCA devices supporting speaker playback and internal
DMIC capture.

> diff --git a/sound/soc/codecs/sn622x-sdca-sdw.c b/sound/soc/codecs/sn622x-sdca-sdw.c
> new file mode 100644
> index 0000000000000..b492fda63e37f
> --- /dev/null
> +++ b/sound/soc/codecs/sn622x-sdca-sdw.c

[ ... ]

> +#define SN622X_SPK_VOL_PRIM_DEFAULT		0x00u
> +#define SN622X_SPK_VOL_SECOND_DEFAULT		0xfau
> +#define SN622X_SPK_CHR_VOL_PRIM_DEFAULT		0x00u
> +#define SN622X_SPK_CHR_VOL_SECOND_DEFAULT	0xfau
> +#define SN622X_REG_SPEAKER_FUN_STATUS_CTL \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_SPEAKER, SN622X_SDCA_ENT_ENTITY0, \
> +				     SN622X_SDCA_CTL_FUNCTION_STATUS, 0))
> +
> +/* Speaker vendor SCP (not SDCA): charge-pump enable value per SN6220 map */
> +#define SN622X_VENDOR_REG_CHARGE_PUMP	0x00002086u
> +#define SN622X_CHARGE_PUMP_ENABLE	0x0bu
> +
> +/* DMIC capture (function 2) */
> +#define SN622X_REG_DMIC_CAP_MUTE \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_USER_FU20, \
> +				     SN622X_SDCA_CTL_FU_MUTE, SN622X_SDCA_CH_L))
> +#define SN622X_REG_DMIC_CAP_CHR_MUTE \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_USER_FU20, \
> +				     SN622X_SDCA_CTL_FU_MUTE, SN622X_SDCA_CH_R))
> +#define SN622X_REG_DMIC_CAP_VOL_FRAC \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_USER_FU20, \
> +				     SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_L))
> +#define SN622X_REG_DMIC_CAP_VOL_INT \
> +	SN622X_SDCA_U32(SDW_SDCA_MBQ_CTL(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, \
> +				      SN622X_SDCA_ENT_USER_FU20, \
> +				      SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_L)))
> +#define SN622X_REG_DMIC_CAP_CHR_VOL_FRAC \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_USER_FU20, \
> +				     SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_R))
> +#define SN622X_REG_DMIC_CAP_CHR_VOL_INT \
> +	SN622X_SDCA_U32(SDW_SDCA_MBQ_CTL(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, \
> +				      SN622X_SDCA_ENT_USER_FU20, \
> +				      SN622X_SDCA_CTL_FU_VOLUME, SN622X_SDCA_CH_R)))
> +#define SN622X_REG_DMIC_CAP_RATE_SEL \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_CS02, \
> +				     SN622X_SDCA_CTL_SAMPLE_FREQ_INDEX, 0))
> +#define SN622X_REG_DMIC_MFPU_BYPASS \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_MFPU08, \
> +				     SN622X_SDCA_CTL_FU_MUTE, 0))
> +#define SN622X_REG_DMIC_MFPU_ALGO_ENABLE \
> +	SN622X_SDCA_U32(SDW_SDCA_CTL(SN622X_FUNC_NUM_MIC_ARRAY, SN622X_SDCA_ENT_MFPU08, \
> +				     SN622X_SDCA_CTL_FU_VOLUME, 0))

[ ... ]

> +/* DMIC vendor init table; run when analog not yet restored for this attach. */
> +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_dbg(dev, "sn622x: restore dmic analog (%s)\n", why ? why : "?");
> +
> +	ret = sn622x_dmic_apply_defaults(dev, sn622x);
> +	if (ret < 0) {
> +		dev_warn(dev, "sn622x: restore dmic: init table failed (%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;
> +}
> +
> +/* DMIC vendor/analog after sdw_stream_add_slave; PDE/FU via DAPM. */
> +static void sn622x_dmic_capture_prepare(struct device *dev,
> +					struct sn622x_sdca_priv *sn622x,
> +					unsigned int pcm_rate,
> +					bool bringup)
> +{
> +	unsigned int st = 0;
> +	struct reg_sequence clear_dmic =
> +		REG_SEQ0(SN622X_REG_DMIC_FUN_STATUS_CTL, 0x61);
> +	int r;
> +
> +	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 (regmap_read_bypassed(sn622x->regmap, SN622X_REG_DMIC_FUN_STATUS_CTL,
> +				 &st) == 0 &&
> +	    (st & (SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET))) {
> +		regmap_multi_reg_write_bypassed(sn622x->regmap, &clear_dmic, 1);
> +		usleep_range(1000, 1500);
> +	}
> +
> +	if (bringup || !sn622x->dmic_analog_restored)
> +		sn622x_restore_dmic_analog(dev, sn622x,
> +					   bringup ? "dmic_pmu" : "dmic_recover");
> +
> +	if (!sn622x->dmic_cap_cfg_done) {
> +		static const struct reg_sequence cap_cfg[] = {
> +			REG_SEQ0(0x00002126u, 0x18),
> +			REG_SEQ0(0x00002127u, 0x01),
> +			REG_SEQ0(0x000020f3u, 0x30),
> +		};
> +
> +		r = regmap_multi_reg_write_bypassed(sn622x->regmap, cap_cfg,
> +						    ARRAY_SIZE(cap_cfg));
> +		if (r < 0)
> +			dev_warn(dev,
> +				 "sn622x: dmic prepare: cap vendor cfg failed (%d)\n",
> +				 r);
> +		else
> +			sn622x->dmic_cap_cfg_done = true;
> +	}
> +
> +	sn622x->dmic_route_latched = true;
> +	(void)pcm_rate;
> +
> +out_unlock:
> +	mutex_unlock(&sn622x->path_lock);
> +}

[Severity: High]
Are dmic_analog_restored and dmic_cap_cfg_done left set across device
resets and system suspend?

Once a first capture stream sets both flags, neither is ever cleared on
SDW_SLAVE_UNATTACHED, system suspend, or when SN622X_REG_DMIC_FUN_STATUS_CTL
reports SN622X_FUN_NEEDS_INIT | SN622X_FUN_HAS_BEEN_RESET.  After a codec
reset or power loss, sn622x_sdca_io_init() and
sn622x_dmic_capture_prepare() acknowledge and clear the Function Status
reset bits without re-running sn622x_dmic_apply_defaults() or
reprogramming cap_cfg[].

[ ... ]

> +static int sn622x_sdca_mbq_size(struct device *dev, unsigned int reg)
> +{
> +	if (!SDW_SDCA_VALID_CTL(reg))
> +		return 1;
> +
> +	switch (reg) {
> +	case SN622X_REG_VOL_SECOND:
> +	case SN622X_REG_CHR_VOL_SECOND:
> +	case SN622X_REG_DMIC_CAP_VOL_INT:
> +	case SN622X_REG_DMIC_CAP_VOL_FRAC:
> +	case SN622X_REG_DMIC_CAP_CHR_VOL_INT:
> +	case SN622X_REG_DMIC_CAP_CHR_VOL_FRAC:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}

[Severity: High]
Does sn622x_sdca_mbq_size() reject the SDW_SDCA_MBQ_CTL() volume addresses
while sn622x_fu_mute_event() writes the MBQ bytes in reverse order?

SDW_SDCA_MBQ_CTL() sets BIT(13), which makes SDW_SDCA_VALID_CTL(reg) false.
As a result, the SN622X_REG_*_VOL_SECOND and SN622X_REG_DMIC_CAP_*_VOL_INT
cases are unreachable, SN622X_REG_DMIC_CAP_*_VOL_FRAC returns 2, and
SN622X_REG_*_VOL_PRIM returns 1.

In addition, sn622x_fu_mute_event() writes the base address (BIT(13) == 0)
before the MBQ staging address (BIT(13) == 1) instead of letting
regmap-sdw-mbq perform a single 2-byte write to the base control address
(which stages the upper byte at BIT(13) == 1 first and commits via
BIT(13) == 0 second).  For DMIC, writing 0x4d to VOL_FRAC (size 2) latches
0x004d and the subsequent 1-byte write of 0xfb to VOL_INT is left
uncommitted in the MBQ latch; for speaker, writing 0x00 to VOL_PRIM
commits a stale MBQ byte and leaves 0xfa in VOL_SECOND uncommitted.

[ ... ]

> +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_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;
> +	}
> +	/* PCM open: defer full io_init until streams close (same bus, no extra SCP). */
> +	if (sn622x->first_hw_init &&
> +	    (sn622x->playback_active || sn622x->dmic_active)) {
> +		dev_dbg(dev, "sn622x: io_init: stream open — skip bus access\n");
> +		sn622x->hw_init = true;
> +		mutex_unlock(&sn622x->path_lock);
> +		return 0;
> +	}
> +	/* Capture still active: minimal cache/PM + DMIC FUN ACK; route in prepare. */
> +	if (sn622x->dmic_active) {

[Severity: High]
Does the first dmic_active check in sn622x_sdca_io_init() make the
following if (sn622x->dmic_active) block unreachable and skip re-attach
initialization?

sn622x->dmic_active can only become true in sn622x_sdca_trigger() after
initial attachment has already set sn622x->first_hw_init = true.  When the
slave detaches and re-attaches while a playback or capture stream is open,
the first branch always matches, sets sn622x->hw_init = true, and returns
without disabling regcache_cache_only, masking SDCA interrupts, or
acknowledging Function Status, and io_init is never re-run when the stream
closes.

[ ... ]

> +static bool sn622x_dmic_needs_recover(const struct sn622x_sdca_priv *sn622x)
> +{
> +	if (!sn622x->dmic_active)
> +		return false;
> +	if (!sn622x->dmic_route_latched)
> +		return true;
> +	if (sn622x->dmic_recover_until &&
> +	    time_before(jiffies, sn622x->dmic_recover_until))
> +		return true;
> +	return false;
> +}
> +
> +/*
> + * Deferred bring-up after UNATTACH (external HP mux): runtime PM cleanup,
> + * io_init when re-attached, DMIC vendor prepare retries while capture is open.
> + */
> +static void sn622x_bus_recover_work(struct work_struct *work)
> +{
> +	struct sn622x_sdca_priv *sn622x =
> +		container_of(work, struct sn622x_sdca_priv, bus_recover_work.work);
> +	struct device *dev;
> +	bool got_pm = false;
> +	int ret;
> +
> +	if (!sn622x->slave)
> +		return;
> +
> +	dev = &sn622x->slave->dev;
> +
> +	if (!sn622x_slave_attached(sn622x->slave)) {
> +		if (sn622x_dmic_needs_recover(sn622x))
> +			sn622x_schedule_bus_recover(sn622x,
> +						    SN622X_BUS_RECOVER_DMIC_MS);
> +		return;
> +	}
> +
> +	ret = pm_runtime_resume_and_get(dev);
> +	if (ret < 0 && ret != -EACCES)
> +		return;
> +	if (ret == 0)
> +		got_pm = true;
> +
> +	sn622x_pm_recover(dev);
> +
> +	if (!sn622x->hw_init)
> +		sn622x_sdca_io_init(dev, sn622x->slave);
> +
> +	if (sn622x_dmic_needs_recover(sn622x) &&
> +	    (!sn622x->playback_active || !sn622x->dmic_route_latched)) {
> +		dev_dbg(dev, "sn622x: bus_recover: DMIC capture prepare\n");
> +		sn622x_dmic_capture_prepare(dev, sn622x, sn622x->dmic_rate, false);
> +		if (sn622x_dmic_needs_recover(sn622x))
> +			sn622x_schedule_bus_recover(sn622x,
> +						    SN622X_BUS_RECOVER_DMIC_MS);
> +	}

[Severity: Medium]
Does sn622x_dmic_needs_recover() cause sn622x_bus_recover_work() to poll
indefinitely while unattached and repeatedly after recovery?

Because !sn622x->dmic_route_latched is checked before
sn622x->dmic_recover_until, an unattached slave reschedules
bus_recover_work every 150 ms without bound instead of stopping at the 2
second deadline.  Once attached, sn622x_dmic_capture_prepare() sets
dmic_route_latched = true without clearing dmic_recover_until, so
sn622x_dmic_needs_recover() keeps returning true for the full 2 seconds
and repeatedly re-runs sn622x_dmic_capture_prepare() every 150 ms when
playback_active is 0.

> +
> +	if (got_pm) {
> +		pm_runtime_mark_last_busy(dev);
> +		pm_runtime_put_autosuspend(dev);
> +	}
> +}
> +
> +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);
> +
> +	if (status == SDW_SLAVE_UNATTACHED) {
> +		unsigned long prev_unattach = sn622x->last_unattach_jiffies;
> +
> +		sn622x->hw_init = false;
> +		sn622x->last_unattach_jiffies = jiffies;
> +		/* After ATTACH, capture prepare re-latches route; keep dmic_analog_restored. */
> +		sn622x->dmic_route_latched = false;
> +		if (prev_unattach &&
> +		    time_before(jiffies, prev_unattach +
> +				msecs_to_jiffies(SN622X_UNATTACH_STORM_WINDOW_MS)))
> +			sn622x->unattach_storm++;
> +		else
> +			sn622x->unattach_storm = 1;
> +		if (sn622x->dmic_active &&
> +		    sn622x->unattach_storm >= SN622X_UNATTACH_STORM_MAX) {
> +			dev_warn(&slave->dev,
> +				 "sn622x: rapid UNATTACH — stop DMIC recover\n");
> +			sn622x->dmic_active = false;
> +			sn622x->dmic_recover_until = 0;
> +			cancel_delayed_work(&sn622x->bus_recover_work);
> +		} else if (sn622x->dmic_active) {
> +			sn622x->dmic_recover_until = jiffies + 2 * HZ;
> +		}
> +		sn622x_schedule_bus_recover(sn622x, SN622X_BUS_RECOVER_SETTLE_MS);
> +	}

[Severity: Medium]
Doesn't sn622x_schedule_bus_recover() immediately re-queue
bus_recover_work right after the unattach-storm branch cancels it?

Also, when SDW_SLAVE_ATTACHED occurs within SN622X_ATTACH_DEBOUNCE_MS,
sn622x_sdca_update_status() defers sn622x_sdca_io_init() to
bus_recover_work; if the capture stream closes during that window,
cancel_delayed_work_sync(&sn622x->bus_recover_work) in
sn622x_sdca_pcm_hw_free() cancels the pending io_init and leaves hw_init
false while attached.  In addition, dmic_active, dmic_route_latched,
dmic_recover_until, dmic_rate, playback_active, and hw_init are accessed
across PCM callbacks, update_status, and bus_recover_work without common
locking.

[ ... ]

> +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;
> +	/* dev_num 1 on this link: wake_capable is unsupported on Intel hosts. */
> +	prop->wake_capable = false;
> +
> +	/* SN6220: speaker playback (port1) + DMIC capture (port3) only */
> +	prop->source_ports = BIT(SN622X_PORT_DMIC_CAPTURE);

[Severity: Medium]
Should sn622x_sdca_read_prop(), sn622x_sdca_io_init(), and
sn622x_restore_dmic_analog() check sn622x_sdca_disco_omits_mic(slave)?

Currently only sn622x_dmic_apply_defaults() checks
sn622x_sdca_disco_omits_mic(slave).  On platforms where DisCo omits the
mic function, sn622x_sdca_read_prop() still exposes
SN622X_PORT_DMIC_CAPTURE, and sn622x_sdca_io_init() and
sn622x_restore_dmic_analog() still read and write
SN622X_REG_DMIC_FUN_STATUS_CTL on a non-existent SDCA function.

[ ... ]

> +/* 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;
> +		}

[Severity: Medium]
Why does sn622x_clear_dp0_int() duplicate the SoundWire bus core's
sdw_handle_dp0_interrupt()?

The bus core already clears SDW_DP0_INT and completes slave->port_ready[0]
in sdw_handle_slave_alerts() before invoking interrupt_callback, and
SDW_DP0_SDCA_CASCADE clears once SDW_SCP_SDCA_INT1..4 are cleared.
Clearing DP0 interrupt bits and signaling slave->port_ready[0] from the
codec driver's interrupt_callback and clk_stop paths risks losing DP0
status notifications or causing spurious port_ready completions.

[ ... ]

> +	snd_sdw_params_to_config(substream, params, &stream_config, &port_config);
> +	stream_config.frame_rate = 48000;
> +	if (stream_config.bps > 16 &&
> +	    params_format(params) == SNDRV_PCM_FORMAT_S16_LE)
> +		stream_config.bps = 16;

[Severity: Low]
Can stream_config.bps > 16 ever be true when params_format(params) is
SNDRV_PCM_FORMAT_S16_LE?

snd_sdw_params_to_config() sets stream_config.bps to
snd_pcm_format_width(params_format(params)), which is already 16 for
SNDRV_PCM_FORMAT_S16_LE.  In addition, SN622X_SPK_CHR_VOL_PRIM_DEFAULT,
SN622X_REG_DMIC_MFPU_BYPASS, SN622X_REG_DMIC_MFPU_ALGO_ENABLE,
SN622X_SDCA_ENT_MFPU08, SN622X_ROUTE_AFTER_D3_US_MIN/MAX,
SN622X_ROUTE_BEFORE_ACTIVE_US_MIN/MAX, SN622X_UAJ_DMIC_PPU11, and the
pcm_rate parameter of sn622x_dmic_capture_prepare() (making
sn622x->dmic_rate and sn622x->disable_irq write-only) are unused.

> +	port_config.num = port;
> +
> +	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;
> +		ret = regmap_write(sn622x->regmap, SN622X_REG_RATE_SEL, 0x01);
> +		if (ret < 0)
> +			dev_warn(dai->dev,
> +				 "sn622x: hw_params: speaker rate_sel failed (%d)\n",
> +				 ret);
> +		sn622x_speaker_playback_prepare(dai->dev, sn622x);
> +	} else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
> +		   dai->id == SN622X_DAI_DMIC) {
> +		sn622x->dmic_route_latched = false;
> +		sn622x->dmic_rate = params_rate(params);
> +		ret = regmap_write(sn622x->regmap, SN622X_REG_DMIC_CAP_RATE_SEL,
> +				   0x01);
> +		if (ret < 0)
> +			dev_warn(dai->dev,
> +				 "sn622x: hw_params: dmic rate_sel failed (%d)\n",
> +				 ret);
> +		sn622x_dmic_capture_prepare(dai->dev, sn622x, sn622x->dmic_rate,
> +					    true);
> +	}
> +out:
> +	if (got_pm) {
> +		pm_runtime_mark_last_busy(component->dev);
> +		pm_runtime_put_autosuspend(component->dev);
> +	}
> +	return ret;
> +}

[Severity: Medium]
If regmap_write() fails here after sdw_stream_add_slave() succeeds, does
sn622x_sdca_pcm_hw_params() leak the SoundWire stream runtime and leave
SN622X_PB_ACTIVE_SPK set?

When hw_params returns a negative error code, ASoC does not mark the DAI
for hw_free rollback, so sdw_stream_remove_slave() is never called on
stream teardown (leaving m_rt linked on bus->m_rt_list) and
sn622x->playback_active remains stuck set.

> +
> +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->bus_recover_work);
> +	}
> +	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
> +	    dai->id == SN622X_DAI_SPEAKER) {
> +		sn622x->playback_active &= ~SN622X_PB_ACTIVE_SPK;
> +	}
> +
> +	sdw_stream_remove_slave(sn622x->slave, sdw_stream);

[Severity: Medium]
Does returning early when pm_runtime_resume_and_get() fails in
sn622x_sdca_pcm_hw_free() skip sdw_stream_remove_slave() and work
cancellation?

sn622x_sdca_pcm_hw_free() performs no hardware register I/O, so aborting on
a runtime resume failure leaks the slave stream runtime and leaves
bus_recover_work and dmic_active / playback_active active after PCM close.

[ ... ]

> +	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);
> +
> +	return 0;
> +}

[Severity: High]
Does enabling runtime PM in RPM_SUSPENDED state during sn622x_sdca_init()
cause pm_runtime_set_active() in sn622x_sdca_io_init() to always fail with
-EAGAIN?

__pm_runtime_set_status() rejects pm_runtime_set_active() with -EAGAIN when
runtime PM is already enabled (disable_depth == 0) and runtime_error == 0.
When the slave attaches and sn622x_sdca_io_init() runs,
pm_runtime_set_active(dev) fails, leaving dev->power.runtime_status at
RPM_SUSPENDED while regcache_cache_only is false, so
pm_runtime_put_autosuspend(dev) sees the device as already suspended and
never invokes sn622x_sdca_dev_suspend().

In addition, if dev->power.runtime_error is set at probe when
disable_depth is already 1, calling pm_runtime_disable(dev) increments
disable_depth to 2 while pm_runtime_enable(dev) only decrements it to 1;
sn622x_sdca_sdw_remove() only calls pm_runtime_disable() when
first_hw_init is true (leaking the enable count if unbound before attach)
and omits pm_runtime_dont_use_autosuspend(); sn622x_bus_recover_work()
returns early when pm_runtime_resume_and_get() fails with -EINVAL before
reaching sn622x_pm_recover(); and reading dev->power.runtime_error
directly fails to compile when CONFIG_PM is disabled.

> +
> +static int sn622x_sdca_sdw_probe(struct sdw_slave *slave,
> +				 const struct sdw_device_id *id)
> +{
> +	struct regmap *regmap;
> +	int ret;
> +
> +	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;
> +
> +	regmap = devm_regmap_init_sdw_mbq_cfg(&slave->dev, slave,
> +					      &sn622x_sdca_regmap,
> +					      &sn622x_sdca_mbq_cfg);
> +	if (IS_ERR(regmap)) {
> +		dev_err(&slave->dev,
> +			"sn622x: devm_regmap_init_sdw_mbq_cfg failed (%ld)\n",
> +			PTR_ERR(regmap));
> +		return PTR_ERR(regmap);
> +	}
> +
> +	ret = sn622x_sdca_init(&slave->dev, 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_sdca_sdca_irq_mask_all(sn622x);
> +		SN622X_DBG(&slave->dev, "SoundWire probe finished OK\n");
> +	}
> +
> +	return ret;
> +}

[ ... ]

> +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);
> +}

[Severity: High]
Can sn622x_sdca_sdw_probe() and sn622x_sdca_dev_system_suspend() call
sn622x_sdca_sdca_irq_mask_all() while the slave is unattached or the
SoundWire bus is runtime-suspended?

sn622x_sdca_sdca_irq_mask_all() issues four sdw_write_no_pm() transfers.
In sn622x_sdca_sdw_probe(), the slave may still be SDW_SLAVE_UNATTACHED
before update_status() runs.  In sn622x_sdca_dev_system_suspend(), checking
!sn622x->first_hw_init instead of !sn622x->hw_init means that if the codec
and parent SoundWire controller have already runtime-suspended and stopped
the clock, system suspend issues SoundWire transactions over a
suspended/unattached bus.

[Severity: Medium]
Can sn622x->bus_recover_work run concurrently with or after
sn622x_sdca_dev_system_suspend()?

Neither sn622x_sdca_dev_system_suspend() nor sn622x_sdca_dev_suspend()
cancels bus_recover_work.  Because sn622x_bus_recover_work() continues
when pm_runtime_resume_and_get(dev) returns -EACCES (which the PM core
returns while runtime PM is disabled for system sleep), a pending work item
can run during system suspend and call sn622x_sdca_io_init(), clearing
disable_irq, disabling regcache_cache_only, and issuing bus transfers.

> +
> +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);
> +	int ret;
> +
> +	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));
> +
> +	if (slave->unattach_request) {
> +		ret = sdw_slave_wait_for_init(slave, SN622X_PROBE_TIMEOUT_MS);
> +		if (ret)
> +			dev_dbg(dev, "sn622x: resume: init wait failed (%d)\n", ret);
> +	}
> +
> +	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;
> +
> +	/* Resume: enable regmap I/O; avoid regcache_sync (stale cache vs live device). */
> +	regcache_cache_only(sn622x->regmap, false);
> +
> +	return 0;
> +}

[Severity: High]
Does sn622x_sdca_dev_resume() leave sn622x->regmap stuck in cache-only
mode when the slave resumes for a SoundWire alert or when
sdw_slave_wait_for_init() fails?

When a runtime-suspended slave raises an alert, sdw_handle_slave_alerts()
sets slave->status = SDW_SLAVE_ALERT before calling
pm_runtime_get_sync(&slave->dev).  Because sn622x_slave_attached() only
checks slave->status == SDW_SLAVE_ATTACHED, sn622x_sdca_dev_resume()
returns 0 without calling regcache_cache_only(sn622x->regmap, false), so
the device transitions to RPM_ACTIVE while regmap stays cache-only (and
when the slave returns to SDW_SLAVE_ATTACHED, sn622x_sdca_update_status()
sees hw_init == true and skips io_init).

[Severity: Medium]
Should sn622x_sdca_dev_resume() propagate errors when
sdw_slave_wait_for_init() fails or the slave is still unattached instead
of clearing slave->unattach_request and returning 0?

Returning 0 when initialization has not completed marks the device
RPM_ACTIVE with slave->unattach_request cleared and regcache_cache_only
still set to true.  Also, when the slave re-attaches within
SN622X_ATTACH_DEBOUNCE_MS, sn622x_sdca_update_status() defers
sn622x_sdca_io_init() to bus_recover_work and returns 0, which causes the
SoundWire bus core to complete slave->initialization_complete and wake
sdw_slave_wait_for_init() before io_init has run.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201025636.60506-1-qianghua.wang@senarytech.com?part=1

  reply	other threads:[~2026-12-01  3:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  2:56 [PATCH v2 0/3] ASoC: add Senary SN622x SDCA SoundWire support Qianghua Wang
2026-12-01  2:56 ` [PATCH v2 1/3] ASoC: codecs: add SN622x SDCA SoundWire codec support Qianghua Wang
2026-12-01  3:23   ` sashiko-bot [this message]
2026-12-01  2:56 ` [PATCH v2 2/3] ASoC: sdw_utils: add SN622x codec_info and DAPM hooks Qianghua Wang
2026-12-01  3:08   ` sashiko-bot
2026-12-01  2:56 ` [PATCH v2 3/3] ASoC: Intel: soc-acpi: add SN622x PTL/NVL SoundWire machines Qianghua Wang
2026-12-01  3:06   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-242426@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=qianghua.wang@senarytech.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox