//I2C values #define P17_I2CA_ADC_ADD_MASK 0x000000fe //The address is a 7 bit address #define P17_I2CA_ADC_RW_MASK 0x00000001 //bit mask for R/W #define P17_I2CA_ADC_TRANS_MASK 0x00000010 //Bit mask for I2c address DAC value #define P17_I2CA_ADC_ABORT_MASK 0x00000020 //Bit mask for I2C transaction abort flag #define P17_I2CA_ADC_LAST_MASK 0x00000040 //Bit mask for Last word transaction #define P17_I2CA_ADC_BYTE_MASK 0x00000080 //Bit mask for Byte Mode #define P17_I2CA_ADC_ADD 0x00000034 //This is the Device address for ADC #define P17_I2CA_ADC_READ 0x00000001 //To perform a read operation #define P17_I2CA_ADC_START 0x00000100 //Start I2C transaction #define P17_I2CA_ADC_ABORT 0x00000200 //I2C transaction abort #define P17_I2CA_ADC_LAST 0x00000400 //I2C last transaction #define P17_I2CA_ADC_BYTE 0x00000800 //I2C one byte mode #define P17_I2CD_ADC_REG_MASK 0xfe000000 //ADC address register #define P17_I2CD_ADC_DAT_MASK 0x01ff0000 //ADC data register #define P17_ADC_TIMEOUT 0x0000000e //ADC Timeout Clock Disable #define P17_ADC_IFC_CTRL 0x00000016 //ADC Interface Control #define P17_ADC_MASTER 0x00000018 //ADC Master Mode Control #define P17_ADC_POWER 0x0000001a //ADC PowerDown Control #define P17_ADC_ATTEN_ADCL 0x0000001c //ADC Attenuation ADCL #define P17_ADC_ATTEN_ADCR 0x0000001e //ADC Attenuation ADCR #define P17_ADC_ALC_CTRL1 0x00000020 //ADC ALC Control 1 #define P17_ADC_ALC_CTRL2 0x00000022 //ADC ALC Control 2 #define P17_ADC_ALC_CTRL3 0x00000024 //ADC ALC Control 3 #define P17_ADC_NOISE_CTRL 0x00000026 //ADC Noise Gate Control #define P17_ADC_LIMIT_CTRL 0x00000028 //ADC Limiter Control #define P17_ADC_MUX 0x0000002a //ADC Mux offset #define P17_ADC_GAIN_MASK 0x000000ff //Mask for ADC Gain #define P17_ADC_ZERODB 0x000000cf //Value to set ADC to 0dB #define P17_ADC_MUTE_MASK 0x000000c0 //Mask for ADC mute #define P17_ADC_MUTE 0x000000c0 //Value to mute ADC #define P17_ADC_OSR 0x00000008 //Mask for ADC oversample rate select #define P17_ADC_TIMEOUT_DISABLE 0x00000008 //Value and mask to disable Timeout clock #define P17_ADC_HPF_DISABLE 0x00000100 //Value and mask to disable High pass filter #define P17_ADC_TRANWIN_MASK 0x00000070 //Mask for Length of Transient Window #define P17_ADC_MUX_MASK 0x0000000f //Mask for ADC Mux #define P17_ADC_MUX_MIC 0x00000002 //Value to select Mic at ADC Mux #define P17_ADC_MUX_LINEIN 0x00000004 //Value to select LineIn at ADC Mux #define P17_ADC_MUX_PHONE 0x00000001 //Value to select TAD at ADC Mux (Not used) #define P17_ADC_MUX_AUX 0x00000008 //Value to select Aux at ADC Mux /** * @brief Write values to ADC through P17 I2C. * * @param ULONG ulMask: \n * The 16bit bits mask of the value which needs to be written. i.e. only bits mask of 1 will be written to the hardware. * Although it is of datatype ULONG (32 bit), only the upper 16 bit is used because for P17 I2C, upper 16 bit is for * writing and lower 16 bit is for reading. * * @param ULONG ulValue: \n * The 16bit value to be written. * Although it is of datatype ULONG (32 bit), only the upper 16 bit is used because for P17 I2C, upper 16 bit is for * writing and lower 16 bit is for reading. * * @param BOOL bMustWrite: \n * Set to TRUE will ensure a write to ADC. * Set to FALSE will only trigger a write to ADC if the value to be written is different from cached value. * * @return * If this function succeeds, the return value is TRUE. * If it fails, the return value is FALSE. * * @remarks If a write to the ADC is not really necessary, i.e. if the value to be written in is the same as the value already in * ADC, we should avoid writing to ADC by setting bMustWrite to FALSE. Times which we really need to write to ADC * regardless of the values in ADC is during ADC init and during powering up from hibernation. * * @note For the ADC we are using, there is no way we can read from it, therefore, only WriteADC() is implemented. * */ BOOL CHardwareP17::WriteADC(ULONG ulMask, ULONG ulValue, BOOL bMustWrite) { CTDPFEX(DBG_HWSETTINGS,("WriteADC ulMask %x, ulValue %x\n", ulMask, ulValue)); ULONG OldADCValue=(ULONG)GetADCCacheValue((ulValue&P17_I2CD_ADC_REG_MASK)>>24); ULONG NewADCValue=OldADCValue; NewADCValue<<=16; NewADCValue &= ~(ulMask); NewADCValue |= (ulValue&ulMask); if(((NewADCValue>>16)==OldADCValue)&&(!bMustWrite)) return TRUE; SetADCCacheValue(((ulValue&P17_I2CD_ADC_REG_MASK)>>24), (USHORT)(NewADCValue>>16)); HWIODATA Addr, Data; ULONG retry; //Set the ADC Register and values //Send the data to ADC Addr.Reg = P17_PTR; Addr.Mask = 0xffffffff; Addr.Value = (P17_I2C_D); Data.Reg = P17_DATA; Data.Mask = 0xffffffff; Data.Value = NewADCValue; CTDPFEX(DBG_HWSETTINGS,("Write to I2C_D, ulmask %x, ulValue %x\n", Data.Mask, Data.Value)); WriteIndirectReg(&Addr, &Data); for(retry=0;retry<10;retry++) { //Send the data to ADC Addr.Reg = P17_PTR; Addr.Mask = 0xffffffff; Addr.Value = (P17_I2C_A); Data.Reg = P17_DATA; Data.Mask = P17_I2CA_ADC_READ|P17_I2CA_ADC_LAST|P17_I2CA_ADC_START|P17_I2CA_ADC_ADD_MASK; Data.Value = P17_I2CA_ADC_LAST|P17_I2CA_ADC_START|P17_I2CA_ADC_ADD; WriteIndirectReg(&Addr, &Data); CTDPFEX(DBG_HWSETTINGS,("Write to I2C_A, ulmask %x, ulValue %x\n", Data.Mask, Data.Value)); //Wait till the transaction ends ULONG timeout=0; while(1) { Data.Mask = P17_I2CA_ADC_ABORT|P17_I2CA_ADC_START; Data.Value = 0; ReadIndirectReg(&Addr, &Data); timeout++; if((Data.Value & P17_I2CA_ADC_START)==0) break; if(timeout>1000) break; } //Read back and see if the transaction is successful if((Data.Value & P17_I2CA_ADC_ABORT)==0) break; } if(retry==10) { CTDPFEX(DBG_HWSETTINGS,("Writing to ADC failed!\n")); return FALSE; } return TRUE; }