@@ -530,12 +530,61 @@ static int nau8540_set_tdm_slot(struct snd_soc_dai *dai,
530
530
return 0 ;
531
531
}
532
532
533
+ static int nau8540_dai_trigger (struct snd_pcm_substream * substream ,
534
+ int cmd , struct snd_soc_dai * dai )
535
+ {
536
+ struct snd_soc_component * component = dai -> component ;
537
+ struct nau8540 * nau8540 = snd_soc_component_get_drvdata (component );
538
+ struct regmap * regmap = nau8540 -> regmap ;
539
+ unsigned int val ;
540
+ int ret = 0 ;
541
+
542
+ /* Reading the peak data to detect abnormal data in the ADC channel.
543
+ * If abnormal data happens, the driver takes recovery actions to
544
+ * refresh the ADC channel.
545
+ */
546
+ switch (cmd ) {
547
+ case SNDRV_PCM_TRIGGER_START :
548
+ regmap_update_bits (regmap , NAU8540_REG_CLOCK_CTRL ,
549
+ NAU8540_CLK_AGC_EN , NAU8540_CLK_AGC_EN );
550
+ regmap_update_bits (regmap , NAU8540_REG_ALC_CONTROL_3 ,
551
+ NAU8540_ALC_CH_ALL_EN , NAU8540_ALC_CH_ALL_EN );
552
+
553
+ regmap_read (regmap , NAU8540_REG_PEAK_CH1 , & val );
554
+ dev_dbg (nau8540 -> dev , "1.ADC CH1 peak data %x" , val );
555
+ if (!val ) {
556
+ regmap_update_bits (regmap , NAU8540_REG_MUTE ,
557
+ NAU8540_PGA_CH_ALL_MUTE , NAU8540_PGA_CH_ALL_MUTE );
558
+ regmap_update_bits (regmap , NAU8540_REG_MUTE ,
559
+ NAU8540_PGA_CH_ALL_MUTE , 0 );
560
+ regmap_write (regmap , NAU8540_REG_RST , 0x1 );
561
+ regmap_write (regmap , NAU8540_REG_RST , 0 );
562
+ regmap_read (regmap , NAU8540_REG_PEAK_CH1 , & val );
563
+ dev_dbg (nau8540 -> dev , "2.ADC CH1 peak data %x" , val );
564
+ if (!val ) {
565
+ dev_err (nau8540 -> dev , "Channel recovery failed!!" );
566
+ ret = - EIO ;
567
+ }
568
+ }
569
+ regmap_update_bits (regmap , NAU8540_REG_CLOCK_CTRL ,
570
+ NAU8540_CLK_AGC_EN , 0 );
571
+ regmap_update_bits (regmap , NAU8540_REG_ALC_CONTROL_3 ,
572
+ NAU8540_ALC_CH_ALL_EN , 0 );
573
+ break ;
574
+
575
+ default :
576
+ break ;
577
+ }
578
+
579
+ return ret ;
580
+ }
533
581
534
582
static const struct snd_soc_dai_ops nau8540_dai_ops = {
535
583
.startup = nau8540_dai_startup ,
536
584
.hw_params = nau8540_hw_params ,
537
585
.set_fmt = nau8540_set_fmt ,
538
586
.set_tdm_slot = nau8540_set_tdm_slot ,
587
+ .trigger = nau8540_dai_trigger ,
539
588
};
540
589
541
590
#define NAU8540_RATES SNDRV_PCM_RATE_8000_48000
0 commit comments