Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gopi Chandra Sekhar Reddy Kanala" <gopi.kanala@oss.qualcomm.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt
Date: Sat, 05 Dec 2026 16:24:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-251742@kernel.org> (raw)
In-Reply-To: <20261205-b4-sdca-wcd9378-jack-v1-2-60ec9bff39ea@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] ASoC: wcd9378-sdca: MBHC registers lost across system
  suspend/resume
- [Medium] ASoC: wcd9378-sdca: set_jack() re-arms MBHC on jack teardown
  (NULL)
- [Medium] ASoC: wcd9378-sdca: unconditional SDCA_CASCADE clear can drop
  IRQs
- [Medium] ASoC: wcd9378-sdca: wcd9378_sdca_set_jack() clobbers MBHC
  bitfields
- [Medium] ASoC: sdca: unsynchronized jack_state access in
  sdca_jack_set_jack()
- [Low] ASoC: wcd9378-sdca: dropping DP0_INT clear races slave->probed
  on rebind
--

commit 2907479fe1dfbb0d350e7f5726d9243e85e8dab0
Author: Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>

ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt

This commit enables WCD9378 mechanical MBHC jack detection by arming the
MBHC comparator from a new .set_jack callback, toggling DET_TYP after each
GE 35 interrupt, clearing the latched DP0_INT.SDCA_CASCADE bit in the
SoundWire interrupt callback, and updating the GE 35 Safe_Mode range and
MBHC_CTRL DEVICE_DET init-table entries.

> diff --git a/sound/soc/codecs/wcd9378-sdca.c b/sound/soc/codecs/wcd9378-sdca.c
> index efbbeb3dc721a..8bfb2b10b5263 100644
> --- a/sound/soc/codecs/wcd9378-sdca.c
> +++ b/sound/soc/codecs/wcd9378-sdca.c

[ ... ]

