hal_phy.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. {
  46. if ( ((BitMask>>i) & 0x1 ) == 1)
  47. break;
  48. }
  49. return (i);
  50. }
  51. //
  52. // ==> RF shadow Operation API Code Section!!!
  53. //
  54. /*-----------------------------------------------------------------------------
  55. * Function: PHY_RFShadowRead
  56. * PHY_RFShadowWrite
  57. * PHY_RFShadowCompare
  58. * PHY_RFShadowRecorver
  59. * PHY_RFShadowCompareAll
  60. * PHY_RFShadowRecorverAll
  61. * PHY_RFShadowCompareFlagSet
  62. * PHY_RFShadowRecorverFlagSet
  63. *
  64. * Overview: When we set RF register, we must write shadow at first.
  65. * When we are running, we must compare shadow abd locate error addr.
  66. * Decide to recorver or not.
  67. *
  68. * Input: NONE
  69. *
  70. * Output: NONE
  71. *
  72. * Return: NONE
  73. *
  74. * Revised History:
  75. * When Who Remark
  76. * 11/20/2008 MHC Create Version 0.
  77. *
  78. *---------------------------------------------------------------------------*/
  79. u32
  80. PHY_RFShadowRead(
  81. IN PADAPTER Adapter,
  82. IN u8 eRFPath,
  83. IN u32 Offset)
  84. {
  85. return RF_Shadow[eRFPath][Offset].Value;
  86. } /* PHY_RFShadowRead */
  87. VOID
  88. PHY_RFShadowWrite(
  89. IN PADAPTER Adapter,
  90. IN u8 eRFPath,
  91. IN u32 Offset,
  92. IN u32 Data)
  93. {
  94. RF_Shadow[eRFPath][Offset].Value = (Data & bRFRegOffsetMask);
  95. RF_Shadow[eRFPath][Offset].Driver_Write = _TRUE;
  96. } /* PHY_RFShadowWrite */
  97. BOOLEAN
  98. PHY_RFShadowCompare(
  99. IN PADAPTER Adapter,
  100. IN u8 eRFPath,
  101. IN u32 Offset)
  102. {
  103. u32 reg;
  104. // Check if we need to check the register
  105. if (RF_Shadow[eRFPath][Offset].Compare == _TRUE)
  106. {
  107. reg = rtw_hal_read_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask);
  108. // Compare shadow and real rf register for 20bits!!
  109. if (RF_Shadow[eRFPath][Offset].Value != reg)
  110. {
  111. // Locate error position.
  112. RF_Shadow[eRFPath][Offset].ErrorOrNot = _TRUE;
  113. //RT_TRACE(COMP_INIT, DBG_LOUD,
  114. //("PHY_RFShadowCompare RF-%d Addr%02lx Err = %05lx\n",
  115. //eRFPath, Offset, reg));
  116. }
  117. return RF_Shadow[eRFPath][Offset].ErrorOrNot ;
  118. }
  119. return _FALSE;
  120. } /* PHY_RFShadowCompare */
  121. VOID
  122. PHY_RFShadowRecorver(
  123. IN PADAPTER Adapter,
  124. IN u8 eRFPath,
  125. IN u32 Offset)
  126. {
  127. // Check if the address is error
  128. if (RF_Shadow[eRFPath][Offset].ErrorOrNot == _TRUE)
  129. {
  130. // Check if we need to recorver the register.
  131. if (RF_Shadow[eRFPath][Offset].Recorver == _TRUE)
  132. {
  133. rtw_hal_write_rfreg(Adapter, eRFPath, Offset, bRFRegOffsetMask,
  134. RF_Shadow[eRFPath][Offset].Value);
  135. //RT_TRACE(COMP_INIT, DBG_LOUD,
  136. //("PHY_RFShadowRecorver RF-%d Addr%02lx=%05lx",
  137. //eRFPath, Offset, RF_Shadow[eRFPath][Offset].Value));
  138. }
  139. }
  140. } /* PHY_RFShadowRecorver */
  141. VOID
  142. PHY_RFShadowCompareAll(
  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. {
  149. for (Offset = 0; Offset <= maxReg; Offset++)
  150. {
  151. PHY_RFShadowCompare(Adapter, eRFPath, Offset);
  152. }
  153. }
  154. } /* PHY_RFShadowCompareAll */
  155. VOID
  156. PHY_RFShadowRecorverAll(
  157. IN PADAPTER Adapter)
  158. {
  159. u8 eRFPath =0;
  160. u32 Offset = 0, maxReg= GET_RF6052_REAL_MAX_REG(Adapter);
  161. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++)
  162. {
  163. for (Offset = 0; Offset <= maxReg; Offset++)
  164. {
  165. PHY_RFShadowRecorver(Adapter, eRFPath, Offset);
  166. }
  167. }
  168. } /* PHY_RFShadowRecorverAll */
  169. VOID
  170. PHY_RFShadowCompareFlagSet(
  171. IN PADAPTER Adapter,
  172. IN u8 eRFPath,
  173. IN u32 Offset,
  174. IN u8 Type)
  175. {
  176. // Set True or False!!!
  177. RF_Shadow[eRFPath][Offset].Compare = Type;
  178. } /* PHY_RFShadowCompareFlagSet */
  179. VOID
  180. PHY_RFShadowRecorverFlagSet(
  181. IN PADAPTER Adapter,
  182. IN u8 eRFPath,
  183. IN u32 Offset,
  184. IN u8 Type)
  185. {
  186. // Set True or False!!!
  187. RF_Shadow[eRFPath][Offset].Recorver= Type;
  188. } /* PHY_RFShadowRecorverFlagSet */
  189. VOID
  190. PHY_RFShadowCompareFlagSetAll(
  191. IN PADAPTER Adapter)
  192. {
  193. u8 eRFPath = 0;
  194. u32 Offset = 0, maxReg= GET_RF6052_REAL_MAX_REG(Adapter);
  195. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++)
  196. {
  197. for (Offset = 0; Offset <= maxReg; Offset++)
  198. {
  199. // 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!!
  200. if (Offset != 0x26 && Offset != 0x27)
  201. PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, _FALSE);
  202. else
  203. PHY_RFShadowCompareFlagSet(Adapter, eRFPath, Offset, _TRUE);
  204. }
  205. }
  206. } /* PHY_RFShadowCompareFlagSetAll */
  207. VOID
  208. PHY_RFShadowRecorverFlagSetAll(
  209. IN PADAPTER Adapter)
  210. {
  211. u8 eRFPath = 0;
  212. u32 Offset = 0, maxReg= GET_RF6052_REAL_MAX_REG(Adapter);
  213. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++)
  214. {
  215. for (Offset = 0; Offset <= maxReg; Offset++)
  216. {
  217. // 2008/11/20 MH For S3S4 test, we only check reg 26/27 now!!!!
  218. if (Offset != 0x26 && Offset != 0x27)
  219. PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, _FALSE);
  220. else
  221. PHY_RFShadowRecorverFlagSet(Adapter, eRFPath, Offset, _TRUE);
  222. }
  223. }
  224. } /* PHY_RFShadowCompareFlagSetAll */
  225. VOID
  226. PHY_RFShadowRefresh(
  227. IN PADAPTER Adapter)
  228. {
  229. u8 eRFPath = 0;
  230. u32 Offset = 0, maxReg= GET_RF6052_REAL_MAX_REG(Adapter);
  231. for (eRFPath = 0; eRFPath < RF6052_MAX_PATH; eRFPath++)
  232. {
  233. for (Offset = 0; Offset <= maxReg; Offset++)
  234. {
  235. RF_Shadow[eRFPath][Offset].Value = 0;
  236. RF_Shadow[eRFPath][Offset].Compare = _FALSE;
  237. RF_Shadow[eRFPath][Offset].Recorver = _FALSE;
  238. RF_Shadow[eRFPath][Offset].ErrorOrNot = _FALSE;
  239. RF_Shadow[eRFPath][Offset].Driver_Write = _FALSE;
  240. }
  241. }
  242. } /* PHY_RFShadowRead */