1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
21 Copyright (c) Realtek Semiconductor Corp. All rights reserved.
27 Implement HW Power sequence configuration CMD handling routine for Realtek devices.
31 ---------- --------------- -------------------------------
32 2011-10-26 Lucas Modify to be compatible with SD4-CE driver.
33 2011-07-07 Roger Create.
37 #include <HalPwrSeqCmd.h>
38 #include <usb_ops_linux.h>
41 /* This routine deals with the Power Configuration CMDs parsing
42 * for RTL8723/RTL8188E Series IC.
44 * We should follow specific format which was released from HW SD.
46 u8 HalPwrSeqCmdParsing(struct adapter *padapter, u8 cut_vers, u8 fab_vers,
47 u8 ifacetype, struct wl_pwr_cfg pwrseqcmd[])
49 struct wl_pwr_cfg pwrcfgcmd = {0};
54 u32 poll_count = 0; /* polling autoload done. */
55 u32 max_poll_count = 5000;
58 pwrcfgcmd = pwrseqcmd[aryidx];
60 RT_TRACE(_module_hal_init_c_ , _drv_info_,
61 ("HalPwrSeqCmdParsing: offset(%#x) cut_msk(%#x) fab_msk(%#x) interface_msk(%#x) base(%#x) cmd(%#x) msk(%#x) value(%#x)\n",
62 GET_PWR_CFG_OFFSET(pwrcfgcmd),
63 GET_PWR_CFG_CUT_MASK(pwrcfgcmd),
64 GET_PWR_CFG_FAB_MASK(pwrcfgcmd),
65 GET_PWR_CFG_INTF_MASK(pwrcfgcmd),
66 GET_PWR_CFG_BASE(pwrcfgcmd),
67 GET_PWR_CFG_CMD(pwrcfgcmd),
68 GET_PWR_CFG_MASK(pwrcfgcmd),
69 GET_PWR_CFG_VALUE(pwrcfgcmd)));
71 /* 2 Only Handle the command whose FAB, CUT, and Interface are matched */
72 if ((GET_PWR_CFG_FAB_MASK(pwrcfgcmd) & fab_vers) &&
73 (GET_PWR_CFG_CUT_MASK(pwrcfgcmd) & cut_vers) &&
74 (GET_PWR_CFG_INTF_MASK(pwrcfgcmd) & ifacetype)) {
75 switch (GET_PWR_CFG_CMD(pwrcfgcmd)) {
77 RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_READ\n"));
80 RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_WRITE\n"));
81 offset = GET_PWR_CFG_OFFSET(pwrcfgcmd);
83 /* Read the value from system register */
84 value = usb_read8(padapter, offset);
86 value &= ~(GET_PWR_CFG_MASK(pwrcfgcmd));
87 value |= (GET_PWR_CFG_VALUE(pwrcfgcmd) & GET_PWR_CFG_MASK(pwrcfgcmd));
89 /* Write the value back to system register */
90 usb_write8(padapter, offset, value);
93 RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_POLLING\n"));
96 offset = GET_PWR_CFG_OFFSET(pwrcfgcmd);
98 value = usb_read8(padapter, offset);
100 value &= GET_PWR_CFG_MASK(pwrcfgcmd);
101 if (value == (GET_PWR_CFG_VALUE(pwrcfgcmd) & GET_PWR_CFG_MASK(pwrcfgcmd)))
106 if (poll_count++ > max_poll_count) {
107 DBG_88E("Fail to polling Offset[%#x]\n", offset);
113 RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_DELAY\n"));
114 if (GET_PWR_CFG_VALUE(pwrcfgcmd) == PWRSEQ_DELAY_US)
115 udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd));
117 udelay(GET_PWR_CFG_OFFSET(pwrcfgcmd)*1000);
120 /* When this command is parsed, end the process */
121 RT_TRACE(_module_hal_init_c_ , _drv_info_, ("HalPwrSeqCmdParsing: PWR_CMD_END\n"));
125 RT_TRACE(_module_hal_init_c_ , _drv_err_, ("HalPwrSeqCmdParsing: Unknown CMD!!\n"));
130 aryidx++;/* Add Array Index */