tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc9630 / com_drvapi.h
1 /******************************************************************************
2  ** File Name:      com_drvapi.h                                                 *
3  ** Author:         weihua.wang                                               *
4  ** DATE:           2006-4-24                                                 *
5  ** Copyright:      2006 Spreadtrum, Incoporated. All Rights Reserved.        *
6  ** Description:    This file defines the common macro definiton and structure*
7  **                      for uart drv and usb virtual com                     *
8  ******************************************************************************
9
10  ******************************************************************************
11  **                        Edit History                                       *
12  ** --------------------------------------------------------------------------*
13  ** DATE           NAME             DESCRIPTION                               *
14  ** 25/04/2006     weihua.wang      creat                                     *
15  ** 02/09/2008     Tao.Zhou         driver arrangement                        *
16  ******************************************************************************/
17 #ifndef _COM_DRVAPI_H_
18 #define _COM_DRVAPI_H_
19
20 /**---------------------------------------------------------------------------*
21  **                         Compiler Flag                                     *
22  **---------------------------------------------------------------------------*/
23 #ifdef __cplusplus
24 extern   "C"
25 {
26 #endif
27
28 /**---------------------------------------------------------------------------*
29  **                         Macro definition                                  *
30  **---------------------------------------------------------------------------*/
31 enum{
32     UART_COM0 = 0x0,
33     UART_COM1 = 0x1,
34     UART_COM2 = 0x2,
35     UART_COM3 = 0x3
36 };
37
38 #define UART_COM0               (0)
39 #define UART_COM1               (1)
40 #define UART_COM2               (2)
41 #define UART_COM3               (3)
42
43
44 #define USB_COM0                (0)
45 #define USB_COM1                (1)
46 #define USB_MAX_NUM             (2)
47
48 #define CARD_COM0               (0)
49 #define CARD_COM1               (1)
50 #define CARDCOM_MAX_NUM         (2)
51
52 /* add for DUN COM @eddie.li */
53 #define DUN_COM                 (0)
54 #define DUN_MAX_NUM             (1)
55 /* add for DUN COM @eddie.li end */
56
57 //return sts
58 #define UART_SUCCESS            (0)
59 #define UART_FAILURE            (1)
60 #define UART_PORT_NUM_ERR       (2)
61 #define UART_PORT_REOPEN_ERR    (3)
62 #define UART_PORT_RECLOSE_ERR   (4)
63 #define UART_CALLBACK_ERR       (5)
64
65 //event type
66 #define EVENT_DATA_TO_READ      (0)
67 #define EVENT_WRITE_COMPLETE    (1)
68 #define EVENT_INIT_COMPLETE     (2)
69 #define EVENT_SHUTDOWN_COMPLETE (3)
70 #define COM_MAX_EVENT           (4)
71
72 //Baud Rate. (CLK = 12.998 MHz)
73 #define BAUD_1200               0x2A50
74 #define BAUD_2400               0x1528
75 #define BAUD_4800               0x0A94
76 #define BAUD_9600               0x054A
77 #define BAUD_19200              0x02A5
78 #define BAUD_38400              0x0152
79 #define BAUD_57600              0x00E2
80 #define BAUD_115200             0x0071
81 #define BAUD_230400             0x0038
82 #define BAUD_460800             0x001C
83 #define BAUD_921600             0x000E
84
85 //#define UART_GET_MUTEX_WAIT_TIME  500  //wait for 500ms at most
86
87 /*
88     Uart software settings
89 */
90 #define TX_WATER_MARK      8
91
92 // Set uart register directly, for debug purpose, not commend
93 #define UART0_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
94     {\
95         *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_IEN)   = (ien);\
96         *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CTL0)  = (ctl0);\
97         *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CTL1)  = (ctl1);\
98         *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CTL2)  = (ctl2);\
99         *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CLKD0) = (ckd0);\
100         *(volatile uint32 *)(ARM_UART0_BASE + ARM_UART_CLKD1) = (ckd1);\
101     }
102
103 #define UART1_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
104     {\
105         *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_IEN)   = (ien);\
106         *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CTL0)  = (ctl0);\
107         *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CTL1)  = (ctl1);\
108         *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CTL2)  = (ctl2);\
109         *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CLKD0) = (ckd0);\
110         *(volatile uint32 *)(ARM_UART1_BASE + ARM_UART_CLKD1) = (ckd1);\
111     }
112
113 #define UART2_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
114     {\
115         *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_IEN)   = (ien);\
116         *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CTL0)  = (ctl0);\
117         *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CTL1)  = (ctl1);\
118         *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CTL2)  = (ctl2);\
119         *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CLKD0) = (ckd0);\
120         *(volatile uint32 *)(ARM_UART2_BASE + ARM_UART_CLKD1) = (ckd1);\
121     }
122
123 #define UART3_QUCIKCFG(ien, ctl0, ctl1, ctl2, ckd0, ckd1)\
124     {\
125         *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_IEN)   = (ien);\
126         *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CTL0)  = (ctl0);\
127         *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CTL1)  = (ctl1);\
128         *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CTL2)  = (ctl2);\
129         *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CLKD0) = (ckd0);\
130         *(volatile uint32 *)(ARM_UART3_BASE + ARM_UART_CLKD1) = (ckd1);\
131     }
132 #if 0
133 #define UART_INIT_UART_LOWLEVEL(reg_base, baudrate) {\
134         *(volatile uint32 *)((reg_base) + ARM_UART_IEN)   = 0x00;\
135         *(volatile uint32 *)((reg_base)+ ARM_UART_CTL0)   = 0x1C;\
136         *(volatile uint32 *)((reg_base) + ARM_UART_CTL1)  = 0x00;\
137         *(volatile uint32 *)((reg_base) + ARM_UART_CLKD0) = \
138                 (CHIP_GetAPBClk() + (baudrate / 2)) / (baudrate);\
139         *(volatile uint32 *)((reg_base) + ARM_UART_CLKD1) = 0x00;\
140     }
141 #endif
142 typedef enum
143 {
144     FIVE_BITS = 0,
145     SIX_BITS,
146     SEVEN_BITS,
147     EIGHT_BITS
148 } UART_BYTE_SIZE_E;
149
150 typedef enum
151 {
152     EVEN_PARITY = 0,
153     ODD_PARITY
154 } UART_PARITY_E;
155
156 typedef enum
157 {
158     PARITY_DISABLE = 0,
159     PARITY_ENABLE
160 } UART_PARITY_SET_E;
161
162 typedef enum
163 {
164     UNUSED = 0,
165     ONE_STOP_BIT,
166     ONE_AND_HALF_BIT,
167     TWO_STOP_BIT
168 } UART_STOP_BIT_E;
169
170 typedef enum
171 {
172     NO_FLOW_CONTROL = 0,
173     HW_FLOW_CONTROL
174 } UART_FLOW_CTR_E;
175
176 /* uart deepsleep wakeup control */
177 typedef enum
178 {
179     DS_WAKEUP_DISABLE = 0,
180     DS_WAKEUP_ENABLE
181 } UART_DS_CTRL_E;
182
183 /* uart deepsleep wakeup conditon */
184 typedef enum
185 {
186     DS_WAKEUP_TYPE_START = 0,
187     DS_WAKEUP_BY_RXD     ,
188     DS_WAKEUP_BY_DSR     ,
189     DS_WAKEUP_BY_RXD_DSR ,
190     DS_WAKEUP_BY_CTS     ,
191     DS_WAKEUP_BY_CTS_RXD ,
192     DS_WAKEUP_BY_CTS_DSR ,
193     DS_WAKEUP_BY_CTS_DSR_RXD,
194     DS_WAKEUP_TYPE_MAX
195 } UART_DS_TYPE_E;
196
197 /**---------------------------------------------------------------------------*
198  **                         Global Variables                                                                                   *
199  **---------------------------------------------------------------------------*/
200 /**---------------------------------------------------------------------------*
201  **                         Constant Variables                                                                                *
202  **---------------------------------------------------------------------------*/
203
204 /**---------------------------------------------------------------------------*
205 **                         Struct definition                                                                                    *
206 **---------------------------------------------------------------------------*/
207 typedef void (*UartCallback) (uint32 event);
208
209 typedef struct
210 {
211     uint16 tx_watermark; // 0~127B
212     uint16 rx_watermark; // 0~127B
213     uint32 baud_rate;
214     UART_PARITY_E     parity;
215     UART_PARITY_SET_E parity_enable;
216     UART_BYTE_SIZE_E  byte_size;
217     UART_STOP_BIT_E   stop_bits;
218     UART_FLOW_CTR_E   flow_control;
219     UART_DS_CTRL_E    ds_wakeup_en;
220     UART_DS_TYPE_E    ds_wakeup_type;
221 } UART_INIT_PARA_T;
222
223 /**---------------------------------------------------------------------------*
224  **                         Function Prototypes                               *
225  **---------------------------------------------------------------------------*/
226
227 /*****************************************************************************/
228 //  Description:   This function initilizes uart port, configure uart
229 //                   registers, interrupt service, and register callback
230 //                   function for notifying the status of uart read and write.
231 //  Param:         uint32 port_num: usb virtual com num USB_COM0/USB_COM1
232 //                 UART_INIT_PARA_T* :include param for uart, only useful for uart
233 //                 UartCallback func :uplayer callback
234 //  Author:        xingyun.he
235 //  Note:          NONE
236 /*****************************************************************************/
237 PUBLIC uint32 UART_Initilize (uint32 port_num,
238                               UART_INIT_PARA_T *para,
239                               UartCallback func);
240
241 /*****************************************************************************/
242 //  Description:  This function close uart port
243 //  Author:       weihua.wang
244 //  Param :       uint32 port_num: usb virtual com number
245 //  Note:         NONE
246 /*****************************************************************************/
247 PUBLIC uint32 UART_Close (uint32 port_num);
248
249 /*****************************************************************************/
250 // Description :   Use the given baudrate to init the uart register.
251 //                 and can receivce/send data via it.
252 // Global resource dependence:  NONE
253 // Author :        Lin.liu
254 // Input:
255 //        uart port num: UART_COM0, UART_COM1
256 //        baudrate : the baudrate need to be set( 115200, 9600 etc ).
257 // Return:
258 //        None
259 // Note:           NONE
260 /*****************************************************************************/
261 PUBLIC void UART_InitUartLowLevel (uint32 port, uint32 baudrate);
262
263 /*****************************************************************************/
264 //  Description:  This function is used to get uart port deepsleep-awaken
265 //                function status: enable or disable
266 //  Author:       zhengjiang.lei
267 //  Param :
268 //  Note:         NONE
269 /*****************************************************************************/
270 PUBLIC BOOLEAN UARTCOM_DslpFuncSts_Get (uint32 port_num);
271
272 /*****************************************************************************/
273 // Description :   check the DSR and set the DTR to enable/disable deep sleep
274 // Global resource dependence:  NONE
275 // Author :        Jim.zhang
276 // Note :          If DSR = 1: Disable deep sleep, DTR = 1
277 //                 If DSR = 0, Enable deep sleep,  DTR = 0
278 /*****************************************************************************/
279 PUBLIC void UART_CheckDeepSleepFlag (void);
280
281 /*****************************************************************************/
282 //  Description:   This function read data from receiving buffer.It is called*
283 //                 when up layfer receives the event of "EVENT_DATA_TO_READ".*
284 //  Author:        weihua.wang                                               *
285 //  Param :        uint32 port_num : uart com number index                   *
286 //                 uint8* buffer   : des buffer header address               *
287 //                 uint32 length   : size to be read                         *
288 //  Return:        if success,return size read in effect                     *
289 //  Note:          NONE                                                      *
290 /*****************************************************************************/
291 PUBLIC uint32 UART_ReadData (uint32 port_num,
292                              uint8 *buffer,
293                              uint32 length);
294
295 /*****************************************************************************/
296 //  Description:   This function record data which will be written to        *
297 //                  tx fifo and enable tx fifo empty interrupt. The length   *
298 //                  of data should be not larger than FIFO_SIZE(127B).       *
299 //  Author:        weihua.wang                                               *
300 //  Param :        uint32 port_num : uart com number index                   *
301 //                 uint8* buffer   : src buffer header address               *
302 //                 uint32 length   : size to be writed                       *
303 //  Return:        if success,return size writed in effect                   *
304 //  Note:          NONE                                                      *
305 /*****************************************************************************/
306 PUBLIC uint32 UART_WriteData (uint32 port_num,
307                               const uint8 *buffer,
308                               uint32 length);
309
310 /*****************************************************************************/
311 //  Description:   This function record data which will be written to        *
312 //                  tx fifo and enable tx fifo empty interrupt. The length   *
313 //                  of data should be not larger than FIFO_SIZE     .       *
314 //  Author:        weihua.wang                                               *
315 //  Param :        uint32 port_num : uart com number index                   *
316 //                 uint8* buffer   : src buffer header address               *
317 //                 uint32 length   : size to be writed                       *
318 //  Return:        if success,return size writed in effect                   *
319 //  Note:          NONE                                                      *
320 /*****************************************************************************/
321 PUBLIC uint32 UART_WriteDataEx (uint32 port_num,
322                                 const uint8 *buffer,
323                                 uint32 length,
324                                 BOOLEAN irq_en);
325 /*****************************************************************************/
326 //  Description:   This function get char from uart receive register.        *
327 //  Author:        xingyun.he                                                *
328 //  Return value:  Returns a char from uart receive register.                *
329 //  Note:          return -1 indicates that no char received from fifo       *
330 /*****************************************************************************/
331 PUBLIC int32 UART_DumpGetChar (uint32 phy_port);
332
333 /*****************************************************************************/
334 //  Description:   This function put a char to the uart send register.       *
335 //  Author:        xingyun.he                                                *
336 //  Return value:  put a char from uart receive register.                    *
337 //  Note:          NONE                                                      *
338 /*****************************************************************************/
339 PUBLIC void UART_DumpPutChar (uint32 phy_port, uint8 nchar);
340
341 /*****************************************************************************/
342 //  Description:   This function read data in sync mode.                     *
343 //  Author:        Tao.Zhou                                                  *
344 //  Return value:  Returns a char from uart receive register.                *
345 //  Note:          return -1 indicates that no char received from fifo       *
346 /*****************************************************************************/
347 PUBLIC uint32 UART_ReadDataSync (uint32 port_num, uint8 *buffer, uint32 length);
348
349 /*****************************************************************************/
350 //  Description:   This function write data in sync mode.                    *
351 //  Author:        Tao.Zhou                                                  *
352 //  Return value:  put a char from uart receive register.                    *
353 //  Note:          NONE                                                      *
354 /*****************************************************************************/
355 PUBLIC void UART_WriteDataSync (uint32 port_num, const uint8 *buffer, uint32 length);
356
357
358 /*****************************************************************************/
359 //  Description:   This function set uart speed                              *
360 //  Author:        xingyun.he                                                *
361 //  Note:          NONE                                                      *
362 /*****************************************************************************/
363 PUBLIC void UART_SetBaudSpeed (uint32 port_num, uint32 speed);
364
365
366 /*****************************************************************************/
367 //  Description:   This function set uart parity parameter                   *
368 //  Global resource dependence : NONE                                        *
369 //  Author:        Tao.Zhou                                                  *
370 //  Note:          NONE                                                      *
371 /*****************************************************************************/
372 PUBLIC void UART_SetParity (uint32 port_num, UART_PARITY_E parity);
373
374
375 /*****************************************************************************/
376 //  Description:   uart parity enable/disable                                *
377 //  Global resource dependence : NONE                                        *
378 //  Author:        Tao.Zhou                                                  *
379 //  Note:          NONE                                                      *
380 /*****************************************************************************/
381 PUBLIC void UART_ParityEnable (uint32 port_num, UART_PARITY_SET_E is_enable);
382
383
384 /*****************************************************************************/
385 //  Description:   This function set uart byte size                          *
386 //  Global resource dependence : NONE                                        *
387 //  Author:        Tao.Zhou                                                  *
388 //  Note:          NONE                                                      *
389 /*****************************************************************************/
390 PUBLIC void UART_SetByteSize (uint32 port_num, UART_BYTE_SIZE_E byte_size);
391
392 /*****************************************************************************/
393 //  Description:   This function set uart stop bits                          *
394 //  Global resource dependence : NONE                                        *
395 //  Author:        Tao.Zhou                                                  *
396 //  Note:          NONE                                                      *
397 /*****************************************************************************/
398 PUBLIC void UART_SetStopBits (uint32 port_num, UART_STOP_BIT_E stop_bits);
399
400
401 /*****************************************************************************/
402 //  Description:   This function set uart tx water mark                      *
403 //  Global resource dependence : NONE                                        *
404 //  Author:        Tao.Zhou                                                  *
405 //  Note:          NONE                                                      *
406 /*****************************************************************************/
407 PUBLIC void UART_SetTxWaterMark (uint32 port_num, uint16 tx_watermark);
408
409 /*****************************************************************************/
410 //  Description:   This function set uart rx water mark                      *
411 //  Global resource dependence : NONE                                        *
412 //  Author:        Tao.Zhou                                                  *
413 //  Note:          NONE                                                      *
414 /*****************************************************************************/
415 PUBLIC void UART_SetRxWaterMark (uint32 port_num, uint16 rx_watermark);
416
417 /*****************************************************************************/
418 //  Description:    return the available size in uart fifo
419 //  Global resource dependence:  NONE
420 //  Author:         weihua.wang
421 //  Param   :       uint32 port_num: usb virtual com number
422 //  Note:           NONE
423 /*****************************************************************************/
424 PUBLIC uint32 UART_GetTxFifoCnt (uint32 phy_port);
425
426 /*****************************************************************************/
427 //  Description:    return the Tx fifo is busy or idle
428 //  Global resource dependence:  NONE
429 //  Author  :       Jeff.Li
430 //  Param   :       uint32 port_num: usb virtual com number
431 //  Return  :       1 - busy, 0 - idle
432 //  Note:           This interface is just for 8801H platform currently
433 /*****************************************************************************/
434 PUBLIC BOOLEAN UART_IsTxFifoBusy (uint32 phy_port);
435
436 //@David.Jia 2007.7.4  cr82866 begin
437 /*****************************************************************************/
438 //  Description:    return the received bytes in uart fifo
439 //  Global resource dependence:  NONE
440 //  Author:         David.Jia
441 //  Param   :       uint32 port_num: com number
442 //  Note:           NONE
443 /*****************************************************************************/
444 PUBLIC uint32 UART_GetRxFifoCnt (uint32 phy_port);
445 //@David.Jia 2007.7.4  cr82866 end
446
447 /*****************************************************************************/
448 //  Description:   uart hardware flow control enable/disable                 *
449 //  Global resource dependence : NONE                                        *
450 //  Author:        Tao.Zhou                                                  *
451 //  Note:          NONE                                                      *
452 /*****************************************************************************/
453 PUBLIC void UART_FlowCtlEnable (uint32 port_num, UART_FLOW_CTR_E is_enable);
454
455 /*****************************************************************************/
456 //  Description:   uart fifo control by DAM enable/disable                   *
457 //  Global resource dependence : NONE                                        *
458 //  Author:        Tao.Zhou                                                  *
459 //  Note:          NONE                                                      *
460 /*****************************************************************************/
461 PUBLIC void UART_DmaModeEnable (uint32 port_num, BOOLEAN is_enable);
462
463 /*****************************************************************************/
464 //  Description:    uart tx empty enable/disable
465 //  Global resource dependence:  NONE
466 //  Author:         weihua.wang
467 //  Param   :       uint32 port_num: usb virtual com number
468 //                  BOOLEAN is_enable: TRUE/FALSE
469 //  Note:           NONE
470 /*****************************************************************************/
471 PUBLIC void UART_Tx_Int_Enable (uint32 phy_port, BOOLEAN is_enable);
472
473 /*****************************************************************************/
474 //  Description:    uart rx full enable/disable
475 //  Global resource dependence:  NONE
476 //  Author:         weihua.wang
477 //  Param   :       uint32 port_num: usb virtual com number
478 //                  BOOLEAN is_enable: TRUE/FALSE
479 //  Note:           NONE
480 /*****************************************************************************/
481 PUBLIC void UART_Rx_Int_Enable (uint32 phy_port, BOOLEAN is_enable);
482
483 /*****************************************************************************/
484 //  Description:   enable/disable self loop mode                             *
485 //  Global resource dependence : NONE                                        *
486 //  Author:        Tao.Zhou                                                  *
487 //  Note:          NONE                                                      *
488 /*****************************************************************************/
489 PUBLIC void UART_SelfLoopEnable (uint32 phy_port, BOOLEAN is_enable);
490
491 /*****************************************************************************/
492 //  Description:   uart callback function register                           *
493 //  Global resource dependence : NONE                                        *
494 //  Author:        Tao.Zhou                                                  *
495 //  Note:          NONE                                                      *
496 /*****************************************************************************/
497 PUBLIC void UART_RegCallBack (uint32 port_num, UartCallback func);
498
499 /*****************************************************************************/
500 //  Description:   uart callback function unregister                         *
501 //  Global resource dependence : NONE                                        *
502 //  Author:        Tao.Zhou                                                  *
503 //  Note:          NONE                                                      *
504 /*****************************************************************************/
505 PUBLIC void UART_UnRegCallBack (uint32 port_num);
506
507 /*****************************************************************************/
508 //  Description:   uart dma mode writing                                     *
509 //  Global resource dependence : NONE                                        *
510 //  Author:        Tao.Zhou                                                  *
511 //  Note:          NONE                                                      *
512 /*****************************************************************************/
513 PUBLIC void UART_DmaWriteData (uint32 port_num, const uint8 *buffer, uint32 length);
514 //PUBLIC uint32 UART_WriteData(uint32 port_num, const uint8* buffer, uint32 length);
515
516 /*****************************************************************************/
517 //  Description:   get the max number of UART
518 //  Global resource dependence : NONE
519 //  Author:        hanjun.liu
520 //  Note:          NONE
521 /*****************************************************************************/
522 PUBLIC uint32 UART_MaxPortNum (void);
523
524 /*****************************************************************************/
525 //  Description:   get the  of UART
526 //  Global resource dependence : NONE
527 //  Author:        hanjun.liu
528 //  Note:          NONE
529 /*****************************************************************************/
530 PUBLIC uint32 UART_RxWaterMark (void);
531
532 PUBLIC void DSPLogUARTSwitchOn (void);
533 PUBLIC void DSPLogUARTSwitchOff (void);
534
535 uint32 GetUART0BaseAddr (void);
536
537 uint32 getRMUartBaseAddr (void);
538 /**---------------------------------------------------------------------------*
539  **                         Compiler Flag                                     *
540  **---------------------------------------------------------------------------*/
541 #ifdef __cplusplus
542 }
543 #endif
544
545 #endif //ยข_COM_DRVAPI_H_