@@ -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+
347375static 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 );
0 commit comments