summaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/cs42l84.c
diff options
context:
space:
mode:
authorJames Calligeros <jcalligeros99@gmail.com>2024-10-19 16:47:33 +0200
committerMark Brown <broonie@kernel.org>2024-10-24 17:09:19 +0200
commit2391b8719d686b1947b5f81250281fa112da91dc (patch)
treea408dd43bece00f521666d9b96af57e0e3cba5cd /sound/soc/codecs/cs42l84.c
parentASoC: cs42l84: Add new codec driver (diff)
downloadlinux-2391b8719d686b1947b5f81250281fa112da91dc.tar.xz
linux-2391b8719d686b1947b5f81250281fa112da91dc.zip
ASoC: cs42l84: leverage ring sense IRQs to correctly detect headsets
Some jacks integrated on devices with this codec, such as certain Apple Silicon Macs, have quite trigger-happy tip sense switches that cause a tip sense IRQ before the plug is fully seated. If users are unfortunate with their timing, this can lead to headsets being detected as mic-less headphones among other issues with the codec's device detection routines. Introduce some rudimentary ring sense interrupt handling so that we can re-trigger the codec's detection routines when we are certain that the plug is fully seated. This seems to differ from what other Cirrus drivers do, but is necessary for devices to be reliably detected properly here. Signed-off-by: James Calligeros <jcalligeros99@gmail.com> Reviewed-by: Neal Gompa <neal@gompa.dev> Link: https://patch.msgid.link/20241020-cs42l84-v2-3-37ba2b6721d9@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to '')
-rw-r--r--sound/soc/codecs/cs42l84.c90
1 files changed, 60 insertions, 30 deletions
diff --git a/sound/soc/codecs/cs42l84.c b/sound/soc/codecs/cs42l84.c
index 84a1e8ac818c..47731cdc0e67 100644
--- a/sound/soc/codecs/cs42l84.c
+++ b/sound/soc/codecs/cs42l84.c
@@ -44,7 +44,8 @@ struct cs42l84_private {
struct gpio_desc *reset_gpio;
struct snd_soc_jack *jack;
struct mutex irq_lock;
- u8 plug_state;
+ u8 tip_state;
+ u8 ring_state;
int pll_config;
int bclk;
u8 pll_mclk_f;
@@ -798,13 +799,23 @@ static void cs42l84_revert_hs(struct cs42l84_private *cs42l84)
FIELD_PREP(CS42L84_HS_DET_CTL2_SET, 2));
}
+static void cs42l84_set_interrupt_masks(struct cs42l84_private *cs42l84,
+ unsigned int val)
+{
+ regmap_update_bits(cs42l84->regmap, CS42L84_TSRS_PLUG_INT_MASK,
+ CS42L84_RS_PLUG | CS42L84_RS_UNPLUG |
+ CS42L84_TS_PLUG | CS42L84_TS_UNPLUG,
+ val);
+}
+
static irqreturn_t cs42l84_irq_thread(int irq, void *data)
{
struct cs42l84_private *cs42l84 = (struct cs42l84_private *)data;
unsigned int stickies[1];
unsigned int masks[1];
unsigned int reg;
- u8 current_plug_status;
+ u8 current_tip_state;
+ u8 current_ring_state;
int i;
mutex_lock(&cs42l84->irq_lock);
@@ -818,16 +829,24 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data)
irq_params_table[i].mask;
}
+ /* When handling plug sene IRQs, we only care about EITHER tip OR ring.
+ * Ring is useless on remove, and is only useful on insert for
+ * detecting if the plug state has changed AFTER we have handled the
+ * tip sense IRQ, e.g. if the plug was not fully seated within the tip
+ * sense debounce time.
+ */
+
if ((~masks[0]) & irq_params_table[0].mask) {
regmap_read(cs42l84->regmap, CS42L84_TSRS_PLUG_STATUS, &reg);
- current_plug_status = (((char) reg) &
+
+ current_tip_state = (((char) reg) &
(CS42L84_TS_PLUG | CS42L84_TS_UNPLUG)) >>
CS42L84_TS_PLUG_SHIFT;
- switch (current_plug_status) {
- case CS42L84_PLUG:
- if (cs42l84->plug_state != CS42L84_PLUG) {
- cs42l84->plug_state = CS42L84_PLUG;
+ if (current_tip_state != cs42l84->tip_state) {
+ cs42l84->tip_state = current_tip_state;
+ switch (current_tip_state) {
+ case CS42L84_PLUG:
dev_dbg(cs42l84->dev, "Plug event\n");
cs42l84_detect_hs(cs42l84);
@@ -840,47 +859,58 @@ static irqreturn_t cs42l84_irq_thread(int irq, void *data)
* was disconnected at any point during the detection procedure.
*/
regmap_read(cs42l84->regmap, CS42L84_TSRS_PLUG_STATUS, &reg);
- current_plug_status = (((char) reg) &
+ current_tip_state = (((char) reg) &
(CS42L84_TS_PLUG | CS42L84_TS_UNPLUG)) >>
CS42L84_TS_PLUG_SHIFT;
- if (current_plug_status != CS42L84_PLUG) {
+ if (current_tip_state != CS42L84_PLUG) {
dev_dbg(cs42l84->dev, "Wobbly connection, detection invalidated\n");
- cs42l84->plug_state = CS42L84_UNPLUG;
+ cs42l84->tip_state = CS42L84_UNPLUG;
cs42l84_revert_hs(cs42l84);
}
- }
- break;
- case CS42L84_UNPLUG:
- if (cs42l84->plug_state != CS42L84_UNPLUG) {
- cs42l84->plug_state = CS42L84_UNPLUG;
+ /* Unmask ring sense interrupts */
+ cs42l84_set_interrupt_masks(cs42l84, 0);
+ break;
+ case CS42L84_UNPLUG:
+ cs42l84->ring_state = CS42L84_UNPLUG;
dev_dbg(cs42l84->dev, "Unplug event\n");
cs42l84_revert_hs(cs42l84);
cs42l84->hs_type = 0;
snd_soc_jack_report(cs42l84->jack, 0,
SND_JACK_HEADSET);
+
+ /* Mask ring sense interrupts */
+ cs42l84_set_interrupt_masks(cs42l84,
+ CS42L84_RS_PLUG | CS42L84_RS_UNPLUG);
+ break;
+ default:
+ cs42l84->ring_state = CS42L84_TRANS;
+ break;
}
- break;
- default:
- if (cs42l84->plug_state != CS42L84_TRANS)
- cs42l84->plug_state = CS42L84_TRANS;
+ mutex_unlock(&cs42l84->irq_lock);
+
+ return IRQ_HANDLED;
+ }
+
+ /* Tip state didn't change, we must've got a ring sense IRQ */
+ current_ring_state = (((char) reg) &
+ (CS42L84_RS_PLUG | CS42L84_RS_UNPLUG)) >>
+ CS42L84_RS_PLUG_SHIFT;
+
+ if (current_ring_state != cs42l84->ring_state) {
+ cs42l84->ring_state = current_ring_state;
+ if (current_ring_state == CS42L84_PLUG)
+ cs42l84_detect_hs(cs42l84);
}
}
+
mutex_unlock(&cs42l84->irq_lock);
return IRQ_HANDLED;
}
-static void cs42l84_set_interrupt_masks(struct cs42l84_private *cs42l84)
-{
- regmap_update_bits(cs42l84->regmap, CS42L84_TSRS_PLUG_INT_MASK,
- CS42L84_RS_PLUG | CS42L84_RS_UNPLUG |
- CS42L84_TS_PLUG | CS42L84_TS_UNPLUG,
- CS42L84_RS_PLUG | CS42L84_RS_UNPLUG);
-}
-
static void cs42l84_setup_plug_detect(struct cs42l84_private *cs42l84)
{
unsigned int reg;
@@ -910,7 +940,7 @@ static void cs42l84_setup_plug_detect(struct cs42l84_private *cs42l84)
/* Save the initial status of the tip sense */
regmap_read(cs42l84->regmap, CS42L84_TSRS_PLUG_STATUS, &reg);
- cs42l84->plug_state = (((char) reg) &
+ cs42l84->tip_state = (((char) reg) &
(CS42L84_TS_PLUG | CS42L84_TS_UNPLUG)) >>
CS42L84_TS_PLUG_SHIFT;
@@ -1017,8 +1047,8 @@ static int cs42l84_i2c_probe(struct i2c_client *i2c_client)
/* Setup plug detection */
cs42l84_setup_plug_detect(cs42l84);
- /* Mask/Unmask Interrupts */
- cs42l84_set_interrupt_masks(cs42l84);
+ /* Mask ring sense interrupts */
+ cs42l84_set_interrupt_masks(cs42l84, CS42L84_RS_PLUG | CS42L84_RS_UNPLUG);
/* Register codec for machine driver */
ret = devm_snd_soc_register_component(&i2c_client->dev,