blob: a04bbf0f9739391df5a48d15687e3b22709e61f1 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2012
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*******************************************************************************
37 * Filename:
38 * ---------
39 * uart.c
40 *
41 * Project:
42 * --------
43 * TATAKA
44 *
45 * Description:
46 * ------------
47 * This Module defines the uart1 driver and the adaption layer
48 * between driver and TATAKA protocol.
49 * Author:
50 * -------
51 * -------
52 * -------
53 * -------
54 *
55 * ==========================================================================
56 * $Log$
57 *
58 * 07 02 2019 yao.xue
59 * [MOLY00418070] ISR Centralization : remove UART & WDT & Logseq IRQSensitivity/IRQ_Register_LISR
60 * ISR Centralization : remove UART & WDT & Logseq IRQSensitivity/IRQ_Register_LISR
61 *
62 * 04 11 2019 yao.xue
63 * [MOLY00397471] [VMOLY]Use API ust_us_duration take place ust_get_duration
64 * modify API ust_us_duration takeplace ust_get_duration in uart/slt code
65 *
66 * 02 15 2019 panu.peisa
67 * [MOLY00384803] [Gen97][SystemService][Change Request] KAL Refactoring Phase-in
68 *
69 * Added changes to swrd part.
70 *
71 * 10 29 2018 yao.xue
72 * [MOLY00360949] [SWRD] DRVTEST maintain
73 * Fix DRVTEST build pass in SWRD
74 *
75 * 03 13 2018 shenghui.shi
76 * [MOLY00309657] UMOLYE driver warning fix
77 * update UART driver
78 *
79 * 11 21 2017 shenghui.shi
80 * [MOLY00290848] [UMOLYA] Usage of INT_SW_SecVersion
81 * removed no used API INT_SW_SecVersion
82 *
83 * 11 21 2017 shenghui.shi
84 * [MOLY00290848] [UMOLYA] Usage of INT_SW_SecVersion
85 * remove INT_SW_SecVersion API from UART driver. This API is not used in 93/95
86 *
87 *
88 * 11 07 2017 shenghui.shi
89 * [MOLY00288093] update UART driver to remove no needed project option
90 * .
91 *
92 * 11 07 2017 shenghui.shi
93 * [MOLY00288093] update UART driver to remove no needed project option
94 * update uart driver to remove no needed files
95 *
96 * 11 03 2017 shenghui.shi
97 * [MOLY00287577] UMOLYA HISR coding change for UART part
98 * .
99 *
100 * 10 24 2017 yao.xue
101 * [MOLY00284920] [Cervino] UART driver porting for Cervino.
102 *
103 * 09 15 2017 da.li
104 * [MOLY00270315] [System Service][KIR] make ex robust before ex steplog work
105 * Replace INT_QueryExceptionStatus with #include <ex_public.h>.
106 *
107 * 09 08 2017 da.li
108 * [MOLY00274163] [Sylvia] Driver porting
109 * Build warning(error) fix.
110 *
111 * 09 07 2017 da.li
112 * [MOLY00274163] [Sylvia] Driver porting
113 * UART driver porting for Sylvia.
114 *
115 * 07 13 2017 shenghui.shi
116 * [MOLY00263518] Update UART driver test code
117 * fix build error
118 *
119 * 07 13 2017 shenghui.shi
120 * [MOLY00263518] Update UART driver test code
121 * update UART driver
122 *
123 * 06 12 2017 flamingo.wang
124 * [MOLY00244966] [ZION][IDC] add chip define of MT6739 in idc driver
125 * Add MT6739 define
126 *
127 * 06 12 2017 flamingo.wang
128 * [MOLY00254599] Normal mode UARTDriver���ܳ�Log
129 * norm uart mode print log fix
130 *
131 * 04 24 2017 shenghui.shi
132 * [MOLY00243727] update UART PDN feature
133 * update UART pdn feature,to void system could not entry DCM issue.
134 *
135 * 03 07 2017 shenghui.shi
136 * [MOLY00233604] UART print driver update for baudrate
137 * update UART driver for uart include.
138 *
139 * 02 07 2017 shenghui.shi
140 * [MOLY00228102] [Bianco Bring-up]UMOLYA uart driver update
141 * update UART dbgprint driver
142 *
143 * 09 22 2016 yuke.ren
144 * [MOLY00204183] Fix UART HDMA usage
145 * set RX SEL for RX channel
146 *
147 *
148 * 09 20 2016 yuke.ren
149 * [MOLY00204183] Fix UART HDMA usage
150 * .
151 *
152 * 07 15 2016 shenghui.shi
153 * [MOLY00171995] update uart driver for 93
154 * update UART cloclk to 26MHz (after GEN93 Bitfile 2016071380)
155 *
156 * 05 19 2016 shenghui.shi
157 * [MOLY00175766] NVRAM update for UMOLYA
158 * modify UART 26MHz macro to 20.8MHz to match real clock freq.
159 *
160 * 03 30 2016 shenghui.shi
161 * [MOLY00171995] update uart driver for 93
162 * update uart driver for 93.
163 *
164 * 01 27 2016 shenghui.shi
165 * [MOLY00081492] [UART] update uart driver
166 * use sst_get_exception_count() to replace INT_Exception_Enter.
167 *
168 * 01 22 2016 shenghui.shi
169 * [MOLY00162415] [Coverity inspect] driver coding issue fix
170 * [coverity inspect]driver coding issue fix
171 *
172 * 01 15 2016 shenghui.shi
173 * [MOLY00081492] [UART] update uart driver
174 * Merging
175 *
176 * update UART debug driver to use HMDA mode.
177 *
178 * 10 13 2015 shenghui.shi
179 * [MOLY00145129] fixed EWS build error which caused by UART IRQ naming exchange on ELBRUS
180 * .
181 *
182 * 10 13 2015 shenghui.shi
183 * [MOLY00145129] fixed EWS build error which caused by UART IRQ naming exchange on ELBRUS
184 * .
185 *
186 * 08 17 2015 shenghui.shi
187 * [MOLY00137551] [MOLY_LINUX_DOWNLOADBIN notify] ELBRUS_FPGA(BASIC) build error
188 * <saved by Perforce>
189 *
190 * 06 18 2015 da.li
191 * [MOLY00121478] [UMOLY][JADE]UART driver compile error fix
192 * Compile error fix on JADE(MT6755).
193 *
194 * 06 15 2015 da.li
195 * [MOLY00121478] [UMOLY][JADE]UART driver compile error fix
196 * UART driver compile error fix on MT6755(JADE).
197 *
198 * 05 11 2015 shenghui.shi
199 * [MOLY00081492] [UART] update uart driver
200 * pdn clear UART/GDMA clock before use UART driver
201 *
202 * 04 02 2015 tero.jarkko
203 * [MOLY00094214] [System Service][MOLY Kernel Internal Request]Modify driver HISR to individual HISR
204 *
205 * 03 25 2015 shenghui.shi
206 * [MOLY00104131] [UMOLY][Klocwork] Fix potential code defect in uart driver
207 * .
208 *
209 * 02 11 2015 shenghui.shi
210 * [MOLY00081492] [UART] update uart driver
211 * fix ews build error
212 *
213 * 02 11 2015 shenghui.shi
214 * [MOLY00081492] [UART] update uart driver
215 * 1. add sw escape feature to UMOLY
216 * 2. phase out VFIFO hw code in devdrv_common.c
217 *
218 * 12 18 2014 shenghui.shi
219 * [MOLY00081492] [UART] update uart driver
220 * .
221 *
222 * 11 17 2014 shenghui.shi
223 * [MOLY00084720] update UMOLY HDMA HISR
224 * move GDMA2 to DEVDRV share HISR
225 *
226 * 11 17 2014 shenghui.shi
227 * [MOLY00084720] update UMOLY HDMA HISR
228 * .
229 *
230 * 05 13 2014 shenghui.shi
231 * [MOLY00062001] TK6291 UART Fix EWS error
232 * .
233 *
234 * 05 13 2014 shenghui.shi
235 * [MOLY00065467] [TK6291] update UART driver for TK6291
236 * update UART clock to 26MHZ for TK6291
237 *
238 * 04 08 2014 shenghui.shi
239 * [MOLY00062001] TK6291 UART Fix EWS error
240 * .
241 *
242 * 04 08 2014 shenghui.shi
243 * [MOLY00062003] [MakeFile] [Modify Common Makefile] Disable __CUST_NEW__
244 * update a patch for no __FPGA__ macro
245 *
246 * 04 08 2014 shenghui.shi
247 * [MOLY00062001] TK6291 UART Fix EWS error
248 * update uart driver to fix ews error
249 *
250 * 01 10 2014 shenghui.shi
251 * [MOLY00043671] [klocwork_95][LTE] in uart.c, line 428
252 * .
253 *
254 * 01 10 2014 shenghui.shi
255 * [MOLY00043674] [klocwork_95][LTE] in uart.c, line 2247
256 * update uart driver to fix uninitial risk.
257 *
258 * 01 09 2014 shenghui.shi
259 * [MOLY00052974] MT6595 UART driver merge to Trunk
260 * MT6595 uart driver merge to MOLY TRUNK
261 *
262 * 12 10 2013 shenghui.shi
263 * [MOLY00049628] MT6595 UART merge to Trunk
264 * .
265 *
266 * 10 29 2013 shenghui.shi
267 * [MOLY00044172] uart all memory dump
268 * .
269 *
270 * 10 02 2013 vend_brandon-hy.lin
271 * [MOLY00040071] [MT6290] SRCLKEN cannot be toggled when LTE sleep feature is enable
272 * Fix SRCLEN_OUT0 cannot be toggle when LTE sleep feature is enable.
273 * Solution: enlarge transmission time of dummy fdma patch.
274 *
275 * 09 13 2013 shenghui.shi
276 * [MOLY00035078] [MT6290][PDN] Enable GDMA & HDMA related module PDN support
277 * move uart pdn_clr from dcl_tty.c to uart.c
278 *
279 * 09 03 2013 shenghui.shi
280 * [MOLY00036272] open UART SlEEP_EN feature
281 * open uart SLEEP_EN feature when MTK_SLEEP_EN enable.
282 *
283 * 08 29 2013 shenghui.shi
284 * [MOLY00035659] [MOLY] [MT6290][SLT] SLT Tool Communication API for driver test
285 * .
286 *
287 * 08 29 2013 shenghui.shi
288 * [MOLY00035768] fix uart build warnning
289 * .
290 *
291 * 08 26 2013 shenghui.shi
292 * [MOLY00035078] [MT6290][PDN] Enable GDMA & HDMA related module PDN support
293 * add uart PDN feature
294 *
295 * 08 14 2013 shenghui.shi
296 * [MOLY00033671] update exception uart driver for void use qbm_dest_q
297 * .
298 *
299 * 08 12 2013 shenghui.shi
300 * [MOLY00033396] update dummy_fdma() patch
301 * .
302 *
303 * 08 02 2013 shenghui.shi
304 * [MOLY00032203] update dummy_fdma for GDMA sleep ack issue
305 * update dummy_fdma() for GDMA sleep ack issue
306 * 08/02/2013 shenghui.shi
307 * [MOLY00032203]update dummy_fdma() for GDMA sleep ack issue
308 *
309 * 07 29 2013 shenghui.shi
310 * [MOLY00030921] [MT6290]Low Power Feature patch back from CBr
311 * merge UART dummy_fdma() patch from Branch to Trunk.
312 *
313 * 04 24 2013 shenghui.shi
314 * [MOLY00020330] MT6290 UART driver update
315 * uart driver update: modify the uart_hdma_isr().
316 *
317 * 04 03 2013 shenghui.shi
318 * [MOLY00012769] IOMUX driver
319 * update UART driver: add ASIC version for UART_CLOCK
320 *
321 * 02 04 2013 ansel.liao
322 * [MOLY00006575] Add UART/HDMA Driver
323 * rename: 7208 -> 6290
324 *
325 * 01 29 2013 ansel.liao
326 * [MOLY00006575] Add UART/HDMA Driver
327 * Integration change.
328 *
329 * 01 22 2013 ansel.liao
330 * [MOLY00006575] USIM driver modification
331 * *: remove an en-Q situation which won't occur
332 *
333 * 01 15 2013 ansel.liao
334 * [MOLY00006575] Add UART/HDMA Driver
335 * *: recover U_GetUARTByte function, WCP3/SE7/SD9 Chuanbo need this function to verify MSDC driver (port from MT6280)
336 *
337 * 01 14 2013 ansel.liao
338 * [MOLY00006575] Add UART/HDMA Driver
339 * Integration change.
340 *
341 * 01 04 2013 ansel.liao
342 * [MOLY00006575] Add UART/HDMA Driver
343 * *: clear rx data timeout counter periodly to prevent XON/XOFF of sw flow control to destroy rx data timeout mechanism
344 *
345 * 01 02 2013 ansel.liao
346 * [MOLY00006575] Add UART/HDMA Driver
347 * *: does not destroy rx queue when head of queue is null
348 *
349 * 12 26 2012 ansel.liao
350 * [MOLY00006575] Add UART/HDMA Driver
351 * Integration change.
352 *
353 * 12 25 2012 ansel.liao
354 * [MOLY00006575] Add UART/HDMA Driver
355 * *: free all TGPD/RGPD when TTY_CMD_EXCEPTION_CLEAR_CHANNEL is get
356 *
357 * 12 19 2012 ansel.liao
358 * [MOLY00006575] Add UART/HDMA Driver
359 * Integration change.
360 *
361 * 12 06 2012 ansel.liao
362 * [MOLY00006575] Add UART/HDMA Driver
363 * Integration change.
364 *
365 * 11 30 2012 ansel.liao
366 * [MOLY00006575] Add UART/HDMA Driver
367 * add dbg_flush and corresponding drvtest
368 *
369 * 11 27 2012 ansel.liao
370 * [MOLY00006575] Add UART/HDMA Driver
371 * update stress test
372 *
373 * 11 25 2012 ansel.liao
374 * [MOLY00006575] Add UART/HDMA Driver
375 * update UART stress test
376 *
377 * 11 23 2012 ansel.liao
378 * [MOLY00006575] Add UART/HDMA Driver
379 * Add UART/HDMA driver
380 ****************************************************************************/
381#include "drv_features.h"
382#include "kal_general_types.h"
383#include "kal_public_api.h"
384#ifdef KTEST_UART_TRACES
385#include "kal_hrt_api.h"
386#endif
387#include "kal_public_defs.h"
388#include "hisr_config.h"
389#include "stack_msgs.h"
390#include "stack_ltlcom.h" /* Task message communiction */
391#include "drv_comm.h"
392#include "reg_base.h"
393#include "uart_hw.h"
394#include "bmd.h"
395#include "intrCtrl.h"
396#include "drvpdn.h"
397#include "stack_config.h" /*MOD_UART1_HISR,MOD_UART2_HISR*/
398#include "uart_sw.h"
399#include "uart_internal.h"
400#include "dcl.h"
401#include "uart_gpd.h"
402#include "drv_msgid.h"
403#include "devdrv_ls.h"
404#include "pll.h"
405#include "drv_gdma.h"
406// for HDMA
407#include "qmu_bm.h"
408#include "qmu_bm_size.h"
409#include "qmu_bm_util.h"
410#include "init.h"
411#include "cpu.h"
412#include "cache_sw.h"
413#include <ex_item.h>
414#include <ex_public.h>
415#if defined(__HMU_ENABLE__)
416#include "hmu.h"
417#include "hmu_conf_data.h"
418#endif
419#include "us_timer.h"
420
421#if !defined(DRV_UART_OFF)
422
423#define UART_CLOCK (26*1000000)
424
425#ifndef MD_IRQID_MDGDMA2
426#define MD_IRQID_MDGDMA2 PS_IRQID_MDGDMA2
427#endif
428
429// To enable or disable META Mode SW Escaping, defined this macro to enable it
430#define META_MODE_SW_ESCAPING
431#define UART_ESCAPE_CHAR 0x77
432#define UART_ECPT_MAX_TIMEOUT 5000 //5s
433
434kal_uint8 UART_handle;
435
436tty_excp_hif_state uart_ecpt_tx_state[MAX_UART_PORT_NUM] =
437{
438 HIF_STATE_NORMAL,
439 HIF_STATE_NORMAL,
440};
441UART_ecpt_timer_t uart_ecpt_timer[MAX_UART_PORT_NUM];
442UARTStruct UARTPort[MAX_UART_PORT_NUM];
443
444#ifdef DRV_DEBUG
445kal_uint8 uart_initialize[MAX_UART_PORT_NUM];
446#endif /*DRV_DEBUG*/
447
448#define DEBUG_PORT uart_port1 // Use UART1 as debug port
449#define DEBUG_BAUDRATE 115200
450kal_int32 init_log_fail_count = 0;
451kal_bool mutex_status = KAL_FALSE;
452kal_mutexid mutexid = 0;
453
454#if __LTE_ONLY__
455#define MCU_BOOT_SPEED 40040000
456#else
457//MCU booting speed 26M/baudrate(bits/second) = 260M/baudrate(bytes/second) = MCU tick/bytes
458#define MCU_BOOT_SPEED 260000000 //Currently all chips use 26M, 260M because of count [MCU ticks/byte]
459#endif
460
461kal_bool send_Txilm[MAX_UART_PORT_NUM] = {// change from kal_uint8 to kal_bool, avoid Warning 641: Converting enum 'kal_bool' to int"
462 KAL_FALSE,
463 KAL_FALSE,
464};
465
466kal_bool send_Rxilm[MAX_UART_PORT_NUM] = {// change from kal_uint8 to kal_bool, avoid Warning 641: Converting enum 'kal_bool' to int"
467 KAL_TRUE,
468 KAL_TRUE,
469};
470
471const VOID_FUNC UART_HISR[MAX_UART_PORT_NUM] =
472{
473 UART1_HISR,
474 UART2_HISR,
475};
476
477const kal_uint32 UART_BaseAddr[MAX_UART_PORT_NUM] =
478{
479 UART1_base,
480 UART2_base,
481};
482#ifdef __DMA_UART_VIRTUAL_FIFO__
483kal_bool UART_VFIFO_support[MAX_UART_PORT_NUM] =
484{
485 KAL_TRUE,
486 KAL_TRUE,
487};
488
489#else
490kal_bool UART_VFIFO_support[MAX_UART_PORT_NUM] =
491{
492 KAL_FALSE,
493 KAL_FALSE,
494};
495#endif/*__DMA_UART_VIRTUAL_FIFO__*/
496
497//Add for new internal func
498void UART2_TrxHandler(void);
499kal_uint8 UART_GetIRQCode(UART_PORT port);
500void uart_qbm_virt_to_phy(void** pp_gpd_head, void** pp_gpd_tail);
501void uart_qbm_phy_to_virt(void**pp_gpd_head, void**pp_gpd_tail);
502void UART_META_PutBytes(UART_PORT port, void * gpd_head, void * gpd_tail);
503kal_uint16 U_ExBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid);
504void UART_META_ExBytes(UART_PORT port, void * gpd_head, void * gpd_tail);
505
506
507
508kal_uint8 uart_escape_state=0;
509
510extern UartDriver_strcut* pUart_CMD_FUNC[];
511#if defined(DRV_DEBUG_BUFFER_DMA_MODE) && !defined(KTEST_UART_TRACES)
512kal_spinlockid print_buf_lock = 0;
513#endif
514//void dummy_fdma(kal_uint32 gdma_start);
515
516
517void UART_Calback(void *parameter);
518void U_ConfigEscape (UART_PORT port, kal_uint8 EscChar, kal_uint16 ESCGuardtime, module_type ownerid);
519void UART_TrxHandler(void *parameter);
520void UART_TxDMAHandler(void *parameter, kal_uint8 chk_done);
521/*UART Customization */
522extern const UART_customize_function_struct *UART_GetFunc(void);
523const UART_customize_function_struct *UartCustomFunc;
524const UART_rings_struct *UART_rings;
525kal_bool WaitForUARTTx[MAX_UART_PORT_NUM] = {KAL_FALSE};
526
527#define ASSERT_WAIT_LOOP 0xffffffff
528#define VFIFO_SWITCH_WAIT_LOOP 100000
529kal_uint16 DELAY_FOR_PUTBYTE = 300;
530
531// for HDMA
532void *uart_tgpd_head[3];
533void *uart_rgpd_head[3];
534void *uart_tgpd_tail[3];
535void *uart_rgpd_tail[3];
536
537void *uart_wait_tgpd_head[3];
538void *uart_wait_tgpd_tail[3];
539
540
541// for UART Exception mode
542kal_uint8 uart_ecpt_bps_buf[UART_ECPT_QBM_BPS_BUF_SZ];
543kal_bool uart_ecpt_init = KAL_FALSE;
544uart_bps_gpd_t uart_bps_gpd;
545
546
547#if defined(DRV_UART_MEMORY_TRACE)
548UART_DRV_DBG_STRUCT UART_DRV_DBG_INFO_DATA;
549/*uart_drv_dbg_trace(NAND_READ_START,drv_get_current_time(),0,0);*/
550void uart_drv_dbg_trace(kal_uint16 index, kal_uint32 time, kal_uint32 data1, kal_uint32 data2)
551{
552 kal_uint32 savedMask;
553 savedMask = SaveAndSetIRQMask();
554 {
555 UART_DRV_DBG_INFO_DATA.dbg_data[UART_DRV_DBG_INFO_DATA.dbg_data_idx&(MAX_UART_DRV_DBG_INFO_SIZE-1)].tag = index;
556 UART_DRV_DBG_INFO_DATA.dbg_data[UART_DRV_DBG_INFO_DATA.dbg_data_idx&(MAX_UART_DRV_DBG_INFO_SIZE-1)].time = time;
557 UART_DRV_DBG_INFO_DATA.dbg_data[UART_DRV_DBG_INFO_DATA.dbg_data_idx&(MAX_UART_DRV_DBG_INFO_SIZE-1)].data1 = data1;
558 UART_DRV_DBG_INFO_DATA.dbg_data[UART_DRV_DBG_INFO_DATA.dbg_data_idx&(MAX_UART_DRV_DBG_INFO_SIZE-1)].data2 = data2;
559 UART_DRV_DBG_INFO_DATA.dbg_data_idx++;
560 }
561 RestoreIRQMask(savedMask);
562}
563#endif //#if defined(DRV_UART_MEMORY_TRACE)
564
565
566
567void uart_customize_init(void)
568{
569 /* retreive the function table */
570 UartCustomFunc=UART_GetFunc();
571 /* use the entry in function table to retreive desired information */
572 UART_rings = UartCustomFunc->UART_Get_Data();
573
574}
575
576kal_bool UART_IsVfifoSetting(UART_PORT port, UART_TxRx_VFIFO_support vs)
577{
578#ifdef __DMA_UART_VIRTUAL_FIFO__
579 if(port >= MAX_UART_PORT_NUM)
580 return KAL_FALSE;
581 if(vs != NONE_VFIFO)
582 return UART_VFIFO_support[port];
583 else //NONE_VFIFO
584 return (kal_bool)!UART_VFIFO_support[port];
585#else
586 if(vs == NONE_VFIFO)
587 return KAL_TRUE;
588 else //NONE_VFIFO
589 return KAL_FALSE;
590#endif
591}
592
593/*check if chip can support auto escape*/
594kal_bool uart_support_autoescape(void)
595{
596 return KAL_TRUE;
597}
598
599void UART_sendilm(UART_PORT port, msg_type msgid) {}
600
601//Add for U_ClrRxBuffer and U_ClrTxBuffer, reduce code size
602void UART_Set_NormalFlowControl(UART_PORT port)
603{
604 if (UARTPort[port].DCB.flowControl == fc_none)
605 DRV_UART_WriteReg(UART_IER(UART_BaseAddr[port]),IER_HW_NORMALINTS);
606 else if (UARTPort[port].DCB.flowControl == fc_hw)
607 DRV_UART_WriteReg(UART_IER(UART_BaseAddr[port]),IER_HW_NORMALINTS);
608 else if (UARTPort[port].DCB.flowControl == fc_sw)
609 DRV_UART_WriteReg(UART_IER(UART_BaseAddr[port]),IER_SW_NORMALINTS);
610}
611
612void U_ClrRxBuffer(UART_PORT port, module_type ownerid) /*clear sw buffer*/
613{
614 kal_uint32 savedMask;
615
616 savedMask = SaveAndSetIRQMask();
617 BWrite_addr(UARTPort[port].Rx_Buffer) = 0;
618 BRead_addr(UARTPort[port].Rx_Buffer) = 0;
619
620// UART_Set_NormalFlowControl(port);
621
622 send_Rxilm[port] = KAL_TRUE;
623 RestoreIRQMask(savedMask);
624
625// HDMA procedure
626 uart_en_q_de_q_with_mutex(port, UART_RX, UART_DE_Q_ALL, NULL, NULL);
627// end of HDMA procedure
628
629}
630
631void U_ClrTxBuffer(UART_PORT port, module_type ownerid) /*clear sw buffer*/
632{
633
634 kal_uint32 savedMask;
635
636 savedMask = SaveAndSetIRQMask();
637
638 BWrite_addr(UARTPort[port].Tx_Buffer) = 0;
639 BRead_addr(UARTPort[port].Tx_Buffer) = 0;
640
641// UART_Set_NormalFlowControl(port);
642
643 send_Txilm[port] = KAL_TRUE;
644
645 RestoreIRQMask(savedMask);
646
647
648// HDMA procedure
649 uart_en_q_de_q_with_mutex(port, UART_TX, UART_DE_Q_ALL, NULL, NULL);
650// end of HDMA procedure
651}
652void UART_EnableTX(UART_PORT port, kal_bool enable)
653{
654 if (port < MAX_UART_PORT_NUM)
655 {
656 UARTPort[port].EnableTX= enable;
657 if(enable == KAL_TRUE){
658 EnableTxIntr(UART_BaseAddr[port]);
659 }else{
660 DisableTxIntr(UART_BaseAddr[port]);
661 }
662 }else{
663 ASSERT(0);
664 }
665}
666
667void UART_SleepOnTx_Enable(UART_PORT port, UART_SLEEP_ON_TX enable_flag) {}
668
669kal_uint16 U_GetBytesAvail(UART_PORT port)
670{
671 kal_uint16 real_count;
672
673 Buf_GetBytesAvail(&(UARTPort[port].Rx_Buffer),real_count);
674
675 return real_count;
676}
677
678kal_uint16 U_GetTxRoomLeft(UART_PORT port)
679{
680 kal_uint16 real_count;
681
682 Buf_GetRoomLeft(&(UARTPort[port].Tx_Buffer),real_count);
683 return real_count;
684}
685
686#ifndef __ROMSA_SUPPORT__ /* Note: for ROM code */
687
688#if defined(__MTK_INTERNAL__) && defined(__MTK_TARGET__)
689kal_uint16 DEVDRV_LS_INTERNCODE
690#else
691kal_uint16
692#endif
693U_GetTxISRRoomLeft(UART_PORT port)
694{
695 return 0;
696}
697
698#endif /* Note: for ROM code */
699
700
701/*
702* FUNCTION
703* GetUARTByte
704*
705* DESCRIPTION
706* This function is to read data from UART
707*
708* CALLS
709* This function is to receive data through UART
710*
711* PARAMETERS
712* None
713*
714* RETURNS
715* the data from UART
716*
717* GLOBALS AFFECTED
718* external_global
719*/
720kal_uint8 U_GetUARTByte(UART_PORT port)
721{
722 kal_uint8 data;
723 kal_uint8 U_GetUARTByteWithTimeOut(UART_PORT port, kal_uint8* ch, kal_uint32 timeout_value);//liming add statement
724 while(!U_GetUARTByteWithTimeOut(port, &data, 0xffffffff)); // for descrease code size (U_GetUARTByte &U_GetUARTByteTimeout)
725 return data;
726}
727
728
729/*
730* FUNCTION
731* GetUARTByte
732*
733* DESCRIPTION
734* This function is to read data from UART
735*
736* CALLS
737* This function is to receive data through UART
738*
739* PARAMETERS
740* None
741*
742* RETURNS
743* the data from UART
744*
745* GLOBALS AFFECTED
746* external_global
747*/
748kal_uint8 U_GetUARTByteWithTimeOut(UART_PORT port, kal_uint8* ch, kal_uint32 timeout_value)
749{
750 kal_uint8 res_byte = 0;
751 kal_uint8 data;
752
753 while(timeout_value != 0)
754 {
755 kal_uint16 LSR;
756 LSR = DRV_UART_Reg(UART_LSR(UART_BaseAddr[port]));
757 if (LSR & UART_LSR_DR)
758 {
759 data = (kal_uint8)DRV_UART_Reg(UART_RBR(UART_BaseAddr[port]));
760 res_byte = 1;
761 //only META port use old flow control escape character,
762 if( (kal_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_DHL_READER)||
763 (uart_support_autoescape()==KAL_FALSE&&UARTPort[port].DCB.flowControl==fc_sw))
764 {
765 if(uart_escape_state==0)
766 {
767 if(data==0x77)
768 uart_escape_state=0x77;
769 else
770 {
771 *ch = data;
772 break;
773 }
774 }
775 else if (uart_escape_state==0x77)
776 {
777 uart_escape_state=0x0;
778
779 if (data == 0x01)
780 {
781 *ch = UARTPort[port].DCB.xonChar;
782 break;
783 }
784 else if (data == 0x02)
785 {
786 *ch = UARTPort[port].DCB.xoffChar;
787 break;
788 }
789 else if (data == 0x03)
790 {
791 *ch = 0x77;
792 break;
793 }
794 }
795 }
796 else
797 {
798 *ch = data;
799 break;
800 }
801 }
802
803 --timeout_value;
804 }
805
806 return res_byte;
807}
808
809/*
810* FUNCTION
811* PutUARTByte
812*
813* DESCRIPTION
814* This function is to write data to UART
815*
816* CALLS
817* This function is to transmit data through UART
818*
819* PARAMETERS
820* None
821*
822* RETURNS
823* the data from UART
824*
825* GLOBALS AFFECTED
826* external_global
827*/
828void PutUARTRingBufferData(UART_PORT port) {}
829
830void UART_PutUARTByte_limited(UART_PORT port, kal_uint8 data)
831{
832 volatile kal_uint16 LSR;
833 kal_uint32 count = 0;
834
835 if(init_log_fail_count > 3)
836 {
837 DRV_UART_WriteReg(UART_THR(UART_BaseAddr[port]),(kal_uint16)data);
838 return;
839 }
840
841 while(1)
842 {
843 LSR = DRV_UART_Reg(UART_LSR(UART_BaseAddr[port]));
844 count++;
845 if ( LSR & UART_LSR_THRE )
846 {
847 DRV_UART_WriteReg(UART_THR(UART_BaseAddr[port]),(kal_uint16)data);
848 break;
849 }
850 else if(count > (MCU_BOOT_SPEED/DEBUG_BAUDRATE) )
851 {
852 DRV_UART_WriteReg(UART_THR(UART_BaseAddr[port]),(kal_uint16)data); //don't care the pending
853 init_log_fail_count++;
854 break;
855 }
856}
857}
858
859void U_PutUARTByte(UART_PORT port, kal_uint8 data) {
860 kal_uint16 LSR;
861
862 while(1)
863 {
864 LSR = DRV_UART_Reg(UART_LSR(UART_BaseAddr[port]));
865 if ( LSR & UART_LSR_THRE )
866 {
867 DRV_UART_WriteReg(UART_THR(UART_BaseAddr[port]),(kal_uint16)data);
868 break;
869 }
870 }
871}
872void PutUARTData(UART_PORT port, kal_uint8 escape_char, kal_uint8 data)
873{
874 if(port >= MAX_UART_PORT_NUM)
875 return;
876
877 //only META port use old flow control escape character,
878if((kal_query_boot_mode() == FACTORY_BOOT && UARTPort[port].DCB.flowControl == fc_sw && UARTPort[port].ownerid == MOD_DHL_READER)
879 || (uart_support_autoescape() == KAL_FALSE && UARTPort[port].DCB.flowControl == fc_sw))
880 {
881 if (data == UARTPort[port].DCB.xonChar)
882 {
883 pUart_CMD_FUNC[port]->PutUARTByte(port, escape_char);
884 pUart_CMD_FUNC[port]->PutUARTByte(port, 0x01);
885 }
886 else if (data == UARTPort[port].DCB.xoffChar)
887 {
888 pUart_CMD_FUNC[port]->PutUARTByte(port, escape_char);
889 pUart_CMD_FUNC[port]->PutUARTByte(port, 0x02);
890 }
891 else if (data == escape_char)
892 {
893 pUart_CMD_FUNC[port]->PutUARTByte(port, escape_char);
894 pUart_CMD_FUNC[port]->PutUARTByte(port, 0x03);
895 }
896 else
897 {
898 pUart_CMD_FUNC[port]->PutUARTByte(port, data);
899 }
900 }
901 else
902 {
903 pUart_CMD_FUNC[port]->PutUARTByte(port, data);
904 }
905}
906
907void PutUARTByteDelay(UART_PORT port, kal_uint8 data)
908{
909 kal_uint16 LSR;
910 kal_uint16 i;
911 if(port >= MAX_UART_PORT_NUM)
912 return;
913
914 while(1)
915 {
916 LSR = DRV_UART_Reg(UART_LSR(UART_BaseAddr[port]));
917
918 if( LSR & UART_LSR_THRE )
919 {
920 for(i = 0; i < DELAY_FOR_PUTBYTE; i++); //add delay...
921 DRV_UART_WriteReg(UART_THR(UART_BaseAddr[port]),(kal_uint16)data);
922 break;
923 }
924 }
925}
926
927void PutUARTDataDelay(UART_PORT port, kal_uint8 escape_char, kal_uint8 data)
928{
929 if(port >= MAX_UART_PORT_NUM)
930 return;
931
932 if( (kal_query_boot_mode()== FACTORY_BOOT && UARTPort[port].DCB.flowControl==fc_sw && UARTPort[port].ownerid==MOD_DHL_READER)||
933 (uart_support_autoescape()==KAL_FALSE))
934 {
935 if (data == UARTPort[port].DCB.xonChar)
936 {
937 PutUARTByteDelay(port, escape_char);
938 PutUARTByteDelay(port, 0x01);
939 }
940 else if (data == UARTPort[port].DCB.xoffChar)
941 {
942 PutUARTByteDelay(port, escape_char);
943 PutUARTByteDelay(port, 0x02);
944 }
945 else if (data == escape_char)
946 {
947 PutUARTByteDelay(port, escape_char);
948 PutUARTByteDelay(port, 0x03);
949 }
950 else
951 {
952 PutUARTByteDelay(port, data);
953 }
954 }
955 else
956 {
957 PutUARTByteDelay(port, data);
958 }
959}
960
961
962kal_uint16 U_ExBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid)
963{
964 kal_uint16 real_count= Length, index;
965 kal_uint16 data_count = 0;
966
967 if((kal_query_boot_mode() == FACTORY_BOOT && UARTPort[port].DCB.flowControl == fc_sw && UARTPort[port].ownerid == MOD_DHL_READER)
968 || (uart_support_autoescape() == KAL_FALSE && UARTPort[port].DCB.flowControl == fc_sw))
969 //if(0)
970 {
971 for(index = 0; (index < real_count) && (data_count < Length); index++)
972 {
973 // The following are for software flow control
974 if(uart_escape_state==0)
975 {
976 if(*(Buffaddr + index) == 0x77)
977 {
978 uart_escape_state=0x77;
979 } else
980 {
981 *(Buffaddr + data_count) = *(Buffaddr + index);
982 data_count++;
983 }
984
985 } else if(uart_escape_state == 0x77)
986 {
987 switch(*(Buffaddr + index))
988 {
989 case 0x01:
990 *(Buffaddr+data_count) = 0x11;//UARTPort[port].DCB.xonChar;
991 data_count++;
992 break;
993 case 0x02:
994 *(Buffaddr+data_count)= 0x13; //UARTPort[port].DCB.xoffChar;
995 data_count++;
996 break;
997 case 0x03:
998 *(Buffaddr + data_count) = 0x77;
999 data_count++;
1000 break;
1001 default:
1002 break;
1003
1004 }
1005 uart_escape_state=0x0;
1006 }
1007
1008
1009 }
1010 }else{
1011 for(index = 0; (index < real_count) && (data_count < Length); index++){
1012 *(Buffaddr + data_count) = *(Buffaddr + index);
1013 data_count++;
1014 }
1015
1016 }
1017
1018 return data_count;
1019}
1020
1021void UART_META_ExBytes(UART_PORT port, void * gpd_head, void * gpd_tail){
1022 hdma_tbd_t *bd_ptr = NULL, *p_bd_cur =NULL;
1023 hdma_tgpd_t *gpd_ptr = NULL;
1024 kal_uint32 gpd_data_len=0, gpd_data_real_len = 0, bd_data_len=0, bd_data_real_len = 0;
1025 kal_uint8 *gpd_data_ptr=NULL, *bd_data_ptr=NULL;
1026
1027
1028 gpd_ptr = (hdma_tgpd_t*)gpd_head;
1029 while(1){
1030 if (QBM_DES_GET_BDP(gpd_ptr)) {
1031 bd_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
1032 p_bd_cur = bd_ptr;
1033 while (1) {
1034 bd_data_len = QBM_DES_GET_DATALEN(p_bd_cur);
1035 if(bd_data_len>0){
1036 bd_data_ptr = QBM_DES_GET_DATAPTR(p_bd_cur);
1037 QBM_CACHE_INVALID(bd_data_ptr, bd_data_len);
1038 bd_data_real_len = U_ExBytes(port,bd_data_ptr ,bd_data_len, NULL, UARTPort[port].ownerid);
1039 if (bd_data_len != bd_data_real_len) {
1040 QBM_CACHE_FLUSH(bd_data_ptr, bd_data_real_len);
1041 QBM_DES_SET_DATALEN(p_bd_cur, bd_data_real_len);
1042 QBM_CACHE_FLUSH(p_bd_cur, QBM_SIZE_TGPD);
1043 }
1044 }
1045 if (QBM_DES_GET_EOL(p_bd_cur)) {
1046 break;
1047 }
1048 p_bd_cur =(void *) QBM_DES_GET_NEXT(p_bd_cur);
1049
1050 }
1051 } else{
1052 gpd_data_len = QBM_DES_GET_DATALEN(gpd_ptr);
1053 if(gpd_data_len>0){
1054 gpd_data_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
1055 QBM_CACHE_INVALID(gpd_data_ptr, gpd_data_len);
1056 gpd_data_real_len = U_ExBytes(port,gpd_data_ptr ,gpd_data_len, NULL, UARTPort[port].ownerid);
1057 if (gpd_data_len != gpd_data_real_len) {
1058 QBM_CACHE_FLUSH(gpd_data_ptr, gpd_data_real_len);
1059 QBM_DES_SET_DATALEN(gpd_ptr,gpd_data_real_len);
1060 QBM_CACHE_FLUSH(gpd_ptr, QBM_SIZE_TGPD);
1061 }
1062 }
1063 }
1064 if(gpd_ptr == gpd_tail)
1065 {
1066 break;
1067 } else
1068 {
1069 gpd_ptr = (void *) QBM_DES_GET_NEXT(gpd_ptr);
1070 }
1071 }
1072}
1073void UART_Boot_PutUARTBytes(UART_PORT port, kal_uint8 *data,kal_uint16 len)
1074{
1075 volatile kal_uint16 LSR;
1076 kal_uint16 index;
1077 static kal_uint32 UART_Boot_Send_Count = 0;
1078
1079 UART_Boot_Send_Count+=len;
1080
1081 for(index=0;index<len;index++)
1082 UART_PutUARTByte_limited(port,*(data+index));
1083
1084 index = 0;
1085 while(1) //make sure tx already send out all data.
1086 {
1087 LSR = DRV_UART_Reg(UART_LSR(UART_BaseAddr[port]));
1088 if( LSR & UART_LSR_THRE )
1089 {
1090 break;
1091 }else if( (MCU_BOOT_SPEED/DEBUG_BAUDRATE) < index++)
1092 {
1093 init_log_fail_count++;
1094 break;
1095 }
1096 }
1097}
1098
1099void U_PutUARTBytes(UART_PORT port, kal_uint8 *data,kal_uint16 len) {
1100 kal_uint16 index;
1101
1102 for(index=0;index<len;index++)
1103 pUart_CMD_FUNC[port]->PutUARTByte(port,*(data+index));
1104
1105}
1106void PutUARTDatas(UART_PORT port, kal_uint8 escape_char, kal_uint8 *data,kal_uint16 len)
1107{
1108 kal_uint16 index;
1109 if(port >= MAX_UART_PORT_NUM)
1110 return;
1111
1112 if( (sst_get_exception_count() > 0) && (0 == UARTPort[port].Tx_DMA_Ch) && (1500000 == UARTPort[port].DCB.baud))
1113 for(index=0;index<len;index++)
1114 PutUARTDataDelay(port,escape_char,*(data+index));
1115 else
1116 for(index=0;index<len;index++)
1117 PutUARTData(port,escape_char,*(data+index));
1118}
1119
1120void U_SetBaudRate(UART_PORT port, UART_baudrate baudrate, module_type ownerid)
1121{
1122 kal_uint16 byte = 0;
1123 kal_uint32 freq_div = 1;
1124 kal_uint32 sample_count = 0;
1125 kal_uint32 UART_BASE;
1126
1127 UART_BASE = UART_BaseAddr[port];
1128 UARTPort[port].DCB.baud = baudrate;
1129
1130 if(baudrate)
1131 {
1132 do {
1133 sample_count = (UART_CLOCK + (freq_div * baudrate / 2)) / (freq_div * baudrate);
1134 if(sample_count > 0xff) freq_div++;
1135 } while(sample_count > 0xff);
1136 }
1137
1138 // configure register
1139 DRV_UART_WriteReg(UART_RATE_STEP(UART_BASE), 0x3);
1140
1141 byte = DRV_Reg32(UART_LCR(UART_BASE)); // DLAB start
1142 DRV_WriteReg32(UART_LCR(UART_BASE), byte | UART_LCR_DLAB);
1143
1144 DRV_WriteReg32(UART_DLL(UART_BASE), freq_div & 0xFF);
1145 DRV_WriteReg32(UART_DLH(UART_BASE), (freq_div >> 8) & 0xFF);
1146
1147 DRV_UART_WriteReg(UART_STEP_COUNT(UART_BASE), sample_count - 1);
1148 DRV_UART_WriteReg(UART_SAMPLE_COUNT(UART_BASE), sample_count >> 1);
1149 DRV_UART_WriteReg(UART_LCR(UART_BASE), byte); // DLAB end
1150}
1151
1152
1153void UART_Bootup_Init()
1154{
1155 UARTPort[DEBUG_PORT].ownerid = (module_type)( (kal_uint16)MOD_UART1_HISR + (kal_uint8) DEBUG_PORT);
1156
1157 //Set SW flow control as equal to catcher default flow control
1158 DRV_UART_WriteReg(UART_LCR(UART1_base),0xbf); /* Enchance setting */
1159 DRV_UART_WriteReg(UART_EFR(UART1_base),UART_EFR_SWFlowCtrlX1);
1160
1161 //always open as new SW flow control, DHL under META will reset to disable
1162 {
1163 DRV_UART_WriteReg(UART_ESCAPE_DAT(UART1_base),0x77);
1164 DRV_UART_WriteReg(UART_ESCAPE_EN(UART1_base),0x1);
1165 }
1166 DRV_UART_WriteReg(UART_XON1(UART1_base),0x11);
1167 DRV_UART_WriteReg(UART_XOFF1(UART1_base),0x13);
1168 DRV_UART_WriteReg(UART_XON2(UART1_base),0x11);
1169 DRV_UART_WriteReg(UART_XOFF2(UART1_base),0x13);
1170 DRV_UART_WriteReg(UART_LCR(UART1_base),0x3);
1171
1172
1173 U_SetBaudRate(DEBUG_PORT, DEBUG_BAUDRATE, (module_type)( (kal_uint16)MOD_UART1_HISR + (kal_uint8) DEBUG_PORT));
1174}
1175
1176/*This function is to cover 6218B/6219 hw bug.
1177UART should not send receiving data to its FIFO when doing auto baud*/
1178void U_SetAutoBaud_Div(UART_PORT port, module_type ownerid) {}
1179
1180void U_SetDCBConfig(UART_PORT port, UARTDCBStruct *UART_Config, module_type ownerid)
1181{
1182 kal_uint16 byte;
1183 kal_uint16 IER;
1184 kal_uint32 savedMask;
1185 kal_uint32 UART_BASE;
1186
1187 UART_BASE = UART_BaseAddr[port];
1188 savedMask = SaveAndSetIRQMask();
1189 IER = DRV_UART_Reg(UART_IER(UART_BASE));
1190 DRV_UART_WriteReg(UART_IER(UART_BASE),UART_IER_ALLOFF);
1191 RestoreIRQMask(savedMask);
1192
1193 U_SetBaudRate(port, UART_Config->baud, ownerid);
1194
1195 /* Setup N81 */
1196 byte = DRV_UART_Reg(UART_LCR(UART_BASE)); /* DLAB start */
1197 byte &= ~UART_DATA_MASK;
1198 switch(UART_Config->dataBits)
1199 {
1200 case len_5:
1201 byte |= UART_WLS_5;
1202 break;
1203
1204 case len_6:
1205 byte |= UART_WLS_6;
1206 break;
1207
1208 case len_7:
1209 byte |= UART_WLS_7;
1210 break;
1211
1212 case len_8:
1213 byte |= UART_WLS_8;
1214 break;
1215
1216 default:
1217 break;
1218 }
1219 byte &= ~UART_STOP_MASK;
1220 switch(UART_Config->stopBits)
1221 {
1222 case sb_1:
1223 byte |= UART_1_STOP;
1224 break;
1225
1226 case sb_2:
1227 byte |= UART_2_STOP;
1228 break;
1229
1230 case sb_1_5:
1231 byte |= UART_1_5_STOP;
1232 break;
1233
1234 default:
1235 break;
1236 }
1237
1238 byte &= ~UART_PARITY_MASK;
1239 switch(UART_Config->parity)
1240 {
1241 case pa_none:
1242 byte |= UART_NONE_PARITY;
1243 break;
1244
1245 case pa_odd:
1246 byte |= UART_ODD_PARITY;
1247 break;
1248
1249 case pa_even:
1250 byte |= UART_EVEN_PARITY;
1251 break;
1252
1253 case pa_space:
1254 byte |= UART_SPACE_PARITY;
1255 break;
1256
1257 default:
1258 break;
1259 }
1260 DRV_UART_WriteReg(UART_LCR(UART_BASE),byte); /* DLAB End */
1261 /* flowControl */
1262 byte = DRV_UART_Reg(UART_LCR(UART_BASE));
1263
1264 DRV_UART_WriteReg(UART_LCR(UART_BASE),0xbf); /* Enchance setting */
1265 switch(UART_Config->flowControl)
1266 {
1267 case fc_none:
1268 DRV_UART_WriteReg(UART_EFR(UART_BASE),UART_EFR_ALLOFF);
1269
1270 // Disable AutoEscape, we expect to use this functionality for S/W flow control
1271 /*For AutoEscape*/
1272 DRV_UART_WriteReg(UART_ESCAPE_EN(UART_BaseAddr[port]),0x0);
1273
1274 break;
1275
1276 case fc_hw:
1277 DRV_UART_WriteReg(UART_EFR(UART_BASE),UART_EFR_AutoRTSCTS);
1278
1279 // Disable AutoEscape, we expect to use this functionality for S/W flow control
1280 /*For AutoEscape*/
1281 DRV_UART_WriteReg(UART_ESCAPE_EN(UART_BaseAddr[port]),0x0);
1282 break;
1283
1284 case fc_sw:
1285
1286 DRV_UART_WriteReg(UART_EFR(UART_BASE), UART_EFR_SWFlowCtrlX1 |UART_EFR_Enchance);
1287 //reset first
1288 DRV_UART_WriteReg(UART_ESCAPE_EN(UART_BaseAddr[port]),0x0);
1289 if(uart_support_autoescape()==KAL_TRUE)
1290 {
1291 /*For META, Dont use auto escape*/
1292#if defined(META_MODE_SW_ESCAPING)
1293 if(kal_query_boot_mode() != FACTORY_BOOT || UARTPort[port].ownerid != MOD_DHL_READER)
1294#endif
1295 {
1296 /*For AutoEscape*/
1297 DRV_UART_WriteReg(UART_ESCAPE_DAT(UART_BaseAddr[port]),0x77);
1298 DRV_UART_WriteReg(UART_ESCAPE_EN(UART_BaseAddr[port]),0x1);
1299 }
1300 }
1301 break;
1302
1303 default:
1304 break;
1305 }
1306 /* XON and XOFF characters */
1307 DRV_UART_WriteReg(UART_XON1(UART_BASE),UART_Config->xonChar);
1308 DRV_UART_WriteReg(UART_XOFF1(UART_BASE),UART_Config->xoffChar);
1309 DRV_UART_WriteReg(UART_XON2(UART_BASE),UART_Config->xonChar);
1310 DRV_UART_WriteReg(UART_XOFF2(UART_BASE),UART_Config->xoffChar);
1311 DRV_UART_WriteReg(UART_LCR(UART_BASE),byte); /* DLAB End */
1312
1313 kal_mem_cpy( &UARTPort[port].DCB, UART_Config, sizeof(UARTDCBStruct) );
1314
1315 savedMask = SaveAndSetIRQMask();
1316 DRV_UART_WriteReg(UART_IER(UART_BASE),IER);
1317 RestoreIRQMask(savedMask);
1318}
1319
1320void U_ReadDCBConfig (UART_PORT port, UARTDCBStruct *DCB)
1321{
1322 kal_mem_cpy( DCB, &UARTPort[port].DCB, sizeof(UARTDCBStruct) );
1323}
1324
1325void UART_loopback(UART_PORT port)
1326{
1327 kal_uint16 tmp;
1328 kal_uint32 UART_BASE;
1329 /* Enable Loop Back test!! */
1330 if(port >= MAX_UART_PORT_NUM)
1331 return;
1332 UART_BASE = UART_BaseAddr[port];
1333 tmp = DRV_UART_Reg(UART_MCR(UART_BASE));
1334 tmp |= UART_MCR_LOOPB;
1335 DRV_UART_WriteReg(UART_MCR(UART_BASE), tmp);
1336}
1337
1338void UART_PDN_Disable(UART_PORT port)
1339{
1340 switch(port)
1341 {
1342 case uart_port1:
1343 PDN_CLR(PDN_UART0);
1344 #if defined(__HIF_UART_SUPPORT__) ||(defined(DRV_DEBUG)&&(defined(DRV_DEBUG_DMA_MODE) || defined(DRV_DEBUG_BUFFER_DMA_MODE)))
1345 HDMA_PDN_CLR(port+2);
1346 HDMA_PDN_CLR(port+3);
1347 #endif
1348 break;
1349 case uart_port2:
1350 PDN_CLR(PDN_UART1);
1351 break;
1352 default:
1353 ASSERT(0);
1354 break;
1355 }
1356}
1357
1358void UART_PDN_Enable(UART_PORT port)
1359{
1360 switch(port)
1361 {
1362 case uart_port1:
1363 PDN_SET(PDN_UART0);
1364 HDMA_PDN_SET(port+2);
1365 HDMA_PDN_SET(port+3);
1366 break;
1367 case uart_port2:
1368 PDN_SET(PDN_UART1);
1369 break;
1370 default:
1371 ASSERT(0);
1372 break;
1373 }
1374}
1375
1376void UART_HWInit(UART_PORT port)
1377{
1378 UARTDCBStruct *DCBdefault;
1379 UARTDCBStruct UART_DefaultConfig =
1380 {
1381 UART_BAUD_1500000, // baud
1382 len_8, // dataBits
1383 sb_1, // stopBits
1384 pa_none, // parity
1385 fc_none, // no flow control
1386 0x11, // xonChar
1387 0x13, // xoffChar
1388 KAL_FALSE
1389 };
1390 kal_uint32 UART_BASE;
1391
1392 if(port >= MAX_UART_PORT_NUM)
1393 return;
1394 UART_BASE = UART_BaseAddr[port];
1395
1396 UART_PDN_Disable(port);
1397
1398 /* Setup N81,(UART_WLS_8 | UART_NONE_PARITY | UART_1_STOP) = 0x03 */
1399 /* BaudRate and autoflowcontrol */
1400 DCBdefault = (UARTDCBStruct *)&UART_DefaultConfig;
1401 U_SetDCBConfig(port, DCBdefault, UARTPort[port].ownerid);
1402
1403 DRV_UART_Reg(UART_LSR(UART_BASE));
1404 DRV_UART_Reg(UART_MSR(UART_BASE));
1405
1406 /* DTR , RTS is on, data will be coming,Output2 is high */
1407 DRV_UART_SetBits(UART_MCR(UART_BASE), UART_MCR_Normal);
1408
1409 DRV_UART_WriteReg(UART_IER(UART_BASE), UART_IER_ALLOFF);
1410
1411 // Set handle value to 0xFF to indicate this handle is invalid
1412 UARTPort[port].handle = 0xFF;
1413
1414 UARTPort[port].Rec_state = UART_RecNormal;
1415 UARTPort[port].port_no = port;
1416
1417 UARTPort[port].sleep_on_tx = uart_sleep_on_tx_allow;
1418 UARTPort[port].EnableTX= KAL_TRUE;
1419 UARTPort[port].power_on= KAL_TRUE;
1420
1421 // HDMA related HW init
1422 // init FIFO Control Regitser: UART_FCR_RFTL_12 | UART_FCR_TFTL_0 | UART_FCR_CLRT | UART_FCR_CLRR | UART_FCR_FIFOE
1423 DRV_UART_WriteReg(UART_FCR(UART_BaseAddr[port]), 0x87);
1424#if defined(MTK_SLEEP_ENABLE)
1425 DRV_UART_WriteReg(UART_SLEEP_EN(UART_BASE),KAL_TRUE);
1426#endif
1427 switch(port)
1428 {
1429 case uart_port1:
1430 // init TX HDMA
1431 HDMA_MODE_CONFIG(UART1_HDMA_TX_CHANNEL, HDMA_CKSUM_EN_DEFAULT, HDMA_LIST_MODE, HDMA_CKSUM_12B);
1432 HDMA_CONFIG(UART1_HDMA_TX_CHANNEL, HDMA_BURST_SIZE_DEFAULT, HDMA_DEV_BUS_WIDTH_DEFAULT, HDMA_MEM_BUS_WIDTH_DEFAULT);
1433 HDMA_BUF0_XFER_SIZE_CONFIG(UART1_HDMA_TX_CHANNEL, 0);
1434
1435 // init RX HDMA
1436 HDMA_CONFIG_RX_SEL(UART1_HDMA_RX_CHANNEL, 0x3);
1437 HDMA_MODE_CONFIG(UART1_HDMA_RX_CHANNEL, HDMA_CKSUM_EN_DEFAULT, HDMA_LIST_MODE, HDMA_CKSUM_12B);
1438 HDMA_CONFIG(UART1_HDMA_RX_CHANNEL, HDMA_BURST_SIZE_DEFAULT, HDMA_DEV_BUS_WIDTH_DEFAULT, HDMA_MEM_BUS_WIDTH_DEFAULT);
1439 HDMA_BUF0_XFER_SIZE_CONFIG(UART1_HDMA_RX_CHANNEL, 0);
1440#ifdef DRV_DEBUG
1441 DRV_WriteReg32(UART_DMA_EN(UART_BaseAddr[port]), 0x0);
1442#else
1443 DRV_WriteReg32(UART_DMA_EN(UART_BaseAddr[port]), UART_TXRXDMA_ON|UART_TO_CNT_AUTORST);
1444 DRV_WriteReg32(UART_DMA_ACK(UART_BaseAddr[port]),UART_DMA_ACK_DIS);
1445#endif
1446 break;
1447
1448 case uart_port2:
1449 break;
1450 default:
1451 ASSERT(0);
1452 break;
1453 }
1454
1455 // If needTxDoneCb is 1, the driver must call DclSerialPort_DrvTxDone(handle, source_id, tx_ior) after tx_ior data is sent.
1456 // initial value is 0
1457 UARTPort[port].need_tx_done_cb = KAL_FALSE;
1458}
1459
1460kal_bool U_Open(UART_PORT port, module_type ownerid)
1461{
1462 kal_uint32 UART_BASE;
1463 kal_uint16 MSR;
1464 kal_uint8 byte;
1465 kal_uint8 irq_code = 0;
1466
1467 UART_BASE = UART_BaseAddr[port];
1468 if(port == uart_port_null)
1469 return KAL_FALSE;
1470
1471 UARTPort[port].initialized = KAL_TRUE;
1472 UARTPort[port].ownerid = ownerid;
1473
1474 UARTPort[port].RingBuffers.rx_buffer = UART_rings->ring[port].rx_adrs;
1475 UARTPort[port].RingBuffers.tx_buffer = UART_rings->ring[port].tx_adrs;
1476 Buf_init(&(UARTPort[port].Rx_Buffer),(kal_uint8 *)(UARTPort[port].RingBuffers.rx_buffer),(kal_uint16)UART_rings->ring[port].rx_len);
1477 Buf_init(&(UARTPort[port].Tx_Buffer),(kal_uint8 *)(UARTPort[port].RingBuffers.tx_buffer),(kal_uint16)UART_rings->ring[port].tx_len);
1478 if( UART_IsVfifoSetting(port, TX_VFIFO) == KAL_FALSE )
1479 {
1480 UARTPort[port].RingBuffers.txISR_buffer = UART_rings->ring[port].txisr_adrs;
1481 Buf_init(&(UARTPort[port].Tx_Buffer_ISR),(kal_uint8 *)(UARTPort[port].RingBuffers.txISR_buffer),(kal_uint16)UART_rings->ring[port].txisr_len);
1482 }
1483
1484 MSR = DRV_UART_Reg(UART_MSR(UART_BASE));
1485
1486 if (MSR & UART_MSR_DSR)
1487 UARTPort[port].DSR = io_high;
1488 else
1489 UARTPort[port].DSR = io_low;
1490
1491 /* Rx FIFO trigger = 62, Tx FIFO trigger is 16, and FIFO enable. */
1492 DRV_UART_WriteReg(UART_FCR(UART_BASE),UART_FCR_Normal);
1493
1494 if( UART_IsVfifoSetting(port, TXRX_VFIFO))
1495 {
1496 ASSERT(0);/*wrong configuration*/
1497 }
1498 else
1499 {
1500 if (UARTPort[port].DCB.flowControl == fc_none)
1501 {
1502 DRV_UART_WriteReg(UART_IER(UART_BaseAddr[port]),IER_HW_NORMALINTS);
1503 }
1504 else if (UARTPort[port].DCB.flowControl == fc_hw)
1505 {
1506// DRV_UART_WriteReg(UART_IER(UART_BaseAddr[port]),IER_HW_NORMALINTS);
1507 DRV_UART_WriteReg32(UART_MCR(UART_BASE), (DRV_UART_Reg32(UART_MCR(UART_BASE)) | 0x02));
1508 byte = DRV_UART_Reg(UART_LCR(UART_BASE));
1509 DRV_UART_WriteReg(UART_LCR(UART_BASE), 0xbf);
1510 DRV_UART_WriteReg(UART_EFR(UART_BASE), DRV_UART_Reg(UART_EFR(UART_BASE)) | UART_EFR_AutoRTSCTS);
1511 DRV_UART_WriteReg(UART_LCR(UART_BASE), byte);
1512 }
1513 else if (UARTPort[port].DCB.flowControl == fc_sw)
1514 {
1515 // need to set EFR enhance before IRE
1516 byte = DRV_UART_Reg(UART_LCR(UART_BASE));
1517 DRV_UART_WriteReg(UART_LCR(UART_BASE),0xbf);
1518 DRV_UART_WriteReg(UART_EFR(UART_BASE), DRV_UART_Reg(UART_EFR(UART_BASE)) | UART_EFR_Enchance);
1519 DRV_UART_WriteReg(UART_LCR(UART_BASE),byte);
1520
1521 DRV_UART_WriteReg(UART_IER(UART_BaseAddr[port]),IER_SW_NORMALINTS);
1522 DRV_UART_WriteReg(UART_ESCAPE_EN(UART_BaseAddr[port]),0x0); //reset to disable first
1523 if(uart_support_autoescape()==KAL_TRUE)
1524 {
1525 /*For META, Dont use auto escape*/
1526#if defined(META_MODE_SW_ESCAPING)
1527 if(kal_query_boot_mode() != FACTORY_BOOT || UARTPort[port].ownerid != MOD_DHL_READER)
1528#endif
1529 {
1530 /*For AutoEscape*/
1531 byte = DRV_UART_Reg(UART_LCR(UART_BASE));
1532 // DLAB start */
1533 DRV_UART_WriteReg(UART_LCR(UART_BASE),0xbf); /* Enchance setting */
1534 DRV_UART_WriteReg(UART_XON1(UART_BaseAddr[port]),0x11);
1535 DRV_UART_WriteReg(UART_XON2(UART_BaseAddr[port]),0x11);
1536 DRV_UART_WriteReg(UART_XOFF1(UART_BaseAddr[port]),0x13);
1537 DRV_UART_WriteReg(UART_XOFF2(UART_BaseAddr[port]),0x13);
1538 //autoescape
1539 DRV_UART_WriteReg(UART_ESCAPE_DAT(UART_BaseAddr[port]),0x77);
1540 DRV_UART_WriteReg(UART_ESCAPE_EN(UART_BaseAddr[port]),0x1);
1541 DRV_UART_WriteReg(UART_LCR(UART_BASE),byte); /* Enchance setting */
1542 }
1543 }
1544 }
1545 }
1546
1547 /*For excetpion, we dont need to do the following */
1548#ifdef __MTK_TARGET__
1549 if(INT_QueryExceptionStatus())
1550 return KAL_TRUE;
1551#endif
1552 switch(port)
1553 {
1554 case uart_port1:
1555 irq_code = UART_GetIRQCode(uart_port1);
1556 IRQMask(irq_code);
1557 //IRQ_Register_LISR(irq_code, UART1_LISR, "UART1");
1558 //IRQSensitivity(irq_code, LEVEL_SENSITIVE);
1559 IRQClearInt(irq_code);
1560 DRV_WriteReg32(UART_IER(UART_BASE), 0x4);
1561 IRQUnmask(irq_code);
1562 break;
1563
1564 case uart_port2:
1565 irq_code = UART_GetIRQCode(uart_port2);
1566 IRQMask(irq_code);
1567 //IRQ_Register_LISR(irq_code, UART2_LISR, "UART2");
1568 //IRQSensitivity(irq_code, LEVEL_SENSITIVE);
1569 IRQClearInt(irq_code);
1570 DRV_WriteReg32(UART_IER(UART_BASE), 0x4);
1571 IRQUnmask(irq_code);
1572 break;
1573 default:
1574 ASSERT(0);
1575 break;
1576 }
1577
1578 IRQMask(UART_HDMA_INTR_ID);
1579 //IRQ_Register_LISR(UART_HDMA_INTR_ID, uart_hdma_lisr, "UART_HDMA");
1580 //IRQSensitivity(UART_HDMA_INTR_ID, LEVEL_SENSITIVE);
1581
1582 HDMA_LENERR_INTR_UNMASK(2);
1583 HDMA_BD_CSERR_INTR_UNMASK(2);
1584 HDMA_GPD_CSERR_INTR_UNMASK(2);
1585 HDMA_LENERR_INTR_UNMASK(3);
1586 HDMA_BD_CSERR_INTR_UNMASK(3);
1587 HDMA_GPD_CSERR_INTR_UNMASK(3);
1588 HDMA_QE_INTR_UNMASK(3); // RX done
1589 HDMA_INT_CLEAR_ALL();
1590 IRQUnmask(UART_HDMA_INTR_ID);
1591
1592 return KAL_TRUE;
1593}
1594
1595void U_Purge(UART_PORT port, UART_buffer dir, module_type ownerid)
1596{
1597 kal_uint32 UART_BASE = UART_BaseAddr[port];
1598
1599 /* Rx FIFO trigger = 62, Tx FIFO trigger is 16, and FIFO enable. */
1600 // for MT6290, Rx FIFO trigger = 12. Tx FIFO trigger is 0
1601 if (dir == RX_BUF)
1602 DRV_UART_WriteReg(UART_FCR(UART_BASE),(UART_FCR_Normal & ~UART_FCR_CLRT));
1603 else
1604 DRV_UART_WriteReg(UART_FCR(UART_BASE),(UART_FCR_Normal & ~UART_FCR_CLRR));
1605}
1606
1607void U_Close(UART_PORT port, module_type ownerid)
1608{
1609 kal_uint32 UART_BASE = UART_BaseAddr[port];
1610 kal_uint8 irq_code;
1611
1612 UARTPort[port].initialized = KAL_FALSE;
1613 UARTPort[port].ownerid = (module_type) ((kal_uint16) MOD_UART1_HISR + (kal_uint8) port);
1614
1615 switch(port)
1616 {
1617 case uart_port1:
1618 irq_code = UART_GetIRQCode(uart_port1);
1619 IRQMask(irq_code);
1620 break;
1621 case uart_port2:
1622 irq_code = UART_GetIRQCode(uart_port2);
1623 IRQMask(irq_code);
1624 break;
1625 default:
1626 ASSERT(0);
1627 break;
1628 }
1629
1630 DRV_UART_WriteReg(UART_IER(UART_BASE), UART_IER_ALLOFF);
1631
1632 U_ConfigEscape(port, 0xff, 0, UARTPort[port].ownerid);
1633
1634 U_ClrRxBuffer(port, UARTPort[port].ownerid); // clear sw RX buffer
1635 U_ClrTxBuffer(port, UARTPort[port].ownerid); // clear sw TX buffer
1636 U_Purge(port, RX_BUF, UARTPort[port].ownerid); // clear hw RX FIFO
1637 U_Purge(port, TX_BUF, UARTPort[port].ownerid); // clear hw TX FIFO
1638
1639 DRV_UART_WriteReg(UART_IER(UART_BASE),UART_IER_ALLOFF);
1640
1641 UART_PDN_Enable(port);
1642
1643
1644 if(UARTPort[port].handle != 0xFF)
1645 {
1646 UARTPort[port].handle = 0xFF;
1647 }
1648}
1649
1650void U_SetOwner (UART_PORT port, module_type ownerid)
1651{
1652 U_ClrTxBuffer(port, UARTPort[port].ownerid); // clear sw TX buffer
1653 U_ClrRxBuffer(port, UARTPort[port].ownerid); // clear sw RX buffer
1654
1655 UARTPort[port].ownerid = ownerid;
1656 UARTPort[port].need_tx_done_cb = KAL_FALSE;
1657}
1658
1659module_type U_GetOwnerID(UART_PORT port)
1660{
1661 return UARTPort[port].ownerid;
1662}
1663
1664void U_ConfigEscape (UART_PORT port, kal_uint8 EscChar, kal_uint16 ESCGuardtime, module_type ownerid)
1665{
1666
1667 UARTPort[port].ESCDet.EscChar = EscChar;
1668 UARTPort[port].ESCDet.GuardTime = ESCGuardtime;
1669 // Escape character register is WO
1670 DRV_UART_WriteReg(UART_ESCAPE_DAT(UART_BaseAddr[port]), EscChar); // added by ansel
1671 DRV_UART_WriteReg(UART_GUARD(UART_BaseAddr[port]), ESCGuardtime); // added by ansel
1672 if (UARTPort[port].ESCDet.GuardTime)
1673 {
1674 UARTPort[port].Rec_state = UART_RecNormal;
1675 }
1676}
1677
1678void U_SetFlowCtrl(UART_PORT port, kal_bool XON, module_type ownerid) {} /*NULL for all*/
1679
1680kal_uint32 U_GetFlowCtrl(UART_PORT port, module_type ownerid)
1681{
1682 kal_uint16 IER, LCR;
1683 kal_uint32 savedMask;
1684 kal_uint32 UART_BASE;
1685 kal_uint32 EFR;
1686
1687 UART_BASE = UART_BaseAddr[port];
1688
1689 savedMask = SaveAndSetIRQMask();
1690 IER = DRV_UART_Reg(UART_IER(UART_BASE));
1691 DRV_UART_WriteReg(UART_IER(UART_BASE), UART_IER_ALLOFF);
1692 RestoreIRQMask(savedMask);
1693
1694 LCR = DRV_UART_Reg(UART_LCR(UART_BASE));
1695 DRV_UART_WriteReg(UART_LCR(UART_BASE), 0xBF);
1696 EFR = DRV_UART_Reg(UART_EFR(UART_BASE));
1697 DRV_UART_WriteReg(UART_LCR(UART_BASE), LCR);
1698
1699 savedMask = SaveAndSetIRQMask();
1700 DRV_UART_WriteReg(UART_IER(UART_BASE), IER);
1701 RestoreIRQMask(savedMask);
1702
1703 return EFR;
1704}
1705
1706void U_CtrlDCD(UART_PORT port, IO_level SDCD, module_type ownerid) {} /*NULL for DCE*/
1707void U_CtrlRI (UART_PORT port, IO_level SRI, module_type ownerid) {} /*NULL for DCE*/
1708void U_CtrlDTR (UART_PORT port, IO_level SDTR, module_type ownerid) {}
1709void U_ReadHWStatus(UART_PORT port, IO_level *SDSR, IO_level *SCTS)
1710{
1711 kal_uint16 MSR;
1712 kal_uint32 UART_BASE;
1713
1714 UART_BASE = UART_BaseAddr[port];
1715 MSR = DRV_UART_Reg(UART_MSR(UART_BASE));
1716 *SDSR = (IO_level)(( MSR & UART_MSR_DSR) >> 5);
1717 *SCTS = (IO_level)(( MSR & UART_MSR_CTS) >> 4);
1718}
1719
1720void U_CtrlBreak(UART_PORT port, IO_level SBREAK, module_type ownerid)
1721{
1722 kal_uint32 UART_BASE = UART_BaseAddr[port];
1723 if(SBREAK == io_high)
1724 {
1725 if(HDMA_BUF0_IS_ACTIVE((port + 2)))
1726 HDMA_BUF0_STOP((port + 2));
1727 DRV_UART_SetBits(UART_LCR(UART_BASE), UART_LCR_BREAK);
1728 } else
1729 {
1730 DRV_UART_ClearBits(UART_LCR(UART_BASE), UART_LCR_BREAK);
1731 if(uart_wait_tgpd_head[port] != NULL || uart_tgpd_head[port] != NULL)
1732 HDMA_BUF0_RESUME((port + 2));
1733 }
1734}
1735
1736kal_uint16 U_GetBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid)
1737{
1738 kal_uint16 real_count, index;
1739 kal_uint16 data_count = 0;
1740
1741 if(status != NULL)
1742 *status = 0;
1743
1744 DisableRxIntr(UART_BaseAddr[port]);
1745 if (status != NULL)
1746 {
1747 if (UARTPort[port].EscFound)
1748 {
1749 *status |= UART_STAT_EscDet;
1750 UARTPort[port].EscFound = KAL_FALSE;
1751 }
1752 if(UARTPort[port].breakDet)
1753 {
1754 *status |= UART_STAT_Break;
1755 UARTPort[port].breakDet = KAL_FALSE;
1756 }
1757 }
1758
1759 EnableRxIntr(UART_BaseAddr[port]);
1760
1761 do {
1762 Buf_GetBytesAvail(&(UARTPort[port].Rx_Buffer),real_count);
1763
1764 if((kal_query_boot_mode() == FACTORY_BOOT && UARTPort[port].DCB.flowControl == fc_sw && UARTPort[port].ownerid == MOD_DHL_READER)
1765 || (uart_support_autoescape() == KAL_FALSE && UARTPort[port].DCB.flowControl == fc_sw))
1766 {
1767
1768 for(index = 0; (index < real_count) && (data_count < Length); index++)
1769 {
1770 Buf_Pop(&(UARTPort[port].Rx_Buffer), *(Buffaddr + data_count));
1771
1772 // The following are for software flow control
1773 if(uart_escape_state==0)
1774 {
1775 if(*(Buffaddr + data_count) == 0x77)
1776 {
1777 uart_escape_state=0x77;
1778 } else
1779 {
1780 data_count++;
1781 }
1782
1783 } else if(uart_escape_state == 0x77)
1784 {
1785 switch(*(Buffaddr + data_count))
1786 {
1787 case 0x01:
1788 *(Buffaddr+data_count) = UARTPort[port].DCB.xonChar;
1789 data_count++;
1790 break;
1791 case 0x02:
1792 *(Buffaddr+data_count)=UARTPort[port].DCB.xoffChar;
1793 data_count++;
1794 break;
1795 case 0x03:
1796 *(Buffaddr + data_count) = 0x77;
1797 data_count++;
1798 break;
1799 default:
1800 break;
1801
1802 }
1803 uart_escape_state=0x0;
1804
1805 }
1806 }
1807
1808 } else // HW flow control
1809 {
1810 for(index = 0; (index < real_count) && (data_count < Length); index++)
1811 {
1812 Buf_Pop(&(UARTPort[port].Rx_Buffer),*(Buffaddr + data_count));
1813 data_count++;
1814 }
1815 }
1816
1817 // satisfy uart owner request, so break
1818 if (data_count == Length) break;
1819
1820 // disable interrupt
1821 DisableRxIntr(UART_BaseAddr[port]);
1822
1823 Buf_GetBytesAvail(&(UARTPort[port].Rx_Buffer),real_count);
1824 // there is no data in ringbuffer, so break
1825 if(real_count == 0)
1826 {
1827 send_Rxilm[port] = KAL_TRUE;
1828 // enable interrupt
1829 EnableRxIntr(UART_BaseAddr[port]);
1830 break;
1831 }
1832
1833 /* enable interrupt*/
1834 EnableRxIntr(UART_BaseAddr[port]);
1835 } while(KAL_TRUE);
1836
1837 return data_count;
1838}
1839
1840#ifdef DRV_DEBUG
1841
1842void UART_DMA_PutBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length)
1843{
1844 if(port>=uart_port3){
1845 return;
1846 }
1847 clean_and_invalidate_dcache(CPU_CACHE_LINE_ALIGN_ADDR((kal_uint32)Buffaddr), CPU_CACHE_LINE_ALIGN_LEN((kal_uint32)Buffaddr, (kal_uint32)Length));
1848
1849 HDMA_BUF0_PROG_ADDR_CONFIG(port+2, (kal_uint32)Buffaddr);
1850 HDMA_BUF0_XFER_SIZE_CONFIG(port+2, (kal_uint32)Length);
1851
1852 Data_Sync_Barrier();
1853
1854 HDMA_BUF0_START(port+2);
1855}
1856
1857kal_uint16 BMT_PutBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length)
1858{
1859 kal_uint16 real_count, index;
1860 #if defined(DRV_DEBUG_BUFFER_DMA_MODE)
1861 kal_uint16 is_empty;
1862 #endif
1863 if(port >= MAX_UART_PORT_NUM)
1864 return 0;
1865
1866 Buf_GetRoomLeft(&(UARTPort[port].Tx_Buffer), real_count);
1867 if(real_count > Length)
1868 {
1869 real_count = Length;
1870 }
1871
1872 /*
1873 * The spin lock is used for the con-currency case of HDMA HISR
1874 * and dbg_print. The write/read pointer of buffer is the basis
1875 * whether to start the next DMA or NOT, so use the spin lock
1876 * to protect the pointer updatding actions
1877 */
1878 #if defined(DRV_DEBUG_BUFFER_DMA_MODE)
1879 #ifndef KTEST_UART_TRACES
1880 kal_take_spinlock(print_buf_lock, KAL_INFINITE_WAIT);
1881 #else
1882 kal_hrt_take_itc_lock(KAL_ITC_PRINT, KAL_INFINITE_WAIT);
1883 #endif
1884
1885 /* To check if DMA should be start in this API */
1886 Buf_IsEmpty(&(UARTPort[port].Tx_Buffer), is_empty);
1887 #endif
1888
1889 for(index = 0; index < real_count; index++)
1890 {
1891 Buf_Push(&(UARTPort[port].Tx_Buffer), *(Buffaddr + index));
1892 }
1893
1894 #if defined(DRV_DEBUG_BUFFER_DMA_MODE)
1895 #ifndef KTEST_UART_TRACES
1896 kal_give_spinlock(print_buf_lock);
1897 #else
1898 kal_hrt_give_itc_lock(KAL_ITC_PRINT);
1899 #endif
1900 #endif
1901
1902 switch(port)
1903 {
1904 case uart_port1:
1905 #if defined(DRV_DEBUG_BUFFER_DMA_MODE)
1906 if (is_empty == Buff_isEmpty)
1907 UART_TxDMAHandler(&UARTPort[uart_port1], 0);
1908 #else
1909 EnableTxIntr(UART_BaseAddr[port]);
1910 #endif
1911 break;
1912 case uart_port2:
1913 EnableTxIntr(UART_BaseAddr[port]);
1914 break;
1915 default:
1916 ASSERT(0);
1917 break;
1918 }
1919
1920
1921 return real_count;
1922}
1923#endif /*DRV_DEBUG*/
1924
1925/*************************************************************************
1926 * FUNCTION
1927 * UART_GetTxWorkingMode
1928 *
1929 * DESCRIPTION
1930 *
1931 * This function is to get the uart TX working mode.
1932 *
1933 * PARAMETERS
1934 * port - the uart port
1935 *
1936 * RETURNS
1937 * UART_ON_VFIFO: the uart port Tx working on VFIFO mode
1938 * UART_ON_DMA: the uart port Tx working on normal DMA mode
1939 * UART_ON_MCU: the uart port Tx working on sw mode
1940 *
1941 * Global AFFECTED
1942 *
1943 *************************************************************************/
1944UART_WORKING_MODE UART_GetTxWorkingMode(UART_PORT port)
1945{
1946 if(UART_IsVfifoSetting(port, TX_VFIFO))
1947 return UART_ON_VFIFO;
1948
1949 return UART_ON_MCU;
1950}
1951
1952kal_uint16 U_PutBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid )
1953{
1954 kal_uint16 real_count, index;
1955 if(port >= MAX_UART_PORT_NUM)
1956 return 0;
1957
1958 Buf_GetRoomLeft(&(UARTPort[port].Tx_Buffer), real_count);
1959 if(real_count > Length)
1960 {
1961 real_count = Length;
1962 }
1963
1964 for(index = 0; index < real_count; index++)
1965 {
1966 Buf_Push(&(UARTPort[port].Tx_Buffer), *(Buffaddr + index));
1967 }
1968
1969 switch(port)
1970 {
1971 case uart_port1:
1972 EnableTxIntr(UART_BaseAddr[port]);
1973 break;
1974 case uart_port2:
1975 EnableTxIntr(UART_BaseAddr[port]);
1976 break;
1977 default:
1978 ASSERT(0);
1979 break;
1980 }
1981 return real_count;
1982}
1983
1984#ifndef __ROMSA_SUPPORT__ /* Note: for ROM code */
1985
1986#if defined(__MTK_INTERNAL__) && defined(__MTK_TARGET__)
1987kal_uint16 DEVDRV_LS_INTERNCODE
1988#else
1989kal_uint16
1990#endif
1991U_PutISRBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid)
1992{
1993 return 0;
1994}
1995#endif /* Note: for ROM code */
1996
1997#if defined(__MTK_INTERNAL__) && defined(__MTK_TARGET__)
1998kal_uint16 DEVDRV_LS_INTERNCODE
1999#else
2000kal_uint16
2001#endif
2002U_SendISRData(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode, kal_uint8 escape_char, module_type ownerid)
2003{
2004 return 0;
2005}
2006
2007kal_uint16 U_SendData(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid)
2008{
2009 return 0;
2010}
2011
2012//============================== ISR level ====================
2013/*============================ UART1 ========================*/
2014void UART_RLSHandler(void *parameter)
2015{
2016 kal_uint16 LSR;
2017 UARTStruct *UARTData = (UARTStruct *) parameter;
2018 kal_uint32 UART_BASE;
2019
2020 if(UARTData->port_no >= MAX_UART_PORT_NUM)
2021 return;
2022
2023 UART_BASE = UART_BaseAddr[UARTData->port_no];
2024 LSR = DRV_UART_Reg(UART_LSR(UART_BASE));
2025/*
2026 if(LSR & UART_LSR_OE) dbg_print("Overrun Error\n\r");
2027 if(LSR & UART_LSR_PE) dbg_print("Parity Error\n\r");
2028 if(LSR & UART_LSR_FE) dbg_print("Framing Error\n\r");
2029*/
2030 if(LSR & UART_LSR_BI)
2031 {
2032 UARTData->breakDet = KAL_TRUE;
2033 U_Purge(UARTData->port_no, RX_BUF, UARTPort[UARTData->port_no].ownerid);
2034 }
2035
2036 if((LSR & UART_LSR_OE) || (LSR & UART_LSR_FIFOERR))
2037 {
2038 //for check BT overwrite UART FIFO, because BT do not use flow control, lost data will cause BT fail
2039// if((UARTPort[UARTData->port_no].ownerid == MOD_BT))
2040// {
2041// UART_DBG(__LINE__, UART_GetTimeStamp(), ust_get_current_time(), LSR);
2042// ASSERT(!(LSR & UART_LSR_OE)); // BT send too fast, VFIFO can not get bus, overwrite UART FIFO
2043// }
2044 DisableRLSIntr(UART_BASE);
2045 }
2046}
2047
2048void UART_Calback(void *parameter) {}
2049
2050void UART_SetRateFix(UART_PORT port) {}
2051
2052int uart_pio_get_data_like_dma(UART_PORT port, kal_uint8 *ptr_dat, kal_uint32 allow_len)
2053{
2054 int real_len = 0;
2055 kal_uint32 base = UART_BaseAddr[port];
2056 if ((DRV_Reg8(UART_LSR(base))&UART_LSR_DR) == 0) {
2057 /* RX no data */
2058 return 0;
2059 }
2060 for(;;) {
2061 while ((real_len < allow_len) && (DRV_Reg8(UART_LSR(base))&UART_LSR_DR)) {
2062 *ptr_dat++ = DRV_Reg8(UART_RBR(base));
2063 real_len ++;
2064 }
2065
2066 if (real_len == allow_len) {
2067 /* Got Enough data */
2068 break;
2069 }
2070
2071 /* 32k timer, 30us */
2072 kal_uint32 delayTime1;
2073 delayTime1 = drv_get_current_time()+3; /* delay 60~90us*/
2074 while(delayTime1 != drv_get_current_time()) {
2075 if ((DRV_Reg8(UART_LSR(base))&UART_LSR_DR))
2076 break;
2077
2078 }
2079
2080 if ((DRV_Reg8(UART_LSR(base))&UART_LSR_DR) == 0) {
2081 /* RX Timeout */
2082 break;
2083 }
2084 }
2085
2086 return real_len;
2087}
2088void UART_RecHandler(void *parameter) {
2089 UARTStruct *UARTData=(UARTStruct *)parameter;
2090 kal_uint32 UART_BASE;
2091 kal_uint16 RoomLeft;
2092 kal_uint16 LSR;
2093 kal_uint8 cRXChar;
2094 if(UARTData->port_no >= MAX_UART_PORT_NUM)
2095 return;
2096
2097 UART_BASE = UART_BaseAddr[UARTData->port_no];
2098 Buf_GetRoomLeft(&(UARTData->Rx_Buffer),RoomLeft);
2099
2100 while (RoomLeft)
2101 {
2102 LSR = DRV_UART_Reg(UART_LSR(UART_BASE));
2103 if (LSR & UART_LSR_BI)
2104 {
2105 UARTData->breakDet = KAL_TRUE;
2106 U_Purge(UARTData->port_no,RX_BUF,UARTPort[UARTData->port_no].ownerid);
2107 LSR = DRV_UART_Reg(UART_LSR(UART_BASE));
2108 }
2109
2110 if (LSR & UART_LSR_DR)
2111 {
2112
2113 cRXChar = (kal_uint8)DRV_UART_Reg(UART_RBR(UART_BASE));
2114
2115 Buf_Push(&(UARTData->Rx_Buffer),cRXChar);
2116 RoomLeft--;
2117 }
2118 else
2119 {
2120 break;
2121 }
2122 }
2123 if (!RoomLeft) /*buffer is full*/
2124 DisableRxIntr(UART_BASE);
2125
2126
2127}
2128
2129#if defined(DRV_DEBUG_BUFFER_DMA_MODE)
2130/* This function might be called by HISR and dbg_print */
2131void UART_TxDMAHandler(void *parameter, kal_uint8 chk_done)
2132{
2133 UARTStruct *UARTData = (UARTStruct *) parameter;
2134 kal_uint16 real_count_TASK, done_count;
2135 BUFFER_INFO *TxBuf = (BUFFER_INFO *)(&(UARTData->Tx_Buffer));
2136
2137 if(UARTData->port_no >= MAX_UART_PORT_NUM)
2138 return;
2139
2140 /*
2141 * The spin lock is used for the con-currency case of HDMA HISR
2142 * and dbg_print. The write/read pointer of buffer is the basis
2143 * whether to start the next DMA or NOT, so use the spin lock
2144 * to protect the pointer updatding actions
2145 */
2146 #ifndef KTEST_UART_TRACES
2147 kal_take_spinlock(print_buf_lock, KAL_INFINITE_WAIT);
2148 #else
2149 kal_hrt_take_itc_lock(KAL_ITC_PRINT, KAL_INFINITE_WAIT);
2150 #endif
2151
2152 if (chk_done) {
2153 done_count = DRV_Reg32(GDMA_HCCR(UARTData->port_no+2)) & 0xFFFF;
2154
2155 if (done_count) {
2156 BRead(TxBuf) += done_count;
2157 if (BRead(TxBuf) >= BLength(TxBuf))
2158 BRead(TxBuf) -= BLength(TxBuf);
2159 }
2160 }
2161
2162 Buf_GetBytesAvail_DMA(&(UARTData->Tx_Buffer), real_count_TASK);
2163
2164 #ifndef KTEST_UART_TRACES
2165 kal_give_spinlock(print_buf_lock);
2166 #else
2167 kal_hrt_give_itc_lock(KAL_ITC_PRINT);
2168 #endif
2169
2170 if (real_count_TASK) {
2171 clean_and_invalidate_dcache(CPU_CACHE_LINE_ALIGN_ADDR((kal_uint32)BuffRead(TxBuf)),
2172 CPU_CACHE_LINE_ALIGN_LEN((kal_uint32)BuffRead(TxBuf), (kal_uint32)real_count_TASK));
2173
2174 HDMA_BUF0_PROG_ADDR_CONFIG(UARTData->port_no+2, (kal_uint32)BuffRead(TxBuf));
2175 HDMA_BUF0_XFER_SIZE_CONFIG(UARTData->port_no+2, (kal_uint32)real_count_TASK);
2176 HDMA_BUF0_START(UARTData->port_no+2);
2177
2178 return;
2179 }
2180}
2181#endif
2182
2183void UART_TrxHandler(void *parameter)
2184{
2185 UARTStruct *UARTData = (UARTStruct *) parameter;
2186 kal_uint32 UART_BASE;
2187 kal_uint16 byteCount, index;
2188 kal_uint16 real_count_TASK, real_count = 0;
2189 kal_uint16 offset;
2190 kal_uint8 TX_DATA;
2191
2192 if(UARTData->port_no >= MAX_UART_PORT_NUM)
2193 return;
2194
2195 UART_BASE = UART_BaseAddr[UARTData->port_no];
2196
2197 byteCount = UART1_TxFIFO_DEPTH;
2198
2199 if(real_count != byteCount)
2200 {
2201 Buf_GetBytesAvail(&(UARTData->Tx_Buffer), real_count_TASK);
2202 offset = byteCount - real_count;
2203 real_count = real_count_TASK;
2204 if(real_count_TASK > offset)
2205 {
2206 real_count = offset;
2207 }
2208
2209 for(index = 0; index < real_count; index++)
2210 {
2211 Buf_Pop(&(UARTData->Tx_Buffer),TX_DATA);
2212 DRV_UART_WriteReg(UART_THR(UART_BASE), (kal_uint16) TX_DATA);
2213 }
2214 }
2215
2216 Buf_GetBytesAvail(&(UARTData->Tx_Buffer), real_count_TASK);
2217 if(real_count_TASK == 0)
2218 DisableTxIntr(UART_BASE);
2219}
2220
2221void UART_MsHandler(void *parameter) {}
2222
2223//Bei add for get irq code
2224kal_uint8 UART_GetIRQCode(UART_PORT port)
2225{
2226 kal_uint8 IRQ_code = 0;
2227 switch(port)
2228 {
2229 case uart_port1:
2230 IRQ_code = IRQ_UART_MD0_CODE;
2231 break;
2232 case uart_port2:
2233 IRQ_code = IRQ_UART_MD1_CODE;
2234 break;
2235 default:
2236 break;
2237 }
2238 return IRQ_code;
2239}
2240
2241void UART1_LISR(kal_uint32 vector)
2242{
2243 IRQMask(IRQ_UART_MD0_CODE);
2244 kal_activate_hisr_index(UART_1_HISR);
2245}
2246
2247void UART1_HISR(void)
2248{
2249 kal_uint16 IIR;
2250
2251 IIR = DRV_UART_Reg(UART_IIR(UART_BaseAddr[uart_port1]));
2252 if (IIR & UART_IIR_INT_INVALID)
2253 {
2254 IRQClearInt(IRQ_UART_MD0_CODE);
2255 IRQUnmask(IRQ_UART_MD0_CODE);
2256
2257 return;
2258 }
2259
2260 switch(IIR & UART_IIR_INT_MASK)
2261 {
2262
2263 case UART_IIR_RLS:
2264 UART_RLSHandler(&UARTPort[uart_port1]);
2265 break;
2266 case UART_IIR_CTI:
2267 case UART_IIR_RDA:
2268#ifdef __SLT_TOOL_SUPPORT__
2269 UART_RecHandler(&UARTPort[uart_port1]) ;
2270#endif
2271 break;
2272 case UART_IIR_THRE:
2273 UART_TrxHandler(&UARTPort[uart_port1]);
2274 break;
2275 case UART_IIR_MS :
2276 case UART_IIR_SWFlowCtrl:
2277 case UART_IIR_HWFlowCtrl:
2278 default:
2279 break;
2280 }
2281 IRQClearInt(IRQ_UART_MD0_CODE);
2282 IRQUnmask(IRQ_UART_MD0_CODE);
2283}
2284
2285/*============================ UART2 ========================*/
2286void UART2_LISR(kal_uint32 vector)
2287{
2288 IRQMask(IRQ_UART_MD1_CODE);
2289 kal_activate_hisr_index(UART_2_HISR);
2290}
2291
2292void UART2_HISR(void)
2293{
2294 kal_uint16 IIR;
2295
2296 IIR = DRV_UART_Reg(UART_IIR(UART_BaseAddr[uart_port2]));
2297 if (IIR & UART_IIR_INT_INVALID)
2298 {
2299 IRQClearInt(IRQ_UART_MD1_CODE);
2300 IRQUnmask(IRQ_UART_MD1_CODE);
2301
2302 return;
2303 }
2304
2305 switch(IIR & UART_IIR_INT_MASK)
2306 {
2307
2308 case UART_IIR_RLS:
2309 UART_RLSHandler(&UARTPort[uart_port2]);
2310 break;
2311 case UART_IIR_CTI:
2312 case UART_IIR_RDA:
2313 break;
2314 case UART_IIR_THRE:
2315 UART_TrxHandler(&UARTPort[uart_port2]);
2316 break;
2317 case UART_IIR_MS :
2318 case UART_IIR_SWFlowCtrl:
2319 case UART_IIR_HWFlowCtrl:
2320 default:
2321 break;
2322 }
2323 IRQClearInt(IRQ_UART_MD1_CODE);
2324 IRQUnmask(IRQ_UART_MD1_CODE);
2325}
2326
2327
2328typedef struct _ut_hdma_intr_s{
2329 kal_uint32 hdma_done_int;
2330 kal_uint32 hdma_qe_int;
2331 kal_uint32 hdma_len_err_int;
2332 kal_uint32 hdma_bd_cserr_int;
2333 kal_uint32 hdma_gpd_cserr_int;
2334}ut_hdma_intr_t;
2335
2336volatile static ut_hdma_intr_t ut_hdma_intr_record[2];
2337
2338
2339void uart_hdma_lisr(kal_uint32 vector)
2340{
2341 IRQMask(UART_HDMA_INTR_ID);
2342 kal_activate_hisr_index(GDMA2_HISR);
2343}
2344
2345void uart_hdma_hisr(void)
2346{
2347 //kal_uint32 mask;
2348 kal_uint32 val, chl;
2349 kal_uint32 i;
2350
2351 //mask = SaveAndSetIRQMask();
2352
2353 val = DRV_Reg32(GDMA_GISAR_UART);
2354
2355 //Set the interrupt record table
2356 for(i = 0; i < sizeof(ut_hdma_intr_record) / sizeof(ut_hdma_intr_t); i++ ){
2357 chl = i + 2;
2358
2359 if(IS_HDMA_DONE_INTR(val, chl)){
2360 ut_hdma_intr_record[i].hdma_done_int++;
2361
2362 #if defined(DRV_DEBUG_BUFFER_DMA_MODE)
2363 if (chl == UART1_HDMA_TX_CHANNEL) {
2364 UART_TxDMAHandler(&UARTPort[uart_port1], 1);
2365 }
2366 #endif
2367 }
2368
2369 if(IS_HDMA_QE_INTR(val, chl)){
2370 ut_hdma_intr_record[i].hdma_qe_int++;
2371
2372 #if defined(__HMU_ENABLE__)
2373 if (chl == UART1_HDMA_RX_CHANNEL) {
2374 // trigger UARTCORE task to polling RX
2375 hmu_hifeg_set(HIF_DRV_EG_HIF_TICK_EVENT_UART);
2376 }
2377 #endif
2378 }
2379
2380 if(IS_HDMA_GPD_CSERR_INTR(val, chl)){
2381 ut_hdma_intr_record[i].hdma_gpd_cserr_int++;
2382 ASSERT(0);
2383 }
2384
2385 if(IS_HDMA_BD_CSERR_INTR(val, chl)){
2386 ut_hdma_intr_record[i].hdma_bd_cserr_int++;
2387 ASSERT(0);
2388 }
2389
2390 if(IS_HDMA_LENERR_INTR(val, chl)){
2391 ut_hdma_intr_record[i].hdma_len_err_int++;
2392 ASSERT(0);
2393 }
2394 }
2395
2396 //Clear the interrupt status
2397 HDMA_INT_CLEAR_ALL();
2398
2399 //RestoreIRQMask(mask);
2400 IRQUnmask(UART_HDMA_INTR_ID);
2401}
2402
2403#ifdef __USB_COM_PORT_ENABLE__
2404extern UARTStruct USB2UARTPort[MAX_USB_PORT_NUM];
2405#endif /*__USB_COM_PORT_ENABLE__*/
2406
2407void UART_SetSleepEnable(UART_PORT port, kal_bool enable)
2408{
2409 DRV_UART_WriteReg(UART_SLEEP_EN(UART_BaseAddr[port]), enable);
2410}
2411
2412//This API only for test purpose, can only be called by MEUT DVT test.
2413//*********** do not call this API directly ************
2414//*********** do not call this API directly ************
2415//*********** do not call this API directly ************
2416void UART_set_FIFO_trigger(UART_PORT port, kal_uint16 tx_level, kal_uint16 rx_level)
2417{
2418 if(port >= MAX_UART_PORT_NUM)
2419 return;
2420 DRV_UART_WriteReg(UART_FCR(UART_BaseAddr[port]), ((tx_level<<4) | (rx_level<<6) | 0x7));
2421}
2422
2423void U_Register_TX_cb(UART_PORT port, module_type ownerid, UART_TX_FUNC func) {}
2424void U_Register_RX_cb(UART_PORT port, module_type ownerid, UART_RX_FUNC func) {}
2425void UART_TurnOnPower(UART_PORT port, kal_bool enable) {}
2426
2427/* This is to check that all the data in UART TX ring buffer is empty. */
2428kal_bool UART_CheckTxBufferEmpty(UART_PORT port)
2429{
2430 kal_uint8 result;
2431 void *p_cur_gpd;
2432 if(port >= MAX_UART_PORT_NUM)
2433 return KAL_FALSE;
2434
2435// HDMA
2436 if(uart_wait_tgpd_head[port] != NULL || uart_wait_tgpd_tail[port] != NULL) return KAL_FALSE;
2437 p_cur_gpd = uart_tgpd_head[port];
2438 while(1)
2439 {
2440 if(p_cur_gpd == NULL) break;
2441 if(p_cur_gpd == uart_tgpd_tail[port]) break;
2442 if(QBM_DES_GET_HWO(p_cur_gpd + 0x40000000)) return KAL_FALSE;
2443 p_cur_gpd = QBM_DES_GET_NEXT(p_cur_gpd);
2444 }
2445
2446 Buf_IsEmpty(&(UARTPort[port].Tx_Buffer), result);
2447 return ((Buff_isEmpty == result) ? KAL_TRUE : KAL_FALSE);
2448}
2449
2450/* This is to check that all TX data have been sent out
2451including UART TX ring buffer and UART FIFO. */
2452kal_bool UART_CheckTxAllSentOut(UART_PORT port)
2453{
2454 if(port >= MAX_UART_PORT_NUM)
2455 return KAL_FALSE;
2456
2457 if (UART_CheckTxBufferEmpty(port) == KAL_FALSE)
2458 return KAL_FALSE;
2459 if (UART_LSR_TEMT & DRV_UART_Reg(UART_LSR(UART_BaseAddr[port])))
2460 return KAL_TRUE;
2461 else
2462 return KAL_FALSE;
2463}
2464
2465
2466// this function has a problem
2467void UART_GetTxBufferSize(UART_PORT port, kal_uint32 *total_size, kal_uint32 *rest_size)
2468{
2469 if(port >= MAX_UART_PORT_NUM)
2470 return;
2471 *total_size = UARTPort[port].Tx_Buffer.Length;
2472 if(uart_tgpd_head[port] != NULL || uart_wait_tgpd_head[port] != NULL)
2473 {
2474 *rest_size = uart_cal_tgpd_buf_length((void *) GDMA_HDCPRN((port + 2)), (void *) uart_tgpd_tail[port]);
2475 *rest_size += uart_cal_tgpd_buf_length((void *) uart_wait_tgpd_head[port], (void *) uart_wait_tgpd_tail[port]);
2476
2477 } else
2478 Buf_GetBytesAvail(&(UARTPort[port].Tx_Buffer), *rest_size);
2479}
2480
2481
2482/*
2483* FUNCTION
2484* UART_VFIFO_TX_DMA_Enable
2485*
2486* DESCRIPTION
2487* for
2488*
2489* CALLS
2490* This function is called to enable or disable VFIFO DMA TX
2491* it is for logacc only , logacc will take UART TX , it might cause UART & VFIFO DMA sync problem
2492* so we must disable VFIFO DMA when logacc on
2493* enable and reset VFIFO DMA when logacc off
2494*
2495* PARAMETERS
2496* port: uart port
2497* enable: disable or enable VFIFO DMA TX
2498* RETURNS
2499* None
2500*
2501* GLOBALS AFFECTED
2502* external_global
2503*/
2504void UART_VFIFO_TX_DMA_Enable(UART_PORT port,kal_bool enable) {}
2505
2506
2507
2508
2509// Used under ASSERT condition
2510// This has effect only when the port does NOT support VFIFO and used as Catcher port
2511// After ASSERT, DHL will wait UART to send out all the data before ASSERT.
2512// But now, all the interrupts are disabled, DHL may wait forever when the UART port is configured with DMA
2513// To solve this problem, we provide this function for DHL to call
2514// in order to send out all the data in ring buffer before ASSERT
2515// DHL will open UART port again after previous data is sent out
2516void UART_AssertWaitPrevDataSentOut(UART_PORT port){
2517 kal_uint16 LSR;
2518 kal_uint16 TX_DATA;
2519
2520 if(port >= MAX_UART_PORT_NUM)
2521 return;
2522
2523 // Manually send out data by MCU polling
2524 while(!UART_CheckTxBufferEmpty(port))
2525 {
2526 LSR = DRV_UART_Reg(UART_LSR(UART_BaseAddr[port]));
2527 if(LSR & UART_LSR_THRE)
2528 {
2529 Buf_Pop(&(UARTPort[port].Tx_Buffer), TX_DATA);
2530 DRV_UART_WriteReg(UART_THR(UART_BaseAddr[port]), (kal_uint16) TX_DATA);
2531 }
2532 }
2533
2534 // Wait UART controller to sent out the data in FIFO
2535 while(!UART_CheckTxAllSentOut(port));
2536}
2537
2538kal_uint32 UART_Get_Maxbaudrate(UART_PORT port)
2539{
2540 return 6000000;
2541}
2542
2543kal_uint32 UART_PutBytesIor(UART_PORT port, void *putIor)
2544{
2545 void *p_ior;
2546 if(port >= MAX_UART_PORT_NUM)
2547 return 0;
2548
2549 p_ior = putIor;
2550 while(1)
2551 {
2552 // if there is no tgpd, atach a bypass tgpd
2553 uart_en_q_de_q_with_mutex(port, UART_TX, UART_EN_Q, ((tty_io_request_t *) putIor)->first_gpd, ((tty_io_request_t *) putIor)->last_gpd);
2554 if(((tty_io_request_t *) p_ior)->next_request == NULL)
2555 {
2556 break;
2557 } else
2558 {
2559 p_ior = ((tty_io_request_t *) p_ior)->next_request;
2560 }
2561 }
2562
2563 return 0;
2564}
2565
2566kal_uint32 UART_PutBytesIor_LIGHT(UART_PORT port, void *putIor)
2567{
2568 void *p_ior;
2569 if(port >= MAX_UART_PORT_NUM)
2570 return 0;
2571
2572 p_ior = putIor;
2573 while(1)
2574 {
2575 // if there is no tgpd, atach a bypass tgpd
2576 uart_en_q_de_q_with_mutex(port, UART_TX, UART_EN_Q_LIGHT, ((tty_io_request_t *) putIor)->first_gpd, ((tty_io_request_t *) putIor)->last_gpd);
2577 if(((tty_io_request_t *) p_ior)->next_request == NULL)
2578 {
2579 break;
2580 } else
2581 {
2582 p_ior = ((tty_io_request_t *) p_ior)->next_request;
2583 }
2584 }
2585
2586 return 0;
2587}
2588
2589kal_uint32 UART_GetBytesIor(UART_PORT port, void *ior)
2590{
2591 void *p_ior;
2592
2593 if(port >= MAX_UART_PORT_NUM)
2594 return 0;
2595
2596 p_ior = ior;
2597 while(1)
2598 {
2599 uart_en_q_de_q_with_mutex(port, UART_RX, UART_EN_Q, ((tty_io_request_t *) p_ior)->first_gpd, ((tty_io_request_t *) p_ior)->last_gpd);
2600 if(((tty_io_request_t *) p_ior)->next_request == NULL)
2601 {
2602 break;
2603 } else
2604 {
2605 p_ior = ((tty_io_request_t *) p_ior)->next_request;
2606 }
2607 }
2608
2609 return 0;
2610}
2611
2612
2613void UART_DriverInit(UART_PORT port)
2614{
2615 module_type ownerid;
2616 static kal_bool b_uart_custom_init = KAL_FALSE;
2617 kal_bool Is_OpenUart = KAL_TRUE;
2618
2619 ownerid = (MOD_UART1_HISR + port);
2620
2621 // Customization
2622 if(b_uart_custom_init == KAL_FALSE)
2623 {
2624 uart_customize_init();
2625 b_uart_custom_init = KAL_TRUE;
2626 }
2627
2628 if(Is_OpenUart == KAL_TRUE)
2629 {
2630 UART_HWInit(port);
2631
2632 pUart_CMD_FUNC[port]= &UartDriver;
2633
2634 U_Open(port, ownerid);
2635 }
2636
2637 // create mutex
2638 if(mutex_status == KAL_FALSE && !INT_QueryExceptionStatus())
2639 {
2640 mutexid = kal_create_mutex("DRV_UART");
2641 mutex_status = KAL_TRUE;
2642 }
2643}
2644
2645void UART_SetNeedTxDoneCb(UART_PORT port, kal_bool needTxDoneCb, module_type ownerid)
2646{
2647 UARTPort[port].need_tx_done_cb = needTxDoneCb;
2648}
2649
2650kal_uint32 uart_cal_tgpd_buf_length(void *head, void *tail)
2651{
2652 void *gpd_cur, *bd_cur;
2653 kal_uint32 sum = 0;
2654
2655 if(head == NULL || tail == NULL)
2656 return 0;
2657
2658 gpd_cur = head;
2659 while(1)
2660 {
2661 if(QBM_DES_GET_BPS(gpd_cur) == 0)
2662 {
2663 if(QBM_DES_GET_BDP(gpd_cur))
2664 {
2665 bd_cur = QBM_DES_GET_DATAPTR(gpd_cur);
2666 while(1)
2667 {
2668 sum += QBM_DES_GET_DATALEN(bd_cur);
2669
2670 if(QBM_DES_GET_EOL(bd_cur)) {break;}
2671 else {bd_cur = QBM_DES_GET_NEXT(bd_cur);}
2672 }
2673 } else
2674 {
2675 sum += QBM_DES_GET_DATALEN(gpd_cur);
2676 }
2677 }
2678
2679 if(gpd_cur == tail) {return sum;}
2680 else {gpd_cur = QBM_DES_GET_NEXT(gpd_cur);}
2681 }
2682}
2683
2684void uart_en_q_de_q_with_mutex(UART_PORT port, kal_bool tx_or_rx, kal_uint8 en_q_or_de_q, void *p_ior_head, void *p_ior_tail)
2685{
2686 void *p_gpd_head = NULL;
2687 void *p_gpd_tail = NULL;
2688 void *p_gpd_cur = NULL;
2689 kal_uint32 queue_len = 0;
2690 tty_io_request_t *ior = NULL;
2691if(!kal_if_hisr()){
2692 // lock mutex
2693 kal_take_mutex(mutexid);
2694}
2695 DCL_HANDLE handle = DclSerialPort_Open(port, 0);
2696
2697 if(tx_or_rx == (kal_bool) UART_TX)
2698 {
2699 if(en_q_or_de_q == UART_EN_Q)
2700 {
2701
2702 uart_cal_chksum_and_flush_gpd_list(p_ior_head, p_ior_tail);
2703
2704 if(uart_wait_tgpd_head[port] == NULL && uart_wait_tgpd_tail[port] == NULL)
2705 {
2706 uart_wait_tgpd_head[port] = p_ior_head;
2707 uart_wait_tgpd_tail[port] = p_ior_tail;
2708 } else
2709 {
2710 qbmt_common_en_q_rx(p_ior_head, p_ior_tail, (void **) &uart_wait_tgpd_head[port], (void **) &uart_wait_tgpd_tail[port]);
2711 }
2712 } else if(en_q_or_de_q == UART_EN_Q_LIGHT)
2713 {
2714 if(uart_wait_tgpd_head[port] == NULL && uart_wait_tgpd_tail[port] == NULL)
2715 {
2716 uart_wait_tgpd_head[port] = p_ior_head;
2717 uart_wait_tgpd_tail[port] = p_ior_tail;
2718 } else
2719 {
2720 qbmt_common_en_q_rx(p_ior_head, p_ior_tail, (void **) &uart_wait_tgpd_head[port], (void **) &uart_wait_tgpd_tail[port]);
2721 }
2722 } else
2723 {
2724 if(uart_tgpd_head[port] != NULL)
2725 {
2726 if(en_q_or_de_q == UART_DE_Q)
2727 {
2728 queue_len = qbmt_de_q((void **) &uart_tgpd_head[port], (void **) &uart_tgpd_tail[port], (void **) &p_gpd_head, (void **) &p_gpd_tail);
2729 } else if(en_q_or_de_q == UART_DE_Q_ALL)
2730 {
2731#if defined(META_MODE_SW_ESCAPING)
2732 if(kal_query_boot_mode() != FACTORY_BOOT)
2733#endif
2734 {
2735 HDMA_BUF0_STOP((2 + port));
2736 }
2737 uart_clear_hwo_of_gpd_list(uart_tgpd_head[port], uart_tgpd_tail[port]);
2738 queue_len = qbmt_de_q((void **) &uart_tgpd_head[port], (void **) &uart_tgpd_tail[port], (void **) &p_gpd_head, (void **) &p_gpd_tail);
2739 QBM_FREE_ONE(uart_tgpd_head[port]);
2740
2741 if(uart_wait_tgpd_head[port] != NULL)
2742 {
2743 if(queue_len > 0)
2744 {
2745 qbmt_common_en_q_rx(uart_wait_tgpd_head[port], uart_wait_tgpd_tail[port], (void **) &p_gpd_head, (void **) &p_gpd_tail);
2746 } else
2747 {
2748 p_gpd_head = uart_wait_tgpd_head[port];
2749 p_gpd_tail = uart_wait_tgpd_tail[port];
2750 queue_len = 1;
2751 }
2752 uart_clear_hwo_of_gpd_list(p_gpd_head, p_gpd_tail);
2753 }
2754
2755 uart_tgpd_head[port] = NULL;
2756 uart_tgpd_tail[port] = NULL;
2757 uart_wait_tgpd_head[port] = NULL;
2758 uart_wait_tgpd_tail[port] = NULL;
2759 } else ASSERT(0);
2760
2761 if(queue_len > 0)
2762 {
2763 if(UARTPort[port].need_tx_done_cb)
2764 {
2765 ior = (tty_io_request_t *) QBM_DES_GET_SW_CTRL_FIELD(p_gpd_head);
2766 ior->first_gpd = p_gpd_head;
2767 ior->last_gpd = p_gpd_tail;
2768 ior->next_request = NULL;
2769 DclSerialPort_DrvTxDone(handle, kal_get_active_module_id(), ior);
2770 } else
2771 {
2772 qbmt_dest_q((void *) p_gpd_head, (void *) p_gpd_tail);
2773 }
2774 }
2775 }
2776 }
2777 } else
2778 {
2779 if(en_q_or_de_q == (kal_bool) UART_EN_Q)
2780 {
2781 if(uart_rgpd_head[port] == NULL && uart_rgpd_tail[port] == NULL)
2782 {
2783 uart_cal_chksum_and_flush_gpd_list(p_ior_head, p_ior_tail);
2784
2785 QBM_DES_CLR_HWO(p_ior_tail);
2786 QBM_CACHE_FLUSH((void *) p_ior_tail, QBM_SIZE_GPD_BD_TST);
2787 HDMA_BUF0_PROG_ADDR_CONFIG((3 + port), p_ior_head);
2788 uart_rgpd_head[port] = p_ior_head;
2789 uart_rgpd_tail[port] = p_ior_tail;
2790 HDMA_BUF0_START((3 + port));
2791 }else{
2792 qbmt_common_en_q_rx(p_ior_head, p_ior_tail, (void **) &uart_rgpd_head[port], (void **) &uart_rgpd_tail[port]);
2793 uart_cal_chksum_and_flush_gpd_list(uart_rgpd_head[port], uart_rgpd_tail[port]);
2794 QBM_DES_CLR_HWO(uart_rgpd_tail[port]);
2795 QBM_CACHE_FLUSH((void *) uart_rgpd_tail[port], QBM_SIZE_GPD_BD_TST);
2796
2797 HDMA_BUF0_RESUME((3 + port));
2798 }
2799 } else
2800 {
2801 if(uart_rgpd_head[port] == NULL)
2802 {
2803 if(!kal_if_hisr()){
2804 kal_give_mutex(mutexid);
2805 }
2806 return;
2807 } else
2808 {
2809 if(en_q_or_de_q == UART_DE_Q)
2810 {
2811 queue_len = qbmt_de_q((void **) &uart_rgpd_head[port], (void **) &uart_rgpd_tail[port], (void **) &p_gpd_head, (void **) &p_gpd_tail);
2812 } else if(en_q_or_de_q == UART_DE_Q_ALL)
2813 {
2814 // stop q
2815 HDMA_BUF0_STOP((port + 3));
2816 // de-Q all GPDs
2817 p_gpd_head = uart_rgpd_head[port];
2818 p_gpd_tail = uart_rgpd_tail[port];
2819 uart_rgpd_head[port] = NULL;
2820 uart_rgpd_tail[port] = NULL;
2821 queue_len = 1; // not real queue length
2822 }
2823
2824 if(p_gpd_head != NULL && p_gpd_tail != NULL && queue_len > 0)
2825 {
2826#if defined(META_MODE_SW_ESCAPING) && !defined(UART_SIM_QMU)
2827 if(kal_query_boot_mode() == FACTORY_BOOT){
2828 UART_META_ExBytes(port, p_gpd_head, p_gpd_tail);
2829 }
2830#endif
2831 ior = (tty_io_request_t *) QBM_DES_GET_SW_CTRL_FIELD(p_gpd_head);
2832 ior->first_gpd = p_gpd_head;
2833 ior->last_gpd = p_gpd_tail;
2834 ior->next_request = NULL;
2835 DclSerialPort_DrvRx(handle, kal_get_active_module_id(), ior); // need to modify
2836 }
2837 }
2838 }
2839 }
2840
2841 if(uart_wait_tgpd_head[port] != NULL && uart_wait_tgpd_tail[port] != NULL && !(DRV_Reg32(UART_LCR(UART_BaseAddr[port])) & UART_LCR_BREAK))
2842 {
2843 if(uart_tgpd_head[port] == NULL && uart_tgpd_tail[port] == NULL)
2844 {
2845 uart_tgpd_head[port] = uart_wait_tgpd_head[port];
2846 uart_tgpd_tail[port] = uart_wait_tgpd_tail[port];
2847
2848 // connect a BPS GPD to the tail
2849 qbmt_alloc_q(QBM_TYPE_TGPD_BPS, 1, (void **) &p_gpd_cur, (void **) &p_gpd_cur);
2850 ASSERT(p_gpd_cur!= NULL);
2851
2852 qbmt_common_en_q_rx(p_gpd_cur, p_gpd_cur, (void **) &uart_tgpd_head[port], (void **) &uart_tgpd_tail[port]);
2853#if defined(META_MODE_SW_ESCAPING)
2854 if(kal_query_boot_mode() == FACTORY_BOOT){
2855 UART_META_PutBytes(port,uart_tgpd_head[port], uart_tgpd_tail[port]);
2856 }else
2857#endif
2858 {
2859 HDMA_BUF0_PROG_ADDR_CONFIG((2 + port), uart_tgpd_head[port]);
2860 HDMA_BUF0_START((2 + port));
2861 }
2862 uart_wait_tgpd_head[port] = NULL;
2863 uart_wait_tgpd_tail[port] = NULL;
2864 } else if(QBM_DES_GET_BPS(uart_tgpd_head[port]) && QBM_DES_GET_BPS(uart_tgpd_tail[port]))
2865 {
2866 QBM_FREE_ONE(uart_tgpd_head[port]);
2867
2868 uart_tgpd_head[port] = uart_wait_tgpd_head[port];
2869 uart_tgpd_tail[port] = uart_wait_tgpd_tail[port];
2870
2871 // connect a BPS GPD to the tail
2872 qbmt_alloc_q(QBM_TYPE_TGPD_BPS, 1, (void **) &p_gpd_cur, (void **) &p_gpd_cur);
2873 ASSERT(p_gpd_cur!= NULL);
2874 qbmt_common_en_q_rx(p_gpd_cur, p_gpd_cur, (void **) &uart_tgpd_head[port], (void **) &uart_tgpd_tail[port]);
2875#if defined(META_MODE_SW_ESCAPING)
2876 if(kal_query_boot_mode() == FACTORY_BOOT){
2877 UART_META_PutBytes(port,uart_wait_tgpd_head[port], uart_wait_tgpd_tail[port]);
2878 }else
2879#endif
2880 {
2881 HDMA_BUF0_PROG_ADDR_CONFIG((2 + port), uart_wait_tgpd_head[port]);
2882 HDMA_BUF0_START((2 + port));
2883 }
2884 uart_wait_tgpd_head[port] = NULL;
2885 uart_wait_tgpd_tail[port] = NULL;
2886 }
2887 }
2888 if(!kal_if_hisr()){
2889 // unlock mutex
2890 kal_give_mutex(mutexid);
2891 }
2892 return;
2893}
2894
2895
2896void uart_qbm_virt_to_phy(void** pp_gpd_head, void** pp_gpd_tail)
2897{
2898 void *gpd_ptr = NULL, *gpd_ptr_tmp = NULL;
2899 void *bd_ptr = NULL, *bd_ptr_tmp = NULL;;
2900 void *pgd_data_ptr = NULL, *bd_data_ptr = NULL;
2901
2902 *pp_gpd_head = (void*)virt_to_phys(*pp_gpd_head);
2903 gpd_ptr = *pp_gpd_head;
2904 while(1)
2905 {
2906 if(QBM_DES_GET_BDP(gpd_ptr))
2907 {
2908 bd_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
2909 bd_ptr = (void*)virt_to_phys(bd_ptr);
2910 QBM_DES_SET_DATAPTR(gpd_ptr,bd_ptr);
2911 qbm_cal_set_checksum_by_len((const kal_uint8 *)gpd_ptr, 12);
2912 while(1)
2913 {
2914 bd_data_ptr = QBM_DES_GET_DATAPTR(bd_ptr);
2915 bd_data_ptr = (void*)virt_to_phys(bd_data_ptr);
2916 QBM_DES_SET_DATAPTR(bd_ptr,bd_data_ptr);
2917 if(QBM_DES_GET_EOL(bd_ptr))
2918 {
2919 break;
2920 } else
2921 {
2922 bd_ptr_tmp = (void*)QBM_DES_GET_NEXT(bd_ptr);
2923 bd_ptr_tmp = (void*)virt_to_phys(bd_ptr_tmp);
2924 QBM_DES_SET_NEXT(bd_ptr,bd_ptr_tmp);
2925 qbm_cal_set_checksum_by_len((const kal_uint8 *)bd_ptr, 12);
2926 bd_ptr = QBM_DES_GET_NEXT(bd_ptr);
2927 }
2928 }
2929 } else
2930 {
2931 pgd_data_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
2932 pgd_data_ptr = (void*)virt_to_phys(pgd_data_ptr);
2933 QBM_DES_SET_DATAPTR(gpd_ptr,pgd_data_ptr);
2934 }
2935
2936 if(gpd_ptr == *pp_gpd_tail)
2937 {
2938 break;
2939 } else
2940 {
2941 gpd_ptr_tmp = (void*)QBM_DES_GET_NEXT(gpd_ptr);
2942 gpd_ptr_tmp = (void*)virt_to_phys(gpd_ptr_tmp);
2943 QBM_DES_SET_NEXT(gpd_ptr,gpd_ptr_tmp);
2944 qbm_cal_set_checksum_by_len((const kal_uint8 *) gpd_ptr, 12);
2945 gpd_ptr = QBM_DES_GET_NEXT(gpd_ptr);
2946 }
2947
2948 }
2949
2950}
2951
2952void uart_qbm_phy_to_virt(void**pp_gpd_head, void**pp_gpd_tail)
2953{
2954 void *gpd_ptr = NULL, *gpd_ptr_tmp = NULL;
2955 void *bd_ptr = NULL, *bd_ptr_tmp = NULL;;
2956 void *pgd_data_ptr = NULL, *bd_data_ptr = NULL;
2957
2958
2959 *pp_gpd_head = (void*)phys_to_virt(*pp_gpd_head);
2960 QBM_CACHE_INVALID(*pp_gpd_head, QBM_SIZE_TGPD);
2961 gpd_ptr = *pp_gpd_head;
2962 *pp_gpd_tail = (void*)phys_to_virt(*pp_gpd_tail);
2963 QBM_CACHE_INVALID(*pp_gpd_tail, QBM_SIZE_TGPD);
2964 while(1)
2965 {
2966 if(QBM_DES_GET_BDP(gpd_ptr))
2967 {
2968 bd_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
2969 bd_ptr = (void*)phys_to_virt(bd_ptr);
2970 QBM_CACHE_INVALID(bd_ptr, QBM_SIZE_TBD);
2971 QBM_DES_SET_DATAPTR(gpd_ptr,bd_ptr);
2972
2973 while(1)
2974 {
2975 bd_data_ptr = QBM_DES_GET_DATAPTR(bd_ptr);
2976 bd_data_ptr = (void*)phys_to_virt(bd_data_ptr);
2977 QBM_CACHE_INVALID(bd_data_ptr, QBM_SIZE_CACHE_ALIGN(QBM_DES_GET_DATALEN(bd_data_ptr)));
2978 QBM_DES_SET_DATAPTR(bd_ptr,bd_data_ptr);
2979
2980 if(QBM_DES_GET_EOL(bd_ptr))
2981 {
2982 break;
2983 } else
2984 {
2985 bd_ptr_tmp = (void*)QBM_DES_GET_NEXT(bd_ptr);
2986 bd_ptr_tmp = (void*)phys_to_virt(bd_ptr_tmp);
2987 QBM_CACHE_INVALID(bd_ptr_tmp, QBM_SIZE_TBD);
2988 QBM_DES_SET_NEXT(bd_ptr,bd_ptr_tmp);
2989 bd_ptr = QBM_DES_GET_NEXT(bd_ptr);
2990 }
2991 }
2992 } else
2993 {
2994 pgd_data_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
2995 pgd_data_ptr = (void*)phys_to_virt(pgd_data_ptr);
2996 QBM_CACHE_INVALID(pgd_data_ptr, QBM_SIZE_CACHE_ALIGN(QBM_DES_GET_DATALEN(pgd_data_ptr)));
2997 QBM_DES_SET_DATAPTR(gpd_ptr,pgd_data_ptr);
2998 }
2999
3000 if(gpd_ptr == *pp_gpd_tail)
3001 {
3002 break;
3003 } else
3004 {
3005 gpd_ptr_tmp = (void*)QBM_DES_GET_NEXT(gpd_ptr);
3006 gpd_ptr_tmp = (void*)phys_to_virt(gpd_ptr_tmp);
3007 QBM_CACHE_INVALID(gpd_ptr_tmp, QBM_SIZE_TGPD);
3008 QBM_DES_SET_NEXT(gpd_ptr,gpd_ptr_tmp);
3009 gpd_ptr = QBM_DES_GET_NEXT(gpd_ptr);
3010 }
3011
3012 }
3013
3014}
3015
3016void UART_META_PutBytes(UART_PORT port, void * gpd_head, void * gpd_tail){
3017 hdma_tbd_t *bd_ptr = NULL, *p_bd_cur =NULL;
3018 hdma_tgpd_t *gpd_ptr = NULL;
3019 kal_uint8 gpd_ext_len=0, bd_ext_len=0;
3020 kal_uint32 gpd_data_len=0, bd_data_len=0;
3021 kal_uint8 *gpd_ext_ptr=NULL, *gpd_data_ptr=NULL, *bd_ext_ptr=NULL, *bd_data_ptr=NULL;
3022
3023 gpd_ptr = (hdma_tgpd_t*)gpd_head;
3024 while(1){
3025 if(QBM_DES_GET_HWO(gpd_ptr)==0){
3026 break;
3027 }
3028 if(QBM_DES_GET_BPS(gpd_ptr)){
3029 QBM_DES_CLR_HWO(gpd_ptr);
3030 QBM_CACHE_FLUSH(gpd_ptr, QBM_SIZE_TGPD);
3031 goto next;
3032 }
3033 if (QBM_DES_GET_EXTLEN(gpd_ptr)) {
3034 gpd_ext_len = QBM_DES_GET_EXTLEN(gpd_ptr);
3035 gpd_ext_ptr = QBM_DES_GET_EXT(gpd_ptr);
3036 PutUARTDatas(port, UART_ESCAPE_CHAR, gpd_ext_ptr,gpd_ext_len);
3037 //U_SendData(port, gpd_ext_ptr, gpd_ext_len, FACTORY_BOOT, UART_ESCAPE_CHAR, UARTPort[port].ownerid);
3038 }
3039 if (QBM_DES_GET_BDP(gpd_ptr)) {
3040 bd_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
3041 p_bd_cur = bd_ptr;
3042 while (1) {
3043 if (QBM_DES_GET_EXTLEN(p_bd_cur)) {
3044 bd_ext_len = QBM_DES_GET_EXTLEN(p_bd_cur);
3045 bd_ext_ptr = QBM_DES_GET_EXT(p_bd_cur);
3046 PutUARTDatas(port, UART_ESCAPE_CHAR, bd_ext_ptr,bd_ext_len);
3047 //U_SendData(port, bd_ext_ptr, bd_ext_len, FACTORY_BOOT, UART_ESCAPE_CHAR, UARTPort[port].ownerid);
3048
3049 }
3050 if (QBM_DES_GET_DATALEN(p_bd_cur)) {
3051 bd_data_len = QBM_DES_GET_DATALEN(p_bd_cur);
3052 bd_data_ptr = QBM_DES_GET_DATAPTR(p_bd_cur);
3053 PutUARTDatas(port, UART_ESCAPE_CHAR, bd_data_ptr,bd_data_len);
3054 //U_SendData(port, bd_data_ptr, bd_data_len, FACTORY_BOOT, UART_ESCAPE_CHAR, UARTPort[port].ownerid);
3055 }
3056 if (QBM_DES_GET_EOL(p_bd_cur)) {
3057 break;
3058 }
3059 p_bd_cur = (void *)QBM_DES_GET_NEXT(p_bd_cur);
3060 }
3061 } else{
3062
3063 gpd_data_len = QBM_DES_GET_DATALEN(gpd_ptr);
3064 gpd_data_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
3065 PutUARTDatas(port, UART_ESCAPE_CHAR, gpd_data_ptr,gpd_data_len);
3066 //U_SendData(port, gpd_data_ptr, gpd_data_len, FACTORY_BOOT, UART_ESCAPE_CHAR, UARTPort[port].ownerid);
3067 }
3068
3069 QBM_DES_CLR_HWO(gpd_ptr);
3070 QBM_CACHE_FLUSH(gpd_ptr, QBM_SIZE_TGPD);
3071 if(gpd_ptr == gpd_tail)
3072 {
3073 break;
3074 } else
3075 {
3076next:
3077 gpd_ptr = (void *) QBM_DES_GET_NEXT(gpd_ptr);
3078 }
3079 }
3080
3081 /* Cooperate with Non-Blocking CACHE API */
3082 MM_Sync();
3083}
3084
3085
3086void uart_cal_chksum_and_flush_gpd_list(void * gpd_head, void * gpd_tail)
3087{
3088 hdma_tbd_t *gpd_ptr = NULL, *bd_ptr = NULL;
3089 void *pgd_data_ptr = NULL, *bd_data_ptr = NULL;
3090
3091 gpd_ptr = (hdma_tbd_t*)gpd_head;
3092 while(1)
3093 {
3094 QBM_DES_SET_HWO(gpd_ptr);
3095#if !defined(__DRVTEST_SW_DOMAIN__)
3096 qbm_cal_set_checksum_by_len((const kal_uint8 *) gpd_ptr, 12);
3097#endif
3098 QBM_CACHE_FLUSH((void *) gpd_ptr, QBM_SIZE_TGPD);
3099
3100 if(QBM_DES_GET_BDP(gpd_ptr))
3101 {
3102 bd_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
3103 while(1)
3104 {
3105#if !defined(__DRVTEST_SW_DOMAIN__)
3106 qbm_cal_set_checksum_by_len((const kal_uint8 *) bd_ptr, 12);
3107#endif
3108 QBM_CACHE_FLUSH((void *) bd_ptr, QBM_SIZE_TBD);
3109 bd_data_ptr = QBM_DES_GET_DATAPTR(bd_ptr);
3110 QBM_CACHE_FLUSH((void *) bd_data_ptr, QBM_DES_GET_DATALEN(bd_ptr));
3111
3112 if(QBM_DES_GET_EOL(bd_ptr))
3113 {
3114 break;
3115 } else
3116 {
3117 bd_ptr = (void *) QBM_DES_GET_NEXT(bd_ptr);
3118 }
3119 }
3120 } else
3121 {
3122 pgd_data_ptr = QBM_DES_GET_DATAPTR(gpd_ptr);
3123 QBM_CACHE_FLUSH((void *) pgd_data_ptr, QBM_DES_GET_DATALEN(gpd_ptr));
3124 }
3125
3126 if(gpd_ptr == gpd_tail)
3127 {
3128 break;
3129 } else
3130 {
3131 gpd_ptr = (void *) QBM_DES_GET_NEXT(gpd_ptr);
3132 }
3133
3134 }
3135
3136 /* Cooperate with Non-Blocking CACHE API */
3137 MM_Sync();
3138}
3139
3140void uart_clear_hwo_of_gpd_list(void *gpd_head, void *gpd_tail)
3141{
3142 hdma_tbd_t *gpd_ptr = NULL;//, *bd_ptr = NULL;
3143
3144 gpd_ptr = gpd_head;
3145 while(1)
3146 {
3147 QBM_DES_CLR_HWO(gpd_ptr);
3148 QBM_CACHE_FLUSH(gpd_ptr, QBM_SIZE_GPD_BD_TST);
3149
3150 if(gpd_ptr == gpd_tail)
3151 {
3152 break;
3153 } else
3154 {
3155 gpd_ptr = (void *) QBM_DES_GET_NEXT(gpd_ptr);
3156 }
3157 }
3158
3159 /* Cooperate with Non-Blocking CACHE API */
3160 MM_Sync();
3161}
3162
3163typedef struct _uart_bps_gpd_pool {
3164 void *gpd_head;
3165 void *gpd_tail;
3166 kal_uint32 free_num;
3167 kal_uint32 alloc_ok_cnt;
3168 kal_uint32 alloc_fail_cnt;
3169 kal_uint32 free_ok_cnt;
3170 void *buffer_start;
3171 void *buffer_end;
3172 kal_uint32 total_num;
3173} uart_bps_gpd_pool;
3174
3175static void *uart_discard_tgpd_head = NULL;
3176static void *uart_discard_tgpd_tail = NULL;
3177static void *uart_discard_rgpd_head = NULL;
3178static void *uart_discard_rgpd_tail = NULL;
3179static kal_uint32 uart_excpt_tx_bytes[MAX_UART_PORT_NUM];
3180static kal_uint32 uart_excpt_rx_bytes[MAX_UART_PORT_NUM];
3181static uart_bps_gpd_pool uart_bps_gpd_pool_info;
3182
3183extern void uart_cal_chksum_and_flush_gpd_list(void *gpd_head, void *gpd_tail);
3184
3185
3186kal_bool uart_except_init_qbm()
3187{
3188 uart_bps_gpd_pool *gpd_pool = &uart_bps_gpd_pool_info;
3189 bm_queue_config conf;
3190 kal_uint32 ret;
3191
3192 qbm_init_q_config(&conf);
3193
3194 conf.buff_num = UART_ECPT_QBM_BPS_NUM;
3195 conf.p_mem_pool_str = uart_ecpt_bps_buf;
3196 conf.p_mem_pool_end = conf.p_mem_pool_str + UART_ECPT_QBM_BPS_BUF_SZ;
3197 ret = qbm_init_queue_non_free(QBM_TYPE_TGPD_BPS, &conf,
3198 &gpd_pool->gpd_head,
3199 &gpd_pool->gpd_tail);
3200 if(QBM_ERROR_OK != ret)
3201 return KAL_FALSE;
3202
3203 gpd_pool->buffer_start = conf.p_mem_pool_str;
3204 gpd_pool->buffer_end = conf.p_mem_pool_end;
3205 gpd_pool->total_num = conf.buff_num;
3206 gpd_pool->free_num = conf.buff_num;
3207
3208 return KAL_TRUE;
3209}
3210
3211kal_bool uart_except_check_bps_gpd(void *p_gpd)
3212{
3213 kal_uint8* uart_bps_buf;
3214
3215 uart_bps_buf = uart_ecpt_bps_buf;
3216
3217 if (((kal_uint8 *)p_gpd >= uart_bps_buf) && ((kal_uint8 *)p_gpd < uart_bps_buf + UART_ECPT_QBM_BPS_BUF_SZ)){
3218 return KAL_TRUE;
3219 }
3220 return KAL_FALSE;
3221}
3222
3223void uart_except_free_bps_gpd(void *p_gpd)
3224{
3225 uart_bps_gpd_pool *gpd_pool = &uart_bps_gpd_pool_info;
3226
3227 ASSERT(uart_except_check_bps_gpd(p_gpd));
3228
3229 if (gpd_pool->gpd_head == NULL) {
3230 gpd_pool->gpd_head = gpd_pool->gpd_tail = p_gpd;
3231 } else {
3232 QBM_DES_SET_NEXT(gpd_pool->gpd_tail, p_gpd);
3233 gpd_pool->gpd_tail = p_gpd;
3234 }
3235
3236 gpd_pool->free_num ++;
3237 gpd_pool->free_ok_cnt ++;
3238}
3239
3240void *uart_except_alloc_bps_gpd(kal_bool tx_or_rx)
3241{
3242 void *p_ret_gpd;
3243 uart_bps_gpd_pool *gpd_pool = &uart_bps_gpd_pool_info;
3244
3245 if (gpd_pool->gpd_head == NULL) {
3246 gpd_pool->alloc_fail_cnt ++;
3247 return NULL;
3248 }
3249
3250 p_ret_gpd = gpd_pool->gpd_head;
3251 if (gpd_pool->gpd_head == gpd_pool->gpd_tail) {
3252 gpd_pool->gpd_head = gpd_pool->gpd_tail = NULL;
3253 } else {
3254 gpd_pool->gpd_head = QBM_DES_GET_NEXT(gpd_pool->gpd_head);
3255 }
3256
3257 gpd_pool->free_num --;
3258 gpd_pool->alloc_ok_cnt ++;
3259
3260 QBM_DES_SET_NEXT(p_ret_gpd, NULL);
3261
3262 //QBM_DES_SET_BPS(p_ret_gpd);
3263
3264 return p_ret_gpd;
3265}
3266
3267kal_uint32 uart_except_free_bps_gpd_in_list(void **pp_head, void **pp_tail)
3268{
3269 void *p_gpd_cur, *p_gpd_pre, *p_gpd_nex;
3270 int free_num = 0;
3271
3272 p_gpd_cur = *pp_head;
3273 p_gpd_pre = NULL;
3274
3275 if (*pp_head == NULL || *pp_tail == NULL)
3276 return 0;
3277
3278 while (1) {
3279 p_gpd_nex = QBM_DES_GET_NEXT(p_gpd_cur);
3280 if (uart_except_check_bps_gpd(p_gpd_cur)) {
3281 /* free this gpd from list */
3282 if (p_gpd_pre == NULL)
3283 *pp_head = p_gpd_nex;
3284 else
3285 QBM_DES_SET_NEXT(p_gpd_pre, p_gpd_nex);
3286
3287 uart_except_free_bps_gpd(p_gpd_cur);
3288 free_num ++;
3289 } else {
3290 p_gpd_pre = p_gpd_cur;
3291 }
3292
3293 if(p_gpd_cur == *pp_tail)
3294 break;
3295
3296 p_gpd_cur = p_gpd_nex;
3297 }
3298
3299 return free_num;
3300}
3301
3302void uart_except_en_q_rx(
3303 void *p_new_head,
3304 void *p_new_tail,
3305 void **pp_orig_head,
3306 void **pp_orig_tail
3307 )
3308{
3309 void *p_orig_tail = NULL;
3310
3311 ASSERT(pp_orig_head!=NULL);
3312 ASSERT(pp_orig_tail!=NULL);
3313 if (*pp_orig_head != NULL) {
3314 p_orig_tail = *pp_orig_tail;
3315
3316 /* set new tail's HWO=0 */
3317 QBM_DES_CLR_HWO(p_new_tail);
3318 QBM_CACHE_FLUSH(p_new_tail, QBM_SIZE_TGPD);
3319
3320 /* link new list to tail of orig list */
3321 QBM_DES_SET_NEXT(p_orig_tail, p_new_head);
3322
3323 /* re-calc the orig tail's checksum */
3324#if !defined(__DRVTEST_SW_DOMAIN__)
3325 qbm_cal_set_checksum_wth_hwo(p_orig_tail);
3326#endif
3327
3328 /* set the orig tail's HWO=1 */
3329 QBM_DES_SET_HWO(p_orig_tail);
3330 QBM_CACHE_FLUSH(p_orig_tail, QBM_SIZE_TGPD);
3331
3332 /* update the orig tail */
3333 *pp_orig_tail = p_new_tail;
3334 } else {
3335 *pp_orig_head = p_new_head;
3336 *pp_orig_tail = p_new_tail;
3337 }
3338}
3339/* the last gpd will not be de-queued */
3340kal_uint32 uart_except_de_q(
3341 void **pp_src_head,
3342 void **pp_src_tail,
3343 void **pp_new_head,
3344 void **pp_new_tail
3345 )
3346{
3347 kal_uint32 deqno = 0;
3348 void *p_this_gpd = NULL;
3349 *pp_new_head = NULL;
3350 *pp_new_tail = NULL;
3351
3352 if (pp_src_head != NULL && *pp_src_head != NULL && *pp_src_head != *pp_src_tail) {
3353 p_this_gpd = *pp_src_head;
3354 QBM_CACHE_INVALID(p_this_gpd, QBM_SIZE_TGPD);
3355 if (!QBM_DES_GET_HWO(p_this_gpd)){
3356 *pp_new_head = p_this_gpd;
3357
3358 while(!QBM_DES_GET_HWO(p_this_gpd) && p_this_gpd != *pp_src_tail) {
3359 *pp_new_tail = p_this_gpd;
3360 deqno ++;
3361
3362 p_this_gpd = QBM_DES_GET_NEXT(p_this_gpd);
3363 QBM_CACHE_INVALID(p_this_gpd, QBM_SIZE_TGPD);
3364 }
3365
3366 *pp_src_head = p_this_gpd;
3367 }
3368 }
3369
3370 return deqno;
3371}
3372
3373kal_uint32 uart_except_de_q_with_timeout(
3374 UART_PORT port,
3375 void **pp_src_head,
3376 void **pp_src_tail,
3377 void **pp_new_head,
3378 void **pp_new_tail
3379 )
3380{
3381 kal_uint32 deqno = 0;
3382 void *p_this_gpd = NULL;
3383 *pp_new_head = NULL;
3384 *pp_new_tail = NULL;
3385
3386 if (pp_src_head != NULL && *pp_src_head != NULL && *pp_src_head != *pp_src_tail) {
3387 p_this_gpd = *pp_src_head;
3388 QBM_CACHE_INVALID(p_this_gpd, QBM_SIZE_TGPD);
3389 if (!QBM_DES_GET_HWO(p_this_gpd)){
3390 *pp_new_head = p_this_gpd;
3391
3392 while(!QBM_DES_GET_HWO(p_this_gpd) && p_this_gpd != *pp_src_tail) {
3393 *pp_new_tail = p_this_gpd;
3394 deqno ++;
3395
3396 p_this_gpd = QBM_DES_GET_NEXT(p_this_gpd);
3397 QBM_CACHE_INVALID(p_this_gpd, QBM_SIZE_TGPD);
3398 }
3399
3400 *pp_src_head = p_this_gpd;
3401 uart_ecpt_timer_reset(port);
3402 }else{
3403 uart_ecpt_timer_start(port);
3404 }
3405 }
3406
3407 return deqno;
3408}
3409
3410DCL_STATUS uart_except_check_dma_status(kal_uint32 hdma_channel)
3411{
3412 kal_uint32 int_sts;
3413 DCL_STATUS ret_sts = STATUS_OK;
3414
3415 int_sts = DRV_Reg32(GDMA_GISAR_UART);
3416
3417 if(IS_HDMA_LENERR_INTR(int_sts, hdma_channel)) {
3418 DRV_WriteReg32(GDMA_GISAR_UART, (HDMA_INTR_CHL_MASK(hdma_channel) << 16));
3419 ret_sts = STATUS_FAIL;
3420 }
3421
3422 if(IS_HDMA_BD_CSERR_INTR(int_sts, hdma_channel)) {
3423 DRV_WriteReg32(GDMA_GISAR_UART, (HDMA_INTR_CHL_MASK(hdma_channel) << 24));
3424 ret_sts = STATUS_ERROR_CRCERROR;
3425 }
3426
3427 if(IS_HDMA_GPD_CSERR_INTR(int_sts, hdma_channel)) {
3428 DRV_WriteReg32(GDMA_GISAR_UART, (HDMA_INTR_CHL_MASK(hdma_channel) << 28));
3429 ret_sts = STATUS_ERROR_CRCERROR;
3430 }
3431
3432 return ret_sts;
3433}
3434
3435DCL_STATUS
3436uart_en_q_de_q_for_ecpt(
3437 UART_PORT port,
3438 kal_bool tx_or_rx,
3439 kal_uint8 en_q_or_de_q,
3440 void **pp_gpd_head,
3441 void **pp_gpd_tail,
3442 kal_uint32 *p_num
3443)
3444{
3445 void *p_gpd_head, *p_gpd_tail; /* work queue */
3446 void *p_bps_gpd;
3447 kal_uint32 deq_num;
3448 DCL_STATUS ret = STATUS_OK;
3449 kal_uint32 hdma_ch;
3450 kal_uint32 xfer_bytes;
3451
3452 ASSERT(pp_gpd_head != NULL);
3453 ASSERT(pp_gpd_tail != NULL);
3454
3455 /* get global variable to local variable */
3456 if (tx_or_rx == (kal_bool)UART_TX) {
3457 p_gpd_head = uart_tgpd_head[port];
3458 p_gpd_tail = uart_tgpd_tail[port];
3459 } else {
3460 p_gpd_head = uart_rgpd_head[port];
3461 p_gpd_tail = uart_rgpd_tail[port];
3462 }
3463
3464 hdma_ch = (tx_or_rx == (kal_bool)UART_TX)?port+2:port+3;
3465
3466 if (en_q_or_de_q == UART_EN_Q) {
3467 if (*pp_gpd_head == NULL || *pp_gpd_tail == NULL) {
3468 goto end;
3469 }
3470
3471 /* alloc a bypass gpd */
3472 if (tx_or_rx == (kal_bool)UART_TX) {
3473 p_bps_gpd = uart_except_alloc_bps_gpd(tx_or_rx);
3474 if (p_bps_gpd == NULL) {
3475 ret = STATUS_FAIL;
3476 goto end;
3477 }
3478
3479 /* append the bypass gpd to the gpd list */
3480 QBM_DES_SET_NEXT(*pp_gpd_tail, p_bps_gpd);
3481 *pp_gpd_tail = p_bps_gpd;
3482 } else {
3483 QBM_DES_CLR_HWO(*pp_gpd_tail);
3484 }
3485
3486 /* re-calc checksum and flush cache */
3487 uart_cal_chksum_and_flush_gpd_list(*pp_gpd_head, *pp_gpd_tail);
3488
3489 /* now, start en-q operation */
3490 if (p_gpd_head == NULL) {
3491 /* clear tail's HWO bit manually */
3492 QBM_DES_CLR_HWO(*pp_gpd_tail);
3493 QBM_CACHE_FLUSH(*pp_gpd_tail, QBM_SIZE_TGPD_BPS);
3494
3495 p_gpd_head = *pp_gpd_head;
3496 p_gpd_tail = *pp_gpd_tail;
3497#if defined(META_MODE_SW_ESCAPING)
3498 if((kal_query_boot_mode() == FACTORY_BOOT) && (tx_or_rx ==(kal_bool)UART_TX)){
3499 UART_META_PutBytes(port, p_gpd_head, p_gpd_tail);
3500 }else
3501#endif
3502 {
3503 /* newly configure and start DMA */
3504 HDMA_BUF0_PROG_ADDR_CONFIG(hdma_ch, p_gpd_head);
3505 HDMA_BUF0_START(hdma_ch);
3506 }
3507 } else {
3508 /* Because META mode Tx should be done before new en_q, p_gpd_head must be NULL. so Tx would not be affected by new Start putbytes.
3509 The following step just for backup, but should not be running. If it run, will may send more data or lose data*/
3510#if defined(META_MODE_SW_ESCAPING)
3511 if((kal_query_boot_mode() == FACTORY_BOOT) && (tx_or_rx ==(kal_bool)UART_TX)){
3512 UART_META_PutBytes(port, p_gpd_head, p_gpd_tail);
3513 }else
3514#endif
3515 {
3516 /* tail's HWO bit will be cleared automatically */
3517 /* en-q and resume DMA */
3518 uart_except_en_q_rx(*pp_gpd_head, *pp_gpd_tail, (void **)&p_gpd_head, (void **)&p_gpd_tail);
3519 HDMA_BUF0_RESUME(hdma_ch);
3520 }
3521 }
3522 } else if (en_q_or_de_q == UART_DE_Q) {
3523 if (p_gpd_head == NULL) {
3524 *pp_gpd_head = NULL;
3525 *pp_gpd_tail = NULL;
3526 if (NULL != p_num)
3527 *p_num = 0;
3528 goto end;
3529 }
3530
3531 if(tx_or_rx == (kal_bool)UART_TX){
3532 deq_num = uart_except_de_q_with_timeout(port,(void **)&p_gpd_head, (void **) &p_gpd_tail, (void **)pp_gpd_head, (void **)pp_gpd_tail);
3533 }else{
3534 deq_num = uart_except_de_q((void **)&p_gpd_head, (void **) &p_gpd_tail, (void **)pp_gpd_head, (void **)pp_gpd_tail);
3535 }
3536
3537 if (deq_num == 0) {
3538 *pp_gpd_head = NULL;
3539 *pp_gpd_tail = NULL;
3540 if (NULL != p_num)
3541 *p_num = deq_num;
3542 goto end;
3543 }
3544
3545 /* check if all is done */
3546 if (p_gpd_head == p_gpd_tail && QBM_DES_GET_HWO(p_gpd_head)==0) {
3547 if (uart_except_check_bps_gpd(p_gpd_head)) {
3548 uart_except_free_bps_gpd(p_gpd_head);
3549 QBM_DES_SET_NEXT(*pp_gpd_tail, NULL);
3550 } else {
3551 QBM_DES_SET_NEXT(*pp_gpd_tail, p_gpd_head);
3552 *pp_gpd_tail = p_gpd_head;
3553 }
3554
3555 p_gpd_head = p_gpd_tail = NULL;
3556 }
3557
3558 /* check and free bypass GPD allocated by us in list */
3559 deq_num -= uart_except_free_bps_gpd_in_list(pp_gpd_head, pp_gpd_tail);
3560
3561 if (NULL != p_num && deq_num > 0) {
3562 *p_num = deq_num;
3563#if defined(META_MODE_SW_ESCAPING)
3564 if(kal_query_boot_mode() == FACTORY_BOOT && tx_or_rx == (kal_bool)UART_RX){
3565 UART_META_ExBytes(port, *pp_gpd_head, *pp_gpd_tail);
3566 }
3567#endif
3568 xfer_bytes = uart_cal_tgpd_buf_length(*pp_gpd_head, *pp_gpd_tail);
3569 if (tx_or_rx == (kal_bool)UART_TX)
3570 uart_excpt_tx_bytes[port] += xfer_bytes;
3571 else
3572 uart_excpt_rx_bytes[port] += xfer_bytes;
3573 }
3574
3575 } else {
3576 ASSERT(en_q_or_de_q != UART_EN_Q && en_q_or_de_q != UART_DE_Q);
3577 }
3578
3579 /* updated global variable from local variable */
3580 if (tx_or_rx == (kal_bool)UART_TX) {
3581 uart_tgpd_head[port] = p_gpd_head;
3582 uart_tgpd_tail[port] = p_gpd_tail;
3583 } else {
3584 uart_rgpd_head[port] = p_gpd_head;
3585 uart_rgpd_tail[port] = p_gpd_tail;
3586 }
3587
3588end:
3589 return ret;
3590}
3591
3592DCL_STATUS uart_ecpt_tx_gpd(UART_PORT port, void *p_first_gpd, void *p_last_gpd)
3593{
3594 ASSERT(port < MAX_UART_PORT_NUM);
3595
3596 return uart_en_q_de_q_for_ecpt(port, UART_TX, UART_EN_Q, &p_first_gpd, &p_last_gpd, NULL);
3597}
3598
3599DCL_STATUS uart_ecpt_tx_done_info(UART_PORT port, void **pp_first_gpd, void **pp_last_gpd, kal_uint32 *gpd_num)
3600{
3601 ASSERT(port < MAX_UART_PORT_NUM);
3602
3603 return uart_en_q_de_q_for_ecpt(port, UART_TX, UART_DE_Q, pp_first_gpd, pp_last_gpd, gpd_num);
3604}
3605
3606DCL_STATUS uart_ecpt_assign_rx_gpd(UART_PORT port, void *p_first_gpd, void *p_last_gpd)
3607{
3608 ASSERT(port < MAX_UART_PORT_NUM);
3609
3610 return uart_en_q_de_q_for_ecpt(port, UART_RX, UART_EN_Q, &p_first_gpd, &p_last_gpd, NULL);
3611}
3612
3613DCL_STATUS uart_ecpt_get_rx_gpd(UART_PORT port, void **pp_first_gpd, void **pp_last_gpd, kal_uint32 *gpd_num)
3614{
3615 ASSERT(port < MAX_UART_PORT_NUM);
3616
3617 return uart_en_q_de_q_for_ecpt(port, UART_RX, UART_DE_Q, pp_first_gpd, pp_last_gpd, gpd_num);
3618}
3619
3620void uart_ecpt_clear_sw_queue(UART_PORT port)
3621{
3622 static kal_bool first_time_clear = KAL_TRUE;
3623
3624 if (first_time_clear) {
3625 first_time_clear = KAL_FALSE;
3626
3627 if (uart_wait_tgpd_head[port] != NULL) {
3628 if (uart_discard_tgpd_head != NULL) {
3629 QBM_DES_SET_NEXT(uart_discard_tgpd_tail, uart_wait_tgpd_head[port]);
3630 uart_discard_tgpd_tail = uart_wait_tgpd_tail[port];
3631 } else {
3632 uart_discard_tgpd_head = uart_wait_tgpd_head[port];
3633 uart_discard_tgpd_tail = uart_wait_tgpd_tail[port];
3634 }
3635 }
3636
3637 if (uart_tgpd_head[port] != NULL) {
3638 if (uart_discard_tgpd_head != NULL) {
3639 QBM_DES_SET_NEXT(uart_discard_tgpd_tail, uart_tgpd_head[port]);
3640 uart_discard_tgpd_tail = uart_tgpd_tail[port];
3641 } else {
3642 uart_discard_tgpd_head = uart_tgpd_head[port];
3643 uart_discard_tgpd_tail = uart_tgpd_tail[port];
3644 }
3645 }
3646
3647 if (uart_rgpd_head[port] != NULL) {
3648 if (uart_discard_rgpd_head != NULL) {
3649 QBM_DES_SET_NEXT(uart_discard_rgpd_tail, uart_rgpd_head[port]);
3650 uart_discard_rgpd_tail = uart_rgpd_tail[port];
3651 } else {
3652 uart_discard_rgpd_head = uart_rgpd_head[port];
3653 uart_discard_rgpd_tail = uart_rgpd_tail[port];
3654 }
3655 }
3656
3657 } else {
3658 ;
3659 }
3660
3661 uart_wait_tgpd_head[port] = NULL;
3662 uart_wait_tgpd_tail[port] = NULL;
3663
3664 uart_tgpd_head[port] = NULL;
3665 uart_tgpd_tail[port] = NULL;
3666
3667 uart_rgpd_head[port] = NULL;
3668 uart_rgpd_tail[port] = NULL;
3669}
3670
3671DCL_STATUS uart_ecpt_clear_ch(UART_PORT port)
3672{
3673 kal_uint32 val = 0;
3674
3675 ASSERT(port < MAX_UART_PORT_NUM);
3676
3677#if defined(META_MODE_SW_ESCAPING)
3678 if(kal_query_boot_mode() != FACTORY_BOOT)
3679#endif
3680 {
3681 /* Wait Tx HDMA Channel to be inactive */
3682 while(HDMA_BUF0_IS_ACTIVE((port + 2)))
3683 {
3684 val = DRV_Reg32(GDMA_GISAR_UART);
3685 if(IS_HDMA_LENERR_INTR(val, (2 + port))) break;
3686 if(IS_HDMA_GPD_CSERR_INTR(val, (2 + port))) break;
3687 if(IS_HDMA_BD_CSERR_INTR(val, (2 + port))) break;
3688 }
3689
3690 /* Stop Tx HDMA Channel */
3691 HDMA_BUF0_STOP((2 + port));
3692 while (HDMA_BUF0_IS_ACTIVE((port + 2)));
3693}
3694 /* Stop Rx HDMA Channel */
3695 HDMA_BUF0_STOP((3 + port));
3696 while (HDMA_BUF0_IS_ACTIVE((port + 3)));
3697
3698 /* Clear SW Queue */
3699 uart_ecpt_clear_sw_queue(port);
3700
3701 return STATUS_OK;
3702}
3703
3704void uart_ecpt_timer_reset(UART_PORT port){
3705 ASSERT(port < MAX_UART_PORT_NUM);
3706 uart_ecpt_timer[port].timer_during = 0;
3707 uart_ecpt_timer[port].timer_old = 0;
3708 uart_ecpt_timer[port].timer_now = 0;
3709 uart_ecpt_timer[port].timer_start = 0;
3710}
3711
3712void uart_ecpt_timer_start(UART_PORT port)
3713{
3714 ASSERT(port < MAX_UART_PORT_NUM);
3715 if(uart_ecpt_timer[port].timer_start == 0){
3716 uart_ecpt_timer[port].timer_now = ust_get_current_time();
3717 uart_ecpt_timer[port].timer_old = uart_ecpt_timer[port].timer_now;
3718 uart_ecpt_timer[port].timer_during = 0;
3719 uart_ecpt_timer[port].timer_start = 1;
3720 }else{
3721 uart_ecpt_timer[port].timer_now = ust_get_current_time();
3722 }
3723}
3724
3725kal_uint32 uart_ecpt_get_timer_during(UART_PORT port)
3726{
3727 ASSERT(port < MAX_UART_PORT_NUM);
3728 uart_ecpt_timer[port].timer_during =ust_us_duration(uart_ecpt_timer[port].timer_old,uart_ecpt_timer[port].timer_now)/1000 ;
3729 return uart_ecpt_timer[port].timer_during;
3730}
3731
3732DCL_STATUS uart_ecpt_init_hif(UART_PORT port)
3733{
3734 ASSERT(port < MAX_UART_PORT_NUM);
3735
3736 /* need re-init hardware ??? */
3737
3738 /* initial exception mode qbm */
3739 if (uart_except_init_qbm() != KAL_TRUE) {
3740 return STATUS_FAIL;
3741 }
3742 return STATUS_OK;
3743}
3744
3745DCL_STATUS uart_except_reset(UART_PORT port)
3746{
3747 ASSERT(port < MAX_UART_PORT_NUM);
3748 uart_ecpt_tx_state[port] = HIF_STATE_NORMAL;
3749 uart_ecpt_timer_reset(port);
3750
3751 return STATUS_OK;
3752}
3753kal_uint32 uart_ecpt_get_tx_state(UART_PORT port){
3754 ASSERT(port < MAX_UART_PORT_NUM);
3755 kal_uint32 timer_dur = 0;
3756 timer_dur = uart_ecpt_get_timer_during(port);
3757 if(timer_dur>=UART_ECPT_MAX_TIMEOUT){
3758 uart_ecpt_tx_state[port] = HIF_STATE_TXERROR;
3759 uart_ecpt_timer_reset( port);
3760 }else{
3761 uart_ecpt_tx_state[port] = HIF_STATE_NORMAL;
3762 }
3763
3764 return uart_ecpt_tx_state[port];
3765}
3766
3767
3768#else //#if !defined(DRV_UART_OFF)
3769
3770UARTStruct UARTPort[MAX_UART_PORT_NUM];
3771
3772kal_bool UART_VFIFO_support[MAX_UART_PORT_NUM] =
3773{
3774 KAL_FALSE,
3775 KAL_FALSE,
3776};
3777
3778void UART_Boot_PutUARTBytes(UART_PORT port, kal_uint8 *data,kal_uint16 len){}
3779void U_Register(UART_PORT port, UartType_enum type, UartDriver_strcut* drv){}
3780kal_bool U_Open(UART_PORT port, module_type ownerid){}
3781void U_Close(UART_PORT port, module_type ownerid){}
3782kal_uint16 U_GetBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, kal_uint8 *status, module_type ownerid){}
3783kal_uint16 U_PutBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid){}
3784kal_uint16 U_GetBytesAvail(UART_PORT port){}
3785kal_uint16 U_GetTxRoomLeft(UART_PORT port){}
3786kal_uint16 U_PutISRBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length, module_type ownerid){}
3787kal_uint16 U_GetTxISRRoomLeft(UART_PORT port){}
3788kal_uint16 U_SendISRData(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode, kal_uint8 escape_char, module_type ownerid){}
3789kal_uint16 U_SendData(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length,kal_uint8 mode,kal_uint8 escape_char, module_type ownerid ){}
3790void U_Purge(UART_PORT port, UART_buffer dir, module_type ownerid){}
3791void U_SetOwner (UART_PORT port, module_type ownerid){}
3792void U_SetFlowCtrl(UART_PORT port, kal_bool XON, module_type ownerid){}
3793void U_ConfigEscape (UART_PORT port, kal_uint8 EscChar, kal_uint16 ESCGuardtime, module_type ownerid){}
3794void U_SetDCBConfig(UART_PORT port, UARTDCBStruct *UART_Config, module_type ownerid){}
3795void U_CtrlDCD(UART_PORT port, IO_level SDCD, module_type ownerid){}
3796void U_CtrlBreak(UART_PORT port, IO_level SBREAK, module_type ownerid){}
3797void U_ClrRxBuffer(UART_PORT port, module_type ownerid){}
3798void U_ClrTxBuffer(UART_PORT port, module_type ownerid){}
3799void U_SetBaudRate(UART_PORT port, UART_baudrate baudrate, module_type ownerid){}
3800module_type U_GetOwnerID(UART_PORT port){}
3801void U_SetAutoBaud_Div(UART_PORT port, module_type ownerid){}
3802void U_Register_TX_cb(UART_PORT port, module_type ownerid, UART_TX_FUNC func){}
3803void U_Register_RX_cb(UART_PORT port, module_type ownerid, UART_RX_FUNC func){}
3804kal_uint8 U_GetUARTByte(UART_PORT port){}
3805kal_uint8 U_GetUARTByteWithTimeOut(UART_PORT port, kal_uint8* ch, kal_uint32 timeout_value){return 0;}
3806void U_PutUARTByte(UART_PORT port, kal_uint8 data){}
3807void U_PutUARTBytes(UART_PORT port, kal_uint8 *data, kal_uint16 len){}
3808void U_ReadDCBConfig(UART_PORT port, UARTDCBStruct *DCB){}
3809void U_CtrlRI (UART_PORT port, IO_level SRI, module_type ownerid){}
3810void U_CtrlDTR (UART_PORT port, IO_level SDTR, module_type ownerid){}
3811void U_ReadHWStatus(UART_PORT port, IO_level *SDSR, IO_level *SCTS){}
3812void UART_AssertWaitPrevDataSentOut(UART_PORT port){}
3813void UART_Calback(void *parameter){}
3814void UART_CheckAT_Callback(void *parameter){}
3815kal_bool UART_CheckTxAllSentOut(UART_PORT port){}
3816kal_bool UART_CheckTxBufferEmpty(UART_PORT port){}
3817void UART_CompensateAT(UART_PORT port){}
3818void uart_customize_init(void){}
3819void UART_dafault_rx_cb(UART_PORT port){}
3820void UART_dafault_tx_cb(UART_PORT port){}
3821void UART_DriverInit(UART_PORT port){}
3822void UART_EnableTX(UART_PORT port, kal_bool enable){}
3823void UART_GetTxBufferSize(UART_PORT port, kal_uint32 *total_size, kal_uint32 *rest_size){}
3824void UART_HWInit(UART_PORT port){}
3825kal_bool UART_IsVfifoSetting(UART_PORT port, UART_TxRx_VFIFO_support vs){}
3826void UART_RecHandler(void *parameter){}
3827void UART_MsHandler(void *parameter){}
3828void UART_RLSHandler(void *parameter){}
3829void UART_sendilm(UART_PORT port, msg_type msgid){}
3830void UART_set_FIFO_trigger(UART_PORT port, kal_uint16 tx_level, kal_uint16 rx_level){}
3831void UART_SetRateFix(UART_PORT port){}
3832void UART_SetSleepEnable(UART_PORT port, kal_bool enable){}
3833void UART_SleepOnTx_Enable(UART_PORT port, UART_SLEEP_ON_TX enable_flag){}
3834kal_bool uart_support_autoescape(void){}
3835void UART_SwitchPort(UART_PORT *APP_port, UART_PORT new_uart_port){}
3836void UART_TrxHandler(void *parameter){}
3837void UART_TxDMAHandler(void *parameter, kal_uint8 chk_done){}
3838void UART_TurnOnPower(UART_PORT port, kal_bool enable){}
3839void UART1_HISR(void){}
3840void UART2_HISR(void){}
3841void PutUARTDatas(UART_PORT port, kal_uint8 escape_char, kal_uint8 *data,kal_uint16 len){}
3842kal_uint16 BMT_PutBytes(UART_PORT port, kal_uint8 *Buffaddr, kal_uint16 Length){}
3843void PutUARTRingBufferData(UART_PORT port){}
3844void UART_loopback(UART_PORT port){}
3845void UART_dsp_dafault_tx_cb(UART_PORT port){}
3846void UART_dsp_dafault_rx_cb(UART_PORT port){}
3847#endif //if !defined(DRV_UART_OFF)
3848
3849
3850// uart dispatch funtion table
3851UartDriver_strcut UartDriver=
3852{
3853 U_Open,
3854 U_Close,
3855 U_GetBytes, // SIO_CMD_GET_BYTES is not supported
3856 U_PutBytes, // SIO_CMD_PUT_BYTES is not supported
3857 U_GetBytesAvail, // SIO_CMD_GET_RX_AVAIL is not supported
3858 U_GetTxRoomLeft, // SIO_CMD_GET_TX_AVAIL is not supported
3859 U_PutISRBytes, // SIO_CMD_PUT_ISR_BYTES is not supported
3860 U_GetTxISRRoomLeft, // SIO_CMD_GET_ISR_TX_AVAIL is not supported
3861 U_Purge,
3862 U_SetOwner,
3863 U_SetFlowCtrl,
3864 U_ConfigEscape,
3865 U_SetDCBConfig,
3866 U_CtrlDCD, // SIO_CMD_CTRL_DCD is not supported
3867 U_CtrlBreak,
3868 U_ClrRxBuffer,
3869 U_ClrTxBuffer,
3870 U_SetBaudRate,
3871 U_SendISRData, // SIO_CMD_SEND_ISR_DATA is not supported
3872 U_SendData, // SIO_CMD_SEND_DATA is not supported
3873 U_GetOwnerID,
3874 U_SetAutoBaud_Div, // SIO_CMD_SET_AUTOBAUD_DIV is not supported
3875 /*TY adds these to expand flexibility 2004/10/15*/
3876 U_Register_TX_cb, // SIO_CMD_REG_TX_CB is not supported
3877 U_Register_RX_cb, // SIO_CMD_REG_RX_CB is not supported
3878 /*TY adds these to let virtual COM port can retrive exception log 2005/3/8*/
3879 U_GetUARTByte, // SIO_CMD_GET_UART_BYTE is not supported
3880 U_PutUARTByte, // SIO_CMD_PUT_UART_BYTE is not supported
3881 U_PutUARTBytes, // SIO_CMD_PUT_UART_BYTES is not supported
3882 /*for virtual com port to return DCB configuration*/
3883 U_ReadDCBConfig,
3884 U_CtrlRI, // SIO_CMD_CTRL_RI is not supported
3885 U_CtrlDTR, // SIO_CMD_CTRL_DTR is not supported
3886 U_ReadHWStatus,
3887 U_GetUARTByteWithTimeOut
3888};
3889
3890
3891typedef struct hdma_tgpd_ss {
3892 kal_uint8 hwo:1;
3893 kal_uint8 bdp:1;
3894 kal_uint8 bps:1;
3895 kal_uint8 resv1:4;
3896 kal_uint8 ioc:1;
3897 kal_uint8 cksum;
3898 kal_uint16 resv2;
3899 kal_uint32 nextPtr;
3900 kal_uint32 bufPtr;
3901 kal_uint8 resv3;
3902} hdma_tgpd_tt;
3903
3904typedef struct hdma_rgpd_ss {
3905 kal_uint8 hwo:1;
3906 kal_uint8 bdp:1;
3907 kal_uint8 bps:1;
3908 kal_uint8 resv1:4;
3909 kal_uint8 ioc:1;
3910 kal_uint8 cksum;
3911 kal_uint16 allowBufLen;
3912 kal_uint32 nextPtr;
3913 kal_uint32 bufPtr;
3914 kal_uint16 bufLen;
3915 kal_uint16 resv2;
3916} hdma_rgpd_tt;
3917
3918
3919// dummy_fdma() just for mt6595 workaround patch. removed on LR12.
3920/*
3921void dummy_fdma(kal_uint32 gdma_start)
3922{
3923
3924 FDMA_PDN_CLR(3);
3925 if(gdma_start == 0){
3926 DRV_WriteReg32(0xff2c0080, 0x4); // stop (GDMA_FDCR0)
3927 FDMA_PDN_SET(3);
3928 }
3929 else{
3930 DRV_WriteReg32(0xff2c0080, 0x4); // stop (GDMA_FDCR0)
3931 while(DRV_Reg32(0xff2c0014) & (1<<16)); // check done state (GDMA_FDCSR0)
3932
3933 DRV_WriteReg32(0xff2c0014, 0x02000000); // GDMA_FDCSR
3934 DRV_WriteReg32(0xff2c0084, 0xbf830C20); // GDMA_FDSAR3
3935 DRV_WriteReg32(0xff2c0088, 0xbf830C24); // GDMA_FDDAR3
3936 DRV_WriteReg32(0xff2c0080, 0xffff43a1); // start (GDMA_FDCR3)
3937 }
3938 return;
3939}
3940
3941}
3942*/
3943
3944extern UARTStruct UARTPort[];
3945extern Seriport_HANDLER_T Uart_Drv_Handler;
3946
3947enum {
3948 INIT_NOTINIT,
3949 INIT_REG_CB,
3950 INIT_DRV_ATTACH,
3951 INIT_DRV_INIT,
3952 INIT_UPMOD_INIT,
3953 INIT_SET_BAUDRATE,
3954 INIT_DONE,
3955} uart_excpt_drv_init_stage = INIT_NOTINIT;
3956kal_bool uart_excpt_drv_init_done_g = KAL_FALSE;
3957kal_bool uart_st_in_except_mode_g = KAL_FALSE;
3958
3959#if defined __UART_UT__
3960kal_int32 uart_hmu_pre_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3961{
3962 return KAL_TRUE;
3963}
3964
3965kal_int32 uart_hmu_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3966{
3967 return 0;
3968}
3969
3970kal_int32 uart_hmu_post_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3971{
3972 return KAL_TRUE;
3973}
3974
3975kal_int32 uart_hmu_pre_deinit(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3976{
3977 return KAL_TRUE;
3978}
3979
3980kal_int32 uart_hmu_deinit(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3981{
3982 return KAL_TRUE;
3983}
3984
3985kal_int32 uart_hmu_post_deinit(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3986{
3987 return KAL_TRUE;
3988}
3989
3990kal_int32 uart_hmu_except_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3991{
3992 return KAL_TRUE;
3993}
3994
3995#else
3996
3997kal_int32 uart_hmu_pre_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
3998{
3999 return KAL_TRUE;
4000}
4001
4002kal_int32 uart_hmu_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
4003{
4004
4005 return KAL_TRUE;
4006}
4007
4008kal_int32 uart_hmu_post_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
4009{
4010 return KAL_TRUE;
4011}
4012
4013kal_int32 uart_hmu_pre_deinit(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
4014{
4015 return KAL_TRUE;
4016}
4017
4018kal_int32 uart_hmu_deinit(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
4019{
4020
4021 return KAL_TRUE;
4022}
4023
4024kal_int32 uart_hmu_post_deinit(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
4025{
4026 return KAL_TRUE;
4027}
4028
4029UARTStruct* uart_core_get_instance(kal_uint32 uart_port)
4030{
4031 return &UARTPort[uart_port];
4032}
4033
4034DCL_STATUS uart_ttyhdr_reg_ttycore(UARTStruct*p_dev_inst, kal_uint32 port)
4035{
4036 DCL_STATUS status;
4037 DCL_HANDLE handle;
4038
4039 handle = DclSerialPort_Open(port, 0);
4040
4041 uart_excpt_drv_init_stage = INIT_REG_CB;
4042 status = DclSerialPort_DrvRegisterCb(handle, &Uart_Drv_Handler);
4043
4044 if (KAL_TRUE == uart_st_in_except_mode_g && STATUS_ALREADY_OPENED == status) {
4045 return STATUS_OK;
4046 }
4047 return status;
4048}
4049
4050DCL_STATUS uart_ttyhdr_cmd_init(UART_PORT port)
4051{
4052 DCL_STATUS status;
4053 DCL_HANDLE handle;
4054 DCL_CTRL_DATA_T data;
4055
4056 handle = DclSerialPort_Open(port, 0);
4057
4058 uart_excpt_drv_init_stage = INIT_DRV_ATTACH;
4059 status = DclSerialPort_DrvAttach(handle);
4060 if(status != STATUS_OK)
4061 {
4062 return STATUS_FAIL;
4063 }
4064
4065 uart_excpt_drv_init_stage = INIT_DRV_INIT;
4066 status = DclSerialPort_Control(handle, SIO_CMD_INIT, &data);
4067
4068 return status;
4069
4070}
4071
4072DCL_STATUS uart_ttyhdr_upmodule_init(UART_PORT port)
4073{
4074 DCL_STATUS status;
4075 DCL_HANDLE handle;
4076 UART_CTRL_DCB_T data;
4077
4078 handle = DclSerialPort_Open(port, 0);
4079
4080 uart_excpt_drv_init_stage = INIT_UPMOD_INIT;
4081 status = DclSerialPort_UpModuleInit(handle, MOD_DRV_DBG, TTY_FLAG_NEW_TX | TTY_FLAG_NEW_RX);
4082 if (status != STATUS_OK && status != STATUS_ALREADY_OPENED) {
4083 return status;
4084 }
4085
4086 //DclSerialPort_UpModuleRegisterCb(handle, dbg_print_tty_rx_cb, NULL, dbg_print_tty_state_cb);
4087
4088 data.u4OwenrId = MOD_DRV_DBG;
4089 data.rUARTConfig.u4Baud = UART_BAUD_1500000;
4090 data.rUARTConfig.u1DataBits = len_8;
4091 data.rUARTConfig.u1StopBits = sb_1;
4092 data.rUARTConfig.u1Parity = pa_none;
4093 data.rUARTConfig.u1FlowControl = fc_sw;
4094 data.rUARTConfig.ucXonChar = 0x11;
4095 data.rUARTConfig.ucXoffChar = 0x13;
4096 data.rUARTConfig.fgDSRCheck = KAL_FALSE;
4097
4098 // Set baudrate
4099 uart_excpt_drv_init_stage = INIT_SET_BAUDRATE;
4100 status = DclSerialPort_Control(handle, SIO_CMD_SET_DCB_CONFIG, (DCL_CTRL_DATA_T*)&data);
4101
4102 return status;
4103}
4104
4105kal_int32 uart_hmu_except_init(kal_uint32 dev_mapping, kal_uint32 ext_devinfo_len, kal_char *ext_devinfo)
4106{
4107 DCL_STATUS ret;
4108 UARTStruct* p_dev_inst;
4109 kal_uint32 uart_port;
4110 kal_uint32 init_ports[] = {uart_port1, uart_port2};
4111 kal_uint32 ret_val = 0;
4112 int i;
4113
4114 uart_st_in_except_mode_g = KAL_TRUE;
4115 if (uart_excpt_drv_init_done_g == KAL_TRUE) {
4116 return 0;
4117 }
4118
4119 for (i = 0; i < sizeof(init_ports)/sizeof(init_ports[0]); i++) {
4120 uart_port = init_ports[i];
4121
4122 p_dev_inst = uart_core_get_instance(uart_port);
4123
4124 if(p_dev_inst->initialized == KAL_TRUE){
4125 continue;
4126 }
4127
4128 ret = uart_ttyhdr_reg_ttycore(p_dev_inst, uart_port);
4129 if (STATUS_OK != ret) {
4130 ret_val = -1;
4131 continue;
4132 }
4133
4134 ret = uart_ttyhdr_cmd_init(uart_port);
4135 if (STATUS_OK != ret) {
4136 ret_val = -1;
4137 continue;
4138 }
4139 }
4140
4141 uart_excpt_drv_init_stage = INIT_DONE;
4142 uart_excpt_drv_init_done_g = KAL_TRUE;
4143
4144 return ret_val;
4145}
4146
4147#endif
4148
4149