blob: 928ecfcf3a36f1d8963fe415725305c69763b550 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#ifndef __HIF_HAL_H__
2/* !ignore me! */
3#define __HIF_HAL_H__
4
5#include "kal_general_types.h"
6#include "drv_features.h"
7
8#ifdef DRV_HIF_SUPPORT
9
10/* <GROUP CallBackFunctions>
11 FUNCTION
12 HIF_CALLBACK
13 DESCRIPTION
14 HIF callback function
15 HIF callback function is called when HIF interrupt has arrived. It indicates HIF has finished the last data transfer.
16 HIF callback function is called in the context of HISR.
17*/
18typedef void (*HIF_CALLBACK)(void);
19
20/* HIF Handle.
21 HIF handle can be retrieved from hif_open(). It is used for most HIF APIs.
22*/
23typedef kal_uint32 HIF_HANDLE;
24
25/* HIF transfer type.
26 Defines the transfer type of HIF interface.
27*/
28typedef enum
29{
30 /* HIF transfer with A0=1. Use CPU to move data. */
31 HIF_TYPE_A0H_CPU,
32 /* HIF transfer with A0=1. Use DMA to transfer data. */
33 HIF_TYPE_A0H_DMA,
34 /* HIF transfer with A0=0. Use CPU to move data. */
35 HIF_TYPE_A0L_CPU,
36 /* HIF transfer with A0=0. Use DMA to transfer data. */
37 HIF_TYPE_A0L_DMA,
38} HIF_TYPE;
39
40/* HIF result enum.
41*/
42typedef enum
43{
44 /* Indicates no error occurs in the last operation. */
45 HIF_RESULT_OK,
46 /* Indicates some errors have occured in the last operation. */
47 HIF_RESULT_ERROR,
48 /* Indicates the function is not supported on the current platform. */
49 HIF_RESULT_NOT_SUPPORTED,
50 /* Indicates the HIF handle is not valid. */
51 HIF_RESULT_INVALID_HANDLE,
52 /* Indicates the input argument is not valid. */
53 HIF_RESULT_INVALID_ARGUMENT,
54 /* Indicates that the HIF power was not turned on when making HIF transactions. */
55 HIF_RESULT_HIF_NOT_POWER_ON,
56 /* Indicates that the HIF power was not turned on when making HIF transactions. */
57 HIF_RESULT_DMA_IS_BUSY
58} HIF_RESULT;
59
60/*************************************************************************************************************************************
61 * HIF IOCTL code definition.
62 * For detail description and usage of HIF control codes, please refer to <xref target="HIF HAL IOCTL Code" text="HIF IOCTL Code" />.
63 *************************************************************************************************************************************/
64typedef enum
65{
66 /****************************************************************************************************************
67 * Get the current HIF configuration parameters.
68 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_GET_PARAM" />.
69 ****************************************************************************************************************/
70 HIF_IOCTL_GET_PARAM,
71 /****************************************************************************************************************
72 * Set ultra high control for HIF.
73 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_ULTRA_HIGH_CTRL" />.
74 ****************************************************************************************************************/
75 HIF_IOCTL_ULTRA_HIGH_CTRL,
76 /****************************************************************************************************************
77 * Query HIF timing support.
78 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_TIMING_SUPPORT" />.
79 ****************************************************************************************************************/
80 HIF_IOCTL_QUERY_TIMING_SUPPORT,
81 /****************************************************************************************************************
82 * Query HIF capabilities.
83 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_CAPABILITY" />.
84 ****************************************************************************************************************/
85 HIF_IOCTL_QUERY_CAPABILITY,
86 /****************************************************************************************************************
87 * Query HIF clock support.
88 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_CLOCK_SUPPORT" />.
89 ****************************************************************************************************************/
90 HIF_IOCTL_QUERY_CLOCK_SUPPORT,
91 /****************************************************************************************************************
92 * Query HIF power state.
93 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_QUERY_POWER_STATE" />.
94 ****************************************************************************************************************/
95 HIF_IOCTL_QUERY_POWER_STATE,
96 /****************************************************************************************************************
97 * TD realtime support.
98 * For detail description and usage of this control code, please refer to <xref target="HIF_IOCTL_REALTIME_REQUEST" />.
99 ****************************************************************************************************************/
100 HIF_IOCTL_REALTIME_CALLBACK
101} HIF_IOCTL_CODE;
102
103/**********************************
104 * HIF configuration parameters.
105 *
106 * Remarks
107 * <img name="hif_write_timing" />
108 *
109 * <img name="hif_read_timing" />
110 **********************************/
111typedef struct
112{
113 /* Chip Select (LPCE#) to Write Strobe (LWR#) setup time. */
114 kal_uint32 hif_time_c2ws;
115 /* Chip Select (LPCE#) to Write Strobe (LWR#) hold time. */
116 kal_uint32 hif_time_c2wh;
117 /* Write wait state time. */
118 kal_uint32 hif_time_wst;
119 /* Chip Select (LPCE#) to Read Strobe (LRD#) setup time. */
120 kal_uint32 hif_time_c2rs;
121 /* Chip Select (LPCE#) to Read Strobe (LRD#) hold time. */
122 kal_uint32 hif_time_c2rh;
123 /* Read latency time. */
124 kal_uint32 hif_time_rlt;
125 /* Chip Select high width. */
126 kal_uint32 hif_time_chw;
127 /* HIF base clock. Unit in MHz. */
128 kal_uint32 hif_base_clk;
129 /* HIF bus width. */
130 kal_uint32 hif_bus_width;
131} HIF_CONFIG_T;
132
133/* This structure is used as the parameter of HIF_IOCTL_QUERY_TIMING_SUPPORT.
134*/
135typedef struct
136{
137 /* Indicates whether C2WS is supported. */
138 kal_bool c2ws_support;
139 /* Indicates whether C2WH is supported. */
140 kal_bool c2wh_support;
141 /* Indicates whether WST is supported. */
142 kal_bool wst_support;
143 /* Indicates whether C2RS is supported. */
144 kal_bool c2rs_support;
145 /* Indicates whether C2RH is supported. */
146 kal_bool c2rh_support;
147 /* Indicates whether CHW is supported. */
148 kal_bool chw_support;
149 /* Indicates whether RLT is supported. */
150 kal_bool rlt_support;
151} HIF_QUERY_TIMING_SUPPORT_T;
152
153/* This structure is used as the parameter of HIF_IOCTL_QUERY_CLOCK_SUPPORT.
154*/
155typedef struct
156{
157 /* This array contains the supported clock frequencies. Unit in MHz. Value 0 indicates invalid clock frequency.*/
158 kal_uint32 clock[4];
159} HIF_QUERY_CLOCK_SUPPORT_T;
160
161/* This structure is used as the parameter of HIF_IOCTL_QUERY_CAPABILITY.
162*/
163typedef struct
164{
165 /* Minimum value for HIF transfer length. */
166 kal_uint32 transfer_length_min;
167 /* Maximum value for HIF transfer length. */
168 kal_uint32 transfer_length_max;
169} HIF_CAPABILITY_T;
170
171/* This structure is used as the parameter of HIF_IOCTL_ULTRA_HIGH_CTRL.
172*/
173typedef struct
174{
175 /* Enable ultra high signal during HIF transaction. */
176 kal_bool ultra_high_en;
177} HIF_ULTRA_HIGH_CTRL_T;
178
179
180/* This structure is used as the parameter of HIF_IOCTL_QUERY_POWER_STATE.
181*/
182typedef struct
183{
184 /* HIF power state. */
185 kal_bool hif_power_on;
186} HIF_POWER_STATE_T;
187
188/* This structure is used as the parameter of HIF_IOCTL_REALTIME_CALLBACK.
189*/
190typedef struct
191{
192 /* Enable realtime request,Call HIF callback function(hif_hisr) at LISR level. */
193 kal_bool realtime_callback_en;
194} HIF_REALTIME_CALLBACK_T;
195
196/**************************************************************************************************************************************
197 * Function
198 * hif_init
199 * Description
200 * Initialize HIF hardware and structures.
201 * Returns
202 * None.
203 * Remarks
204 * <color Red>This function is called in system initialization. HIF user does not need to call this function.</color>
205 **************************************************************************************************************************************/
206void hif_init(void);
207
208/**************************************************************************************************************************************
209 * Function
210 * hif_open
211 * Description
212 * Open and get HIF handle.
213 * Parameters
214 * port : [IN] HIF port. Zero based port index.
215 * Returns
216 * Return a HIF handle.
217 * Example
218 * <code>
219 * HIF_HANDLE handle;
220 * handle = hif_open(0);
221 * </code>
222 **************************************************************************************************************************************/
223HIF_HANDLE hif_open(kal_uint32 port);
224
225/********************************************************
226 * Function
227 * hif_close
228 * Description
229 * Release a HIF handle.
230 * Parameters
231 * handle : [IN] HIF handle. Retrieved from hif_open().
232 * Returns
233 * Return a HIF result code.
234 * Example
235 * <code>
236 * HIF_HANDLE handle;
237 * handle = hif_open(0);
238 * // HIF operations.
239 * hif_close(handle);
240 * </code>
241 ********************************************************/
242HIF_RESULT hif_close(HIF_HANDLE handle);
243
244/***********************************************************************
245 * Function
246 * hif_config
247 * Description
248 * Configure HIF timing parameters.
249 * HIF parameters must be set before any HIF transmissions.
250 * Parameters
251 * handle : [IN] HIF handle. Retrieved from hif_open().
252 * pConfigParam : [IN] HIF parameters. Refer to HIF_CONFIG_T for details.
253 * Returns
254 * Return a HIF result code.
255 * Example
256 * <code>
257 * HIF_HANDLE handle;
258 * HIF_CONFIG_T hif_config_param;
259 * handle = hif_open(0);
260 * hif_config_param.hif_time_c2ws = 3;
261 * hif_config_param.hif_time_c2wh = 2;
262 * hif_config_param.hif_time_wst = 15;
263 * hif_config_param.hif_time_c2rs = 4;
264 * hif_config_param.hif_time_c2rh = 0;
265 * hif_config_param.hif_time_rlt = 0x1f;
266 * hif_config_param.hif_base_clk = 122;
267 * hif_config_param.hif_bus_width = 16;
268 * hif_config(handle, &hif_config_param);
269 * // ...
270 * hif_close(handle);
271 * </code>
272 ***********************************************************************/
273HIF_RESULT hif_config(HIF_HANDLE handle, HIF_CONFIG_T* pConfigParam);
274
275/*******************************************************************************
276 * Function
277 * hif_write
278 * Description
279 * Fire a HIF transmission for output.
280 * Parameters
281 * handle : [IN] HIF handle. Retrieved from hif_open().
282 * type : [IN] HIF transfer type. Refer to HIF_TYPE for details.
283 * addr : [IN] Data buffer address for output.
284 * size : [IN] Data length for HIF transfer. Unit in bytes.
285 * fCB : [IN] Specifies the callback function when the transmission completes.
286 * If fCB is specified, HIF driver uses interrupt mode. This API is asynchronous.
287 * If fCB is NULL, HIF drvier uses polling mode. This API becomes synchronous.
288 * Returns
289 * Return a HIF result code.
290 * Remarks
291 * If type is set to HIF_TYPE_A0H_CPU or HIF_TYPE_A0L_CPU, fCB is ignored. HIF driver works synchronous in CPU mode.
292 * Example
293 * <code>
294 * HIF_HANDLE handle;
295 * handle = hif_open(0);
296 * // ...
297 *
298 * // Synchronous call.
299 * hif_write(handle, HIF_TYPE_A0H_CPU, hif_test_buffer, 1024, NULL);
300 *
301 * // Asynchronous call.
302 * hif_write(handle, HIF_TYPE_A0H_DMA, hif_test_buffer, 1024, hif_test_cb);
303 * // Wait for a event which is set in callback function.
304 * // ...
305 * hif_close(handle);
306 * </code>
307 *******************************************************************************/
308HIF_RESULT hif_write(HIF_HANDLE handle, HIF_TYPE type, kal_uint32 addr, kal_uint32 size, HIF_CALLBACK fCB);
309
310/*******************************************************************************
311 * Function
312 * hif_read
313 * Description
314 * Fire a HIF transmission for input.
315 * Parameters
316 * handle : [IN] HIF handle. Retrieved from hif_open().
317 * type : [IN] HIF transfer type. Refer to HIF_TYPE for details.
318 * addr : [IN] Data buffer address for input.
319 * size : [IN] Data length for HIF transfer. Unit in bytes.
320 * fCB : [IN] Specifies the callback function when the transmission completes.
321 * If fCB is specified, HIF driver uses interrupt mode. This API is asynchronous.
322 * If fCB is NULL, HIF drvier uses polling mode. This API becomes synchronous.
323 * Returns
324 * Return a HIF result code.
325 * Remarks
326 * If type is set to HIF_TYPE_A0H_CPU or HIF_TYPE_A0L_CPU, fCB is ignored. HIF driver works synchronous in CPU mode.
327 * Example
328 * <code>
329 * HIF_HANDLE handle;
330 * handle = hif_open(0);
331 * // ...
332 *
333 * // Synchronous call.
334 * hif_read(handle, HIF_TYPE_A0H_CPU, hif_test_buffer, 1024, NULL);
335 *
336 * // Asynchronous call.
337 * hif_read(handle, HIF_TYPE_A0H_DMA, hif_test_buffer, 1024, hif_test_cb);
338 * // Wait for a event which is set in callback function.
339 * // ...
340 * hif_close(handle);
341 * </code>
342 *******************************************************************************/
343HIF_RESULT hif_read(HIF_HANDLE handle, HIF_TYPE type, kal_uint32 addr, kal_uint32 size, HIF_CALLBACK fCB);
344
345/*****************************************************************************
346 * Function
347 * hif_power_ctrl
348 * Description
349 * Enable or disable HIF hardware power.
350 * Parameters
351 * handle : [IN] HIF handle. Retrieved from hif_open().
352 * bPowerOn : [IN] Set KAL_TRUE to power on HIF hardware. Set KAL_FALSE to power off HIF hardware.
353 * Returns
354 * Return a HIF result code.
355 * Example
356 * <code>
357 * HIF_HANDLE handle;
358 * handle = hif_open(0);
359 * hif_power_ctrl(handle, KAL_TRUE);
360 * // HIF operations.
361 * hif_power_ctrl(handle, KAL_FALSE);
362 * hif_close(handle);
363 * </code>
364 *****************************************************************************/
365HIF_RESULT hif_power_ctrl(HIF_HANDLE handle, kal_bool bPowerOn);
366
367/*****************************************************************************
368 * Function
369 * hif_ioctl
370 * Description
371 * IO Control for HIF driver.
372 * A series of HIF control code is defined for extension usage. Refer to HIF_IOCTL_CODE.
373 * Parameters
374 * handle : [IN] HIF handle. Retrieved from hif_open().
375 * code : [IN] HIF control code. Refer to HIF_IOCTL_CODE.
376 * pParam : [IN/OUT] Parameter for HIF IO Control. The definition depends on the specified control code. Refer to HIF_IOCTL_CODE.
377 * Returns
378 * Return a HIF result code.
379 * The return value is HIF_RESULT_NOT_SUPPORTED if the current platform does not support the sepcific control code.
380 * Example
381 * <code>
382 * HIF_HANDLE handle;
383 * HIF_CONFIG_T config;
384 * handle = hif_open(0);
385 * hif_ioctl(handle, HIF_IOCTL_GET_PARAM, &amp;config);
386 * hif_close(handle);
387 * </code>
388 *****************************************************************************/
389HIF_RESULT hif_ioctl(HIF_HANDLE handle, HIF_IOCTL_CODE code, void* pParam);
390
391#endif
392
393#endif