fc8300_es1_tun.c 62 KB

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