halbtc8821cwifionly.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include "mp_precomp.h"
  2. static struct rfe_type_8821c_wifi_only gl_rfe_type_8821c_1ant;
  3. static struct rfe_type_8821c_wifi_only *rfe_type = &gl_rfe_type_8821c_1ant;
  4. VOID hal8821c_wifi_only_switch_antenna(
  5. IN struct wifi_only_cfg *pwifionlycfg,
  6. IN u1Byte is_5g
  7. )
  8. {
  9. boolean switch_polatiry_inverse = false;
  10. u8 regval_0xcb7 = 0;
  11. u8 pos_type, ctrl_type;
  12. if (!rfe_type->ext_ant_switch_exist)
  13. return;
  14. /* swap control polarity if use different switch control polarity*/
  15. /* Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux, 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */
  16. /* Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG, 0xcb4[29:28] = 2b'10 => Ant to WLG */
  17. if (rfe_type->ext_ant_switch_ctrl_polarity)
  18. switch_polatiry_inverse = !switch_polatiry_inverse;
  19. /* swap control polarity if 1-Ant at Aux */
  20. if (rfe_type->ant_at_main_port == false)
  21. switch_polatiry_inverse = !switch_polatiry_inverse;
  22. if (is_5g)
  23. pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA;
  24. else
  25. pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG;
  26. switch (pos_type) {
  27. default:
  28. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA:
  29. break;
  30. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG:
  31. if (!rfe_type->wlg_Locate_at_btg)
  32. switch_polatiry_inverse = !switch_polatiry_inverse;
  33. break;
  34. }
  35. if (pwifionlycfg->haldata_info.ant_div_cfg)
  36. ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV;
  37. else
  38. ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW;
  39. switch (ctrl_type) {
  40. default:
  41. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW:
  42. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2);
  43. /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
  44. halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff, 0x77);
  45. regval_0xcb7 = (switch_polatiry_inverse == false ? 0x1 : 0x2);
  46. /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
  47. halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x30000000, regval_0xcb7);
  48. break;
  49. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
  50. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2);
  51. /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
  52. halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff, 0x88);
  53. /* no regval_0xcb7 setup required, because antenna switch control value by antenna diversity */
  54. break;
  55. }
  56. }
  57. VOID halbtc8821c_wifi_only_set_rfe_type(
  58. IN struct wifi_only_cfg *pwifionlycfg
  59. )
  60. {
  61. /* the following setup should be got from Efuse in the future */
  62. rfe_type->rfe_module_type = (pwifionlycfg->haldata_info.rfe_type) & 0x1f;
  63. rfe_type->ext_ant_switch_ctrl_polarity = 0;
  64. switch (rfe_type->rfe_module_type) {
  65. case 0:
  66. default:
  67. rfe_type->ext_ant_switch_exist = true;
  68. rfe_type->ext_ant_switch_type =
  69. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, WLG*/
  70. rfe_type->wlg_Locate_at_btg = false;
  71. rfe_type->ant_at_main_port = true;
  72. break;
  73. case 1:
  74. rfe_type->ext_ant_switch_exist = true;
  75. rfe_type->ext_ant_switch_type =
  76. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, WLG */
  77. rfe_type->wlg_Locate_at_btg = false;
  78. rfe_type->ant_at_main_port = true;
  79. break;
  80. case 2:
  81. rfe_type->ext_ant_switch_exist = true;
  82. rfe_type->ext_ant_switch_type =
  83. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, BTG */
  84. rfe_type->wlg_Locate_at_btg = true;
  85. rfe_type->ant_at_main_port = true;
  86. break;
  87. case 3:
  88. rfe_type->ext_ant_switch_exist = true;
  89. rfe_type->ext_ant_switch_type =
  90. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, WLG */
  91. rfe_type->wlg_Locate_at_btg = false;
  92. rfe_type->ant_at_main_port = false;
  93. break;
  94. case 4:
  95. rfe_type->ext_ant_switch_exist = true;
  96. rfe_type->ext_ant_switch_type =
  97. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, BTG */
  98. rfe_type->wlg_Locate_at_btg = true;
  99. rfe_type->ant_at_main_port = false;
  100. break;
  101. case 5:
  102. rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/
  103. rfe_type->ext_ant_switch_type =
  104. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE;
  105. rfe_type->wlg_Locate_at_btg = false;
  106. rfe_type->ant_at_main_port = true;
  107. break;
  108. case 6:
  109. rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/
  110. rfe_type->ext_ant_switch_type =
  111. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE;
  112. rfe_type->wlg_Locate_at_btg = false;
  113. rfe_type->ant_at_main_port = true;
  114. break;
  115. case 7:
  116. rfe_type->ext_ant_switch_exist = true; /*2-Ant, DPDT, BTG*/
  117. rfe_type->ext_ant_switch_type =
  118. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT;
  119. rfe_type->wlg_Locate_at_btg = true;
  120. rfe_type->ant_at_main_port = true;
  121. break;
  122. }
  123. }
  124. VOID
  125. ex_hal8821c_wifi_only_hw_config(
  126. IN struct wifi_only_cfg *pwifionlycfg
  127. )
  128. {
  129. halbtc8821c_wifi_only_set_rfe_type(pwifionlycfg);
  130. /* set gnt_wl, gnt_bt control owner to WL*/
  131. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x70, 0x400000, 0x1);
  132. /*gnt_wl=1 , gnt_bt=0*/
  133. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1704, 0xffffffff, 0x7700);
  134. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1700, 0xffffffff, 0xc00f0038);
  135. }
  136. VOID
  137. ex_hal8821c_wifi_only_scannotify(
  138. IN struct wifi_only_cfg *pwifionlycfg,
  139. IN u1Byte is_5g
  140. )
  141. {
  142. hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
  143. }
  144. VOID
  145. ex_hal8821c_wifi_only_switchbandnotify(
  146. IN struct wifi_only_cfg *pwifionlycfg,
  147. IN u1Byte is_5g
  148. )
  149. {
  150. hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
  151. }