hw_codec.c 18.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
#if 1
/*
 * hw_codec.c
 *
 *  Created on: 2019-6-4
 *      Author: Windowns
 *  Updated date: July 28 2020 by Leelin
 */
#include "os_config.h"


#include "c_def.h"
#include "debug.h"
#include "oem.h"

#include "regmap.h"

#include "hw_codec.h"
#include "hw_uart.h"
#include "hw_dma.h"
#include "hw_da_pp.h"
#include "hw_pll.h"
#include "hw_da_pp.h"

#include "app_i2c.h"

#define ADC_MASTER
#define SINGLE_ENDED_OUTPUT



//#define ADC_LOOPBACK
//#define DAI_LOOPBACK
//#define SIDETONE         /*BYPASS*/
//#define CLOSE_ADC_OUTPUT
//#define CLOSE_DAC_OUTPUT //close headphone dac output
//#define MIC_IN_INPUT
#define MIC_BIAS_LEVEL
//#define MIC_BYPASS_DAC_PATH
#define ADC_RX_ENABLE

/***********there are 4 parameters for adjust Mic_boost input gain************/
/***********00b =0dB;01b=6dB;10b=12dB; 11b=20dB***********************/


#define MIC_BOOST_GAIN	0x00        //00b:0dB; 01b:6dB; 10b:12dB; 11b:20dB.

//ADC: fixed step=0.75dB; Min: -12dB, Max: 35.25dB
//#define ADC_PCA_GAIN	0x10		//0db
#define ADC_PCA_GAIN	0x00		//-12db

/************************************************************************/
void hw_codec_adc_channel_with_gain(U8 channel,U8 mic_boost, U8 gain_dB, U8 diff)
{
	U8 temp, val;
/*************IF ALC function is selected the following ADC PAG_gain setting will be invalid .***/
/*************ADC POWER UP for Corresponding channel *****************/

    temp = 0x06;
    REG_CODEC_R57 = temp;  //ADC mute enable
    delayms(100);

    #if 1
        if(channel == enAUX_CHANNEL)
        {
            temp = 0x9D;   // noise 0x2 Good for LINR IN  1011 1101 0xBD; or 1001 1101 (bit5 = 0 extra delay).
            //temp = 0xBD;   ////LINR IN  1011 1101  (bit5 = 1 quick inverter).temp = 0xBD;
        }

        else if(channel == enMIC_P_CHANL)
        {
            temp = 0x9F;     // noise 0x3-4 MIC IN  without Mic_bias power up at 6bit and no delay
          //temp = 0x9F;   // have extra delay
          
        }

        else if(channel == enMIC_P_CH_WITH_BIAS)
        {
          //mp = 0xDF;   // have extra delay
          temp = 0xFF;   // Mic_bias Power up with no delay
          
        }
        else 
        {
          temp = 0x00;   //audio_codec_ADC power down.
          REG_CODEC_R4B = temp;
          delayms(5);

          #if (defined AUDIO_PWM_OUTPUT)
              temp = 0x00;   
              REG_CODEC_R12 = temp;  // dac playback is not used
              delayms(5);
          #endif

          return;
        }
    #endif

        REG_CODEC_R4B = temp; //ADC power on
        delayms(10);


/******************channels select**************************/

            //i = 38
    if((channel == enMIC_P_CHANL) || (channel == enMIC_P_CH_WITH_BIAS))
    {
        if(diff == enDIFFERENTIAL)
        {
            temp = 0x1E;         // MIC differential input 0x1E  very good
        } 
        else
        {   
            //#ifdef OTK5286_B_D
            temp = 0x1E;          //otk528x  
        	//#endif
        }
    }       
    else 
    {   
        #if( defined  OTK5286_B_D || defined HAVE_VREF_PIN)
        {
            temp = 0x22;	
        }
        #else
        {

            //temp = 0x18;
            //temp = 0x1A;

            temp = 0x12;   //differential for otk5285 for no VREF pin
        }
        #endif
    }
	
    REG_CODEC_R4C = temp;   // channel and single -ended select
    delayms(10);

/***********bandgad Reference voltage Fine Tune ************/
    #if (defined  OTK5286_B_D)
       temp = 0xDB;                 //noise 0x2

    #elif (defined OTK5285) 
       if(channel == enAUX_CHANNEL)
       {
           //temp = 0x3F;        // noise 0x5-6
           temp = 0x5B;          // 0x5-6
           
       }
       else
       {
           temp = 0x3B;          // noise 0x6
       }     
    #else
           temp = 0x1B;         // noise 0x6 with R4C = 0x1E;

    #endif

       REG_CODEC_R12 = temp;  // 0xdf,bf,9f,7f,3f,1f only one can select

       delayms(10);
        
 /*******************************************************************/       
 /************************power gain with boost of Mic **************/       
    U8   mic_boost_gain = 0;
    char adc_pga_gain = 0;

    if (channel == enMIC_P_CHANL || enMIC_P_CH_WITH_BIAS)
    {
        switch(mic_boost)
       {
            case enMIC_BOOST_0dB:
                 mic_boost_gain =0;
                 break;
            case enMIC_BOOST_6dB:
                 mic_boost_gain =1;
                 break;
            case enMIC_BOOST12dB:
                 mic_boost_gain =2;
                 break;
            case enMIC_BOOST20dB:
                 mic_boost_gain =3;
                 break;
            default:
                mic_boost_gain  =0;
                 break;       
        }
     }
     else
     {
           mic_boost_gain =0;
     }

    adc_pga_gain = HW_CODEC_ADC_PGA_UNIT_dB (gain_dB);
 	if (adc_pga_gain < 0)
 	{
		adc_pga_gain = 0x0;
	}
	else if(adc_pga_gain > 0x3F)
	{
		adc_pga_gain = 0x3E;
	}
    else
    {   
        adc_pga_gain = (adc_pga_gain & 0x3E);   // it is only for getting a value of even.
    }
	
    //i = 42 Left channel
	temp = adc_pga_gain | (mic_boost_gain << 6);
	REG_CODEC_R51 = temp;
	
   

    delayms(50);
	//i = 43 Right channel
	temp = adc_pga_gain | (mic_boost_gain << 6);
	REG_CODEC_R52 = temp;
	delayus(50);
  
    temp = 0x00;
    REG_CODEC_R57 = temp;  //ADC mute disable
    delayms(100);
    
}

