fc8080_bb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fc8080_bb.c
  4. Description : baseband source file
  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. *******************************************************************************/
  19. #include <linux/kernel.h>
  20. #include "fci_types.h"
  21. #include "fci_oal.h"
  22. #include "fci_hal.h"
  23. #include "fci_tun.h"
  24. #include "fc8080_regs.h"
  25. #define POWER_SAVE_MODE
  26. #define LOCK_TIME_TICK 5 /* 5ms */
  27. #define SLOCK_MAX_TIME 200
  28. #define FLOCK_MAX_TIME 300
  29. #define DLOCK_MAX_TIME 500
  30. static s32 fc8080_set_xtal(HANDLE handle)
  31. {
  32. #if (FC8080_FREQ_XTAL == 24576)
  33. bbm_long_write(handle, BBM_NCO_OFFSET, 0x04000000);
  34. bbm_byte_write(handle, BBM_NCO_INV, 0x80);
  35. bbm_byte_write(handle, BBM_EZ_CONST, 0x80);
  36. bbm_byte_write(handle, BBM_CLK_MODE, 0x02);
  37. /* filter coefficient */
  38. bbm_byte_write(handle, BBM_COEF00, 0x02);
  39. bbm_byte_write(handle, BBM_COEF01, 0x0f);
  40. bbm_byte_write(handle, BBM_COEF02, 0x0d);
  41. bbm_byte_write(handle, BBM_COEF03, 0x00);
  42. bbm_byte_write(handle, BBM_COEF04, 0x04);
  43. bbm_byte_write(handle, BBM_COEF05, 0x03);
  44. bbm_byte_write(handle, BBM_COEF06, 0x1c);
  45. bbm_byte_write(handle, BBM_COEF07, 0x19);
  46. bbm_byte_write(handle, BBM_COEF08, 0x02);
  47. bbm_byte_write(handle, BBM_COEF09, 0x0c);
  48. bbm_byte_write(handle, BBM_COEF0A, 0x04);
  49. bbm_byte_write(handle, BBM_COEF0B, 0x30);
  50. bbm_byte_write(handle, BBM_COEF0C, 0xed);
  51. bbm_byte_write(handle, BBM_COEF0D, 0x13);
  52. bbm_byte_write(handle, BBM_COEF0E, 0x4f);
  53. bbm_byte_write(handle, BBM_COEF0F, 0x6b);
  54. #elif (FC8080_FREQ_XTAL == 16384)
  55. /* clock mode */
  56. bbm_long_write(handle, BBM_NCO_OFFSET, 0x04000000);
  57. bbm_byte_write(handle, BBM_NCO_INV, 0x80);
  58. bbm_byte_write(handle, BBM_EZ_CONST, 0x80);
  59. bbm_byte_write(handle, BBM_CLK_MODE, 0x00);
  60. /* filter coefficient */
  61. bbm_byte_write(handle, BBM_COEF00, 0x02);
  62. bbm_byte_write(handle, BBM_COEF01, 0x0f);
  63. bbm_byte_write(handle, BBM_COEF02, 0x0d);
  64. bbm_byte_write(handle, BBM_COEF03, 0x00);
  65. bbm_byte_write(handle, BBM_COEF04, 0x04);
  66. bbm_byte_write(handle, BBM_COEF05, 0x03);
  67. bbm_byte_write(handle, BBM_COEF06, 0x1c);
  68. bbm_byte_write(handle, BBM_COEF07, 0x19);
  69. bbm_byte_write(handle, BBM_COEF08, 0x02);
  70. bbm_byte_write(handle, BBM_COEF09, 0x0c);
  71. bbm_byte_write(handle, BBM_COEF0A, 0x04);
  72. bbm_byte_write(handle, BBM_COEF0B, 0x30);
  73. bbm_byte_write(handle, BBM_COEF0C, 0xed);
  74. bbm_byte_write(handle, BBM_COEF0D, 0x13);
  75. bbm_byte_write(handle, BBM_COEF0E, 0x4f);
  76. bbm_byte_write(handle, BBM_COEF0F, 0x6b);
  77. #elif (FC8080_FREQ_XTAL == 19200)
  78. bbm_long_write(handle, BBM_NCO_OFFSET, 0x0369d037);
  79. bbm_byte_write(handle, BBM_NCO_INV, 0x96);
  80. bbm_byte_write(handle, BBM_EZ_CONST, 0x6d);
  81. bbm_byte_write(handle, BBM_CLK_MODE, 0x00);
  82. /* filter coefficient */
  83. bbm_byte_write(handle, BBM_COEF00, 0x0e);
  84. bbm_byte_write(handle, BBM_COEF01, 0x00);
  85. bbm_byte_write(handle, BBM_COEF02, 0x03);
  86. bbm_byte_write(handle, BBM_COEF03, 0x03);
  87. bbm_byte_write(handle, BBM_COEF04, 0x1f);
  88. bbm_byte_write(handle, BBM_COEF05, 0x1a);
  89. bbm_byte_write(handle, BBM_COEF06, 0x1b);
  90. bbm_byte_write(handle, BBM_COEF07, 0x03);
  91. bbm_byte_write(handle, BBM_COEF08, 0x0a);
  92. bbm_byte_write(handle, BBM_COEF09, 0x05);
  93. bbm_byte_write(handle, BBM_COEF0A, 0x37);
  94. bbm_byte_write(handle, BBM_COEF0B, 0x2d);
  95. bbm_byte_write(handle, BBM_COEF0C, 0xfa);
  96. bbm_byte_write(handle, BBM_COEF0D, 0x1f);
  97. bbm_byte_write(handle, BBM_COEF0E, 0x49);
  98. bbm_byte_write(handle, BBM_COEF0F, 0x5c);
  99. #elif (FC8080_FREQ_XTAL == 24000)
  100. bbm_long_write(handle, BBM_NCO_OFFSET, 0x02bb0cf8);
  101. bbm_byte_write(handle, BBM_NCO_INV, 0xbc);
  102. bbm_byte_write(handle, BBM_EZ_CONST, 0x57);
  103. bbm_byte_write(handle, BBM_CLK_MODE, 0x00);
  104. /* filter coefficient */
  105. bbm_byte_write(handle, BBM_COEF00, 0x02);
  106. bbm_byte_write(handle, BBM_COEF01, 0x02);
  107. bbm_byte_write(handle, BBM_COEF02, 0x00);
  108. bbm_byte_write(handle, BBM_COEF03, 0x0c);
  109. bbm_byte_write(handle, BBM_COEF04, 0x1c);
  110. bbm_byte_write(handle, BBM_COEF05, 0x1f);
  111. bbm_byte_write(handle, BBM_COEF06, 0x05);
  112. bbm_byte_write(handle, BBM_COEF07, 0x08);
  113. bbm_byte_write(handle, BBM_COEF08, 0x04);
  114. bbm_byte_write(handle, BBM_COEF09, 0x3a);
  115. bbm_byte_write(handle, BBM_COEF0A, 0x31);
  116. bbm_byte_write(handle, BBM_COEF0B, 0x34);
  117. bbm_byte_write(handle, BBM_COEF0C, 0x07);
  118. bbm_byte_write(handle, BBM_COEF0D, 0x26);
  119. bbm_byte_write(handle, BBM_COEF0E, 0x42);
  120. bbm_byte_write(handle, BBM_COEF0F, 0x4e);
  121. #elif (FC8080_FREQ_XTAL == 26000)
  122. bbm_long_write(handle, BBM_NCO_OFFSET, 0x03c7ea98);
  123. bbm_byte_write(handle, BBM_NCO_INV, 0x87);
  124. bbm_byte_write(handle, BBM_EZ_CONST, 0x79);
  125. bbm_byte_write(handle, BBM_CLK_MODE, 0x02);
  126. /* filter coefficient */
  127. bbm_byte_write(handle, BBM_COEF00, 0x0f);
  128. bbm_byte_write(handle, BBM_COEF01, 0x0d);
  129. bbm_byte_write(handle, BBM_COEF02, 0x0f);
  130. bbm_byte_write(handle, BBM_COEF03, 0x03);
  131. bbm_byte_write(handle, BBM_COEF04, 0x04);
  132. bbm_byte_write(handle, BBM_COEF05, 0x1f);
  133. bbm_byte_write(handle, BBM_COEF06, 0x19);
  134. bbm_byte_write(handle, BBM_COEF07, 0x1c);
  135. bbm_byte_write(handle, BBM_COEF08, 0x07);
  136. bbm_byte_write(handle, BBM_COEF09, 0x0b);
  137. bbm_byte_write(handle, BBM_COEF0A, 0x3f);
  138. bbm_byte_write(handle, BBM_COEF0B, 0x2d);
  139. bbm_byte_write(handle, BBM_COEF0C, 0xf2);
  140. bbm_byte_write(handle, BBM_COEF0D, 0x19);
  141. bbm_byte_write(handle, BBM_COEF0E, 0x4d);
  142. bbm_byte_write(handle, BBM_COEF0F, 0x65);
  143. #elif (FC8080_FREQ_XTAL == 27000)
  144. bbm_long_write(handle, BBM_NCO_OFFSET, 0x03a4114b);
  145. bbm_byte_write(handle, BBM_NCO_INV, 0x8d);
  146. bbm_byte_write(handle, BBM_EZ_CONST, 0x75);
  147. bbm_byte_write(handle, BBM_CLK_MODE, 0x02);
  148. /* filter coefficient */
  149. bbm_byte_write(handle, BBM_COEF00, 0x0e);
  150. bbm_byte_write(handle, BBM_COEF01, 0x0e);
  151. bbm_byte_write(handle, BBM_COEF02, 0x01);
  152. bbm_byte_write(handle, BBM_COEF03, 0x04);
  153. bbm_byte_write(handle, BBM_COEF04, 0x03);
  154. bbm_byte_write(handle, BBM_COEF05, 0x1d);
  155. bbm_byte_write(handle, BBM_COEF06, 0x19);
  156. bbm_byte_write(handle, BBM_COEF07, 0x1f);
  157. bbm_byte_write(handle, BBM_COEF08, 0x09);
  158. bbm_byte_write(handle, BBM_COEF09, 0x09);
  159. bbm_byte_write(handle, BBM_COEF0A, 0x3b);
  160. bbm_byte_write(handle, BBM_COEF0B, 0x2d);
  161. bbm_byte_write(handle, BBM_COEF0C, 0xf5);
  162. bbm_byte_write(handle, BBM_COEF0D, 0x1c);
  163. bbm_byte_write(handle, BBM_COEF0E, 0x4b);
  164. bbm_byte_write(handle, BBM_COEF0F, 0x61);
  165. #elif (FC8080_FREQ_XTAL == 27120)
  166. bbm_long_write(handle, BBM_NCO_OFFSET, 0x039ff180);
  167. bbm_byte_write(handle, BBM_NCO_INV, 0x8d);
  168. bbm_byte_write(handle, BBM_EZ_CONST, 0x74);
  169. bbm_byte_write(handle, BBM_CLK_MODE, 0x02);
  170. /* filter coefficient */
  171. bbm_byte_write(handle, BBM_COEF00, 0x0e);
  172. bbm_byte_write(handle, BBM_COEF01, 0x0e);
  173. bbm_byte_write(handle, BBM_COEF02, 0x01);
  174. bbm_byte_write(handle, BBM_COEF03, 0x04);
  175. bbm_byte_write(handle, BBM_COEF04, 0x03);
  176. bbm_byte_write(handle, BBM_COEF05, 0x1d);
  177. bbm_byte_write(handle, BBM_COEF06, 0x19);
  178. bbm_byte_write(handle, BBM_COEF07, 0x1f);
  179. bbm_byte_write(handle, BBM_COEF08, 0x09);
  180. bbm_byte_write(handle, BBM_COEF09, 0x09);
  181. bbm_byte_write(handle, BBM_COEF0A, 0x3b);
  182. bbm_byte_write(handle, BBM_COEF0B, 0x2d);
  183. bbm_byte_write(handle, BBM_COEF0C, 0xf5);
  184. bbm_byte_write(handle, BBM_COEF0D, 0x1c);
  185. bbm_byte_write(handle, BBM_COEF0E, 0x4b);
  186. bbm_byte_write(handle, BBM_COEF0F, 0x61);
  187. #elif (FC8080_FREQ_XTAL == 32000)
  188. bbm_long_write(handle, BBM_NCO_OFFSET, 0x03126eb8);
  189. bbm_byte_write(handle, BBM_NCO_INV, 0xa7);
  190. bbm_byte_write(handle, BBM_EZ_CONST, 0x62);
  191. bbm_byte_write(handle, BBM_CLK_MODE, 0x02);
  192. /* filter coefficient */
  193. bbm_byte_write(handle, BBM_COEF00, 0x0e);
  194. bbm_byte_write(handle, BBM_COEF01, 0x0e);
  195. bbm_byte_write(handle, BBM_COEF02, 0x01);
  196. bbm_byte_write(handle, BBM_COEF03, 0x04);
  197. bbm_byte_write(handle, BBM_COEF04, 0x03);
  198. bbm_byte_write(handle, BBM_COEF05, 0x1d);
  199. bbm_byte_write(handle, BBM_COEF06, 0x19);
  200. bbm_byte_write(handle, BBM_COEF07, 0x1f);
  201. bbm_byte_write(handle, BBM_COEF08, 0x09);
  202. bbm_byte_write(handle, BBM_COEF09, 0x09);
  203. bbm_byte_write(handle, BBM_COEF0A, 0x3b);
  204. bbm_byte_write(handle, BBM_COEF0B, 0x3d);
  205. bbm_byte_write(handle, BBM_COEF0C, 0xf5);
  206. bbm_byte_write(handle, BBM_COEF0D, 0x1c);
  207. bbm_byte_write(handle, BBM_COEF0E, 0x4b);
  208. bbm_byte_write(handle, BBM_COEF0F, 0x61);
  209. #elif (FC8080_FREQ_XTAL == 38400)
  210. bbm_long_write(handle, BBM_NCO_OFFSET, 0x0369d037);
  211. bbm_byte_write(handle, BBM_NCO_INV, 0x96);
  212. bbm_byte_write(handle, BBM_EZ_CONST, 0x6d);
  213. bbm_byte_write(handle, BBM_CLK_MODE, 0x01);
  214. /* filter coefficient */
  215. bbm_byte_write(handle, BBM_COEF00, 0x0e);
  216. bbm_byte_write(handle, BBM_COEF01, 0x00);
  217. bbm_byte_write(handle, BBM_COEF02, 0x03);
  218. bbm_byte_write(handle, BBM_COEF03, 0x03);
  219. bbm_byte_write(handle, BBM_COEF04, 0x1f);
  220. bbm_byte_write(handle, BBM_COEF05, 0x1a);
  221. bbm_byte_write(handle, BBM_COEF06, 0x1b);
  222. bbm_byte_write(handle, BBM_COEF07, 0x03);
  223. bbm_byte_write(handle, BBM_COEF08, 0x0a);
  224. bbm_byte_write(handle, BBM_COEF09, 0x05);
  225. bbm_byte_write(handle, BBM_COEF0A, 0x37);
  226. bbm_byte_write(handle, BBM_COEF0B, 0x2d);
  227. bbm_byte_write(handle, BBM_COEF0C, 0xfa);
  228. bbm_byte_write(handle, BBM_COEF0D, 0x1f);
  229. bbm_byte_write(handle, BBM_COEF0E, 0x49);
  230. bbm_byte_write(handle, BBM_COEF0F, 0x5c);
  231. #endif
  232. return BBM_OK;
  233. }
  234. s32 fc8080_reset(HANDLE handle)
  235. {
  236. bbm_write(handle, BBM_MD_RESET, 0xfe);
  237. ms_wait(1);
  238. bbm_write(handle, BBM_MD_RESET, 0xff);
  239. return BBM_OK;
  240. }
  241. s32 fc8080_probe(HANDLE handle)
  242. {
  243. u16 ver;
  244. bbm_word_read(handle, BBM_CHIP_ID, &ver);
  245. printk(KERN_DEBUG "TDMB %s : ver(0x%x)\n", __func__, ver);
  246. return (ver == 0x8080) ? BBM_OK : BBM_NOK;
  247. }
  248. s32 fc8080_init(HANDLE handle)
  249. {
  250. #ifdef FC8080_I2C
  251. bbm_write(handle, BBM_TSO_SELREG, 0xc4);
  252. #endif
  253. fc8080_reset(handle);
  254. fc8080_set_xtal(handle);
  255. bbm_write(handle, BBM_LDO_VCTRL, 0x35);
  256. bbm_write(handle, BBM_XTAL_CCTRL, 0x14);
  257. bbm_write(handle, BBM_RF_XTAL_EN, 0x0f);
  258. bbm_write(handle, BBM_ADC_OPMODE, 0x67);
  259. /*bbm_write(handle, BBM_FIC_CFG_CRC16, 0x03);*/
  260. bbm_word_write(handle, BBM_OFDM_DET_MAX_THRESHOLD, 0x0a00);
  261. bbm_write(handle, BBM_FTOFFSET_RANGE, 0x20);
  262. bbm_write(handle, BBM_AGC530_EN, 0x53);
  263. bbm_write(handle, BBM_BLOCK_AVG_SIZE_LOCK, 0x49);
  264. bbm_word_write(handle, BBM_GAIN_CONSTANT, 0x0303);
  265. bbm_write(handle, BBM_DET_CNT_BOUND, 0x60);
  266. bbm_write(handle, BBM_UNLOCK_DETECT_EN, 0x00);
  267. bbm_write(handle, BBM_DCE_CTRL, 0x27);
  268. bbm_write(handle, BBM_PGA_GAIN_MAX, 0x18);
  269. bbm_write(handle, BBM_PGA_GAIN_MIN, 0xe8);
  270. #if (FC8080_FREQ_XTAL == 24000)
  271. bbm_write(handle, BBM_SYNC_MTH, 0x43);
  272. #else
  273. bbm_write(handle, BBM_SYNC_MTH, 0xc3);
  274. #endif
  275. #if (FC8080_FREQ_XTAL == 16384) || (FC8080_FREQ_XTAL == 24576)
  276. bbm_write(handle, BBM_SFSYNC_ON, 0x00);
  277. #else
  278. bbm_write(handle, BBM_SFSYNC_ON, 0x01);
  279. #endif
  280. bbm_write(handle, BBM_RESYNC_EN, 0x01);
  281. bbm_write(handle, BBM_RESYNC_AUTO_CONDITION_EN, 0x00);
  282. bbm_write(handle, BBM_MSC_CFG_SPD, 0xff);
  283. #if defined(POWER_SAVE_MODE)
  284. bbm_write(handle, BBM_PS0_RF_ENABLE, 0x06);
  285. bbm_write(handle, BBM_PS1_ADC_ENABLE, 0x07);
  286. bbm_write(handle, BBM_PS2_BB_ENABLE, 0x07);
  287. bbm_write(handle, BBM_PS2_BB_ADD_SHIFT, 0x21);
  288. #else
  289. bbm_write(handle, BBM_PS0_RF_ENABLE, 0x04);
  290. bbm_write(handle, BBM_PS1_ADC_ENABLE, 0x05);
  291. bbm_write(handle, BBM_PS2_BB_ENABLE, 0x05);
  292. #endif
  293. bbm_write(handle, BBM_PS1_ADC_ADD_SHIFT, 0x71);
  294. bbm_word_write(handle, BBM_BUF_FIC_START, FIC_BUF_START);
  295. bbm_word_write(handle, BBM_BUF_FIC_END, FIC_BUF_END);
  296. bbm_word_write(handle, BBM_BUF_FIC_THR, FIC_BUF_THR);
  297. bbm_word_write(handle, BBM_BUF_CH0_START, CH0_BUF_START);
  298. bbm_word_write(handle, BBM_BUF_CH0_END, CH0_BUF_END);
  299. bbm_word_write(handle, BBM_BUF_CH0_THR, CH0_BUF_THR);
  300. bbm_word_write(handle, BBM_BUF_CH1_START, CH1_BUF_START);
  301. bbm_word_write(handle, BBM_BUF_CH1_END, CH1_BUF_END);
  302. bbm_word_write(handle, BBM_BUF_CH1_THR, CH1_BUF_THR);
  303. bbm_word_write(handle, BBM_BUF_CH2_START, CH2_BUF_START);
  304. bbm_word_write(handle, BBM_BUF_CH2_END, CH2_BUF_END);
  305. bbm_word_write(handle, BBM_BUF_CH2_THR, CH2_BUF_THR);
  306. bbm_write(handle, BBM_DM_CTRL, 0xa0);
  307. bbm_write(handle, BBM_OVERRUN_GAP, 0x06);
  308. bbm_word_write(handle, BBM_BUF_INT, 0x0107);
  309. bbm_word_write(handle, BBM_BUF_ENABLE, 0x0000);
  310. #ifdef FC8080_I2C
  311. bbm_write(handle, BBM_TSO_CLKDIV, 0x01);
  312. #else
  313. bbm_write(handle, BBM_MD_INT_EN, BBM_MF_INT);
  314. bbm_write(handle, BBM_MD_INT_STATUS, BBM_MF_INT);
  315. #endif
  316. return BBM_OK;
  317. }
  318. s32 fc8080_deinit(HANDLE handle)
  319. {
  320. bbm_write(handle, BBM_MD_RESET, 0x00);
  321. return BBM_OK;
  322. }
  323. s32 fc8080_channel_select(HANDLE handle, u8 subch_id, u8 buf_id)
  324. {
  325. u8 buf_en = 0;
  326. bbm_read(handle, BBM_BUF_ENABLE, &buf_en);
  327. bbm_write(handle, BBM_BUF_ENABLE, buf_en | (1 << buf_id));
  328. bbm_write(handle, BBM_SCH0_SET_IDI + buf_id, 0x40 | subch_id);
  329. return BBM_OK;
  330. }
  331. s32 fc8080_video_select(HANDLE handle, u8 subch_id, u8 buf_id, u8 cdi_id)
  332. {
  333. u16 fec_en = 0;
  334. if (cdi_id == 0) {
  335. bbm_write(handle, BBM_FEC_RST, 0x1c);
  336. bbm_write(handle, BBM_FEC_RST, 0x00);
  337. }
  338. bbm_word_read(handle, BBM_MSC_CFG_SCH0, &fec_en);
  339. if ((fec_en & 0x00ff) && (fec_en & 0xff00) && cdi_id == 0) {
  340. bbm_write(handle, BBM_FEC_ON, 0x00);
  341. bbm_write(handle, BBM_MSC_CFG_SCH0 + cdi_id, 0x00);
  342. bbm_write(handle, BBM_MSC_CFG_SCH0 + cdi_id, fec_en & 0x00ff);
  343. bbm_write(handle, BBM_FEC_ON, 0x01);
  344. }
  345. if (fc8080_channel_select(handle, subch_id, buf_id) != BBM_OK)
  346. return BBM_NOK;
  347. bbm_write(handle, BBM_MSC_CFG_SCH0 + cdi_id, 0x40 | subch_id);
  348. bbm_write(handle, BBM_BUF_CH0_SUBID + buf_id, 0x40 | subch_id);
  349. return BBM_OK;
  350. }
  351. s32 fc8080_audio_select(HANDLE handle, u8 subch_id, u8 buf_id)
  352. {
  353. if (fc8080_channel_select(handle, subch_id, buf_id) != BBM_OK)
  354. return BBM_NOK;
  355. bbm_write(handle, BBM_BUF_CH0_SUBID + buf_id, 0x40 | subch_id);
  356. return BBM_OK;
  357. }
  358. s32 fc8080_data_select(HANDLE handle, u8 subch_id, u8 buf_id)
  359. {
  360. if (fc8080_channel_select(handle, subch_id, buf_id) != BBM_OK)
  361. return BBM_NOK;
  362. bbm_write(handle, BBM_BUF_CH0_SUBID + buf_id, 0x40 | subch_id);
  363. return BBM_OK;
  364. }
  365. s32 fc8080_channel_deselect(HANDLE handle, u8 subch_id, u8 buf_id)
  366. {
  367. u8 buf_en = 0;
  368. bbm_read(handle, BBM_BUF_ENABLE, &buf_en);
  369. bbm_write(handle, BBM_BUF_ENABLE, buf_en & (~(1 << buf_id)));
  370. bbm_write(handle, BBM_SCH0_SET_IDI + buf_id, 0);
  371. return BBM_OK;
  372. }
  373. s32 fc8080_video_deselect(HANDLE handle, u8 subch_id, u8 buf_id, u8 cdi_id)
  374. {
  375. u16 fec_en = 0;
  376. u8 buf_en = 0;
  377. bbm_write(handle, BBM_BUF_CH0_SUBID + buf_id, 0x00);
  378. bbm_word_read(handle, BBM_MSC_CFG_SCH0, &fec_en);
  379. if (!((fec_en & 0xff00) && (fec_en & 0x00ff) && cdi_id == 0))
  380. bbm_write(handle, BBM_MSC_CFG_SCH0 + cdi_id, 0x00);
  381. if (fc8080_channel_deselect(handle, subch_id, buf_id) != BBM_OK)
  382. return BBM_NOK;
  383. bbm_read(handle, BBM_BUF_CH0_SUBID, &buf_en);
  384. if (buf_en == 0 && (fec_en & 0xff00) && cdi_id == 1)
  385. bbm_write(handle, BBM_MSC_CFG_SCH0, 0x00);
  386. return BBM_OK;
  387. }
  388. s32 fc8080_audio_deselect(HANDLE handle, u8 subch_id, u8 buf_id)
  389. {
  390. if (fc8080_channel_deselect(handle, subch_id, buf_id) != BBM_OK)
  391. return BBM_NOK;
  392. bbm_write(handle, BBM_BUF_CH0_SUBID + buf_id, 0);
  393. return BBM_OK;
  394. }
  395. s32 fc8080_data_deselect(HANDLE handle, u8 subch_id, u8 buf_id)
  396. {
  397. if (fc8080_channel_deselect(handle, subch_id, buf_id) != BBM_OK)
  398. return BBM_NOK;
  399. bbm_write(handle, BBM_BUF_CH0_SUBID + buf_id, 0);
  400. return BBM_OK;
  401. }
  402. s32 fc8080_scan_status(HANDLE handle)
  403. {
  404. s32 i, res = BBM_NOK;
  405. u8 mode = 0, status = 0, sync_status = 0;
  406. s32 slock_cnt, flock_cnt, dlock_cnt;
  407. bbm_read(handle, BBM_OFDM_DET, &mode);
  408. if ((mode & 0x01) == 0x01) {
  409. slock_cnt = SLOCK_MAX_TIME / LOCK_TIME_TICK;
  410. flock_cnt = FLOCK_MAX_TIME / LOCK_TIME_TICK;
  411. dlock_cnt = DLOCK_MAX_TIME / LOCK_TIME_TICK;
  412. /* OFDM Detect */
  413. for (i = 0; i < slock_cnt; i++) {
  414. ms_wait(LOCK_TIME_TICK);
  415. bbm_read(handle, BBM_DETECT_OFDM, &status);
  416. if (status & 0x01)
  417. break;
  418. }
  419. if (i == slock_cnt) {
  420. printk(KERN_DEBUG "TDMB :status(0x%x) s(%d)\n",
  421. status, slock_cnt);
  422. return BBM_NOK;
  423. }
  424. if ((status & 0x02) == 0x00) {
  425. printk(KERN_DEBUG "TDMB %s : status(0x%x)\n",
  426. __func__, status);
  427. return BBM_NOK;
  428. }
  429. /* FRS */
  430. for (i += 1; i < flock_cnt; i++) {
  431. ms_wait(LOCK_TIME_TICK);
  432. bbm_read(handle, BBM_SYNC_STAT, &sync_status);
  433. if (sync_status & 0x01)
  434. break;
  435. }
  436. if (i == flock_cnt) {
  437. printk(KERN_DEBUG "TDMB %s : flock_cnt(0x%x)\n"
  438. , __func__
  439. , flock_cnt);
  440. return BBM_NOK;
  441. }
  442. /* Digital Lock */
  443. for (i += 1; i < dlock_cnt; i++) {
  444. ms_wait(LOCK_TIME_TICK);
  445. bbm_read(handle, BBM_SYNC_STAT, &sync_status);
  446. if (sync_status & 0x20) {
  447. printk(KERN_DEBUG "TDMB :sync_status(0x%x)\n",
  448. sync_status);
  449. return BBM_OK;
  450. }
  451. }
  452. } else {
  453. dlock_cnt = DLOCK_MAX_TIME / LOCK_TIME_TICK;
  454. for (i = 0; i < dlock_cnt; i++) {
  455. ms_wait(LOCK_TIME_TICK);
  456. bbm_read(handle, BBM_SYNC_STAT, &sync_status);
  457. if (sync_status & 0x20) {
  458. printk(KERN_DEBUG "TDMB :sync_status(0x%x)\n",
  459. sync_status);
  460. return BBM_OK;
  461. }
  462. }
  463. }
  464. printk(KERN_DEBUG "TDMB %s : res(0x%x)\n"
  465. , __func__, res);
  466. return res;
  467. }