Skip to content

Commit 969357e

Browse files
davidrau0914broonie
authored andcommitted
ASoC: da7219: Fix pole orientation detection on OMTP headsets when playing music
The OMTP pin define headsets can be mis-detected as line out instead of OMTP, causing obvious issues with audio quality. This patch is to put increased resistances within the device at a suitable point. To solve this issue better, the new mechanism setup ground switches with conditional delay control and these allow for more stabile detection process to operate as intended. This conditional delay control will not impact the hardware process but use extra system resource. This commit improves control of ground switches in the AAD logic. Signed-off-by: David Rau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent c1dd6bf commit 969357e

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

sound/soc/codecs/da7219-aad.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,14 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data)
351351
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
352352
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
353353
u8 events[DA7219_AAD_IRQ_REG_MAX];
354-
u8 statusa;
354+
u8 statusa, srm_st;
355355
int i, report = 0, mask = 0;
356356

357+
srm_st = snd_soc_component_read(component, DA7219_PLL_SRM_STS) & DA7219_PLL_SRM_STS_MCLK;
358+
msleep(da7219_aad->gnd_switch_delay * ((srm_st == 0x0) ? 2 : 1) - 4);
359+
/* Enable ground switch */
360+
snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01);
361+
357362
/* Read current IRQ events */
358363
regmap_bulk_read(da7219->regmap, DA7219_ACCDET_IRQ_EVENT_A,
359364
events, DA7219_AAD_IRQ_REG_MAX);
@@ -453,8 +458,8 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data)
453458
snd_soc_dapm_disable_pin(dapm, "Mic Bias");
454459
snd_soc_dapm_sync(dapm);
455460

456-
/* Enable ground switch */
457-
snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01);
461+
/* Disable ground switch */
462+
snd_soc_component_update_bits(component, 0xFB, 0x01, 0x00);
458463
}
459464
}
460465

@@ -830,6 +835,32 @@ static void da7219_aad_handle_pdata(struct snd_soc_component *component)
830835
}
831836
}
832837

838+
static void da7219_aad_handle_gnd_switch_time(struct snd_soc_component *component)
839+
{
840+
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
841+
struct da7219_aad_priv *da7219_aad = da7219->aad;
842+
u8 jack_det;
843+
844+
jack_det = snd_soc_component_read(component, DA7219_ACCDET_CONFIG_2)
845+
& DA7219_JACK_DETECT_RATE_MASK;
846+
switch (jack_det) {
847+
case 0x00:
848+
da7219_aad->gnd_switch_delay = 32;
849+
break;
850+
case 0x10:
851+
da7219_aad->gnd_switch_delay = 64;
852+
break;
853+
case 0x20:
854+
da7219_aad->gnd_switch_delay = 128;
855+
break;
856+
case 0x30:
857+
da7219_aad->gnd_switch_delay = 256;
858+
break;
859+
default:
860+
da7219_aad->gnd_switch_delay = 32;
861+
break;
862+
}
863+
}
833864

834865
/*
835866
* Suspend/Resume
@@ -907,9 +938,6 @@ int da7219_aad_init(struct snd_soc_component *component)
907938
snd_soc_component_update_bits(component, DA7219_ACCDET_CONFIG_1,
908939
DA7219_BUTTON_CONFIG_MASK, 0);
909940

910-
/* Enable ground switch */
911-
snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01);
912-
913941
INIT_WORK(&da7219_aad->btn_det_work, da7219_aad_btn_det_work);
914942
INIT_WORK(&da7219_aad->hptest_work, da7219_aad_hptest_work);
915943

@@ -927,6 +955,8 @@ int da7219_aad_init(struct snd_soc_component *component)
927955
regmap_bulk_write(da7219->regmap, DA7219_ACCDET_IRQ_MASK_A,
928956
&mask, DA7219_AAD_IRQ_REG_MAX);
929957

958+
da7219_aad_handle_gnd_switch_time(component);
959+
930960
return 0;
931961
}
932962

sound/soc/codecs/da7219-aad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ enum da7219_aad_event_regs {
187187
struct da7219_aad_priv {
188188
struct snd_soc_component *component;
189189
int irq;
190+
int gnd_switch_delay;
190191

191192
u8 micbias_pulse_lvl;
192193
u32 micbias_pulse_time;

0 commit comments

Comments
 (0)