pwrseqcmd.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include <pwrseqcmd.h>
  20. #include <usb_ops_linux.h>
  21. /* This routine deals with the Power Configuration CMDs parsing
  22. * for RTL8723/RTL8188E Series IC.
  23. */
  24. u8 rtl88eu_pwrseqcmdparsing(struct adapter *padapter, u8 cut_vers, u8 fab_vers,
  25. u8 ifacetype, struct wl_pwr_cfg pwrseqcmd[])
  26. {
  27. struct wl_pwr_cfg pwrcfgcmd = {0};
  28. u8 poll_bit = false;
  29. u32 aryidx = 0;
  30. u8 value = 0;
  31. u32 offset = 0;
  32. u32 poll_count = 0; /* polling autoload done. */
  33. u32 max_poll_count = 5000;
  34. do {
  35. pwrcfgcmd = pwrseqcmd[aryidx];
  36. RT_TRACE(_module_hal_init_c_, _drv_info_,
  37. ("rtl88eu_pwrseqcmdparsing: offset(%#x) cut_msk(%#x)"
  38. "fab_msk(%#x) interface_msk(%#x) base(%#x) cmd(%#x)"
  39. "msk(%#x) value(%#x)\n",
  40. GET_PWR_CFG_OFFSET(pwrcfgcmd),
  41. GET_PWR_CFG_CUT_MASK(pwrcfgcmd),
  42. GET_PWR_CFG_FAB_MASK(pwrcfgcmd),
  43. GET_PWR_CFG_INTF_MASK(pwrcfgcmd),
  44. GET_PWR_CFG_BASE(pwrcfgcmd),
  45. GET_PWR_CFG_CMD(pwrcfgcmd),
  46. GET_PWR_CFG_MASK(pwrcfgcmd),
  47. GET_PWR_CFG_VALUE(pwrcfgcmd)));
  48. /* Only Handle the command whose FAB, CUT, and Interface are matched */
  49. if ((GET_PWR_CFG_FAB_MASK(pwrcfgcmd) & fab_vers) &&
  50. (GET_PWR_CFG_CUT_MASK(pwrcfgcmd) & cut_vers) &&
  51. (GET_PWR_CFG_INTF_MASK(pwrcfgcmd) & ifacetype)) {
  52. switch (GET_PWR_CFG_CMD(pwrcfgcmd)) {
  53. case PWR_CMD_READ:
  54. RT_TRACE(_module_hal_init_c_, _drv_info_,
  55. ("rtl88eu_pwrseqcmdparsing: PWR_CMD_READ\n"));
  56. break;
  57. case PWR_CMD_WRITE:
  58. RT_TRACE(_module_hal_init_c_, _drv_info_,
  59. ("rtl88eu_pwrseqcmdparsing: PWR_CMD_WRITE\n"));
  60. offset = GET_PWR_CFG_OFFSET(pwrcfgcmd);
  61. /* Read the value from system register */
  62. value = usb_read8(padapter, offset);
  63. value &= ~(GET_PWR_CFG_MASK(pwrcfgcmd));
  64. value |= (GET_PWR_CFG_VALUE(pwrcfgcmd) &
  65. GET_PWR_CFG_MASK(pwrcfgcmd));
  66. /* Write the value back to system register */
  67. usb_write8(padapter, offset, value);
  68. break;
  69. case PWR_CMD_POLLING:
  70. RT_TRACE(_module_hal_init_c_, _drv_info_,
  71. ("rtl88eu_pwrseqcmdparsing: PWR_CMD_POLLING\n"));
  72. poll_bit = false;
  73. offset = GET_PWR_CFG_OFFSET(pwrcfgcmd);
  74. do {
  75. value = usb_read8(padapter, offset);
  76. value &= GET_PWR_CFG_MASK(pwrcfgcmd);
  77. if (value == (GET_PWR_CFG_VALUE(pwrcfgcmd) &
  78. GET_PWR_CFG_MASK(pwrcfgcmd)))
  79. poll_bit = true;
  80. else
  81. udelay(10);
  82. if (poll_count++ > max_poll_count) {
  83. DBG_88E("Fail to polling Offset[%#x]\n", offset);
  84. return false;
  85. }
  86. } while (!poll_bit);
  87. break;
  88. case PWR_CMD_DELAY:
  89. RT_TRACE(_module_hal_init_c_, _drv_info_,
  90. ("rtl88eu_pwrseqcmdparsing: PWR_CMD_DELAY\n"));
  91. if (GET_PWR_CFG_VALUE(pwrcfgcmd) == PWRSEQ_DELAY_US)
  92. udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd));
  93. else
  94. udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd)*1000);
  95. break;
  96. case PWR_CMD_END:
  97. /* When this command is parsed, end the process */
  98. RT_TRACE(_module_hal_init_c_, _drv_info_,
  99. ("rtl88eu_pwrseqcmdparsing: PWR_CMD_END\n"));
  100. return true;
  101. default:
  102. RT_TRACE(_module_hal_init_c_, _drv_err_,
  103. ("rtl88eu_pwrseqcmdparsing: Unknown CMD!!\n"));
  104. break;
  105. }
  106. }
  107. aryidx++;/* Add Array Index */
  108. } while (1);
  109. return true;
  110. }