> @@ -826,16 +817,11 @@ static struct sdca_init_write wcd9378_sdca_init_table[] = {
>  	{ .addr = 0x40c80008, .val = 0x01 }, /* SMP_JACK_CTRL FUNC_ACT (RESET_FUNCTION_NOW) */
>  	{ .addr = 0x40c00008, .val = 0x02 }, /* SMP_JACK_CTRL CMT_GRP_MASK */
>  	{ .addr = 0x40c80000, .val = 0xff }, /* SMP_JACK_CTRL FUNC_STAT */
> -	{ .addr = 0x00000000, .val = 0x08 }, /* clear DP0 INT status SDCA_CASCADE */
>  	{ .addr = 0x00000041, .val = 0x08 }, /* SCP_INT_STATUS_MASK_1 PORT_0_CASCADE_3 */

[Severity: Low]
Can dropping this DP0_INT clear leave SDCA_CASCADE stuck during driver rebind?

On unbind, sdw_bus_remove() clears slave->probed without resetting
slave->prop.paging_support.  On rebind, wcd9378_sdca_probe() calls
sdca_class_probe(), which queues boot_work before sdw_bus_probe() sets
slave->probed = true:

CPU0 (rebind)                     CPU1 (boot_work / IRQ)
sdca_class_probe()
  queue_work(&drv->boot_work)
                                  class_function_boot()
                                    sdca_regmap_write_init()
                                      unmask SCP_INT_STATUS_MASK_1
                                  sdw_handle_slave_alerts()
                                    if (slave->probed)  <-- false, skips cb
sdw_bus_probe()
  slave->probed = true

If DP0_INT.SDCA_CASCADE is already latched when SCP_INT_STATUS_MASK_1 is
unmasked, sdw_handle_slave_alerts() skips wcd9378_sdca_interrupt_callback(),
hits MAX_RETRY, and leaves the peripheral in ALERT.  Keeping the DP0_INT clear
in wcd9378_sdca_init_table[] avoids relying on the interrupt callback during
probe-time initialization.

[ ... ]

> +int wcd9378_sdca_interrupt_callback(struct sdw_slave *slave,
> +				    struct sdw_slave_intr_status *status)
> +{
> +	int ret;
> +
> +	if (!status->sdca_cascade)
> +		return 0;
> +
> +	ret = sdw_write_no_pm(slave, SDW_DP0_INT, SDW_DP0_SDCA_CASCADE);
> +	if (ret < 0)
> +		dev_err(&slave->dev, "SDCA_CASCADE clear failed:%d\n", ret);
> +
> +	return 0;
> +}

[Severity: Medium]
Can clearing SDW_DP0_SDCA_CASCADE unconditionally drop a pending SDCA
interrupt?

In sdw_handle_slave_alerts(), handle_nested_irq() runs before
wcd9378_sdca_interrupt_callback():

IRQ thread                        Hardware
regmap_irq_thread()
  ack SDW_SCP_SDCA_INT1
  sdca_jack_process()
    wcd9378_sdca_post_jack_irq_process()
      toggle MECH_DET_TYP
    snd_soc_dapm_put_enum_double()
                                  opposite jack transition fires
                                    sets SDW_SCP_SDCA_INT1 bit 4
                                    latches DP0_INT.SDCA_CASCADE
wcd9378_sdca_interrupt_callback()
  write SDW_DP0_INT               <-- clears cascade while SDCA_4 is pending

Because wcd9378_sdca_post_jack_irq_process() flips DET_TYP before the DAPM and
PDE updates complete, a transition arriving in that window is stranded in
SDW_SCP_SDCA_INT1 once DP0_INT is cleared, leaving DET_TYP inverted relative
to the physical jack state.  The same unconditional clear also drops
interrupts arriving while slave->irq is disabled or during snd_soc_card_bind()
before sdca_irq_populate() unmasks SDCA_4 in regmap_irq.

Checking that no unmasked SDW_SCP_SDCA_INT1..4 bits remain set before clearing
SDW_DP0_SDCA_CASCADE would avoid losing pending events.

[ ... ]

> +static int wcd9378_sdca_set_jack(struct sdw_slave *slave, struct regmap *dev_regmap)
> +{
> +	struct device *dev = &slave->dev;
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(dev);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to resume for jack detect enable: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = regmap_write(dev_regmap, WCD9378_MBHC_NEW_INT_MECH_DET_CURRENT_ADDR,
> +			   WCD9378_MBHC_HSDET_PULLUP_CTL_2P0_UA);
> +	if (ret) {
> +		dev_err(dev, "MBHC_NEW_INT_MECH_DET_CURRENT: %d\n", ret);
> +		goto out;
> +	}
> +
> +	ret = regmap_write(dev_regmap, WCD9378_ANA_MBHC_MECH_ADDR,
> +			   WCD9378_ANA_MBHC_MECH_ENABLE);
> +	if (ret) {
> +		dev_err(dev, "ANA_MBHC_MECH: %d\n", ret);
> +		goto out;
> +	}

[Severity: Medium]
Does wcd9378_sdca_set_jack() re-arm MBHC when a machine driver detaches the
jack with jack == NULL?

class_function_set_jack() calls core->ops->set_jack() unconditionally without
passing jack or an enable flag, and machine drivers such as x1e80100 call
snd_soc_component_set_jack(component, NULL, NULL) in
qcom_snd_headset_jack_cleanup() on teardown or probe rollback.  Writing
WCD9378_ANA_MBHC_MECH_ENABLE leaves the comparator, bias, pull-up current, and
RCO powered on after unbind and resets DET_TYP to insertion polarity, which
can trigger spurious SDCA_4 interrupts during teardown or re-introduce the
SDCA_4 interrupt storm on deferred re-probe.  Passing whether a jack is being
attached or detached and disabling MBHC on NULL would avoid this.

[Severity: Medium]
Does arming GE 35 interrupts here expose an unsynchronized data race on
jack_state during sound-card teardown?

On teardown in snd_soc_card_cleanup_resources(), dai_link->exit() calls
qcom_snd_headset_jack_cleanup() -> sdca_jack_set_jack(info, NULL) before
snd_soc_card_link_components_remove() runs sdca_irq_cleanup() -> free_irq():

CPU0 (card teardown)              CPU1 (GE 35 IRQ thread)
sdca_jack_set_jack(info, NULL)    detected_mode_handler()
  lock(&info->irq_lock)             sdca_jack_process()
  jack_state->mask |= ...             lock(&card->controls_rwsem)
  jack_state->jack = NULL             sdca_jack_report()
                                        snd_soc_jack_report(jack_state->jack,
                                                            ...,
                                                            jack_state->mask)
                                          <-- data race on jack_state

sdca_jack_set_jack() updates jack_state->mask and jack_state->jack under
info->irq_lock, while sdca_jack_process() holds only controls_rwsem (and
cannot take info->irq_lock because sdca_irq_cleanup() holds it across
free_irq()).  This leaves a KCSAN-detectable data race and can report events
on a detached jack, made more likely when wcd9378_sdca_set_jack() re-writes
WCD9378_ANA_MBHC_MECH_ENABLE right before sdca_jack_set_jack() clears the
pointer.

> +	ret = regmap_write(dev_regmap, WCD9378_MBHC_NEW_PLUG_DETECT_CTL_ADDR,
> +			   WCD9378_MBHC_INSREM_DBNC_96MS);
> +	if (ret) {
> +		dev_err(dev, "MBHC_NEW_PLUG_DETECT_CTL: %d\n", ret);
> +		goto out;
> +	}
> +
> +	ret = regmap_write(dev_regmap, WCD9378_ANA_MBHC_ELECT_ADDR,
> +			   WCD9378_ANA_MBHC_ELECT_BIAS_EN);
> +	if (ret) {
> +		dev_err(dev, "ANA_MBHC_ELECT: %d\n", ret);
> +		goto out;
> +	}
> +
> +	ret = regmap_write(dev_regmap, WCD9378_MBHC_NEW_CTL_1_ADDR,
> +			   WCD9378_MBHC_NEW_CTL_1_RCO_EN);
> +	if (ret)
> +		dev_err(dev, "MBHC_NEW_CTL_1: %d\n", ret);

[Severity: Medium]
Do these full-byte regmap_write() calls clobber unrelated default bitfields in
the MBHC control registers?

In the sibling WCD937x/WCD938x/WCD939x codecs sharing this analog block,
MBHC_NEW_PLUG_DETECT_CTL defaults to 0xe9 (including MIC_CLAMP_CTL in
bits [5:4]), ANA_MBHC_ELECT defaults to 0x08 (ELECT_DET_TYPE), and
MBHC_NEW_CTL_1 defaults to 0x02 (BTN_DBNC_CTL), and wcd_mbhc_initialise()
updates INSREM_DBNC, BIAS_EN, and RCO_EN with masked field writes.  Writing
0x06, 0x01, and 0x80 directly zeroes those defaults, disabling automatic mic
clamping and clearing the other fields; using regmap_update_bits() would
preserve them.

> +out:
> +	pm_runtime_mark_last_busy(dev);
> +	pm_runtime_put_autosuspend(dev);
> +
> +	return ret;
> +}

[Severity: High]
Are these five MBHC registers lost across system suspend and resume?

wcd9378_sdca_set_jack() programs them only once during sound-card bind via
dev_regmap, where class_dev_regmap_volatile() marks every register outside
SDW_SCP_SDCA_INTMASK1..4 volatile so regcache_sync() never restores them.  On
system resume, class_function_runtime_resume() resets the function and replays
wcd9378_sdca_init_table[] (which intentionally omits MBHC arming), and neither
wcd9378_sdca_system_resume() nor class_function_runtime_resume() re-arms MBHC,
permanently disabling jack insertion and removal detection after a
suspend/resume cycle.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-sdca-wcd9378-jack-v1-0-60ec9bff39ea@oss.qualcomm.com?part=2

      reply	other threads:[~2026-12-05 16:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 15:59 [PATCH 0/2] ASoC: SDCA: support hardware jack detection on WCD9378 Gopi Chandra Sekhar Reddy Kanala
2026-12-05 15:59 ` [PATCH 1/2] ASoC: SDCA: add jack ops hooks Gopi Chandra Sekhar Reddy Kanala
2026-12-05 16:18   ` sashiko-bot
2026-12-05 15:59 ` [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt Gopi Chandra Sekhar Reddy Kanala
2026-12-05 16:24   ` sashiko-bot [this message]

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-251742@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gopi.kanala@oss.qualcomm.com \
    --cc=linux-sound@vger.kernel.org \
    --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