void hw_codec_adc_ALC_Peak_Limiter(U8 alc_sel,U8 alc_mod,U8 maxgain,U8 mingain,U8 noise_threshold,U8 alc_lvl)
{
    U8 temp, val;
	
	if( alc_sel == enALC_SEL_INVALID)
    {   
    	temp = 0x00;
    	REG_CODEC_R54 = temp;   //ALC_SEL_Disable.
    	
       
    	delayms(50);
        return;
    }
    else
    {   
        #if 1
        if(alc_mod == enALC_NORMAL_MOD)
        {
            temp = 0x80 | ( maxgain<<3 | mingain );
        	REG_CODEC_R54 = temp;   //ALC_SEL_is active with alc_mode, gain max,gain min.

        
        	delayms(50);

            temp = HW_CODEC_ADC_ALC_LEVEL_dBFS(alc_lvl);
            temp = ((temp << 4 | noise_threshold <<1) & 0xFF);
        	REG_CODEC_R55 = temp;   //ALC_SEL_is active with alc_mode, gain max,gain min.
        	
          
        	delayms(50);
        }
        else //limiter mode
        {

            temp = 0xC0 | ( maxgain<<3 | mingain );
        	REG_CODEC_R54 = temp;   //ALC_SEL_is active with alc_mode, gain max,gain min.
        	
        	delayms(50);

            temp = HW_CODEC_ADC_ALC_LEVEL_dBFS(alc_lvl);
            temp = ((temp << 4 | noise_threshold <<1) & 0xFF);
        	REG_CODEC_R55 = temp;   //ALC_SEL_is active with alc_mode, gain max,gain min.
        	
        	delayms(50);
       }
       #endif

            temp =  0x44;    
            REG_CODEC_R56 = temp;  //attack timing step.
            delayms(5);

            temp =  0xc4;    
            REG_CODEC_R58 = temp;  //attenuation noise by 33dB.
            delayms(5);

            temp =  0x44;    
            REG_CODEC_R5A = temp;  //Right channel
            delayms(5);
            temp =  0x07;          // 
            REG_CODEC_R5B = temp;  //Right channel
            delayms(5);
    }

}
void hw_codec_dac_output_with_gain(U8 enable,U8 gain_dB, U8 sidetone )
{
    

    U8 temp, val;
    //i = 1
	temp = 0x87;
	REG_CODEC_R09 = temp;   //DAC soft mute enable
	delayms(100);

    if( enable == enDAC_POWER_OFF)
    {
       
       #if 0  //adc is not working. dissipation 4-6mA at 4.0V input
       temp = 0x00;
       REG_CODEC_R12 = temp;  //bandgap power down
       delayms(5);
       
       temp = 0x40;           // 0x40 RAM power saving mode.
	   REG_CODEC_R40 = temp;
       delayus(10);
       
       #endif

       temp = 0x00; 
       REG_CODEC_R0F = temp;  //DAC,headphone power down
       delayus(10);
      
       
       return;
    }

    else
    {
        #if 0
        //i = 2   noted: removed to ADC
        temp = 0xDB;	
        REG_CODEC_R12 = temp;
    	delayus(5);
        #endif
     

        #if 1
        temp = 0xD4;
    	REG_CODEC_R11 = temp;   
        delayus(10);
    	//i = 3
    	//temp = 0x02;
        temp = 0x4e;
		//temp = 0xce;
    	REG_CODEC_R10 = temp;  //output bias current reduce at 6bit.
    	delayus(5);
        
    	//i = 5
    	temp = 0x2C;
    	REG_CODEC_R15 = temp;  //basic setup for DAC internal Regulator
    	delayus(50);

        //i = 6
    	temp = 0xD4;
    	REG_CODEC_R11 = temp;   //
    	
        delayms(1);

    	//i = 7
        temp = 0xB6;			  //anti-pop function
    	REG_CODEC_R13 = temp;
    
        delayms(1);

    	//i = 8
    	temp = 0x48;
    	REG_CODEC_R0F = temp;    // DAC_POWER_ON
    	delayus(10);

        //i = 9
    	temp = 0x7C;
    	REG_CODEC_R0F = temp;    // DAC_POWER_ON
    	delayus(50);
        
        //i = 10
    	temp = 0x7D;           //7E. Disable sidetone analog pass to DAC at 7bit.
    	REG_CODEC_R0F = temp;  // DAC_POWER_ON
    	
       
    	temp = 0x02;     //11.45mA

    	//i = 11
    	//temp = 0x06;
        //temp = 0x4e;
    	REG_CODEC_R10 = temp;  //output bias current reduce at 6bit. repeating i = 3.
    	delayus(5);

        //i = 12
    	temp = 0x0E;
    	REG_CODEC_R02 = temp;  // i2s format
    	delayus(5);
      

    	//i = 13
    	temp = 0x04;
    	REG_CODEC_R03 = temp;  //mclk1 divide.
    	delayus(5);
       
    	//i = 14
    	temp = 0x00;
    	REG_CODEC_R04 = temp;  //zero crossing setup
    	delayus(5);
       


    	//j = 15
    	//temp = 0x9F;  // 0xd4
    	temp = 0xD4;
        
    	REG_CODEC_R11 = temp;  //adjust internal  analog current
    	delayus(5);
       
    	//i = 16
    	temp = 0x00;
    	REG_CODEC_R05 = temp;  //oversampling ratio.
    	delayus(5);
       

    	//i = 17
    	temp = 0xB1;
    	REG_CODEC_R06 = temp;       //256FS
    	delayus(5);
       

           //i = 18
        #ifdef ADC_LOOPBACK         //PCM digital loopback adc to dac
    	temp = 0x02;	
        #else
    	temp = 0x00;
        #endif
    	REG_CODEC_R0B = temp;      //PCM digital loopback to dac
    	delayus(5);
      

    	//i = 19
        #ifdef DAI_LOOPBACK        //slave mode
    	temp = 0x88;
        #else
    	temp = 0x08;
        #endif
    	REG_CODEC_R0C = temp;  
    	delayus(5);
       

    	//i = 20
    	temp = 0x40;
    	REG_CODEC_R0D = temp;
    	delayus(5);
       

    	//i = 21
    	temp = 0x00;
    	REG_CODEC_R0E = temp;
    	delayus(5);
      
    	//i = 22

        
    	//i = 25
    	temp = 0xED;
    	REG_CODEC_R36 = temp;
    	delayus(5);
        

    	//i = 26
    	temp = 0x86;
    	REG_CODEC_R09 = temp;    //soft dac mute disable
    
       
        #endif

        temp = HW_CODEC_DAC_PGA_UNIT_dB(gain_dB);

        REG_CODEC_R17 = temp;
        delayus(5);
        REG_CODEC_R18 = temp;
        delayus(5);
       
        
       
    }

    if(sidetone == 1)   // DAC_power_on with sidetone bypass to DAC at 7bit
	{ 
       temp = 0x80;
       REG_CODEC_R0F = REG_CODEC_R0F | temp;
	   delayus(5);
       
       temp = 0x01;
       REG_CODEC_R4F = REG_CODEC_R4F | temp;  // bit0 enable sidetone bypass to DAC mixter output path.
	   delayus(5);
      
       
    }
    delayms(10);


    temp = 0x86;
	REG_CODEC_R09 = temp;   //ADC mute disable.
	delayms(100);


}
void hw_codec_adc_init(void)
{
	U8 temp, val;
	
    //i = 4
	temp = 0x22;          //R14 output mixer gain attenuation -3.3db
	REG_CODEC_R14 = temp;
	delayus(5);

    //i = 27
	temp = 0x04;
	REG_CODEC_R40 = temp;   //soft reset enable to adc analog core at bit2 
	
    delayms(10);
   

	//i = 28
	temp = 0x00;  
	REG_CODEC_R40 = temp;
	delayms(10);
   

	//i = 29
	temp = 0x0E;
	REG_CODEC_R41 = temp;
	delayus(5);
   

	//i = 20
	//temp = 0x2A;             // 14.94HZ
	//temp = 0x18;             // HPF_cut_off at 120.3Hz
	//temp = 0x1E;             // 59.92
    temp = 0x22;               // HPF 29.9Hz
	REG_CODEC_R42 = temp;  
	delayus(5);
   
	//i = 31
	temp = 0x04;
	REG_CODEC_R43 = temp;
	delayus(5);
   
    //i = 32
	temp = 0x90;
	REG_CODEC_R44 = temp;
	delayus(5);
   
    //j = 33
	temp = 0x10;
	REG_CODEC_R44 = temp;  //SINC_Rate=16,value=0x10;
	delayus(5);
    
    //i = 34
	temp = 0x00;
	REG_CODEC_R45 = temp;
	delayus(5);
    
    //i = 35
	temp = 0x40;
	REG_CODEC_R48 = temp;
	delayus(5);
    
	//i = 36
	temp = 0x00;
	REG_CODEC_R49 = temp;
	delayus(5);
   
	//i = 37
   
    //i = 38

	//i = 39
	//temp = 0x3C;  
	temp = 0x17;    // 0x17 reduce internal consumption.
	REG_CODEC_R4D = temp;
	delayus(5);
   

	//i = 40
    #ifdef MIC_BIAS_LEVEL
    #ifdef MIC_BYPASS_DAC_PATH
    //temp = 0x71;  //Mic_Bias 2.35V(1.608V) with x1 extra driving Strength.
    //temp = 0x31;	//MIC_BIAS 2.35V
    //temp = 0x29;  //MIC_BIAS 1.96(real is 1.337V)
    //temp = 0x19;	//MIC_BIAS 1.81(real is 1.233V)
    temp = 0x09;    //1.57V(real is 1.0V) with reduce bias cousumption(0x08)

    #elif (defined LOW_CONSUMPTION_MODE)
    temp = 0x0C;

    #else
    temp = 0x70;  //Mic_Bias 2.35V(1.608V) with x1 extra driving Strength.
    //temp = 0x30;	//MIC_BIAS 2.35V
    //temp = 0x28;  //MIC_BIAS 1.96(real is 1.337V)
    //temp = 0x18;	//MIC_BIAS 1.81(real is 1.233V)
    //temp = 0x08;  //1.57V(real is 1.0V) with reduce bias cousumption(0x08)
    #endif

    REG_CODEC_R4E = temp;
	delayus(5);   
    #endif
   
    //i = 41
	temp = 0x34;
	REG_CODEC_R4F = temp;
	delayus(5);
   

	//i = 42
	temp = ADC_PCA_GAIN | (MIC_BOOST_GAIN << 6);
	REG_CODEC_R51 = temp;
	delayus(5);
    

	//i = 43
	temp = ADC_PCA_GAIN | (MIC_BOOST_GAIN << 6);
	REG_CODEC_R52 = temp;
	delayus(5);
    

    #if 0   //R54,R55 is only for ALC, but flowing sett value is wrong.
	//i = 44
	temp = 0x38;
	REG_CODEC_R54 = temp;
	delayus(5);
   
    //i = 45
	temp = 0x74;
	REG_CODEC_R55 = temp;
	delayus(5);
   
    #endif

    //i = 46
	temp = 0x09; //master
	REG_CODEC_R47 = temp;
	delayus(5);
   
	//i = 47
	temp = 0x00;
	REG_CODEC_R1E = temp;
	delayus(5);
   

    //i = 48
	temp = 0x03;
	REG_CODEC_R40 = temp;
	delayus(5);
    
} 


