fci_tun.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fci_tun.c
  4. Description : source of tuner control 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. *******************************************************************************/
  19. #include "fci_types.h"
  20. #include "fc8300_regs.h"
  21. #include "fci_hal.h"
  22. #include "fci_tun.h"
  23. #include "fci_hpi.h"
  24. #include "fc8300_bb.h"
  25. #include "fc8300_tun.h"
  26. #include "fci_oal.h"
  27. #define FC8300_TUNER_ADDR 0x58
  28. struct I2C_DRV {
  29. int (*init)(HANDLE handle, DEVICEID devid,
  30. s32 speed, s32 slaveaddr);
  31. int (*read)(HANDLE handle, DEVICEID devid,
  32. u8 chip, u8 addr, u8 alen, u8 *data, u8 len);
  33. int (*write)(HANDLE handle, DEVICEID devid,
  34. u8 chip, u8 addr, u8 alen, u8 *data, u8 len);
  35. int (*deinit)(HANDLE handle, DEVICEID devid);
  36. };
  37. static struct I2C_DRV fcihpi = {
  38. &fci_hpi_init,
  39. &fci_hpi_read,
  40. &fci_hpi_write,
  41. &fci_hpi_deinit
  42. };
  43. struct TUNER_DRV {
  44. int (*init)(HANDLE handle, DEVICEID devid,
  45. enum BROADCAST_TYPE broadcast);
  46. int (*set_freq)(HANDLE handle, DEVICEID devid, u32 freq);
  47. int (*get_rssi)(HANDLE handle, DEVICEID devid, s32 *rssi);
  48. int (*deinit)(HANDLE handle, DEVICEID devid);
  49. };
  50. static struct TUNER_DRV fc8300_tuner = {
  51. &fc8300_tuner_init,
  52. &fc8300_set_freq,
  53. &fc8300_get_rssi,
  54. &fc8300_tuner_deinit
  55. };
  56. static u8 tuner_addr = FC8300_TUNER_ADDR;
  57. static enum BROADCAST_TYPE broadcast_type = ISDBT_13SEG;
  58. static enum I2C_TYPE tuner_i2c = FCI_HPI_TYPE;
  59. static struct I2C_DRV *tuner_ctrl = &fcihpi;
  60. static struct TUNER_DRV *tuner = &fc8300_tuner;
  61. s32 tuner_ctrl_select(HANDLE handle, DEVICEID devid, enum I2C_TYPE type)
  62. {
  63. print_log(0," %s\n",__func__);
  64. switch (type) {
  65. case FCI_HPI_TYPE:
  66. print_log(0," FCI_HPI_TYPE\n");
  67. tuner_ctrl = &fcihpi;
  68. break;
  69. default:
  70. print_log(0," DEFAULT ERROR\n");
  71. return BBM_E_TN_CTRL_SELECT;
  72. }
  73. if (tuner_ctrl->init(handle, devid, 600, 0))
  74. return BBM_E_TN_CTRL_INIT;
  75. tuner_i2c = type;
  76. return BBM_OK;
  77. }
  78. s32 tuner_ctrl_deselect(HANDLE handle, DEVICEID devid)
  79. {
  80. print_log(0," %s\n",__func__);
  81. if (tuner_ctrl == NULL)
  82. return BBM_E_TN_CTRL_SELECT;
  83. tuner_ctrl->deinit(handle, devid);
  84. tuner_ctrl = NULL;
  85. return BBM_OK;
  86. }
  87. s32 tuner_i2c_read(HANDLE handle, DEVICEID devid,
  88. u8 addr, u8 alen, u8 *data, u8 len)
  89. {
  90. if (tuner_ctrl == NULL)
  91. return BBM_E_TN_CTRL_SELECT;
  92. if (tuner_ctrl->read(handle, devid,
  93. tuner_addr, addr, alen, data, len))
  94. return BBM_E_TN_READ;
  95. return BBM_OK;
  96. }
  97. s32 tuner_i2c_write(HANDLE handle, DEVICEID devid,
  98. u8 addr, u8 alen, u8 *data, u8 len)
  99. {
  100. if (tuner_ctrl == NULL)
  101. return BBM_E_TN_CTRL_SELECT;
  102. if (tuner_ctrl->write(handle, devid,
  103. tuner_addr, addr, alen, data, len))
  104. return BBM_E_TN_WRITE;
  105. return BBM_OK;
  106. }
  107. s32 tuner_set_freq(HANDLE handle, DEVICEID devid, u32 freq, u8 subch)
  108. {
  109. #ifdef BBM_I2C_TSIF
  110. u8 tsif_en = 0;
  111. #endif
  112. if (tuner == NULL)
  113. return BBM_E_TN_SELECT;
  114. #ifdef BBM_I2C_TSIF
  115. if (devid == DIV_MASTER || devid == DIV_BROADCAST) {
  116. bbm_byte_read(handle, DIV_MASTER, BBM_TS_SEL, &tsif_en);
  117. bbm_byte_write(handle, DIV_MASTER, BBM_TS_SEL, tsif_en & 0x7f);
  118. }
  119. #endif
  120. fc8300_set_core_clk(handle, devid, broadcast_type, freq);
  121. bbm_byte_write(handle, devid, BBM_CENTER_CH_NUM, subch);
  122. switch (broadcast_type) {
  123. case ISDBT_1SEG:
  124. case ISDBTMM_1SEG:
  125. case ISDBTSB_1SEG:
  126. case ISDBT_CATV_1SEG:
  127. freq -= 380;
  128. break;
  129. case ISDBTSB_3SEG:
  130. #if (BBM_BAND_WIDTH == 6)
  131. freq -= 1000;
  132. #elif (BBM_BAND_WIDTH == 7)
  133. freq -= 1170;
  134. #else /* BBM)BAND_WIDTH == 8 */
  135. freq -= 1330;
  136. #endif
  137. break;
  138. case ISDBT_13SEG:
  139. case ISDBTMM_13SEG:
  140. case ISDBT_CATV_13SEG:
  141. break;
  142. }
  143. if (tuner->set_freq(handle, devid, freq))
  144. return BBM_E_TN_SET_FREQ;
  145. fc8300_reset(handle, devid);
  146. #ifdef BBM_I2C_TSIF
  147. if (devid == DIV_MASTER || devid == DIV_BROADCAST)
  148. bbm_byte_write(handle, DIV_MASTER, BBM_TS_SEL, tsif_en);
  149. #endif
  150. return BBM_OK;
  151. }
  152. s32 tuner_select(HANDLE handle, DEVICEID devid,
  153. enum PRODUCT_TYPE product, enum BROADCAST_TYPE broadcast)
  154. {
  155. switch (product) {
  156. case FC8300_TUNER:
  157. tuner = &fc8300_tuner;
  158. tuner_addr = FC8300_TUNER_ADDR;
  159. broadcast_type = broadcast;
  160. break;
  161. }
  162. if (tuner == NULL)
  163. {
  164. print_log(0,"ERROR tuner == NULL\n");
  165. return BBM_E_TN_SELECT;
  166. }
  167. if (tuner->init(handle, devid, broadcast))
  168. {
  169. print_log(0,"tuner->init\n");
  170. return BBM_E_TN_INIT;
  171. }
  172. fc8300_set_broadcast_mode(handle, devid, broadcast);
  173. #ifdef BBM_ES
  174. if (product == FC8300_TUNER) {
  175. u8 chip_ver = 0x00;
  176. tuner_i2c_read(handle, devid, 0xff, 1, &chip_ver, 1);
  177. if (chip_ver == 0xc0)
  178. return BBM_OK;
  179. bbm_byte_write(handle, DIV_MASTER, BBM_RESYNC_ENABLE, 0xcf);
  180. bbm_long_write(handle, DIV_BROADCAST, BBM_MEMORY_RWM0,
  181. 0x05555555);
  182. bbm_byte_write(handle, DIV_BROADCAST, BBM_SFS_FTS_ERR_MAX_1SEG,
  183. 0x08);
  184. bbm_byte_write(handle, DIV_BROADCAST, BBM_SFS_FTS_ERR_MAX_3SEG,
  185. 0x08);
  186. bbm_byte_write(handle, DIV_BROADCAST, BBM_PGA_GAIN_MAX, 0x0c);
  187. bbm_byte_write(handle, DIV_BROADCAST, BBM_CSF_GAIN_MAX, 0x09);
  188. bbm_byte_write(handle, DIV_MASTER, BBM_FD_OUT_MODE, 0x03);
  189. bbm_byte_write(handle, DIV_MASTER, BBM_DIV_START_MODE, 0x17);
  190. bbm_byte_write(handle, DIV_BROADCAST,
  191. BBM_PSAT_ON_REF_1SEG_QPSK, 0x1a);
  192. bbm_byte_write(handle, DIV_BROADCAST,
  193. BBM_PSAT_ON_REF_1SEG_16QAM, 0x1b);
  194. switch (broadcast) {
  195. case ISDBT_1SEG:
  196. case ISDBTMM_1SEG:
  197. case ISDBTSB_1SEG:
  198. case ISDBT_CATV_1SEG:
  199. case ISDBTSB_3SEG:
  200. bbm_byte_write(handle, DIV_BROADCAST, BBM_SFS_MTH,
  201. 0x32);
  202. break;
  203. case ISDBT_13SEG:
  204. case ISDBTMM_13SEG:
  205. case ISDBT_CATV_13SEG:
  206. bbm_byte_write(handle, DIV_BROADCAST, BBM_SFS_MTH,
  207. 0x31);
  208. break;
  209. }
  210. #if defined(BBM_2_DIVERSITY) || defined(BBM_4_DIVERSITY)
  211. bbm_byte_write(handle, DIV_MASTER, BBM_XTAL_OUTBUF_EN, 0x00);
  212. bbm_byte_write(handle, DIV_MASTER, BBM_XTAL_OUTBUF_GAIN, 0x03);
  213. bbm_word_write(handle, DIV_BROADCAST, BBM_FD_RD_LATENCY_1SEG,
  214. 0x1840);
  215. bbm_byte_write(handle, DIV_BROADCAST, BBM_COMB_OFF, 0x80);
  216. #else /* SINGLE */
  217. bbm_word_write(handle, DIV_BROADCAST, BBM_FD_RD_LATENCY_1SEG,
  218. 0x0002);
  219. #endif /* #if defined(BBM_2_DIVERSITY) || defined(BBM_4_DIVERSITY) */
  220. }
  221. #endif /* #ifdef BBM_ES */
  222. return BBM_OK;
  223. }
  224. s32 tuner_deselect(HANDLE handle, DEVICEID devid)
  225. {
  226. if (tuner == NULL)
  227. return BBM_E_TN_SELECT;
  228. if (tuner->deinit(handle, devid))
  229. return BBM_NOK;
  230. tuner = NULL;
  231. return BBM_OK;
  232. }
  233. s32 tuner_get_rssi(HANDLE handle, DEVICEID devid, s32 *rssi)
  234. {
  235. if (tuner == NULL)
  236. return BBM_E_TN_SELECT;
  237. if (tuner->get_rssi(handle, devid, rssi))
  238. return BBM_E_TN_RSSI;
  239. return BBM_OK;
  240. }