xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8822cs/hal/halmac/halmac_api.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun  *
3*4882a593Smuzhiyun  * Copyright(c) 2016 - 2019 Realtek Corporation. All rights reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify it
6*4882a593Smuzhiyun  * under the terms of version 2 of the GNU General Public License as
7*4882a593Smuzhiyun  * published by the Free Software Foundation.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but WITHOUT
10*4882a593Smuzhiyun  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12*4882a593Smuzhiyun  * more details.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  ******************************************************************************/
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include "halmac_type.h"
17*4882a593Smuzhiyun #include "halmac_api.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #if (HALMAC_PLATFORM_WINDOWS)
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #if HALMAC_8822B_SUPPORT
22*4882a593Smuzhiyun #include "halmac_88xx/halmac_init_win8822b.h"
23*4882a593Smuzhiyun #endif
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #if HALMAC_8821C_SUPPORT
26*4882a593Smuzhiyun #include "halmac_88xx/halmac_init_win8821c.h"
27*4882a593Smuzhiyun #endif
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #if HALMAC_8814B_SUPPORT
30*4882a593Smuzhiyun #include "halmac_88xx_v1/halmac_init_win8814b_v1.h"
31*4882a593Smuzhiyun #endif
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun #if HALMAC_8822C_SUPPORT
34*4882a593Smuzhiyun #include "halmac_88xx/halmac_init_win8822c.h"
35*4882a593Smuzhiyun #endif
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #if HALMAC_8812F_SUPPORT
38*4882a593Smuzhiyun #include "halmac_88xx/halmac_init_win8812f.h"
39*4882a593Smuzhiyun #endif
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #else
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #if HALMAC_88XX_SUPPORT
44*4882a593Smuzhiyun #include "halmac_88xx/halmac_init_88xx.h"
45*4882a593Smuzhiyun #endif
46*4882a593Smuzhiyun #if HALMAC_88XX_V1_SUPPORT
47*4882a593Smuzhiyun #include "halmac_88xx_v1/halmac_init_88xx_v1.h"
48*4882a593Smuzhiyun #if defined(HALMAC_DATA_CPU_EN)
49*4882a593Smuzhiyun #include "halmac_88xxd_v1/halmac_init_88xxd_v1.h"
50*4882a593Smuzhiyun #endif
51*4882a593Smuzhiyun #endif
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #endif
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun enum chip_id_hw_def {
56*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8723A = 0x01,
57*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8188E = 0x02,
58*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8881A = 0x03,
59*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8812A = 0x04,
60*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8821A = 0x05,
61*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8723B = 0x06,
62*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8192E = 0x07,
63*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8814A = 0x08,
64*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8821C = 0x09,
65*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8822B = 0x0A,
66*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8703B = 0x0B,
67*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8188F = 0x0C,
68*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8192F = 0x0D,
69*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8197F = 0x0E,
70*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8723D = 0x0F,
71*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8814B = 0x11,
72*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8822C = 0x13,
73*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_8812F = 0x14,
74*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_UNDEFINE = 0x7F,
75*4882a593Smuzhiyun 	CHIP_ID_HW_DEF_PS = 0xEA,
76*4882a593Smuzhiyun };
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun static enum halmac_ret_status
79*4882a593Smuzhiyun chk_pltfm_api(void *drv_adapter, enum halmac_interface intf,
80*4882a593Smuzhiyun 	      struct halmac_platform_api *pltfm_api);
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun static enum halmac_ret_status
83*4882a593Smuzhiyun get_chip_info(void *drv_adapter, struct halmac_platform_api *pltfm_api,
84*4882a593Smuzhiyun 	      enum halmac_interface intf, struct halmac_adapter *adapter);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun static u8
87*4882a593Smuzhiyun pltfm_reg_r8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
88*4882a593Smuzhiyun 		  u32 offset);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun static enum halmac_ret_status
91*4882a593Smuzhiyun pltfm_reg_w8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
92*4882a593Smuzhiyun 		  u32 offset, u8 data);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun static u8
95*4882a593Smuzhiyun pltfm_reg_r_indir_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
96*4882a593Smuzhiyun 		       u32 offset);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun static enum halmac_ret_status
99*4882a593Smuzhiyun cnv_to_sdio_bus_offset(u32 *offset);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /**
102*4882a593Smuzhiyun  * halmac_init_adapter() - init halmac_adapter
103*4882a593Smuzhiyun  * @drv_adapter : the adapter of caller
104*4882a593Smuzhiyun  * @pltfm_api : the platform APIs which is used in halmac
105*4882a593Smuzhiyun  * @intf : bus interface
106*4882a593Smuzhiyun  * @halmac_adapter : the adapter of halmac
107*4882a593Smuzhiyun  * @halmac_api : the function pointer of APIs
108*4882a593Smuzhiyun  * Author : KaiYuan Chang / Ivan Lin
109*4882a593Smuzhiyun  * Return : enum halmac_ret_status
110*4882a593Smuzhiyun  * More details of status code can be found in prototype document
111*4882a593Smuzhiyun  */
112*4882a593Smuzhiyun enum halmac_ret_status
halmac_init_adapter(void * drv_adapter,struct halmac_platform_api * pltfm_api,enum halmac_interface intf,struct halmac_adapter ** halmac_adapter,struct halmac_api ** halmac_api)113*4882a593Smuzhiyun halmac_init_adapter(void *drv_adapter, struct halmac_platform_api *pltfm_api,
114*4882a593Smuzhiyun 		    enum halmac_interface intf,
115*4882a593Smuzhiyun 		    struct halmac_adapter **halmac_adapter,
116*4882a593Smuzhiyun 		    struct halmac_api **halmac_api)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun 	struct halmac_adapter *adapter = NULL;
119*4882a593Smuzhiyun 	enum halmac_ret_status status = HALMAC_RET_SUCCESS;
120*4882a593Smuzhiyun 	u8 *buf = NULL;
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	union {
123*4882a593Smuzhiyun 		u32 i;
124*4882a593Smuzhiyun 		u8 x[4];
125*4882a593Smuzhiyun 	} ENDIAN_CHECK = { 0x01000000 };
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 	status = chk_pltfm_api(drv_adapter, intf, pltfm_api);
128*4882a593Smuzhiyun 	if (status != HALMAC_RET_SUCCESS)
129*4882a593Smuzhiyun 		return status;
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT, HALMAC_DBG_ALWAYS,
132*4882a593Smuzhiyun 			     HALMAC_SVN_VER "\n"
133*4882a593Smuzhiyun 			     "HALMAC_MAJOR_VER = %d\n"
134*4882a593Smuzhiyun 			     "HALMAC_PROTOTYPE_VER = %d\n"
135*4882a593Smuzhiyun 			     "HALMAC_MINOR_VER = %d\n"
136*4882a593Smuzhiyun 			     "HALMAC_PATCH_VER = %d\n",
137*4882a593Smuzhiyun 			     HALMAC_MAJOR_VER, HALMAC_PROTOTYPE_VER,
138*4882a593Smuzhiyun 			     HALMAC_MINOR_VER, HALMAC_PATCH_VER);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	if (ENDIAN_CHECK.x[0] == HALMAC_SYSTEM_ENDIAN) {
141*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
142*4882a593Smuzhiyun 				     HALMAC_DBG_ERR,
143*4882a593Smuzhiyun 				     "[ERR]Endian setting err!!\n");
144*4882a593Smuzhiyun 		return HALMAC_RET_ENDIAN_ERR;
145*4882a593Smuzhiyun 	}
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	buf = (u8 *)pltfm_api->RTL_MALLOC(drv_adapter, sizeof(*adapter));
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun 	if (!buf) {
150*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
151*4882a593Smuzhiyun 				     HALMAC_DBG_ERR,
152*4882a593Smuzhiyun 				     "[ERR]Malloc HAL adapter err!!\n");
153*4882a593Smuzhiyun 		return HALMAC_RET_MALLOC_FAIL;
154*4882a593Smuzhiyun 	}
155*4882a593Smuzhiyun 	pltfm_api->RTL_MEMSET(drv_adapter, buf, 0x00, sizeof(*adapter));
156*4882a593Smuzhiyun 	adapter = (struct halmac_adapter *)buf;
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 	*halmac_adapter = adapter;
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	adapter->pltfm_api = pltfm_api;
161*4882a593Smuzhiyun 	adapter->drv_adapter = drv_adapter;
162*4882a593Smuzhiyun 	intf = (intf == HALMAC_INTERFACE_AXI) ? HALMAC_INTERFACE_PCIE : intf;
163*4882a593Smuzhiyun 	adapter->intf = intf;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	if (get_chip_info(drv_adapter, pltfm_api, intf, adapter)
166*4882a593Smuzhiyun 	    != HALMAC_RET_SUCCESS) {
167*4882a593Smuzhiyun 		PLTFM_FREE(*halmac_adapter, sizeof(**halmac_adapter));
168*4882a593Smuzhiyun 		*halmac_adapter = NULL;
169*4882a593Smuzhiyun 		return HALMAC_RET_CHIP_NOT_SUPPORT;
170*4882a593Smuzhiyun 	}
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	PLTFM_MUTEX_INIT(&adapter->efuse_mutex);
173*4882a593Smuzhiyun 	PLTFM_MUTEX_INIT(&adapter->h2c_seq_mutex);
174*4882a593Smuzhiyun 	PLTFM_MUTEX_INIT(&adapter->sdio_indir_mutex);
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun #if (HALMAC_PLATFORM_WINDOWS == 0)
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun #if HALMAC_88XX_SUPPORT
179*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8822B ||
180*4882a593Smuzhiyun 	    adapter->chip_id == HALMAC_CHIP_ID_8821C ||
181*4882a593Smuzhiyun 	    adapter->chip_id == HALMAC_CHIP_ID_8822C ||
182*4882a593Smuzhiyun 	    adapter->chip_id == HALMAC_CHIP_ID_8812F) {
183*4882a593Smuzhiyun 		init_adapter_param_88xx(adapter);
184*4882a593Smuzhiyun 		status = mount_api_88xx(adapter);
185*4882a593Smuzhiyun 	}
186*4882a593Smuzhiyun #endif
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun #if HALMAC_88XX_V1_SUPPORT
189*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8814B) {
190*4882a593Smuzhiyun 		init_adapter_param_88xx_v1(adapter);
191*4882a593Smuzhiyun 		status = mount_api_88xx_v1(adapter);
192*4882a593Smuzhiyun 	}
193*4882a593Smuzhiyun #if defined(HALMAC_DATA_CPU_EN)
194*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8814B) {
195*4882a593Smuzhiyun 		init_adapter_param_88xxd_v1(adapter);
196*4882a593Smuzhiyun 		status = mount_api_88xxd_v1(adapter);
197*4882a593Smuzhiyun 	}
198*4882a593Smuzhiyun #endif
199*4882a593Smuzhiyun #endif
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun #else
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun #if HALMAC_8822B_SUPPORT
204*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8822B) {
205*4882a593Smuzhiyun 		init_adapter_param_win8822b(adapter);
206*4882a593Smuzhiyun 		status = mount_api_win8822b(adapter);
207*4882a593Smuzhiyun 	}
208*4882a593Smuzhiyun #endif
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun #if HALMAC_8821C_SUPPORT
211*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8821C) {
212*4882a593Smuzhiyun 		init_adapter_param_win8821c(adapter);
213*4882a593Smuzhiyun 		status = mount_api_win8821c(adapter);
214*4882a593Smuzhiyun 	}
215*4882a593Smuzhiyun #endif
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun #if HALMAC_8814B_SUPPORT
218*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8814B) {
219*4882a593Smuzhiyun 		init_adapter_param_win8814b_v1(adapter);
220*4882a593Smuzhiyun 		status = mount_api_win8814b_v1(adapter);
221*4882a593Smuzhiyun 	}
222*4882a593Smuzhiyun #endif
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun #if HALMAC_8822C_SUPPORT
225*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8822C) {
226*4882a593Smuzhiyun 		init_adapter_param_win8822c(adapter);
227*4882a593Smuzhiyun 		status = mount_api_win8822c(adapter);
228*4882a593Smuzhiyun 	}
229*4882a593Smuzhiyun #endif
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun #if HALMAC_8812F_SUPPORT
232*4882a593Smuzhiyun 	if (adapter->chip_id == HALMAC_CHIP_ID_8812F) {
233*4882a593Smuzhiyun 		init_adapter_param_win8812f(adapter);
234*4882a593Smuzhiyun 		status = mount_api_win8812f(adapter);
235*4882a593Smuzhiyun 	}
236*4882a593Smuzhiyun #endif
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun #endif
239*4882a593Smuzhiyun 	*halmac_api = (struct halmac_api *)adapter->halmac_api;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun #if HALMAC_DBG_MONITOR_IO
242*4882a593Smuzhiyun 	mount_api_dbg(adapter);
243*4882a593Smuzhiyun #endif
244*4882a593Smuzhiyun 	PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	return status;
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun /**
250*4882a593Smuzhiyun  * halmac_halt_api() - stop halmac_api action
251*4882a593Smuzhiyun  * @adapter : the adapter of halmac
252*4882a593Smuzhiyun  * Author : Ivan Lin
253*4882a593Smuzhiyun  * Return : enum halmac_ret_status
254*4882a593Smuzhiyun  * More details of status code can be found in prototype document
255*4882a593Smuzhiyun  */
256*4882a593Smuzhiyun enum halmac_ret_status
halmac_halt_api(struct halmac_adapter * adapter)257*4882a593Smuzhiyun halmac_halt_api(struct halmac_adapter *adapter)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun 	PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 	adapter->halmac_state.api_state = HALMAC_API_STATE_HALT;
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun 	PLTFM_MSG_TRACE("[TRACE]%s <===\n", __func__);
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun /**
269*4882a593Smuzhiyun  * halmac_deinit_adapter() - deinit halmac adapter
270*4882a593Smuzhiyun  * @adapter : the adapter of halmac
271*4882a593Smuzhiyun  * Author : KaiYuan Chang / Ivan Lin
272*4882a593Smuzhiyun  * Return : enum halmac_ret_status
273*4882a593Smuzhiyun  * More details of status code can be found in prototype document
274*4882a593Smuzhiyun  */
275*4882a593Smuzhiyun enum halmac_ret_status
halmac_deinit_adapter(struct halmac_adapter * adapter)276*4882a593Smuzhiyun halmac_deinit_adapter(struct halmac_adapter *adapter)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun 	PLTFM_MSG_TRACE("[TRACE]%s ===>\n", __func__);
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 	PLTFM_MUTEX_DEINIT(&adapter->efuse_mutex);
281*4882a593Smuzhiyun 	PLTFM_MUTEX_DEINIT(&adapter->h2c_seq_mutex);
282*4882a593Smuzhiyun 	PLTFM_MUTEX_DEINIT(&adapter->sdio_indir_mutex);
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun 	if (adapter->efuse_map) {
285*4882a593Smuzhiyun 		PLTFM_FREE(adapter->efuse_map, adapter->hw_cfg_info.efuse_size);
286*4882a593Smuzhiyun 		adapter->efuse_map = (u8 *)NULL;
287*4882a593Smuzhiyun 	}
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	if (adapter->sdio_fs.macid_map) {
290*4882a593Smuzhiyun 		PLTFM_FREE(adapter->sdio_fs.macid_map,
291*4882a593Smuzhiyun 			   adapter->sdio_fs.macid_map_size);
292*4882a593Smuzhiyun 		adapter->sdio_fs.macid_map = (u8 *)NULL;
293*4882a593Smuzhiyun 	}
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun 	if (adapter->halmac_state.psd_state.data) {
296*4882a593Smuzhiyun 		PLTFM_FREE(adapter->halmac_state.psd_state.data,
297*4882a593Smuzhiyun 			   adapter->halmac_state.psd_state.data_size);
298*4882a593Smuzhiyun 		adapter->halmac_state.psd_state.data = (u8 *)NULL;
299*4882a593Smuzhiyun 	}
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun 	if (adapter->halmac_api) {
302*4882a593Smuzhiyun 		PLTFM_FREE(adapter->halmac_api, sizeof(struct halmac_api));
303*4882a593Smuzhiyun 		adapter->halmac_api = NULL;
304*4882a593Smuzhiyun 	}
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 	PLTFM_FREE(adapter, sizeof(*adapter));
307*4882a593Smuzhiyun 
308*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun static enum halmac_ret_status
chk_pltfm_api(void * drv_adapter,enum halmac_interface intf,struct halmac_platform_api * pltfm_api)312*4882a593Smuzhiyun chk_pltfm_api(void *drv_adapter, enum halmac_interface intf,
313*4882a593Smuzhiyun 	      struct halmac_platform_api *pltfm_api)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun 	if (!pltfm_api)
316*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 	if (!pltfm_api->MSG_PRINT)
319*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	if (intf == HALMAC_INTERFACE_SDIO) {
322*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD52_READ) {
323*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
324*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-r\n");
325*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
326*4882a593Smuzhiyun 		}
327*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_READ_8) {
328*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
329*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-r8\n");
330*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
331*4882a593Smuzhiyun 		}
332*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_READ_16) {
333*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
334*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-r16\n");
335*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
336*4882a593Smuzhiyun 		}
337*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_READ_32) {
338*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
339*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-r32\n");
340*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
341*4882a593Smuzhiyun 		}
342*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_READ_N) {
343*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
344*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-rn\n");
345*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
346*4882a593Smuzhiyun 		}
347*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD52_WRITE) {
348*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
349*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-w\n");
350*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
351*4882a593Smuzhiyun 		}
352*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_WRITE_8) {
353*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
354*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-w8\n");
355*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
356*4882a593Smuzhiyun 		}
357*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_WRITE_16) {
358*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
359*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-w16\n");
360*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
361*4882a593Smuzhiyun 		}
362*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD53_WRITE_32) {
363*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
364*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-w32\n");
365*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
366*4882a593Smuzhiyun 		}
367*4882a593Smuzhiyun 		if (!pltfm_api->SDIO_CMD52_CIA_READ) {
368*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
369*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]sdio-cia\n");
370*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
371*4882a593Smuzhiyun 		}
372*4882a593Smuzhiyun 	}
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun 	if (intf == HALMAC_INTERFACE_USB || intf == HALMAC_INTERFACE_PCIE) {
375*4882a593Smuzhiyun 		if (!pltfm_api->REG_READ_8) {
376*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
377*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]reg-r8\n");
378*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
379*4882a593Smuzhiyun 		}
380*4882a593Smuzhiyun 		if (!pltfm_api->REG_READ_16) {
381*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
382*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]reg-r16\n");
383*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
384*4882a593Smuzhiyun 		}
385*4882a593Smuzhiyun 		if (!pltfm_api->REG_READ_32) {
386*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
387*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]reg-r32\n");
388*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
389*4882a593Smuzhiyun 		}
390*4882a593Smuzhiyun 		if (!pltfm_api->REG_WRITE_8) {
391*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
392*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]reg-w8\n");
393*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
394*4882a593Smuzhiyun 		}
395*4882a593Smuzhiyun 		if (!pltfm_api->REG_WRITE_16) {
396*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
397*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]reg-w16\n");
398*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
399*4882a593Smuzhiyun 		}
400*4882a593Smuzhiyun 		if (!pltfm_api->REG_WRITE_32) {
401*4882a593Smuzhiyun 			pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
402*4882a593Smuzhiyun 					     HALMAC_DBG_ERR, "[ERR]reg-w32\n");
403*4882a593Smuzhiyun 			return HALMAC_RET_PLATFORM_API_NULL;
404*4882a593Smuzhiyun 		}
405*4882a593Smuzhiyun 	}
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun 	if (!pltfm_api->RTL_FREE) {
408*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
409*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mem-free\n");
410*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
411*4882a593Smuzhiyun 	}
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun 	if (!pltfm_api->RTL_MALLOC) {
414*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
415*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mem-malloc\n");
416*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
417*4882a593Smuzhiyun 	}
418*4882a593Smuzhiyun 	if (!pltfm_api->RTL_MEMCPY) {
419*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
420*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mem-cpy\n");
421*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
422*4882a593Smuzhiyun 	}
423*4882a593Smuzhiyun 	if (!pltfm_api->RTL_MEMSET) {
424*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
425*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mem-set\n");
426*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
427*4882a593Smuzhiyun 	}
428*4882a593Smuzhiyun 	if (!pltfm_api->RTL_DELAY_US) {
429*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
430*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]time-delay\n");
431*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
432*4882a593Smuzhiyun 	}
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	if (!pltfm_api->MUTEX_INIT) {
435*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
436*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mutex-init\n");
437*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
438*4882a593Smuzhiyun 	}
439*4882a593Smuzhiyun 	if (!pltfm_api->MUTEX_DEINIT) {
440*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
441*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mutex-deinit\n");
442*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
443*4882a593Smuzhiyun 	}
444*4882a593Smuzhiyun 	if (!pltfm_api->MUTEX_LOCK) {
445*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
446*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mutex-lock\n");
447*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
448*4882a593Smuzhiyun 	}
449*4882a593Smuzhiyun 	if (!pltfm_api->MUTEX_UNLOCK) {
450*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
451*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]mutex-unlock\n");
452*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
453*4882a593Smuzhiyun 	}
454*4882a593Smuzhiyun 	if (!pltfm_api->EVENT_INDICATION) {
455*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
456*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]event-indication\n");
457*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
458*4882a593Smuzhiyun 	}
459*4882a593Smuzhiyun #if HALMAC_DBG_MONITOR_IO
460*4882a593Smuzhiyun 	if (!pltfm_api->READ_MONITOR) {
461*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
462*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]read-monitor\n");
463*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
464*4882a593Smuzhiyun 	}
465*4882a593Smuzhiyun 	if (!pltfm_api->WRITE_MONITOR) {
466*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
467*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]write-monitor\n");
468*4882a593Smuzhiyun 		return HALMAC_RET_PLATFORM_API_NULL;
469*4882a593Smuzhiyun 	}
470*4882a593Smuzhiyun #endif
471*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun /**
475*4882a593Smuzhiyun  * halmac_get_version() - get HALMAC version
476*4882a593Smuzhiyun  * @version : return version of major, prototype, minor and patch information
477*4882a593Smuzhiyun  * Author : KaiYuan Chang / Ivan Lin
478*4882a593Smuzhiyun  * Return : enum halmac_ret_status
479*4882a593Smuzhiyun  * More details of status code can be found in prototype document
480*4882a593Smuzhiyun  */
481*4882a593Smuzhiyun enum halmac_ret_status
halmac_get_version(struct halmac_ver * version)482*4882a593Smuzhiyun halmac_get_version(struct halmac_ver *version)
483*4882a593Smuzhiyun {
484*4882a593Smuzhiyun 	version->major_ver = (u8)HALMAC_MAJOR_VER;
485*4882a593Smuzhiyun 	version->prototype_ver = (u8)HALMAC_PROTOTYPE_VER;
486*4882a593Smuzhiyun 	version->minor_ver = (u8)HALMAC_MINOR_VER;
487*4882a593Smuzhiyun 	version->patch_ver = (u8)HALMAC_PATCH_VER;
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun static enum halmac_ret_status
get_chip_info(void * drv_adapter,struct halmac_platform_api * pltfm_api,enum halmac_interface intf,struct halmac_adapter * adapter)493*4882a593Smuzhiyun get_chip_info(void *drv_adapter, struct halmac_platform_api *pltfm_api,
494*4882a593Smuzhiyun 	      enum halmac_interface intf, struct halmac_adapter *adapter)
495*4882a593Smuzhiyun {
496*4882a593Smuzhiyun 	u8 chip_id;
497*4882a593Smuzhiyun 	u8 chip_ver;
498*4882a593Smuzhiyun 	u32 cnt;
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun 	if (adapter->intf == HALMAC_INTERFACE_SDIO) {
501*4882a593Smuzhiyun 		pltfm_reg_w8_sdio(drv_adapter, pltfm_api, REG_SDIO_HSUS_CTRL,
502*4882a593Smuzhiyun 				  pltfm_reg_r8_sdio(drv_adapter, pltfm_api,
503*4882a593Smuzhiyun 						    REG_SDIO_HSUS_CTRL) &
504*4882a593Smuzhiyun 						    ~(BIT(0)));
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun 		cnt = 10000;
507*4882a593Smuzhiyun 		while (!(pltfm_reg_r8_sdio(drv_adapter, pltfm_api,
508*4882a593Smuzhiyun 					   REG_SDIO_HSUS_CTRL) & BIT(1))) {
509*4882a593Smuzhiyun 			cnt--;
510*4882a593Smuzhiyun 			if (cnt == 0)
511*4882a593Smuzhiyun 				return HALMAC_RET_SDIO_LEAVE_SUSPEND_FAIL;
512*4882a593Smuzhiyun 		}
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun 		chip_id = pltfm_reg_r_indir_sdio(drv_adapter, pltfm_api,
515*4882a593Smuzhiyun 						 REG_SYS_CFG2);
516*4882a593Smuzhiyun 		chip_ver = pltfm_reg_r_indir_sdio(drv_adapter, pltfm_api,
517*4882a593Smuzhiyun 						  REG_SYS_CFG1 + 1) >> 4;
518*4882a593Smuzhiyun 	} else {
519*4882a593Smuzhiyun 		chip_id = pltfm_api->REG_READ_8(drv_adapter, REG_SYS_CFG2);
520*4882a593Smuzhiyun 		chip_ver = pltfm_api->REG_READ_8(drv_adapter,
521*4882a593Smuzhiyun 						 REG_SYS_CFG1 + 1) >> 4;
522*4882a593Smuzhiyun 	}
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun 	adapter->chip_ver = (enum halmac_chip_ver)chip_ver;
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun 	if (chip_id == CHIP_ID_HW_DEF_8822B) {
527*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_8822B;
528*4882a593Smuzhiyun 	} else if (chip_id == CHIP_ID_HW_DEF_8821C) {
529*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_8821C;
530*4882a593Smuzhiyun 	} else if (chip_id == CHIP_ID_HW_DEF_8814B) {
531*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_8814B;
532*4882a593Smuzhiyun 	} else if (chip_id == CHIP_ID_HW_DEF_8197F) {
533*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_8197F;
534*4882a593Smuzhiyun 	} else if (chip_id == CHIP_ID_HW_DEF_8822C) {
535*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_8822C;
536*4882a593Smuzhiyun 	} else if (chip_id == CHIP_ID_HW_DEF_8812F) {
537*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_8812F;
538*4882a593Smuzhiyun 	} else {
539*4882a593Smuzhiyun 		adapter->chip_id = HALMAC_CHIP_ID_UNDEFINE;
540*4882a593Smuzhiyun 		PLTFM_MSG_ERR("[ERR]Chip id is undefined\n");
541*4882a593Smuzhiyun 		return HALMAC_RET_CHIP_NOT_SUPPORT;
542*4882a593Smuzhiyun 	}
543*4882a593Smuzhiyun 
544*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun 
547*4882a593Smuzhiyun static u8
pltfm_reg_r8_sdio(void * drv_adapter,struct halmac_platform_api * pltfm_api,u32 offset)548*4882a593Smuzhiyun pltfm_reg_r8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
549*4882a593Smuzhiyun 		  u32 offset)
550*4882a593Smuzhiyun {
551*4882a593Smuzhiyun 	u8 value8;
552*4882a593Smuzhiyun 	enum halmac_ret_status status = HALMAC_RET_SUCCESS;
553*4882a593Smuzhiyun 
554*4882a593Smuzhiyun 	if (0 == (offset & 0xFFFF0000))
555*4882a593Smuzhiyun 		offset |= WLAN_IOREG_OFFSET;
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	status = cnv_to_sdio_bus_offset(&offset);
558*4882a593Smuzhiyun 	if (status != HALMAC_RET_SUCCESS)
559*4882a593Smuzhiyun 		return status;
560*4882a593Smuzhiyun 
561*4882a593Smuzhiyun 	value8 = pltfm_api->SDIO_CMD52_READ(drv_adapter, offset);
562*4882a593Smuzhiyun 
563*4882a593Smuzhiyun 	return value8;
564*4882a593Smuzhiyun }
565*4882a593Smuzhiyun 
566*4882a593Smuzhiyun static enum halmac_ret_status
pltfm_reg_w8_sdio(void * drv_adapter,struct halmac_platform_api * pltfm_api,u32 offset,u8 data)567*4882a593Smuzhiyun pltfm_reg_w8_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
568*4882a593Smuzhiyun 		  u32 offset, u8 data)
569*4882a593Smuzhiyun {
570*4882a593Smuzhiyun 	enum halmac_ret_status status = HALMAC_RET_SUCCESS;
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun 	if (0 == (offset & 0xFFFF0000))
573*4882a593Smuzhiyun 		offset |= WLAN_IOREG_OFFSET;
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 	status = cnv_to_sdio_bus_offset(&offset);
576*4882a593Smuzhiyun 
577*4882a593Smuzhiyun 	if (status != HALMAC_RET_SUCCESS)
578*4882a593Smuzhiyun 		return status;
579*4882a593Smuzhiyun 
580*4882a593Smuzhiyun 	pltfm_api->SDIO_CMD52_WRITE(drv_adapter, offset, data);
581*4882a593Smuzhiyun 
582*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
583*4882a593Smuzhiyun }
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun static u8
pltfm_reg_r_indir_sdio(void * drv_adapter,struct halmac_platform_api * pltfm_api,u32 offset)586*4882a593Smuzhiyun pltfm_reg_r_indir_sdio(void *drv_adapter, struct halmac_platform_api *pltfm_api,
587*4882a593Smuzhiyun 		       u32 offset)
588*4882a593Smuzhiyun {
589*4882a593Smuzhiyun 	u8 value8, tmp, cnt = 50;
590*4882a593Smuzhiyun 	u32 reg_cfg = REG_SDIO_INDIRECT_REG_CFG;
591*4882a593Smuzhiyun 	u32 reg_data = REG_SDIO_INDIRECT_REG_DATA;
592*4882a593Smuzhiyun 	enum halmac_ret_status status = HALMAC_RET_SUCCESS;
593*4882a593Smuzhiyun 
594*4882a593Smuzhiyun 	status = cnv_to_sdio_bus_offset(&reg_cfg);
595*4882a593Smuzhiyun 	if (status != HALMAC_RET_SUCCESS)
596*4882a593Smuzhiyun 		return status;
597*4882a593Smuzhiyun 	status = cnv_to_sdio_bus_offset(&reg_data);
598*4882a593Smuzhiyun 	if (status != HALMAC_RET_SUCCESS)
599*4882a593Smuzhiyun 		return status;
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	pltfm_api->SDIO_CMD52_WRITE(drv_adapter, reg_cfg, (u8)offset);
602*4882a593Smuzhiyun 	pltfm_api->SDIO_CMD52_WRITE(drv_adapter, reg_cfg + 1,
603*4882a593Smuzhiyun 				    (u8)(offset >> 8));
604*4882a593Smuzhiyun 	pltfm_api->SDIO_CMD52_WRITE(drv_adapter, reg_cfg + 2,
605*4882a593Smuzhiyun 				    (u8)(BIT(3) | BIT(4)));
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun 	do {
608*4882a593Smuzhiyun 		tmp = pltfm_api->SDIO_CMD52_READ(drv_adapter, reg_cfg + 2);
609*4882a593Smuzhiyun 		cnt--;
610*4882a593Smuzhiyun 	} while (((tmp & BIT(4)) == 0) && (cnt > 0));
611*4882a593Smuzhiyun 
612*4882a593Smuzhiyun 	if (((cnt & BIT(4)) == 0) && cnt == 0)
613*4882a593Smuzhiyun 		pltfm_api->MSG_PRINT(drv_adapter, HALMAC_MSG_INIT,
614*4882a593Smuzhiyun 				     HALMAC_DBG_ERR, "[ERR]sdio indir read\n");
615*4882a593Smuzhiyun 
616*4882a593Smuzhiyun 	value8 = pltfm_api->SDIO_CMD52_READ(drv_adapter, reg_data);
617*4882a593Smuzhiyun 
618*4882a593Smuzhiyun 	return value8;
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun 
621*4882a593Smuzhiyun /*Note: copy from cnv_to_sdio_bus_offset_88xx*/
622*4882a593Smuzhiyun static enum halmac_ret_status
cnv_to_sdio_bus_offset(u32 * offset)623*4882a593Smuzhiyun cnv_to_sdio_bus_offset(u32 *offset)
624*4882a593Smuzhiyun {
625*4882a593Smuzhiyun 	switch ((*offset) & 0xFFFF0000) {
626*4882a593Smuzhiyun 	case WLAN_IOREG_OFFSET:
627*4882a593Smuzhiyun 		*offset &= HALMAC_WLAN_MAC_REG_MSK;
628*4882a593Smuzhiyun 		*offset |= HALMAC_SDIO_CMD_ADDR_MAC_REG << 13;
629*4882a593Smuzhiyun 		break;
630*4882a593Smuzhiyun 	case SDIO_LOCAL_OFFSET:
631*4882a593Smuzhiyun 		*offset &= HALMAC_SDIO_LOCAL_MSK;
632*4882a593Smuzhiyun 		*offset |= HALMAC_SDIO_CMD_ADDR_SDIO_REG << 13;
633*4882a593Smuzhiyun 		break;
634*4882a593Smuzhiyun 	default:
635*4882a593Smuzhiyun 		*offset = 0xFFFFFFFF;
636*4882a593Smuzhiyun 		return HALMAC_RET_CONVERT_SDIO_OFFSET_FAIL;
637*4882a593Smuzhiyun 	}
638*4882a593Smuzhiyun 
639*4882a593Smuzhiyun 	return HALMAC_RET_SUCCESS;
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun 
642