#if (defined LOW_CONSUMPTION_MODE)
void audio_codec_standby(U8 enable)
{
   if(enable == 1)
   {
       U8 temp;
       temp = 0x87;
       REG_CODEC_R09 = temp;    // ADC soft mute
       delayms(150);

       #if 1  //adc is not working. dissipation will reduce to 4-6mA at 4.0V input
       temp = 0x00;
       REG_CODEC_R12 = temp;  //bandgap power down,it will affect adc and cause it no input
       delayus(5);
       
       temp = 0x40;           // 0x40 RAM power saving mode.
       REG_CODEC_R40 = temp;
       delayus(10);
       #endif

       temp = 0x00; 
       REG_CODEC_R0F = temp;     //ADC,headphone power down
       delayms(50);
   }
   else
   {

        app_dac_adc_fifo_init();  // solved POP noise when switching

        HW_CODEC_ADC_INIT;
        HW_CODEC_ADC_CHANNEL_WITH_GAIN(enMIC_P_CHANL,enMIC_BOOST_6dB,0,enDIFFERENTIAL);

        #if (defined AUDIO_PWM_OUTPUT)
        HW_CODEC_DAC_OUTPUT_WITH_GAIN(enDAC_POWER_OFF, 0, 0);
        #endif
   }
}

#endif

