halbtc8821cwifionly.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2016 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #include "mp_precomp.h"
  16. static struct rfe_type_8821c_wifi_only gl_rfe_type_8821c_1ant;
  17. static struct rfe_type_8821c_wifi_only *rfe_type = &gl_rfe_type_8821c_1ant;
  18. VOID hal8821c_wifi_only_switch_antenna(
  19. IN struct wifi_only_cfg *pwifionlycfg,
  20. IN u1Byte is_5g
  21. )
  22. {
  23. boolean switch_polatiry_inverse = false;
  24. u8 regval_0xcb7 = 0;
  25. u8 pos_type, ctrl_type;
  26. if (!rfe_type->ext_ant_switch_exist)
  27. return;
  28. /* swap control polarity if use different switch control polarity*/
  29. /* 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 */
  30. /* Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG, 0xcb4[29:28] = 2b'10 => Ant to WLG */
  31. if (rfe_type->ext_ant_switch_ctrl_polarity)
  32. switch_polatiry_inverse = !switch_polatiry_inverse;
  33. /* swap control polarity if 1-Ant at Aux */
  34. if (rfe_type->ant_at_main_port == false)
  35. switch_polatiry_inverse = !switch_polatiry_inverse;
  36. if (is_5g)
  37. pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA;
  38. else
  39. pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG;
  40. switch (pos_type) {
  41. default:
  42. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA:
  43. break;
  44. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG:
  45. if (!rfe_type->wlg_Locate_at_btg)
  46. switch_polatiry_inverse = !switch_polatiry_inverse;
  47. break;
  48. }
  49. if (pwifionlycfg->haldata_info.ant_div_cfg)
  50. ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV;
  51. else
  52. ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW;
  53. switch (ctrl_type) {
  54. default:
  55. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW:
  56. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2);
  57. /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
  58. halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff, 0x77);
  59. regval_0xcb7 = (switch_polatiry_inverse == false ? 0x1 : 0x2);
  60. /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */
  61. halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x30000000, regval_0xcb7);
  62. break;
  63. case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV:
  64. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2);
  65. /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
  66. halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff, 0x88);
  67. /* no regval_0xcb7 setup required, because antenna switch control value by antenna diversity */
  68. break;
  69. }
  70. }
  71. VOID halbtc8821c_wifi_only_set_rfe_type(
  72. IN struct wifi_only_cfg *pwifionlycfg
  73. )
  74. {
  75. /* the following setup should be got from Efuse in the future */
  76. rfe_type->rfe_module_type = (pwifionlycfg->haldata_info.rfe_type) & 0x1f;
  77. rfe_type->ext_ant_switch_ctrl_polarity = 0;
  78. switch (rfe_type->rfe_module_type) {
  79. case 0:
  80. default:
  81. rfe_type->ext_ant_switch_exist = true;
  82. rfe_type->ext_ant_switch_type =
  83. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, WLG*/
  84. rfe_type->wlg_Locate_at_btg = false;
  85. rfe_type->ant_at_main_port = true;
  86. break;
  87. case 1:
  88. rfe_type->ext_ant_switch_exist = true;
  89. rfe_type->ext_ant_switch_type =
  90. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, WLG */
  91. rfe_type->wlg_Locate_at_btg = false;
  92. rfe_type->ant_at_main_port = true;
  93. break;
  94. case 2:
  95. rfe_type->ext_ant_switch_exist = true;
  96. rfe_type->ext_ant_switch_type =
  97. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, BTG */
  98. rfe_type->wlg_Locate_at_btg = true;
  99. rfe_type->ant_at_main_port = true;
  100. break;
  101. case 3:
  102. rfe_type->ext_ant_switch_exist = true;
  103. rfe_type->ext_ant_switch_type =
  104. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, WLG */
  105. rfe_type->wlg_Locate_at_btg = false;
  106. rfe_type->ant_at_main_port = false;
  107. break;
  108. case 4:
  109. rfe_type->ext_ant_switch_exist = true;
  110. rfe_type->ext_ant_switch_type =
  111. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, BTG */
  112. rfe_type->wlg_Locate_at_btg = true;
  113. rfe_type->ant_at_main_port = false;
  114. break;
  115. case 5:
  116. rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/
  117. rfe_type->ext_ant_switch_type =
  118. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE;
  119. rfe_type->wlg_Locate_at_btg = false;
  120. rfe_type->ant_at_main_port = true;
  121. break;
  122. case 6:
  123. rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/
  124. rfe_type->ext_ant_switch_type =
  125. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE;
  126. rfe_type->wlg_Locate_at_btg = false;
  127. rfe_type->ant_at_main_port = true;
  128. break;
  129. case 7:
  130. rfe_type->ext_ant_switch_exist = true; /*2-Ant, DPDT, BTG*/
  131. rfe_type->ext_ant_switch_type =
  132. BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT;
  133. rfe_type->wlg_Locate_at_btg = true;
  134. rfe_type->ant_at_main_port = true;
  135. break;
  136. }
  137. }
  138. VOID
  139. ex_hal8821c_wifi_only_hw_config(
  140. IN struct wifi_only_cfg *pwifionlycfg
  141. )
  142. {
  143. halbtc8821c_wifi_only_set_rfe_type(pwifionlycfg);
  144. /* set gnt_wl, gnt_bt control owner to WL*/
  145. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x70, 0x400000, 0x1);
  146. /*gnt_wl=1 , gnt_bt=0*/
  147. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1704, 0xffffffff, 0x7700);
  148. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1700, 0xffffffff, 0xc00f0038);
  149. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x6c0, 0xffffffff, 0xaaaaaaaa);
  150. halwifionly_phy_set_bb_reg(pwifionlycfg, 0x6c4, 0xffffffff, 0xaaaaaaaa);
  151. }
  152. VOID
  153. ex_hal8821c_wifi_only_scannotify(
  154. IN struct wifi_only_cfg *pwifionlycfg,
  155. IN u1Byte is_5g
  156. )
  157. {
  158. hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
  159. }
  160. VOID
  161. ex_hal8821c_wifi_only_switchbandnotify(
  162. IN struct wifi_only_cfg *pwifionlycfg,
  163. IN u1Byte is_5g
  164. )
  165. {
  166. hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
  167. }
  168. VOID
  169. ex_hal8821c_wifi_only_connectnotify(
  170. IN struct wifi_only_cfg *pwifionlycfg,
  171. IN u1Byte is_5g
  172. )
  173. {
  174. hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g);
  175. }