change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8825 / sio.h
1 /******************************************************************************
2  ** File Name:      sio.h                                                     *
3  ** Author:         Richard Yang                                              *
4  ** DATE:           04/02/2002                                                *
5  ** Copyright:      2002 Spreatrum, Incoporated. All Rights Reserved.         *
6  ** Description:    This driver is for development board, Integrator/AP.      *
7  ******************************************************************************
8
9  ******************************************************************************
10  **                        Edit History                                       *
11  ** ------------------------------------------------------------------------- *
12  ** DATE           NAME             DESCRIPTION                               *
13  ** 04/02/2002     Richard.Yang     Create.                                   *
14  ** 05/13/2002     Richard.Yang     Add sio_send_packet, sio_send_log_packet  *
15  ** 05/30/2003     Eric.zhou        Add AT through channel server associated  *
16  ** functions.                                                                    *
17  ** 08/25/2003     Zhemin.Lin     Add MIX_MODE for COM_USER port, according MS00004213 *
18  ******************************************************************************/
19
20 #ifndef _SIO_H_
21 #define _SIO_H_
22
23 /**---------------------------------------------------------------------------*
24  **                         Dependencies                                      *
25  **---------------------------------------------------------------------------*/
26 #include "sci_types.h"
27 #include "com_drvapi.h"
28 #include "chip.h"
29
30
31 /**---------------------------------------------------------------------------*
32  **                         Compiler Flag                                     *
33  **---------------------------------------------------------------------------*/
34 #ifdef __cplusplus
35 extern   "C"
36 {
37 #endif
38
39 #define SIO_PPP_SUCCESS 0
40 #define SIO_PPP_FAIL    -1
41
42 #define SIO_RX_FLOW_CONTROL 0x1
43 #define SIO_TX_FLOW_CONTROL 0x2
44
45
46 /*
47     Debug port communications protocol flag.
48 */
49 #define ESCAPE_BYTE       0x7D
50 #define FLAG_BYTE         0x7E
51 #define COMPLEMENT_BYTE   0x20
52
53 /*
54     Uart/USB port definitions
55 */
56
57 #define COM0             (0)
58 #define COM1             (1)
59 #define COM2             (2)
60 #define COM3             (3)
61 #define VIR_COM0         (4)
62 #define VIR_COM1         (5)
63 #define DSK_COM0         (6)
64 #define DSK_COM1         (7)
65 /* added @eddie.li */
66 #define VIR_COM2         (8)
67 #define MAX_SIO_PORT_NUM (9)
68 /* added @eddie.li end */
69
70 #define MAX_LOGICAL_SIO_PORT_NUM  2             //'COM_DATA', 'COM_DEBUG'
71 #define SIO_ALREADY_OPEN  0x55
72
73 #define LOG_FRM_MED       0
74 #define LOG_FRM_NONE      1
75 #define LOG_FRM_END       2
76
77 #define ATC_MODE          0x01
78 #define DATA_MODE         0x02
79 #define MIX_MODE    0x03
80
81 #define COM_USER          0
82 #define COM_DATA          0
83 #define COM_DEBUG         1
84
85
86 // @Tao.Zhou, CR:MS00057325, 09/29/2006
87 /* We must send at least(FIFO_SIZE - FIFO_EMPTY - fifo_cnt) bytes during one interrupt */
88 #define FIFO_EMPTY        6
89
90 #define GET_BUF_FREE_SIZE(free_size, _buf)  \
91     if (_buf->start_point >= _buf->end_point) \
92     {\
93         free_size = (int) ((int)_buf->size - _buf->start_point + _buf->end_point - 1);\
94     }\
95     else\
96     {\
97         free_size = (int) (_buf->end_point - _buf->start_point - 1);\
98     }
99
100 #define GET_BUF_DATA_SIZE(data_size, _buf)  \
101     if (_buf->start_point >= _buf->end_point) \
102     {\
103         data_size = (int) (_buf->start_point - _buf->end_point);\
104     }\
105     else\
106     {\
107         data_size = (int) ((int)(_buf->size) + _buf->start_point - _buf->end_point);\
108     }
109
110 #if defined(PLATFORM_SC8800H) || defined(PLATFORM_SC8800G)  || defined(CONFIG_SC8810)//modified by tyler.song for compiling error.
111 #define ATC_REC_BUF_SIZE           2600
112 #else
113 #define ATC_REC_BUF_SIZE           1600
114 #endif
115
116
117 // SIO definition
118
119 typedef void *HSIO;
120 typedef struct
121 {
122     uint32  baud_rate;
123     uint8   parity;
124     uint8   stop_bits;
125     uint8   byte_size;
126     uint8   flow_control;
127 } SIO_CONTROL_S;
128
129 typedef struct
130 {
131     uint32  cbInQue;
132     uint32  cbOutQue;
133 } UARTSTAT_S, *UARTSTAT_PTR_T;
134
135 typedef void (* ATC_CALLBACK) (uint32);
136
137
138
139 /*
140     Software structures
141 */
142 typedef struct
143 {
144     uint32  size;              // Total Size of the buffer.
145     volatile int  start_point;       // First data in the buffer.
146     volatile int  end_point;         // Last data in the buffer.
147     volatile uint32  status;            // Indicate the buffer status.
148     uint32  lost_num;          //
149     uint8   *sio_buf_ptr;      // Sio buffer address.
150 } SIO_BUF_S;
151
152 typedef struct 
153 {
154     uint32 (*init) (uint32 port_num, UART_INIT_PARA_T * ,
155                     UartCallback callback);                /* drv com creat   */
156
157     uint32 (*close) (uint32 port_num);                           /* drv com close   */
158
159     uint32 (*get_fifocnt) (uint32 phy_port);                     /* get tx fifo cnt */
160
161     uint32 (*read) (uint32 port_num,uint8 *buffer,uint32 length); /* read data from drv */
162
163     uint32 (*write) (uint32 port_num,const uint8 *buffer,uint32 length); /*send data to drv*/
164
165     int32 (*get_char) (uint32 phy_port);                         /* read single char*/
166
167     void (*put_char) (uint32 phy_port, uint8 nchar);             /* send signle char*/
168
169     void (*tx_enable) (uint32 phy_port,BOOLEAN is_enable);       /* drv send enable */
170
171     void (*rx_enable) (uint32 phy_port,BOOLEAN is_enable);       /* drv receive enable*/
172
173     void (*flush) (uint32 phy_port);                             /* only useful for usb virtual com     */
174     /* flush data from local buffer to fifo*/
175 } sio_operation_st;
176
177 typedef struct
178 {
179     uint32 sio_port_index;
180     uint32 phy_port_index;
181 } SIO_PORT_CVT_T;
182
183 typedef struct
184 {
185     uint32         open_flag;
186     uint32         phy_port;
187     SIO_CONTROL_S  dcb;
188     SIO_BUF_S      tx_buf;
189     SIO_BUF_S      rx_buf;
190     SIO_BUF_S      atc_buf;
191     volatile unsigned       mdm_stat;   /* modem status at last change */
192     volatile uint32         last_tx;    // Last time for tx
193     struct   com_line      *p_line;     /* ptr to comline driver structure
194                                            no use for debug port, just for user port */
195         sio_operation_st sio_op;  /* sio operation for COM_DEBUG/COM_DATA */
196
197
198 } SIO_INFO_S;
199
200 /*
201     Functions definitions
202 */
203 /* Create a device control block.*/
204 PUBLIC HSIO SIO_Create (uint32        port,
205                         uint32        phy_port,
206                         SIO_CONTROL_S *dcb
207                        );
208 PUBLIC uint32 SIO_SetBaudRate (uint32 port, uint32 baud_rate);
209 PUBLIC uint32 SIO_GetBaudRate (uint32 port);
210 PUBLIC void SIO_SetATCBuffer (uint8 *src,uint16 length);
211 PUBLIC uint32 SIO_ChangeMode (uint32 mode);
212 PUBLIC uint32 SIO_GetMode (void);
213 PUBLIC  void  SIO_Close (uint32  port);
214 PUBLIC  void  SIO_BuildDCB (
215     uint32         port,
216     SIO_CONTROL_S  *dcb
217 );
218
219 PUBLIC SIO_INFO_S *SIO_GetPPPPort (void);
220 PUBLIC  int   SIO_ReadPPPFrame (
221     uint32 port,  // Port number COM_USER, COM_DEBUG
222     uint8  *src,            // Data to receive
223     int    size,            // MAX size to receive
224     uint32 *dest_len        // Actual size received
225 );
226
227 PUBLIC  int   SIO_WritePPPFrame (
228     uint32  port,
229     uint8   *src,
230     int     size
231 );
232
233 PUBLIC  int   SIO_FastWritePPPFrame (
234     uint32  port,
235     uint8   *src,
236     int     size
237 );
238
239 PUBLIC  int   SIO_GetChar (
240     uint32 port
241 );
242
243 PUBLIC  int   SIO_PutChar (
244     uint32  port,
245     uint8   nchar
246 );
247
248 /*****************************************************************************/
249 // Description :    this function changes userport from one mode to another,
250 //                       following mode transition can be done by this funcition:
251 //                       MIX_MODE-->ATC_MODE
252 //                       MIX_MODE-->DATA_MODE
253 //                       ATC_MODE-->MIX_MODE
254 //                       ATC_MODE-->DATA_MODE
255 // Global resource dependence :
256 // Author :         Zhemin.Lin
257 // Note :
258 /*****************************************************************************/
259 PUBLIC  uint32 SIO_SetUserPortMode (
260     uint32 mode
261 );
262 PUBLIC  uint32 SIO_ClearError (
263     uint32          port,
264     uint32          *error_ptr,
265     UARTSTAT_PTR_T  *uart_stat_ptr
266 );
267
268 PUBLIC  int    SIO_SendLogPacket (
269     uint32  *head_ptr,
270     int     head_len,
271     uint32  *body_ptr,
272     int     body_len
273 );
274
275 PUBLIC  int    SIO_SendPacket (
276     void  *src,
277     int   size
278 );
279
280 PUBLIC void SIO_ATC_SetMixMode (
281     BOOLEAN mix_enable
282 );
283
284 PUBLIC int SIO_SendFrame (
285     void *src,
286     int size
287 );
288
289 PUBLIC uint16 SIO_GetFreePPPFrameCount (void);
290
291 PUBLIC int     SIO_DumpGetChar (
292     uint32 port
293 );
294 PUBLIC void    SIO_DumpPutChar (
295     uint32 port,
296     char   nchar
297 );
298
299 PUBLIC void SIO_DumpPutCharEnd (
300     uint32 port
301 );
302
303 PUBLIC uint32  SIO_WaitEvent (
304     uint32  port,
305     uint32  *event_mask
306 );
307
308 PUBLIC void SIO_ResetBuf (
309     uint32 port
310 );
311
312 PUBLIC void SIO_ATC_ReadCmdLine (
313     uint8  *data_ptr,       // Output argument, point to the buf which is
314     // alloced by caller
315     uint   length,          // The length of cmd line which should be read from
316     // sio
317     uint   *read_length_ptr // The actual read length
318 );
319
320 PUBLIC void SIO_ATC_WriteCmdRes (
321     uint8  *res_data_ptr,  // Point to the response infomation buffer
322     uint   length          // The length of response infomation buffer
323 );
324
325  PUBLIC void SIO_ATC_ClrCmdLine (
326     void
327 );
328  
329 void SIO_ATC_SetCmdLineTerminateChar (
330     uint8 terminate_char1,   // Default terminate char is '\n'
331     uint8 terminate_char2    // Default terminate char is '\0'
332 );
333 PUBLIC void SIO_ATC_SetCmdLineBackSpaceChar (
334     uint8  back_space_char  // Default backspace char value is 8
335 );
336
337 PUBLIC void SIO_ATC_SetDataMode (BOOLEAN mode);
338 PUBLIC void SIO_ATC_SetEcho (BOOLEAN IsEcho);
339
340 PUBLIC void SIO_ATC_SetCallback (
341     ATC_CALLBACK callback
342 );
343
344 PUBLIC void SIO_BuildDCB (
345     uint32         port,
346     SIO_CONTROL_S  *dcb
347 );
348 /*sio variable extern*/
349 #define            MAX_PLUS_NUMBER   3
350 #define            MODE_CHANGE_DELAY 1000 // 1000 milliseconds
351 #define            BACKSPACE_CHAR    0x08
352 #define            END_CHAR          0x0D
353 #define            PLUS_CHAR         '+'
354
355
356 #ifdef _U0_FLOW_CONTROL
357 #define     SPACE_CHECK_DELAY       300     // time delay of space check of Rx buffer for COM_DATA
358 #define     EMPTY_SPACE_WATER_MARK  258     // empty sapce water mark of rx buffer 
359 #endif
360
361 #define     XOFF    0x13    // Xoff of Software flow control.
362 #define     XON     0x11    // Xon of Software flow control.
363 #if 0
364 #define DO_ATC_CALLBACK(len) \
365     if ( NULL == AT_callback_ind) \
366     {\
367         DefaultAtHandle(len);\
368     }\
369     else \
370     {\
371         (*AT_callback_ind)(len);\
372     }
373 #endif
374 //@Zhemin.Lin, 08/15/2003
375 /*****************************************************************************/
376 // Description :    Update clock divider value due to the change of system frequency
377 // Global resource dependence :
378 // Author :         Zhemin.Lin
379 // Note :
380 /*****************************************************************************/
381 PUBLIC void SIO_UpdateDividerValue (void);
382
383 //@Zhemin.Lin, CR:MS00004213, 08/22/2003, begin
384
385 //SIO communication error type
386 typedef enum
387 {
388     SIO_PARITY_ERROR,
389     SIO_CHECKSUM_ERROR,
390     SIO_TIMEOUT_ERROR
391 } SIO_LINK_ERROR_E;
392 typedef void (*SIO_ERROR_HANDLE) (uint32 portid, SIO_LINK_ERROR_E linkerror);
393
394 typedef enum
395 {
396     SIO_NOTIFY_READY,
397     SIO_NOTIFY_BUSY,
398     SIO_NOTIFY_STATUS
399 } SIO_NOTIFY_ID_E;
400 typedef void (*SIO_NOTIFY_HANDLE) (uint32 notify_id, uint32 param);
401
402 /*****************************************************************************/
403 // Description :    Register error handle, when sio link error,  driver will call this handle to deal
404 //                       the errors
405 // Global resource dependence :
406 // Author :         Zhemin.Lin
407 // Note :
408 /*****************************************************************************/
409 PUBLIC uint32 SIO_RegisterErrorHandle (SIO_ERROR_HANDLE errorhandle);
410
411 /*****************************************************************************/
412 // Description :    Register notify handle, under the mix mode, when sio drv receive a ready
413 //                       package or busy package or status package, it will call the notify handle
414 // Global resource dependence :
415 // Author :         Zhemin.Lin
416 // Note :
417 /*****************************************************************************/
418 PUBLIC uint32 SIO_RegisterNotifyHandle (SIO_NOTIFY_HANDLE notifyhandle);
419
420 /*****************************************************************************/
421 // Description :    Register data receive function
422 // Global resource dependence :
423 // Author :         Zhemin.Lin
424 // Note :
425 /*****************************************************************************/
426 PUBLIC uint32 SIO_RegisterDataRecvHandle (ATC_CALLBACK recvhandle);
427
428 /*****************************************************************************/
429 // Description :    under the MIX_MODE,  use this function to send data package
430 // Global resource dependence :
431 // Author :         Zhemin.Lin
432 // Note :
433 /*****************************************************************************/
434 PUBLIC uint32 SIO_SendDataPacket (uint8 *src, uint32 length);
435
436 /*****************************************************************************/
437 // Description :    under the MIX_MODE,  use this function to send status package
438 // Global resource dependence :
439 // Author :         Zhemin.Lin
440 // Note :
441 /*****************************************************************************/
442 PUBLIC uint32 SIO_SendStatusPacket (uint8 status);
443
444 /*****************************************************************************/
445 // Description :    under the MIX_MODE,  use this function to send ready package
446 // Global resource dependence :
447 // Author :         Zhemin.Lin
448 // Note :
449 /*****************************************************************************/
450 PUBLIC uint32 SIO_SendReadyPacket (void);
451
452 /*****************************************************************************/
453 // Description :    under the MIX_MODE,  use this function to send busy package
454 // Global resource dependence :
455 // Author :         Zhemin.Lin
456 // Note :
457 /*****************************************************************************/
458 PUBLIC uint32 SIO_SendBusyPacket (void);
459
460 /*****************************************************************************/
461 // Description :    this function changes userport from one mode to another,
462 //                       following mode transition can be done by this funcition:
463 //                       MIX_MODE-->ATC_MODE
464 //                       MIX_MODE-->DATA_MODE
465 //                       ATC_MODE-->MIX_MODE
466 //                       ATC_MODE-->DATA_MODE
467 // Global resource dependence :
468 // Author :         Zhemin.Lin
469 // Note :
470 /*****************************************************************************/
471 PUBLIC uint32 SIO_SetUserPortMode (uint32 mode);
472
473 /*****************************************************************************/
474 // Description :    get the mode of COM_USER port
475 // Global resource dependence :
476 // Author :         Zhemin.Lin
477 // Note :
478 /*****************************************************************************/
479 PUBLIC uint32 SIO_GetUserPortMode (void);
480
481 /*****************************************************************************/
482 // Description :    get phy port no from logical port
483 // Global resource dependence :
484 // Author :        weihua.wang
485 // Note :          uint32 port: COM_DEUBG/COM_DATA
486 /*****************************************************************************/
487 PUBLIC uint32 SIO_GetPhyPortNo (uint32 port);
488
489 /*****************************************************************************/
490 // Description :    get the mode of COM_USER port
491 // Global resource dependence :
492 // Author :         hanjun.liu
493 // Note :
494 /*****************************************************************************/
495
496 PUBLIC void SIO_SendRemainLogMessage (void);
497 //@Zhemin.Lin, CR:MS00004213, 08/22/2003, end
498
499 /*@jim.zhang CR:MS00008486 04/06/2004 */
500 /*****************************************************************************/
501 // Description :   get the mix used state for GPRS.
502 // Global resource dependence :
503 // Author :        Jim.zhang
504 // Note : return 1 means PPP and Log are mixed, 0 means not mixed.
505 /*****************************************************************************/
506 PUBLIC BOOLEAN SIO_IsPPPMixedLogel (void);
507 /* end CR:MS00008486 */
508
509 /*
510 ** Send the char of PPP out.
511 ** It's the function called by PPP.
512 */
513 PUBLIC int uart_ppp_putc (int port, uint8 ch);
514
515 /*****************************************************************************/
516 // Description :   Use the given baudrate to init the uart register.
517 //                 and can receivce/send data via it.
518 // Global resource dependence :
519 // Author :        Lin.liu
520 // Input:
521 //        port        : uart port number, UART_COM0/1
522 //        baudrate : the baudrate need to be set( 115200, 9600 etc ).
523 // Return:
524 //        None
525 // Note :
526 /*****************************************************************************/
527 PUBLIC void SIO_InitUartLowLevel (uint32 port,  uint32 baudrate);
528
529 /*****************************************************************************/
530 // Description :   get com_debug/com_data rx buffer max size;
531 // Global resource dependence :
532 // Author :
533 // Input:     COM_Port No.
534 // Return:
535 //        COM_DEBUG/Data rx buffer max size
536 // Note :
537 /*****************************************************************************/
538 PUBLIC int32 SIO_GetRxBufMaxSize (uint32 port);
539
540 /*****************************************************************************/
541 // Description :  Register COM operations to the table.
542 // Global resource dependence :
543 // Author :        eddie.li
544 // Input:
545 //
546 // Return:
547 //        None
548 // Note :
549 /*****************************************************************************/
550 PUBLIC void SIO_RegisterOpsToTab (uint32                  port,
551                                   uint32                  phy_port,
552                                   sio_operation_st ops);
553
554
555 PUBLIC uint32 SIO_PhyPortfromIndex (uint32 index);
556
557 /**---------------------------------------------------------------------------*
558  **                         Compiler Flag                                     *
559  **---------------------------------------------------------------------------*/
560 #ifdef __cplusplus
561 }
562 #endif
563
564 #endif /*End sio.h*/
565