* [PATCH 0/2] ASoC: SDCA: support hardware jack detection on WCD9378
@ 2026-12-05 15:59 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 15:59 ` [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt Gopi Chandra Sekhar Reddy Kanala
0 siblings, 2 replies; 5+ messages in thread
From: Gopi Chandra Sekhar Reddy Kanala @ 2026-12-05 15:59 UTC (permalink / raw)
To: Charles Keepax, Maciej Strozek, Bard Liao, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown,
Srinivas Kandagatla
Cc: linux-sound, patches, linux-arm-msm,
Gopi Chandra Sekhar Reddy Kanala
The SDCA class driver arms a Function's jack detection from its static
init_table, which suits parts whose detection hardware is safe to leave
enabled as soon as the device is configured. The WCD9378 is not one of
them: enabling its mechanical detector before the machine driver has
registered the jack raises a detection interrupt that cannot be
reported while the sound card probe is still deferred, and the detector
must be re-armed for the opposite transition direction after every
event.
Patch 1 adds two optional sdca_class_ops hooks for this. set_jack runs
from the class function driver's .set_jack just before the jack is
registered; post_jack_irq_process runs on every jack interrupt, after
the status has been read and before it is applied. Both default to
NULL, so nothing changes for parts that do not need them. The patch
also adds a back-pointer from sdca_interrupt_info to the device-level
sdca_class_drv: sdca_jack_process() runs at Function level and had no
typed route to the device's ops, and reading drvdata back as an
sdca_class_drv only works while that member happens to sit first in the
codec's private struct.
Patch 2 implements both hooks in the WCD9378 driver to enable GE 35
DETECTED_MODE detection, and clears the part's SDCA_CASCADE bit from
its SoundWire interrupt callback. That bit is specified as the
read-only OR of the SDCA interrupt status bits, so the bus driver never
writes it, but on this part it latches: left asserted it holds
SCP_INT1.PORT_0 set and the peripheral never leaves ALERT.
Tested on a Glymur CRD: headset insert and removal are reported during
playback, and an accessory present at boot is reported without waiting
for a transition.
Signed-off-by: Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>
---
Gopi Chandra Sekhar Reddy Kanala (2):
ASoC: SDCA: add jack ops hooks
ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt
include/sound/sdca_class.h | 13 +++
include/sound/sdca_interrupts.h | 8 ++
sound/soc/codecs/wcd9378-sdca.c | 155 ++++++++++++++++++++++++++++++-----
sound/soc/codecs/wcd9378-sdca.h | 2 +
sound/soc/codecs/wcd9378-sdw.c | 3 +-
sound/soc/sdca/sdca_class.c | 2 +
sound/soc/sdca/sdca_class_function.c | 8 ++
sound/soc/sdca/sdca_interrupts.c | 4 +-
sound/soc/sdca/sdca_jack.c | 10 +++
9 files changed, 181 insertions(+), 24 deletions(-)
---
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
change-id: 20261205-b4-sdca-wcd9378-jack-29eb57a1411f
Best regards,
--
Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] ASoC: SDCA: add jack ops hooks
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 ` 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
1 sibling, 1 reply; 5+ messages in thread
From: Gopi Chandra Sekhar Reddy Kanala @ 2026-12-05 15:59 UTC (permalink / raw)
To: Charles Keepax, Maciej Strozek, Bard Liao, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown,
Srinivas Kandagatla
Cc: linux-sound, patches, linux-arm-msm,
Gopi Chandra Sekhar Reddy Kanala
Extend sdca_class_ops with two optional hooks so codecs can defer
enabling their jack-detection hardware to a safe point instead of
driving it from the static init_table:
- set_jack: invoked from the class function driver's ASoC .set_jack,
just before the jack is registered with sdca_jack_set_jack(). Some
devices must not have detection enabled before the machine driver
has finished registering the jack, as a detection interrupt raised
while the card probe is still deferred cannot be reported. Enabling
at this point also means the initial state read by
sdca_jack_set_jack() already reflects the hardware, so an accessory
present at boot is seen without waiting for a transition.
- post_jack_irq_process: invoked from sdca_jack_process() on every
jack interrupt, after the status has been read but before it is
applied, for devices whose detection hardware has to be
reconfigured after each transition.
Wire both into class_function_set_jack() and sdca_jack_process()
respectively. Failures are reported with dev_warn() and are
non-fatal, since a failed hardware enable should not prevent the jack
from being registered.
sdca_jack_process() runs at Function level and has no typed route to
the device-level sdca_class_drv. drvdata on the SoundWire device
belongs to the codec driver, which embeds sdca_class_drv in its own
larger private struct, so reading drvdata back as an sdca_class_drv
only works while that member happens to sit first. Add a core
back-pointer to sdca_interrupt_info, and an info back-pointer on each
sdca_interrupt, so Function-level handlers can reach the owning
device's ops without touching drvdata at all.
core is optional: it is assigned by the device-level driver after
allocation, and callers of devm_sdca_irq_allocate() that are not
sdca_class_drv users simply leave it unset, so sdca_jack_process()
tolerates a NULL core.
Signed-off-by: Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>
---
include/sound/sdca_class.h | 13 +++++++++++++
include/sound/sdca_interrupts.h | 8 ++++++++
sound/soc/sdca/sdca_class.c | 2 ++
sound/soc/sdca/sdca_class_function.c | 8 ++++++++
sound/soc/sdca/sdca_interrupts.c | 4 +++-
sound/soc/sdca/sdca_jack.c | 10 ++++++++++
6 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/include/sound/sdca_class.h b/include/sound/sdca_class.h
index 794a756472cd..073f122633e2 100644
--- a/include/sound/sdca_class.h
+++ b/include/sound/sdca_class.h
@@ -26,10 +26,23 @@ struct sdca_function_data;
* DT/non-DisCo platforms. Called once per SDCA function with
* @dev pointing at that function's device. Pure data source;
* performs no bus I/O. Return 0 on success or a negative errno.
+ * @set_jack: called from the class function driver's ASoC .set_jack, just
+ * before the jack is registered with sdca_jack_set_jack(). Use
+ * to enable detection hardware that must not be active any
+ * earlier. Enabling here means the initial state reported by
+ * sdca_jack_set_jack() already reflects the hardware. May be
+ * NULL.
+ * @post_jack_irq_process: called from sdca_jack_process() on every jack
+ * interrupt, after the status has been read but before it is
+ * applied. Use to reconfigure detection hardware that needs
+ * updating after each transition. May be NULL.
*/
struct sdca_class_ops {
int (*populate_function)(struct device *dev,
struct sdca_function_data *function);
+ int (*set_jack)(struct sdw_slave *slave, struct regmap *dev_regmap);
+ int (*post_jack_irq_process)(struct sdw_slave *slave,
+ struct regmap *dev_regmap);
};
struct sdca_class_drv {
diff --git a/include/sound/sdca_interrupts.h b/include/sound/sdca_interrupts.h
index 3b30146e21db..fa53ccf27b79 100644
--- a/include/sound/sdca_interrupts.h
+++ b/include/sound/sdca_interrupts.h
@@ -16,6 +16,7 @@
struct device;
struct snd_soc_component;
+struct sdca_class_drv;
struct sdca_function_data;
#define SDCA_MAX_INTERRUPTS 31 /* the last bit is reserved for future extensions */
@@ -23,6 +24,7 @@ struct sdca_function_data;
/**
* struct sdca_interrupt - contains information about a single SDCA interrupt
* @name: The name of the interrupt.
+ * @info: Pointer to the interrupt information that owns this interrupt.
* @dev: Pointer to the Function device.
* @device_regmap: Pointer to the IRQ regmap.
* @function_regmap: Pointer to the SDCA Function regmap.
@@ -40,6 +42,7 @@ struct sdca_function_data;
struct sdca_interrupt {
const char *name;
+ struct sdca_interrupt_info *info;
struct device *dev;
struct regmap *device_regmap;
struct regmap *function_regmap;
@@ -60,6 +63,9 @@ struct sdca_interrupt {
* struct sdca_interrupt_info - contains top-level SDCA interrupt information
* @irq_chip: regmap irq chip structure.
* @irq_data: regmap irq chip data structure.
+ * @core: Optional pointer to the device-level SDCA class driver owning
+ * this interrupt information, letting Function-level handlers reach the
+ * device's ops. Left NULL by drivers that do not use sdca_class_drv.
* @irqs: Array of data for each individual IRQ.
* @irq_lock: Protects access to the list of sdca_interrupt structures.
*/
@@ -67,6 +73,8 @@ struct sdca_interrupt_info {
struct regmap_irq_chip irq_chip;
struct regmap_irq_chip_data *irq_data;
+ struct sdca_class_drv *core;
+
struct sdca_interrupt irqs[SDCA_MAX_INTERRUPTS];
struct mutex irq_lock; /* Protect irqs list across functions */
diff --git a/sound/soc/sdca/sdca_class.c b/sound/soc/sdca/sdca_class.c
index 7676c9624349..c0fb41af9425 100644
--- a/sound/soc/sdca/sdca_class.c
+++ b/sound/soc/sdca/sdca_class.c
@@ -119,6 +119,8 @@ static void class_boot_work(struct work_struct *work)
if (IS_ERR(drv->irq_info))
goto err;
+ drv->irq_info->core = drv;
+
ret = sdca_dev_register_functions(drv->sdw);
if (ret)
goto err;
diff --git a/sound/soc/sdca/sdca_class_function.c b/sound/soc/sdca/sdca_class_function.c
index 1f0b5954a948..7f0533671263 100644
--- a/sound/soc/sdca/sdca_class_function.c
+++ b/sound/soc/sdca/sdca_class_function.c
@@ -214,6 +214,14 @@ static int class_function_set_jack(struct snd_soc_component *component,
{
struct class_function_drv *drv = snd_soc_component_get_drvdata(component);
struct sdca_class_drv *core = drv->core;
+ int ret;
+
+ if (core->ops && core->ops->set_jack) {
+ ret = core->ops->set_jack(core->sdw, core->dev_regmap);
+ if (ret)
+ dev_warn(component->dev,
+ "failed to enable hardware jack detection: %d\n", ret);
+ }
return sdca_jack_set_jack(core->irq_info, jack);
}
diff --git a/sound/soc/sdca/sdca_interrupts.c b/sound/soc/sdca/sdca_interrupts.c
index 2c3f16093969..d871c7d6b8a0 100644
--- a/sound/soc/sdca/sdca_interrupts.c
+++ b/sound/soc/sdca/sdca_interrupts.c
@@ -648,8 +648,10 @@ struct sdca_interrupt_info *devm_sdca_irq_allocate(struct device *sdev,
info->irq_chip = sdca_irq_chip;
- for (i = 0; i < ARRAY_SIZE(info->irqs); i++)
+ for (i = 0; i < ARRAY_SIZE(info->irqs); i++) {
+ info->irqs[i].info = info;
info->irqs[i].device_regmap = regmap;
+ }
ret = devm_mutex_init(sdev, &info->irq_lock);
if (ret)
diff --git a/sound/soc/sdca/sdca_jack.c b/sound/soc/sdca/sdca_jack.c
index 73f8067906a9..8c9ca3b51d27 100644
--- a/sound/soc/sdca/sdca_jack.c
+++ b/sound/soc/sdca/sdca_jack.c
@@ -19,6 +19,7 @@
#include <sound/control.h>
#include <sound/jack.h>
#include <sound/sdca.h>
+#include <sound/sdca_class.h>
#include <sound/sdca_function.h>
#include <sound/sdca_interrupts.h>
#include <sound/sdca_jack.h>
@@ -36,6 +37,7 @@ int sdca_jack_process(struct sdca_interrupt *interrupt)
{
struct device *dev = interrupt->dev;
struct snd_soc_component *component = interrupt->component;
+ struct sdca_class_drv *core = interrupt->info->core;
struct snd_soc_card *card = component->card;
struct rw_semaphore *rwsem = &card->snd_card->controls_rwsem;
struct jack_state *state = interrupt->priv;
@@ -82,6 +84,14 @@ int sdca_jack_process(struct sdca_interrupt *interrupt)
dev_dbg(dev, "%s: %#x\n", interrupt->name, val);
+ /* core is unset on devices that are not sdca_class_drv users */
+ if (core && core->ops && core->ops->post_jack_irq_process) {
+ ret = core->ops->post_jack_irq_process(core->sdw,
+ core->dev_regmap);
+ if (ret)
+ dev_warn(dev, "jack post-process failed: %d\n", ret);
+ }
+
ucontrol = kzalloc_obj(*ucontrol);
if (!ucontrol)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt
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 15:59 ` Gopi Chandra Sekhar Reddy Kanala
2026-12-05 16:24 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Gopi Chandra Sekhar Reddy Kanala @ 2026-12-05 15:59 UTC (permalink / raw)
To: Charles Keepax, Maciej Strozek, Bard Liao, Pierre-Louis Bossart,
Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown,
Srinivas Kandagatla
Cc: linux-sound, patches, linux-arm-msm,
Gopi Chandra Sekhar Reddy Kanala
The mechanical MBHC comparator (ANA_MBHC_MECH L_DET_EN) was never
armed, so physical headset insertion/removal never raised the GE 35
Detected Mode (SDCA_4) interrupt. It can't simply be added to the
static init_table: arming it before the ASoC machine driver registers
the jack causes a continuous SDCA_4 storm that blocks the deferred
sound-card probe.
Implement wcd9378_sdca_set_jack(): arms the comparator (pullup
current, ANA_MBHC_MECH, debounce, ANA_MBHC_ELECT, RCO_EN) once the
jack is being registered, using the new sdca_class_ops .set_jack
hook. Implement wcd9378_sdca_post_jack_irq_process(): toggles
ANA_MBHC_MECH's DET_TYP bit after every GE 35 interrupt, via the new
.post_jack_irq_process hook, so the shared comparator still catches
the next opposite-direction transition.
Also fix MBHC_CTRL DEVICE_DET's ACCESSORY_TYPE[2:0] field, which
selects what Detected_Mode/Selected_Mode the HW FSM reports on
insertion. The init table wrote value 1, forcing Jack_Unknown: this
only updates Detected_Mode and leaves Selected_Mode untouched, so
sdca_jack_process()'s Jack_Unknown-substitution path ended up
reporting a stale Selected_Mode=0 (Safe_Mode) on every insertion
instead of the real accessory type. Write the reset default of 3
(Headset) instead, so Selected_Mode updates directly and insertion
reports the correct terminal type.
Also fix the GE 35 Selected_Mode range table's handling of Safe_Mode
(mode 0, Unplugged): per the SDCA spec, Safe_Mode is not a Terminal
Type at all, so range_ge35_mode_data previously carried a fabricated
"Unplugged -> HPH" alias row purely to satisfy sdca_asoc.c's
probe-time DAPM route builder, which hard-fails probe if any static
GE mode has no matching range entry. Remove that row, and leave GE 35
mode 0's SU 45 selector control disconnected (val = 0x0) in
ge35_mode0_controls instead -- entity_parse_su_device() skips building
a route for a disconnected (val == 0) selector control entirely, so no
range entry is required for mode 0 any more, and ge_count_routes()
applies the same filter so the route array stays correctly sized.
sdca_jack_report() then reports Safe_Mode correctly for free, via
sdca_range_search()'s natural "no match -> type 0" return, with no
driver-side alias needed. It also drops a duplicate item from the
Selected_Mode enum, which already carries "Jack Unplugged" (value 0)
unconditionally ahead of the range-derived entries.
Servicing that interrupt needs DP0_INT.SDCA_CASCADE to deassert, and
on this part it does not. SDCA defines the bit as the read-only output
of an OR over the post-mask SDCA interrupt status bits, with no clear
path of its own, so the bus driver deliberately does not write it, see
commit b3a6809e623c ("soundwire: bus: don't clear SDCA_CASCADE bit").
A WCD9378 does not behave that way: the bit latches. Measured on a
jack insert, with both reads issued back to back on the same bus with
nothing in between, all four SCP_SDCA_INT1-4 registers read 0x00 while
DP0_INT still read 0x08:
wcd9378: mbhc: SDCA_INT pre 08000000 mask 10000000 post 00000000 DP0 0x8
Left asserted the cascade holds SCP_INT1.PORT_0 set, so the peripheral
never leaves ALERT. sdw_handle_slave_alerts() ORs sdca_cascade into
its loop condition, which a stuck bit keeps true on its own, and every
jack event ends in:
sdw:3:0217:0110:00:3 Reached MAX_RETRY on alert read
Clear the bit from the peripheral's own .interrupt_callback(). That
callback runs after handle_nested_irq() has serviced the cascaded SDCA
sources and before the bus re-reads DP0_INT for its end-of-iteration
check, which makes it the one place the write is both safe and
effective, and it leaves the bus driver untouched: its spec behaviour
stays intact for every other SDCA peripheral.
The init-table write of DP0_INT is dropped as well: the bit re-latches
at runtime, so acking it once at probe does nothing.
With this in place the jack flow completes and no MAX_RETRY is
reported.
Signed-off-by: Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>
---
sound/soc/codecs/wcd9378-sdca.c | 155 ++++++++++++++++++++++++++++++++++------
sound/soc/codecs/wcd9378-sdca.h | 2 +
sound/soc/codecs/wcd9378-sdw.c | 3 +-
3 files changed, 137 insertions(+), 23 deletions(-)
diff --git a/sound/soc/codecs/wcd9378-sdca.c b/sound/soc/codecs/wcd9378-sdca.c
index efbbeb3dc721..8bfb2b10b526 100644
--- a/sound/soc/codecs/wcd9378-sdca.c
+++ b/sound/soc/codecs/wcd9378-sdca.c
@@ -101,15 +101,11 @@ static u32 range_su_sel_data[] = { 0x0, 0x1 };
static u32 range_pde_req_ps_data[] = { 0x0, 0x3 };
/*
- * GE 35 SelectedMode -> terminal type.
- *
- * Tambora MBHC only handles mechanical detection; ADC HP/HS
- * discrimination is not implemented, so modes 0 (Unplugged) and 1
- * (Unknown) are aliased to Headphone (mode 4) to keep the DAPM path
- * alive. Mode 2 (Line-out) is not fitted on this board.
+ * GE 35 SelectedMode -> terminal type. Mode 1 (Unknown) is aliased to
+ * Headphone as this part only does mechanical detection. Mode 0
+ * (Unplugged) has no terminal type and is omitted.
*/
static u32 range_ge35_mode_data[] = {
- 0x0, 0x6c0, /* Unplugged -> HPH (alias) */
0x1, 0x6c0, /* Unknown -> HPH (alias) */
0x3, 0x6d0, /* Headset */
0x4, 0x6c0, /* Headphone */
@@ -408,13 +404,9 @@ static struct sdca_control entity_pde47_controls[] = {
static struct sdca_entity *entity_ot43_sources[] = { &wcd9378_sdca_entities[QSJ_IT41] };
static struct sdca_entity *entity_ot45_sources[] = { &wcd9378_sdca_entities[QSJ_IT41] };
-/*
- * GE 35 mode -> SU selector. Modes 0/1 alias to Headphone (see
- * range_ge35_mode_data). SU 45 = source 1 (XU 42) for HPH paths,
- * SU 43 = source 1 (XU 42) for Headset.
- */
+/* GE 35 mode -> SU selector. Mode 0 (Unplugged) leaves SU 45 disconnected. */
static struct sdca_ge_control ge35_mode0_controls[] = {
- { .id = 0x8, .sel = 0x1, .cn = 0x0, .val = 0x1 },
+ { .id = 0x8, .sel = 0x1, .cn = 0x0, .val = 0x0 },
};
static struct sdca_ge_control ge35_mode1_controls[] = {
@@ -440,7 +432,7 @@ static struct sdca_control entity_ge35_controls[] = {
{ .sel = SDCA_CTL_GE_SELECTED_MODE, .mode = SDCA_ACCESS_MODE_RW,
.layers = SDCA_ACCESS_LAYER_CLASS, .cn_list = 0x1,
.interrupt_position = SDCA_NO_INTERRUPT,
- .range = { .cols = 0x2, .rows = 0x4, .data = range_ge35_mode_data },
+ .range = { .cols = 0x2, .rows = 0x3, .data = range_ge35_mode_data },
.has_reset = true, .reset = 0,
.label = SDCA_CTL_SELECTED_MODE_NAME },
{ .sel = 0x2, .mode = SDCA_ACCESS_MODE_RO, .layers = SDCA_ACCESS_LAYER_CLASS, .cn_list = 0x1,
@@ -813,8 +805,7 @@ static struct sdca_init_write wcd9378_sdca_init_table[] = {
{ .addr = 0x401804f2, .val = 0x80 }, /* DRE_DLY_VAL SWR_HPHL(0) */
{ .addr = 0x401804f2, .val = 0x00 }, /* DRE_DLY_VAL SWR_HPHR(0) */
{ .addr = 0x40180501, .val = 0x01 }, /* SEQR_CTRL SYS_USAGE_CTRL */
- /* Arms MBHC: jack insertion asserts SDCA_4 (GE_DETECTED_MODE). */
- { .addr = 0x40180601, .val = 0x01 }, /* MBHC_CTRL DEVICE_DET */
+ { .addr = 0x40180601, .val = 0x03 }, /* MBHC_CTRL DEVICE_DET */
{ .addr = 0x40180414, .val = 0x00 }, /* CDC_COMP_CTL_0 */
{ .addr = 0x401804f2, .val = 0x88 }, /* DRE_DLY_VAL */
{ .addr = 0x40180517, .val = 0x07 }, /* SEQR_CTRL HPH_UP_T7 */
@@ -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 */
/* Only SDCA_4 unmasked; protection IRQs stay masked. */
{ .addr = 0x0000005c, .val = 0x10 }, /* INTMASK_1 SDCA_4 (GE_DETECTED_MODE) */
{ .addr = 0x4018016a, .val = 0x00 }, /* CP_DTOP_CTRL_14 */
{ .addr = 0x40180165, .val = 0x6b }, /* CP_DTOP_CTRL_9 */
- /*
- * L_DET_EN is left disabled: asserting SDCA_4 before the machine
- * card registers the jack blocks the deferred card probe.
- */
};
/* Function Descriptor */
@@ -860,6 +846,18 @@ static struct sdca_function_data wcd9378_sdca_data = {
/* Vendor SCP register: host clock divide-by-2 (bank 1 shadow). */
#define WCD9378_SCP_HOST_CLK_DIV2_CTL_B1 0xf0
+#define WCD9378_ANA_MBHC_MECH_ADDR 0x40180014
+#define WCD9378_ANA_MBHC_MECH_ENABLE 0xb5
+#define WCD9378_ANA_MBHC_MECH_DET_TYP 0x20
+#define WCD9378_ANA_MBHC_ELECT_ADDR 0x40180015
+#define WCD9378_ANA_MBHC_ELECT_BIAS_EN 0x01
+#define WCD9378_MBHC_NEW_INT_MECH_DET_CURRENT_ADDR 0x401801b1
+#define WCD9378_MBHC_HSDET_PULLUP_CTL_2P0_UA 0x08
+#define WCD9378_MBHC_NEW_PLUG_DETECT_CTL_ADDR 0x40180122
+#define WCD9378_MBHC_INSREM_DBNC_96MS 0x06
+#define WCD9378_MBHC_NEW_CTL_1_ADDR 0x40180120
+#define WCD9378_MBHC_NEW_CTL_1_RCO_EN 0x80
+
/* Slave ports 1..8, mapped to master ports via qcom,port-mapping. */
#define WCD9378_SDCA_MAX_PORTS 8
@@ -867,6 +865,30 @@ static const char * const wcd9378_sdca_supplies[] = {
"vdd-buck", "vdd-rxtx", "vdd-io", "vdd-mic-bias",
};
+/*
+ * SDCA_CASCADE is specified as the read-only OR of the SDCA interrupt
+ * status bits, so the bus driver never writes it. On this part the bit
+ * latches instead: left asserted it holds SCP_INT1.PORT_0 set and the
+ * peripheral never leaves ALERT, so sdw_handle_slave_alerts() retries to
+ * MAX_RETRY on every jack event. Clear it from this callback, which runs
+ * after the cascaded sources have been serviced and before the bus
+ * re-reads DP0_INT.
+ */
+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;
+}
+
int wcd9378_sdca_read_prop(struct sdw_slave *slave)
{
struct sdw_slave_prop *prop = &slave->prop;
@@ -966,8 +988,97 @@ static int wcd9378_sdca_populate_function(struct device *dev,
return 0;
}
+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;
+ }
+
+ 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);
+
+out:
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
+
+ return ret;
+}
+
+/*
+ * MECH_DET_TYP selects the transition direction the mechanical detector is
+ * armed for; toggle it after each event so the next one is still seen.
+ */
+static int wcd9378_sdca_post_jack_irq_process(struct sdw_slave *slave,
+ struct regmap *dev_regmap)
+{
+ struct device *dev = &slave->dev;
+ unsigned int val;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(dev);
+ if (ret < 0) {
+ dev_err(dev, "failed to resume for mech detect rearm: %d\n", ret);
+ return ret;
+ }
+
+ ret = regmap_read(dev_regmap, WCD9378_ANA_MBHC_MECH_ADDR, &val);
+ if (ret) {
+ dev_err(dev, "ANA_MBHC_MECH read for rearm: %d\n", ret);
+ goto out;
+ }
+
+ val ^= WCD9378_ANA_MBHC_MECH_DET_TYP;
+
+ ret = regmap_write(dev_regmap, WCD9378_ANA_MBHC_MECH_ADDR, val);
+ if (ret)
+ dev_err(dev, "ANA_MBHC_MECH write for rearm: %d\n", ret);
+
+out:
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_put_autosuspend(dev);
+
+ return ret;
+}
+
static const struct sdca_class_ops wcd9378_sdca_class_ops = {
- .populate_function = wcd9378_sdca_populate_function,
+ .populate_function = wcd9378_sdca_populate_function,
+ .set_jack = wcd9378_sdca_set_jack,
+ .post_jack_irq_process = wcd9378_sdca_post_jack_irq_process,
};
int wcd9378_sdca_probe(struct sdw_slave *slave,
diff --git a/sound/soc/codecs/wcd9378-sdca.h b/sound/soc/codecs/wcd9378-sdca.h
index 6ddae9da395b..eda37865cbd2 100644
--- a/sound/soc/codecs/wcd9378-sdca.h
+++ b/sound/soc/codecs/wcd9378-sdca.h
@@ -11,6 +11,8 @@ int wcd9378_sdca_probe(struct sdw_slave *slave,
const struct sdw_device_id *id);
void wcd9378_sdca_remove(struct sdw_slave *slave);
int wcd9378_sdca_read_prop(struct sdw_slave *slave);
+int wcd9378_sdca_interrupt_callback(struct sdw_slave *slave,
+ struct sdw_slave_intr_status *status);
int wcd9378_sdca_runtime_suspend(struct device *dev);
int wcd9378_sdca_runtime_resume(struct device *dev);
diff --git a/sound/soc/codecs/wcd9378-sdw.c b/sound/soc/codecs/wcd9378-sdw.c
index 52295e7646cf..f7e2ce963eb1 100644
--- a/sound/soc/codecs/wcd9378-sdw.c
+++ b/sound/soc/codecs/wcd9378-sdw.c
@@ -23,7 +23,8 @@ static const struct dev_pm_ops wcd9378_sdw_pm_ops = {
};
static const struct sdw_slave_ops wcd9378_sdw_ops = {
- .read_prop = wcd9378_sdca_read_prop,
+ .read_prop = wcd9378_sdca_read_prop,
+ .interrupt_callback = wcd9378_sdca_interrupt_callback,
};
static const struct sdw_device_id wcd9378_sdw_id[] = {
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] ASoC: SDCA: add jack ops hooks
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
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-05 16:18 UTC (permalink / raw)
To: Gopi Chandra Sekhar Reddy Kanala; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ASoC: SDCA: set_jack() hardware enable is not restored after
system resume
- [Medium] ASoC: SDCA: class_function_set_jack() enables jack HW even
when jack is NULL
- [Medium] ASoC: SDCA: race between set_jack() and
post_jack_irq_process() hooks
- [Low] ASoC: SDCA: core jack layer couples to sdca_class_drv and omits
lock docs
- [Low] ASoC: SDCA: inaccurate set_jack() doc claim on initial hardware
state read
--
commit 44baabaeaf479d2ea44b8b468dfe123bdbd091ca
Author: Gopi Chandra Sekhar Reddy Kanala <gopi.kanala@oss.qualcomm.com>
ASoC: SDCA: add jack ops hooks
This commit adds optional set_jack and post_jack_irq_process callbacks to
struct sdca_class_ops and wires a back-pointer from sdca_interrupt_info to
sdca_class_drv so sdca_jack_process() can invoke the post-IRQ hook.
> diff --git a/include/sound/sdca_class.h b/include/sound/sdca_class.h
> index 794a756472cd6..073f122633e24 100644
> --- a/include/sound/sdca_class.h
> +++ b/include/sound/sdca_class.h
> @@ -26,10 +26,23 @@ struct sdca_function_data;
> * DT/non-DisCo platforms. Called once per SDCA function with
> * @dev pointing at that function's device. Pure data source;
> * performs no bus I/O. Return 0 on success or a negative errno.
> + * @set_jack: called from the class function driver's ASoC .set_jack, just
> + * before the jack is registered with sdca_jack_set_jack(). Use
> + * to enable detection hardware that must not be active any
> + * earlier. Enabling here means the initial state reported by
> + * sdca_jack_set_jack() already reflects the hardware. May be
> + * NULL.
[Severity: Low]
Is this comment (and the commit message) accurate about the initial state
reported by sdca_jack_set_jack()?
sdca_jack_set_jack() calls sdca_jack_report(), which reads the cached
SDCA_CTL_GE_SELECTED_MODE register rather than volatile
SDCA_CTL_GE_DETECTED_MODE. During snd_soc_card_bind(), machine drivers call
snd_soc_component_set_jack() from dai_link->init or card->late_probe before
snd_soc_component_fixup_controls() invokes sdca_irq_populate() to request
detected_mode_handler(). Because sdca_jack_process() has not run yet,
sdca_jack_set_jack() only reports the cached default value rather than live
hardware state.
[ ... ]
> diff --git a/include/sound/sdca_interrupts.h b/include/sound/sdca_interrupts.h
> index 3b30146e21db5..fa53ccf27b798 100644
> --- a/include/sound/sdca_interrupts.h
> +++ b/include/sound/sdca_interrupts.h
> @@ -60,6 +63,9 @@ struct sdca_interrupt {
> * struct sdca_interrupt_info - contains top-level SDCA interrupt information
> * @irq_chip: regmap irq chip structure.
> * @irq_data: regmap irq chip data structure.
> + * @core: Optional pointer to the device-level SDCA class driver owning
> + * this interrupt information, letting Function-level handlers reach the
> + * device's ops. Left NULL by drivers that do not use sdca_class_drv.
> * @irqs: Array of data for each individual IRQ.
> * @irq_lock: Protects access to the list of sdca_interrupt structures.
> */
> @@ -67,6 +73,8 @@ struct sdca_interrupt_info {
> struct regmap_irq_chip irq_chip;
> struct regmap_irq_chip_data *irq_data;
>
> + struct sdca_class_drv *core;
> +
> struct sdca_interrupt irqs[SDCA_MAX_INTERRUPTS];
[Severity: Low]
Should struct sdca_interrupt_info carry a direct pointer to
struct sdca_class_drv? This couples the reusable core snd-soc-sdca library
(sdca_interrupts.h and sdca_jack.c) to the upper-layer class driver instead
of using a generic jack or interrupt callback or wrapping the IRQ handler
via sdca_irq_request().
Separately, sdca_jack_process() calls post_jack_irq_process() while holding
card->snd_card->controls_rwsem for writing, and runs it before updating
SELECTED_MODE via snd_soc_dapm_put_enum_double() and calling
sdca_jack_report(). The struct sdca_class_ops kernel-doc does not mention
the held controls_rwsem lock or the sleepable and runtime PM expectations
for these callbacks.
[ ... ]
> diff --git a/sound/soc/sdca/sdca_class_function.c b/sound/soc/sdca/sdca_class_function.c
> index 1f0b5954a948c..7f05336712639 100644
> --- a/sound/soc/sdca/sdca_class_function.c
> +++ b/sound/soc/sdca/sdca_class_function.c
> @@ -214,6 +214,14 @@ static int class_function_set_jack(struct snd_soc_component *component,
> {
> struct class_function_drv *drv = snd_soc_component_get_drvdata(component);
> struct sdca_class_drv *core = drv->core;
> + int ret;
> +
> + if (core->ops && core->ops->set_jack) {
> + ret = core->ops->set_jack(core->sdw, core->dev_regmap);
> + if (ret)
> + dev_warn(component->dev,
> + "failed to enable hardware jack detection: %d\n", ret);
> + }
>
> return sdca_jack_set_jack(core->irq_info, jack);
> }
[Severity: Medium]
Should core->ops->set_jack() be called when jack is NULL?
ASoC machine drivers call snd_soc_component_set_jack(component, NULL, NULL)
to detach the jack on card teardown or probe-deferral rollback, for example
in qcom_snd_headset_jack_cleanup(). Because set_jack() takes neither jack
nor an enable flag and is called unconditionally here, teardown re-enables
hardware jack detection with no attached jack and gives codec drivers no way
to disable it. Passing jack (or an enable boolean) to the callback would
let drivers distinguish attach from detach.
[Severity: High]
How is hardware jack detection restored after system suspend and resume?
Machine drivers invoke snd_soc_component_set_jack() once during
dai_link->init, not on system resume. During system resume,
class_function_runtime_resume() resets the function and replays init_table
(which no longer enables jack detection), while class_dev_regmap_volatile()
marks every register in core->dev_regmap except SDW_SCP_SDCA_INTMASK1..4 as
volatile so regcache_sync(drv->dev_regmap) does not restore vendor
jack-detection registers written by core->ops->set_jack(). Without
tracking whether a jack is attached and re-invoking set_jack() on resume
after class_function_init_device(), hardware jack detection stays disabled
after the first system suspend/resume cycle.
[ ... ]
> diff --git a/sound/soc/sdca/sdca_jack.c b/sound/soc/sdca/sdca_jack.c
> index 73f8067906a90..8c9ca3b51d272 100644
> --- a/sound/soc/sdca/sdca_jack.c
> +++ b/sound/soc/sdca/sdca_jack.c
> @@ -82,6 +84,14 @@ int sdca_jack_process(struct sdca_interrupt *interrupt)
>
> dev_dbg(dev, "%s: %#x\n", interrupt->name, val);
>
> + /* core is unset on devices that are not sdca_class_drv users */
> + if (core && core->ops && core->ops->post_jack_irq_process) {
> + ret = core->ops->post_jack_irq_process(core->sdw,
> + core->dev_regmap);
> + if (ret)
> + dev_warn(dev, "jack post-process failed: %d\n", ret);
> + }
> +
> ucontrol = kzalloc_obj(*ucontrol);
> if (!ucontrol)
> return -ENOMEM;
[Severity: Medium]
Can core->ops->post_jack_irq_process() race with core->ops->set_jack()?
During card teardown, snd_soc_card_cleanup_resources() runs
snd_soc_link_exit() before snd_soc_card_link_components_remove() frees the
jack IRQ via sdca_irq_cleanup():
CPU0 CPU1 (threaded IRQ)
snd_soc_card_cleanup_resources()
snd_soc_link_exit()
class_function_set_jack()
ops->set_jack(...)
detected_mode_handler()
sdca_jack_process()
guard(rwsem_write)(rwsem)
ops->post_jack_irq_process(...)
<-- concurrent regmap writes
snd_soc_card_link_components_remove()
sdca_irq_cleanup()
class_function_set_jack() holds neither controls_rwsem nor irq_lock, so
multi-register sequences and read-modify-write updates in set_jack() and
post_jack_irq_process() can interleave on core->dev_regmap and corrupt the
hardware jack-detection state. Serializing both hooks under a common lock
(or disabling the jack IRQ around set_jack()) would prevent the race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-b4-sdca-wcd9378-jack-v1-0-60ec9bff39ea@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] ASoC: codecs: wcd9378-sdca: enable MBHC jack-detect (GE 35) interrupt
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
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-05 16:24 UTC (permalink / raw)
To: Gopi Chandra Sekhar Reddy Kanala; +Cc: linux-sound
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-05 16:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.