MT6620: add the new driver JB2 V1.0
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / common / core / stp_exp.c
1 /*******************************************************************************
2 *                E X T E R N A L   R E F E R E N C E S
3 ********************************************************************************
4 */
5 #if 0    //to do---- need check why need this header file
6 #include <linux/types.h>
7 #include <linux/major.h>
8 #include <linux/errno.h>
9 #include <linux/signal.h>
10 #include <linux/fcntl.h>
11 #include <linux/sched.h>
12 #include <linux/interrupt.h>
13 #include <linux/tty.h>
14 #include <linux/timer.h>
15 #include <linux/ctype.h>
16 #include <linux/mm.h>
17 #include <linux/string.h>
18 #include <linux/slab.h>
19 #include <linux/poll.h>
20 #include <linux/bitops.h>
21 #include <linux/audit.h>
22 #include <linux/file.h>
23 #include <linux/module.h>
24
25 #include <linux/spinlock.h>
26 #include <linux/delay.h> /* udelay() */
27
28 #include <asm/uaccess.h>
29 #include <asm/system.h>
30 #endif
31 #include "stp_core.h"
32 #include "stp_exp.h"
33
34 /*******************************************************************************
35 *                          C O N S T A N T S
36 ********************************************************************************
37 */
38
39
40 /*******************************************************************************
41 *                         D A T A   T Y P E S
42 ********************************************************************************
43 */
44
45
46 /*******************************************************************************
47 *                        P U B L I C   D A T A
48 ********************************************************************************
49 */
50 /*******************************************************************************
51 *                       P R I V A T E   D A T A
52 ********************************************************************************
53 */
54 static MTK_WCN_STP_IF_TX stp_uart_if_tx = NULL;
55 static MTK_WCN_STP_IF_TX stp_sdio_if_tx = NULL;
56 static ENUM_STP_TX_IF_TYPE g_stp_if_type = STP_MAX_IF_TX;
57 static MTK_WCN_STP_IF_RX stp_if_rx = NULL;
58 static MTK_WCN_STP_EVENT_CB event_callback_tbl[MTKSTP_MAX_TASK_NUM] = {0x0};
59 static MTK_WCN_STP_EVENT_CB tx_event_callback_tbl[MTKSTP_MAX_TASK_NUM] = {0x0};
60
61 /******************************************************************************
62 *                   F U N C T I O N   D E C L A R A T I O N S
63 *******************************************************************************
64 */
65
66 /*******************************************************************************
67 *                          F U N C T I O N S
68 ********************************************************************************
69 */
70
71 INT32 mtk_wcn_sys_if_rx(UINT8 *data, INT32 size)
72 {
73     if(stp_if_rx == 0x0)
74     {
75         return (-1);
76     }
77     else
78     {
79         (*stp_if_rx)(data, size);
80         return 0;
81     }
82 }
83
84 static INT32 mtk_wcn_sys_if_tx (
85     const UINT8 *data,
86     const UINT32 size,
87     UINT32 *written_size
88     )
89 {
90
91     if (STP_UART_IF_TX == g_stp_if_type) {
92         return stp_uart_if_tx != NULL ? (*stp_uart_if_tx)(data, size, written_size) : -1;
93     }
94     else if (STP_SDIO_IF_TX == g_stp_if_type) {
95         return stp_sdio_if_tx != NULL ? (*stp_sdio_if_tx)(data, size, written_size) : -1;
96     }
97     else {
98         /*if (g_stp_if_type >= STP_MAX_IF_TX) */ /* George: remove ALWAYS TRUE condition */
99         return (-1);
100     }
101 }
102
103 static INT32 mtk_wcn_sys_event_set(UINT8 function_type)
104 {
105     if((function_type < MTKSTP_MAX_TASK_NUM) && (event_callback_tbl[function_type] != 0x0))
106     {
107         (*event_callback_tbl[function_type])();
108     }
109     else {
110         /* FIXME: error handling */
111         osal_dbg_print("[%s] STP set event fail. It seems the function is not active.\n", __func__);
112     }
113
114     return 0;
115 }
116
117 static INT32 mtk_wcn_sys_event_tx_resume(UINT8 winspace)
118 {
119     int type = 0;
120
121     for(type = 0 ;  type < MTKSTP_MAX_TASK_NUM ; type ++ )
122     {
123         if(tx_event_callback_tbl[type])
124         {
125             tx_event_callback_tbl[type]();
126         }
127     }
128
129     return 0;
130 }
131
132 static INT32 mtk_wcn_sys_check_function_status(UINT8 type, UINT8 op){
133
134     /*op == FUNCTION_ACTIVE, to check if funciton[type] is active ?*/
135     if(!(type >= 0 && type < MTKSTP_MAX_TASK_NUM))
136     {
137         return STATUS_FUNCTION_INVALID;
138     }
139
140     if(op == OP_FUNCTION_ACTIVE)
141     {
142         if(event_callback_tbl[type] != 0x0)
143         {
144             return STATUS_FUNCTION_ACTIVE;
145         }
146         else
147         {
148             return STATUS_FUNCTION_INACTIVE;
149         }
150     }
151     /*you can define more operation here ..., to queury function's status/information*/
152
153     return STATUS_OP_INVALID;
154 }
155
156 INT32 mtk_wcn_stp_register_if_rx(MTK_WCN_STP_IF_RX func)
157 {
158     stp_if_rx = func;
159
160     return 0;    
161 }
162
163 VOID mtk_wcn_stp_set_if_tx_type (
164     ENUM_STP_TX_IF_TYPE stp_if_type
165     )
166 {
167     g_stp_if_type = stp_if_type;
168     osal_dbg_print("[%s] set STP_IF_TX to %s.\n",
169         __FUNCTION__,
170         (STP_UART_IF_TX == stp_if_type)? "UART" : ((STP_SDIO_IF_TX == stp_if_type) ? "SDIO" : "NULL"));
171 }
172
173 INT32 mtk_wcn_stp_register_if_tx (
174     ENUM_STP_TX_IF_TYPE stp_if,
175     MTK_WCN_STP_IF_TX func
176     )
177 {
178     if (STP_UART_IF_TX == stp_if) 
179     {
180         stp_uart_if_tx = func;
181     }
182     else if (STP_SDIO_IF_TX == stp_if) 
183     {
184         stp_sdio_if_tx = func;
185     }
186     else 
187     {
188         osal_dbg_print("[%s] STP_IF_TX(%d) out of boundary.\n", __FUNCTION__, stp_if);
189         return -1;
190     }
191
192     return 0;
193 }
194
195 INT32 mtk_wcn_stp_register_event_cb(INT32 type, MTK_WCN_STP_EVENT_CB func)
196 {
197     if (type < MTKSTP_MAX_TASK_NUM)
198     {
199         event_callback_tbl[type] = func;
200
201         /*clear rx queue*/
202         osal_dbg_print("Flush type = %d Rx Queue\n", type);
203         mtk_wcn_stp_flush_rx_queue(type);
204     }
205
206     return 0;
207 }
208
209 INT32 mtk_wcn_stp_register_tx_event_cb(INT32 type, MTK_WCN_STP_EVENT_CB func)
210 {
211     if(type < MTKSTP_MAX_TASK_NUM)
212     {
213         tx_event_callback_tbl[type] = func;
214     }
215     else
216     {
217         osal_bug_on(0);
218     }
219
220     return 0;
221 }
222
223 INT32 stp_drv_init(VOID)
224 {
225     mtkstp_callback cb =
226     {
227         .cb_if_tx           = mtk_wcn_sys_if_tx,
228         .cb_event_set       = mtk_wcn_sys_event_set,
229         .cb_event_tx_resume = mtk_wcn_sys_event_tx_resume,
230         .cb_check_funciton_status = mtk_wcn_sys_check_function_status
231     };
232
233     return mtk_wcn_stp_init(&cb);
234 }
235
236 VOID stp_drv_exit(VOID)
237 {
238     mtk_wcn_stp_deinit();
239
240     return;
241 }
242
243 EXPORT_SYMBOL(mtk_wcn_stp_register_if_tx);
244 EXPORT_SYMBOL(mtk_wcn_stp_register_if_rx);
245 EXPORT_SYMBOL(mtk_wcn_stp_register_event_cb);
246 EXPORT_SYMBOL(mtk_wcn_stp_register_tx_event_cb);
247 EXPORT_SYMBOL(mtk_wcn_stp_parser_data);
248 EXPORT_SYMBOL(mtk_wcn_stp_send_data);
249 EXPORT_SYMBOL(mtk_wcn_stp_send_data_raw);
250 EXPORT_SYMBOL(mtk_wcn_stp_receive_data);
251 EXPORT_SYMBOL(mtk_wcn_stp_is_rxqueue_empty);
252 EXPORT_SYMBOL(mtk_wcn_stp_set_bluez);
253 EXPORT_SYMBOL(mtk_wcn_stp_is_ready);
254 EXPORT_SYMBOL(mtk_wcn_stp_dbg_log_ctrl);
255
256
257
258
259