mtk_uart.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #ifndef __MTK_UART_H__
  2. #define __MTK_UART_H__
  3. #ifndef CONFIG_OF
  4. #include <mach/mt_reg_base.h>
  5. #endif
  6. #include <mt-plat/sync_write.h>
  7. #include "platform_uart.h"
  8. /*---------------------------------------------------------------------------*/
  9. #if defined(ENABLE_VFIFO_DEBUG)
  10. /*---------------------------------------------------------------------------*/
  11. #define DGBUF_INIT(v) \
  12. do { \
  13. if (UART_DEBUG_EVT(DBG_EVT_BUF)) { \
  14. v->dbgidx = (v->dbgidx+1)%(ARRAY_SIZE(v->dbg)); \
  15. v->cur = &v->dbg[v->dbgidx]; \
  16. v->cur->idx = 0; \
  17. } \
  18. } while (0)
  19. /*---------------------------------------------------------------------------*/
  20. #define DGBUF_PUSH_CH(v, c) \
  21. do { \
  22. if (UART_DEBUG_EVT(DBG_EVT_BUF)) \
  23. v->cur->dat[v->cur->idx++] = (char)(c); \
  24. } while (0)
  25. /*---------------------------------------------------------------------------*/
  26. #define DGBUF_PUSH_STR(v, s, l) \
  27. do { \
  28. if (UART_DEBUG_EVT(DBG_EVT_BUF)) {\
  29. memcpy(&v->cur->dat[v->cur->idx], (s), (l)); \
  30. v->cur->idx += (l); \
  31. } \
  32. } while (0)
  33. #else
  34. /*---------------------------------------------------------------------------*/
  35. #define DGBUF_INIT(v)
  36. #define DGBUF_PUSH_CH(v, c)
  37. #define DGBUF_PUSH_STR(v, s, l)
  38. #endif
  39. /******************************************************************************
  40. * ENUM & STRUCT
  41. ******************************************************************************/
  42. typedef enum {
  43. UART_NON_DMA,
  44. UART_TX_DMA,
  45. UART_TX_VFIFO_DMA,
  46. UART_RX_VFIFO_DMA,
  47. } UART_DMA_TYPE;
  48. /*---------------------------------------------------------------------------*/
  49. typedef enum {
  50. UART_TX_VFIFO,
  51. UART_RX_VFIFO,
  52. UART_VFIFO_NUM
  53. } UART_VFF_TYPE;
  54. /*---------------------------------------------------------------------------*/
  55. /* uart dma mode */
  56. enum {
  57. UART_DMA_MODE_0,
  58. UART_DMA_MODE_1,
  59. };
  60. /*---------------------------------------------------------------------------*/
  61. /* flow control mode */
  62. enum {
  63. UART_FC_NONE, /*NO flow control */
  64. UART_FC_SW, /*MTK SW Flow Control, differs from Linux Flow Control */
  65. UART_FC_HW, /*HW Flow Control */
  66. };
  67. /*---------------------------------------------------------------------------*/
  68. struct mtk_uart_setting {
  69. u8 tx_mode;
  70. u8 rx_mode;
  71. u8 dma_mode;
  72. u8 sysrq;
  73. int tx_trig;
  74. int rx_trig;
  75. unsigned long uart_base;
  76. #ifdef CONFIG_OF
  77. unsigned long uart_phys_base;
  78. unsigned long irq_flags;
  79. #endif
  80. #if !defined(CONFIG_MTK_LEGACY)
  81. struct clk *clk_uart_main;
  82. #endif /* !defined(CONFIG_MTK_LEGACY) */
  83. u8 irq_num;
  84. u8 irq_sen;
  85. u8 set_bit; /*APMCU_CG_SET0 */
  86. u8 clr_bit; /*APMCU_CG_CLR0 */
  87. int pll_id;
  88. u8 hw_flow; /*support hardware flow control or not?! */
  89. u8 vff; /*support vfifo or not!? */
  90. u16 _align;
  91. };
  92. /*---------------------------------------------------------------------------*/
  93. #define C_UART_DEBUG_BUF_NUM (5)
  94. /*---------------------------------------------------------------------------*/
  95. struct mtk_uart_buf {
  96. unsigned char *dat;
  97. unsigned int idx;
  98. unsigned int len;
  99. };
  100. /*---------------------------------------------------------------------------*/
  101. struct mtk_uart_vfifo {
  102. struct mtk_uart_dma *dma; /* vfifo dma owner */
  103. /*configuration */
  104. u16 ch;
  105. u16 size;
  106. u16 trig;
  107. u16 type; /*UART_RX_VFIFO / UART_TX_VFIFO */
  108. void *base;
  109. void *port; /*only tx */
  110. void *addr;
  111. atomic_t reg_cb;
  112. atomic_t entry; /* entry count */
  113. spinlock_t iolock;
  114. struct timer_list timer; /* vfifo timer */
  115. struct hrtimer flush;
  116. dma_addr_t dmahd; /* dma handle */
  117. struct tasklet_struct flush_tasklet;
  118. struct mtk_uart_buf dbg[C_UART_DEBUG_BUF_NUM];
  119. struct mtk_uart_buf *cur;
  120. int dbgidx;
  121. unsigned int irq_id;
  122. };
  123. /*---------------------------------------------------------------------------*/
  124. struct mtk_uart_dma {
  125. struct mtk_uart *uart; /* dma uart */
  126. atomic_t free; /* dma channel free */
  127. unsigned short mode; /* dma mode */
  128. unsigned short dir; /* dma transfer direction */
  129. struct tasklet_struct tasklet; /* dma handling tasklet */
  130. struct completion done; /* dma transfer done */
  131. struct mtk_uart_vfifo *vfifo; /* dma vfifo */
  132. };
  133. /*---------------------------------------------------------------------------*/
  134. struct mtk_uart_register {
  135. unsigned int dll;
  136. unsigned int dlh;
  137. unsigned int ier;
  138. unsigned int lcr;
  139. unsigned int mcr;
  140. unsigned int fcr;
  141. unsigned int lsr;
  142. unsigned int efr;
  143. unsigned int highspeed;
  144. unsigned int sample_count;
  145. unsigned int sample_point;
  146. unsigned int fracdiv_l;
  147. unsigned int fracdiv_m;
  148. unsigned int escape_en;
  149. unsigned int guard;
  150. unsigned int rx_sel;
  151. };
  152. /*---------------------------------------------------------------------------*/
  153. struct mtk_uart {
  154. struct uart_port port;
  155. unsigned long base;
  156. int nport;
  157. unsigned int old_status;
  158. unsigned int tx_stop;
  159. unsigned int rx_stop;
  160. unsigned int ms_enable;
  161. unsigned int auto_baud;
  162. unsigned int line_status;
  163. unsigned int ignore_rx;
  164. unsigned int flow_ctrl;
  165. unsigned long pending_tx_reqs;
  166. unsigned long tx_trig; /* tx fifo trigger level */
  167. unsigned long rx_trig; /* rx fifo trigger level */
  168. unsigned long sysclk;
  169. unsigned long evt_mask;
  170. unsigned long lsr_status;
  171. int baudrate; /*current baudrate */
  172. int custom_baud; /*custom baudrate passed from serial_struct */
  173. int dma_mode;
  174. int tx_mode;
  175. int rx_mode;
  176. int fctl_mode; /*flow control */
  177. int poweron_count;
  178. int timeout_count; /*for console write */
  179. unsigned int fcr_back_up; /* FCR register is a write only register */
  180. struct mtk_uart_register registers;
  181. struct mtk_uart_dma dma_tx;
  182. struct mtk_uart_dma dma_rx;
  183. struct mtk_uart_vfifo *tx_vfifo;
  184. struct mtk_uart_vfifo *rx_vfifo;
  185. struct mtk_uart_setting *setting;
  186. unsigned int (*write_allow)(struct mtk_uart *uart);
  187. unsigned int (*read_allow)(struct mtk_uart *uart);
  188. void (*write_byte)(struct mtk_uart *uart, unsigned int byte);
  189. unsigned int (*read_byte)(struct mtk_uart *uart);
  190. unsigned int (*read_status)(struct mtk_uart *uart);
  191. };
  192. /*---------------------------------------------------------------------------*/
  193. /* fiq debugger */
  194. /*---------------------------------------------------------------------------*/
  195. struct fiq_dbg_event {
  196. u32 iir;
  197. int data;
  198. };
  199. /*---------------------------------------------------------------------------*/
  200. /* #define UART_READ8(REG) __raw_readb(REG) */
  201. /* #define UART_READ16(REG) __raw_readw(REG) */
  202. /* #define UART_READ32(REG) __raw_readl(REG) */
  203. #define UART_READ8(REG) (*(volatile unsigned char *)(REG))
  204. #define UART_READ16(REG) (*(volatile unsigned short *)(REG))
  205. #define UART_READ32(REG) (*(volatile unsigned int *)(REG))
  206. #define reg_sync_writeb(v, a) mt_reg_sync_writeb(v, a)
  207. #define reg_sync_writel(v, a) mt_reg_sync_writel(v, a)
  208. /*---------------------------------------------------------------------------*/
  209. #define UART_SET_BITS(BS, REG) ((*(volatile u32 *)(REG)) |= (u32)(BS))
  210. #define UART_CLR_BITS(BS, REG) ((*(volatile u32 *)(REG)) &= ~((u32)(BS)))
  211. /*---------------------------------------------------------------------------*/
  212. extern spinlock_t mtk_console_lock;
  213. extern struct mtk_uart *console_port;
  214. unsigned int mtk_uart_pdn_enable(char *port, int enable);
  215. extern void update_history_byte(char is_tx, int nport, unsigned char byte);
  216. extern void update_history_time(char is_tx, int nport);
  217. extern void update_history_bulk(char is_tx, int nport, unsigned char *chars, int count);
  218. #ifdef CONFIG_FIQ_DEBUGGER
  219. extern struct resource fiq_resource[];
  220. #endif /* CONFIG_FIQ_DEBUGGER */
  221. #endif /* MTK_UART_H */