navienginebsp/ne1_tb/inc/cs42l51.h
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 * ne1_tb\inc\cs42l51.h
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CS42L51_H_
       
    22 #define CS42L51_H_
       
    23 #include <drivers/iic_channel.h>
       
    24 
       
    25 
       
    26 const TUint KMaxAttempts 		 = 2000;  // Number of maximum attempts in operations
       
    27 const TInt8 KCodecWriteCommand 	=  0x94;   // value of the first byte to be sent in each write request on CSI bus.
       
    28 
       
    29 const TInt KCodecResetPin = 25; // GPIO pin 25 works as AUDIO_RESET
       
    30 const TInt KCodecCSPin = 12; // GPIO pin 12 works as CS.
       
    31 
       
    32 const TUint KHwCS42L51ChipID     = 0x01;  // Chip I.D. and Revision Register (Address 01h) (Read Only)
       
    33 const TUint KHwCS42L51PwrCtrl = 0x02;  // Power Control 1
       
    34 const TUint KHtCS42L51PwrCtrl_PDN_ALL  =  0x7f;  // Power Down ALL (bit 7-reserved)
       
    35 const TUint KHtCS42L51PwrCtrl_PDN_DACB  = 1<<6;  // Power Down DACB
       
    36 const TUint KHtCS42L51PwrCtrl_PDN_DACA  = 1<<5;  // Power Down DACA
       
    37 const TUint KHtCS42L51PwrCtrl_PDN_PGAB  = 1<<4;  // Power Down PGAB
       
    38 const TUint KHtCS42L51PwrCtrl_PDN_PGAA  = 1<<3;  // Power Down PGAA
       
    39 const TUint KHtCS42L51PwrCtrl_PDN_ADCB  = 1<<2;  // Power Down ADCB
       
    40 const TUint KHtCS42L51PwrCtrl_PDN_ADCA  = 1<<1;  // Power Down ADCA
       
    41 const TUint KHtCS42L51PwrCtrl_PDN  	   = 1<<0;  // Power Down
       
    42 
       
    43 const TUint KHwCS42L51MicPwrSpeed = 0x03;  // MIC Power Control & Speed Control
       
    44 const TUint KHtCS42L51MicPwrSpeed_AUTO     		= 1<<7;  // Auto-Detect Speed Mode
       
    45 const TUint KHtCS42L51MicPwrSpeed_3ST_SP    	= 1<<4;  // Tri-State Serial Port Interface
       
    46 const TUint KHtCS42L51MicPwrSpeed_PDN_MICB  	= 1<<3;  // Power Down MICB
       
    47 const TUint KHtCS42L51MicPwrSpeed_PDN_MICA  	= 1<<2;  // Power Down MICA
       
    48 const TUint KHtCS42L51MicPwrSpeed_PDN_MICBIAS 	= 1<<1;  // MCLK Divide By 2
       
    49 const TUint KHtCS42L51MicPwrSpeed_MCLKDIV2 	  	= 1<<0;  // MCLK Divide By 2
       
    50 
       
    51 const TUint KHsCS42L51MicPwrSpeed    = 5; // Speed shift (bits[6:5])
       
    52 const TUint KHCS42L51MicPwrSpeed_SpeedQSM = 3; // Quarter-Speed Mode (QSM) - 4 to 12.5 kHz sample rates
       
    53 const TUint KHCS42L51MicPwrSpeed_SpeedHSM = 2; // Half-Speed Mode (HSM) - 12.5 to 25 kHz sample rates
       
    54 const TUint KHCS42L51MicPwrSpeed_SpeedSSM = 1; // Single-Speed Mode (SSM) - 4 to 50 kHz sample rates
       
    55 const TUint KHCS42L51MicPwrSpeed_SpeedDSM = 0; // Double-Speed Mode (DSM) - 50 to 100 kHz sample rates
       
    56 
       
    57 const TUint KHwCS42L51Ctrl = 0x04;  // Interface Control
       
    58 const TUint KHtCS42L51Ctrl_SDOUT_SDIN = 1<<7;  // SDOUT to SDIN Loopback
       
    59 const TUint KHtCS42L51Ctrl_MS     	 = 1<<6;  // Master/Slave Mode
       
    60 const TUint KHtCS42L51Ctrl_ADC_I2S    = 1<<2;  // ADC I2S or Left-Justified
       
    61 const TUint KHtCS42L51Ctrl_DIGMIX     = 1<<1;  // Digital Mix
       
    62 const TUint KHtCS42L51Ctrl_MICMIX     = 1<<0;  // Mic Mix
       
    63 
       
    64 const TUint KHsCS42L51CtrlFormat = 3; // DAC Digital Interface Format shift(DAC_DIF[5:3])
       
    65 const TUint KHCS42L51CtrlLeftJustifiedUpto24bit  = 0;
       
    66 const TUint KHCS42L51CtrlI2sUpto24bit 			 = 1;
       
    67 const TUint KHCS42L51CtrlRightJustifiedUpto24bit = 2;
       
    68 const TUint KHCS42L51CtrlRightJustifiedUpto20bit = 3;
       
    69 const TUint KHCS42L51CtrlRightJustifiedUpto18bit = 4;
       
    70 const TUint KHCS42L51CtrlRightJustifiedUpto16bit = 5;
       
    71 
       
    72 const TUint KHwCS42L51MicCtrl = 0x05;  // MIC Control
       
    73 const TUint KHtCS42L51MicCtrl_ADC_SNGVOL  = 1<<7; // ADC Single Volume Control
       
    74 const TUint KHtCS42L51MicCtrl_ADCB_DBOOST = 1<<6; // ADCB 20 dB Digital Boost
       
    75 const TUint KHtCS42L51MicCtrl_ADCA_DBOOST = 1<<5; // ADCA 20 dB Digital Boost
       
    76 const TUint KHtCS42L51MicCtrl_MICBIAS_SEL = 1<<4; // MIC Bias Select
       
    77 const TUint KHtCS42L51MicCtrl_MICB_BOOST  = 1<<1; // MIC B Preamplifier Boost
       
    78 const TUint KHtCS42L51MicCtrl_MICA_BOOST  = 1<<0; // MIC A Preamplifier Boost
       
    79 const TUint KHsCS42L51MicCtrl_MICBIAS	  = 2; // MIC Bias Level shift (0-3) [3:2]
       
    80 
       
    81 const TUint KHwCS42L51ADCCtrl = 0x06;  // ADC Control
       
    82 const TUint KHtCS42L51ADCCtrl_ADCB_HPFEN  = 1<<7; // ADCB High-Pass Filter Enable
       
    83 const TUint KHtCS42L51ADCCtrl_ADCB_HPFRZ  = 1<<6; // ADCB High-Pass Filter Freeze
       
    84 const TUint KHtCS42L51ADCCtrl_ADCA_HPFEN  = 1<<5; // ADCA High-Pass Filter Enable
       
    85 const TUint KHtCS42L51ADCCtrl_ADCA_HPFRZ  = 1<<4; // ADCA High-Pass Filter Freeze
       
    86 const TUint KHtCS42L51ADCCtrl_SOFTB 	  = 1<<3; // Soft Ramp CHB Control
       
    87 const TUint KHtCS42L51ADCCtrl_ZCROSSB 	  = 1<<2; // Zero Cross CHB Control
       
    88 const TUint KHtCS42L51ADCCtrl_SOFTA 	  = 1<<1; // Soft Ramp CHA Control
       
    89 const TUint KHtCS42L51ADCCtrl_ZCROSSA 	  = 1<<0; // Zero Cross CHA Control
       
    90 
       
    91 const TUint KHwCS42L51ADCInputMute = 0x07;  // ADCx Input Select, Invert & Mute
       
    92 const TUint KHsCS42L51ADCInputMute_AINB_MUX  = 6; // ADCB Input Select Bits [7:6]
       
    93 const TUint KHsCS42L51ADCInputMute_AINA_MUX  = 4; // ADCA Input Select Bits [5:4]
       
    94 /*
       
    95 PDN_PGAx AINx_MUX[1:0] Selected Path to ADC
       
    96 	0 	  00 		AIN1x-->PGAx
       
    97 	0	  01 		AIN2x-->PGAx
       
    98 	0 	  10 		AIN3x/MICINx-->PGAx
       
    99 	0 	  11 		AIN3x/MICINx-->Pre-Amp(+16/+32 dB Gain)-->PGAx
       
   100 	1 	  00 		AIN1x
       
   101 	1 	  01 		AIN2x
       
   102 	1 	  10 		AIN3x/MICINx
       
   103 	1 	  11 		Reserved */
       
   104 const TUint KHwCS42L51ADCInputMute_INV_ADCB   = 1<<3; // ADCB Invert Signal Polarity
       
   105 const TUint KHwCS42L51ADCInputMute_INV_ADCA   = 1<<2; // ADCA Invert Signal Polarity
       
   106 const TUint KHwCS42L51ADCInputMute_ADCB_MUTE  = 1<<1; // ADCB Channel Mute
       
   107 const TUint KHwCS42L51ADCInputMute_ADCA_MUTE  = 1<<0; // ADCA Channel Mute
       
   108 
       
   109 const TUint KHwCS42L51DACOutputControl = 0x08;  // DAC Output Control
       
   110 const TUint KHsCS42L51DACOutputControl_HP_GAIN = 5; // Headphone Analog Gain (HP_GAIN[7:5])
       
   111 const TUint KHtCS42L51DACOutputControl_DAC_SNGVOL = 1<<4; // DAC Single Volume Control
       
   112 const TUint KHtCS42L51DACOutputControl_INV_PCMB   = 1<<3; // PCMB Invert Signal Polarity
       
   113 const TUint KHtCS42L51DACOutputControl_INV_PCMA   = 1<<2; // PCMA Invert Signal Polarity
       
   114 const TUint KHtCS42L51DACOutputControl_DACB_MUTE  = 1<<1; // DACB Channel Mute
       
   115 const TUint KHtCS42L51DACOutputControl_DACA_MUTE  = 1<<0; // DACA Channel Mute
       
   116 const TUint KHtCS42L51DACOutputControl_DACAB_MUTE  = 3<<0; // DACA and DACB Channel Mute
       
   117 
       
   118 
       
   119 const TUint KHwCS42L51DACControl = 0x09;  // DAC Control
       
   120 const TUint KHsCS42L51DACControl_DATA_SEL = 6; // DAC Data Selection (DATA_SEL[7:6])
       
   121 /*00 - PCM Serial Port to DAC
       
   122   01 - Signal Processing Engine to DAC
       
   123   10 - ADC Serial Port to DAC
       
   124   11 - Reserved */
       
   125 const TUint KHtCS42L51DACControl_FREEZE = 1<<5; // Freeze Controls
       
   126 const TUint KHtCS42L51DACControl_DEEMPH = 1<<3; // DAC De-Emphasis Control
       
   127 const TUint KHtCS42L51DACControl_AMUTE = 1<<2; // Analog Output Auto MUTE
       
   128 const TUint KHsCS42L51DACControl_DAC_SZC = 0; // DAC Soft Ramp and Zero Cross Control (DAC_SZC[1:0])
       
   129 
       
   130 const TUint KHwCS42L51ALC_PGA_A_Control = 0x0A;  // ALCA & PGAA Control
       
   131 const TUint KHtCS42L51ALC_PGA_A_Control_ALC_SRDIS = 1<<7; // ALCA Soft Ramp Disable
       
   132 const TUint KHtCS42L51ALC_PGA_A_Control_ALC_ZCDIS = 1<<6; // ALCA Zero Cross Disable
       
   133 const TUint KHsCS42L51ALC_PGA_A_Control_PGA_VOL = 0; // PGA A Gain Control
       
   134 
       
   135 const TUint KHwCS42L51ALC_PGA_B_Control = 0x0B;  // ALCB & PGAB Control
       
   136 const TUint KHtCS42L51ALC_PGA_B_Control_ALC_SRDIS = 1<<7; // ALCB Soft Ramp Disable
       
   137 const TUint KHtCS42L51ALC_PGA_B_Control_ALC_ZCDIS = 1<<6; // ALCB Zero Cross Disable
       
   138 const TUint KHsCS42L51ALC_PGA_B_Control_PGA_VOL = 0; // PGA B Gain Control
       
   139 
       
   140 const TUint KHwCS42L51ALC_ADC_A_Attenuator = 0x0C;  // ADCA Attenuator
       
   141 const TUint KHwCS42L51ALC_ADC_B_Attenuator = 0x0D;  // ADCB Attenuator
       
   142 
       
   143 const TUint KHwCS42L51ALC_ADC_A_MixVolume = 0x0E;  // ADCA Mixer Volume Control
       
   144 const TUint KHwCS42L51ALC_ADC_B_MixVolume = 0x0F;  // ADCB Mixer Volume Control
       
   145 
       
   146 const TUint KHwCS42L51ALC_PCM_A_MixVolume = 0x10;  // PCMA Mixer Volume Control
       
   147 const TUint KHwCS42L51ALC_PCM_B_MixVolume = 0x11;  // PCMB Mixer Volume Control
       
   148 
       
   149 // this applies to ADCx_MixVolume and PCMx_MixVolume registers..
       
   150 const TUint KHtCS42L51ALC_MixVolume_ChannelMute = 1<<7; // Channel Mute
       
   151 const TUint KHmCS42L51ALC_MixVolume_VolumeMask 	= 0x7F;  // Volume Control Mask
       
   152 
       
   153 const TUint KHwCS42L51ALC_Beep_FQ_Time = 0x12;  // Beep Frequency & Timing Configuration
       
   154 const TUint KHsCS42L51ALC_Beep_FQ 	 	 = 4;   // Beep Frequency (FREQ[7:4])
       
   155 const TUint KHmCS42L51ALC_Beep_FQ_Mask 	 = 0xF0; // Beep frequency mask
       
   156 const TUint KHsCS42L51ALC_Beep_Time 	 = 0; // Beep on duration (ONTIME[3:0])
       
   157 const TUint KHmCS42L51ALC_Beep_Time_Mask = 0x0F; // Time on duration mask
       
   158 
       
   159 const TUint KHwCS42L51ALC_Beep_Off_Volume = 0x13;  // Beep Off Time & Volume
       
   160 const TUint KHsCS42L51ALC_Beep_Off		   = 5; // Beep off time mask
       
   161 const TUint KHmCS42L51ALC_Beep_Off_Mask    = 0xE0; // Beep off time mask
       
   162 const TUint KHmCS42L51ALC_Beep_Volume_Mask = 0x1F; // Beep volume mask
       
   163 
       
   164 const TUint KHwCS42L51ALC_Beep_Conf_Tone = 0x14;  // Beep Configuration & Tone Configuration
       
   165 const TUint KHtCS42L51ALC_Beep_Conf_Tone_REPEAT  = 1<<7; // Repeat Beep
       
   166 const TUint KHtCS42L51ALC_Beep_Conf_Tone_BEEP 	 = 1<<6; // Beep
       
   167 const TUint KHtCS42L51ALC_Beep_Conf_Tone_TC_EN 	 = 1<<0; // Tone Control Enable
       
   168 const TUint KHsCS42L51ALC_Beep_Conf_Tone_TREB_CF = 3; // Treble Corner Frequency (TREB_CF[4:3])
       
   169 const TUint KHsCS42L51ALC_Beep_Conf_Tone_BASS_CF = 1; // Bass Corner Frequency (BASS_CF[2:1])
       
   170 
       
   171 const TUint KHwCS42L51ALC_ToneCtrl = 0x15; // Tone Control
       
   172 const TUint KHsCS42L51ALC_ToneCtrl_TREB 	 = 4; 	 // Treble Gain Level (TREB[7:4])
       
   173 const TUint KHmCS42L51ALC_ToneCtrl_TREB_Mask = 0xF0; // Treble Gain Level mask
       
   174 const TUint KHsCS42L51ALC_ToneCtrl_BASS 	 = 0; 	 // Bass Gain Level (TREB[7:4])
       
   175 const TUint KHmCS42L51ALC_ToneCtrl_BASS_Mask = 0x0F; // Bass Gain Level mask
       
   176 
       
   177 const TUint KHwCS42L51ALC_Out_A_Volume = 0x16;  // AOUTA Volume Control
       
   178 const TUint KHwCS42L51ALC_Out_B_Volume = 0x17;  // AOUTB Volume Control
       
   179 const TUint KHbCS42L51ALC_Volume_Min = 25;  	// Value for ALC_Out_x for Minimum Volume
       
   180 
       
   181 
       
   182 const TUint KHwCS42L51ALC_PCM_Mix 	 	    = 0x18;  // PCM Channel Mixer
       
   183 const TUint KHwCS42L51ALC_Limiter_SZCD 	    = 0x19;  // Limiter Threshold SZC Disable
       
   184 const TUint KHwCS42L51ALC_Limiter_Release   = 0x1A;  // Limiter Release Rate Register
       
   185 const TUint KHwCS42L51ALC_Limiter_Attack    = 0x1B;  // Limiter Attack Rate Register
       
   186 const TUint KHwCS42L51ALC_ALCE_Attack_Rate  = 0x1C;  // ALC Enable & Attack Rate
       
   187 const TUint KHwCS42L51ALC_ALC_Release_Rate  = 0x1D;  // ALC Release Rate
       
   188 const TUint KHwCS42L51ALC_ALC_Threshold  	= 0x1E;  // ALC Threshold
       
   189 const TUint KHwCS42L51ALC_NoiseGate_Misc  	= 0x1F;  // Noise Gate Configuration & Misc
       
   190 const TUint KHwCS42L51ALC_Status  			= 0x20;  // Noise Gate Configuration & Misc
       
   191 const TUint KHwCS42L51ALC_Charge_Pump_Fq 	= 0x21;  // Charge Pump Frequency
       
   192 
       
   193 /**
       
   194 Definiton of audio codec singleton class...
       
   195 */
       
   196 class RCS42AudioCodec
       
   197 	{
       
   198 public:
       
   199 
       
   200 	struct TCodecConfigData
       
   201 		{
       
   202 		TInt8 iAddress;
       
   203 		TInt8 iRegister;
       
   204 		TInt8 iData;
       
   205 		};
       
   206 public:
       
   207 	static TInt Open(RCS42AudioCodec* &aSelf); // open the reference codec
       
   208 	static void Close(RCS42AudioCodec* &aSelf); // close the reference to the codec
       
   209 	TInt SetPlayVolume(TInt aVolume); // set the Playback volume
       
   210 	TInt SetRecordVolume(TInt aVolume); // set the Record volume
       
   211 
       
   212 private:
       
   213 	RCS42AudioCodec();
       
   214 	static TInt Create(); // create an instance of the codec
       
   215 	static void Destroy(); // delete an instance of the codec
       
   216 	TInt DoWrite(TUint16 aRegAddr, TUint16 aData);
       
   217 	void StartWrite();
       
   218 	TInt StopWrite();
       
   219 	void Write(TUint16 aRegAddr, TUint16 aData); // access codec's registers
       
   220 	TInt Init();
       
   221 	void PowerDown();
       
   222 	static RCS42AudioCodec* iSelf;
       
   223 	static TInt iRefCnt;
       
   224 	TInt iTransferStatus;
       
   225 	TUint8 iInterfaceCtrlVal;
       
   226 	TInt iResult;
       
   227 
       
   228 #ifdef _DEBUG
       
   229 	TBool iStartWriteCalled;
       
   230 #endif
       
   231 	TConfigSpiBufV01 iHeaderBuff;
       
   232 	TPckgBuf <TCodecConfigData> iTransBuff;
       
   233 	TUint32 iCsiBusConfig;
       
   234 	};
       
   235 
       
   236 
       
   237 #endif /*CS42L51_H_*/