@@ -484,6 +484,33 @@ static int rt1015_bypass_boost_get(struct snd_kcontrol *kcontrol,
484484 return 0 ;
485485}
486486
487+ static void rt1015_calibrate (struct rt1015_priv * rt1015 )
488+ {
489+ struct snd_soc_component * component = rt1015 -> component ;
490+ struct regmap * regmap = rt1015 -> regmap ;
491+
492+ snd_soc_dapm_mutex_lock (& component -> dapm );
493+ regcache_cache_bypass (regmap , true);
494+
495+ regmap_write (regmap , RT1015_PWR1 , 0xd7df );
496+ regmap_write (regmap , RT1015_PWR4 , 0x00b2 );
497+ regmap_write (regmap , RT1015_CLSD_INTERNAL8 , 0x2008 );
498+ regmap_write (regmap , RT1015_CLSD_INTERNAL9 , 0x0140 );
499+ regmap_write (regmap , RT1015_GAT_BOOST , 0x0efe );
500+ regmap_write (regmap , RT1015_PWR_STATE_CTRL , 0x000d );
501+ regmap_write (regmap , RT1015_PWR_STATE_CTRL , 0x000e );
502+ regmap_write (regmap , RT1015_DC_CALIB_CLSD1 , 0x5a00 );
503+ regmap_write (regmap , RT1015_DC_CALIB_CLSD1 , 0x5a01 );
504+ regmap_write (regmap , RT1015_DC_CALIB_CLSD1 , 0x5a05 );
505+ msleep (500 );
506+ regmap_write (regmap , RT1015_PWR1 , 0x0 );
507+
508+ regcache_cache_bypass (regmap , false);
509+ regcache_mark_dirty (regmap );
510+ regcache_sync (regmap );
511+ snd_soc_dapm_mutex_unlock (& component -> dapm );
512+ }
513+
487514static int rt1015_bypass_boost_put (struct snd_kcontrol * kcontrol ,
488515 struct snd_ctl_elem_value * ucontrol )
489516{
@@ -494,27 +521,45 @@ static int rt1015_bypass_boost_put(struct snd_kcontrol *kcontrol,
494521
495522 if (!rt1015 -> dac_is_used ) {
496523 rt1015 -> bypass_boost = ucontrol -> value .integer .value [0 ];
497- if (rt1015 -> bypass_boost == RT1015_Bypass_Boost ) {
498- snd_soc_component_write (component ,
499- RT1015_PWR4 , 0x00b2 );
500- snd_soc_component_write (component ,
501- RT1015_CLSD_INTERNAL8 , 0x2008 );
502- snd_soc_component_write (component ,
503- RT1015_CLSD_INTERNAL9 , 0x0140 );
504- snd_soc_component_write (component ,
505- RT1015_GAT_BOOST , 0x0efe );
506- snd_soc_component_write (component ,
507- RT1015_PWR_STATE_CTRL , 0x000d );
508- msleep (500 );
509- snd_soc_component_write (component ,
510- RT1015_PWR_STATE_CTRL , 0x000e );
524+ if (rt1015 -> bypass_boost == RT1015_Bypass_Boost &&
525+ !rt1015 -> cali_done ) {
526+ rt1015_calibrate (rt1015 );
527+ rt1015 -> cali_done = 1 ;
528+
529+ regmap_write (rt1015 -> regmap , RT1015_MONO_DYNA_CTRL , 0x0010 );
511530 }
512531 } else
513532 dev_err (component -> dev , "DAC is being used!\n" );
514533
515534 return 0 ;
516535}
517536
537+ static void rt1015_flush_work (struct work_struct * work )
538+ {
539+ struct rt1015_priv * rt1015 = container_of (work , struct rt1015_priv ,
540+ flush_work .work );
541+ struct snd_soc_component * component = rt1015 -> component ;
542+ unsigned int val , i = 0 , count = 20 ;
543+
544+ while (i < count ) {
545+ usleep_range (1000 , 1500 );
546+ dev_dbg (component -> dev , "Flush DAC (retry:%u)\n" , i );
547+ regmap_read (rt1015 -> regmap , RT1015_CLK_DET , & val );
548+ if (val & 0x800 )
549+ break ;
550+ i ++ ;
551+ }
552+
553+ regmap_write (rt1015 -> regmap , RT1015_SYS_RST1 , 0x0597 );
554+ regmap_write (rt1015 -> regmap , RT1015_SYS_RST1 , 0x05f7 );
555+ regmap_write (rt1015 -> regmap , RT1015_MAN_I2C , 0x0028 );
556+
557+ if (val & 0x800 )
558+ dev_dbg (component -> dev , "Flush DAC completed.\n" );
559+ else
560+ dev_warn (component -> dev , "Fail to flush DAC data.\n" );
561+ }
562+
518563static const struct snd_kcontrol_new rt1015_snd_controls [] = {
519564 SOC_SINGLE_TLV ("DAC Playback Volume" , RT1015_DAC1 , RT1015_DAC_VOL_SFT ,
520565 127 , 0 , dac_vol_tlv ),
@@ -568,12 +613,7 @@ static int r1015_dac_event(struct snd_soc_dapm_widget *w,
568613 break ;
569614
570615 case SND_SOC_DAPM_POST_PMU :
571- if (rt1015 -> bypass_boost == RT1015_Bypass_Boost ) {
572- regmap_write (rt1015 -> regmap , RT1015_MAN_I2C , 0x00a8 );
573- regmap_write (rt1015 -> regmap , RT1015_SYS_RST1 , 0x0597 );
574- regmap_write (rt1015 -> regmap , RT1015_SYS_RST1 , 0x05f7 );
575- regmap_write (rt1015 -> regmap , RT1015_MAN_I2C , 0x0028 );
576- }
616+ regmap_write (rt1015 -> regmap , RT1015_MAN_I2C , 0x00a8 );
577617 break ;
578618
579619 case SND_SOC_DAPM_POST_PMD :
@@ -589,6 +629,8 @@ static int r1015_dac_event(struct snd_soc_dapm_widget *w,
589629 RT1015_SYS_RST1 , 0x05f5 );
590630 }
591631 rt1015 -> dac_is_used = 0 ;
632+
633+ cancel_delayed_work_sync (& rt1015 -> flush_work );
592634 break ;
593635
594636 default :
@@ -597,6 +639,24 @@ static int r1015_dac_event(struct snd_soc_dapm_widget *w,
597639 return 0 ;
598640}
599641
642+ static int rt1015_amp_drv_event (struct snd_soc_dapm_widget * w ,
643+ struct snd_kcontrol * kcontrol , int event )
644+ {
645+ struct snd_soc_component * component =
646+ snd_soc_dapm_to_component (w -> dapm );
647+ struct rt1015_priv * rt1015 = snd_soc_component_get_drvdata (component );
648+
649+ switch (event ) {
650+ case SND_SOC_DAPM_POST_PMU :
651+ if (rt1015 -> hw_config == RT1015_HW_28 )
652+ schedule_delayed_work (& rt1015 -> flush_work , msecs_to_jiffies (10 ));
653+ break ;
654+ default :
655+ break ;
656+ }
657+ return 0 ;
658+ }
659+
600660static const struct snd_soc_dapm_widget rt1015_dapm_widgets [] = {
601661 SND_SOC_DAPM_SUPPLY ("LDO2" , RT1015_PWR1 , RT1015_PWR_LDO2_BIT , 0 ,
602662 NULL , 0 ),
@@ -630,6 +690,8 @@ static const struct snd_soc_dapm_widget rt1015_dapm_widgets[] = {
630690 r1015_dac_event , SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
631691 SND_SOC_DAPM_POST_PMD ),
632692
693+ SND_SOC_DAPM_OUT_DRV_E ("Amp Drv" , SND_SOC_NOPM , 0 , 0 , NULL , 0 ,
694+ rt1015_amp_drv_event , SND_SOC_DAPM_POST_PMU ),
633695 SND_SOC_DAPM_OUTPUT ("SPO" ),
634696};
635697
@@ -648,7 +710,8 @@ static const struct snd_soc_dapm_route rt1015_dapm_routes[] = {
648710 { "DAC" , NULL , "MIXERV" },
649711 { "DAC" , NULL , "SUMV" },
650712 { "DAC" , NULL , "VREFLV" },
651- { "SPO" , NULL , "DAC" },
713+ { "Amp Drv" , NULL , "DAC" },
714+ { "SPO" , NULL , "Amp Drv" },
652715};
653716
654717static int rt1015_hw_params (struct snd_pcm_substream * substream ,
@@ -888,15 +951,19 @@ static int rt1015_probe(struct snd_soc_component *component)
888951
889952 rt1015 -> component = component ;
890953 rt1015 -> bclk_ratio = 0 ;
954+ rt1015 -> cali_done = 0 ;
891955 snd_soc_component_write (component , RT1015_BAT_RPO_STEP1 , 0x061c );
892956
957+ INIT_DELAYED_WORK (& rt1015 -> flush_work , rt1015_flush_work );
958+
893959 return 0 ;
894960}
895961
896962static void rt1015_remove (struct snd_soc_component * component )
897963{
898964 struct rt1015_priv * rt1015 = snd_soc_component_get_drvdata (component );
899965
966+ cancel_delayed_work_sync (& rt1015 -> flush_work );
900967 regmap_write (rt1015 -> regmap , RT1015_RESET , 0 );
901968}
902969
@@ -1022,6 +1089,8 @@ static int rt1015_i2c_probe(struct i2c_client *i2c,
10221089 return ret ;
10231090 }
10241091
1092+ rt1015 -> hw_config = (i2c -> addr == 0x29 ) ? RT1015_HW_29 : RT1015_HW_28 ;
1093+
10251094 regmap_read (rt1015 -> regmap , RT1015_DEVICE_ID , & val );
10261095 if ((val != RT1015_DEVICE_ID_VAL ) && (val != RT1015_DEVICE_ID_VAL2 )) {
10271096 dev_err (& i2c -> dev ,
0 commit comments