HalPwrSeqCmd.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /* 2 Only Handle the command whose FAB, CUT, and Interface are matched */
  59. if ((GET_PWR_CFG_FAB_MASK(PwrCfgCmd) & FabVersion) &&
  60. (GET_PWR_CFG_CUT_MASK(PwrCfgCmd) & CutVersion) &&
  61. (GET_PWR_CFG_INTF_MASK(PwrCfgCmd) & InterfaceType)) {
  62. switch (GET_PWR_CFG_CMD(PwrCfgCmd)) {
  63. case PWR_CMD_READ:
  64. break;
  65. case PWR_CMD_WRITE:
  66. offset = GET_PWR_CFG_OFFSET(PwrCfgCmd);
  67. #ifdef CONFIG_SDIO_HCI
  68. /* */
  69. /* <Roger_Notes> We should deal with interface specific address mapping for some interfaces, e.g., SDIO interface */
  70. /* 2011.07.07. */
  71. /* */
  72. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO) {
  73. /* Read Back SDIO Local value */
  74. value = SdioLocalCmd52Read1Byte(padapter, offset);
  75. value &= ~(GET_PWR_CFG_MASK(PwrCfgCmd));
  76. value |= (GET_PWR_CFG_VALUE(PwrCfgCmd) & GET_PWR_CFG_MASK(PwrCfgCmd));
  77. /* Write Back SDIO Local value */
  78. SdioLocalCmd52Write1Byte(padapter, offset, value);
  79. } else
  80. #endif
  81. {
  82. #ifdef CONFIG_GSPI_HCI
  83. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  84. offset = SPI_LOCAL_OFFSET | offset;
  85. #endif
  86. /* Read the value from system register */
  87. value = rtw_read8(padapter, offset);
  88. value = value & (~(GET_PWR_CFG_MASK(PwrCfgCmd)));
  89. value = value | (GET_PWR_CFG_VALUE(PwrCfgCmd) & GET_PWR_CFG_MASK(PwrCfgCmd));
  90. /* Write the value back to sytem register */
  91. rtw_write8(padapter, offset, value);
  92. }
  93. break;
  94. case PWR_CMD_POLLING:
  95. bPollingBit = _FALSE;
  96. offset = GET_PWR_CFG_OFFSET(PwrCfgCmd);
  97. #ifdef CONFIG_GSPI_HCI
  98. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  99. offset = SPI_LOCAL_OFFSET | offset;
  100. #endif
  101. do {
  102. #ifdef CONFIG_SDIO_HCI
  103. if (GET_PWR_CFG_BASE(PwrCfgCmd) == PWR_BASEADDR_SDIO)
  104. value = SdioLocalCmd52Read1Byte(padapter, offset);
  105. else
  106. #endif
  107. value = rtw_read8(padapter, offset);
  108. value = value & GET_PWR_CFG_MASK(PwrCfgCmd);
  109. if (value == (GET_PWR_CFG_VALUE(PwrCfgCmd) & GET_PWR_CFG_MASK(PwrCfgCmd)))
  110. bPollingBit = _TRUE;
  111. else
  112. rtw_udelay_os(10);
  113. if (pollingCount++ > maxPollingCnt) {
  114. RTW_ERR("HalPwrSeqCmdParsing: Fail to polling Offset[%#x]=%02x\n", offset, value);
  115. return _FALSE;
  116. }
  117. } while (!bPollingBit);
  118. break;
  119. case PWR_CMD_DELAY:
  120. if (GET_PWR_CFG_VALUE(PwrCfgCmd) == PWRSEQ_DELAY_US)
  121. rtw_udelay_os(GET_PWR_CFG_OFFSET(PwrCfgCmd));
  122. else
  123. rtw_udelay_os(GET_PWR_CFG_OFFSET(PwrCfgCmd) * 1000);
  124. break;
  125. case PWR_CMD_END:
  126. /* When this command is parsed, end the process */
  127. return _TRUE;
  128. break;
  129. default:
  130. break;
  131. }
  132. }
  133. AryIdx++;/* Add Array Index */
  134. } while (1);
  135. return _TRUE;
  136. }