Skip to content

Commit 7fde88e

Browse files
David Raubroonie
authored andcommitted
ASoC: da7219: Improve the IRQ process to increase the stability
Remove the sleep control in IRQ thread and create an individual task to handel it for Jack plug in event. This commit improves the control of ground switches in the AAD IRQ. Signed-off-by: David Rau <David.Rau.opensource@dm.renesas.com> Link: https://lore.kernel.org/r/20230215101045.21456-1-David.Rau.opensource@dm.renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 76f5aaa commit 7fde88e

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

sound/soc/codecs/da7219-aad.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,26 +339,49 @@ static void da7219_aad_hptest_work(struct work_struct *work)
339339
SND_JACK_HEADSET | SND_JACK_LINEOUT);
340340
}
341341

342+
static void da7219_aad_jack_det_work(struct work_struct *work)
343+
{
344+
struct da7219_aad_priv *da7219_aad =
345+
container_of(work, struct da7219_aad_priv, jack_det_work);
346+
struct snd_soc_component *component = da7219_aad->component;
347+
u8 srm_st;
348+
349+
mutex_lock(&da7219_aad->jack_det_mutex);
350+
351+
srm_st = snd_soc_component_read(component, DA7219_PLL_SRM_STS) & DA7219_PLL_SRM_STS_MCLK;
352+
msleep(da7219_aad->gnd_switch_delay * ((srm_st == 0x0) ? 2 : 1) - 4);
353+
/* Enable ground switch */
354+
snd_soc_component_update_bits(component, 0xFB, 0x01, 0x01);
355+
356+
mutex_unlock(&da7219_aad->jack_det_mutex);
357+
}
358+
342359

343360
/*
344361
* IRQ
345362
*/
346363

364+
static irqreturn_t da7219_aad_pre_irq_thread(int irq, void *data)
365+
{
366+
367+
struct da7219_aad_priv *da7219_aad = data;
368+
369+
if (!da7219_aad->jack_inserted)
370+
schedule_work(&da7219_aad->jack_det_work);
371+
372+
return IRQ_WAKE_THREAD;
373+
}
374+
347375
static irqreturn_t da7219_aad_irq_thread(int irq, void *data)
348376
{
349377
struct da7219_aad_priv *da7219_aad = data;
350378
struct snd_soc_component *component = da7219_aad->component;
351379
struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
352380
struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
353381
u8 events[DA7219_AAD_IRQ_REG_MAX];
354-
u8 statusa, srm_st;
382+
u8 statusa;
355383
int i, report = 0, mask = 0;
356384

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-
362385
/* Read current IRQ events */
363386
regmap_bulk_read(da7219->regmap, DA7219_ACCDET_IRQ_EVENT_A,
364387
events, DA7219_AAD_IRQ_REG_MAX);
@@ -377,6 +400,9 @@ static irqreturn_t da7219_aad_irq_thread(int irq, void *data)
377400
events[DA7219_AAD_IRQ_REG_A], events[DA7219_AAD_IRQ_REG_B],
378401
statusa);
379402

403+
if (!da7219_aad->jack_inserted)
404+
cancel_work_sync(&da7219_aad->jack_det_work);
405+
380406
if (statusa & DA7219_JACK_INSERTION_STS_MASK) {
381407
/* Jack Insertion */
382408
if (events[DA7219_AAD_IRQ_REG_A] &
@@ -940,8 +966,9 @@ int da7219_aad_init(struct snd_soc_component *component)
940966

941967
INIT_WORK(&da7219_aad->btn_det_work, da7219_aad_btn_det_work);
942968
INIT_WORK(&da7219_aad->hptest_work, da7219_aad_hptest_work);
969+
INIT_WORK(&da7219_aad->jack_det_work, da7219_aad_jack_det_work);
943970

944-
ret = request_threaded_irq(da7219_aad->irq, NULL,
971+
ret = request_threaded_irq(da7219_aad->irq, da7219_aad_pre_irq_thread,
945972
da7219_aad_irq_thread,
946973
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
947974
"da7219-aad", da7219_aad);

sound/soc/codecs/da7219-aad.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define __DA7219_AAD_H
1212

1313
#include <linux/timer.h>
14+
#include <linux/mutex.h>
1415
#include <sound/soc.h>
1516
#include <sound/jack.h>
1617
#include <sound/da7219-aad.h>
@@ -196,6 +197,9 @@ struct da7219_aad_priv {
196197

197198
struct work_struct btn_det_work;
198199
struct work_struct hptest_work;
200+
struct work_struct jack_det_work;
201+
202+
struct mutex jack_det_mutex;
199203

200204
struct snd_soc_jack *jack;
201205
bool micbias_resume_enable;

0 commit comments

Comments
 (0)