fc8300_es2_tun.c 69 KB

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