@@ -484,6 +484,33 @@ static int rt1015_bypass_boost_get(struct snd_kcontrol *kcontrol,
484
484
return 0 ;
485
485
}
486
486
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
+
487
514
static int rt1015_bypass_boost_put (struct snd_kcontrol * kcontrol ,
488
515
struct snd_ctl_elem_value * ucontrol )
489
516
{
@@ -494,27 +521,45 @@ static int rt1015_bypass_boost_put(struct snd_kcontrol *kcontrol,
494
521
495
522
if (!rt1015 -> dac_is_used ) {
496
523
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 );
511
530
}
512
531
} else
513
532
dev_err (component -> dev , "DAC is being used!\n" );
514
533
515
534
return 0 ;
516
535
}
517
536
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
+
518
563
static const struct snd_kcontrol_new rt1015_snd_controls [] = {
519
564
SOC_SINGLE_TLV ("DAC Playback Volume" , RT1015_DAC1 , RT1015_DAC_VOL_SFT ,
520
565
127 , 0 , dac_vol_tlv ),
@@ -568,12 +613,7 @@ static int r1015_dac_event(struct snd_soc_dapm_widget *w,
568
613
break ;
569
614
570
615
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 );
577
617
break ;
578
618
579
619
case SND_SOC_DAPM_POST_PMD :
@@ -589,6 +629,8 @@ static int r1015_dac_event(struct snd_soc_dapm_widget *w,
589
629
RT1015_SYS_RST1 , 0x05f5 );
590
630
}
591
631
rt1015 -> dac_is_used = 0 ;
632
+
633
+ cancel_delayed_work_sync (& rt1015 -> flush_work );
592
634
break ;
593
635
594
636
default :
@@ -597,6 +639,24 @@ static int r1015_dac_event(struct snd_soc_dapm_widget *w,
597
639
return 0 ;
598
640
}
599
641
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
+
600
660
static const struct snd_soc_dapm_widget rt1015_dapm_widgets [] = {
601
661
SND_SOC_DAPM_SUPPLY ("LDO2" , RT1015_PWR1 , RT1015_PWR_LDO2_BIT , 0 ,
602
662
NULL , 0 ),
@@ -630,6 +690,8 @@ static const struct snd_soc_dapm_widget rt1015_dapm_widgets[] = {
630
690
r1015_dac_event , SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
631
691
SND_SOC_DAPM_POST_PMD ),
632
692
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 ),
633
695
SND_SOC_DAPM_OUTPUT ("SPO" ),
634
696
};
635
697
@@ -648,7 +710,8 @@ static const struct snd_soc_dapm_route rt1015_dapm_routes[] = {
648
710
{ "DAC" , NULL , "MIXERV" },
649
711
{ "DAC" , NULL , "SUMV" },
650
712
{ "DAC" , NULL , "VREFLV" },
651
- { "SPO" , NULL , "DAC" },
713
+ { "Amp Drv" , NULL , "DAC" },
714
+ { "SPO" , NULL , "Amp Drv" },
652
715
};
653
716
654
717
static int rt1015_hw_params (struct snd_pcm_substream * substream ,
@@ -888,15 +951,19 @@ static int rt1015_probe(struct snd_soc_component *component)
888
951
889
952
rt1015 -> component = component ;
890
953
rt1015 -> bclk_ratio = 0 ;
954
+ rt1015 -> cali_done = 0 ;
891
955
snd_soc_component_write (component , RT1015_BAT_RPO_STEP1 , 0x061c );
892
956
957
+ INIT_DELAYED_WORK (& rt1015 -> flush_work , rt1015_flush_work );
958
+
893
959
return 0 ;
894
960
}
895
961
896
962
static void rt1015_remove (struct snd_soc_component * component )
897
963
{
898
964
struct rt1015_priv * rt1015 = snd_soc_component_get_drvdata (component );
899
965
966
+ cancel_delayed_work_sync (& rt1015 -> flush_work );
900
967
regmap_write (rt1015 -> regmap , RT1015_RESET , 0 );
901
968
}
902
969
@@ -1022,6 +1089,8 @@ static int rt1015_i2c_probe(struct i2c_client *i2c,
1022
1089
return ret ;
1023
1090
}
1024
1091
1092
+ rt1015 -> hw_config = (i2c -> addr == 0x29 ) ? RT1015_HW_29 : RT1015_HW_28 ;
1093
+
1025
1094
regmap_read (rt1015 -> regmap , RT1015_DEVICE_ID , & val );
1026
1095
if ((val != RT1015_DEVICE_ID_VAL ) && (val != RT1015_DEVICE_ID_VAL2 )) {
1027
1096
dev_err (& i2c -> dev ,
0 commit comments