mtv23x_rf.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /******************************************************************************
  2. * (c) COPYRIGHT 2013 RAONTECH, Inc. ALL RIGHTS RESERVED.
  3. *
  4. * TITLE : MTV23x RF services source file.
  5. *
  6. * FILENAME : mtv23x_rf.c
  7. *
  8. * DESCRIPTION :
  9. * Library of routines to initialize, and operate on the RAONTECH T-DMB demod.
  10. *
  11. ******************************************************************************/
  12. /******************************************************************************
  13. * REVISION HISTORY
  14. *
  15. * DATE NAME REMARKS
  16. * ---------- ------------- ------------------------------------------------
  17. * 08/01/2013 Yang, Maverick Revised for REV3
  18. * 03/03/2013 Yang, Maverick Created.
  19. ******************************************************************************/
  20. #include "mtv23x_rf.h"
  21. #include "mtv23x_rf_adc_data.h"
  22. #include "mtv23x_internal.h"
  23. /*
  24. Down conversion Signal Monitoring.
  25. */
  26. /* #define DEBUG_A_TEST_ZERO */
  27. static const struct RTV_REG_INIT_INFO t_mtv23x_INIT[] = {
  28. {0x25, 0xF8},
  29. {0x26, 0x00},
  30. {0x28, 0xDD},
  31. {0x29, 0xC4},
  32. {0x2C, 0x1D},
  33. {0x2D, 0x90},
  34. {0x2F, 0x06},
  35. {0x30, 0xDF},
  36. {0x33, 0x11},
  37. {0x36, 0x09},
  38. {0x38, 0xF0},
  39. {0x39, 0x00},
  40. {0x3A, 0xAA},
  41. {0x3E, 0x2D},
  42. {0x47, 0x59},
  43. {0x48, 0x28},
  44. {0x49, 0x41},
  45. {0x4A, 0x70},
  46. {0x4B, 0x65},
  47. {0x4E, 0x4B},
  48. {0x50, 0x6F},
  49. {0x51, 0x3C},
  50. {0x53, 0x65},
  51. {0x54, 0xC0},
  52. {0x5D, 0x01},
  53. {0x5E, 0x70},
  54. {0x5F, 0x75},
  55. {0x60, 0x62},
  56. {0x61, 0x80},
  57. {0x69, 0x0E},
  58. {0x6A, 0x14},
  59. {0x6B, 0x18},
  60. {0x6C, 0xFF},
  61. {0x6D, 0xFD},
  62. {0x6E, 0x19},
  63. {0x70, 0x80},
  64. {0x71, 0x6E},
  65. {0x74, 0x15},
  66. {0x75, 0xA4},
  67. {0x77, 0x69},
  68. {0x78, 0x3D},
  69. {0x7D, 0x28},
  70. {0x81, 0x9C},
  71. {0x83, 0x9F},
  72. {0x85, 0x40},
  73. {0x86, 0x87},
  74. {0x87, 0x84},
  75. {0x88, 0x22},
  76. {0x89, 0x20},
  77. {0x8A, 0xF6},
  78. {0x8B, 0xB5},
  79. {0x8C, 0xFC},
  80. {0x8D, 0xFF},
  81. {0x8E, 0xFE},
  82. {0x8F, 0xFD},
  83. {0x90, 0xFD},
  84. {0x91, 0xFC},
  85. {0x92, 0x0E},
  86. {0x93, 0x0D},
  87. {0x94, 0x09},
  88. {0x95, 0xA3},
  89. {0x96, 0xF0},
  90. {0x97, 0x19},
  91. {0x99, 0x42},
  92. {0x9A, 0x6C},
  93. {0x9B, 0x10},
  94. {0x9C, 0x8E},
  95. {0x9D, 0x3C},
  96. {0x9E, 0x30},
  97. {0x9F, 0x63},
  98. {0xA1, 0x40},
  99. {0xA2, 0x5C},
  100. {0xA3, 0x1C},
  101. {0xA4, 0x85},
  102. {0xA5, 0xB4},
  103. {0xA6, 0x30},
  104. {0xA7, 0x00},
  105. {0xA9, 0x00},
  106. {0xAA, 0x04},
  107. {0xAB, 0x30},
  108. {0xAC, 0x00},
  109. {0xAD, 0x14},
  110. {0xAE, 0x30},
  111. {0xAF, 0x00},
  112. {0xB1, 0x00},
  113. {0xB2, 0x04},
  114. {0xB3, 0x30},
  115. {0xB4, 0x00},
  116. {0xB5, 0xB1},
  117. {0xB7, 0x05},
  118. {0xBC, 0x1F},
  119. {0xBD, 0x1F},
  120. {0xBE, 0x5F},
  121. {0xBF, 0x1F},
  122. {0xC0, 0x1F},
  123. {0xC1, 0x5F},
  124. {0xC2, 0x1F},
  125. {0xC3, 0x1F},
  126. {0xC4, 0x5F},
  127. {0xC6, 0x4A},
  128. {0xC7, 0x4A},
  129. {0xCA, 0xCA},
  130. {0xCB, 0x4A},
  131. {0xCC, 0x4F},
  132. {0xCF, 0x80},
  133. {0xD0, 0x20},
  134. {0xD4, 0x1F},
  135. {0xD7, 0x80},
  136. {0xD8, 0x00},
  137. {0xDA, 0xA4},
  138. {0xDF, 0x01},
  139. {0xE2, 0x24},
  140. {0xE5, 0xA8},
  141. {0xE6, 0xA6},
  142. {0xE7, 0x64}
  143. };
  144. static enum E_RTV_BANDWIDTH_TYPE g_aeBwType;
  145. UINT g_dwRtvPrevChFreqKHz;
  146. static U32 g_nLnaTuneVal;
  147. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  148. enum E_RTV_BANDWIDTH_TYPE g_aeBwType_slave;
  149. U32 g_nLnaTuneVal_slave;
  150. #endif
  151. static int rtvRF_ConfigureClkCKSYN(enum E_RTV_BANDWIDTH_TYPE eBwType)
  152. {
  153. U8 WR6D = 0, WR6E = 0, WR70 = 0, WR71 = 0;
  154. U8 WR2A = 0, WR72 = 0, WR73 = 0, WR74 = 0, WR75 = 0;
  155. WR6D = RTV_REG_GET(0x6d) & 0xFC;
  156. WR6E = RTV_REG_GET(0x6e) & 0x00;
  157. WR70 = RTV_REG_GET(0x70) & 0x00;
  158. WR2A = RTV_REG_GET(0x2A) & 0xF7;
  159. WR71 = RTV_REG_GET(0x71) & 0x00;
  160. WR72 = RTV_REG_GET(0x72) & 0x03;
  161. WR73 = RTV_REG_GET(0x73) & 0x03;
  162. WR74 = RTV_REG_GET(0x74) & 0x0F;
  163. WR75 = RTV_REG_GET(0x75) & 0x03;
  164. RTV_REG_SET(0x6D, WR6D | (U8)g_atBW_TABLE_CKSYN[eBwType][2]);
  165. RTV_REG_SET(0x6E, WR6E | (U8)g_atBW_TABLE_CKSYN[eBwType][0]);
  166. RTV_REG_SET(0x70, WR70 | (U8)(g_atBW_TABLE_CKSYN[eBwType][1] & 0xFF));
  167. RTV_REG_SET(0x2A, WR2A | (U8)(g_atBW_TABLE_CKSYN[eBwType][3] << 3));
  168. RTV_REG_SET(0x71, WR71 | (U8)(((g_atBW_TABLE_CKSYN[eBwType][1] & 0x300) >> 2)
  169. | g_atBW_TABLE_CKSYN[eBwType][4]));
  170. RTV_REG_SET(0x72, WR72 | (U8)(g_atBW_TABLE_CKSYN[eBwType][6] << 2));
  171. RTV_REG_SET(0x73, WR73 | (U8)(g_atBW_TABLE_CKSYN[eBwType][5] << 2));
  172. RTV_REG_SET(0x74, WR74 | (U8)(g_atBW_TABLE_CKSYN[eBwType][7] << 4));
  173. RTV_REG_SET(0x75, WR75 | (U8)(g_atBW_TABLE_CKSYN[eBwType][8] << 2));
  174. if (rtvRF_LockCheck(1) != RTV_SUCCESS)
  175. return RTV_ADC_CLK_UNLOCKED;
  176. return RTV_SUCCESS;
  177. }
  178. static int rtvRF_ConfigureIIRFilter(enum E_RTV_BANDWIDTH_TYPE eBwType)
  179. {
  180. U8 WR95 = 0;
  181. WR95 = RTV_REG_GET(0x95) & 0xC0;
  182. RTV_REG_SET(0x95, (WR95 | (U8)((g_atBW_TABLE_IIR[eBwType][0]<<4) | ((g_atBW_TABLE_IIR[eBwType][1]&0xF0000)>>16))));
  183. RTV_REG_SET(0x96, ((g_atBW_TABLE_IIR[eBwType][1] & 0x0FF00)>>8));
  184. RTV_REG_SET(0x97, ((g_atBW_TABLE_IIR[eBwType][1] & 0x000FF)>>0));
  185. RTV_REG_SET(0x98, ((g_atBW_TABLE_IIR[eBwType][2] & 0xFF000)>>12));
  186. RTV_REG_SET(0x99, ((g_atBW_TABLE_IIR[eBwType][2] & 0x00FF0)>>4));
  187. RTV_REG_SET(0x9A, (U8)((((g_atBW_TABLE_IIR[eBwType][2] & 0x0000F)>>0) << 4) |
  188. ((g_atBW_TABLE_IIR[eBwType][3] & 0xF0000)>>16)));
  189. RTV_REG_SET(0x9B, (U8)((g_atBW_TABLE_IIR[eBwType][3] & 0x0FF00)>>8));
  190. RTV_REG_SET(0x9C, (U8)((g_atBW_TABLE_IIR[eBwType][3] & 0x000FF)>>0));
  191. RTV_REG_SET(0x9D, (U8)((((g_atBW_TABLE_IIR[eBwType][13] & 0xF0000)>>16) << 4) |
  192. (U8)((g_atBW_TABLE_IIR[eBwType][4] & 0xF0000)>>16)));
  193. RTV_REG_SET(0x9E, (U8)((g_atBW_TABLE_IIR[eBwType][4] & 0x0FF00)>>8));
  194. RTV_REG_SET(0x9F, (U8)((g_atBW_TABLE_IIR[eBwType][4] & 0x000FF)>>0));
  195. RTV_REG_SET(0xA0, (U8)((g_atBW_TABLE_IIR[eBwType][5] & 0xFF000)>>12));
  196. RTV_REG_SET(0xA1, (U8)((g_atBW_TABLE_IIR[eBwType][5] & 0x00FF0)>>4));
  197. RTV_REG_SET(0xA2, (U8)((((g_atBW_TABLE_IIR[eBwType][5] & 0x0000F)>>0) << 4) |
  198. ((g_atBW_TABLE_IIR[eBwType][6] & 0xF0000)>>16)));
  199. RTV_REG_SET(0xA3, (U8)((g_atBW_TABLE_IIR[eBwType][6] & 0x0FF00)>>8));
  200. RTV_REG_SET(0xA4, (U8)((g_atBW_TABLE_IIR[eBwType][6] & 0x000FF)>>0));
  201. RTV_REG_SET(0xA5, (U8)((((g_atBW_TABLE_IIR[eBwType][13] & 0x0F000)>>12) << 4) |
  202. (U8)((g_atBW_TABLE_IIR[eBwType][7] & 0xF0000)>>16)));
  203. RTV_REG_SET(0xA6, (U8)((g_atBW_TABLE_IIR[eBwType][7] & 0x0FF00)>>8));
  204. RTV_REG_SET(0xA7, (U8)((g_atBW_TABLE_IIR[eBwType][7] & 0x000FF)>>0));
  205. RTV_REG_SET(0xA8, (U8)((g_atBW_TABLE_IIR[eBwType][8] & 0xFF000)>>12));
  206. RTV_REG_SET(0xA9, (U8)((g_atBW_TABLE_IIR[eBwType][8] & 0x00FF0)>>4));
  207. RTV_REG_SET(0xAA, (U8)((((g_atBW_TABLE_IIR[eBwType][8] & 0x0000F)>>0) << 4) |
  208. ((g_atBW_TABLE_IIR[eBwType][9] & 0xF0000)>>16)));
  209. RTV_REG_SET(0xAB, (U8)((g_atBW_TABLE_IIR[eBwType][9] & 0x0FF00)>>8));
  210. RTV_REG_SET(0xAC, (U8)((g_atBW_TABLE_IIR[eBwType][9] & 0x000FF)>>0));
  211. RTV_REG_SET(0xAD, (U8)((((g_atBW_TABLE_IIR[eBwType][13] & 0x00F00)>>8) << 4) |
  212. (U8)((g_atBW_TABLE_IIR[eBwType][10] & 0xF0000)>>16)));
  213. RTV_REG_SET(0xAE, (U8)((g_atBW_TABLE_IIR[eBwType][10] & 0x0FF00)>>8));
  214. RTV_REG_SET(0xAF, (U8)((g_atBW_TABLE_IIR[eBwType][10] & 0x000FF)>>0));
  215. RTV_REG_SET(0xB0, (U8)((g_atBW_TABLE_IIR[eBwType][11] & 0xFF000)>>12));
  216. RTV_REG_SET(0xB1, (U8)((g_atBW_TABLE_IIR[eBwType][11] & 0x00FF0)>>4));
  217. RTV_REG_SET(0xB2, (U8)((((g_atBW_TABLE_IIR[eBwType][11] & 0x0000F)>>0) << 4) |
  218. ((g_atBW_TABLE_IIR[eBwType][12] & 0xF0000)>>16)));
  219. RTV_REG_SET(0xB3, (U8)((g_atBW_TABLE_IIR[eBwType][12] & 0x0FF00)>>8));
  220. RTV_REG_SET(0xB4, (U8)((g_atBW_TABLE_IIR[eBwType][12] & 0x000FF)>>0));
  221. RTV_REG_SET(0xB5, (U8)((g_atBW_TABLE_IIR[eBwType][13] & 0x000FF)>>0));
  222. return RTV_SUCCESS;
  223. }
  224. static int rtvRF_ConfigureBBA(enum E_RTV_BANDWIDTH_TYPE eBwType)
  225. {
  226. U8 WR3E = 0, WR3F = 0, WR50 = 0, WR51 = 0, WR4F = 0, WR4E = 0, WR77 = 0;
  227. WR3E = RTV_REG_GET(0x3E) & 0x00;
  228. WR3F = RTV_REG_GET(0x3F) & 0x03;
  229. WR50 = RTV_REG_GET(0x50) & 0x1F;
  230. WR51 = RTV_REG_GET(0x51) & 0x8F;
  231. WR4F = RTV_REG_GET(0x4F) & 0x1F;
  232. WR4E = RTV_REG_GET(0x4E) & 0x1F;
  233. WR77 = RTV_REG_GET(0x77) & 0xFC;
  234. RTV_REG_SET(0x3E, WR3E | g_atBW_TABLE_BBA[eBwType][0]);
  235. RTV_REG_SET(0x3F, WR3F | (g_atBW_TABLE_BBA[eBwType][1] << 2));
  236. RTV_REG_SET(0x50, WR50 | (g_atBW_TABLE_BBA[eBwType][2] << 5));
  237. RTV_REG_SET(0x51, WR51 | (g_atBW_TABLE_BBA[eBwType][3] << 4));
  238. RTV_REG_SET(0x4F, WR4F | (g_atBW_TABLE_BBA[eBwType][4] << 5));
  239. RTV_REG_SET(0x4E, WR4E | (g_atBW_TABLE_BBA[eBwType][5] << 5));
  240. RTV_REG_SET(0x77, WR77 | (g_atBW_TABLE_BBA[eBwType][6] << 0));
  241. return RTV_SUCCESS;
  242. }
  243. static int rtvRF_ConfigureADC(enum E_RTV_BANDWIDTH_TYPE eBwType)
  244. {
  245. U8 WRB7 = 0, WRC8 = 0, WRC9 = 0, WRCA = 0, WRCB = 0, WRCC = 0;
  246. U8 WRCD = 0, WRCE = 0;
  247. U8 WRD1 = 0, WRD2 = 0, WRD3 = 0, WRD5 = 0, WRD6 = 0, WRD7 = 0;
  248. U8 WRD8 = 0, WRD9 = 0, WRDA = 0;
  249. WRB7 = RTV_REG_GET(0xB7) & 0x07;
  250. WRC8 = RTV_REG_GET(0xC8) & 0x80;
  251. WRC9 = RTV_REG_GET(0xC9) & 0x80;
  252. WRCA = RTV_REG_GET(0xCA) & 0x80;
  253. WRCB = RTV_REG_GET(0xCB) & 0x80;
  254. WRCC = RTV_REG_GET(0xCC) & 0x80;
  255. WRCD = RTV_REG_GET(0xCD) & 0x80;
  256. WRCE = RTV_REG_GET(0xCE) & 0x80;
  257. WRD1 = RTV_REG_GET(0xD1) & 0x80;
  258. WRD2 = RTV_REG_GET(0xD2) & 0x80;
  259. WRD3 = RTV_REG_GET(0xD3) & 0x80;
  260. WRD5 = RTV_REG_GET(0xD5) & 0x80;
  261. WRD6 = RTV_REG_GET(0xD6) & 0x80;
  262. WRD7 = RTV_REG_GET(0xD7) & 0x80;
  263. WRD8 = RTV_REG_GET(0xD8) & 0x80;
  264. WRD9 = RTV_REG_GET(0xD9) & 0xC0;
  265. WRDA = RTV_REG_GET(0xDA) & 0xC0;
  266. RTV_REG_SET(0xB7, (WRB7 | (g_atBW_TABLE_ADC[eBwType][45] << 6) |
  267. (g_atBW_TABLE_ADC[eBwType][46] << 5)));
  268. RTV_REG_SET(0xB8, (g_atBW_TABLE_ADC[eBwType][44]));
  269. RTV_REG_SET(0xB9, (g_atBW_TABLE_ADC[eBwType][43]));
  270. RTV_REG_SET(0xBA, (g_atBW_TABLE_ADC[eBwType][42]));
  271. RTV_REG_SET(0xBB, (g_atBW_TABLE_ADC[eBwType][41]));
  272. RTV_REG_SET(0xBC, ((g_atBW_TABLE_ADC[eBwType][37] & 0x03) << 6) |
  273. g_atBW_TABLE_ADC[eBwType][40]);
  274. RTV_REG_SET(0xBD, (((g_atBW_TABLE_ADC[eBwType][37] & 0x0C) >> 2) << 6) |
  275. g_atBW_TABLE_ADC[eBwType][39]);
  276. RTV_REG_SET(0xBE, (((g_atBW_TABLE_ADC[eBwType][37] & 0x30) >> 4) << 6) |
  277. g_atBW_TABLE_ADC[eBwType][38]);
  278. RTV_REG_SET(0xBF, ((g_atBW_TABLE_ADC[eBwType][33] & 0x03) << 6) |
  279. (g_atBW_TABLE_ADC[eBwType][36]));
  280. RTV_REG_SET(0xC0, (((g_atBW_TABLE_ADC[eBwType][33] & 0x0C) >> 2) << 6) |
  281. (g_atBW_TABLE_ADC[eBwType][35]));
  282. RTV_REG_SET(0xC1, (((g_atBW_TABLE_ADC[eBwType][33] & 0x30) >> 4) << 6) |
  283. (g_atBW_TABLE_ADC[eBwType][34]));
  284. RTV_REG_SET(0xC2, ((g_atBW_TABLE_ADC[eBwType][29] & 0x03) << 6) |
  285. (g_atBW_TABLE_ADC[eBwType][32]));
  286. RTV_REG_SET(0xC3, (((g_atBW_TABLE_ADC[eBwType][29] & 0x0C) >> 2) << 6) |
  287. (g_atBW_TABLE_ADC[eBwType][31]));
  288. RTV_REG_SET(0xC4, (((g_atBW_TABLE_ADC[eBwType][29] & 0x30) >> 4) << 6) |
  289. (g_atBW_TABLE_ADC[eBwType][30]));
  290. RTV_REG_SET(0xC5, (g_atBW_TABLE_ADC[eBwType][28]));
  291. RTV_REG_SET(0xC6, (g_atBW_TABLE_ADC[eBwType][27]));
  292. RTV_REG_SET(0xC7, (g_atBW_TABLE_ADC[eBwType][26]));
  293. RTV_REG_SET(0xC8, (WRC8 | (g_atBW_TABLE_ADC[eBwType][25])));
  294. RTV_REG_SET(0xC9, (WRC9 | (g_atBW_TABLE_ADC[eBwType][24])));
  295. RTV_REG_SET(0xCA, (WRCA | (g_atBW_TABLE_ADC[eBwType][23])));
  296. RTV_REG_SET(0xCB, (WRCB | (g_atBW_TABLE_ADC[eBwType][22])));
  297. RTV_REG_SET(0xCC, (WRCC | (g_atBW_TABLE_ADC[eBwType][21])));
  298. RTV_REG_SET(0xCD, (WRCD | (g_atBW_TABLE_ADC[eBwType][20])));
  299. RTV_REG_SET(0xCE, (WRCE | (g_atBW_TABLE_ADC[eBwType][19])));
  300. RTV_REG_SET(0xCF, (g_atBW_TABLE_ADC[eBwType][18] << 6) |
  301. (g_atBW_TABLE_ADC[eBwType][17] << 4) |
  302. (g_atBW_TABLE_ADC[eBwType][16] << 2) |
  303. (g_atBW_TABLE_ADC[eBwType][15] << 0));
  304. RTV_REG_SET(0xD0, (g_atBW_TABLE_ADC[eBwType][14]));
  305. RTV_REG_SET(0xD1, (WRD1 | (g_atBW_TABLE_ADC[eBwType][13])));
  306. RTV_REG_SET(0xD2, (WRD2 | (g_atBW_TABLE_ADC[eBwType][12])));
  307. RTV_REG_SET(0xD3, (WRD3 | (g_atBW_TABLE_ADC[eBwType][11])));
  308. RTV_REG_SET(0xD4, (g_atBW_TABLE_ADC[eBwType][10]));
  309. RTV_REG_SET(0xD5, (WRD5 | (g_atBW_TABLE_ADC[eBwType][9])));
  310. RTV_REG_SET(0xD6, (WRD6 | (g_atBW_TABLE_ADC[eBwType][8])));
  311. RTV_REG_SET(0xD7, (WRD7 | (g_atBW_TABLE_ADC[eBwType][7])));
  312. RTV_REG_SET(0xD8, (WRD8 | (g_atBW_TABLE_ADC[eBwType][6])));
  313. RTV_REG_SET(0xD9, (WRD9 | (g_atBW_TABLE_ADC[eBwType][5])));
  314. RTV_REG_SET(0xDA, (WRDA | (g_atBW_TABLE_ADC[eBwType][4])));
  315. RTV_REG_SET(0xDB, ((g_atBW_TABLE_ADC[eBwType][3]) << 4) |
  316. (g_atBW_TABLE_ADC[eBwType][2]));
  317. RTV_REG_SET(0xDC, ((g_atBW_TABLE_ADC[eBwType][1]) << 4) |
  318. (g_atBW_TABLE_ADC[eBwType][0]));
  319. return RTV_SUCCESS;
  320. }
  321. static INT rtvRF_ChangeLpfBwType(enum E_RTV_BANDWIDTH_TYPE eBwType)
  322. {
  323. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  324. if (rtvMTV23x_Get_Diversity_Current_path() == DIVERSITY_MASTER) {
  325. if (g_aeBwType == eBwType)
  326. return RTV_SUCCESS;
  327. } else {
  328. if (g_aeBwType_slave == eBwType)
  329. return RTV_SUCCESS;
  330. }
  331. #else
  332. if (g_aeBwType == eBwType)
  333. return RTV_SUCCESS;
  334. #endif
  335. RTV_REG_MAP_SEL(RF_PAGE);
  336. if (rtvRF_ConfigureClkCKSYN(eBwType) != RTV_SUCCESS)
  337. return RTV_ADC_CLK_UNLOCKED;
  338. rtvRF_ConfigureIIRFilter(eBwType);
  339. rtvRF_ConfigureBBA(eBwType);
  340. rtvRF_ConfigureADC(eBwType);
  341. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  342. if (rtvMTV23x_Get_Diversity_Current_path() == DIVERSITY_MASTER)
  343. g_aeBwType = eBwType;
  344. else
  345. g_aeBwType_slave = eBwType;
  346. #else
  347. g_aeBwType = eBwType;
  348. #endif
  349. return RTV_SUCCESS;
  350. }
  351. static INT rtvRF_Lna_Tuning(U32 dwLoFreq)
  352. {
  353. U8 nidx = 0;
  354. U8 WR50 = 0, WR73 = 0, WR4E = 0, WR69 = 0, WR88 = 0, WR89 = 0;
  355. U8 WR8A = 0, WR8B = 0;
  356. U8 WR6C = 0, WR6D = 0, WR6A = 0, WR6B = 0, WR8C = 0, WR8D = 0;
  357. U8 WR8E = 0, WR8F = 0;
  358. U8 WR90 = 0, WR91 = 0, WR92 = 0, WR87 = 0, WR93 = 0, WR94 = 0;
  359. if (75000 < dwLoFreq && 90000 >= dwLoFreq)
  360. nidx = 0;
  361. else if (90000 < dwLoFreq && 100000 >= dwLoFreq)
  362. nidx = 1;
  363. else if (100000 < dwLoFreq && 115000 >= dwLoFreq)
  364. nidx = 2;
  365. else if (115000 < dwLoFreq && 180000 >= dwLoFreq)
  366. nidx = 3;
  367. else if (180000 < dwLoFreq && 190000 >= dwLoFreq)
  368. nidx = 4;
  369. else if (190000 < dwLoFreq && 200000 >= dwLoFreq)
  370. nidx = 5;
  371. else if (200000 < dwLoFreq && 210000 >= dwLoFreq)
  372. nidx = 6;
  373. else if (210000 < dwLoFreq && 220000 >= dwLoFreq)
  374. nidx = 7;
  375. else if (220000 < dwLoFreq && 230000 >= dwLoFreq)
  376. nidx = 8;
  377. else if (230000 < dwLoFreq && 240000 >= dwLoFreq)
  378. nidx = 9;
  379. else if (240000 < dwLoFreq && 250000 >= dwLoFreq)
  380. nidx = 10;
  381. else if (250000 < dwLoFreq && 320000 >= dwLoFreq)
  382. nidx = 11;
  383. else if (320000 < dwLoFreq && 510000 >= dwLoFreq)
  384. nidx = 12;
  385. else if (510000 < dwLoFreq && 540000 >= dwLoFreq)
  386. nidx = 13;
  387. else if (540000 < dwLoFreq && 560000 >= dwLoFreq)
  388. nidx = 14;
  389. else if (560000 < dwLoFreq && 600000 >= dwLoFreq)
  390. nidx = 15;
  391. else if (600000 < dwLoFreq && 630000 >= dwLoFreq)
  392. nidx = 16;
  393. else if (630000 < dwLoFreq && 710000 >= dwLoFreq)
  394. nidx = 17;
  395. else if (710000 < dwLoFreq && 810000 >= dwLoFreq)
  396. nidx = 18;
  397. else if (810000 < dwLoFreq && 880000 >= dwLoFreq)
  398. nidx = 19;
  399. else
  400. return RTV_INVAILD_FREQUENCY_RANGE;
  401. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  402. if (rtvMTV23x_Get_Diversity_Current_path() == DIVERSITY_MASTER) {
  403. if (g_nLnaTuneVal == nidx)
  404. return RTV_SUCCESS;
  405. } else {
  406. if (g_nLnaTuneVal_slave == nidx)
  407. return RTV_SUCCESS;
  408. }
  409. #else
  410. if (g_nLnaTuneVal == nidx)
  411. return RTV_SUCCESS;
  412. #endif
  413. RTV_REG_MAP_SEL(RF_PAGE);
  414. WR50 = RTV_REG_GET(0x50) & 0xE0;
  415. WR73 = RTV_REG_GET(0x73) & 0xFC;
  416. WR4E = RTV_REG_GET(0x4E) & 0xE0;
  417. WR69 = RTV_REG_GET(0x69) & 0x80;
  418. WR88 = RTV_REG_GET(0x88) & 0x03;
  419. WR89 = RTV_REG_GET(0x89) & 0x03;
  420. WR8A = RTV_REG_GET(0x8A) & 0x00;
  421. WR8B = RTV_REG_GET(0x8B) & 0x00;
  422. WR6C = RTV_REG_GET(0x6C) & 0x03;
  423. WR6D = RTV_REG_GET(0x6D) & 0x03;
  424. WR6A = RTV_REG_GET(0x6A) & 0xC1;
  425. WR6B = RTV_REG_GET(0x6B) & 0x03;
  426. WR8C = RTV_REG_GET(0x8C) & 0x00;
  427. WR8D = RTV_REG_GET(0x8D) & 0x00;
  428. WR8E = RTV_REG_GET(0x8E) & 0x00;
  429. WR8F = RTV_REG_GET(0x8F) & 0x00;
  430. WR90 = RTV_REG_GET(0x90) & 0x00;
  431. WR91 = RTV_REG_GET(0x91) & 0x00;
  432. WR92 = RTV_REG_GET(0x92) & 0x00;
  433. WR87 = RTV_REG_GET(0x87) & 0xFB;
  434. WR93 = RTV_REG_GET(0x93) & 0x03;
  435. WR94 = RTV_REG_GET(0x94) & 0x03;
  436. RTV_REG_SET(0x50, WR50 | g_atLNA_TABLE[nidx][0]);
  437. RTV_REG_SET(0x73, WR73 | g_atLNA_TABLE[nidx][1]);
  438. RTV_REG_SET(0x4E, WR4E | g_atLNA_TABLE[nidx][2]);
  439. RTV_REG_SET(0x69, WR69 | (g_atLNA_TABLE[nidx][3] << 2)
  440. | g_atLNA_TABLE[nidx][28]);
  441. RTV_REG_SET(0x88, WR88 | (g_atLNA_TABLE[nidx][4] << 5)
  442. | (g_atLNA_TABLE[nidx][5] << 2));
  443. RTV_REG_SET(0x89, WR89 | (g_atLNA_TABLE[nidx][6] << 5)
  444. | (g_atLNA_TABLE[nidx][7] << 2));
  445. RTV_REG_SET(0x8A, WR8A | (g_atLNA_TABLE[nidx][8] << 4)
  446. | g_atLNA_TABLE[nidx][9]);
  447. RTV_REG_SET(0x8B, WR8B | (g_atLNA_TABLE[nidx][10] << 4)
  448. | g_atLNA_TABLE[nidx][11]);
  449. RTV_REG_SET(0x6C, WR6C | (g_atLNA_TABLE[nidx][12] << 2));
  450. RTV_REG_SET(0x6D, WR6D | (g_atLNA_TABLE[nidx][13] << 2));
  451. RTV_REG_SET(0x6A, WR6A | (g_atLNA_TABLE[nidx][14] << 1));
  452. RTV_REG_SET(0x6B, WR6B | (g_atLNA_TABLE[nidx][15] << 2));
  453. RTV_REG_SET(0x8C, WR8C | (g_atLNA_TABLE[nidx][16] << 2)
  454. | ((g_atLNA_TABLE[nidx][18] & 0x18) >> 3));
  455. RTV_REG_SET(0x8D, WR8D | (g_atLNA_TABLE[nidx][20] << 2)
  456. | ((g_atLNA_TABLE[nidx][18] & 0x06) >> 1));
  457. RTV_REG_SET(0x8E, WR8E | (g_atLNA_TABLE[nidx][24] << 2)
  458. | ((g_atLNA_TABLE[nidx][18] & 0x01) << 1)
  459. | ((g_atLNA_TABLE[nidx][22] & 0x10) >> 4));
  460. RTV_REG_SET(0x8F, WR8F | (g_atLNA_TABLE[nidx][17] << 2)
  461. | ((g_atLNA_TABLE[nidx][22] & 0x0C) >> 2));
  462. RTV_REG_SET(0x90, WR90 | (g_atLNA_TABLE[nidx][21] << 2)
  463. | ((g_atLNA_TABLE[nidx][22] & 0x03) >> 0));
  464. RTV_REG_SET(0x91, WR91 | (g_atLNA_TABLE[nidx][25] << 2)
  465. | ((g_atLNA_TABLE[nidx][26] & 0x18) >> 3));
  466. RTV_REG_SET(0x92, WR92 | (g_atLNA_TABLE[nidx][19] << 2)
  467. | ((g_atLNA_TABLE[nidx][26] & 0x06) >> 1));
  468. RTV_REG_SET(0x87, WR87 | ((g_atLNA_TABLE[nidx][26] & 0x01) << 2));
  469. RTV_REG_SET(0x93, WR93 | (g_atLNA_TABLE[nidx][23] << 2));
  470. RTV_REG_SET(0x94, WR94 | (g_atLNA_TABLE[nidx][27] << 2));
  471. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  472. if (rtvMTV23x_Get_Diversity_Current_path() == DIVERSITY_MASTER)
  473. g_nLnaTuneVal = nidx;
  474. else
  475. g_nLnaTuneVal_slave = nidx;
  476. #else
  477. g_nLnaTuneVal = nidx;
  478. #endif
  479. return RTV_SUCCESS;
  480. }
  481. static INT rtvRF_SetUpVCO(U32 dwLoFreq, U32 *dwPllfreq)
  482. {
  483. INT nRet = RTV_SUCCESS;
  484. UINT nVcoDivRate = 0;
  485. RTV_REG_MAP_SEL(RF_PAGE);
  486. if (dwLoFreq < 107500) {
  487. nVcoDivRate = 5;
  488. RTV_REG_MASK_SET(0x78, 0x0F, 0x0F);
  489. } else if (dwLoFreq >= 107500 && dwLoFreq < 215000) {
  490. nVcoDivRate = 4;
  491. RTV_REG_MASK_SET(0x78, 0x0F, 0x0E);
  492. } else if (dwLoFreq >= 215000 && dwLoFreq < 430000) {
  493. nVcoDivRate = 3;
  494. RTV_REG_MASK_SET(0x78, 0x0F, 0x0E);
  495. } else {
  496. nVcoDivRate = 2;
  497. RTV_REG_MASK_SET(0x78, 0x0F, 0x0D);
  498. }
  499. *dwPllfreq = dwLoFreq * (1<<nVcoDivRate);
  500. RTV_REG_MASK_SET(0x28, 0x03, ((nVcoDivRate & 0x06)>>1));
  501. RTV_REG_MASK_SET(0x29, 0x08, (nVcoDivRate & 0x01)<<3);
  502. if (*dwPllfreq >= 1720000 && *dwPllfreq < 1892000) {
  503. RTV_REG_MASK_SET(0x94, 0x02, 0x00);
  504. RTV_REG_MASK_SET(0x78, 0x70, 0x40);
  505. RTV_REG_MASK_SET(0xEA, 0x60, 0x00);
  506. } else if (*dwPllfreq >= 1892000 && *dwPllfreq < 3440000) {
  507. RTV_REG_MASK_SET(0x94, 0x02, 0x00);
  508. RTV_REG_MASK_SET(0x78, 0x70, 0x30);
  509. RTV_REG_MASK_SET(0xEA, 0x60, 0x00);
  510. } else
  511. nRet = RTV_INVAILD_FREQUENCY_RANGE;
  512. return nRet;
  513. }
  514. static INT rtvRF_SetOfdmPara(enum E_RTV_SERVICE_TYPE eServiceType,
  515. enum E_RTV_BANDWIDTH_TYPE eLpfBwType, U32 dwChFreqKHz)
  516. {
  517. INT nRet = RTV_SUCCESS;
  518. INT nNumAdcType = 0;
  519. const struct RTV_ADC_CFG_INFO *ptOfdmCfgTbl = NULL;
  520. switch (eServiceType) {
  521. #if defined(RTV_ISDBT_ENABLE)
  522. case RTV_SERVICE_UHF_ISDBT_1seg:
  523. nNumAdcType = 1; /* ADC 9MHz */
  524. switch (eLpfBwType) {
  525. case RTV_BW_MODE_6MHZ:
  526. case RTV_BW_MODE_430KHZ:
  527. if ((dwChFreqKHz == 485143) || (dwChFreqKHz == 503143)
  528. || (dwChFreqKHz == 539143) || (dwChFreqKHz == 647143)
  529. || (dwChFreqKHz == 665143) || (dwChFreqKHz == 683143)
  530. || (dwChFreqKHz == 755143))
  531. nNumAdcType = 0; /* ADC 8MHz */
  532. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_6MHz[nNumAdcType];
  533. break;
  534. case RTV_BW_MODE_7MHZ:
  535. case RTV_BW_MODE_500KHZ:
  536. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_7MHz[nNumAdcType];
  537. break;
  538. case RTV_BW_MODE_8MHZ:
  539. case RTV_BW_MODE_571KHZ:
  540. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_8MHz[nNumAdcType];
  541. break;
  542. default:
  543. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Unsupport 1seg BW\n");
  544. return RTV_INVAILD_SERVICE_TYPE;
  545. }
  546. break;
  547. case RTV_SERVICE_VHF_ISDBTmm_1seg:
  548. nNumAdcType = 0; /* ADC 8MHz */
  549. switch (eLpfBwType) {
  550. case RTV_BW_MODE_6MHZ:
  551. case RTV_BW_MODE_430KHZ:
  552. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_6MHz[nNumAdcType];
  553. break;
  554. default:
  555. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Unsupport Tmm1seg\n");
  556. return RTV_INVAILD_SERVICE_TYPE;
  557. }
  558. break;
  559. case RTV_SERVICE_VHF_ISDBTsb_1seg:
  560. nNumAdcType = 1; /* ADC 9MHz */
  561. switch (eLpfBwType) {
  562. case RTV_BW_MODE_6MHZ:
  563. case RTV_BW_MODE_430KHZ:
  564. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_6MHz[nNumAdcType];
  565. break;
  566. default:
  567. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Unsupport Tsb1seg\n");
  568. return RTV_INVAILD_SERVICE_TYPE;
  569. }
  570. break;
  571. case RTV_SERVICE_VHF_ISDBTsb_3seg:
  572. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Unsupport Tsb3seg\n");
  573. return RTV_INVAILD_SERVICE_TYPE;
  574. case RTV_SERVICE_VHF_ISDBTmm_13seg:
  575. nNumAdcType = 4; /* ADC 20.48MHz */
  576. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_6MHz[nNumAdcType];
  577. break;
  578. case RTV_SERVICE_UHF_ISDBT_13seg:
  579. if ((dwChFreqKHz == 551143) || (dwChFreqKHz == 581143) ||
  580. (dwChFreqKHz == 611143) || (dwChFreqKHz == 617143) ||
  581. (dwChFreqKHz == 647143) || (dwChFreqKHz == 677143) ||
  582. (dwChFreqKHz == 707143) || (dwChFreqKHz == 737143) ||
  583. (dwChFreqKHz == 767143) || (dwChFreqKHz == 797143))
  584. nNumAdcType = 2; /* ADC 19.2MHz */
  585. else if ((dwChFreqKHz == 491143) || (dwChFreqKHz == 521143))
  586. nNumAdcType = 3; /* ADC 20.0MHz */
  587. else
  588. nNumAdcType = 4; /* ADC 20.48MHz */
  589. switch (eLpfBwType) {
  590. case RTV_BW_MODE_6MHZ:
  591. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_6MHz[nNumAdcType];
  592. break;
  593. case RTV_BW_MODE_7MHZ:
  594. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_7MHz[nNumAdcType];
  595. break;
  596. case RTV_BW_MODE_8MHZ:
  597. ptOfdmCfgTbl = &g_atAdcCfgTbl_ISDBT_8MHz[nNumAdcType];
  598. break;
  599. default:
  600. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Unsupport 13seg\n");
  601. return RTV_INVAILD_SERVICE_TYPE;
  602. }
  603. break;
  604. #endif
  605. #if defined(RTV_DVBT_ENABLE)
  606. case RTV_SERVICE_DVBT:
  607. if ((dwChFreqKHz == 184500) || (dwChFreqKHz == 490000) ||
  608. (dwChFreqKHz == 554000) || (dwChFreqKHz == 618000) ||
  609. (dwChFreqKHz == 674000) || (dwChFreqKHz == 738000) ||
  610. (dwChFreqKHz == 858000))
  611. nNumAdcType = 2; /* ADC 19.2MHz */
  612. else
  613. nNumAdcType = 4; /* ADC 20.48MHz */
  614. switch (eLpfBwType) {
  615. case RTV_BW_MODE_5MHZ:
  616. ptOfdmCfgTbl = &g_atAdcCfgTbl_DVBT_5MHz[nNumAdcType];
  617. break;
  618. case RTV_BW_MODE_6MHZ:
  619. ptOfdmCfgTbl = &g_atAdcCfgTbl_DVBT_6MHz[nNumAdcType];
  620. break;
  621. case RTV_BW_MODE_7MHZ:
  622. ptOfdmCfgTbl = &g_atAdcCfgTbl_DVBT_7MHz[nNumAdcType];
  623. break;
  624. case RTV_BW_MODE_8MHZ:
  625. ptOfdmCfgTbl = &g_atAdcCfgTbl_DVBT_8MHz[nNumAdcType];
  626. break;
  627. default:
  628. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Unsupport DVB-T\n");
  629. return RTV_INVAILD_SERVICE_TYPE;
  630. }
  631. break;
  632. #endif
  633. default:
  634. RTV_DBGMSG0("[rtvRF_SetOfdmPara] Invaild Service Type\n");
  635. return RTV_INVAILD_SERVICE_TYPE;
  636. }
  637. RTV_REG_MAP_SEL(RF_PAGE);
  638. RTV_REG_SET(0x2A, ptOfdmCfgTbl->bData2A);
  639. RTV_REG_SET(0x6E, ptOfdmCfgTbl->bData6E);
  640. RTV_REG_SET(0x70, ptOfdmCfgTbl->bData70);
  641. RTV_REG_SET(0x71, ptOfdmCfgTbl->bData71);
  642. RTV_REG_MASK_SET(0x75, 0xFC, (ptOfdmCfgTbl->bData75 << 2));
  643. if (rtvRF_LockCheck(1) != RTV_SUCCESS)
  644. return RTV_ADC_CLK_UNLOCKED;
  645. if ((eServiceType == RTV_SERVICE_UHF_ISDBT_1seg) ||
  646. (eServiceType == RTV_SERVICE_VHF_ISDBTmm_1seg) ||
  647. (eServiceType == RTV_SERVICE_VHF_ISDBTsb_1seg) ||
  648. (eServiceType == RTV_SERVICE_VHF_ISDBTsb_3seg)) {
  649. RTV_REG_MAP_SEL(LPOFDM_PAGE);
  650. RTV_REG_SET(0x14, (U8)((ptOfdmCfgTbl->dwTNCO >> 0) & 0xFF));
  651. RTV_REG_SET(0x15, (U8)((ptOfdmCfgTbl->dwTNCO >> 8) & 0xFF));
  652. RTV_REG_SET(0x16, (U8)((ptOfdmCfgTbl->dwTNCO >> 16) & 0xFF));
  653. RTV_REG_SET(0x17, (U8)((ptOfdmCfgTbl->dwTNCO >> 24) & 0xFF));
  654. RTV_REG_SET(0x18, (U8)((ptOfdmCfgTbl->dwPNCO >> 0) & 0xFF));
  655. RTV_REG_SET(0x19, (U8)((ptOfdmCfgTbl->dwPNCO >> 8) & 0xFF));
  656. RTV_REG_SET(0x1A, (U8)((ptOfdmCfgTbl->dwPNCO >> 16) & 0xFF));
  657. RTV_REG_SET(0x1B, (U8)((ptOfdmCfgTbl->dwPNCO >> 24) & 0xFF));
  658. RTV_REG_SET(0x1C, (U8)((ptOfdmCfgTbl->dwGAIN) & 0xFF));
  659. RTV_REG_SET(0x1D, (U8)((ptOfdmCfgTbl->dwCFREQGAIN>>0) & 0xFF));
  660. RTV_REG_SET(0x1E, (U8)((ptOfdmCfgTbl->dwCFREQGAIN>>8) & 0xFF));
  661. RTV_REG_SET(0x1F, (U8)((ptOfdmCfgTbl->dwCFREQGAIN>>16) & 0xFF));
  662. } else {
  663. RTV_REG_MAP_SEL(OFDM_PAGE);
  664. switch (eLpfBwType) {
  665. case RTV_BW_MODE_5MHZ:
  666. RTV_REG_MASK_SET(0x11, 0x01, 0x00);
  667. RTV_REG_MASK_SET(0x10, 0xE0, 0xB0);
  668. RTV_REG_MASK_SET(0x1F, 0xC0, 0xC0);
  669. break;
  670. case RTV_BW_MODE_6MHZ:
  671. RTV_REG_MASK_SET(0x11, 0x01, 0x00);
  672. RTV_REG_MASK_SET(0x10, 0xE0, 0xC0);
  673. RTV_REG_MASK_SET(0x1F, 0xC0, 0x80);
  674. break;
  675. case RTV_BW_MODE_7MHZ:
  676. RTV_REG_MASK_SET(0x11, 0x01, 0x00);
  677. RTV_REG_MASK_SET(0x10, 0xE0, 0xE0);
  678. RTV_REG_MASK_SET(0x1F, 0xC0, 0x40);
  679. break;
  680. case RTV_BW_MODE_8MHZ:
  681. RTV_REG_MASK_SET(0x11, 0x01, 0x01);
  682. RTV_REG_MASK_SET(0x10, 0xE0, 0x00);
  683. RTV_REG_MASK_SET(0x1F, 0xC0, 0x00);
  684. break;
  685. default:
  686. RTV_DBGMSG0("[rtvRF_SetFrequency] Unsupported BW\n");
  687. return RTV_INVAILD_SERVICE_TYPE;
  688. break;
  689. }
  690. RTV_REG_SET(0x34, (U8)((ptOfdmCfgTbl->dwTNCO>>0) & 0xFF));
  691. RTV_REG_SET(0x35, (U8)((ptOfdmCfgTbl->dwTNCO>>8) & 0xFF));
  692. RTV_REG_SET(0x36, (U8)((ptOfdmCfgTbl->dwTNCO>>16) & 0xFF));
  693. RTV_REG_SET(0x37, (U8)((ptOfdmCfgTbl->dwTNCO>>24) & 0xFF));
  694. RTV_REG_SET(0x38, (U8) (ptOfdmCfgTbl->dwPNCO>>0));
  695. RTV_REG_SET(0x39, (U8) (ptOfdmCfgTbl->dwPNCO>>8));
  696. RTV_REG_SET(0x3A, (U8) (ptOfdmCfgTbl->dwPNCO>>16));
  697. RTV_REG_SET(0x3B, (U8) (ptOfdmCfgTbl->dwPNCO>>24));
  698. RTV_REG_SET(0x3D, (U8)((ptOfdmCfgTbl->dwCFREQGAIN>>0) & 0xFF));
  699. RTV_REG_SET(0x3E, (U8)((ptOfdmCfgTbl->dwCFREQGAIN>>8) & 0xFF));
  700. RTV_REG_SET(0x3F, (U8)((ptOfdmCfgTbl->dwCFREQGAIN>>16) & 0xFF));
  701. RTV_REG_MASK_SET(0x55, 0xC0, (ptOfdmCfgTbl->dwGAIN & 0x03));
  702. RTV_REG_SET(0x56, (ptOfdmCfgTbl->dwGAIN>>2) & 0xFF);
  703. }
  704. return nRet;
  705. }
  706. static INT rtvRF_SelectService(enum E_RTV_SERVICE_TYPE eServiceType)
  707. {
  708. UINT nRet = RTV_SUCCESS;
  709. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  710. if (rtvMTV23x_Get_Diversity_Current_path() == DIVERSITY_MASTER) {
  711. if (g_eRtvServiceType == eServiceType)
  712. return RTV_SUCCESS;
  713. } else {
  714. if (g_eRtvServiceType_slave == eServiceType)
  715. return RTV_SUCCESS;
  716. }
  717. #else
  718. if (g_eRtvServiceType == eServiceType)
  719. return RTV_SUCCESS;
  720. #endif
  721. rtv_ServiceTypeSelect(eServiceType);
  722. RTV_REG_MAP_SEL(RF_PAGE);
  723. switch (eServiceType) {
  724. case RTV_SERVICE_UHF_ISDBT_1seg:
  725. RTV_REG_SET(0x49, 0x21);
  726. RTV_REG_SET(0x4A, 0x60);
  727. RTV_REG_SET(0x4B, 0x50);
  728. RTV_REG_SET(0x5E, 0x70);
  729. RTV_REG_SET(0x5F, 0x75);
  730. break;
  731. case RTV_SERVICE_VHF_ISDBTmm_1seg:
  732. RTV_REG_SET(0x49, 0x21);
  733. RTV_REG_SET(0x4A, 0x30);
  734. RTV_REG_SET(0x4B, 0x20);
  735. RTV_REG_SET(0x5E, 0x70);
  736. RTV_REG_SET(0x5F, 0x75);
  737. break;
  738. case RTV_SERVICE_VHF_ISDBTsb_1seg:
  739. RTV_REG_SET(0x49, 0x21);
  740. RTV_REG_SET(0x4A, 0x60);
  741. RTV_REG_SET(0x4B, 0x50);
  742. RTV_REG_SET(0x5E, 0x70);
  743. RTV_REG_SET(0x5F, 0x75);
  744. break;
  745. case RTV_SERVICE_VHF_ISDBTsb_3seg:
  746. RTV_DBGMSG0("[rtvRF_SelectService] Unsupported 3seg\n");
  747. break;
  748. case RTV_SERVICE_UHF_ISDBT_13seg:
  749. RTV_REG_SET(0x49, 0x41);
  750. RTV_REG_SET(0x4A, 0x70);
  751. RTV_REG_SET(0x4B, 0x65);
  752. RTV_REG_SET(0x5E, 0x70);
  753. RTV_REG_SET(0x5F, 0x75);
  754. break;
  755. case RTV_SERVICE_VHF_ISDBTmm_13seg:
  756. RTV_REG_SET(0x49, 0x41);
  757. RTV_REG_SET(0x4A, 0x70);
  758. RTV_REG_SET(0x4B, 0x65);
  759. RTV_REG_SET(0x5E, 0x70);
  760. RTV_REG_SET(0x5F, 0x75);
  761. break;
  762. #if defined(RTV_DVBT_ENABLE)
  763. case RTV_SERVICE_DVBT:
  764. RTV_REG_SET(0x49, 0x41);
  765. RTV_REG_SET(0x4A, 0x70);
  766. RTV_REG_SET(0x4B, 0x65);
  767. RTV_REG_SET(0x5E, 0x70);
  768. RTV_REG_SET(0x5F, 0x75);
  769. break;
  770. #endif
  771. default:
  772. nRet = RTV_INVAILD_SERVICE_TYPE;
  773. }
  774. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  775. if (rtvMTV23x_Get_Diversity_Current_path() == DIVERSITY_MASTER)
  776. g_eRtvServiceType = eServiceType;
  777. else
  778. g_eRtvServiceType_slave = eServiceType;
  779. #else
  780. g_eRtvServiceType = eServiceType;
  781. #endif
  782. return nRet;
  783. }
  784. INT rtvRF_SetFrequency(enum E_RTV_SERVICE_TYPE eServiceType,
  785. enum E_RTV_BANDWIDTH_TYPE eLpfBwType, U32 dwChFreqKHz)
  786. {
  787. INT nRet;
  788. U8 pllf_mul = 0, r_div = 4;
  789. U32 dwPLLN = 0, dwPLLF = 0, dwPLLNF = 0;
  790. U32 dwPllFreq = 0, dwLoFreq = 0;
  791. if (rtvRF_ChangeLpfBwType(eLpfBwType) != RTV_SUCCESS)
  792. return RTV_ADC_CLK_UNLOCKED;
  793. nRet = rtvRF_SetOfdmPara(eServiceType, eLpfBwType, dwChFreqKHz);
  794. if (nRet != RTV_SUCCESS)
  795. return nRet;
  796. nRet = rtvRF_SelectService(eServiceType);
  797. if (nRet != RTV_SUCCESS)
  798. return nRet;
  799. if (g_fRtv1segLpMode) {
  800. RTV_REG_MAP_SEL(LPOFDM_PAGE);
  801. if (eServiceType == RTV_SERVICE_VHF_ISDBTmm_1seg) {
  802. RTV_REG_SET(0x10, 0xFA);
  803. dwLoFreq = dwChFreqKHz - 857;
  804. } else {
  805. RTV_REG_SET(0x10, 0xF8);
  806. dwLoFreq = dwChFreqKHz + 857;
  807. }
  808. } else
  809. dwLoFreq = dwChFreqKHz;
  810. if (rtvRF_Lna_Tuning(dwLoFreq) != RTV_SUCCESS)
  811. return RTV_ERROR_LNATUNE;
  812. if (rtvRF_SetUpVCO(dwLoFreq, &dwPllFreq) != RTV_SUCCESS)
  813. return RTV_INVAILD_FREQUENCY_RANGE;
  814. dwPLLN = dwPllFreq / RTV_SRC_CLK_FREQ_KHz;
  815. dwPLLF = dwPllFreq - (dwPLLN * RTV_SRC_CLK_FREQ_KHz);
  816. if (RTV_SRC_CLK_FREQ_KHz == 13000 || RTV_SRC_CLK_FREQ_KHz == 27000) {
  817. pllf_mul = 1;
  818. r_div = 3;
  819. }
  820. dwPLLNF = (dwPLLN<<20)
  821. + (((dwPLLF<<16) / (RTV_SRC_CLK_FREQ_KHz>>r_div)) << pllf_mul);
  822. RTV_REG_MAP_SEL(RF_PAGE);
  823. RTV_REG_SET(0x20, ((dwPLLNF>>22)&0xFF));
  824. RTV_REG_SET(0x21, ((dwPLLNF>>14)&0xFF));
  825. RTV_REG_MASK_SET(0x28, 0xFC, ((dwPLLNF&0x3F)<<2));
  826. RTV_REG_SET(0x22, ((dwPLLNF>>6)&0xFF));
  827. RTV_DELAY_MS(1);
  828. if (rtvRF_LockCheck(0) != RTV_SUCCESS)
  829. return RTV_PLL_UNLOCKED;
  830. if (dwPllFreq >= 2140000 && dwPllFreq < 2950000) {
  831. RTV_REG_MASK_SET(0x94, 0x02, 0x02);
  832. RTV_REG_MASK_SET(0x78, 0x70, 0x50);
  833. RTV_REG_MASK_SET(0xEA, 0x60, 0x40);
  834. } else if (dwPllFreq >= 2950000 && dwPllFreq < 3440000) {
  835. RTV_REG_MASK_SET(0x94, 0x02, 0x02);
  836. RTV_REG_MASK_SET(0x78, 0x70, 0x40);
  837. RTV_REG_MASK_SET(0xEA, 0x60, 0x00);
  838. }
  839. g_dwRtvPrevChFreqKHz = dwChFreqKHz;
  840. return RTV_SUCCESS;
  841. }
  842. INT rtvRF_Initilize(enum E_RTV_BANDWIDTH_TYPE eBandwidthType)
  843. {
  844. UINT nNumTblEntry = 0;
  845. const struct RTV_REG_INIT_INFO *ptInitTbl = NULL;
  846. ptInitTbl = t_mtv23x_INIT;
  847. nNumTblEntry = sizeof(t_mtv23x_INIT) / sizeof(struct RTV_REG_INIT_INFO);
  848. g_aeBwType = MAX_NUM_RTV_BW_MODE_TYPE;
  849. g_nLnaTuneVal = 0xFF;
  850. g_dwRtvPrevChFreqKHz = 0;
  851. #ifdef RTV_DUAL_DIVERISTY_ENABLE
  852. g_aeBwType_slave = MAX_NUM_RTV_BW_MODE_TYPE;
  853. g_nLnaTuneVal_slave = 0xFF;
  854. #endif
  855. RTV_REG_MAP_SEL(RF_PAGE);
  856. do {
  857. RTV_REG_SET(ptInitTbl->bReg, ptInitTbl->bVal);
  858. ptInitTbl++;
  859. } while (--nNumTblEntry);
  860. #ifdef DEBUG_A_TEST_ZERO
  861. RTV_REG_MASK_SET(0x85, 0x02, 0x02);
  862. #endif
  863. if (rtvRF_ChangeLpfBwType(eBandwidthType) != RTV_SUCCESS)
  864. return RTV_ADC_CLK_UNLOCKED;
  865. return RTV_SUCCESS;
  866. }