hal_phy.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 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. #define _HAL_PHY_C_
  16. #include <drv_types.h>
  17. /**
  18. * Function: PHY_CalculateBitShift
  19. *
  20. * OverView: Get shifted position of the BitMask
  21. *
  22. * Input:
  23. * u4Byte BitMask,
  24. *
  25. * Output: none
  26. * Return: u4Byte Return the shift bit bit position of the mask
  27. */
  28. u32
  29. PHY_CalculateBitShift(
  30. u32 BitMask
  31. )
  32. {
  33. u32 i;
  34. for (i = 0; i <= 31; i++) {
  35. if (((BitMask >> i) & 0x1) == 1)
  36. break;
  37. }
  38. return i;
  39. }
  40. #ifdef CONFIG_RF_SHADOW_RW
  41. /* ********************************************************************************
  42. * Constant.
  43. * ********************************************************************************
  44. * 2008/11/20 MH For Debug only, RF */
  45. static RF_SHADOW_T RF_Shadow[RF6052_MAX_PATH][RF6052_MAX_REG];
  46. /*
  47. * ==> RF shadow Operation API Code Section!!!
  48. *
  49. *-----------------------------------------------------------------------------
  50. * Function: PHY_RFShadowRead
  51. * PHY_RFShadowWrite
  52. * PHY_RFShadowCompare
  53. * PHY_RFShadowRecorver
  54. * PHY_RFShadowCompareAll
  55. * PHY_RFShadowRecorverAll
  56. * PHY_RFShadowCompareFlagSet
  57. * PHY_RFShadowRecorverFlagSet
  58. *
  59. * Overview: When we set RF register, we must write shadow at first.
  60. * When we are running, we must compare shadow abd locate error addr.
  61. * Decide to recorver or not.
  62. *
  63. * Input: NONE
  64. *
  65. * Output: NONE
  66. *
  67. * Return: NONE
  68. *
  69. * Revised History:
  70. * When Who Remark
  71. * 11/20/2008 MHC Create Version 0.
  72. *
  73. *---------------------------------------------------------------------------*/
  74. u32
  75. PHY_RFShadowRead(
  76. IN PADAPTER Adapter,
  77. IN enum rf_path eRFPath,
  78. IN u32 Offset)
  79. {
  80. return RF_Shadow[eRFPath][Offset].Value;
  81. } /* PHY_RFShadowRead */
  82. VOID
  83. PHY_RFShadowWrite(
  84. IN PADAPTER Adapter,
  85. IN enum rf_path eRFPath,
  86. IN u32 Offset,
  87. IN u32 Data)
  88. {
  89. RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
  90. RF_Shadow[eRFPath][Offset].Driver_Write = _TRUE;
  91. } /* PHY_RFShadowWrite */
  92. BOOLEAN
  93. PHY_RFShadowCompare(
  94. IN PADAPTER Adapter,
  95. IN enum rf_path eRFPath,
  96. IN u32 Offset)
  97. {
  98. u32 reg;
  99. /* Check if we need to check the register */
  100. if (RF_Shadow[eRFPath][Offset].Compare == _TRUE) {
  101. reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
  102. /* Compare shadow and real rf register for 20bits!! */
  103. if (RF_Shadow[eRFPath][Offset].Value != reg) {
  104. /* Locate error position. */
  105. RF_Shadow[eRFPath][Offset].ErrorOrNot = _TRUE;
  106. }
  107. return RF_Shadow[eRFPath][Offset].ErrorOrNot ;
  108. }
  109. return _FALSE;
  110. } /* PHY_RFShadowCompare */
  111. VOID
  112. PHY_RFShadowRecorver(
  113. IN PADAPTER Adapter,
  114. IN enum rf_path eRFPath,
  115. IN u32 Offset)
  116. {
  117. /* Check if the address is error */
  118. if (RF_Shadow[eRFPath][Offset].ErrorOrNot == _TRUE) {
  119. /* Check if we need to recorver the register. */
  120. if (RF_Shadow[eRFPath][Offset].Recorver == _TRUE) {
  121. rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
  122. RF_Shadow[eRFPath][Offset].Value);
  123. }
  124. }
  125. } /* PHY_RFShadowRecorver */
  126. VOID
  127. PHY_RFShadowCompareAll(
  128. IN PADAPTER Adapter)
  129. {
  130. enum rf_path eRFPath = RF_PATH_A;
  131. u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
  132. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
  133. for (Offset = 0; Offset < maxReg; Offset++)
  134. PHY_RFShadowCompare(Adapter, eRFPath, Offset);
  135. }
  136. } /* PHY_RFShadowCompareAll */
  137. VOID
  138. PHY_RFShadowRecorverAll(
  139. IN PADAPTER Adapter)
  140. {
  141. enum rf_path eRFPath = RF_PATH_A;
  142. u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
  143. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
  144. for (Offset = 0; Offset < maxReg; Offset++)
  145. PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
  146. }
  147. } /* PHY_RFShadowRecorverAll */
  148. VOID
  149. PHY_RFShadowCompareFlagSet(
  150. IN PADAPTER Adapter,
  151. IN enum rf_path eRFPath,
  152. IN u32 Offset,
  153. IN u8 Type)
  154. {
  155. /* Set True or False!!! */
  156. RF_Shadow[eRFPath][Offset].Compare = Type;
  157. } /* PHY_RFShadowCompareFlagSet */
  158. VOID
  159. PHY_RFShadowRecorverFlagSet(
  160. IN PADAPTER Adapter,
  161. IN enum rf_path eRFPath,
  162. IN u32 Offset,
  163. IN u8 Type)
  164. {
  165. /* Set True or False!!! */
  166. RF_Shadow[eRFPath][Offset].Recorver = Type;
  167. } /* PHY_RFShadowRecorverFlagSet */
  168. VOID
  169. PHY_RFShadowCompareFlagSetAll(
  170. IN PADAPTER Adapter)
  171. {
  172. enum rf_path eRFPath = RF_PATH_A;
  173. u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
  174. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
  175. for (Offset = 0; Offset < maxReg; Offset++) {
  176. /* 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
  177. if (Offset != 0x26 && Offset != 0x27)
  178. PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, _FALSE);
  179. else
  180. PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, _TRUE);
  181. }
  182. }
  183. } /* PHY_RFShadowCompareFlagSetAll */
  184. VOID
  185. PHY_RFShadowRecorverFlagSetAll(
  186. IN PADAPTER Adapter)
  187. {
  188. enum rf_path eRFPath = RF_PATH_A;
  189. u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
  190. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
  191. for (Offset = 0; Offset < maxReg; Offset++) {
  192. /* 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!! */
  193. if (Offset != 0x26 && Offset != 0x27)
  194. PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, _FALSE);
  195. else
  196. PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, _TRUE);
  197. }
  198. }
  199. } /* PHY_RFShadowCompareFlagSetAll */
  200. VOID
  201. PHY_RFShadowRefresh(
  202. IN PADAPTER Adapter)
  203. {
  204. enum rf_path eRFPath = RF_PATH_A;
  205. u32 Offset = 0, maxReg = GET_RF6052_REAL_MAX_REG(Adapter);
  206. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++) {
  207. for (Offset = 0; Offset < maxReg; Offset++) {
  208. RF_Shadow[eRFPath][Offset].Value = 0;
  209. RF_Shadow[eRFPath][Offset].Compare = _FALSE;
  210. RF_Shadow[eRFPath][Offset].Recorver = _FALSE;
  211. RF_Shadow[eRFPath][Offset].ErrorOrNot = _FALSE;
  212. RF_Shadow[eRFPath][Offset].Driver_Write = _FALSE;
  213. }
  214. }
  215. } /* PHY_RFShadowRead */
  216. #endif /*CONFIG_RF_SHADOW_RW*/