fc8300_es1_tun.c 62 KB

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