fci_tun.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*****************************************************************************
  2. Copyright(c) 2012 FCI Inc. All Rights Reserved
  3. File name : fci_tun.c
  4. Description : tuner control driver
  5. *******************************************************************************/
  6. #include "fci_types.h"
  7. #include "fci_oal.h"
  8. #include "fci_hal.h"
  9. #include "fci_tun.h"
  10. #include "fci_i2c.h"
  11. #include "fci_bypass.h"
  12. #include "fc8150_regs.h"
  13. #include "fc8150_bb.h"
  14. #include "fc8150_tun.h"
  15. #define FC8150_TUNER_ADDR 0x5b
  16. static u8 tuner_addr = FC8150_TUNER_ADDR;
  17. static enum band_type tuner_band = ISDBT_1_SEG_TYPE;
  18. static enum i2c_type tuner_i2c = FCI_I2C_TYPE;
  19. struct I2C_DRV{
  20. int (*init)(HANDLE hDevice, int speed, int slaveaddr);
  21. int (*read)(HANDLE hDevice, u8 chip, u8 addr
  22. , u8 alen, u8 *data, u8 len);
  23. int (*write)(HANDLE hDevice, u8 chip, u8 addr
  24. , u8 alen, u8 *data, u8 len);
  25. int (*deinit)(HANDLE hDevice);
  26. };
  27. static struct I2C_DRV fcii2c = {
  28. &fci_i2c_init,
  29. &fci_i2c_read,
  30. &fci_i2c_write,
  31. &fci_i2c_deinit
  32. };
  33. static struct I2C_DRV fcibypass = {
  34. &fci_bypass_init,
  35. &fci_bypass_read,
  36. &fci_bypass_write,
  37. &fci_bypass_deinit
  38. };
  39. struct TUNER_DRV{
  40. int (*init)(HANDLE hDevice, enum band_type band);
  41. int (*set_freq)(HANDLE hDevice
  42. , enum band_type band, u32 rf_Khz);
  43. int (*get_rssi)(HANDLE hDevice, int *rssi);
  44. int (*deinit)(HANDLE hDevice);
  45. };
  46. static struct TUNER_DRV fc8150_tuner = {
  47. &fc8150_tuner_init,
  48. &fc8150_set_freq,
  49. &fc8150_get_rssi,
  50. &fc8150_tuner_deinit
  51. };
  52. #if 0
  53. static TUNER_DRV fc8151_tuner = {
  54. &fc8151_tuner_init,
  55. &fc8151_set_freq,
  56. &fc8151_get_rssi,
  57. &fc8151_tuner_deinit
  58. };
  59. #endif
  60. static struct I2C_DRV *tuner_ctrl = &fcii2c;
  61. static struct TUNER_DRV *tuner = &fc8150_tuner;
  62. int tuner_ctrl_select(HANDLE hDevice, enum i2c_type type)
  63. {
  64. switch (type) {
  65. case FCI_I2C_TYPE:
  66. tuner_ctrl = &fcii2c;
  67. break;
  68. case FCI_BYPASS_TYPE:
  69. tuner_ctrl = &fcibypass;
  70. break;
  71. default:
  72. return BBM_E_TN_CTRL_SELECT;
  73. }
  74. if (tuner_ctrl->init(hDevice, 600, 0))
  75. return BBM_E_TN_CTRL_INIT;
  76. tuner_i2c = type;
  77. return BBM_OK;
  78. }
  79. int tuner_ctrl_deselect(HANDLE hDevice)
  80. {
  81. if (tuner_ctrl == NULL)
  82. return BBM_E_TN_CTRL_SELECT;
  83. tuner_ctrl->deinit(hDevice);
  84. tuner_i2c = FCI_I2C_TYPE;
  85. tuner_ctrl = &fcii2c;
  86. return BBM_OK;
  87. }
  88. int tuner_i2c_read(HANDLE hDevice, 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(hDevice, tuner_addr, addr, alen, data, len))
  93. return BBM_E_TN_READ;
  94. return BBM_OK;
  95. }
  96. int tuner_i2c_write(HANDLE hDevice, u8 addr, u8 alen, u8 *data, u8 len)
  97. {
  98. if (tuner_ctrl == NULL)
  99. return BBM_E_TN_CTRL_SELECT;
  100. if (tuner_ctrl->write(hDevice, tuner_addr, addr, alen, data, len))
  101. return BBM_E_TN_WRITE;
  102. return BBM_OK;
  103. }
  104. int tuner_set_freq(HANDLE hDevice, u32 freq)
  105. {
  106. if (tuner == NULL)
  107. return BBM_E_TN_SELECT;
  108. #if (BBM_BAND_WIDTH == 8)
  109. freq -= 460;
  110. #else
  111. freq -= 380;
  112. #endif
  113. if (tuner->set_freq(hDevice, tuner_band, freq))
  114. return BBM_E_TN_SET_FREQ;
  115. fc8150_reset(hDevice);
  116. return BBM_OK;
  117. }
  118. int tuner_select(HANDLE hDevice, u32 product, u32 band)
  119. {
  120. switch (product) {
  121. case FC8150_TUNER:
  122. tuner = &fc8150_tuner;
  123. tuner_addr = FC8150_TUNER_ADDR;
  124. tuner_band = band;
  125. break;
  126. #if 0
  127. case FC8151_TUNER:
  128. tuner = &fc8151_tuner;
  129. tuner_addr = FC8150_TUNER_ADDR;
  130. tuner_band = band;
  131. break;
  132. #endif
  133. default:
  134. return BBM_E_TN_SELECT;
  135. }
  136. if (tuner == NULL)
  137. return BBM_E_TN_SELECT;
  138. if (tuner_i2c == FCI_BYPASS_TYPE)
  139. bbm_write(hDevice, BBM_RF_DEVID, tuner_addr);
  140. if (tuner->init(hDevice, tuner_band))
  141. return BBM_E_TN_INIT;
  142. return BBM_OK;
  143. }
  144. int tuner_deselect(HANDLE hDevice)
  145. {
  146. if (tuner == NULL)
  147. return BBM_E_TN_SELECT;
  148. if (tuner->deinit(hDevice))
  149. return BBM_NOK;
  150. tuner = NULL;
  151. return BBM_OK;
  152. }
  153. int tuner_get_rssi(HANDLE hDevice, s32 *rssi)
  154. {
  155. if (tuner == NULL)
  156. return BBM_E_TN_SELECT;
  157. if (tuner->get_rssi(hDevice, rssi))
  158. return BBM_E_TN_RSSI;
  159. return BBM_OK;
  160. }