blob: 8e3d9e2d2142a8d4b7496f57b9024bb238e95bf6 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/***********************************************************************
2* Copyright (C) 2016, ZTE Corporation.
3*
4* File Name: drvs_tdm.h
5* File Mark:
6* Description: TDM hal interface declaration.
7* Others:
8* Version: v1.0
9* Author: daixunkang
10* Date: 2018-02-26
11*
12* History 1:
13* Date:
14* Version:
15* Author:
16* Modification:
17**********************************************************************/
18#ifndef _HAL_TDM_H
19#define _HAL_TDM_H
20/*************************************************************************
21 * Include files *
22 *************************************************************************/
23#include "drvs_general.h"
24#include "drvs_io_voice.h"
25#include "drvs_i2s.h"
26/*************************************************************************
27 * Macro *
28 *************************************************************************/
29
30
31/**************************************************************************
32* Types *
33 **************************************************************************/
34#define TDM_MOD_CLK_SEL *((volatile UINT32 *)(SOC_CRM_REG_BASE+0x50))
35#define DMA_SEL_CFG *((volatile UINT32 *)(SOC_SYS_REG_BASE+0x120))
36
37typedef enum
38{
39 TDM_NORMAL_MODE,
40 TDM_LOOPBACK_MODE,
41
42 MAX_TDM_TEST_MODE
43} T_ZDrvTdm_TestMode;
44
45typedef enum
46{
47 TDM_MSB_FIRST,
48 TDM_LSB_FIRST,
49
50 MAX_FIRSTBIT
51} T_ZDrvTdm_FstBitSel;
52
53typedef enum {
54 TDM_CLK_8000 = 0x00,
55 TDM_CLK_16000 = 0x01,
56
57 TDM_MAX_CLK
58} T_ZDrvTdm_Clk;
59
60typedef enum
61{
62 TDM_1_SLOT = 0x00,
63 TDM_2_SLOT = 0x01,
64 TDM_3_SLOT = 0x02,
65 TDM_4_SLOT = 0x03,
66 TDM_5_SLOT = 0x04,
67 TDM_6_SLOT = 0x05,
68 TDM_7_SLOT = 0x06,
69 TDM_8_SLOT = 0x07,
70 TDM_9_SLOT = 0x08,
71 TDM_10_SLOT = 0x09,
72 TDM_16_SLOT = 0xa,
73 TDM_32_SLOT = 0xb,
74 TDM_64_SLOT = 0xc,
75 //TDM_128_SLOT = 0x7f,
76
77 MAX_TDM_SLOTNUM
78} T_ZDrvTdm_SlotNum;
79
80typedef enum
81{
82 TDM_TS_8CYCLE = 0x0,
83 TDM_TS_16CYCLE = 0x1,
84 TDM_TS_32CYCLE = 0x2,
85 MAX_TDM_TS_WIDTH
86} T_ZDrvTdm_TsWidth;
87
88/*TDM track select*/
89
90typedef enum
91{
92 TDM_1TS_ENABLE = 0x00,
93 TDM_2TS_ENABLE = 0x01,
94
95 MAX_TDM_TS_ENABLE
96} T_ZDrvTdm_TsEnable;
97
98typedef enum
99{
100 TDM_TX_1BIT_OFFSET = 0x01,
101 TDM_TX_2BIT_OFFSET = 0x02,
102 TDM_TX_3BIT_OFFSET = 0x03,
103 TDM_TX_4BIT_OFFSET = 0x04,
104
105 MAX_TDM_TX_OFFSET
106} T_ZDrvTdm_TxOffset;
107
108typedef enum
109{
110 TDM_RX_1BIT_OFFSET = 0x01,
111 TDM_RX_2BIT_OFFSET = 0x02,
112 TDM_RX_3BIT_OFFSET = 0x03,
113 TDM_RX_4BIT_OFFSET = 0x04,
114
115 MAX_TDM_RX_OFFSET
116} T_ZDrvTdm_RxOffset;
117
118typedef VOID(*T_ZDrvTdm_AUD_PLAY_CB)(VOID);
119/* TDM configuration */
120
121typedef enum
122{
123 TDM_FS_CLK_NEG = 0,
124 TDM_FS_CLK_POS,
125
126 MAX_FS_CLK_SELECT
127} T_ZDrvTdm_FsClkSel;
128
129typedef enum
130{
131 TDM_TX_CLK_NEG = 0,
132 TDM_TX_CLK_POS,
133
134 MAX_TX_CLK_SELECT
135} T_ZDrvTdm_TxClkSel;
136
137typedef enum
138{
139 TDM_RX_CLK_NEG = 0,
140 TDM_RX_CLK_POS,
141
142 MAX_RX_CLK_SELECT
143} T_ZDrvTdm_RxClkSel;
144
145typedef enum
146{
147 TIMING_TDM_FS_1CLK = 0,
148 TIMING_TDM_FS_2CLK,
149 TIMING_TDM_FS_3CLK,
150 TIMING_TDM_FS_4CLK,
151 TIMING_TDM_FS_32CLK = 31,
152
153 MAX_FS_WIDTH
154} T_ZDrvTdm_FsWidth;
155
156typedef enum
157{
158 TIMING_TDM_FS_HIGH = 0,
159 TIMING_TDM_FS_LOW = 1,
160
161 MAX_FS_ACTIVE
162} T_ZDrvTdm_FsActive;
163
164typedef struct
165{
166 BOOL bMaster; /* TRUE: master mode; FALSE: slave mode */
167 UINT32 sample_rate;
168 T_ZDrvTdm_FsClkSel fsClkSel;
169 T_ZDrvTdm_TxClkSel txClkSel;
170 T_ZDrvTdm_RxClkSel rxClkSel;
171 T_ZDrvTdm_TsWidth tTsWidth; /*T_ZDrvTDM_TsWidth*/
172 T_ZDrvTdm_SlotNum tSlotNum;
173 T_ZDrvTdm_FsWidth tFsWidth;
174 T_ZDrvTdm_FsActive tFsActive;
175 T_ZDrvTdm_FstBitSel tTdmFstBit;
176 T_ZDrvTdm_TestMode tTestMode;
177 T_ZDrvTdm_TsEnable tTsEnable;
178 T_ZDrvTdm_TxOffset tTxOffset;
179 T_ZDrvTdm_RxOffset tRxOffset;
180 //T_Tdm_RefClkForTdm refclk;
181
182} T_ZDrvTdm_Cfg;
183
184typedef struct
185{
186 T_ZDrvAudio_Channel channel;
187 UINT32 buffersize;
188 T_ZDrvTdm_AUD_PLAY_CB p_cb;
189} T_ZDrvTdm_Params;
190
191/**************************************************************************
192 * Global Variable *
193 **************************************************************************/
194
195
196/**************************************************************************
197 * Function Prototypes *
198 **************************************************************************/
199/**************************************************************************
200* Function: zDrvTDM_Open
201* Description: This function is used to open a specified TDM device.
202* Parameters:
203* (IN)
204* tId: TDM index
205* (OUT)
206* None.
207* Returns:
208* DRV_SUCCESS: successed.
209* DRV_ERR_NOT_SUPPORTED: this device don't support ioctrl operation.
210* DRV_ERR_INVALID_PARAM: the input parameters are invalid
211* DRV_ERR_OPEN_TIMES: has already been opened
212* DRV_ERROR: error
213* others: others programmer defined error code. for detailed information, please contact with the programmer
214* Others:
215* others error code should be a negative number, and not equal to the value that already be defined in T_ZDrv_ErrCode in drv_pub.h.
216**************************************************************************/
217SINT32 zDrvTdm_Open(T_ZDrvI2s_TransMode tdmTransMode);
218
219SINT32 zDrvTdm_Reset();
220
221/**************************************************************************
222* Function: zDrvTDM_Close
223* Description: This function is used to close a specified TDM device.
224* Parameters:
225* (IN)
226* tId: TDM index
227* (OUT)
228* None.
229* Returns:
230* DRV_SUCCESS: successed.
231* DRV_ERR_NOT_SUPPORTED: this device don't support ioctrl operation.
232* DRV_ERR_NOT_OPENED: has not been opend yet.
233* DRV_ERR_INVALID_PARAM: the input parameters are invalid
234* DRV_ERROR: error
235* others: others programmer defined error code. for detailed information, please contact with the programmer
236* Others:
237* others error code should be a negative number, and not equal to the value that already be defined in T_ZDrv_ErrCode in drv_pub.h.
238* must match the use of zDrvTDM_Open.
239**************************************************************************/
240SINT32 zDrvTdm_Close();
241
242/**************************************************************************
243* Function: zDrvTDM_Start
244* Description: This function is used to start TDM.
245* Parameters:
246* (IN)
247* tId: TDM index
248* (OUT)
249* None.
250* Returns:
251* DRV_SUCCESS: successed.
252* DRV_ERR_NOT_SUPPORTED: this device don't support ioctrl operation.
253* DRV_ERR_NOT_OPENED: has not been opend yet.
254* DRV_ERR_START_TIMES: has been started already.
255* DRV_ERR_INVALID_PARAM: the input parameters are invalid
256* DRV_ERROR: error
257* others: others programmer defined error code. for detailed information, please contact with the programmer
258* Others:
259* others error code should be a negative number, and not equal to the value that already be defined in T_ZDrv_ErrCode in drv_pub.h.
260**************************************************************************/
261SINT32 zDrvTdm_Start(UINT32 buf_size);
262
263/**************************************************************************
264* Function: zDrvTDM_Stop
265* Description: This function is used to stop TDM.
266* Parameters:
267* (IN)
268* tId: TDM index
269* (OUT)
270* None.
271* Returns:
272* DRV_SUCCESS: successed.
273* DRV_ERR_NOT_SUPPORTED: this device don't support ioctrl operation.
274* DRV_ERR_NOT_STARTED: has not been started yet.
275* DRV_ERR_INVALID_PARAM: the input parameters are invalid
276* DRV_ERROR: error
277* others: others programmer defined error code. for detailed information, please contact with the programmer
278* Others:
279* others error code should be a negative number, and not equal to the value that already be defined in T_ZDrv_ErrCode in drv_pub.h.
280* must match the use of zDrvTDM_Start.
281**************************************************************************/
282SINT32 zDrvTdm_Write_Stop();
283SINT32 zDrvTdm_Read_Stop();
284
285/**************************************************************************
286* Function: zDrvTDM_Read
287* Description: This function is used to read data by TDM.
288* Parameters:
289* (IN)
290* tId: TDM index
291* uiLen: buffer length
292* (OUT)
293* pBuf: pointer to the read data buffer
294* Returns:
295* the real byte number of read data if successed
296* DRV_ERR_NOT_SUPPORTED: this device don't support ioctrl operation.
297* DRV_ERR_NOT_STARTED: has not been started yet.
298* DRV_ERR_INVALID_PARAM: the input parameters are invalid
299* DRV_ERROR: error
300* others: others programmer defined error code. for detailed information, please contact with the programmer
301* Others:
302* others error code should be a negative number, and not equal to the value that already be defined in T_ZDrv_ErrCode in drv_pub.h.
303**************************************************************************/
304SINT32 zDrvTdm_Read(UINT8 **pBuf, UINT32 *uiLen);
305
306/**************************************************************************
307* Function: zDrvTDM_Write
308* Description: This function is used to write data by TDM.
309* Parameters:
310* (IN)
311* tId: TDM index
312* pBuf: pointer to the read data buffer
313* uiLen: buffer length
314* (OUT)
315* None.
316* Returns:
317* the real byte number of write data if successed
318* DRV_ERR_NOT_SUPPORTED: this device don't support ioctrl operation.
319* DRV_ERR_NOT_STARTED: has not been started yet.
320* DRV_ERR_INVALID_PARAM: the input parameters are invalid
321* DRV_ERR_BUSY: now is transfering data
322* DRV_ERROR: error
323* others: others programmer defined error code. for detailed information, please contact with the programmer
324* Others:
325* others error code should be a negative number, and not equal to the value that already be defined in T_ZDrv_ErrCode in drv_pub.h.
326**************************************************************************/
327SINT32 zDrvTdm_Write(const UINT8 *pBuf, UINT32 uiLen);
328
329SINT32 zDrvTdm_Write_Start(T_ZDrvTdm_Params *params, T_ZDrvTdm_Cfg *ptCfg);
330SINT32 zDrvTdm_Read_Start(T_ZDrvTdm_Params *params, T_ZDrvTdm_Cfg *ptCfg);
331SINT32 zDrvTdm_Vousb_Start(T_ZDrvTdm_Params *params, T_ZDrvTdm_Cfg *ptCfg);
332
333SINT32 zDrvTdm_GetBuf(UINT8 **pBuf, UINT32 *uiLen);
334SINT32 zDrvTdm_GetRemained(UINT32 *len);
335SINT32 zDrvTdm_FreeBuf(UINT8 *pBuf);
336VOID zDrvTdm_Pause();
337VOID zDrvTdm_Resume();
338
339VOID zDrvTdm_RxRlsSemaBeforeStop();
340VOID zDrvTdm_TxRlsSemaBeforeStop();
341
342#endif /* _HAL_TDM_H */