hal_phy.c 6.3 KB

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