HalPwrSeqCmd.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /*++
  21. Copyright (c) Realtek Semiconductor Corp. All rights reserved.
  22. Module Name:
  23. HalPwrSeqCmd.c
  24. Abstract:
  25. Implement HW Power sequence configuration CMD handling routine for Realtek devices.
  26. Major Change History:
  27. When Who What
  28. ---------- --------------- -------------------------------
  29. 2011-10-26 Lucas Modify to be compatible with SD4-CE driver.
  30. 2011-07-07 Roger Create.
  31. --*/
  32. #include <HalPwrSeqCmd.h>
  33. //
  34. // Description:
  35. // This routine deal with the Power Configuration CMDs parsing for RTL8723/RTL8188E Series IC.
  36. //
  37. // Assumption:
  38. // We should follow specific format which was released from HW SD.
  39. //
  40. // 2011.07.07, added by Roger.
  41. //
  42. u8 HalPwrSeqCmdParsing(
  43. PADAPTER padapter,
  44. u8 CutVersion,
  45. u8 FabVersion,
  46. u8 InterfaceType,
  47. WLAN_PWR_CFG PwrSeqCmd[])
  48. {
  49. WLAN_PWR_CFG PwrCfgCmd = {0};
  50. u8 bPollingBit = _FALSE;
  51. u32 AryIdx = 0;
  52. u8 value = 0;
  53. u32 offset = 0;
  54. u32 pollingCount = 0; // polling autoload done.
  55. u32 maxPollingCnt = 5000;
  56. do {
  57. PwrCfgCmd = PwrSeqCmd[AryIdx];
  58. RT_TRACE(_module_hal_init_c_ , _drv_info_,
  59. ("HalPwrSeqCmdParsing: offset(%#x) cut_msk(%#x) fab_msk(%#x) interface_msk(%#x) base(%#x) cmd(%#x) msk(%#x) value(%#x)\n",
  60. GET_PWR_CFG_OFFSET(PwrCfgCmd),
  61. GET_PWR_CFG_CUT_MASK(PwrCfgCmd),
  62. GET_PWR_CFG_FAB_MASK(PwrCfgCmd),
  63. GET_PWR_CFG_INTF_MASK(PwrCfgCmd),
  64. GET_PWR_CFG_BASE(PwrCfgCmd),
  65. GET_PWR_CFG_CMD(PwrCfgCmd),
  66. GET_PWR_CFG_MASK(PwrCfgCmd),
  67. GET_PWR_CFG_VALUE(PwrCfgCmd)));
  68. //2 Only Handle the command whose FAB, CUT, and Interface are matched
  69. if ((GET_PWR_CFG_FAB_MASK(PwrCfgCmd) & FabVersion) &&
  70. (GET_PWR_CFG_CUT_MASK(PwrCfgCmd) & CutVersion) &&
  71. (GET_PWR_CFG_INTF_MASK(PwrCfgCmd) & InterfaceType))
  72. {
  73. switch (GET_PWR_CFG_CMD(PwrCfgCmd))
  74. {
  75. case PWR_CMD_READ:
  76. RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_READ\n"));
  77. break;
  78. case PWR_CMD_WRITE:
  79. RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_WRITE\n"));
  80. offset = GET_PWR_CFG_OFFSET(PwrCfgCmd);
  81. #ifdef CONFIG_SDIO_HCI
  82. //
  83. // <Roger_Notes> We should deal with interface specific address mapping for some interfaces, e.g., SDIO interface
  84. // 2011.07.07.
  85. //
  86. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  87. {
  88. // Read Back SDIO Local value
  89. value = SdioLocalCmd52Read1Byte(padapter, offset);
  90. value &= ~(GET_PWR_CFG_MASK(PwrCfgCmd));
  91. value |= (GET_PWR_CFG_VALUE(PwrCfgCmd) & GET_PWR_CFG_MASK(PwrCfgCmd));
  92. // Write Back SDIO Local value
  93. SdioLocalCmd52Write1Byte(padapter, offset, value);
  94. }
  95. else
  96. #endif
  97. {
  98. #ifdef CONFIG_GSPI_HCI
  99. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  100. offset = SPI_LOCAL_OFFSET | offset;
  101. #endif
  102. // Read the value from system register
  103. value = rtw_read8(padapter, offset);
  104. value=value&(~(GET_PWR_CFG_MASK(PwrCfgCmd)));
  105. value=value|(GET_PWR_CFG_VALUE(PwrCfgCmd)&GET_PWR_CFG_MASK(PwrCfgCmd));
  106. // Write the value back to sytem register
  107. rtw_write8(padapter, offset, value);
  108. }
  109. break;
  110. case PWR_CMD_POLLING:
  111. RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_POLLING\n"));
  112. bPollingBit = _FALSE;
  113. offset = GET_PWR_CFG_OFFSET(PwrCfgCmd);
  114. #ifdef CONFIG_GSPI_HCI
  115. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  116. offset = SPI_LOCAL_OFFSET | offset;
  117. #endif
  118. do {
  119. #ifdef CONFIG_SDIO_HCI
  120. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  121. value = SdioLocalCmd52Read1Byte(padapter, offset);
  122. else
  123. #endif
  124. value = rtw_read8(padapter, offset);
  125. value=value&GET_PWR_CFG_MASK(PwrCfgCmd);
  126. if (value == (GET_PWR_CFG_VALUE(PwrCfgCmd) & GET_PWR_CFG_MASK(PwrCfgCmd)))
  127. bPollingBit = _TRUE;
  128. else
  129. rtw_udelay_os(10);
  130. if (pollingCount++ > maxPollingCnt) {
  131. DBG_871X("Fail to polling Offset[%#x]\n", offset);
  132. return _FALSE;
  133. }
  134. } while (!bPollingBit);
  135. break;
  136. case PWR_CMD_DELAY:
  137. RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_DELAY\n"));
  138. if (GET_PWR_CFG_VALUE(PwrCfgCmd) == PWRSEQ_DELAY_US)
  139. rtw_udelay_os(GET_PWR_CFG_OFFSET(PwrCfgCmd));
  140. else
  141. rtw_udelay_os(GET_PWR_CFG_OFFSET(PwrCfgCmd)*1000);
  142. break;
  143. case PWR_CMD_END:
  144. // When this command is parsed, end the process
  145. RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_END\n"));
  146. return _TRUE;
  147. break;
  148. default:
  149. RT_TRACE(_module_hal_init_c_ , _drv_err_, ("HalPwrSeqCmdParsing: Unknown CMD!!\n"));
  150. break;
  151. }
  152. }
  153. AryIdx++;//Add Array Index
  154. }while(1);
  155. return _TRUE;
  156. }