xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/phl/hal_g6/hal_headers_le.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 - 2020 Realtek Corporation.
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  *****************************************************************************/
15 #ifndef _HAL_HEADERS_LE_H_
16 #define _HAL_HEADERS_LE_H_
17 
18 /* Common definition from PHL */
19 #include "../rtw_general_def.h"
20 #include "../phl_list.h"
21 #include "../phl_status.h"
22 #include "../pltfm_ops.h"
23 #include "../phl_config.h"
24 #include "../phl_types.h"
25 #include "../phl_regulation_def.h"
26 #include "../phl_chnlplan.h"
27 #include "../phl_country.h"
28 #include "../phl_txpwr.h"
29 /* Exported structure/definition from PHL */
30 #include "../phl_util.h"
31 #include "../phl_def.h"
32 #include "../phl_trx_def.h"
33 #include "../phl_wow_def.h"
34 #include "../phl_btc_def.h"
35 #include "../phl_test_def.h"
36 #include "../phl_debug.h"
37 
38 #ifdef CONFIG_PCI_HCI
39 #include "../hci/phl_trx_def_pcie.h"
40 #endif
41 #ifdef CONFIG_USB_HCI
42 #include "../hci/phl_trx_def_usb.h"
43 #endif
44 #ifdef CONFIG_SDIO_HCI
45 #include "../hci/phl_trx_def_sdio.h"
46 #endif
47 
48 /* Common definition from HAL*/
49 #include "hal_general_def.h"
50 /* Exported structure/definition from HAL */
51 #include "hal_def.h"
52 #include "hal_config.h"
53 
54 /*
55 Exported hal API  from HAL
56 Prevent HAL mac/bb/ rf/ btc cross referencing
57 */
58 #include "hal_api_drv.h"
59 
60 #include "hal_io.h" /*exported hal_read, hal_write API from HAL */
61 #include "hal_fw.h"
62 
63 
64 #if 1
hal_mdelay(struct rtw_hal_com_t * h,int ms)65 static inline void hal_mdelay(struct rtw_hal_com_t *h, int ms)
66 {
67 	_os_delay_ms(halcom_to_drvpriv(h), ms);
68 }
hal_udelay(struct rtw_hal_com_t * h,int us)69 static inline void hal_udelay(struct rtw_hal_com_t *h, int us)
70 {
71 	_os_delay_ms(halcom_to_drvpriv(h), us);
72 }
73 
hal_msleep(struct rtw_hal_com_t * h,int ms)74 static inline void hal_msleep(struct rtw_hal_com_t *h, int ms)
75 {
76 	_os_sleep_ms(halcom_to_drvpriv(h),ms);
77 }
78 
hal_usleep(struct rtw_hal_com_t * h,int us)79 static inline void hal_usleep(struct rtw_hal_com_t *h, int us)
80 {
81 	_os_sleep_us(halcom_to_drvpriv(h), us);
82 }
83 
84 #ifdef DBG_HAL_MEM_MOINTOR
hal_mem_alloc(struct rtw_hal_com_t * h,u32 buf_sz)85 static inline void *hal_mem_alloc(struct rtw_hal_com_t *h, u32 buf_sz)
86 {
87 	_os_atomic_sub(halcom_to_drvpriv(h), &(h->hal_mem), buf_sz);
88 	return _os_mem_alloc(halcom_to_drvpriv(h), buf_sz);
89 }
90 
hal_mem_free(struct rtw_hal_com_t * h,void * buf,u32 buf_sz)91 static inline void hal_mem_free(struct rtw_hal_com_t *h, void *buf, u32 buf_sz)
92 {
93 	_os_atomic_add_return(halcom_to_drvpriv(h), &(h->hal_mem), buf_sz);
94 	_os_mem_free(halcom_to_drvpriv(h), buf, buf_sz);
95 }
96 #else
hal_mem_alloc(struct rtw_hal_com_t * h,u32 buf_sz)97 static inline void *hal_mem_alloc(struct rtw_hal_com_t *h, u32 buf_sz)
98 {
99 	return _os_mem_alloc(halcom_to_drvpriv(h), buf_sz);
100 }
101 
hal_mem_free(struct rtw_hal_com_t * h,void * buf,u32 buf_sz)102 static inline void hal_mem_free(struct rtw_hal_com_t *h, void *buf, u32 buf_sz)
103 {
104 	_os_mem_free(halcom_to_drvpriv(h), buf, buf_sz);
105 }
106 #endif /*DBG_HAL_MEM_MOINTOR*/
hal_mem_set(struct rtw_hal_com_t * h,void * buf,s8 value,u32 size)107 static inline void hal_mem_set(struct rtw_hal_com_t *h, void *buf, s8 value, u32 size)
108 {
109 	_os_mem_set(halcom_to_drvpriv(h), buf, value, size);
110 }
111 
hal_mem_cpy(struct rtw_hal_com_t * h,void * dest,void * src,u32 size)112 static inline void hal_mem_cpy(struct rtw_hal_com_t *h, void *dest,
113 						void *src, u32 size)
114 {
115 	_os_mem_cpy(halcom_to_drvpriv(h), dest, src, size);
116 }
117 
hal_mem_cmp(struct rtw_hal_com_t * h,void * dest,void * src,u32 size)118 static inline int hal_mem_cmp(struct rtw_hal_com_t *h, void *dest,
119 						void *src, u32 size)
120 {
121 	return _os_mem_cmp(halcom_to_drvpriv(h), dest, src, size);
122 }
hal_mutex_init(struct rtw_hal_com_t * h,_os_mutex * mutex)123 static inline void hal_mutex_init(struct rtw_hal_com_t *h, _os_mutex *mutex)
124 {
125 	_os_mutex_init(halcom_to_drvpriv(h), mutex);
126 }
hal_mutex_deinit(struct rtw_hal_com_t * h,_os_mutex * mutex)127 static inline void hal_mutex_deinit(struct rtw_hal_com_t *h, _os_mutex *mutex)
128 {
129 	_os_mutex_deinit(halcom_to_drvpriv(h), mutex);
130 }
hal_mutex_lock(struct rtw_hal_com_t * h,_os_mutex * mutex)131 static inline void hal_mutex_lock(struct rtw_hal_com_t *h, _os_mutex *mutex)
132 {
133 	_os_mutex_lock(halcom_to_drvpriv(h), mutex);
134 }
hal_mutex_unlock(struct rtw_hal_com_t * h,_os_mutex * mutex)135 static inline void hal_mutex_unlock(struct rtw_hal_com_t *h, _os_mutex *mutex)
136 {
137 	_os_mutex_unlock(halcom_to_drvpriv(h), mutex);
138 }
hal_init_timer(struct rtw_hal_com_t * h,_os_timer * timer,void (* call_back_func)(void * context),void * context,const char * sz_id)139 static inline void hal_init_timer(struct rtw_hal_com_t *h, _os_timer *timer,
140 			void (*call_back_func)(void* context),
141 			void *context, const char *sz_id)
142 {
143 	_os_init_timer(halcom_to_drvpriv(h), timer, call_back_func, context, sz_id);
144 }
145 
hal_set_timer(struct rtw_hal_com_t * h,_os_timer * timer,u32 ms_delay)146 static inline void hal_set_timer(struct rtw_hal_com_t *h, _os_timer *timer,
147 								u32 ms_delay)
148 {
149 	_os_set_timer(halcom_to_drvpriv(h), timer, ms_delay);
150 }
hal_cancel_timer(struct rtw_hal_com_t * h,_os_timer * timer)151 static inline void hal_cancel_timer(struct rtw_hal_com_t *h, _os_timer *timer)
152 {
153 	_os_cancel_timer(halcom_to_drvpriv(h), timer);
154 }
hal_release_timer(struct rtw_hal_com_t * h,_os_timer * timer)155 static inline void hal_release_timer(struct rtw_hal_com_t *h, _os_timer *timer)
156 {
157 	_os_release_timer(halcom_to_drvpriv(h), timer);
158 }
159 
160 /*IO OPS*/
161 #ifdef CONFIG_PCI_HCI
hal_pci_read8(struct rtw_hal_com_t * h,u32 addr)162 static inline u8 hal_pci_read8(struct rtw_hal_com_t *h,u32 addr)
163 {
164 	return _os_read8_pcie(halcom_to_drvpriv(h), addr);
165 }
hal_pci_read16(struct rtw_hal_com_t * h,u32 addr)166 static inline u16 hal_pci_read16(struct rtw_hal_com_t *h,u32 addr)
167 {
168 	return _os_read16_pcie(halcom_to_drvpriv(h), addr);
169 }
hal_pci_read32(struct rtw_hal_com_t * h,u32 addr)170 static inline u32 hal_pci_read32(struct rtw_hal_com_t *h,u32 addr)
171 {
172 	return _os_read32_pcie(halcom_to_drvpriv(h), addr);
173 }
174 
hal_pci_write8(struct rtw_hal_com_t * h,u32 addr,u8 val)175 static inline int hal_pci_write8(struct rtw_hal_com_t *h, u32 addr, u8 val)
176 {
177 	return _os_write8_pcie(halcom_to_drvpriv(h), addr, val);
178 }
hal_pci_write16(struct rtw_hal_com_t * h,u32 addr,u16 val)179 static inline int hal_pci_write16(struct rtw_hal_com_t *h, u32 addr, u16 val)
180 {
181 	return _os_write16_pcie(halcom_to_drvpriv(h), addr, val);
182 }
hal_pci_write32(struct rtw_hal_com_t * h,u32 addr,u32 val)183 static inline int hal_pci_write32(struct rtw_hal_com_t *h, u32 addr, u32 val)
184 {
185 	return _os_write32_pcie(halcom_to_drvpriv(h), addr, val);
186 }
187 
188 #endif
189 #ifdef CONFIG_USB_HCI
hal_usb_vendor_req(struct rtw_hal_com_t * h,u8 request,u16 value,u16 index,void * pdata,u16 len,u8 requesttype)190 static inline int hal_usb_vendor_req(struct rtw_hal_com_t *h,
191 			u8 request, u16 value, u16 index,
192 			void *pdata, u16 len, u8 requesttype)
193 {
194 	return _os_usbctrl_vendorreq(halcom_to_drvpriv(h), request, value,
195 					index, pdata, len, requesttype);
196 }
197 #endif /*CONFIG_USB_HCI*/
198 
199 
200 #ifdef CONFIG_SDIO_HCI
hal_sdio_cmd52_r8(struct rtw_hal_com_t * h,u32 offset)201 static inline u8 hal_sdio_cmd52_r8(struct rtw_hal_com_t *h, u32 offset)
202 {
203 	return _os_sdio_cmd52_r8(halcom_to_drvpriv(h), offset);
204 }
hal_sdio_cmd53_r8(struct rtw_hal_com_t * h,u32 offset)205 static inline u8 hal_sdio_cmd53_r8(struct rtw_hal_com_t *h, u32 offset)
206 {
207 	return _os_sdio_cmd53_r8(halcom_to_drvpriv(h), offset);
208 }
209 
hal_sdio_cmd53_r16(struct rtw_hal_com_t * h,u32 offset)210 static inline u16 hal_sdio_cmd53_r16(struct rtw_hal_com_t *h, u32 offset)
211 {
212 	return _os_sdio_cmd53_r16(halcom_to_drvpriv(h), offset);
213 }
214 
hal_sdio_cmd53_r32(struct rtw_hal_com_t * h,u32 offset)215 static inline u32 hal_sdio_cmd53_r32(struct rtw_hal_com_t *h, u32 offset)
216 {
217 	return _os_sdio_cmd53_r32(halcom_to_drvpriv(h), offset);
218 }
219 
hal_sdio_cmd53_rn(struct rtw_hal_com_t * h,u32 offset,u32 size,u8 * data)220 static inline u8 hal_sdio_cmd53_rn(struct rtw_hal_com_t *h,
221 					u32 offset, u32 size, u8 *data)
222 {
223 	return _os_sdio_cmd53_rn(halcom_to_drvpriv(h), offset, size, data);
224 }
225 
hal_sdio_cmd53_r(struct rtw_hal_com_t * h,u32 offset,u32 size,u8 * val)226 static inline u8 hal_sdio_cmd53_r(struct rtw_hal_com_t *h,
227 					u32 offset, u32 size, u8 *val)
228 {
229 	size = _ALIGN(size, 4);
230 	if (size > h->block_sz)
231 		size = _ALIGN(size, h->block_sz);
232 	return _os_sdio_cmd53_r(halcom_to_drvpriv(h), offset, size, val);
233 }
234 
hal_sdio_cmd52_w8(struct rtw_hal_com_t * h,u32 offset,u8 val)235 static inline void hal_sdio_cmd52_w8(struct rtw_hal_com_t *h,
236 					u32 offset, u8 val)
237 {
238 	_os_sdio_cmd52_w8(halcom_to_drvpriv(h), offset, val);
239 }
240 
hal_sdio_cmd53_w8(struct rtw_hal_com_t * h,u32 offset,u8 val)241 static inline void hal_sdio_cmd53_w8(struct rtw_hal_com_t *h,
242 					u32 offset, u8 val)
243 {
244 	_os_sdio_cmd53_w8(halcom_to_drvpriv(h), offset, val);
245 }
246 
hal_sdio_cmd53_w16(struct rtw_hal_com_t * h,u32 offset,u16 val)247 static inline void hal_sdio_cmd53_w16(struct rtw_hal_com_t *h,
248 					u32 offset, u16 val)
249 {
250 	_os_sdio_cmd53_w16(halcom_to_drvpriv(h), offset, val);
251 }
252 
hal_sdio_cmd53_w32(struct rtw_hal_com_t * h,u32 offset,u32 val)253 static inline void hal_sdio_cmd53_w32(struct rtw_hal_com_t *h,
254 					u32 offset, u32 val)
255 {
256 	_os_sdio_cmd53_w32(halcom_to_drvpriv(h), offset, val);
257 }
258 
hal_sdio_cmd53_wn(struct rtw_hal_com_t * h,u32 offset,u32 size,u8 * val)259 static inline void hal_sdio_cmd53_wn(struct rtw_hal_com_t *h,
260 					u32 offset, u32 size, u8 *val)
261 {
262 	_os_sdio_cmd53_wn(halcom_to_drvpriv(h), offset, size, val);
263 }
264 
hal_sdio_cmd53_w(struct rtw_hal_com_t * h,u32 offset,u32 size,u8 * val)265 static inline void hal_sdio_cmd53_w(struct rtw_hal_com_t *h,
266 					u32 offset, u32 size, u8 *val)
267 {
268 	size = _ALIGN(size, 4);
269 	if (size > h->block_sz)
270 		size = _ALIGN(size, h->block_sz);
271 
272 	_os_sdio_cmd53_w(halcom_to_drvpriv(h), offset, size, val);
273 }
274 
hal_sdio_f0_read(struct rtw_hal_com_t * h,u32 addr,void * buf,u32 len)275 static inline u8 hal_sdio_f0_read(struct rtw_hal_com_t *h,
276 					u32 addr, void *buf, u32 len)
277 {
278 
279 	return _os_sdio_f0_read(halcom_to_drvpriv(h), addr, buf, len);
280 }
281 
hal_sdio_read_cia_r8(struct rtw_hal_com_t * h,u32 addr)282 static inline u8 hal_sdio_read_cia_r8(struct rtw_hal_com_t *h, u32 addr)
283 {
284 	return _os_sdio_read_cia_r8(halcom_to_drvpriv(h), addr);
285 }
286 
287 #endif /*CONFIG_SDIO_HCI*/
288 
289 #else
290 /*please refer to hal_pltfm_ops.h*/
291 #define hal_mdelay(h, ms)	_os_delay_ms(halcom_to_drvpriv(h), ms)
292 #define hal_udelay(h, us)	_os_delay_ms(halcom_to_drvpriv(h), us)
293 #define hal_msleep(h, ms)	_os_sleep_ms(halcom_to_drvpriv(h),ms)
294 #define hal_usleep(h, us)	_os_sleep_us(halcom_to_drvpriv(h), us)
295 
296 #define hal_mem_alloc(h, buf_sz) _os_mem_alloc(halcom_to_drvpriv(h), buf_sz)
297 #define hal_mem_free(h, buf, buf_sz)	_os_mem_free(halcom_to_drvpriv(h), buf, buf_sz)
298 #define hal_mem_set(h, buf, value, size)	_os_mem_set(halcom_to_drvpriv(h), buf, value, size)
299 #define hal_mem_cpy(h, dest, src, size)	_os_mem_cpy(halcom_to_drvpriv(h), dest, src, size)
300 #define hal_mem_cmp(h, dest, src, size)	_os_mem_cmp(halcom_to_drvpriv(h), dest, src, size)
301 
302 #define hal_mutex_init(h, mutex)	_os_mutex_init(halcom_to_drvpriv(h), mutex)
303 #define hal_mutex_deinit(h, hmutex)	_os_mutex_deinit(halcom_to_drvpriv(h), mutex)
304 #define hal_mutex_lock(h, mutex)	_os_mutex_lock(halcom_to_drvpriv(h), mutex)
305 #define hal_mutex_unlock(h, mutex)	_os_mutex_unlock(halcom_to_drvpriv(h), mutex)
306 
307 #define hal_init_timer(h, timer, call_back_func, context, sz_id) \
308 	_os_init_timer(halcom_to_drvpriv(h), timer, call_back_func, context, sz_id)
309 #define hal_set_timer(h, timer, ms_delay)	_os_set_timer(halcom_to_drvpriv(h), timer, ms_delay)
310 #define hal_cancel_timer(h, timer)		_os_cancel_timer(halcom_to_drvpriv(h), timer)
311 #define hal_release_timer(h, timer)		_os_release_timer(halcom_to_drvpriv(h), timer)
312 
313 /*IO OPS*/
314 #ifdef CONFIG_PCI_HCI
315 #define hal_pci_read8(h, addr)		_os_read8_pcie(halcom_to_drvpriv(h), addr)
316 #define hal_pci_read16(h, addr)		_os_read16_pcie(halcom_to_drvpriv(h), addr)
317 #define hal_pci_read32(h, addr)		_os_read32_pcie(halcom_to_drvpriv(h), addr)
318 #define hal_pci_write8(h, addr, val)	_os_write8_pcie(halcom_to_drvpriv(h), addr, val)
319 #define hal_pci_write16(h, addr, val)	_os_write16_pcie(halcom_to_drvpriv(h), addr, val)
320 #define hal_pci_write32(h, addr, val)	_os_write32_pcie(halcom_to_drvpriv(h), addr, val)
321 #endif
322 
323 #ifdef CONFIG_USB_HCI
324 #define hal_usb_vendor_req(h, request, value, index, pdata, len, requesttype) \
325 	_os_usbctrl_vendorreq(halcom_to_drvpriv(h), request, value, index, pdata, len, requesttype)
326 #endif /*CONFIG_USB_HCI*/
327 
328 #ifdef CONFIG_SDIO_HCI
329 #define hal_sdio_cmd52_r8(h, offset)	_os_sdio_cmd52_r8(halcom_to_drvpriv(h), offset)
330 #define hal_sdio_cmd53_r8(h, offset)	_os_sdio_cmd53_r8(halcom_to_drvpriv(h), offset)
331 #define hal_sdio_cmd53_r16(h, offset)	_os_sdio_cmd53_r16(halcom_to_drvpriv(h), offset)
332 #define hal_sdio_cmd53_r32(h, offset)	_os_sdio_cmd53_r32(halcom_to_drvpriv(h), offset)
333 #define hal_sdio_cmd53_rn(h, offset, size, data) _os_sdio_cmd53_rn(halcom_to_drvpriv(h), offset, size, data)
334 #define hal_sdio_cmd52_w8(h, offset, val)	_os_sdio_cmd52_w8(halcom_to_drvpriv(h), offset, val)
335 #define hal_sdio_cmd53_w8(h, offset, val)	_os_sdio_cmd53_w8(halcom_to_drvpriv(h), offset, val)
336 #define hal_sdio_cmd53_w16(h, offset, val)	_os_sdio_cmd53_w16(halcom_to_drvpriv(h), offset, val)
337 #define hal_sdio_cmd53_w32(h, offset, val)	_os_sdio_cmd53_w32(halcom_to_drvpriv(h), offset, val)
338 #define hal_sdio_f0_read(h, addr, buf, len)	_os_sdio_f0_read(halcom_to_drvpriv(h), addr, buf, len)
339 #define hal_sdio_read_cia_r8(h, addr)		_os_sdio_read_cia_r8(halcom_to_drvpriv(h), addr)
340 #endif /*CONFIG_SDIO_HCI*/
341 #endif
342 
343 
344 #endif /*_HAL_HEADERS_LE_H_*/
345