fci_tun.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #define FC8300_TUNER_ADDR 0x58
  27. struct I2C_DRV {
  28. int (*init)(HANDLE handle, DEVICEID devid,
  29. s32 speed, s32 slaveaddr);
  30. int (*read)(HANDLE handle, DEVICEID devid,
  31. u8 chip, u8 addr, u8 alen, u8 *data, u8 len);
  32. int (*write)(HANDLE handle, DEVICEID devid,
  33. u8 chip, u8 addr, u8 alen, u8 *data, u8 len);
  34. int (*deinit)(HANDLE handle, DEVICEID devid);
  35. };
  36. static struct I2C_DRV fcihpi = {
  37. &fci_hpi_init,
  38. &fci_hpi_read,
  39. &fci_hpi_write,
  40. &fci_hpi_deinit
  41. };
  42. struct TUNER_DRV {
  43. int (*init)(HANDLE handle, DEVICEID devid,
  44. enum BROADCAST_TYPE broadcast);
  45. int (*set_freq)(HANDLE handle, DEVICEID devid, u32 freq);
  46. int (*get_rssi)(HANDLE handle, DEVICEID devid, s32 *rssi);
  47. int (*deinit)(HANDLE handle, DEVICEID devid);
  48. };
  49. static struct TUNER_DRV fc8300_tuner = {
  50. &fc8300_tuner_init,
  51. &fc8300_set_freq,
  52. &fc8300_get_rssi,
  53. &fc8300_tuner_deinit
  54. };
  55. static u8 tuner_addr = FC8300_TUNER_ADDR;
  56. static enum BROADCAST_TYPE broadcast_type = ISDBT_13SEG;
  57. static enum I2C_TYPE tuner_i2c = FCI_HPI_TYPE;
  58. static struct I2C_DRV *tuner_ctrl = &fcihpi;
  59. static struct TUNER_DRV *tuner = &fc8300_tuner;
  60. s32 tuner_ctrl_select(HANDLE handle, DEVICEID devid, enum I2C_TYPE type)
  61. {
  62. switch (type) {
  63. case FCI_HPI_TYPE:
  64. tuner_ctrl = &fcihpi;
  65. break;
  66. default:
  67. return BBM_E_TN_CTRL_SELECT;
  68. }
  69. if (tuner_ctrl->init(handle, devid, 600, 0))
  70. return BBM_E_TN_CTRL_INIT;
  71. tuner_i2c = type;
  72. return BBM_OK;
  73. }
  74. s32 tuner_ctrl_deselect(HANDLE handle, DEVICEID devid)
  75. {
  76. if (tuner_ctrl == NULL)
  77. return BBM_E_TN_CTRL_SELECT;
  78. tuner_ctrl->deinit(handle, devid);
  79. tuner_ctrl = NULL;
  80. return BBM_OK;
  81. }
  82. s32 tuner_i2c_read(HANDLE handle, DEVICEID devid,
  83. u8 addr, u8 alen, u8 *data, u8 len)
  84. {
  85. if (tuner_ctrl == NULL)
  86. return BBM_E_TN_CTRL_SELECT;
  87. if (tuner_ctrl->read(handle, devid,
  88. tuner_addr, addr, alen, data, len))
  89. return BBM_E_TN_READ;
  90. return BBM_OK;
  91. }
  92. s32 tuner_i2c_write(HANDLE handle, DEVICEID devid,
  93. u8 addr, u8 alen, u8 *data, u8 len)
  94. {
  95. if (tuner_ctrl == NULL)
  96. return BBM_E_TN_CTRL_SELECT;
  97. if (tuner_ctrl->write(handle, devid,
  98. tuner_addr, addr, alen, data, len))
  99. return BBM_E_TN_WRITE;
  100. return BBM_OK;
  101. }
  102. s32 tuner_set_freq(HANDLE handle, DEVICEID devid, u32 freq, u8 subch)
  103. {
  104. #ifdef BBM_I2C_TSIF
  105. u8 tsif_en = 0;
  106. #endif
  107. if (tuner == NULL)
  108. return BBM_E_TN_SELECT;
  109. #ifdef BBM_I2C_TSIF
  110. if (devid == DIV_MASTER || devid == DIV_BROADCAST) {
  111. bbm_byte_read(handle, DIV_MASTER, BBM_TS_SEL, &tsif_en);
  112. bbm_byte_write(handle, DIV_MASTER, BBM_TS_SEL, tsif_en & 0x7f);
  113. }
  114. #endif
  115. fc8300_set_core_clk(handle, devid, broadcast_type, freq);
  116. bbm_byte_write(handle, devid, BBM_CENTER_CH_NUM, subch);
  117. switch (broadcast_type) {
  118. case ISDBT_1SEG:
  119. freq -= 380;
  120. break;
  121. case ISDBT_13SEG:
  122. break;
  123. }
  124. if (tuner->set_freq(handle, devid, freq))
  125. return BBM_E_TN_SET_FREQ;
  126. fc8300_reset(handle, devid);
  127. #ifdef BBM_I2C_TSIF
  128. if (devid == DIV_MASTER || devid == DIV_BROADCAST)
  129. bbm_byte_write(handle, DIV_MASTER, BBM_TS_SEL, tsif_en);
  130. #endif
  131. return BBM_OK;
  132. }
  133. s32 tuner_select(HANDLE handle, DEVICEID devid,
  134. enum PRODUCT_TYPE product, enum BROADCAST_TYPE broadcast)
  135. {
  136. switch (product) {
  137. case FC8300_TUNER:
  138. tuner = &fc8300_tuner;
  139. tuner_addr = FC8300_TUNER_ADDR;
  140. broadcast_type = broadcast;
  141. break;
  142. }
  143. if (tuner == NULL)
  144. return BBM_E_TN_SELECT;
  145. if (tuner->init(handle, devid, broadcast))
  146. return BBM_E_TN_INIT;
  147. fc8300_set_broadcast_mode(handle, devid, broadcast);
  148. return BBM_OK;
  149. }
  150. s32 tuner_deselect(HANDLE handle, DEVICEID devid)
  151. {
  152. if (tuner == NULL)
  153. return BBM_E_TN_SELECT;
  154. if (tuner->deinit(handle, devid))
  155. return BBM_NOK;
  156. tuner = NULL;
  157. return BBM_OK;
  158. }
  159. s32 tuner_get_rssi(HANDLE handle, DEVICEID devid, s32 *rssi)
  160. {
  161. if (tuner == NULL)
  162. return BBM_E_TN_SELECT;
  163. if (tuner->get_rssi(handle, devid, rssi))
  164. return BBM_E_TN_RSSI;
  165. return BBM_OK;
  166. }