| 1 | /* |
|---|
| 2 | |
|---|
| 3 | Driver APIs for MxL201RF Tuner |
|---|
| 4 | |
|---|
| 5 | Copyright, Maxlinear, Inc. |
|---|
| 6 | All Rights Reserved |
|---|
| 7 | |
|---|
| 8 | File Name: MxL201RF_API.c |
|---|
| 9 | |
|---|
| 10 | Version: 6.2.5 |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | //#include "StdAfx.h" |
|---|
| 15 | #include <stddef.h> |
|---|
| 16 | #include "MxL201RF_API.h" |
|---|
| 17 | #include "MxL_User_Define.h" |
|---|
| 18 | #include "MxL201RF.h" |
|---|
| 19 | |
|---|
| 20 | //20120319 csm..MxL201RF_Common.h ¿¡ ¼±¾ðµÇ¾ú´ø °Í. |
|---|
| 21 | const ShiftLUT SHIFT_LUT8[]= |
|---|
| 22 | { |
|---|
| 23 | {331000000, 0x18, 0x04}, |
|---|
| 24 | {338000000, 0x2C, 0x04}, |
|---|
| 25 | {339000000, 0xB4, 0x07}, |
|---|
| 26 | {346000000, 0xD4, 0x07}, |
|---|
| 27 | {363000000, 0xD0, 0x07}, |
|---|
| 28 | {394000000, 0x2C, 0x04}, |
|---|
| 29 | {403000000, 0x62, 0x04}, |
|---|
| 30 | {410000000, 0x2C, 0x04}, |
|---|
| 31 | {411000000, 0xD4, 0x07}, |
|---|
| 32 | {418000000, 0xD4, 0x07}, |
|---|
| 33 | {434000000, 0xD4, 0x07}, |
|---|
| 34 | {435000000, 0xD4, 0x07}, |
|---|
| 35 | {466000000, 0x2C, 0x04}, |
|---|
| 36 | {506000000, 0xD4, 0x07}, |
|---|
| 37 | {538000000, 0x2C, 0x04}, |
|---|
| 38 | {578000000, 0xD4, 0x07}, |
|---|
| 39 | {610000000, 0x2C, 0x04}, |
|---|
| 40 | {650000000, 0xD4, 0x07}, |
|---|
| 41 | {682000000, 0x3C, 0x04}, |
|---|
| 42 | {722000000, 0xCA, 0x07}, |
|---|
| 43 | {754000000, 0x34, 0x04}, |
|---|
| 44 | {794000000, 0xCC, 0x07}, |
|---|
| 45 | {826000000, 0x34, 0x04}, |
|---|
| 46 | {866000000, 0xCC, 0x07}, |
|---|
| 47 | {898000000, 0x34, 0x04}, |
|---|
| 48 | {938000000, 0xCC, 0x07}, |
|---|
| 49 | {970000000, 0x34, 0x04}, |
|---|
| 50 | {-1, 0, 0} |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | const ShiftLUT SHIFT_LUT6[]= |
|---|
| 54 | { |
|---|
| 55 | {339000000, 0xD4, 0x07}, |
|---|
| 56 | {345000000, 0x2C, 0x04}, |
|---|
| 57 | {357000000, 0x2C, 0x04}, |
|---|
| 58 | {363000000, 0xD2, 0x07}, |
|---|
| 59 | {375000000, 0xD4, 0x07}, |
|---|
| 60 | {381000000, 0x2C, 0x04}, |
|---|
| 61 | {393000000, 0x2C, 0x04}, |
|---|
| 62 | {399000000, 0xD4, 0x07}, |
|---|
| 63 | {411000000, 0xD4, 0x07}, |
|---|
| 64 | {417000000, 0x2C, 0x04}, |
|---|
| 65 | {429000000, 0x2C, 0x04}, |
|---|
| 66 | {435000000, 0xD4, 0x07}, |
|---|
| 67 | {447000000, 0xD4, 0x07}, |
|---|
| 68 | {453000000, 0x2C, 0x04}, |
|---|
| 69 | {465000000, 0x2C, 0x04}, |
|---|
| 70 | {471000000, 0xD4, 0x07}, |
|---|
| 71 | {501000000, 0x2C, 0x04}, |
|---|
| 72 | {507000000, 0xD4, 0x07}, |
|---|
| 73 | {537000000, 0x2C, 0x04}, |
|---|
| 74 | {543000000, 0xD4, 0x07}, |
|---|
| 75 | {573000000, 0x2C, 0x04}, |
|---|
| 76 | {579000000, 0xD4, 0x07}, |
|---|
| 77 | {609000000, 0x2C, 0x04}, |
|---|
| 78 | {615000000, 0xD4, 0x07}, |
|---|
| 79 | {645000000, 0x37, 0x04}, |
|---|
| 80 | {651000000, 0xCA, 0x07}, |
|---|
| 81 | {681000000, 0x34, 0x04}, |
|---|
| 82 | {687000000, 0xCC, 0x07}, |
|---|
| 83 | {717000000, 0x2C, 0x04}, |
|---|
| 84 | {723000000, 0xD4, 0x07}, |
|---|
| 85 | {753000000, 0x2C, 0x04}, |
|---|
| 86 | {759000000, 0xD4, 0x07}, |
|---|
| 87 | {789000000, 0x2C, 0x04}, |
|---|
| 88 | {795000000, 0xD4, 0x07}, |
|---|
| 89 | {825000000, 0x34, 0x04}, |
|---|
| 90 | {831000000, 0xCC, 0x07}, |
|---|
| 91 | {861000000, 0x34, 0x04}, |
|---|
| 92 | {867000000, 0xCC, 0x07}, |
|---|
| 93 | {897000000, 0x34, 0x04}, |
|---|
| 94 | {903000000, 0xCC, 0x07}, |
|---|
| 95 | {933000000, 0x34, 0x04}, |
|---|
| 96 | {939000000, 0xCC, 0x07}, |
|---|
| 97 | {969000000, 0x34, 0x04}, |
|---|
| 98 | {975000000, 0xCC, 0x07}, |
|---|
| 99 | {-1, 0, 0} |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|---|
| 104 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|---|
| 105 | // // |
|---|
| 106 | // Tuner Functions // |
|---|
| 107 | // // |
|---|
| 108 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++// |
|---|
| 109 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ |
|---|
| 110 | MxL_ERR_MSG MxL_Set_Register(MxL201RF_TunerConfigS* myTuner, UINT8 RegAddr, UINT8 RegData) |
|---|
| 111 | { |
|---|
| 112 | UINT32 Status=0; |
|---|
| 113 | UINT8 pArray[2]; |
|---|
| 114 | pArray[0] = RegAddr; |
|---|
| 115 | pArray[1] = RegData; |
|---|
| 116 | Status = MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 2); |
|---|
| 117 | if(Status) return MxL_ERR_SET_REG; |
|---|
| 118 | |
|---|
| 119 | return MxL_OK; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | MxL_ERR_MSG MxL_Get_Register(MxL201RF_TunerConfigS* myTuner, UINT8 RegAddr, UINT8 *RegData) |
|---|
| 123 | { |
|---|
| 124 | if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, RegAddr, RegData)) |
|---|
| 125 | return MxL_ERR_GET_REG; |
|---|
| 126 | return MxL_OK; |
|---|
| 127 | |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | MxL_ERR_MSG MxL_Soft_Reset(MxL201RF_TunerConfigS* myTuner) |
|---|
| 131 | { |
|---|
| 132 | UINT8 reg_reset; |
|---|
| 133 | reg_reset = 0xFF; |
|---|
| 134 | if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, ®_reset, 1)) |
|---|
| 135 | return MxL_ERR_OTHERS; |
|---|
| 136 | |
|---|
| 137 | return MxL_OK; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | MxL_ERR_MSG MxL_Stand_By(MxL201RF_TunerConfigS* myTuner) |
|---|
| 142 | { |
|---|
| 143 | UINT8 pArray[4]; /* a array pointer that store the addr and data pairs for I2C write */ |
|---|
| 144 | |
|---|
| 145 | pArray[0] = 0x01; |
|---|
| 146 | pArray[1] = 0x0; |
|---|
| 147 | pArray[2] = 0x10; |
|---|
| 148 | pArray[3] = 0x0; |
|---|
| 149 | |
|---|
| 150 | if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 4)) |
|---|
| 151 | return MxL_ERR_OTHERS; |
|---|
| 152 | |
|---|
| 153 | return MxL_OK; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | MxL_ERR_MSG MxL_Wake_Up(MxL201RF_TunerConfigS* myTuner) |
|---|
| 157 | { |
|---|
| 158 | UINT8 pArray[2]; /* a array pointer that store the addr and data pairs for I2C write */ |
|---|
| 159 | |
|---|
| 160 | pArray[0] = 0x01; |
|---|
| 161 | pArray[1] = 0x01; |
|---|
| 162 | |
|---|
| 163 | if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, 2)) |
|---|
| 164 | return MxL_ERR_OTHERS; |
|---|
| 165 | |
|---|
| 166 | if(MxL_Tuner_RFTune(myTuner, myTuner->RF_Freq_Hz, myTuner->BW_MHz)) |
|---|
| 167 | return MxL_ERR_RFTUNE; |
|---|
| 168 | |
|---|
| 169 | return MxL_OK; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | MxL_ERR_MSG MxL_Tuner_Init(MxL201RF_TunerConfigS* myTuner) |
|---|
| 173 | { |
|---|
| 174 | UINT8 pArray[MAX_ARRAY_SIZE]; /* a array pointer that store the addr and data pairs for I2C write */ |
|---|
| 175 | UINT32 Array_Size; /* a integer pointer that store the number of element in above array */ |
|---|
| 176 | |
|---|
| 177 | /* Soft reset tuner */ |
|---|
| 178 | if(MxL_Soft_Reset(myTuner)) |
|---|
| 179 | return MxL_ERR_INIT; |
|---|
| 180 | |
|---|
| 181 | /* perform initialization calculation */ |
|---|
| 182 | MxL201RF_Init(pArray, &Array_Size, (UINT8)myTuner->Mode, (UINT32)myTuner->Xtal_Freq, |
|---|
| 183 | (UINT32)myTuner->IF_Freq, (UINT8)myTuner->IF_Spectrum, (UINT8)myTuner->ClkOut_Setting, (UINT8)myTuner->ClkOut_Amp, |
|---|
| 184 | (UINT8)myTuner->Xtal_Cap); |
|---|
| 185 | |
|---|
| 186 | /* perform I2C write here */ |
|---|
| 187 | if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, Array_Size)) |
|---|
| 188 | return MxL_ERR_INIT; |
|---|
| 189 | |
|---|
| 190 | return MxL_OK; |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | MxL_ERR_MSG MxL_Tuner_RFTune(MxL201RF_TunerConfigS* myTuner, UINT32 RF_Freq_Hz, MxL201RF_BW_MHz BWMHz) |
|---|
| 195 | { |
|---|
| 196 | UINT8 pArray[MAX_ARRAY_SIZE]; /* a array pointer that store the addr and data pairs for I2C write */ |
|---|
| 197 | UINT32 Array_Size; /* a integer pointer that store the number of element in above array */ |
|---|
| 198 | |
|---|
| 199 | /* Register Address, Mask, and Value for CHANGE_CHAN_SQ */ |
|---|
| 200 | UINT8 Addr = 0x3E; |
|---|
| 201 | UINT8 Mask = 0x20; |
|---|
| 202 | UINT8 Val = 0; |
|---|
| 203 | |
|---|
| 204 | UINT32 counter = 0; |
|---|
| 205 | |
|---|
| 206 | /* Store information into struc */ |
|---|
| 207 | myTuner->RF_Freq_Hz = RF_Freq_Hz; |
|---|
| 208 | myTuner->BW_MHz = BWMHz; |
|---|
| 209 | |
|---|
| 210 | /* Set CHANGE_CHAN_SQ = 0*/ |
|---|
| 211 | MxL_Get_Register(myTuner, Addr, &Val); |
|---|
| 212 | Val = Val & ~Mask; |
|---|
| 213 | MxL_Set_Register(myTuner, Addr, Val); |
|---|
| 214 | |
|---|
| 215 | /* perform Channel Change calculation */ |
|---|
| 216 | MxL201RF_RFTune(pArray,&Array_Size,RF_Freq_Hz,BWMHz, myTuner->Mode); |
|---|
| 217 | |
|---|
| 218 | /* perform I2C write here */ |
|---|
| 219 | if(MxL_I2C_Write((UINT8)myTuner->I2C_Addr, pArray, Array_Size)) |
|---|
| 220 | return MxL_ERR_RFTUNE; |
|---|
| 221 | |
|---|
| 222 | /* SHFLUT HERE */ |
|---|
| 223 | |
|---|
| 224 | /* wait for 1ms */ |
|---|
| 225 | MxL_Delay(1); |
|---|
| 226 | |
|---|
| 227 | /* Set CHANGE_CHAN_SQ = 1*/ |
|---|
| 228 | Val = Val | Mask; |
|---|
| 229 | MxL_Set_Register(myTuner, Addr, Val); |
|---|
| 230 | |
|---|
| 231 | MxL_Delay(2); |
|---|
| 232 | |
|---|
| 233 | /* SHFLUT */ |
|---|
| 234 | MxL_Set_Register(myTuner,0x5F,0x00); |
|---|
| 235 | if(myTuner->Xtal_Freq == MxL_XTAL_24_MHZ) |
|---|
| 236 | { |
|---|
| 237 | counter = 0; |
|---|
| 238 | if(myTuner->BW_MHz == MxL_BW_8MHz) |
|---|
| 239 | { |
|---|
| 240 | while(SHIFT_LUT8[counter].Ch_Freq_Hz != -1) |
|---|
| 241 | { |
|---|
| 242 | if(SHIFT_LUT8[counter].Ch_Freq_Hz == RF_Freq_Hz) |
|---|
| 243 | { |
|---|
| 244 | MxL_Set_Register(myTuner,0x5E,SHIFT_LUT8[counter].Reg1_Val); |
|---|
| 245 | MxL_Set_Register(myTuner,0x5F,SHIFT_LUT8[counter].Reg2_Val); |
|---|
| 246 | break; |
|---|
| 247 | } |
|---|
| 248 | counter++; |
|---|
| 249 | } |
|---|
| 250 | } |
|---|
| 251 | else if(myTuner->BW_MHz == MxL_BW_6MHz) |
|---|
| 252 | { |
|---|
| 253 | while(SHIFT_LUT6[counter].Ch_Freq_Hz != -1) |
|---|
| 254 | { |
|---|
| 255 | if(SHIFT_LUT6[counter].Ch_Freq_Hz == RF_Freq_Hz) |
|---|
| 256 | { |
|---|
| 257 | MxL_Set_Register(myTuner,0x5E,SHIFT_LUT6[counter].Reg1_Val); |
|---|
| 258 | MxL_Set_Register(myTuner,0x5F,SHIFT_LUT6[counter].Reg2_Val); |
|---|
| 259 | break; |
|---|
| 260 | } |
|---|
| 261 | counter++; |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /* Start Tune */ |
|---|
| 267 | MxL_Set_Register(myTuner, 0x10, 0x01); |
|---|
| 268 | |
|---|
| 269 | MxL_Delay(30); |
|---|
| 270 | |
|---|
| 271 | return MxL_OK; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | MxL_ERR_MSG MxL_Enable_LT(MxL201RF_TunerConfigS* myTuner, UINT8 En_LT) |
|---|
| 275 | { |
|---|
| 276 | UINT8 Status; |
|---|
| 277 | if(En_LT) |
|---|
| 278 | Status = MxL_Set_Register(myTuner, 0x0C, 0x00); |
|---|
| 279 | else |
|---|
| 280 | Status = MxL_Set_Register(myTuner, 0x0C, 0x01); |
|---|
| 281 | |
|---|
| 282 | if(Status) |
|---|
| 283 | return MxL_ERR_SET_REG; |
|---|
| 284 | |
|---|
| 285 | return MxL_OK; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | MxL_ERR_MSG MxL_Check_ChipVersion(MxL201RF_TunerConfigS* myTuner, MxL201RF_ChipVersion* myChipVersion) |
|---|
| 290 | { |
|---|
| 291 | UINT8 Data; |
|---|
| 292 | if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0x15, &Data)) |
|---|
| 293 | return MxL_GET_ID_FAIL; |
|---|
| 294 | |
|---|
| 295 | switch(Data & 0x0F) |
|---|
| 296 | { |
|---|
| 297 | case 0x06: *myChipVersion=MxL_201RF_ES4; break; |
|---|
| 298 | default: |
|---|
| 299 | *myChipVersion=MxL_UNKNOWN_ID; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | return MxL_OK; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | MxL_ERR_MSG MxL_RFSynth_Lock_Status(MxL201RF_TunerConfigS* myTuner, BOOL* isLock) |
|---|
| 306 | { |
|---|
| 307 | UINT8 Data; |
|---|
| 308 | *isLock = FALSE; |
|---|
| 309 | if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0x14, &Data)) |
|---|
| 310 | return MxL_ERR_OTHERS; |
|---|
| 311 | Data &= 0x0C; |
|---|
| 312 | if (Data == 0x0C) |
|---|
| 313 | *isLock = TRUE; /* RF Synthesizer is Lock */ |
|---|
| 314 | return MxL_OK; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | MxL_ERR_MSG MxL_REFSynth_Lock_Status(MxL201RF_TunerConfigS* myTuner, BOOL* isLock) |
|---|
| 318 | { |
|---|
| 319 | UINT8 Data; |
|---|
| 320 | *isLock = FALSE; |
|---|
| 321 | if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0x14, &Data)) |
|---|
| 322 | return MxL_ERR_OTHERS; |
|---|
| 323 | Data &= 0x03; |
|---|
| 324 | if (Data == 0x03) |
|---|
| 325 | *isLock = TRUE; /*REF Synthesizer is Lock */ |
|---|
| 326 | return MxL_OK; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | MxL_ERR_MSG MxL_Check_RF_Input_Power(MxL201RF_TunerConfigS* myTuner, REAL32* RF_Input_Level) |
|---|
| 330 | { |
|---|
| 331 | REAL32 temp; |
|---|
| 332 | |
|---|
| 333 | UINT8 Data1, Data2, whole, dec; |
|---|
| 334 | if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0x16, &Data1)) /* LSBs */ |
|---|
| 335 | return MxL_ERR_OTHERS; |
|---|
| 336 | if(MxL_I2C_Read((UINT8)myTuner->I2C_Addr, 0x17, &Data2)) /* MSBs */ |
|---|
| 337 | return MxL_ERR_OTHERS; |
|---|
| 338 | |
|---|
| 339 | /* Determine whole and fractional portions of the power */ |
|---|
| 340 | whole = (Data1 >> 3) | (Data2 << 5); |
|---|
| 341 | dec = Data1 & 0x07; |
|---|
| 342 | |
|---|
| 343 | temp = (REAL32)(whole) + (REAL32)(dec*0.125); |
|---|
| 344 | |
|---|
| 345 | *RF_Input_Level= temp - 120; |
|---|
| 346 | |
|---|
| 347 | return MxL_OK; |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | MxL_ERR_MSG MxL_Input_Power_LUT_Reg_Write(MxL201RF_TunerConfigS* myTuner, UINT8 LUT_Index, UINT8 LUT_Val) |
|---|
| 351 | { |
|---|
| 352 | if(LUT_Index > 15) |
|---|
| 353 | return MxL_ERR_OTHERS; |
|---|
| 354 | |
|---|
| 355 | MxL_Set_Register(myTuner, 0x6A, LUT_Index); |
|---|
| 356 | MxL_Set_Register(myTuner, 0x6B, LUT_Val); |
|---|
| 357 | |
|---|
| 358 | return MxL_OK; |
|---|
| 359 | } |
|---|