platform_uart.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. #ifndef __MTK_PLAT_UART_H__
  2. #define __MTK_PLAT_UART_H__
  3. #include <asm/irq.h>
  4. #include <linux/irq.h>
  5. #if !defined(CONFIG_MTK_CLKMGR)
  6. #include <linux/clk.h>
  7. #endif /* !defined(CONFIG_MTK_CLKMGR) */
  8. #include <linux/pinctrl/consumer.h>
  9. /******************************************************************************
  10. * Function Configuration
  11. ******************************************************************************/
  12. #define ENABLE_DEBUG
  13. #define ENABLE_VFIFO
  14. /* Fix-me: marked for early porting */
  15. #define POWER_FEATURE /*control power-on/power-off */
  16. #define ENABLE_FRACTIONAL
  17. #define ENABLE_SYSFS
  18. /* #define UART_USING_FIX_CLK_ENABLE */
  19. #define UART_FCR_USING_SW_BACK_UP
  20. #define ENABLE_UART_SLEEP
  21. /*---------------------------------------------------------------------------*/
  22. #if defined(WMT_PLAT_ALPS)
  23. #define ENABLE_RAW_DATA_DUMP
  24. #endif
  25. /*---------------------------------------------------------------------------*/
  26. #if defined(ENABLE_VFIFO) && defined(ENABLE_DEBUG)
  27. #define ENABLE_VFIFO_DEBUG
  28. #endif
  29. /******************************************************************************
  30. * MACRO & CONSTANT
  31. ******************************************************************************/
  32. #define DBG_TAG "[UART] "
  33. #define CFG_UART_AUTOBAUD 0
  34. /*---------------------------------------------------------------------------*/
  35. #define UART_VFIFO_SIZE 8192
  36. #define UART_VFIFO_ALERT_LEN 0x3f
  37. /*---------------------------------------------------------------------------*/
  38. #define UART_MAX_TX_PENDING 1024
  39. /*---------------------------------------------------------------------------*/
  40. #define UART_MAJOR 204
  41. #define UART_MINOR 209
  42. #ifdef CONFIG_ARCH_MT6735M
  43. #define CONFIG_VERSION_D2
  44. #endif /* CONFIG_ARCH_MT6735M */
  45. #if defined(CONFIG_MTK_FPGA)
  46. #define UART_NR 2
  47. #else
  48. #ifndef CONFIG_VERSION_D2
  49. #define UART_NR 5
  50. #else /* CONFIG_VERSION_D2 */
  51. #define UART_NR 4
  52. #endif /* CONFIG_VERSION_D2 */
  53. #endif
  54. #ifndef FALSE
  55. #define FALSE (0)
  56. #endif
  57. #ifndef TRUE
  58. #define TRUE (1)
  59. #endif
  60. /*---------------------------------------------------------------------------*/
  61. #define WAIT_UART_ACK_TIMES 10
  62. /*---------------------------------------------------------------------------*/
  63. #define IRQF_LEVEL_TRIGGER_POLARITY IRQF_TRIGGER_LOW
  64. #define IRQF_EDGE_TRIGGER_POLARITY IRQF_TRIGGER_FALLING
  65. /*---- Macro defination remap -----------------------------------------------*/
  66. /*------ IRQ Section -----------------------*/
  67. #ifndef CONFIG_OF
  68. #define UART1_IRQ_ID UART0_IRQ_BIT_ID
  69. #define UART2_IRQ_ID UART1_IRQ_BIT_ID
  70. #define UART3_IRQ_ID UART2_IRQ_BIT_ID
  71. #define UART4_IRQ_ID UART3_IRQ_BIT_ID
  72. #ifndef CONFIG_VERSION_D2
  73. #define UART5_IRQ_ID UART4_IRQ_BIT_ID
  74. #endif /* CONFIG_VERSION_D2 */
  75. #define UART1_VFF_TX_IRQ_ID AP_DMA_UART0_TX_IRQ_BIT_ID
  76. #define UART1_VFF_RX_IRQ_ID AP_DMA_UART0_RX_IRQ_BIT_ID
  77. #define UART2_VFF_TX_IRQ_ID AP_DMA_UART1_TX_IRQ_BIT_ID
  78. #define UART2_VFF_RX_IRQ_ID AP_DMA_UART1_RX_IRQ_BIT_ID
  79. #define UART3_VFF_TX_IRQ_ID AP_DMA_UART2_TX_IRQ_BIT_ID
  80. #define UART3_VFF_RX_IRQ_ID AP_DMA_UART2_RX_IRQ_BIT_ID
  81. #define UART4_VFF_TX_IRQ_ID AP_DMA_UART3_TX_IRQ_BIT_ID
  82. #define UART4_VFF_RX_IRQ_ID AP_DMA_UART3_RX_IRQ_BIT_ID
  83. #ifndef CONFIG_VERSION_D2
  84. #define UART5_VFF_TX_IRQ_ID AP_DMA_UART4_TX_IRQ_BIT_ID
  85. #define UART5_VFF_RX_IRQ_ID AP_DMA_UART4_RX_IRQ_BIT_ID
  86. #endif /* CONFIG_VERSION_D2 */
  87. #endif
  88. /*------ PDN Section -----------------------*/
  89. #if defined(CONFIG_MTK_CLKMGR) && !defined(CONFIG_MTK_FPGA)
  90. #define PDN_FOR_UART1 MT_CG_PERI_UART0
  91. #define PDN_FOR_UART2 MT_CG_PERI_UART1
  92. #define PDN_FOR_UART3 MT_CG_PERI_UART2
  93. #define PDN_FOR_UART4 MT_CG_PERI_UART3
  94. #ifndef CONFIG_VERSION_D2
  95. #define PDN_FOR_UART5 MT_CG_PERI_UART4
  96. #endif /* CONFIG_VERSION_D2 */
  97. #define PDN_FOR_DMA MT_CG_PERI_APDMA
  98. #endif /* defined(CONFIG_MTK_CLKMGR) && !defined(CONFIG_MTK_FPGA) */
  99. #if (defined(CONFIG_FIQ_DEBUGGER_CONSOLE) && defined(CONFIG_FIQ_DEBUGGER))
  100. #define DEFAULT_FIQ_UART_PORT (3)
  101. #endif
  102. /* For ATE factory feature */
  103. #ifdef ATE_FACTORY_ENABLE
  104. #define ATE_FACTORY_MODE 6
  105. #endif
  106. /*---------------------------------------------------------------------------*/
  107. #define MTK_SYSCLK_65 65000000
  108. #define MTK_SYSCLK_49_4 49400000
  109. #define MTK_SYSCLK_58_5 58500000
  110. #define MTK_SYSCLK_52 52000000
  111. #define MTK_SYSCLK_26 26000000
  112. #define MTK_SYSCLK_13 13000000
  113. #define MTK_SYSCLK_6144 61440000
  114. #define MTK_SYSCLK_3072 30720000
  115. #define MTK_SYSCLK_1536 15360000
  116. /*---------------------------------------------------------------------------*/
  117. /* FIXME: MT6593 FPGA porting*/
  118. #ifdef CONFIG_MTK_FPGA
  119. #ifdef FIX_TO_26M
  120. #define UART_SYSCLK MTK_SYSCLK_26
  121. #else
  122. #define UART_SYSCLK 12000000
  123. #endif
  124. #else
  125. #define UART_SYSCLK MTK_SYSCLK_26
  126. #endif
  127. /*---------------------------------------------------------------------------*/
  128. #define ISWEXT (0x80000000) /* extended bit in c_iflag */
  129. /*---------------------------------------------------------------------------*/
  130. /* the size definition of VFF */
  131. #define C_UART1_VFF_TX_SIZE (1024) /* the size must be 8-byte alignment */
  132. #define C_UART1_VFF_RX_SIZE (1024) /* the size must be 8-byte alignment */
  133. #define C_UART2_VFF_TX_SIZE (8192) /* the size must be 8-byte alignment */
  134. #define C_UART2_VFF_RX_SIZE (8192) /* the size must be 8-byte alignment */
  135. #define C_UART3_VFF_TX_SIZE (8192) /* the size must be 8-byte alignment */
  136. #define C_UART3_VFF_RX_SIZE (8192) /* the size must be 8-byte alignment */
  137. #define C_UART4_VFF_TX_SIZE (1024) /* the size must be 8-byte alignment */
  138. #define C_UART4_VFF_RX_SIZE (1024) /* the size must be 8-byte alignment */
  139. #ifndef CONFIG_VERSION_D2
  140. #define C_UART5_VFF_TX_SIZE (1024) /* the size must be 8-byte alignment */
  141. #define C_UART5_VFF_RX_SIZE (1024) /* the size must be 8-byte alignment */
  142. #endif /* CONFIG_VERSION_D2 */
  143. /******************************************************************************
  144. * LOG SETTING
  145. ******************************************************************************/
  146. /* Debug message event */
  147. #define DBG_EVT_NONE 0x00000000 /* No event */
  148. #define DBG_EVT_DMA 0x00000001 /* DMA related event */
  149. #define DBG_EVT_INT 0x00000002 /* UART INT event */
  150. #define DBG_EVT_CFG 0x00000004 /* UART CFG event */
  151. #define DBG_EVT_FUC 0x00000008 /* Function event */
  152. #define DBG_EVT_INFO 0x00000010 /* information event */
  153. #define DBG_EVT_ERR 0x00000020 /* Error event */
  154. #define DBG_EVT_DAT 0x00000040 /* data dump to uart */
  155. #define DBG_EVT_BUF 0x00000080 /* data dump to buffer */
  156. #define DBG_EVT_MSC 0x00000100 /* misc log */
  157. #define DBG_EVT_ALL 0xffffffff
  158. /*---------------------------------------------------------------------------*/
  159. #ifdef ENABLE_DEBUG
  160. /*---------------------------------------------------------------------------*/
  161. #define MSG(evt, fmt, args...) \
  162. do { \
  163. if ((DBG_EVT_##evt) & uart->evt_mask) { \
  164. const char *s = #evt; \
  165. if (DBG_EVT_##evt & DBG_EVT_ERR) \
  166. pr_err(" [UART%d]:%c:%4d: " fmt , \
  167. uart->nport, s[0], __LINE__, ##args); \
  168. else \
  169. pr_notice(" [UART%d]:%c: " fmt , uart->nport, s[0], ##args); \
  170. } \
  171. } while (0)
  172. /*---------------------------------------------------------------------------*/
  173. #define UART_DEBUG_EVT(evt) ((evt) & uart->evt_mask)
  174. /*---------------------------------------------------------------------------*/
  175. #define MSG_FUNC_ENTRY(f) MSG(FUC, "%s\n", __func__)
  176. #define MSG_RAW pr_notice
  177. /*---------------------------------------------------------------------------*/
  178. #else /* release mode: only enable error log */
  179. #define MSG(evt, fmt, args...) MSG##evt(fmt, ##args)
  180. #define MSGERR(fmt, args...) pr_err(" [UART%d]:E:%4d: " fmt, uart->nport, __LINE__, ##args)
  181. #define MSGDMA(fmt, args...)
  182. #define MSGCFG(fmt, args...)
  183. #define MSGFUC(fmt, args...)
  184. #define MSGINFO(fmt, args...)
  185. #define MSGDAT(fmt, args...)
  186. #define MSGMSC(fmt, args...)
  187. #define MSG_RAW(fmt, args...)
  188. #define MSG_FUNC_ENTRY(f) do {} while (0)
  189. #endif /**/
  190. #define MSG_ERR(fmt, args...) pr_err("[UARTX]:E:%4d: " fmt, __LINE__, ##args)
  191. #define MSG_TRC(fmt, args...) pr_notice("[UARTX]:T: " fmt, ##args)
  192. #define DEV_TRC(fmt, args...) pr_notice("[UART%d]:T: " fmt, uart->nport, ##args)
  193. #define DEV_ERR(fmt, args...) pr_err("[UART%d]:E: " fmt, uart->nport, ##args)
  194. /*---------------------------------------------------------------------------*/
  195. #define DRV_NAME "mtk-uart"
  196. /*---------------------------------------------------------------------------*/
  197. /******************************************************************************
  198. * ENUM & STRUCT
  199. ******************************************************************************/
  200. /* uart port ids */
  201. enum {
  202. UART_PORT0 = 0,
  203. UART_PORT1,
  204. UART_PORT2,
  205. UART_PORT3,
  206. #ifndef CONFIG_VERSION_D2
  207. UART_PORT4,
  208. #endif /* CONFIG_VERSION_D2 */
  209. UART_PORT_NUM,
  210. };
  211. /*---------------------------------------------------------------------------*/
  212. #define UART_FIFO_SIZE (16)
  213. /*---------------------------------------------------------------------------*/
  214. #define UART_RBR (unsigned long)(base+0x00) /* Read only */
  215. #define UART_THR (unsigned long)(base+0x00) /* Write only */
  216. #define UART_IER (unsigned long)(base+0x04)
  217. #define UART_IIR (unsigned long)(base+0x08) /* Read only */
  218. #define UART_FCR (unsigned long)(base+0x08) /* Write only */
  219. #define UART_LCR (unsigned long)(base+0x0c)
  220. #define UART_MCR (unsigned long)(base+0x10)
  221. #define UART_LSR (unsigned long)(base+0x14)
  222. #define UART_MSR (unsigned long)(base+0x18)
  223. #define UART_SCR (unsigned long)(base+0x1c)
  224. #define UART_DLL (unsigned long)(base+0x00) /* Only when LCR.DLAB = 1 */
  225. #define UART_DLH (unsigned long)(base+0x04) /* Only when LCR.DLAB = 1 */
  226. #define UART_EFR (unsigned long)(base+0x08) /* Only when LCR = 0xbf */
  227. #define UART_XON1 (unsigned long)(base+0x10) /* Only when LCR = 0xbf */
  228. #define UART_XON2 (unsigned long)(base+0x14) /* Only when LCR = 0xbf */
  229. #define UART_XOFF1 (unsigned long)(base+0x18) /* Only when LCR = 0xbf */
  230. #define UART_XOFF2 (unsigned long)(base+0x1c) /* Only when LCR = 0xbf */
  231. #define UART_AUTOBAUD_EN (unsigned long)(base+0x20)
  232. #define UART_HIGHSPEED (unsigned long)(base+0x24)
  233. #define UART_SAMPLE_COUNT (unsigned long)(base+0x28)
  234. #define UART_SAMPLE_POINT (unsigned long)(base+0x2c)
  235. #define UART_AUTOBAUD_REG (unsigned long)(base+0x30)
  236. #define UART_RATE_FIX_AD (unsigned long)(base+0x34)
  237. #define UART_AUTOBAUD_SAMPLE (unsigned long)(base+0x38)
  238. #define UART_GUARD (unsigned long)(base+0x3c)
  239. #define UART_ESCAPE_DAT (unsigned long)(base+0x40)
  240. #define UART_ESCAPE_EN (unsigned long)(base+0x44)
  241. #define UART_SLEEP_EN (unsigned long)(base+0x48)
  242. #define UART_DMA_EN (unsigned long)(base+0x4c)
  243. #define UART_RXTRI_AD (unsigned long)(base+0x50)
  244. #define UART_FRACDIV_L (unsigned long)(base+0x54)
  245. #define UART_FRACDIV_M (unsigned long)(base+0x58)
  246. #define UART_FCR_RD (unsigned long)(base+0x5C)
  247. #define UART_ACTIVE_EN (unsigned long)(base+0x60)
  248. #define UART_RX_SEL (unsigned long)(base+0xB0)
  249. #define UART_SLEEP_REQ (unsigned long)(base+0xB4)
  250. #define UART_SLEEP_ACK (unsigned long)(base+0xB8)
  251. /* system level, not related to hardware */
  252. #define UST_DUMMY_READ (1 << 31)
  253. /*---------------------------------------------------------------------------*/
  254. /* For MT6589, both RX and TX will not use port to send or receive data */
  255. /* IER */
  256. #define UART_IER_ERBFI (1 << 0) /* RX buffer conatins data int. */
  257. #define UART_IER_ETBEI (1 << 1) /* TX FIFO threshold trigger int. */
  258. #define UART_IER_ELSI (1 << 2) /* BE, FE, PE, or OE int. */
  259. #define UART_IER_EDSSI (1 << 3) /* CTS change (DCTS) int. */
  260. /* When set "1", enable flow control triggered by RX FIFO full when VFIFO_EN is set. */
  261. #define UART_IER_VFF_FC_EN (1 << 4)
  262. #define UART_IER_XOFFI (1 << 5)
  263. #define UART_IER_RTSI (1 << 6)
  264. #define UART_IER_CTSI (1 << 7)
  265. #define UART_IER_ALL_INTS (UART_IER_ERBFI|UART_IER_ETBEI|UART_IER_ELSI|\
  266. UART_IER_EDSSI|UART_IER_XOFFI|UART_IER_RTSI|\
  267. UART_IER_CTSI)
  268. #define UART_IER_HW_NORMALINTS (UART_IER_ERBFI|UART_IER_ELSI|UART_IER_EDSSI|UART_IER_VFF_FC_EN)
  269. #define UART_IER_HW_ALLINTS (UART_IER_ERBFI|UART_IER_ETBEI| \
  270. UART_IER_ELSI|UART_IER_EDSSI)
  271. /*---------------------------------------------------------------------------*/
  272. /* FCR */
  273. #define UART_FCR_FIFOE (1 << 0)
  274. #define UART_FCR_CLRR (1 << 1)
  275. #define UART_FCR_CLRT (1 << 2)
  276. #define UART_FCR_DMA1 (1 << 3)
  277. #define UART_FCR_RXFIFO_1B_TRI (0 << 6)
  278. #define UART_FCR_RXFIFO_6B_TRI (1 << 6)
  279. #define UART_FCR_RXFIFO_12B_TRI (2 << 6)
  280. #define UART_FCR_RXFIFO_RX_TRI (3 << 6)
  281. #define UART_FCR_TXFIFO_1B_TRI (0 << 4)
  282. #define UART_FCR_TXFIFO_4B_TRI (1 << 4)
  283. #define UART_FCR_TXFIFO_8B_TRI (2 << 4)
  284. #define UART_FCR_TXFIFO_14B_TRI (3 << 4)
  285. #define UART_FCR_FIFO_INIT (UART_FCR_FIFOE|UART_FCR_CLRR|UART_FCR_CLRT)
  286. #define UART_FCR_NORMAL (UART_FCR_FIFO_INIT | \
  287. UART_FCR_TXFIFO_4B_TRI| \
  288. UART_FCR_RXFIFO_12B_TRI)
  289. /*---------------------------------------------------------------------------*/
  290. /* LCR */
  291. #define UART_LCR_BREAK (1 << 6)
  292. #define UART_LCR_DLAB (1 << 7)
  293. #define UART_WLS_5 (0 << 0)
  294. #define UART_WLS_6 (1 << 0)
  295. #define UART_WLS_7 (2 << 0)
  296. #define UART_WLS_8 (3 << 0)
  297. #define UART_WLS_MASK (3 << 0)
  298. #define UART_1_STOP (0 << 2)
  299. #define UART_2_STOP (1 << 2)
  300. #define UART_1_5_STOP (1 << 2) /* Only when WLS=5 */
  301. #define UART_STOP_MASK (1 << 2)
  302. #define UART_NONE_PARITY (0 << 3)
  303. #define UART_ODD_PARITY (0x1 << 3)
  304. #define UART_EVEN_PARITY (0x3 << 3)
  305. #define UART_MARK_PARITY (0x5 << 3)
  306. #define UART_SPACE_PARITY (0x7 << 3)
  307. #define UART_PARITY_MASK (0x7 << 3)
  308. /*---------------------------------------------------------------------------*/
  309. /* MCR */
  310. #define UART_MCR_DTR (1 << 0)
  311. #define UART_MCR_RTS (1 << 1)
  312. #define UART_MCR_OUT1 (1 << 2)
  313. #define UART_MCR_OUT2 (1 << 3)
  314. #define UART_MCR_LOOP (1 << 4)
  315. #define UART_MCR_DCM_EN (1 << 5) /* MT6589 move to bit5 */
  316. #define UART_MCR_XOFF (1 << 7) /* read only */
  317. #define UART_MCR_NORMAL (UART_MCR_DTR|UART_MCR_RTS)
  318. /*---------------------------------------------------------------------------*/
  319. /* LSR */
  320. #define UART_LSR_DR (1 << 0)
  321. #define UART_LSR_OE (1 << 1)
  322. #define UART_LSR_PE (1 << 2)
  323. #define UART_LSR_FE (1 << 3)
  324. #define UART_LSR_BI (1 << 4)
  325. #define UART_LSR_THRE (1 << 5)
  326. #define UART_LSR_TEMT (1 << 6)
  327. #define UART_LSR_FIFOERR (1 << 7)
  328. /*---------------------------------------------------------------------------*/
  329. /* MSR */
  330. #define UART_MSR_DCTS (1 << 0)
  331. #define UART_MSR_DDSR (1 << 1)
  332. #define UART_MSR_TERI (1 << 2)
  333. #define UART_MSR_DDCD (1 << 3)
  334. #define UART_MSR_CTS (1 << 4)
  335. #define UART_MSR_DSR (1 << 5)
  336. #define UART_MSR_RI (1 << 6)
  337. #define UART_MSR_DCD (1 << 7)
  338. /*---------------------------------------------------------------------------*/
  339. /* EFR */
  340. #define UART_EFR_EN (1 << 4)
  341. #define UART_EFR_AUTO_RTS (1 << 6)
  342. #define UART_EFR_AUTO_CTS (1 << 7)
  343. #define UART_EFR_SW_CTRL_MASK (0xf << 0)
  344. #define UART_EFR_NO_SW_CTRL (0)
  345. #define UART_EFR_NO_FLOW_CTRL (0)
  346. #define UART_EFR_AUTO_RTSCTS (UART_EFR_AUTO_RTS|UART_EFR_AUTO_CTS)
  347. #define UART_EFR_XON1_XOFF1 (0xa) /* TX/RX XON1/XOFF1 flow control */
  348. #define UART_EFR_XON2_XOFF2 (0x5) /* TX/RX XON2/XOFF2 flow control */
  349. #define UART_EFR_XON12_XOFF12 (0xf) /* TX/RX XON1,2/XOFF1,2 flow control */
  350. #define UART_EFR_XON1_XOFF1_MASK (0xa)
  351. #define UART_EFR_XON2_XOFF2_MASK (0x5)
  352. /*---------------------------------------------------------------------------*/
  353. /* IIR (Read Only) */
  354. #define UART_IIR_NO_INT_PENDING (0x01)
  355. #define UART_IIR_RLS (0x06) /* Receiver Line Status */
  356. #define UART_IIR_RDA (0x04) /* Receive Data Available */
  357. #define UART_IIR_CTI (0x0C) /* Character Timeout Indicator */
  358. #define UART_IIR_THRE (0x02) /* Transmit Holding Register Empty */
  359. #define UART_IIR_MS (0x00) /* Check Modem Status Register */
  360. #define UART_IIR_SW_FLOW_CTRL (0x10) /* Receive XOFF characters */
  361. #define UART_IIR_HW_FLOW_CTRL (0x20) /* CTS or RTS Rising Edge */
  362. #define UART_IIR_FIFO_EN (0xc0)
  363. #define UART_IIR_INT_MASK (0x3f)
  364. /*---------------------------------------------------------------------------*/
  365. /* RateFix */
  366. #define UART_RATE_FIX (1 << 0)
  367. /* #define UART_AUTORATE_FIX (1 << 1) */
  368. #define UART_FREQ_SEL (1 << 1)
  369. #define UART_RATE_FIX_13M (1 << 0) /* means UARTclk = APBclk / 4 */
  370. #define UART_AUTORATE_FIX_13M (1 << 1)
  371. #define UART_FREQ_SEL_13M (1 << 2)
  372. #define UART_RATE_FIX_ALL_13M (UART_RATE_FIX_13M|UART_AUTORATE_FIX_13M| \
  373. UART_FREQ_SEL_13M)
  374. #define UART_RATE_FIX_26M (0 << 0) /* means UARTclk = APBclk / 2 */
  375. #define UART_AUTORATE_FIX_26M (0 << 1)
  376. #define UART_FREQ_SEL_26M (0 << 2)
  377. #define UART_RATE_FIX_16M25 (UART_FREQ_SEL|UART_RATE_FIX)
  378. #define UART_RATE_FIX_32M5 (UART_RATE_FIX)
  379. /*---------------------------------------------------------------------------*/
  380. /* Autobaud sample */
  381. #define UART_AUTOBADUSAM_13M 7
  382. #define UART_AUTOBADUSAM_26M 15
  383. #define UART_AUTOBADUSAM_52M 31
  384. /* #define UART_AUTOBADUSAM_52M 29 */ /* CHECKME! 28 or 29 ? */
  385. #define UART_AUTOBAUDSAM_58_5M 31 /* CHECKME! 31 or 32 ? */
  386. /*---------------------------------------------------------------------------*/
  387. /* DMA enable */
  388. #define UART_RX_DMA_EN (1 << 0)
  389. #define UART_TX_DMA_EN (1 << 1)
  390. #define UART_TO_CNT_AUTORST (1 << 2)
  391. /*---------------------------------------------------------------------------*/
  392. /* Escape character*/
  393. #define UART_ESCAPE_CH 0x77
  394. /*---------------------------------------------------------------------------*/
  395. /* Request UART to sleep*/
  396. #define UART_CLK_OFF_REQ (1 << 0)
  397. /*---------------------------------------------------------------------------*/
  398. /* UART sleep ack*/
  399. #define UART_CLK_OFF_ACK (1 << 0)
  400. /*---------------------------------------------------------------------------*/
  401. /* Debugging */
  402. typedef struct {
  403. u32 NINT:1;
  404. u32 ID:5;
  405. u32 FIFOE:2;
  406. u32 dummy:24;
  407. } UART_IIR_REG;
  408. /*---------------------------------------------------------------------------*/
  409. #ifndef CONFIG_OF
  410. #define VFF_BASE_CH_S (6)
  411. #define VFF_BASE_CH(n) (AP_DMA_BASE+0x0080*(n+1+VFF_BASE_CH_S))
  412. #endif
  413. #define VFF_INT_FLAG(_b) (_b+0x0000)
  414. #define VFF_INT_EN(_b) (_b+0x0004)
  415. #define VFF_EN(_b) (_b+0x0008)
  416. #define VFF_RST(_b) (_b+0x000C)
  417. #define VFF_STOP(_b) (_b+0x0010)
  418. #define VFF_FLUSH(_b) (_b+0x0014)
  419. #define VFF_ADDR(_b) (_b+0x001C)
  420. #define VFF_LEN(_b) (_b+0x0024)
  421. #define VFF_THRE(_b) (_b+0x0028)
  422. #define VFF_WPT(_b) (_b+0x002C)
  423. #define VFF_RPT(_b) (_b+0x0030)
  424. #define VFF_W_INT_BUF_SIZE(_b) (_b+0x0034)
  425. #define VFF_INT_BUF_SIZE(_b) (_b+0x0038)
  426. #define VFF_VALID_SIZE(_b) (_b+0x003C)
  427. #define VFF_LEFT_SIZE(_b) (_b+0x0040)
  428. #define VFF_DEBUG_STATUS(_b) (_b+0x0050)
  429. #define VFF_4G_DRAM_SUPPORT(_b) (_b+0x0054)
  430. #define VFF_VPORT_BASE 0xF7070000
  431. #define VFF_VPORT_CH(id) (VFF_VPORT_BASE + (id) * 0x00000080)
  432. /*---------------------------------------------------------------------------*/
  433. /*VFF_INT_FLAG */
  434. #define VFF_RX_INT_FLAG0_B (1 << 0) /*rx_vff_valid_size >= rx_vff_thre */
  435. /*when UART issues flush to DMA and all data in UART VFIFO is transferred to VFF */
  436. #define VFF_RX_INT_FLAG1_B (1 << 1)
  437. #define VFF_TX_INT_FLAG0_B (1 << 0) /*tx_vff_left_size >= tx_vff_thrs */
  438. #define VFF_INT_FLAG_CLR_B (0 << 0)
  439. /*VFF_INT_EN*/
  440. #define VFF_RX_INT_EN0_B (1 << 0) /*rx_vff_valid_size >= rx_vff_thre */
  441. /*when UART issues flush to DMA and all data in UART VFIFO is transferred to VFF */
  442. #define VFF_RX_INT_EN1_B (1 << 1)
  443. #define VFF_TX_INT_EN_B (1 << 0) /*tx_vff_left_size >= tx_vff_thrs */
  444. #define VFF_INT_EN_CLR_B (0 << 0)
  445. /*VFF_RST*/
  446. #define VFF_WARM_RST_B (1 << 0)
  447. #define VFF_HARD_RST_B (1 << 1)
  448. /*VFF_EN*/
  449. #define VFF_EN_B (1 << 0)
  450. /*VFF_STOP*/
  451. #define VFF_STOP_B (1 << 0)
  452. #define VFF_STOP_CLR_B (0 << 0)
  453. /*VFF_FLUSH*/
  454. #define VFF_FLUSH_B (1 << 0)
  455. #define VFF_FLUSH_CLR_B (0 << 0)
  456. #define VFF_TX_THRE(n) ((n)*7/8) /* tx_vff_left_size >= tx_vff_thrs */
  457. #define VFF_RX_THRE(n) ((n)*3/4) /* trigger level of rx vfifo */
  458. /*---------------------------------------------------------------------------*/
  459. #endif /* MTK_UART_H */