• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define I2S_FAILURE                (1)
22 #define I2S_SUCCESS                (0)
23 
24 #define I2S_DEV_NAME                "i2s"
25 
26 #define I2S_CMD_MAGIC              (0xe280000)
27 enum
28 {
29 	I2S_CMD_UNIT_ENABLE = I2S_CMD_MAGIC + 1,
30 	I2S_CMD_SET_MSTEN,
31 	I2S_CMD_SELECT_MODE,
32 	I2S_CMD_SET_LRCK,
33 	I2S_CMD_SET_SCK_INV,
34 	I2S_CMD_SET_SCK_LSB,
35 	I2S_CMD_SET_SCK_SYNCLEN,
36 	I2S_CMD_SET_PCM_DLEN,
37 	I2S_CMD_SET_FREQ_DATAWIDTH,
38     I2S_CMD_RXINT_EN,
39     I2S_CMD_TXINT_EN,
40     I2S_CMD_RXOVR_EN,
41     I2S_CMD_TXOVR_EN,
42     I2S_CMD_RXFIFO_CLR_EN,
43     I2S_CMD_TXFIFO_CLR_EN,
44     I2S_CMD_RXINT_MODE,
45     I2S_CMD_TXINT_MODE,
46     I2S_CMD_GET_BUSY,
47     I2S_CMD_ENABLE_INTERRUPT,
48     I2S_CMD_DISABLE_INTERRUPT,
49     I2S_CMD_MASTER_ENABLE,
50     I2S_CMD_SLAVE_ENABLE,
51     I2S_CMD_DISABLE_I2S,
52     I2S_CMD_DMA_MASTER_ENABLE,
53     I2S_CMD_DMA_ISR,
54 };
55 
56 
57 #define I2S_BIT_DEBUG
58 #ifdef I2S_BIT_DEBUG
59 #define bit_dbg(fmt, ...)   BK_LOG_RAW(fmt, ##__VA_ARGS__)
60 #else
61 #define bit_dbg(fmt, ...)
62 #endif
63 
64 #define TX_FINISH_FLAG              (1 << 31)
65 #define I2S_SA
66 enum
67 {
68     I2S_MODE_I2S = 0,
69     I2S_MODE_LEFT_JUST = 1,
70     I2S_MODE_RIGHT_JUST = 2,
71     I2S_MODE_SHORT_SYNC = 4,
72     I2S_MODE_LONG_SYNC = 5,
73     I2S_MODE_NORMAL_2B_D = 6,
74     I2S_MODE_DELAY_2B_D = 7
75 };
76 struct i2s_message
77 {
78 	UINT32 *send_buf;
79 	UINT32 send_len;
80 
81 	UINT32 *recv_buf;
82 	UINT32 recv_len;
83 };
84 
85 typedef struct
86 {
87     UINT32 *p_tx_buf;
88     UINT32 *p_rx_buf;
89     UINT32 trans_done;
90 	volatile UINT32 tx_remain_data_cnt;
91     volatile UINT32 rx_remain_data_cnt;
92 } i2s_trans_t;
93 
94 typedef struct
95 {
96     UINT8 rx_level;
97     UINT8 tx_level;
98 } i2s_level_t;
99 
100 typedef struct
101 {
102     UINT32 freq;
103     UINT32 datawidth;
104 } i2s_rate_t;
105 
106 /*******************************************************************************
107 * Function Declarations
108 *******************************************************************************/
109 void i2s_init(int register_isr);
110 void i2s_exit(void);
111 void i2s_isr(void);
112 UINT8 is_i2s_active(void);
113 
114 #ifdef __cplusplus
115 }
116 #endif
117