1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
9 #include <usb_ops_linux.h>
11 /* This routine deals with the Power Configuration CMDs parsing
12 * for RTL8723/RTL8188E Series IC.
14 u8 rtl88eu_pwrseqcmdparsing(struct adapter *padapter, u8 cut_vers,
15 struct wl_pwr_cfg pwrseqcmd[])
17 struct wl_pwr_cfg pwrcfgcmd;
22 u32 poll_count = 0; /* polling autoload done. */
23 u32 max_poll_count = 5000;
26 pwrcfgcmd = pwrseqcmd[aryidx];
28 RT_TRACE(_module_hal_init_c_, _drv_info_,
29 ("rtl88eu_pwrseqcmdparsing: offset(%#x) cut_msk(%#x)"
31 "msk(%#x) value(%#x)\n",
32 GET_PWR_CFG_OFFSET(pwrcfgcmd),
33 GET_PWR_CFG_CUT_MASK(pwrcfgcmd),
34 GET_PWR_CFG_CMD(pwrcfgcmd),
35 GET_PWR_CFG_MASK(pwrcfgcmd),
36 GET_PWR_CFG_VALUE(pwrcfgcmd)));
38 /* Only Handle the command whose CUT is matched */
39 if (GET_PWR_CFG_CUT_MASK(pwrcfgcmd) & cut_vers) {
40 switch (GET_PWR_CFG_CMD(pwrcfgcmd)) {
42 RT_TRACE(_module_hal_init_c_, _drv_info_,
43 ("rtl88eu_pwrseqcmdparsing: PWR_CMD_READ\n"));
46 RT_TRACE(_module_hal_init_c_, _drv_info_,
47 ("rtl88eu_pwrseqcmdparsing: PWR_CMD_WRITE\n"));
48 offset = GET_PWR_CFG_OFFSET(pwrcfgcmd);
50 /* Read the value from system register */
51 value = usb_read8(padapter, offset);
53 value &= ~(GET_PWR_CFG_MASK(pwrcfgcmd));
54 value |= (GET_PWR_CFG_VALUE(pwrcfgcmd) &
55 GET_PWR_CFG_MASK(pwrcfgcmd));
57 /* Write the value back to system register */
58 usb_write8(padapter, offset, value);
61 RT_TRACE(_module_hal_init_c_, _drv_info_,
62 ("rtl88eu_pwrseqcmdparsing: PWR_CMD_POLLING\n"));
65 offset = GET_PWR_CFG_OFFSET(pwrcfgcmd);
67 value = usb_read8(padapter, offset);
68 value &= GET_PWR_CFG_MASK(pwrcfgcmd);
70 if (value == (GET_PWR_CFG_VALUE(pwrcfgcmd) &
71 GET_PWR_CFG_MASK(pwrcfgcmd)))
76 if (poll_count++ > max_poll_count) {
77 DBG_88E("Fail to polling Offset[%#x]\n", offset);
83 RT_TRACE(_module_hal_init_c_, _drv_info_,
84 ("rtl88eu_pwrseqcmdparsing: PWR_CMD_DELAY\n"));
85 if (GET_PWR_CFG_VALUE(pwrcfgcmd) == PWRSEQ_DELAY_US)
86 udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd));
88 udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd)*1000);
91 /* When this command is parsed, end the process */
92 RT_TRACE(_module_hal_init_c_, _drv_info_,
93 ("rtl88eu_pwrseqcmdparsing: PWR_CMD_END\n"));
96 RT_TRACE(_module_hal_init_c_, _drv_err_,
97 ("rtl88eu_pwrseqcmdparsing: Unknown CMD!!\n"));
102 aryidx++;/* Add Array Index */