void hw_codec_dac_anti_pop_power_down(void)
{
	U8 temp, val;

	//i = 1
	temp = 0x3F;
	REG_CODEC_R0F = temp;
	delayus(5);
 
	
	//i = 2
	temp = 0x87;
	REG_CODEC_R09 = temp;
	delayus(5);
    
	
	//i = 3
	temp = 0x7D;
	REG_CODEC_R0F = temp;
	delayus(5);
    
	
	//i = 4
	temp = 0x48;
	REG_CODEC_R0F = temp;
	delayus(5);
    
	
	delayms(1000);
	//i = 5
	temp = 0x40;
	REG_CODEC_R0F = temp;
	delayus(5);
   

	//i = 6
	temp = 0x01;
	REG_CODEC_R13 = temp;
	delayus(5);
   
	//i = 7
	temp = 0x00;
	REG_CODEC_R12 = temp;
	delayus(5);
   
}

	
void audio_code_init(void)
{
	U32 i;
	U8 val;
	U8 flag;
	volatile U32 tmp,tmp1,tmp2,tmp3,temp;
	MISC_PLL_CONTROLs *pll_config;

#if 1//def SPDIF_TX_ENABLE
	//channel_status = 43'b01_1111_101_1_00_11_0000_0001_0001_00000000_00_000_1_0_0;
	//non pcm
	//channel_status = 43'b01_1111_101_1_00_11_0000_0000_0001_00000000_00_000_1_1_0;
	SPDIF_CONFIG_AHB *p_spdif_config;

	temp = SPDIF_CONFIG;
   
    p_spdif_config = (SPDIF_CONFIG_AHB *) &temp;

    p_spdif_config->spdif_enc_enable = 1;
    p_spdif_config->spdif_dec_enable = 1;

	//p_spdif_config->adc_slave = 1;
    
    p_spdif_config->spdif_dec_aux_mask = 1;
    p_spdif_config->spdif_dec_sr_detect_start = 1;
    #ifdef AUDIO_24_BIT_OUTPUT	
    p_spdif_config->spdif_enc_data_24b = 1;
    #else
	p_spdif_config->spdif_enc_data_24b = 0;
    #endif
    
    p_spdif_config->spdif_data_sel = 0;

/*	
    if (MI2S_CHANs == 3) 
        p_spdif_config->spdif_enc_stream = 2;
    else    
        p_spdif_config->spdif_enc_stream = 0;
*/

    p_spdif_config->spdif_enc_stream = 0;

    p_spdif_config->spdif_enc_sample_delay = 6;
    
    p_spdif_config->dac_enable = 1;
    

#ifdef ADC_RX_ENABLE

    #ifdef ADC_MASTER
	p_spdif_config->adc_slave =   1;
    #else
	p_spdif_config->adc_slave =   0;
    #endif
    p_spdif_config->adc_enable =  1; 
#endif

    p_spdif_config->adc_bck_div = 1;

#ifdef AUDIO_ADC_24BIT
    p_spdif_config->adc_i2s_24bit = 1; //1:24-BIT INPUT; 0:16-BIT INPUT
#else
    p_spdif_config->adc_i2s_24bit = 0; //1:24-BIT INPUT; 0:16-BIT INPUT
#endif

    p_spdif_config->adc_lrck_swap = 1;

    SPDIF_CONFIG = temp;


#if 1//ndef AUDIO_PWM_OUTPUT	
	DA_PP_CLASSD_EN |= 0x02; //spdif_en enable
#endif


    //codec setting
#define CODEC_TEST

#ifdef CODEC_TEST
    //U32 val;
	MISC_AUDIO_CODEC_CONTROLs *AudCodec_config;
    U32 test_err = 0;
    
	tmp = REG_MISC_AUDIO_CODEC;
	AudCodec_config = (MISC_AUDIO_CODEC_CONTROLs *)&tmp;
	
	AudCodec_config->codec_Resetn  = 1;
	AudCodec_config->codec_I2C_mode = 0;
	AudCodec_config->codec_MODE = 0;
	AudCodec_config->codec_CSB  = 1;
	AudCodec_config->codec_EXT_CLK_div  = 0;
	REG_MISC_AUDIO_CODEC = tmp;

	delayus(5);    

    hw_codec_adc_init();
    #if 1 //(defined OTK5283P || defined OTK5282P || defined OTK5282)
       // hw_codec_adc_channel_with_gain(enMIC_P_CHANL,enMIC_BOOST_6dB,0,enDIFFERENTIAL);
        hw_codec_adc_channel_with_gain(enAUX_CHANNEL,enMIC_BOOST_6dB,0,enDIFFERENTIAL);
        #if (defined LOW_CONSUMPTION_MODE)
        app_pmu_voltage_ctl(enDC_BUCK_1V6, enLDO_CORE1V0, enCODEC_LDO_2V5);
        #endif
    #else
        hw_codec_adc_channel_with_gain(enAUX_CHANNEL,enMIC_BOOST_0dB,0,enSINGLE_ENDED);
    #endif
    //hw_codec_adc_channel_with_gain(enAUX_CHANNEL,enMIC_BOOST_0dB,0,enDIFFERENTIAL);

    //hw_codec_adc_ALC_Peak_Limiter(enALC_SEL_ACTIVE,enALC_NORMAL_MOD,enALC_MAX_18dB,enALC_MIN_12dB,enNOISE_THD_M66FS,-1.5);
    //hw_codec_adc_ALC_Peak_Limiter(enALC_SEL_ACTIVE,enALC_NORMAL_MOD,enALC_MAX_0dB,enALC_MIN_6dB,enNOISE_THD_M66FS,-4.5);

    #if (defined AUDIO_PWM_OUTPUT)
    
    hw_codec_dac_output_with_gain(enDAC_POWER_ON,0,0);
    hw_codec_dac_output_with_gain(enDAC_POWER_OFF,0,0);   // dissipation 12mA at 4.0V and mic input, reducing 5ma than dac on

    #else
    hw_codec_dac_output_with_gain(enDAC_POWER_ON,0,0);
    #endif

#endif //CODEC_TEST    

#endif //SPDIF_TX_ENABLE
}

void adc_rev_fifo_reset(void)
{
    U32 temp;
	SPDIF_CONFIG_AHB *p_spdif_config;

	temp = SPDIF_CONFIG;

    p_spdif_config->adc_enable =  0; 
    SPDIF_CONFIG = temp;
    delayus(100);
    p_spdif_config->adc_enable =  1; 
    SPDIF_CONFIG = temp;         
}

#endif