* [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