fc8300_es2_tun.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fc8300_es2_tun.c
  4. Description : source of FC8300 tuner driver
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. History :
  17. ----------------------------------------------------------------------
  18. 0p1 -> initial driver
  19. 0p2 -> VCO Currunt Setting Add
  20. 1p2 -> 20130826
  21. 1p0 -> 20130730
  22. 1p1 -> 20130812
  23. 1p4 -> 20130821
  24. 1p5 -> 20130826
  25. 1p6 -> 20130827
  26. 1p7 -> 20130830
  27. 1p8 -> 20130902
  28. 2p1 -> 20130911
  29. 2p5 -> 20131108
  30. *******************************************************************************/
  31. #include "fci_types.h"
  32. #include "fci_oal.h"
  33. #include "fci_tun.h"
  34. #include "fci_hal.h"
  35. #include "fc8300_regs.h"
  36. #include "fc8300_es2_tun.h"
  37. #define DRIVER_VERSION 0x25 /* Driver M2_V2p5*/
  38. #define RFADC_Count 3
  39. #define Cal_Repeat 1
  40. #define FC8300_XTAL_FREQ BBM_XTAL_FREQ
  41. #define FC8300_BAND_WIDTH BBM_BAND_WIDTH
  42. static enum BROADCAST_TYPE broadcast_type = ISDBT_13SEG;
  43. static u8 catv_status;
  44. static u8 broad_check;
  45. /* RF_Driver */
  46. static u32 thread_freq[4] = {707143, 707143, 707143, 707143};
  47. static u32 bc_type[4] = {0, 0, 0, 0};
  48. static u8 device_set;
  49. static u8 thread_set;
  50. static u8 thread_check;
  51. static u8 fc_cal_value[4] = {0, 0, 0, 0};
  52. static u8 status_1seg[4] = {0, 0, 0, 0};
  53. static s8 status_13seg[4] = {0, 0, 0, 0};
  54. static HANDLE t_handle;
  55. static DEVICEID t_devid[4] = {DIV_MASTER, DIV_SLAVE0, DIV_SLAVE1, DIV_SLAVE2};
  56. static s32 fc8300_write(HANDLE handle, DEVICEID devid, u8 addr, u8 data)
  57. {
  58. s32 res;
  59. res = tuner_i2c_write(handle, devid, addr, 1, &data, 1);
  60. return res;
  61. }
  62. static s32 fc8300_read(HANDLE handle, DEVICEID devid, u8 addr, u8 *data)
  63. {
  64. s32 res;
  65. res = tuner_i2c_read(handle, devid, addr, 1, data, 1);
  66. return res;
  67. }
  68. #if 0
  69. static s32 fc8300_bb_write(HANDLE handle, DEVICEID devid, u16 addr, u8 data)
  70. {
  71. s32 res;
  72. res = bbm_write(handle, devid, addr, data);
  73. return res;
  74. }
  75. static s32 fc8300_bb_read(HANDLE handle, DEVICEID devid, u16 addr, u8 *data)
  76. {
  77. s32 res;
  78. res = bbm_read(handle, devid, addr, data);
  79. return res;
  80. }
  81. #endif
  82. #ifdef BBM_ES_CURRENT
  83. static u32 KbdFunc()
  84. {
  85. s32 res = BBM_OK;
  86. s32 i = 0;
  87. u8 up_low_limit = 182;
  88. u8 up_high_limit = 217;
  89. u8 down_low_limit = 177;
  90. u8 down_high_limit = 212;
  91. u8 rssi_buf[4] = {0, 0, 0, 0};
  92. u8 min = 0;
  93. u8 max = 0;
  94. u8 check_thread;
  95. u8 rssi_buff[4][5] = {
  96. {0, 0, 0, 0, 0},
  97. {0, 0, 0, 0, 0},
  98. {0, 0, 0, 0, 0},
  99. {0, 0, 0, 0, 0}
  100. };
  101. u8 lna_temp;
  102. u8 atten_temp;
  103. u8 filter_temp;
  104. u8 lna_set = 0x44;
  105. u8 lna_set1 = 0x44;
  106. u8 lna_set2 = 0x46;
  107. u8 lna_set3 = 0x47;
  108. while (thread_set) {
  109. fc8300_read(t_handle, t_devid[0], 0xfa, &check_thread);
  110. if (check_thread != 0) {
  111. fc8300_write(t_handle, t_devid[0], 0xfa, 0xee);
  112. thread_set = 0;
  113. _endthread();
  114. }
  115. if ((device_set & 0x01) == 1) {
  116. if (bc_type[0] == ISDBT_13SEG) {
  117. lna_set = 0x46;
  118. fc8300_read(t_handle, t_devid[0], 0xeb,
  119. &rssi_buff[0][0]);
  120. fc8300_read(t_handle, t_devid[0], 0xeb,
  121. &rssi_buff[0][1]);
  122. fc8300_read(t_handle, t_devid[0], 0xeb,
  123. &rssi_buff[0][2]);
  124. fc8300_read(t_handle, t_devid[0], 0xeb,
  125. &rssi_buff[0][3]);
  126. fc8300_read(t_handle, t_devid[0], 0xeb,
  127. &rssi_buff[0][4]);
  128. for (i = 0; i < 4; i++) {
  129. if (rssi_buff[0][max] >
  130. rssi_buff[0][i+1])
  131. max = i + 1;
  132. }
  133. for (i = 0; i < 4; i++) {
  134. if (rssi_buff[0][min] <
  135. rssi_buff[0][i+1])
  136. min = i + 1;
  137. }
  138. rssi_buff[0][min] = 0;
  139. rssi_buff[0][max] = 0;
  140. rssi_buf[0] = (rssi_buff[0][0] +
  141. rssi_buff[0][1] +
  142. rssi_buff[0][2] +
  143. rssi_buff[0][3] +
  144. rssi_buff[0][4]) / 3;
  145. /*status_13seg[0] 1 => Buff ON*/
  146. /*status_13seg[0] 0 => Buff OFF*/
  147. if (thread_freq[0] >= 647143) {
  148. if (status_13seg[0] == 0) {
  149. if (rssi_buf[0] > up_low_limit
  150. && rssi_buf[0] <
  151. down_high_limit) {
  152. fc8300_write(
  153. t_handle,
  154. t_devid[0],
  155. 0x03, 0x00);
  156. status_13seg[0]
  157. = 1;
  158. }
  159. } else if (status_13seg[0] == 1) {
  160. if (rssi_buf[0] <
  161. down_low_limit ||
  162. rssi_buf[0] >
  163. up_high_limit) {
  164. fc8300_write(
  165. t_handle,
  166. t_devid[0],
  167. 0x03, 0x04);
  168. status_13seg[0]
  169. = 0;
  170. }
  171. }
  172. } else if (thread_freq[0] < 647143 &&
  173. status_13seg[0] == 1) {
  174. fc8300_write(t_handle, t_devid[0],
  175. 0x03, 0x04);
  176. status_13seg[0] = 0;
  177. }
  178. }
  179. if (bc_type[0] == ISDBT_1SEG) {
  180. if (thread_freq[0] < 590000)
  181. lna_set = lna_set3;
  182. else
  183. lna_set = lna_set2;
  184. }
  185. fc8300_read(t_handle, t_devid[0], 0x95, &lna_temp);
  186. fc8300_read(t_handle, t_devid[0], 0x96, &atten_temp);
  187. fc8300_read(t_handle, t_devid[0], 0xd2, &filter_temp);
  188. lna_temp = lna_temp & 0x0f;
  189. atten_temp = atten_temp & 0x0f;
  190. if (filter_temp >= 9) {
  191. if (status_1seg[0] == 0) {
  192. fc8300_write(t_handle, t_devid[0],
  193. 0x15, 0x44);
  194. status_1seg[0] = 1;
  195. }
  196. } else if (filter_temp < 9) {
  197. if ((atten_temp >= 1) || (lna_temp >= 1)) {
  198. if (status_1seg[0] == 1) {
  199. fc8300_write(t_handle,
  200. t_devid[0],
  201. 0x15, lna_set);
  202. status_1seg[0] = 0;
  203. }
  204. } else {
  205. if (status_1seg[0] == 0) {
  206. fc8300_write(t_handle,
  207. t_devid[0], 0x15, 0x44);
  208. status_1seg[0] = 1;
  209. }
  210. }
  211. }
  212. /*
  213. if (lna_temp >= 1) {
  214. if ((filter_temp < 9) && (status_15[0] != 1)) {
  215. fc8300_write(t_handle, t_devid[0],
  216. 0x15, lna_set);
  217. status_15[0] = 1;
  218. } else if ((filter_temp >= 9) &&
  219. (status_15[0] != 2)) {
  220. fc8300_write(t_handle, t_devid[0],
  221. 0x15, 0x41);
  222. status_15[0] = 2;
  223. }
  224. }
  225. */
  226. }
  227. if ((device_set & 0x02) == 2) {
  228. if (bc_type[1] == ISDBT_13SEG) {
  229. lna_set = 0x46;
  230. fc8300_read(t_handle, t_devid[1], 0xeb,
  231. &rssi_buff[1][0]);
  232. fc8300_read(t_handle, t_devid[1], 0xeb,
  233. &rssi_buff[1][1]);
  234. fc8300_read(t_handle, t_devid[1], 0xeb,
  235. &rssi_buff[1][2]);
  236. fc8300_read(t_handle, t_devid[1], 0xeb,
  237. &rssi_buff[1][3]);
  238. fc8300_read(t_handle, t_devid[1], 0xeb,
  239. &rssi_buff[1][4]);
  240. for (i = 0; i < 4; i++) {
  241. if (rssi_buff[1][max] >
  242. rssi_buff[1][i+1])
  243. max = i + 1;
  244. }
  245. for (i = 0; i < 4; i++) {
  246. if (rssi_buff[1][min] <
  247. rssi_buff[1][i+1])
  248. min = i + 1;
  249. }
  250. rssi_buff[1][min] = 0;
  251. rssi_buff[1][max] = 0;
  252. rssi_buf[1] = (rssi_buff[1][0] +
  253. rssi_buff[1][1] +
  254. rssi_buff[1][2] +
  255. rssi_buff[1][3] +
  256. rssi_buff[1][4]) / 3;
  257. /*status_13seg[1] 1 => Buff ON*/
  258. /*status_13seg[1] 0 => Buff OFF*/
  259. if (thread_freq[1] >= 647143) {
  260. if (status_13seg[1] == 0) {
  261. if (rssi_buf[1] >
  262. up_low_limit &&
  263. rssi_buf[1] <
  264. down_high_limit) {
  265. fc8300_write(
  266. t_handle,
  267. t_devid[1],
  268. 0x03, 0x00);
  269. status_13seg[1] = 1;
  270. }
  271. } else if (status_13seg[1] == 1) {
  272. if (rssi_buf[1] <
  273. down_low_limit ||
  274. rssi_buf[1] >
  275. up_high_limit) {
  276. fc8300_write(t_handle,
  277. t_devid[1],
  278. 0x03, 0x04);
  279. status_13seg[1] = 0;
  280. }
  281. }
  282. } else if (thread_freq[1] < 647143 &&
  283. status_13seg[1] == 1) {
  284. fc8300_write(t_handle, t_devid[1],
  285. 0x03, 0x04);
  286. status_13seg[1] = 0;
  287. }
  288. }
  289. if (bc_type[1] == ISDBT_1SEG) {
  290. if (thread_freq[1] < 590000)
  291. lna_set = lna_set3;
  292. else
  293. lna_set = lna_set1;
  294. }
  295. fc8300_read(t_handle, t_devid[1], 0x95, &lna_temp);
  296. fc8300_read(t_handle, t_devid[1], 0x96, &atten_temp);
  297. fc8300_read(t_handle, t_devid[1], 0xd2, &filter_temp);
  298. lna_temp = lna_temp & 0x0f;
  299. atten_temp = atten_temp & 0x0f;
  300. if (filter_temp >= 9) {
  301. if (status_1seg[1] == 0) {
  302. fc8300_write(t_handle, t_devid[1],
  303. 0x15, 0x44);
  304. status_1seg[1] = 1;
  305. }
  306. } else if (filter_temp < 9) {
  307. if ((atten_temp >= 1) || (lna_temp >= 1)) {
  308. if (status_1seg[1] == 1) {
  309. fc8300_write(t_handle,
  310. t_devid[1],
  311. 0x15, lna_set);
  312. status_1seg[1] = 0;
  313. }
  314. } else {
  315. if (status_1seg[1] == 0) {
  316. fc8300_write(t_handle,
  317. t_devid[1],
  318. 0x15, 0x44);
  319. status_1seg[1] = 1;
  320. }
  321. }
  322. }
  323. }
  324. if ((device_set & 0x04) == 4) {
  325. if (bc_type[2] == ISDBT_13SEG) {
  326. lna_set = 0x46;
  327. fc8300_read(t_handle, t_devid[2], 0xeb,
  328. &rssi_buff[2][0]);
  329. fc8300_read(t_handle, t_devid[2], 0xeb,
  330. &rssi_buff[2][1]);
  331. fc8300_read(t_handle, t_devid[2], 0xeb,
  332. &rssi_buff[2][2]);
  333. fc8300_read(t_handle, t_devid[2], 0xeb,
  334. &rssi_buff[2][3]);
  335. fc8300_read(t_handle, t_devid[2], 0xeb,
  336. &rssi_buff[2][4]);
  337. for (i = 0; i < 4; i++) {
  338. if (rssi_buff[2][max] >
  339. rssi_buff[2][i+1])
  340. max = i + 1;
  341. }
  342. for (i = 0; i < 4; i++) {
  343. if (rssi_buff[2][min] <
  344. rssi_buff[2][i+1])
  345. min = i + 1;
  346. }
  347. rssi_buff[2][min] = 0;
  348. rssi_buff[2][max] = 0;
  349. rssi_buf[2] = (rssi_buff[2][0] +
  350. rssi_buff[2][1] +
  351. rssi_buff[2][2] +
  352. rssi_buff[2][3] +
  353. rssi_buff[2][4]) / 3;
  354. /*status_13seg[2] 1 => Buff ON*/
  355. /*status_13seg[2] 0 => Buff OFF*/
  356. if (thread_freq[2] >= 647143) {
  357. if (status_13seg[2] == 0) {
  358. if (rssi_buf[2] > up_low_limit
  359. && rssi_buf[2] <
  360. down_high_limit) {
  361. fc8300_write(
  362. t_handle,
  363. t_devid[2],
  364. 0x03, 0x00);
  365. status_13seg[2]
  366. = 1;
  367. }
  368. } else if (status_13seg[2] == 1) {
  369. if (rssi_buf[2] <
  370. down_low_limit ||
  371. rssi_buf[2] >
  372. up_high_limit) {
  373. fc8300_write(
  374. t_handle,
  375. t_devid[2],
  376. 0x03, 0x04);
  377. status_13seg[2]
  378. = 0;
  379. }
  380. }
  381. } else if (thread_freq[2] < 647143 &&
  382. status_13seg[2] == 1) {
  383. fc8300_write(t_handle, t_devid[2],
  384. 0x03, 0x04);
  385. status_13seg[2] = 0;
  386. }
  387. }
  388. if (bc_type[2] == ISDBT_1SEG) {
  389. if (thread_freq[2] < 590000)
  390. lna_set = lna_set3;
  391. else
  392. lna_set = lna_set1;
  393. }
  394. fc8300_read(t_handle, t_devid[2], 0x95, &lna_temp);
  395. fc8300_read(t_handle, t_devid[2], 0x96, &atten_temp);
  396. fc8300_read(t_handle, t_devid[2], 0xd2, &filter_temp);
  397. lna_temp = lna_temp & 0x0f;
  398. atten_temp = atten_temp & 0x0f;
  399. if (filter_temp >= 9) {
  400. if (status_1seg[2] == 0) {
  401. fc8300_write(t_handle, t_devid[2],
  402. 0x15, 0x44);
  403. status_1seg[2] = 1;
  404. }
  405. } else if (filter_temp < 9) {
  406. if ((atten_temp >= 1) || (lna_temp >= 1)) {
  407. if (status_1seg[2] == 1) {
  408. fc8300_write(t_handle,
  409. t_devid[2], 0x15,
  410. lna_set);
  411. status_1seg[2] = 0;
  412. }
  413. } else {
  414. if (status_1seg[2] == 0) {
  415. fc8300_write(t_handle,
  416. t_devid[2],
  417. 0x15, 0x44);
  418. status_1seg[2] = 1;
  419. }
  420. }
  421. }
  422. }
  423. if ((device_set & 0x08) == 8) {
  424. if (bc_type[3] == ISDBT_13SEG) {
  425. lna_set = 0x46;
  426. fc8300_read(t_handle, t_devid[3], 0xeb,
  427. &rssi_buff[3][0]);
  428. fc8300_read(t_handle, t_devid[3], 0xeb,
  429. &rssi_buff[3][1]);
  430. fc8300_read(t_handle, t_devid[3], 0xeb,
  431. &rssi_buff[3][2]);
  432. fc8300_read(t_handle, t_devid[3], 0xeb,
  433. &rssi_buff[3][3]);
  434. fc8300_read(t_handle, t_devid[3], 0xeb,
  435. &rssi_buff[3][4]);
  436. for (i = 0; i < 4; i++) {
  437. if (rssi_buff[3][max] >
  438. rssi_buff[3][i+1])
  439. max = i + 1;
  440. }
  441. for (i = 0; i < 4; i++) {
  442. if (rssi_buff[3][min] <
  443. rssi_buff[3][i+1])
  444. min = i + 1;
  445. }
  446. rssi_buff[3][min] = 0;
  447. rssi_buff[3][max] = 0;
  448. rssi_buf[3] = (rssi_buff[3][0] +
  449. rssi_buff[3][1] +
  450. rssi_buff[3][2] +
  451. rssi_buff[3][3] +
  452. rssi_buff[3][4]) / 3;
  453. /*status_13seg[3] 1 => Buff ON*/
  454. /*status_13seg[3] 0 => Buff OFF*/
  455. if (thread_freq[3] >= 647143) {
  456. if (status_13seg[3] == 0) {
  457. if (rssi_buf[3] > up_low_limit
  458. && rssi_buf[3] <
  459. down_high_limit) {
  460. fc8300_write(
  461. t_handle,
  462. t_devid[3],
  463. 0x03, 0x00);
  464. status_13seg[3]
  465. = 1;
  466. }
  467. } else if (status_13seg[3] == 1) {
  468. if (rssi_buf[3] <
  469. down_low_limit ||
  470. rssi_buf[3] >
  471. up_high_limit) {
  472. fc8300_write(
  473. t_handle,
  474. t_devid[3],
  475. 0x03, 0x04);
  476. status_13seg[3]
  477. = 0;
  478. }
  479. }
  480. } else if (thread_freq[3] < 647143 &&
  481. status_13seg[3] == 1) {
  482. fc8300_write(t_handle, t_devid[3],
  483. 0x03, 0x04);
  484. status_13seg[3] = 0;
  485. }
  486. }
  487. if (bc_type[3] == ISDBT_1SEG) {
  488. if (thread_freq[3] < 590000)
  489. lna_set = lna_set3;
  490. else
  491. lna_set = lna_set1;
  492. }
  493. fc8300_read(t_handle, t_devid[3], 0x95, &lna_temp);
  494. fc8300_read(t_handle, t_devid[3], 0x96, &atten_temp);
  495. fc8300_read(t_handle, t_devid[3], 0xd2, &filter_temp);
  496. lna_temp = lna_temp & 0x0f;
  497. atten_temp = atten_temp & 0x0f;
  498. if (filter_temp >= 9) {
  499. if (status_1seg[3] == 0) {
  500. fc8300_write(t_handle, t_devid[3],
  501. 0x15, 0x44);
  502. status_1seg[3] = 1;
  503. }
  504. } else if (filter_temp < 9) {
  505. if ((atten_temp >= 1) || (lna_temp >= 1)) {
  506. if (status_1seg[3] == 1) {
  507. fc8300_write(t_handle,
  508. t_devid[3], 0x15,
  509. lna_set);
  510. status_1seg[3] = 0;
  511. }
  512. } else {
  513. if (status_1seg[3] == 0) {
  514. fc8300_write(t_handle,
  515. t_devid[3],
  516. 0x15, 0x44);
  517. status_1seg[3] = 1;
  518. }
  519. }
  520. }
  521. }
  522. msWait(300);
  523. }
  524. fc8300_write(t_handle, t_devid[0], 0xfa, 0xcc);
  525. _endthread();
  526. return BBM_OK;
  527. }
  528. #endif
  529. static u8 tf_cal(HANDLE handle, DEVICEID devid)
  530. {
  531. u8 rfadc[RFADC_Count];
  532. u32 rfadc_avg = 0;
  533. u8 max_cb_code[Cal_Repeat] = {0};
  534. u8 max_rfadc[Cal_Repeat] = {0};
  535. u8 cal_temp;
  536. u32 x, i, j;
  537. for (x = 0; x < Cal_Repeat; x++) {
  538. for (i = 3; i < 12; i++) {
  539. cal_temp = (16 + i);
  540. fc8300_write(handle, devid, 0x1c, cal_temp);
  541. rfadc_avg = 0;
  542. for (j = 0; j < RFADC_Count; j++) {
  543. fc8300_read(handle, devid, 0xf5, &rfadc[j]);
  544. rfadc_avg = rfadc_avg + rfadc[j];
  545. }
  546. rfadc_avg = rfadc_avg / RFADC_Count;
  547. if (max_rfadc[x] < rfadc_avg) {
  548. max_rfadc[x] = (u8)rfadc_avg;
  549. max_cb_code[x] = (16 + i);
  550. }
  551. }
  552. }
  553. return max_cb_code[0];
  554. }
  555. static s32 fc8300_tuner_set_pll(HANDLE handle, DEVICEID devid, u32 freq,
  556. u32 offset)
  557. {
  558. u8 data_0x51, data_0x57, lo_select, lo_div;
  559. u32 f_diff, f_diff_shifted, n_val, k_val;
  560. u32 f_vco, f_comp, f_lo_kHz;
  561. u32 f_vco_max = 6200000;
  562. u8 lo_divide_ratio[8] = {8, 12, 16, 24, 32, 48, 64, 96};
  563. u32 r_val;
  564. u8 pre_shift_bits = 4;
  565. u8 lock_detect = 0;
  566. u8 i;
  567. f_lo_kHz = freq;
  568. for (lo_select = 0; lo_select < 7; lo_select++)
  569. if (f_vco_max < f_lo_kHz * lo_divide_ratio[lo_select + 1])
  570. break;
  571. lo_div = lo_divide_ratio[lo_select];
  572. f_vco = f_lo_kHz * lo_div;
  573. r_val = 1;
  574. f_comp = FC8300_XTAL_FREQ / r_val;
  575. n_val = f_vco / f_comp;
  576. f_diff = f_vco - f_comp * n_val;
  577. f_diff_shifted = f_diff << (20 - pre_shift_bits);
  578. k_val = f_diff_shifted / (f_comp >> pre_shift_bits);
  579. k_val = k_val | 1;
  580. data_0x57 = ((n_val >> 3) & 0x20);
  581. data_0x57 += (r_val == 1) ? 0 : 0x10;
  582. data_0x57 += (k_val >> 16);
  583. data_0x51 = 0x00;
  584. data_0x51 += (lo_select * 2) + 1;
  585. fc8300_write(handle, devid, 0x7C, 0x00);
  586. fc8300_write(handle, devid, 0x7E, 0x00);
  587. fc8300_write(handle, devid, 0x7F, 0x00);
  588. fc8300_write(handle, devid, 0x80, 0x00);
  589. fc8300_write(handle, devid, 0x81, 0x00);
  590. fc8300_write(handle, devid, 0x15, 0x77);
  591. fc8300_write(handle, devid, 0x91, 0xA8);
  592. fc8300_write(handle, devid, 0x70, 0x63);
  593. fc8300_write(handle, devid, 0x6a, 0x00);
  594. fc8300_write(handle, devid, 0x51, data_0x51);
  595. fc8300_write(handle, devid, 0x57, data_0x57);
  596. fc8300_write(handle, devid, 0x58, (u8) ((k_val >> 8) & 0xFF));
  597. fc8300_write(handle, devid, 0x5a, (u8) n_val);
  598. fc8300_write(handle, devid, 0x59, (u8) ((k_val) & 0xFF));
  599. fc8300_write(handle, devid, 0x50, 0xe3);
  600. fc8300_write(handle, devid, 0x50, 0xff);
  601. for (i = 1; i < 15; i++) {
  602. fc8300_read(handle, devid, 0x64, &lock_detect);
  603. if ((lock_detect & 0x01) == 1) {
  604. fc8300_read(handle, devid, 0x65, &lock_detect);
  605. fc8300_write(handle, devid, 0x6d, (lock_detect | 0x0f));
  606. fc8300_write(handle, devid, 0x6f, (lock_detect | 0x0f) +
  607. 0x10);
  608. fc8300_write(handle, devid, 0x70, 0x40);
  609. fc8300_write(handle, devid, 0x6a, 0x10);
  610. break;
  611. }
  612. msWait(2);
  613. }
  614. for (i = 1; i < 15; i++) {
  615. fc8300_read(handle, devid, 0x76, &lock_detect);
  616. if (lock_detect == 0x20) {
  617. fc8300_write(handle, devid, 0x5a, (u8) n_val);
  618. fc8300_write(handle, devid, 0x50, 0xe3);
  619. fc8300_write(handle, devid, 0x50, 0xff);
  620. break;
  621. }
  622. msWait(2);
  623. }
  624. if (broadcast_type == ISDBT_CATV_13SEG) {
  625. fc8300_write(handle, devid, 0x91, 0xa8);
  626. fc8300_write(handle, devid, 0x15, 0x47);
  627. fc8300_write(handle, devid, 0x19, 0x46);
  628. } else {
  629. fc8300_write(handle, devid, 0x91, 0x78);
  630. fc8300_write(handle, devid, 0x15, 0x46);
  631. }
  632. fc8300_write(handle, devid, 0x7C, 0x30);
  633. fc8300_write(handle, devid, 0x7E, 0x05);
  634. fc8300_write(handle, devid, 0x7F, 0x0A);
  635. fc8300_write(handle, devid, 0x80, 0x3F);
  636. fc8300_write(handle, devid, 0x81, 0x3F);
  637. return BBM_OK;
  638. }
  639. s32 fc8300_es2_vhf(HANDLE handle, DEVICEID devid)
  640. {
  641. u8 i = 0;
  642. u8 filter_cal_60 = 0;
  643. u8 temp = 0;
  644. filter_cal_60 = FC8300_XTAL_FREQ * 72 / 30000;
  645. fc8300_write(handle, devid, 0x00, 0x00);
  646. fc8300_write(handle, devid, 0x02, 0x03);
  647. fc8300_write(handle, devid, 0x03, 0x00);
  648. fc8300_write(handle, devid, 0x08, 0xe5);
  649. fc8300_write(handle, devid, 0x1c, 0x00);
  650. fc8300_write(handle, devid, 0x1d, 0x00);
  651. fc8300_write(handle, devid, 0x21, 0x20);
  652. fc8300_write(handle, devid, 0x24, 0x98);
  653. fc8300_write(handle, devid, 0x5f, 0x40);
  654. fc8300_write(handle, devid, 0x3f, 0x01);
  655. fc8300_write(handle, devid, 0x41, filter_cal_60);
  656. fc8300_write(handle, devid, 0x3f, 0x00);
  657. fc8300_write(handle, devid, 0x3c, 0xff);
  658. fc8300_write(handle, devid, 0x3d, 0xff);
  659. fc8300_write(handle, devid, 0x70, 0x5f);
  660. fc8300_write(handle, devid, 0x04, 0x10);
  661. fc8300_write(handle, devid, 0xed, 0xcc);
  662. fc8300_write(handle, devid, 0x82, 0x88);
  663. fc8300_write(handle, devid, 0x7c, 0x01);
  664. fc8300_write(handle, devid, 0x84, 0x0f);
  665. fc8300_write(handle, devid, 0x85, 0x0a);
  666. fc8300_write(handle, devid, 0x86, 0x1f);
  667. fc8300_write(handle, devid, 0x87, 0x0f);
  668. fc8300_write(handle, devid, 0x88, 0x0f);
  669. fc8300_write(handle, devid, 0x89, 0x0b);
  670. fc8300_write(handle, devid, 0x8a, 0x15);
  671. fc8300_write(handle, devid, 0x8b, 0x0b);
  672. fc8300_write(handle, devid, 0x78, 0x30);
  673. fc8300_write(handle, devid, 0x7e, 0x05);
  674. fc8300_write(handle, devid, 0x7f, 0x0a);
  675. fc8300_write(handle, devid, 0xb2, 0x00);
  676. fc8300_write(handle, devid, 0xb3, 0x0c);
  677. fc8300_write(handle, devid, 0xb4, 0x00);
  678. fc8300_write(handle, devid, 0xb5, 0x0a);
  679. fc8300_write(handle, devid, 0xb6, 0x00);
  680. fc8300_write(handle, devid, 0xb7, 0x0a);
  681. fc8300_write(handle, devid, 0xb8, 0x00);
  682. fc8300_write(handle, devid, 0xb9, 0x0a);
  683. fc8300_write(handle, devid, 0xba, 0x00);
  684. fc8300_write(handle, devid, 0xbb, 0x0a);
  685. fc8300_write(handle, devid, 0xbc, 0x00);
  686. fc8300_write(handle, devid, 0xbd, 0x0a);
  687. fc8300_write(handle, devid, 0xbe, 0x00);
  688. fc8300_write(handle, devid, 0xbf, 0x0a);
  689. fc8300_write(handle, devid, 0xc0, 0x0a);
  690. fc8300_write(handle, devid, 0xc1, 0x00);
  691. fc8300_write(handle, devid, 0xc2, 0x13);
  692. fc8300_write(handle, devid, 0xc3, 0x00);
  693. fc8300_write(handle, devid, 0xf1, 0x53);
  694. fc8300_write(handle, devid, 0xd3, 0x00);
  695. fc8300_write(handle, devid, 0xd4, 0x02);
  696. fc8300_write(handle, devid, 0xd5, 0x04);
  697. fc8300_write(handle, devid, 0xd6, 0x14);
  698. fc8300_write(handle, devid, 0xd7, 0x34);
  699. fc8300_write(handle, devid, 0xd8, 0x36);
  700. fc8300_write(handle, devid, 0xd9, 0x38);
  701. fc8300_write(handle, devid, 0xda, 0x78);
  702. fc8300_write(handle, devid, 0xdb, 0xb8);
  703. fc8300_write(handle, devid, 0xdc, 0xf8);
  704. fc8300_write(handle, devid, 0xdd, 0xf8);
  705. fc8300_write(handle, devid, 0x33, 0x88);
  706. fc8300_write(handle, devid, 0x34, 0x86);
  707. fc8300_write(handle, devid, 0x37, 0x64);
  708. fc8300_write(handle, devid, 0x38, 0x44);
  709. fc8300_write(handle, devid, 0x39, 0x02);
  710. fc8300_write(handle, devid, 0x3e, 0xab);
  711. fc8300_write(handle, devid, 0x13, 0x07);
  712. fc8300_write(handle, devid, 0x15, 0x47);
  713. fc8300_write(handle, devid, 0x84, 0x0f);
  714. fc8300_write(handle, devid, 0x85, 0x0a);
  715. fc8300_write(handle, devid, 0x86, 0x3f);
  716. fc8300_write(handle, devid, 0x87, 0x2f);
  717. fc8300_write(handle, devid, 0x8f, 0xb6);
  718. fc8300_write(handle, devid, 0x90, 0xb2);
  719. fc8300_write(handle, devid, 0x91, 0xa8);
  720. fc8300_write(handle, devid, 0x16, 0x42);
  721. fc8300_write(handle, devid, 0x17, 0x42);
  722. fc8300_write(handle, devid, 0x1a, 0x42);
  723. fc8300_write(handle, devid, 0x1f, 0x77);
  724. fc8300_write(handle, devid, 0x20, 0x42);
  725. fc8300_write(handle, devid, 0xe9, 0x79);
  726. fc8300_write(handle, devid, 0xef, 0xb7);
  727. for (i = 0; i < 30 ; i++) {
  728. msWait(1);
  729. fc8300_read(handle, devid, 0x43, &temp);
  730. if (((temp >> 4) & 0x01) == 1)
  731. break;
  732. }
  733. fc8300_write(handle, devid, 0x5f, 0x00);
  734. fc8300_write(handle, devid, 0x78, 0xf0);
  735. msWait(5);
  736. fc8300_write(handle, devid, 0x78, 0x30);
  737. fc8300_write(handle, devid, 0xfb, FC8300_BAND_WIDTH);
  738. fc8300_write(handle, devid, 0xfc, broadcast_type);
  739. fc8300_write(handle, devid, 0xfd, (u8)(FC8300_XTAL_FREQ / 1000));
  740. fc8300_write(handle, devid, 0xfe, DRIVER_VERSION);
  741. if (FC8300_XTAL_FREQ < 20000)
  742. fc8300_write(handle, devid, 0xF3, 0x55);
  743. else if (FC8300_XTAL_FREQ > 20000)
  744. fc8300_write(handle, devid, 0xF3, 0x54);
  745. /* PLL AGC All Broadcast */
  746. fc8300_write(handle, devid, 0xF4, 0xFF);
  747. fc8300_write(handle, devid, 0xB5, 0x0A);
  748. fc8300_write(handle, devid, 0xB7, 0x0A);
  749. fc8300_write(handle, devid, 0xB9, 0x0A);
  750. fc8300_write(handle, devid, 0xBB, 0x0A);
  751. fc8300_write(handle, devid, 0x50, 0xff);
  752. fc8300_write(handle, devid, 0x5f, 0x00);
  753. fc8300_write(handle, devid, 0x6a, 0x00);
  754. fc8300_write(handle, devid, 0x6b, 0x99);
  755. fc8300_write(handle, devid, 0x6c, 0x99);
  756. fc8300_write(handle, devid, 0x6e, 0x03);
  757. fc8300_write(handle, devid, 0x73, 0x66);
  758. fc8300_write(handle, devid, 0x74, 0x66);
  759. fc8300_write(handle, devid, 0x75, 0x30);
  760. fc8300_write(handle, devid, 0xfa, 0xff);
  761. return BBM_OK;
  762. }
  763. s32 fc8300_es2_uhf(HANDLE handle, DEVICEID devid)
  764. {
  765. u8 i = 0;
  766. u8 filter_cal_60 = 0;
  767. u8 temp = 0;
  768. filter_cal_60 = FC8300_XTAL_FREQ * 72 / 30000;;
  769. fc8300_write(handle, devid, 0x00, 0x00);
  770. fc8300_write(handle, devid, 0x02, 0x01);
  771. fc8300_write(handle, devid, 0x03, 0x04);
  772. fc8300_write(handle, devid, 0x08, 0xe5);
  773. fc8300_write(handle, devid, 0x1d, 0x10);
  774. fc8300_write(handle, devid, 0x21, 0x30);
  775. fc8300_write(handle, devid, 0x24, 0x98);
  776. fc8300_write(handle, devid, 0x5f, 0x40);
  777. fc8300_write(handle, devid, 0x3f, 0x01);
  778. fc8300_write(handle, devid, 0x41, filter_cal_60);
  779. fc8300_write(handle, devid, 0x3f, 0x00);
  780. fc8300_write(handle, devid, 0x3c, 0xff);
  781. fc8300_write(handle, devid, 0x3d, 0xff);
  782. fc8300_write(handle, devid, 0x54, 0x80);
  783. fc8300_write(handle, devid, 0x70, 0x5f);
  784. fc8300_write(handle, devid, 0x04, 0x10);
  785. fc8300_write(handle, devid, 0xed, 0xcc);
  786. fc8300_write(handle, devid, 0x82, 0x88);
  787. fc8300_write(handle, devid, 0x7c, 0x01);
  788. fc8300_write(handle, devid, 0x88, 0x0f);
  789. fc8300_write(handle, devid, 0x89, 0x0b);
  790. fc8300_write(handle, devid, 0x8a, 0x15);
  791. fc8300_write(handle, devid, 0x8b, 0x0b);
  792. fc8300_write(handle, devid, 0x78, 0x30);
  793. fc8300_write(handle, devid, 0x7e, 0x05);
  794. fc8300_write(handle, devid, 0x7f, 0x0a);
  795. fc8300_write(handle, devid, 0xb2, 0x00);
  796. fc8300_write(handle, devid, 0xb3, 0x0c);
  797. fc8300_write(handle, devid, 0xb4, 0x00);
  798. fc8300_write(handle, devid, 0xb5, 0x0a);
  799. fc8300_write(handle, devid, 0xb6, 0x00);
  800. fc8300_write(handle, devid, 0xb7, 0x0a);
  801. fc8300_write(handle, devid, 0xb8, 0x00);
  802. fc8300_write(handle, devid, 0xb9, 0x0a);
  803. fc8300_write(handle, devid, 0xba, 0x00);
  804. fc8300_write(handle, devid, 0xbb, 0x0a);
  805. fc8300_write(handle, devid, 0xbc, 0x00);
  806. fc8300_write(handle, devid, 0xbd, 0x0a);
  807. fc8300_write(handle, devid, 0xbe, 0x00);
  808. fc8300_write(handle, devid, 0xbf, 0x0a);
  809. fc8300_write(handle, devid, 0xc0, 0x0a);
  810. fc8300_write(handle, devid, 0xc1, 0x00);
  811. fc8300_write(handle, devid, 0xc2, 0x13);
  812. fc8300_write(handle, devid, 0xc3, 0x00);
  813. fc8300_write(handle, devid, 0xf1, 0x53);
  814. fc8300_write(handle, devid, 0xd3, 0x00);
  815. fc8300_write(handle, devid, 0xd4, 0x02);
  816. fc8300_write(handle, devid, 0xd5, 0x04);
  817. fc8300_write(handle, devid, 0xd6, 0x14);
  818. fc8300_write(handle, devid, 0xd7, 0x34);
  819. fc8300_write(handle, devid, 0xd8, 0x36);
  820. fc8300_write(handle, devid, 0xd9, 0x38);
  821. fc8300_write(handle, devid, 0xda, 0x78);
  822. fc8300_write(handle, devid, 0xdb, 0xb8);
  823. fc8300_write(handle, devid, 0xdc, 0xf8);
  824. fc8300_write(handle, devid, 0xdd, 0xf8);
  825. fc8300_write(handle, devid, 0x91, 0xa8);
  826. fc8300_write(handle, devid, 0x33, 0x88);
  827. fc8300_write(handle, devid, 0x34, 0x86);
  828. fc8300_write(handle, devid, 0x37, 0x65);
  829. fc8300_write(handle, devid, 0x38, 0x55);
  830. fc8300_write(handle, devid, 0x39, 0x02);
  831. fc8300_write(handle, devid, 0x3e, 0xab);
  832. fc8300_write(handle, devid, 0x13, 0x07);
  833. fc8300_write(handle, devid, 0x15, 0x47);
  834. fc8300_write(handle, devid, 0x84, 0x0f);
  835. fc8300_write(handle, devid, 0x85, 0x0a);
  836. fc8300_write(handle, devid, 0x86, 0x3f);
  837. fc8300_write(handle, devid, 0x87, 0x2f);
  838. fc8300_write(handle, devid, 0x8f, 0xb6);
  839. fc8300_write(handle, devid, 0x90, 0xb2);
  840. fc8300_write(handle, devid, 0xe9, 0x79);
  841. fc8300_write(handle, devid, 0xef, 0xb7);
  842. for (i = 0; i < 30 ; i++) {
  843. msWait(1);
  844. fc8300_read(handle, devid, 0x43, &temp);
  845. if (((temp >> 4) & 0x01) == 1)
  846. break;
  847. }
  848. fc8300_write(handle, devid, 0x5f, 0x00);
  849. fc8300_write(handle, devid, 0x78, 0xf0);
  850. msWait(5);
  851. fc8300_write(handle, devid, 0x78, 0x30);
  852. if (FC8300_XTAL_FREQ == 19200)
  853. fc8300_write(handle, devid, 0x53, 0x16);
  854. else
  855. fc8300_write(handle, devid, 0x53, 0x1a);
  856. fc8300_write(handle, devid, 0xfb, FC8300_BAND_WIDTH);
  857. fc8300_write(handle, devid, 0xfc, broadcast_type);
  858. fc8300_write(handle, devid, 0xfd, (u8)(FC8300_XTAL_FREQ / 1000));
  859. fc8300_write(handle, devid, 0xfe, DRIVER_VERSION);
  860. if (FC8300_XTAL_FREQ < 20000)
  861. fc8300_write(handle, devid, 0xF3, 0x55);
  862. else if (FC8300_XTAL_FREQ > 20000)
  863. fc8300_write(handle, devid, 0xF3, 0x54);
  864. /* PLL AGC All Broadcast */
  865. fc8300_write(handle, devid, 0xF4, 0xFF);
  866. fc8300_write(handle, devid, 0xB5, 0x0A);
  867. fc8300_write(handle, devid, 0xB7, 0x0A);
  868. fc8300_write(handle, devid, 0xB9, 0x0A);
  869. fc8300_write(handle, devid, 0xBB, 0x0A);
  870. fc8300_write(handle, devid, 0x50, 0xff);
  871. fc8300_write(handle, devid, 0x5f, 0x00);
  872. fc8300_write(handle, devid, 0x6a, 0x00);
  873. fc8300_write(handle, devid, 0x6b, 0x99);
  874. fc8300_write(handle, devid, 0x6c, 0x99);
  875. fc8300_write(handle, devid, 0x6e, 0x03);
  876. fc8300_write(handle, devid, 0x73, 0x66);
  877. fc8300_write(handle, devid, 0x74, 0x66);
  878. fc8300_write(handle, devid, 0x75, 0x30);
  879. fc8300_write(handle, devid, 0xfa, 0x20);
  880. fc8300_tuner_set_pll(handle, DIV_MASTER, 545143, 0);
  881. fc8300_write(handle, devid, 0x1e, 0x10);
  882. fc8300_write(handle, devid, 0x1f, 0xf2);
  883. fc8300_write(handle, devid, 0x78, 0x06);
  884. fc8300_write(handle, devid, 0x04, 0x12);
  885. fc8300_write(handle, devid, 0x8d, 0x08);
  886. fc8300_write(handle, devid, 0x8e, 0x13);
  887. fc8300_write(handle, devid, 0x13, 0x07);
  888. fc8300_write(handle, devid, 0x22, 0x01);
  889. fc8300_write(handle, devid, 0x24, 0x11);
  890. fc8300_write(handle, devid, 0x23, 0x17);
  891. if (broad_check == 1) { /* BROADCAST Control */
  892. if ((device_set & 0x01) == 1)
  893. fc_cal_value[0] = (tf_cal(handle, DIV_MASTER) -
  894. 7);
  895. if ((device_set & 0x02) == 2)
  896. fc_cal_value[1] = (tf_cal(handle, DIV_SLAVE0) -
  897. 7);
  898. if ((device_set & 0x04) == 4)
  899. fc_cal_value[2] = (tf_cal(handle, DIV_SLAVE1) -
  900. 7);
  901. if ((device_set & 0x08) == 8)
  902. fc_cal_value[3] = (tf_cal(handle, DIV_SLAVE2) -
  903. 7);
  904. } else if (broad_check == 0) { /* Single Control */
  905. fc_cal_value[0] = (tf_cal(handle, devid) - 7);
  906. }
  907. fc8300_write(handle, devid, 0x1e, 0x00);
  908. fc8300_write(handle, devid, 0x1f, 0x72);
  909. fc8300_write(handle, devid, 0x78, 0x30);
  910. fc8300_write(handle, devid, 0x04, 0x10);
  911. fc8300_write(handle, devid, 0x22, 0x00);
  912. fc8300_write(handle, devid, 0xfa, 0xff);
  913. return BBM_OK;
  914. }
  915. s32 fc8300_es2_tuner_init(HANDLE handle, DEVICEID devid,
  916. enum BROADCAST_TYPE broadcast)
  917. {
  918. u8 temp;
  919. u8 filter_cal_09;
  920. u8 filter_cal_18;
  921. u8 filter_cal_60;
  922. s32 i, cal_temp;
  923. broadcast_type = broadcast;
  924. device_set = 0;
  925. if (devid == DIV_BROADCAST)
  926. broad_check = 1;
  927. else
  928. broad_check = 0;
  929. #if defined(BBM_4_DIVERSITY)
  930. fc8300_read(handle, DIV_SLAVE2, 0x01, &temp);
  931. if (temp == 0xaa) {
  932. device_set = device_set + 8;
  933. bc_type[3] = broadcast_type;
  934. }
  935. fc8300_read(handle, DIV_SLAVE1, 0x01, &temp);
  936. if (temp == 0xaa) {
  937. device_set = device_set + 4;
  938. bc_type[2] = broadcast_type;
  939. }
  940. fc8300_read(handle, DIV_SLAVE0, 0x01, &temp);
  941. if (temp == 0xaa) {
  942. device_set = device_set + 2;
  943. bc_type[1] = broadcast_type;
  944. }
  945. #elif defined(BBM_2_DIVERSITY)
  946. fc8300_read(handle, DIV_SLAVE0, 0x01, &temp);
  947. if (temp == 0xaa) {
  948. device_set = device_set + 2;
  949. bc_type[1] = broadcast_type;
  950. }
  951. #endif /* #if defined(BBM_4_DIVERSITY) */
  952. fc8300_read(handle, DIV_MASTER, 0x01, &temp);
  953. if (temp == 0xaa) {
  954. device_set = device_set + 1;
  955. bc_type[0] = broadcast_type;
  956. }
  957. /*
  958. * ISDBT_1SEG = 0 ==> 0.9
  959. * ISDBTMM_1SEG = 1 ==> 0.9
  960. * ISDBTSB_1SEG = 2 ==> 0.9
  961. * ISDBTSB_3SEG = 3 ==> 1.8
  962. * ISDBT_13SEG = 4 ==> 6 / 7 / 8
  963. * ISDBTMM_13SEG = 5 ==> 6 / 7 / 8
  964. * CATV ==> 6 / 7 / 8
  965. */
  966. if (FC8300_XTAL_FREQ < 32000) {
  967. cal_temp = FC8300_XTAL_FREQ * 72 / 9000;
  968. filter_cal_09 = (u8) cal_temp;
  969. } else {
  970. filter_cal_09 = 0x5f;
  971. }
  972. cal_temp = FC8300_XTAL_FREQ * 72 / 18000;
  973. filter_cal_18 = (u8) cal_temp;
  974. #if (BBM_BAND_WIDTH == 6)
  975. cal_temp = FC8300_XTAL_FREQ * 72 / 30000;
  976. #elif (BBM_BAND_WIDTH == 7)
  977. cal_temp = FC8300_XTAL_FREQ * 72 / 35000;
  978. #else /* BBM_BAND_WIDTH == 8 */
  979. cal_temp = FC8300_XTAL_FREQ * 72 / 40000;
  980. #endif /* #if (BBM_BAND_WIDTH == 6) */
  981. filter_cal_60 = (u8) cal_temp;
  982. if (broadcast_type == ISDBT_1SEG) {
  983. fc8300_write(handle, devid, 0x00, 0x00);
  984. fc8300_write(handle, devid, 0x02, 0x01);
  985. fc8300_write(handle, devid, 0x03, 0x04);
  986. fc8300_write(handle, devid, 0x08, 0xe5);
  987. fc8300_write(handle, devid, 0x1d, 0x10);
  988. fc8300_write(handle, devid, 0x21, 0x30);
  989. fc8300_write(handle, devid, 0x24, 0x98);
  990. fc8300_write(handle, devid, 0x5f, 0x40);
  991. if (FC8300_XTAL_FREQ < 32000) {
  992. fc8300_write(handle, devid, 0x3f, 0x01);
  993. fc8300_write(handle, devid, 0x41, filter_cal_09);
  994. fc8300_write(handle, devid, 0x3f, 0x00);
  995. } else {
  996. fc8300_write(handle, devid, 0x3f, 0x02);
  997. fc8300_write(handle, devid, 0x42, filter_cal_09);
  998. }
  999. fc8300_write(handle, devid, 0x3c, 0xff);
  1000. fc8300_write(handle, devid, 0x3d, 0xff);
  1001. fc8300_write(handle, devid, 0x54, 0x80);
  1002. fc8300_write(handle, devid, 0x70, 0x5f);
  1003. fc8300_write(handle, devid, 0x04, 0x10);
  1004. fc8300_write(handle, devid, 0xed, 0xcc);
  1005. fc8300_write(handle, devid, 0x82, 0x88);
  1006. fc8300_write(handle, devid, 0x7c, 0x01);
  1007. fc8300_write(handle, devid, 0x84, 0x1a);
  1008. fc8300_write(handle, devid, 0x85, 0x0f);
  1009. fc8300_write(handle, devid, 0x86, 0x1f);
  1010. fc8300_write(handle, devid, 0x87, 0x0f);
  1011. fc8300_write(handle, devid, 0x88, 0x0f);
  1012. fc8300_write(handle, devid, 0x89, 0x0b);
  1013. fc8300_write(handle, devid, 0x8a, 0x15);
  1014. fc8300_write(handle, devid, 0x8b, 0x0b);
  1015. fc8300_write(handle, devid, 0x78, 0x30);
  1016. fc8300_write(handle, devid, 0x7e, 0x05);
  1017. fc8300_write(handle, devid, 0x7f, 0x0a);
  1018. fc8300_write(handle, devid, 0xb2, 0x00);
  1019. fc8300_write(handle, devid, 0xb3, 0x0c);
  1020. fc8300_write(handle, devid, 0xb4, 0x00);
  1021. fc8300_write(handle, devid, 0xb5, 0x0a);
  1022. fc8300_write(handle, devid, 0xb6, 0x00);
  1023. fc8300_write(handle, devid, 0xb7, 0x0a);
  1024. fc8300_write(handle, devid, 0xb8, 0x00);
  1025. fc8300_write(handle, devid, 0xb9, 0x0a);
  1026. fc8300_write(handle, devid, 0xba, 0x00);
  1027. fc8300_write(handle, devid, 0xbb, 0x0a);
  1028. fc8300_write(handle, devid, 0xbc, 0x00);
  1029. fc8300_write(handle, devid, 0xbd, 0x0a);
  1030. fc8300_write(handle, devid, 0xbe, 0x00);
  1031. fc8300_write(handle, devid, 0xbf, 0x0a);
  1032. fc8300_write(handle, devid, 0xc0, 0x0a);
  1033. fc8300_write(handle, devid, 0xc1, 0x00);
  1034. fc8300_write(handle, devid, 0xc2, 0x13);
  1035. fc8300_write(handle, devid, 0xc3, 0x00);
  1036. fc8300_write(handle, devid, 0xf1, 0x53);
  1037. fc8300_write(handle, devid, 0xd3, 0x00);
  1038. fc8300_write(handle, devid, 0xd4, 0x02);
  1039. fc8300_write(handle, devid, 0xd5, 0x04);
  1040. fc8300_write(handle, devid, 0xd6, 0x14);
  1041. fc8300_write(handle, devid, 0xd7, 0x34);
  1042. fc8300_write(handle, devid, 0xd8, 0x36);
  1043. fc8300_write(handle, devid, 0xd9, 0x38);
  1044. fc8300_write(handle, devid, 0xda, 0x78);
  1045. fc8300_write(handle, devid, 0xdb, 0xb8);
  1046. fc8300_write(handle, devid, 0xdc, 0xf8);
  1047. fc8300_write(handle, devid, 0xdd, 0xf8);
  1048. fc8300_write(handle, devid, 0x91, 0x68);
  1049. fc8300_write(handle, devid, 0x19, 0x21);
  1050. fc8300_write(handle, devid, 0x1f, 0x72);
  1051. fc8300_write(handle, devid, 0x20, 0x22);
  1052. fc8300_write(handle, devid, 0x33, 0x83);
  1053. fc8300_write(handle, devid, 0x34, 0x44);
  1054. fc8300_write(handle, devid, 0x37, 0x65);
  1055. fc8300_write(handle, devid, 0x38, 0x55);
  1056. fc8300_write(handle, devid, 0x39, 0x02);
  1057. fc8300_write(handle, devid, 0x3e, 0xab);
  1058. fc8300_write(handle, devid, 0x3c, 0xaa);
  1059. fc8300_write(handle, devid, 0x3d, 0xaa);
  1060. fc8300_write(handle, devid, 0x13, 0x07);
  1061. fc8300_write(handle, devid, 0x84, 0x14);
  1062. fc8300_write(handle, devid, 0x85, 0x0f);
  1063. fc8300_write(handle, devid, 0x86, 0x3f);
  1064. fc8300_write(handle, devid, 0x87, 0x2f);
  1065. fc8300_write(handle, devid, 0x8f, 0xb6);
  1066. fc8300_write(handle, devid, 0x90, 0xb2);
  1067. fc8300_write(handle, devid, 0xe9, 0x79);
  1068. fc8300_write(handle, devid, 0xef, 0xb7);
  1069. for (i = 0; i < 30 ; i++) {
  1070. msWait(1);
  1071. fc8300_read(handle, devid, 0x43, &temp);
  1072. if (((temp >> 4) & 0x01) == 1)
  1073. break;
  1074. }
  1075. fc8300_write(handle, devid, 0x5f, 0x00);
  1076. fc8300_write(handle, devid, 0x78, 0xf0);
  1077. msWait(5);
  1078. fc8300_write(handle, devid, 0x78, 0x30);
  1079. if (FC8300_XTAL_FREQ == 19200)
  1080. fc8300_write(handle, devid, 0x53, 0x16);
  1081. else
  1082. fc8300_write(handle, devid, 0x53, 0x1a);
  1083. } else if (broadcast_type == ISDBTMM_1SEG) {
  1084. fc8300_write(handle, devid, 0x00, 0x00);
  1085. fc8300_write(handle, devid, 0x02, 0x03);
  1086. fc8300_write(handle, devid, 0x03, 0x00);
  1087. fc8300_write(handle, devid, 0x08, 0xe5);
  1088. fc8300_write(handle, devid, 0x1c, 0x00);
  1089. fc8300_write(handle, devid, 0x1d, 0x00);
  1090. fc8300_write(handle, devid, 0x21, 0x20);
  1091. fc8300_write(handle, devid, 0x24, 0x98);
  1092. fc8300_write(handle, devid, 0x5f, 0x40);
  1093. if (FC8300_XTAL_FREQ < 32000) {
  1094. fc8300_write(handle, devid, 0x3f, 0x01);
  1095. fc8300_write(handle, devid, 0x41, filter_cal_09);
  1096. fc8300_write(handle, devid, 0x3f, 0x00);
  1097. } else {
  1098. fc8300_write(handle, devid, 0x3f, 0x02);
  1099. fc8300_write(handle, devid, 0x42, filter_cal_09);
  1100. }
  1101. fc8300_write(handle, devid, 0x3c, 0xff);
  1102. fc8300_write(handle, devid, 0x3d, 0xff);
  1103. fc8300_write(handle, devid, 0x70, 0x5f);
  1104. fc8300_write(handle, devid, 0x04, 0x10);
  1105. fc8300_write(handle, devid, 0xed, 0xcc);
  1106. fc8300_write(handle, devid, 0x82, 0x88);
  1107. fc8300_write(handle, devid, 0x7c, 0x01);
  1108. fc8300_write(handle, devid, 0x84, 0x1a);
  1109. fc8300_write(handle, devid, 0x85, 0x0f);
  1110. fc8300_write(handle, devid, 0x86, 0x1f);
  1111. fc8300_write(handle, devid, 0x87, 0x0f);
  1112. fc8300_write(handle, devid, 0x88, 0x0f);
  1113. fc8300_write(handle, devid, 0x89, 0x0b);
  1114. fc8300_write(handle, devid, 0x8a, 0x15);
  1115. fc8300_write(handle, devid, 0x8b, 0x0b);
  1116. fc8300_write(handle, devid, 0x78, 0x30);
  1117. fc8300_write(handle, devid, 0x7e, 0x05);
  1118. fc8300_write(handle, devid, 0x7f, 0x0a);
  1119. fc8300_write(handle, devid, 0xb2, 0x00);
  1120. fc8300_write(handle, devid, 0xb3, 0x0c);
  1121. fc8300_write(handle, devid, 0xb4, 0x00);
  1122. fc8300_write(handle, devid, 0xb5, 0x0a);
  1123. fc8300_write(handle, devid, 0xb6, 0x00);
  1124. fc8300_write(handle, devid, 0xb7, 0x0a);
  1125. fc8300_write(handle, devid, 0xb8, 0x00);
  1126. fc8300_write(handle, devid, 0xb9, 0x0a);
  1127. fc8300_write(handle, devid, 0xba, 0x00);
  1128. fc8300_write(handle, devid, 0xbb, 0x0a);
  1129. fc8300_write(handle, devid, 0xbc, 0x00);
  1130. fc8300_write(handle, devid, 0xbd, 0x0a);
  1131. fc8300_write(handle, devid, 0xbe, 0x00);
  1132. fc8300_write(handle, devid, 0xbf, 0x0a);
  1133. fc8300_write(handle, devid, 0xc0, 0x0a);
  1134. fc8300_write(handle, devid, 0xc1, 0x00);
  1135. fc8300_write(handle, devid, 0xc2, 0x13);
  1136. fc8300_write(handle, devid, 0xc3, 0x00);
  1137. fc8300_write(handle, devid, 0xf1, 0x53);
  1138. fc8300_write(handle, devid, 0xd3, 0x00);
  1139. fc8300_write(handle, devid, 0xd4, 0x02);
  1140. fc8300_write(handle, devid, 0xd5, 0x04);
  1141. fc8300_write(handle, devid, 0xd6, 0x14);
  1142. fc8300_write(handle, devid, 0xd7, 0x34);
  1143. fc8300_write(handle, devid, 0xd8, 0x36);
  1144. fc8300_write(handle, devid, 0xd9, 0x38);
  1145. fc8300_write(handle, devid, 0xda, 0x78);
  1146. fc8300_write(handle, devid, 0xdb, 0xb8);
  1147. fc8300_write(handle, devid, 0xdc, 0xf8);
  1148. fc8300_write(handle, devid, 0xdd, 0xf8);
  1149. fc8300_write(handle, devid, 0x33, 0x88);
  1150. fc8300_write(handle, devid, 0x34, 0x86);
  1151. fc8300_write(handle, devid, 0x37, 0x64);
  1152. fc8300_write(handle, devid, 0x38, 0x44);
  1153. fc8300_write(handle, devid, 0x39, 0x02);
  1154. fc8300_write(handle, devid, 0x3e, 0xab);
  1155. fc8300_write(handle, devid, 0x13, 0x07);
  1156. fc8300_write(handle, devid, 0x15, 0x46);
  1157. fc8300_write(handle, devid, 0x84, 0x14);
  1158. fc8300_write(handle, devid, 0x85, 0x0f);
  1159. fc8300_write(handle, devid, 0x86, 0x3f);
  1160. fc8300_write(handle, devid, 0x87, 0x2f);
  1161. fc8300_write(handle, devid, 0x8f, 0xb6);
  1162. fc8300_write(handle, devid, 0x90, 0xb2);
  1163. fc8300_write(handle, devid, 0x91, 0x68);
  1164. fc8300_write(handle, devid, 0x16, 0x42);
  1165. fc8300_write(handle, devid, 0x17, 0x42);
  1166. fc8300_write(handle, devid, 0x1a, 0x42);
  1167. fc8300_write(handle, devid, 0x1f, 0x77);
  1168. fc8300_write(handle, devid, 0x20, 0x42);
  1169. fc8300_write(handle, devid, 0xe9, 0x79);
  1170. fc8300_write(handle, devid, 0xef, 0xb7);
  1171. for (i = 0; i < 30 ; i++) {
  1172. msWait(1);
  1173. fc8300_read(handle, devid, 0x43, &temp);
  1174. if (((temp >> 4) & 0x01) == 1)
  1175. break;
  1176. }
  1177. fc8300_write(handle, devid, 0x5f, 0x00);
  1178. fc8300_write(handle, devid, 0x78, 0xf0);
  1179. msWait(5);
  1180. fc8300_write(handle, devid, 0x78, 0x30);
  1181. } else if (broadcast_type == ISDBTSB_1SEG) {
  1182. fc8300_write(handle, devid, 0x00, 0x00);
  1183. fc8300_write(handle, devid, 0x02, 0x05);
  1184. fc8300_write(handle, devid, 0x03, 0x04);
  1185. fc8300_write(handle, devid, 0x08, 0x21);
  1186. fc8300_write(handle, devid, 0x1d, 0x00);
  1187. fc8300_write(handle, devid, 0x21, 0x10);
  1188. fc8300_write(handle, devid, 0x24, 0x98);
  1189. fc8300_write(handle, devid, 0x5f, 0x40);
  1190. if (FC8300_XTAL_FREQ < 32000) {
  1191. fc8300_write(handle, devid, 0x3f, 0x01);
  1192. fc8300_write(handle, devid, 0x41, filter_cal_09);
  1193. fc8300_write(handle, devid, 0x3f, 0x00);
  1194. } else {
  1195. fc8300_write(handle, devid, 0x3f, 0x02);
  1196. fc8300_write(handle, devid, 0x42, filter_cal_09);
  1197. }
  1198. for (i = 0; i < 5 ; i++) {
  1199. msWait(10);
  1200. fc8300_read(handle, devid, 0x43, &temp);
  1201. if (((temp >> 4) & 0x01) == 1)
  1202. break;
  1203. }
  1204. fc8300_write(handle, devid, 0x3c, 0xff);
  1205. fc8300_write(handle, devid, 0x3d, 0xff);
  1206. fc8300_write(handle, devid, 0x70, 0x5f);
  1207. fc8300_write(handle, devid, 0x04, 0x10);
  1208. fc8300_write(handle, devid, 0xed, 0xcc);
  1209. fc8300_write(handle, devid, 0x82, 0x88);
  1210. fc8300_write(handle, devid, 0x7c, 0x01);
  1211. fc8300_write(handle, devid, 0x84, 0x1a);
  1212. fc8300_write(handle, devid, 0x85, 0x0f);
  1213. fc8300_write(handle, devid, 0x86, 0x1f);
  1214. fc8300_write(handle, devid, 0x87, 0x0f);
  1215. fc8300_write(handle, devid, 0x88, 0x0f);
  1216. fc8300_write(handle, devid, 0x89, 0x0b);
  1217. fc8300_write(handle, devid, 0x8a, 0x15);
  1218. fc8300_write(handle, devid, 0x8b, 0x0b);
  1219. fc8300_write(handle, devid, 0x78, 0x30);
  1220. fc8300_write(handle, devid, 0x7e, 0x05);
  1221. fc8300_write(handle, devid, 0x7f, 0x0a);
  1222. fc8300_write(handle, devid, 0xb2, 0x00);
  1223. fc8300_write(handle, devid, 0xb3, 0x0c);
  1224. fc8300_write(handle, devid, 0xb4, 0x00);
  1225. fc8300_write(handle, devid, 0xb5, 0x0a);
  1226. fc8300_write(handle, devid, 0xb6, 0x00);
  1227. fc8300_write(handle, devid, 0xb7, 0x0a);
  1228. fc8300_write(handle, devid, 0xb8, 0x00);
  1229. fc8300_write(handle, devid, 0xb9, 0x0a);
  1230. fc8300_write(handle, devid, 0xba, 0x00);
  1231. fc8300_write(handle, devid, 0xbb, 0x0a);
  1232. fc8300_write(handle, devid, 0xbc, 0x00);
  1233. fc8300_write(handle, devid, 0xbd, 0x0a);
  1234. fc8300_write(handle, devid, 0xbe, 0x00);
  1235. fc8300_write(handle, devid, 0xbf, 0x0a);
  1236. fc8300_write(handle, devid, 0xc0, 0x0a);
  1237. fc8300_write(handle, devid, 0xc1, 0x00);
  1238. fc8300_write(handle, devid, 0xc2, 0x13);
  1239. fc8300_write(handle, devid, 0xc3, 0x00);
  1240. fc8300_write(handle, devid, 0xf1, 0x53);
  1241. fc8300_write(handle, devid, 0xd3, 0x00);
  1242. fc8300_write(handle, devid, 0xd4, 0x02);
  1243. fc8300_write(handle, devid, 0xd5, 0x04);
  1244. fc8300_write(handle, devid, 0xd6, 0x14);
  1245. fc8300_write(handle, devid, 0xd7, 0x34);
  1246. fc8300_write(handle, devid, 0xd8, 0x36);
  1247. fc8300_write(handle, devid, 0xd9, 0x38);
  1248. fc8300_write(handle, devid, 0xda, 0x78);
  1249. fc8300_write(handle, devid, 0xdb, 0xb8);
  1250. fc8300_write(handle, devid, 0xdc, 0xf8);
  1251. fc8300_write(handle, devid, 0xdd, 0xf8);
  1252. fc8300_write(handle, devid, 0x33, 0x88);
  1253. fc8300_write(handle, devid, 0x34, 0x86);
  1254. fc8300_write(handle, devid, 0x37, 0x64);
  1255. fc8300_write(handle, devid, 0x38, 0x44);
  1256. fc8300_write(handle, devid, 0x39, 0x02);
  1257. fc8300_write(handle, devid, 0x3e, 0xab);
  1258. fc8300_write(handle, devid, 0x13, 0x07);
  1259. fc8300_write(handle, devid, 0x15, 0x46);
  1260. fc8300_write(handle, devid, 0x84, 0x14);
  1261. fc8300_write(handle, devid, 0x85, 0x0f);
  1262. fc8300_write(handle, devid, 0x86, 0x3f);
  1263. fc8300_write(handle, devid, 0x87, 0x2f);
  1264. fc8300_write(handle, devid, 0x8f, 0xb6);
  1265. fc8300_write(handle, devid, 0x90, 0xb2);
  1266. fc8300_write(handle, devid, 0x91, 0x68);
  1267. fc8300_write(handle, devid, 0x16, 0x42);
  1268. fc8300_write(handle, devid, 0x17, 0x42);
  1269. fc8300_write(handle, devid, 0x1a, 0x42);
  1270. fc8300_write(handle, devid, 0x1f, 0x77);
  1271. fc8300_write(handle, devid, 0x20, 0x42);
  1272. fc8300_write(handle, devid, 0xe9, 0x79);
  1273. fc8300_write(handle, devid, 0xef, 0xb7);
  1274. fc8300_write(handle, devid, 0x5f, 0x00);
  1275. fc8300_write(handle, devid, 0x78, 0xf0);
  1276. msWait(5);
  1277. fc8300_write(handle, devid, 0x78, 0x30);
  1278. } else if (broadcast_type == ISDBTSB_3SEG) {
  1279. fc8300_write(handle, devid, 0x00, 0x00);
  1280. fc8300_write(handle, devid, 0x02, 0x05);
  1281. fc8300_write(handle, devid, 0x03, 0x04);
  1282. fc8300_write(handle, devid, 0x08, 0x21);
  1283. fc8300_write(handle, devid, 0x1d, 0x00);
  1284. fc8300_write(handle, devid, 0x21, 0x10);
  1285. fc8300_write(handle, devid, 0x24, 0x98);
  1286. fc8300_write(handle, devid, 0x5f, 0x40);
  1287. fc8300_write(handle, devid, 0x3f, 0x01);
  1288. fc8300_write(handle, devid, 0x41, filter_cal_18);
  1289. fc8300_write(handle, devid, 0x3f, 0x00);
  1290. fc8300_write(handle, devid, 0x3c, 0xff);
  1291. fc8300_write(handle, devid, 0x3d, 0xff);
  1292. fc8300_write(handle, devid, 0x70, 0x5f);
  1293. fc8300_write(handle, devid, 0x04, 0x10);
  1294. fc8300_write(handle, devid, 0xed, 0xcc);
  1295. fc8300_write(handle, devid, 0x82, 0x88);
  1296. fc8300_write(handle, devid, 0x7c, 0x01);
  1297. fc8300_write(handle, devid, 0x84, 0x1a);
  1298. fc8300_write(handle, devid, 0x85, 0x0f);
  1299. fc8300_write(handle, devid, 0x86, 0x1f);
  1300. fc8300_write(handle, devid, 0x87, 0x0f);
  1301. fc8300_write(handle, devid, 0x88, 0x0f);
  1302. fc8300_write(handle, devid, 0x89, 0x0b);
  1303. fc8300_write(handle, devid, 0x8a, 0x15);
  1304. fc8300_write(handle, devid, 0x8b, 0x0b);
  1305. fc8300_write(handle, devid, 0x78, 0x30);
  1306. fc8300_write(handle, devid, 0x7e, 0x05);
  1307. fc8300_write(handle, devid, 0x7f, 0x0a);
  1308. fc8300_write(handle, devid, 0xb2, 0x00);
  1309. fc8300_write(handle, devid, 0xb3, 0x0c);
  1310. fc8300_write(handle, devid, 0xb4, 0x00);
  1311. fc8300_write(handle, devid, 0xb5, 0x0a);
  1312. fc8300_write(handle, devid, 0xb6, 0x00);
  1313. fc8300_write(handle, devid, 0xb7, 0x0a);
  1314. fc8300_write(handle, devid, 0xb8, 0x00);
  1315. fc8300_write(handle, devid, 0xb9, 0x0a);
  1316. fc8300_write(handle, devid, 0xba, 0x00);
  1317. fc8300_write(handle, devid, 0xbb, 0x0a);
  1318. fc8300_write(handle, devid, 0xbc, 0x00);
  1319. fc8300_write(handle, devid, 0xbd, 0x0a);
  1320. fc8300_write(handle, devid, 0xbe, 0x00);
  1321. fc8300_write(handle, devid, 0xbf, 0x0a);
  1322. fc8300_write(handle, devid, 0xc0, 0x0a);
  1323. fc8300_write(handle, devid, 0xc1, 0x00);
  1324. fc8300_write(handle, devid, 0xc2, 0x13);
  1325. fc8300_write(handle, devid, 0xc3, 0x00);
  1326. fc8300_write(handle, devid, 0xf1, 0x53);
  1327. fc8300_write(handle, devid, 0xd3, 0x00);
  1328. fc8300_write(handle, devid, 0xd4, 0x02);
  1329. fc8300_write(handle, devid, 0xd5, 0x04);
  1330. fc8300_write(handle, devid, 0xd6, 0x14);
  1331. fc8300_write(handle, devid, 0xd7, 0x34);
  1332. fc8300_write(handle, devid, 0xd8, 0x36);
  1333. fc8300_write(handle, devid, 0xd9, 0x38);
  1334. fc8300_write(handle, devid, 0xda, 0x78);
  1335. fc8300_write(handle, devid, 0xdb, 0xb8);
  1336. fc8300_write(handle, devid, 0xdc, 0xf8);
  1337. fc8300_write(handle, devid, 0xdd, 0xf8);
  1338. fc8300_write(handle, devid, 0x33, 0x88);
  1339. fc8300_write(handle, devid, 0x34, 0x86);
  1340. fc8300_write(handle, devid, 0x37, 0x64);
  1341. fc8300_write(handle, devid, 0x38, 0x44);
  1342. fc8300_write(handle, devid, 0x39, 0x02);
  1343. fc8300_write(handle, devid, 0x3e, 0xab);
  1344. fc8300_write(handle, devid, 0x13, 0x07);
  1345. fc8300_write(handle, devid, 0x15, 0x46);
  1346. fc8300_write(handle, devid, 0x84, 0x14);
  1347. fc8300_write(handle, devid, 0x85, 0x0f);
  1348. fc8300_write(handle, devid, 0x86, 0x3f);
  1349. fc8300_write(handle, devid, 0x87, 0x2f);
  1350. fc8300_write(handle, devid, 0x8f, 0xb6);
  1351. fc8300_write(handle, devid, 0x90, 0xb2);
  1352. fc8300_write(handle, devid, 0x91, 0x68);
  1353. fc8300_write(handle, devid, 0x16, 0x42);
  1354. fc8300_write(handle, devid, 0x17, 0x42);
  1355. fc8300_write(handle, devid, 0x1a, 0x42);
  1356. fc8300_write(handle, devid, 0x1f, 0x77);
  1357. fc8300_write(handle, devid, 0x20, 0x42);
  1358. fc8300_write(handle, devid, 0xe9, 0x79);
  1359. fc8300_write(handle, devid, 0xef, 0xb7);
  1360. for (i = 0; i < 30 ; i++) {
  1361. msWait(1);
  1362. fc8300_read(handle, devid, 0x43, &temp);
  1363. if (((temp >> 4) & 0x01) == 1)
  1364. break;
  1365. }
  1366. fc8300_write(handle, devid, 0x5f, 0x00);
  1367. fc8300_write(handle, devid, 0x78, 0xf0);
  1368. msWait(5);
  1369. fc8300_write(handle, devid, 0x78, 0x30);
  1370. } else if (broadcast_type == ISDBT_13SEG) {
  1371. fc8300_write(handle, devid, 0x00, 0x00);
  1372. fc8300_write(handle, devid, 0x02, 0x01);
  1373. fc8300_write(handle, devid, 0x03, 0x04);
  1374. fc8300_write(handle, devid, 0x08, 0xe5);
  1375. fc8300_write(handle, devid, 0x1d, 0x10);
  1376. fc8300_write(handle, devid, 0x21, 0x30);
  1377. fc8300_write(handle, devid, 0x24, 0x98);
  1378. fc8300_write(handle, devid, 0x5f, 0x40);
  1379. fc8300_write(handle, devid, 0x3f, 0x01);
  1380. fc8300_write(handle, devid, 0x41, filter_cal_60);
  1381. fc8300_write(handle, devid, 0x3f, 0x00);
  1382. fc8300_write(handle, devid, 0x3c, 0xff);
  1383. fc8300_write(handle, devid, 0x3d, 0xff);
  1384. fc8300_write(handle, devid, 0x54, 0x80);
  1385. fc8300_write(handle, devid, 0x70, 0x5f);
  1386. fc8300_write(handle, devid, 0x04, 0x10);
  1387. fc8300_write(handle, devid, 0xed, 0xcc);
  1388. fc8300_write(handle, devid, 0x82, 0x88);
  1389. fc8300_write(handle, devid, 0x7c, 0x01);
  1390. fc8300_write(handle, devid, 0x88, 0x0f);
  1391. fc8300_write(handle, devid, 0x89, 0x0b);
  1392. fc8300_write(handle, devid, 0x8a, 0x15);
  1393. fc8300_write(handle, devid, 0x8b, 0x0b);
  1394. fc8300_write(handle, devid, 0x78, 0x30);
  1395. fc8300_write(handle, devid, 0x7e, 0x05);
  1396. fc8300_write(handle, devid, 0x7f, 0x0a);
  1397. fc8300_write(handle, devid, 0xb2, 0x00);
  1398. fc8300_write(handle, devid, 0xb3, 0x0c);
  1399. fc8300_write(handle, devid, 0xb4, 0x00);
  1400. fc8300_write(handle, devid, 0xb5, 0x0a);
  1401. fc8300_write(handle, devid, 0xb6, 0x00);
  1402. fc8300_write(handle, devid, 0xb7, 0x0a);
  1403. fc8300_write(handle, devid, 0xb8, 0x00);
  1404. fc8300_write(handle, devid, 0xb9, 0x0a);
  1405. fc8300_write(handle, devid, 0xba, 0x00);
  1406. fc8300_write(handle, devid, 0xbb, 0x0a);
  1407. fc8300_write(handle, devid, 0xbc, 0x00);
  1408. fc8300_write(handle, devid, 0xbd, 0x0a);
  1409. fc8300_write(handle, devid, 0xbe, 0x00);
  1410. fc8300_write(handle, devid, 0xbf, 0x0a);
  1411. fc8300_write(handle, devid, 0xc0, 0x0a);
  1412. fc8300_write(handle, devid, 0xc1, 0x00);
  1413. fc8300_write(handle, devid, 0xc2, 0x13);
  1414. fc8300_write(handle, devid, 0xc3, 0x00);
  1415. fc8300_write(handle, devid, 0xf1, 0x53);
  1416. fc8300_write(handle, devid, 0xd3, 0x00);
  1417. fc8300_write(handle, devid, 0xd4, 0x02);
  1418. fc8300_write(handle, devid, 0xd5, 0x04);
  1419. fc8300_write(handle, devid, 0xd6, 0x14);
  1420. fc8300_write(handle, devid, 0xd7, 0x34);
  1421. fc8300_write(handle, devid, 0xd8, 0x36);
  1422. fc8300_write(handle, devid, 0xd9, 0x38);
  1423. fc8300_write(handle, devid, 0xda, 0x78);
  1424. fc8300_write(handle, devid, 0xdb, 0xb8);
  1425. fc8300_write(handle, devid, 0xdc, 0xf8);
  1426. fc8300_write(handle, devid, 0xdd, 0xf8);
  1427. fc8300_write(handle, devid, 0x91, 0x78);
  1428. fc8300_write(handle, devid, 0x33, 0x88);
  1429. fc8300_write(handle, devid, 0x34, 0x86);
  1430. fc8300_write(handle, devid, 0x37, 0x65);
  1431. fc8300_write(handle, devid, 0x38, 0x55);
  1432. fc8300_write(handle, devid, 0x39, 0x02);
  1433. fc8300_write(handle, devid, 0x3e, 0xab);
  1434. fc8300_write(handle, devid, 0x13, 0x07);
  1435. fc8300_write(handle, devid, 0x15, 0x46);
  1436. fc8300_write(handle, devid, 0x84, 0x14);
  1437. fc8300_write(handle, devid, 0x85, 0x0f);
  1438. fc8300_write(handle, devid, 0x86, 0x3f);
  1439. fc8300_write(handle, devid, 0x87, 0x2f);
  1440. fc8300_write(handle, devid, 0x8f, 0xb6);
  1441. fc8300_write(handle, devid, 0x90, 0xb2);
  1442. fc8300_write(handle, devid, 0xe9, 0x79);
  1443. fc8300_write(handle, devid, 0xef, 0xb7);
  1444. for (i = 0; i < 30 ; i++) {
  1445. msWait(1);
  1446. fc8300_read(handle, devid, 0x43, &temp);
  1447. if (((temp >> 4) & 0x01) == 1)
  1448. break;
  1449. }
  1450. fc8300_write(handle, devid, 0x5f, 0x00);
  1451. fc8300_write(handle, devid, 0x78, 0xf0);
  1452. msWait(5);
  1453. fc8300_write(handle, devid, 0x78, 0x30);
  1454. if (FC8300_XTAL_FREQ == 19200)
  1455. fc8300_write(handle, devid, 0x53, 0x16);
  1456. else
  1457. fc8300_write(handle, devid, 0x53, 0x1a);
  1458. } else if (broadcast_type == ISDBTMM_13SEG) {
  1459. fc8300_write(handle, devid, 0x00, 0x00);
  1460. fc8300_write(handle, devid, 0x02, 0x03);
  1461. fc8300_write(handle, devid, 0x03, 0x00);
  1462. fc8300_write(handle, devid, 0x08, 0xe5);
  1463. fc8300_write(handle, devid, 0x1c, 0x00);
  1464. fc8300_write(handle, devid, 0x1d, 0x00);
  1465. fc8300_write(handle, devid, 0x21, 0x20);
  1466. fc8300_write(handle, devid, 0x24, 0x98);
  1467. fc8300_write(handle, devid, 0x5f, 0x40);
  1468. fc8300_write(handle, devid, 0x3f, 0x01);
  1469. fc8300_write(handle, devid, 0x41, filter_cal_60);
  1470. fc8300_write(handle, devid, 0x3f, 0x00);
  1471. fc8300_write(handle, devid, 0x3c, 0xff);
  1472. fc8300_write(handle, devid, 0x3d, 0xff);
  1473. fc8300_write(handle, devid, 0x70, 0x5f);
  1474. fc8300_write(handle, devid, 0x04, 0x10);
  1475. fc8300_write(handle, devid, 0xed, 0xcc);
  1476. fc8300_write(handle, devid, 0x82, 0x88);
  1477. fc8300_write(handle, devid, 0x7c, 0x01);
  1478. fc8300_write(handle, devid, 0x84, 0x1a);
  1479. fc8300_write(handle, devid, 0x85, 0x0f);
  1480. fc8300_write(handle, devid, 0x86, 0x1f);
  1481. fc8300_write(handle, devid, 0x87, 0x0f);
  1482. fc8300_write(handle, devid, 0x88, 0x0f);
  1483. fc8300_write(handle, devid, 0x89, 0x0b);
  1484. fc8300_write(handle, devid, 0x8a, 0x15);
  1485. fc8300_write(handle, devid, 0x8b, 0x0b);
  1486. fc8300_write(handle, devid, 0x78, 0x30);
  1487. fc8300_write(handle, devid, 0x7e, 0x05);
  1488. fc8300_write(handle, devid, 0x7f, 0x0a);
  1489. fc8300_write(handle, devid, 0xb2, 0x00);
  1490. fc8300_write(handle, devid, 0xb3, 0x0c);
  1491. fc8300_write(handle, devid, 0xb4, 0x00);
  1492. fc8300_write(handle, devid, 0xb5, 0x0a);
  1493. fc8300_write(handle, devid, 0xb6, 0x00);
  1494. fc8300_write(handle, devid, 0xb7, 0x0a);
  1495. fc8300_write(handle, devid, 0xb8, 0x00);
  1496. fc8300_write(handle, devid, 0xb9, 0x0a);
  1497. fc8300_write(handle, devid, 0xba, 0x00);
  1498. fc8300_write(handle, devid, 0xbb, 0x0a);
  1499. fc8300_write(handle, devid, 0xbc, 0x00);
  1500. fc8300_write(handle, devid, 0xbd, 0x0a);
  1501. fc8300_write(handle, devid, 0xbe, 0x00);
  1502. fc8300_write(handle, devid, 0xbf, 0x0a);
  1503. fc8300_write(handle, devid, 0xc0, 0x0a);
  1504. fc8300_write(handle, devid, 0xc1, 0x00);
  1505. fc8300_write(handle, devid, 0xc2, 0x13);
  1506. fc8300_write(handle, devid, 0xc3, 0x00);
  1507. fc8300_write(handle, devid, 0xf1, 0x53);
  1508. fc8300_write(handle, devid, 0xd3, 0x00);
  1509. fc8300_write(handle, devid, 0xd4, 0x02);
  1510. fc8300_write(handle, devid, 0xd5, 0x04);
  1511. fc8300_write(handle, devid, 0xd6, 0x14);
  1512. fc8300_write(handle, devid, 0xd7, 0x34);
  1513. fc8300_write(handle, devid, 0xd8, 0x36);
  1514. fc8300_write(handle, devid, 0xd9, 0x38);
  1515. fc8300_write(handle, devid, 0xda, 0x78);
  1516. fc8300_write(handle, devid, 0xdb, 0xb8);
  1517. fc8300_write(handle, devid, 0xdc, 0xf8);
  1518. fc8300_write(handle, devid, 0xdd, 0xf8);
  1519. fc8300_write(handle, devid, 0x33, 0x88);
  1520. fc8300_write(handle, devid, 0x34, 0x86);
  1521. fc8300_write(handle, devid, 0x37, 0x64);
  1522. fc8300_write(handle, devid, 0x38, 0x44);
  1523. fc8300_write(handle, devid, 0x39, 0x02);
  1524. fc8300_write(handle, devid, 0x3e, 0xab);
  1525. fc8300_write(handle, devid, 0x13, 0x07);
  1526. fc8300_write(handle, devid, 0x15, 0x46);
  1527. fc8300_write(handle, devid, 0x84, 0x14);
  1528. fc8300_write(handle, devid, 0x85, 0x0f);
  1529. fc8300_write(handle, devid, 0x86, 0x3f);
  1530. fc8300_write(handle, devid, 0x87, 0x2f);
  1531. fc8300_write(handle, devid, 0x8f, 0xb6);
  1532. fc8300_write(handle, devid, 0x90, 0xb2);
  1533. fc8300_write(handle, devid, 0x91, 0x68);
  1534. fc8300_write(handle, devid, 0x16, 0x42);
  1535. fc8300_write(handle, devid, 0x17, 0x42);
  1536. fc8300_write(handle, devid, 0x1a, 0x42);
  1537. fc8300_write(handle, devid, 0x1f, 0x77);
  1538. fc8300_write(handle, devid, 0x20, 0x42);
  1539. fc8300_write(handle, devid, 0xe9, 0x79);
  1540. fc8300_write(handle, devid, 0xef, 0xb7);
  1541. for (i = 0; i < 30 ; i++) {
  1542. msWait(1);
  1543. fc8300_read(handle, devid, 0x43, &temp);
  1544. if (((temp >> 4) & 0x01) == 1)
  1545. break;
  1546. }
  1547. fc8300_write(handle, devid, 0x5f, 0x00);
  1548. fc8300_write(handle, devid, 0x78, 0xf0);
  1549. msWait(5);
  1550. fc8300_write(handle, devid, 0x78, 0x30);
  1551. }
  1552. fc8300_write(handle, devid, 0xfb, FC8300_BAND_WIDTH);
  1553. fc8300_write(handle, devid, 0xfc, broadcast_type);
  1554. fc8300_write(handle, devid, 0xfd, (u8)(FC8300_XTAL_FREQ / 1000));
  1555. fc8300_write(handle, devid, 0xfe, DRIVER_VERSION);
  1556. /* PLL AGC All Broadcast */
  1557. if (FC8300_XTAL_FREQ < 20000)
  1558. fc8300_write(handle, devid, 0xF3, 0x55);
  1559. else if (FC8300_XTAL_FREQ > 20000)
  1560. fc8300_write(handle, devid, 0xF3, 0x54);
  1561. fc8300_write(handle, devid, 0xF4, 0xFF);
  1562. fc8300_write(handle, devid, 0xB5, 0x0A);
  1563. fc8300_write(handle, devid, 0xB7, 0x0A);
  1564. fc8300_write(handle, devid, 0xB9, 0x0A);
  1565. fc8300_write(handle, devid, 0xBB, 0x0A);
  1566. fc8300_write(handle, devid, 0x50, 0xff);
  1567. fc8300_write(handle, devid, 0x5f, 0x00);
  1568. fc8300_write(handle, devid, 0x6a, 0x00);
  1569. fc8300_write(handle, devid, 0x6b, 0x99);
  1570. fc8300_write(handle, devid, 0x6c, 0x99);
  1571. fc8300_write(handle, devid, 0x6e, 0x03);
  1572. fc8300_write(handle, devid, 0x73, 0x66);
  1573. fc8300_write(handle, devid, 0x74, 0x66);
  1574. fc8300_write(handle, devid, 0x75, 0x30);
  1575. if ((broadcast_type == ISDBT_13SEG) || (broadcast_type == ISDBT_1SEG)) {
  1576. fc8300_write(handle, devid, 0xfa, 0x20);
  1577. fc8300_es2_set_freq(handle, devid, 545143);
  1578. fc8300_write(handle, devid, 0x1e, 0x10);
  1579. fc8300_write(handle, devid, 0x1f, 0xf2);
  1580. fc8300_write(handle, devid, 0x78, 0x06);
  1581. fc8300_write(handle, devid, 0x04, 0x12);
  1582. fc8300_write(handle, devid, 0x8d, 0x08);
  1583. fc8300_write(handle, devid, 0x8e, 0x13);
  1584. fc8300_write(handle, devid, 0x13, 0x07);
  1585. fc8300_write(handle, devid, 0x22, 0x01);
  1586. fc8300_write(handle, devid, 0x24, 0x11);
  1587. fc8300_write(handle, devid, 0x23, 0x17);
  1588. if (broad_check == 1) { /* BROADCAST Control */
  1589. if ((device_set & 0x01) == 1)
  1590. fc_cal_value[0] = (tf_cal(handle, DIV_MASTER) -
  1591. 7);
  1592. if ((device_set & 0x02) == 2)
  1593. fc_cal_value[1] = (tf_cal(handle, DIV_SLAVE0) -
  1594. 7);
  1595. if ((device_set & 0x04) == 4)
  1596. fc_cal_value[2] = (tf_cal(handle, DIV_SLAVE1) -
  1597. 7);
  1598. if ((device_set & 0x08) == 8)
  1599. fc_cal_value[3] = (tf_cal(handle, DIV_SLAVE2) -
  1600. 7);
  1601. } else if (broad_check == 0) { /* Single Control */
  1602. fc_cal_value[0] = (tf_cal(handle, devid) - 7);
  1603. }
  1604. fc8300_write(handle, devid, 0x1e, 0x00);
  1605. fc8300_write(handle, devid, 0x1f, 0x72);
  1606. fc8300_write(handle, devid, 0x78, 0x30);
  1607. fc8300_write(handle, devid, 0x04, 0x10);
  1608. fc8300_write(handle, devid, 0x22, 0x00);
  1609. fc8300_write(handle, devid, 0xfa, 0x00);
  1610. }
  1611. return BBM_OK;
  1612. }
  1613. static u32 tunning_mode_0[57][5] = {
  1614. {473143, 0x7d, 0x21, 0x33, 0x1b},
  1615. {479143, 0x7d, 0x77, 0x31, 0x1b},
  1616. {485143, 0x7b, 0x44, 0x31, 0x1a},
  1617. {491143, 0x7b, 0x44, 0x31, 0x1a},
  1618. {497143, 0x7b, 0x44, 0x31, 0x19},
  1619. {503143, 0x7b, 0x44, 0x31, 0x19},
  1620. {509143, 0x7b, 0x44, 0x31, 0x19},
  1621. {515143, 0x7b, 0x44, 0x31, 0x18},
  1622. {521143, 0x7c, 0x44, 0x31, 0x18},
  1623. {527143, 0x7c, 0x44, 0x31, 0x18},
  1624. {533143, 0x7c, 0x44, 0x31, 0x17},
  1625. {539143, 0x7c, 0x44, 0x31, 0x17},
  1626. {545143, 0x7c, 0x44, 0x31, 0x17},
  1627. {551143, 0x7c, 0x44, 0x31, 0x17},
  1628. {557143, 0x7c, 0x44, 0x31, 0x16},
  1629. {563143, 0x7c, 0x44, 0x31, 0x16},
  1630. {569143, 0x7c, 0x44, 0x31, 0x16},
  1631. {575143, 0x7e, 0x44, 0x31, 0x16},
  1632. {581143, 0x7d, 0x44, 0x31, 0x15},
  1633. {587143, 0x7d, 0x44, 0x31, 0x15},
  1634. {593143, 0x7e, 0x44, 0x21, 0x15},
  1635. {599143, 0x7e, 0x44, 0x21, 0x15},
  1636. {605143, 0x7d, 0x44, 0x21, 0x14},
  1637. {611143, 0x7d, 0x44, 0x21, 0x14},
  1638. {617143, 0x7d, 0x44, 0x21, 0x14},
  1639. {623143, 0x7e, 0x44, 0x21, 0x14},
  1640. {629143, 0x7d, 0x44, 0x21, 0x14},
  1641. {635143, 0x80, 0x44, 0x21, 0x13},
  1642. {641143, 0x80, 0x44, 0x21, 0x13},
  1643. {647143, 0x7d, 0x32, 0x21, 0x13},
  1644. {653143, 0x7e, 0x32, 0x21, 0x13},
  1645. {659143, 0x7d, 0x32, 0x21, 0x13},
  1646. {665143, 0x7d, 0x32, 0x21, 0x13},
  1647. {671143, 0x7c, 0x32, 0x21, 0x12},
  1648. {677143, 0x7c, 0x32, 0x21, 0x12},
  1649. {683143, 0x7c, 0x32, 0x21, 0x12},
  1650. {689143, 0x7c, 0x32, 0x21, 0x12},
  1651. {695143, 0x7c, 0x32, 0x21, 0x12},
  1652. {701143, 0x7c, 0x32, 0x21, 0x12},
  1653. {707143, 0x7b, 0x32, 0x21, 0x11},
  1654. {713143, 0x7a, 0x32, 0x21, 0x11},
  1655. {719143, 0x7a, 0x32, 0x21, 0x11},
  1656. {725143, 0x7a, 0x32, 0x21, 0x11},
  1657. {731143, 0x7a, 0x32, 0x21, 0x11},
  1658. {737143, 0x7a, 0x32, 0x21, 0x11},
  1659. {741143, 0x7a, 0x32, 0x21, 0x11},
  1660. {747143, 0x7a, 0x32, 0x21, 0x11},
  1661. {753143, 0x7a, 0x32, 0x21, 0x11},
  1662. {759143, 0x7a, 0x32, 0x21, 0x11},
  1663. {765143, 0x7a, 0x32, 0x21, 0x11},
  1664. {772143, 0x7a, 0x32, 0x21, 0x11},
  1665. {778143, 0x7a, 0x32, 0x21, 0x11},
  1666. {785143, 0x7a, 0x32, 0x21, 0x11},
  1667. {791143, 0x7a, 0x32, 0x21, 0x11},
  1668. {797143, 0x7a, 0x32, 0x21, 0x11},
  1669. {803143, 0x7a, 0x32, 0x21, 0x11},
  1670. {809143, 0x7a, 0x32, 0x21, 0x11}
  1671. };
  1672. static u32 tunning_mode_1[8][7] = {
  1673. {210429, 0x7c, 0x53, 0x42, 0x07, 0x22, 0x1b},
  1674. {216000, 0x7b, 0x52, 0x42, 0x07, 0x22, 0x1b},
  1675. {219000, 0x7b, 0x53, 0x42, 0x07, 0x22, 0x1b},
  1676. {219429, 0x7b, 0x53, 0x42, 0x07, 0x22, 0x1b},
  1677. {219857, 0x7a, 0x53, 0x42, 0x07, 0x22, 0x1b},
  1678. {220714, 0x7a, 0x53, 0x31, 0x04, 0x22, 0x1b},
  1679. {221143, 0x7a, 0x53, 0x31, 0x04, 0x22, 0x1b},
  1680. {221571, 0x7a, 0x53, 0x31, 0x04, 0x22, 0x1b}
  1681. };
  1682. static u32 tunning_mode_4[57][7] = { /* ISDBT 13SEG*/
  1683. {473143, 0x79, 0x77, 0x46, 0x07, 0x22, 0x1b},
  1684. {479143, 0x79, 0x77, 0x46, 0x07, 0x22, 0x1b},
  1685. {485143, 0x79, 0x77, 0x46, 0x07, 0x22, 0x1a},
  1686. {491143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x1a},
  1687. {497143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x19},
  1688. {503143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x19},
  1689. {509143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x19},
  1690. {515143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x18},
  1691. {521143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x18},
  1692. {527143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x18},
  1693. {533143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x17},
  1694. {539143, 0x78, 0x77, 0x46, 0x04, 0x22, 0x17},
  1695. {545143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x17},
  1696. {551143, 0x79, 0x77, 0x46, 0x04, 0x22, 0x17},
  1697. {557143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x16},
  1698. {563143, 0x77, 0x77, 0x46, 0x04, 0x22, 0x16},
  1699. {569143, 0x78, 0x77, 0x46, 0x04, 0x22, 0x16},
  1700. {575143, 0x79, 0x77, 0x46, 0x04, 0x22, 0x16},
  1701. {581143, 0x79, 0x77, 0x46, 0x04, 0x22, 0x15},
  1702. {587143, 0x79, 0x77, 0x46, 0x04, 0x22, 0x15},
  1703. {593143, 0x79, 0x77, 0x46, 0x04, 0x22, 0x15},
  1704. {599143, 0x79, 0x77, 0x46, 0x04, 0x22, 0x15},
  1705. {605143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x14},
  1706. {611143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x14},
  1707. {617143, 0x7b, 0x77, 0x46, 0x04, 0x22, 0x14},
  1708. {623143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x14},
  1709. {629143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x14},
  1710. {635143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x13},
  1711. {641143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x13},
  1712. {647143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x13},
  1713. {653143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x13},
  1714. {659143, 0x7a, 0x77, 0x46, 0x04, 0x22, 0x13},
  1715. {665143, 0x7c, 0x77, 0x46, 0x07, 0x22, 0x13},
  1716. {671143, 0x7c, 0x77, 0x46, 0x07, 0x22, 0x12},
  1717. {677143, 0x7c, 0x77, 0x46, 0x07, 0x22, 0x12},
  1718. {683143, 0x7c, 0x77, 0x46, 0x07, 0x22, 0x12},
  1719. {689143, 0x7c, 0x77, 0x46, 0x07, 0x22, 0x12},
  1720. {695143, 0x7c, 0x77, 0x46, 0x07, 0x22, 0x12},
  1721. {701143, 0x7b, 0x77, 0x46, 0x07, 0x22, 0x12},
  1722. {707143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1723. {713143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1724. {719143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1725. {725143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1726. {731143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1727. {737143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1728. {741143, 0x7a, 0x77, 0x66, 0x07, 0x22, 0x11},
  1729. {747143, 0x7a, 0x77, 0x66, 0x07, 0x22, 0x11},
  1730. {753143, 0x7a, 0x77, 0x66, 0x07, 0x22, 0x11},
  1731. {759143, 0x7a, 0x77, 0x66, 0x07, 0x22, 0x11},
  1732. {765143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1733. {772143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1734. {778143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1735. {785143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x11},
  1736. {791143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x10},
  1737. {797143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x10},
  1738. {803143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x10},
  1739. {809143, 0x7a, 0x77, 0x46, 0x07, 0x22, 0x10}
  1740. };
  1741. static u32 tunning_mode_5[40][7] = {
  1742. {210429, 0x75, 0x54, 0x46, 0x07, 0x22, 0x1b},
  1743. {216000, 0x73, 0x52, 0x46, 0x07, 0x22, 0x1b}
  1744. };
  1745. static u32 tf_offset[2][13] = {
  1746. {473000, 485000, 497000, 515000, 533000, 557000, 581000, 605000,
  1747. 635000, 671000, 707000, 755000, 811000},
  1748. {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0}
  1749. };
  1750. s32 fc8300_es2_set_freq(HANDLE handle, DEVICEID devid, u32 freq)
  1751. {
  1752. u8 i;
  1753. u8 broad_check_set = 0;
  1754. u8 offset = 0;
  1755. u8 bc_type_freq = 0;
  1756. u8 tf_cal_set = 0;
  1757. u8 over_freq = 0;
  1758. t_handle = handle;
  1759. if (devid == DIV_MASTER) { /* Single Control */
  1760. bc_type_freq = bc_type[0];
  1761. t_devid[0] = devid;
  1762. thread_freq[0] = freq;
  1763. } else if (devid == DIV_SLAVE0) { /* Single Control */
  1764. bc_type_freq = bc_type[1];
  1765. t_devid[1] = devid;
  1766. thread_freq[1] = freq;
  1767. } else if (devid == DIV_SLAVE1) { /* Single Control */
  1768. bc_type_freq = bc_type[2];
  1769. t_devid[2] = devid;
  1770. thread_freq[2] = freq;
  1771. } else if (devid == DIV_SLAVE2) { /* Single Control */
  1772. bc_type_freq = bc_type[3];
  1773. t_devid[3] = devid;
  1774. thread_freq[3] = freq;
  1775. } else if (devid == DIV_BROADCAST) { /* BROADCAST Control */
  1776. broad_check_set = 1;
  1777. bc_type_freq = bc_type[0];
  1778. t_devid[0] = DIV_MASTER;
  1779. t_devid[1] = DIV_SLAVE0;
  1780. t_devid[2] = DIV_SLAVE1;
  1781. t_devid[3] = DIV_SLAVE2;
  1782. thread_freq[0] = freq;
  1783. thread_freq[1] = freq;
  1784. thread_freq[2] = freq;
  1785. thread_freq[3] = freq;
  1786. }
  1787. if (bc_type_freq == ISDBT_CATV_13SEG) { /* mode 6*/
  1788. fc8300_write(handle, devid, 0xfa, 0xff);
  1789. if (213143 >= freq) {
  1790. if (catv_status == 0) {
  1791. catv_status = 1;
  1792. fc8300_es2_vhf(handle, devid);
  1793. msWait(1000);
  1794. bc_type_freq = ISDBTMM_13SEG;
  1795. } else if (catv_status == 1) {
  1796. bc_type_freq = ISDBTMM_13SEG;
  1797. } else if (catv_status == 2) {
  1798. catv_status = 1;
  1799. fc8300_es2_vhf(handle, devid);
  1800. msWait(1000);
  1801. }
  1802. } else if (213143 < freq) {
  1803. if (catv_status == 0) {
  1804. catv_status = 2;
  1805. fc8300_es2_uhf(handle, devid);
  1806. msWait(1000);
  1807. bc_type_freq = ISDBT_13SEG;
  1808. } else if (catv_status == 2) {
  1809. bc_type_freq = ISDBT_13SEG;
  1810. } else if (catv_status == 1) {
  1811. catv_status = 1;
  1812. fc8300_es2_uhf(handle, devid);
  1813. msWait(1000);
  1814. }
  1815. }
  1816. }
  1817. if (bc_type_freq == ISDBT_1SEG) { /* mode 0 */
  1818. for (i = 0; i < 57; i++) {
  1819. if (((tunning_mode_0[i][0] + 3000) > freq) &&
  1820. ((tunning_mode_0[i][0] - 3000) <= freq)) {
  1821. fc8300_write(handle, devid, 0xe9,
  1822. tunning_mode_0[i][1]);
  1823. fc8300_write(handle, devid, 0xef,
  1824. tunning_mode_0[i][2]);
  1825. fc8300_write(handle, devid, 0x19,
  1826. tunning_mode_0[i][3]);
  1827. fc8300_write(handle, devid, 0x1c,
  1828. tunning_mode_0[i][4]);
  1829. over_freq = 1;
  1830. break;
  1831. }
  1832. }
  1833. if (over_freq == 0) {
  1834. fc8300_write(handle, devid, 0xe9,
  1835. tunning_mode_0[56][1]);
  1836. fc8300_write(handle, devid, 0xef,
  1837. tunning_mode_0[56][2]);
  1838. fc8300_write(handle, devid, 0x19,
  1839. tunning_mode_0[56][3]);
  1840. fc8300_write(handle, devid, 0x1c,
  1841. tunning_mode_0[56][4]);
  1842. }
  1843. } else if (bc_type_freq == ISDBTMM_1SEG) { /* mode 1 */
  1844. for (i = 0; i < 8; i++) {
  1845. if (((tunning_mode_1[i][0] + 200) > freq) &&
  1846. ((tunning_mode_1[i][0] - 200) <= freq)) {
  1847. fc8300_write(handle, devid, 0xe9,
  1848. tunning_mode_1[i][1]);
  1849. fc8300_write(handle, devid, 0xef,
  1850. tunning_mode_1[i][2]);
  1851. fc8300_write(handle, devid, 0x19,
  1852. tunning_mode_1[i][3]);
  1853. fc8300_write(handle, devid, 0x1f,
  1854. tunning_mode_1[i][4]);
  1855. fc8300_write(handle, devid, 0x20,
  1856. tunning_mode_1[i][5]);
  1857. over_freq = 1;
  1858. break;
  1859. }
  1860. }
  1861. if (over_freq == 0) {
  1862. fc8300_write(handle, devid, 0xe9,
  1863. tunning_mode_1[7][1]);
  1864. fc8300_write(handle, devid, 0xef,
  1865. tunning_mode_1[7][2]);
  1866. fc8300_write(handle, devid, 0x19,
  1867. tunning_mode_1[7][3]);
  1868. fc8300_write(handle, devid, 0x1f,
  1869. tunning_mode_1[7][4]);
  1870. fc8300_write(handle, devid, 0x20,
  1871. tunning_mode_1[7][5]);
  1872. }
  1873. } else if (bc_type_freq == ISDBT_13SEG) { /* mode 4*/
  1874. for (i = 0; i < 57; i++) {
  1875. if (((tunning_mode_4[i][0] + 3000) > freq) &&
  1876. ((tunning_mode_4[i][0] - 3000) <= freq)) {
  1877. fc8300_write(handle, devid, 0xe9,
  1878. tunning_mode_4[i][1]);
  1879. fc8300_write(handle, devid, 0xef,
  1880. tunning_mode_4[i][2]);
  1881. fc8300_write(handle, devid, 0x19,
  1882. tunning_mode_4[i][3]);
  1883. fc8300_write(handle, devid, 0x1f,
  1884. tunning_mode_4[i][4]);
  1885. fc8300_write(handle, devid, 0x20,
  1886. tunning_mode_4[i][5]);
  1887. fc8300_write(handle, devid, 0x1c,
  1888. tunning_mode_4[i][6]);
  1889. over_freq = 1;
  1890. break;
  1891. }
  1892. }
  1893. if (over_freq == 0) {
  1894. fc8300_write(handle, devid, 0xe9,
  1895. tunning_mode_4[56][1]);
  1896. fc8300_write(handle, devid, 0xef,
  1897. tunning_mode_4[56][2]);
  1898. fc8300_write(handle, devid, 0x19,
  1899. tunning_mode_4[56][3]);
  1900. fc8300_write(handle, devid, 0x1f,
  1901. tunning_mode_4[56][4]);
  1902. fc8300_write(handle, devid, 0x20,
  1903. tunning_mode_4[56][5]);
  1904. fc8300_write(handle, devid, 0x1c,
  1905. tunning_mode_4[56][6]);
  1906. }
  1907. } else if (bc_type_freq == ISDBTMM_13SEG) { /* mode 5*/
  1908. for (i = 0; i < 40; i++) {
  1909. if (((tunning_mode_5[i][0] + 1500) > freq) &&
  1910. ((tunning_mode_5[i][0] - 1500) <= freq)) {
  1911. fc8300_write(handle, devid, 0xe9,
  1912. tunning_mode_5[i][1]);
  1913. fc8300_write(handle, devid, 0xef,
  1914. tunning_mode_5[i][2]);
  1915. fc8300_write(handle, devid, 0x19,
  1916. tunning_mode_5[i][3]);
  1917. fc8300_write(handle, devid, 0x1f,
  1918. tunning_mode_5[i][4]);
  1919. fc8300_write(handle, devid, 0x20,
  1920. tunning_mode_5[i][5]);
  1921. over_freq = 1;
  1922. break;
  1923. }
  1924. }
  1925. if (over_freq == 0) {
  1926. fc8300_write(handle, devid, 0xe9,
  1927. tunning_mode_5[39][1]);
  1928. fc8300_write(handle, devid, 0xef,
  1929. tunning_mode_5[39][2]);
  1930. fc8300_write(handle, devid, 0x19,
  1931. tunning_mode_5[39][3]);
  1932. fc8300_write(handle, devid, 0x1f,
  1933. tunning_mode_5[39][4]);
  1934. fc8300_write(handle, devid, 0x20,
  1935. tunning_mode_5[39][5]);
  1936. }
  1937. }
  1938. if (broad_check_set == 0) { /* Single Control */
  1939. if (fc_cal_value[0] != 0) {
  1940. for (i = 0; i < 12; i++) {
  1941. if ((tf_offset[0][i] < freq) &&
  1942. (tf_offset[0][i+1] >= freq)) {
  1943. tf_cal_set = fc_cal_value[0] +
  1944. tf_offset[1][i];
  1945. if (tf_cal_set < 0x10)
  1946. tf_cal_set = 0x10;
  1947. else if (tf_cal_set > 0x1f)
  1948. tf_cal_set = 0x1f;
  1949. fc8300_write(handle, devid, 0x1c,
  1950. tf_cal_set);
  1951. break;
  1952. }
  1953. }
  1954. }
  1955. fc8300_tuner_set_pll(handle, devid, freq, offset);
  1956. } else if (broad_check_set == 1) { /* BROADCAST Control */
  1957. if (fc_cal_value[0] != 0) {
  1958. for (i = 0; i < 12; i++) {
  1959. if ((tf_offset[0][i] < freq) &&
  1960. (tf_offset[0][i+1] >= freq)) {
  1961. tf_cal_set = fc_cal_value[0] +
  1962. tf_offset[1][i];
  1963. if (tf_cal_set < 0x10)
  1964. tf_cal_set = 0x10;
  1965. else if (tf_cal_set > 0x1f)
  1966. tf_cal_set = 0x1f;
  1967. fc8300_write(handle, DIV_MASTER, 0x1c,
  1968. tf_cal_set);
  1969. break;
  1970. }
  1971. }
  1972. }
  1973. if (fc_cal_value[1] != 0) {
  1974. for (i = 0; i < 12; i++) {
  1975. if ((tf_offset[0][i] < freq) &&
  1976. (tf_offset[0][i+1] >= freq)) {
  1977. tf_cal_set = fc_cal_value[1] +
  1978. tf_offset[1][i];
  1979. if (tf_cal_set < 0x10)
  1980. tf_cal_set = 0x10;
  1981. else if (tf_cal_set > 0x1f)
  1982. tf_cal_set = 0x1f;
  1983. fc8300_write(handle, DIV_SLAVE0, 0x1c,
  1984. tf_cal_set);
  1985. break;
  1986. }
  1987. }
  1988. }
  1989. if (fc_cal_value[2] != 0) {
  1990. for (i = 0; i < 12; i++) {
  1991. if ((tf_offset[0][i] < freq) &&
  1992. (tf_offset[0][i+1] >= freq)) {
  1993. tf_cal_set = fc_cal_value[2] +
  1994. tf_offset[1][i];
  1995. if (tf_cal_set < 0x10)
  1996. tf_cal_set = 0x10;
  1997. else if (tf_cal_set > 0x1f)
  1998. tf_cal_set = 0x1f;
  1999. fc8300_write(handle, DIV_SLAVE1, 0x1c,
  2000. tf_cal_set);
  2001. break;
  2002. }
  2003. }
  2004. }
  2005. if (fc_cal_value[3] != 0) {
  2006. for (i = 0; i < 12; i++) {
  2007. if ((tf_offset[0][i] < freq) &&
  2008. (tf_offset[0][i+1] >= freq)) {
  2009. tf_cal_set = fc_cal_value[3] +
  2010. tf_offset[1][i];
  2011. if (tf_cal_set < 0x10)
  2012. tf_cal_set = 0x10;
  2013. else if (tf_cal_set > 0x1f)
  2014. tf_cal_set = 0x1f;
  2015. fc8300_write(handle, DIV_SLAVE2, 0x1c,
  2016. tf_cal_set);
  2017. break;
  2018. }
  2019. }
  2020. }
  2021. if ((device_set & 0x01) == 1)
  2022. fc8300_tuner_set_pll(handle, DIV_MASTER, freq, offset);
  2023. if ((device_set & 0x02) == 2)
  2024. fc8300_tuner_set_pll(handle, DIV_SLAVE0, freq, offset);
  2025. if ((device_set & 0x04) == 4)
  2026. fc8300_tuner_set_pll(handle, DIV_SLAVE1, freq, offset);
  2027. if ((device_set & 0x08) == 8)
  2028. fc8300_tuner_set_pll(handle, DIV_SLAVE2, freq, offset);
  2029. }
  2030. if (bc_type_freq == ISDBT_CATV_13SEG)
  2031. fc8300_write(handle, devid, 0x91, 0xa8);
  2032. else if (bc_type_freq != ISDBT_13SEG)
  2033. fc8300_write(handle, devid, 0x91, 0x68);
  2034. fc8300_read(handle, devid, 0xfa, &thread_check);
  2035. if (thread_check == 0 && thread_set == 0) {
  2036. #ifdef BBM_ES_CURRENT
  2037. _beginthread(KbdFunc , 0, NULL); /* Thread Go */
  2038. #endif
  2039. thread_set = 1;
  2040. } else if (thread_check == 0 && thread_set == 1) {
  2041. status_1seg[0] = 0;
  2042. status_1seg[1] = 0;
  2043. status_1seg[2] = 0;
  2044. status_1seg[3] = 0;
  2045. status_13seg[0] = 0;
  2046. status_13seg[1] = 0;
  2047. status_13seg[2] = 0;
  2048. status_13seg[3] = 0;
  2049. } else if (thread_check != 0) { /* Thread Stop */
  2050. thread_set = 0;
  2051. }
  2052. if (catv_status == 1 || catv_status == 2)
  2053. bc_type_freq = ISDBT_CATV_13SEG;
  2054. return BBM_OK;
  2055. }
  2056. s32 fc8300_es2_get_rssi(HANDLE handle, DEVICEID devid, s32 *rssi)
  2057. {
  2058. u8 reg_value = 0;
  2059. s32 rssi_value = 0;
  2060. fc8300_read(handle, devid, 0xeb, &reg_value);
  2061. rssi_value = reg_value - 256;
  2062. *rssi = rssi_value;
  2063. return BBM_OK;
  2064. }
  2065. s32 fc8300_es2_tuner_deinit(HANDLE handle, DEVICEID devid)
  2066. {
  2067. thread_set = 0;
  2068. msWait(1000);
  2069. return BBM_OK;
  2070. }