uart.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (c) 2019-2025 Allwinner Technology Co., Ltd. ALL rights reserved.
  3. *
  4. * Allwinner is a trademark of Allwinner Technology Co.,Ltd., registered in
  5. * the the People's Republic of China and other countries.
  6. * All Allwinner Technology Co.,Ltd. trademarks are used with permission.
  7. *
  8. * DISCLAIMER
  9. * THIRD PARTY LICENCES MAY BE REQUIRED TO IMPLEMENT THE SOLUTION/PRODUCT.
  10. * IF YOU NEED TO INTEGRATE THIRD PARTY’S TECHNOLOGY (SONY, DTS, DOLBY, AVS OR MPEGLA, ETC.)
  11. * IN ALLWINNERS’SDK OR PRODUCTS, YOU SHALL BE SOLELY RESPONSIBLE TO OBTAIN
  12. * ALL APPROPRIATELY REQUIRED THIRD PARTY LICENCES.
  13. * ALLWINNER SHALL HAVE NO WARRANTY, INDEMNITY OR OTHER OBLIGATIONS WITH RESPECT TO MATTERS
  14. * COVERED UNDER ANY REQUIRED THIRD PARTY LICENSE.
  15. * YOU ARE SOLELY RESPONSIBLE FOR YOUR USAGE OF THIRD PARTY’S TECHNOLOGY.
  16. *
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY ALLWINNER"AS IS" AND TO THE MAXIMUM EXTENT
  19. * PERMITTED BY LAW, ALLWINNER EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND,
  20. * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION REGARDING
  21. * THE TITLE, NON-INFRINGEMENT, ACCURACY, CONDITION, COMPLETENESS, PERFORMANCE
  22. * OR MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  23. * IN NO EVENT SHALL ALLWINNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS, OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  28. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  30. * OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef __UART_I_H__
  33. #define __UART_I_H__
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /*
  38. * Register definitions for UART
  39. */
  40. #define UART_RHB (0x00)
  41. #define UART_RBR (0x00) /* receive buffer register */
  42. #define UART_THR (0x00) /* transmit holding register */
  43. #define UART_DLL (0x00) /* divisor latch low register */
  44. #define UART_DLH (0x04) /* diviso latch high register */
  45. #define UART_IER (0x04) /* interrupt enable register */
  46. #define UART_IIR (0x08) /* interrupt identity register */
  47. #define UART_FCR (0x08) /* FIFO control register */
  48. #define UART_LCR (0x0c) /* line control register */
  49. #define UART_MCR (0x10) /* modem control register */
  50. #define UART_LSR (0x14) /* line status register */
  51. #define UART_MSR (0x18) /* modem status register */
  52. #define UART_SCH (0x1c) /* scratch register */
  53. #define UART_USR (0x7c) /* status register */
  54. #define UART_TFL (0x80) /* transmit FIFO level */
  55. #define UART_RFL (0x84) /* RFL */
  56. #define UART_HALT (0xa4) /* halt tx register */
  57. #define UART_RS485 (0xc0) /* RS485 control and status register */
  58. /*
  59. * register bit field define
  60. */
  61. /* Interrupt Enable Register */
  62. #define UART_IER_MASK (0xff)
  63. #define UART_IER_PTIME (BIT(7))
  64. #define UART_IER_RS485 (BIT(4))
  65. #define UART_IER_MSI (BIT(3))
  66. #define UART_IER_RLSI (BIT(2))
  67. #define UART_IER_THRI (BIT(1))
  68. #define UART_IER_RDI (BIT(0))
  69. /* Interrupt ID Register */
  70. #define UART_IIR_FEFLAG_MASK (BIT(6)|BIT(7))
  71. #define UART_IIR_IID_MASK (BIT(0)|BIT(1)|BIT(2)|BIT(3))
  72. #define UART_IIR_IID_MSTA (0)
  73. #define UART_IIR_IID_NOIRQ (1)
  74. #define UART_IIR_IID_THREMP (2)
  75. #define UART_IIR_IID_RXDVAL (4)
  76. #define UART_IIR_IID_LINESTA (6)
  77. #define UART_IIR_IID_BUSBSY (7)
  78. #define UART_IIR_IID_CHARTO (12)
  79. /* FIFO Control Register */
  80. #define UART_FCR_RXTRG_MASK (BIT(6)|BIT(7))
  81. #define UART_FCR_RXTRG_1CH (0 << 6)
  82. #define UART_FCR_RXTRG_1_4 (1 << 6)
  83. #define UART_FCR_RXTRG_1_2 (2 << 6)
  84. #define UART_FCR_RXTRG_FULL (3 << 6)
  85. #define UART_FCR_TXTRG_MASK (BIT(4)|BIT(5))
  86. #define UART_FCR_TXTRG_EMP (0 << 4)
  87. #define UART_FCR_TXTRG_2CH (1 << 4)
  88. #define UART_FCR_TXTRG_1_4 (2 << 4)
  89. #define UART_FCR_TXTRG_1_2 (3 << 4)
  90. #define UART_FCR_TXFIFO_RST (BIT(2))
  91. #define UART_FCR_RXFIFO_RST (BIT(1))
  92. #define UART_FCR_FIFO_EN (BIT(0))
  93. /* Line Control Register */
  94. #define UART_LCR_DLAB (BIT(7))
  95. #define UART_LCR_SBC (BIT(6))
  96. #define UART_LCR_PARITY_MASK (BIT(5)|BIT(4))
  97. #define UART_LCR_EPAR (1 << 4)
  98. #define UART_LCR_OPAR (0 << 4)
  99. #define UART_LCR_PARITY (BIT(3))
  100. #define UART_LCR_STOP (BIT(2))
  101. #define UART_LCR_DLEN_MASK (BIT(1)|BIT(0))
  102. #define UART_LCR_WLEN5 (0)
  103. #define UART_LCR_WLEN6 (1)
  104. #define UART_LCR_WLEN7 (2)
  105. #define UART_LCR_WLEN8 (3)
  106. /* Modem Control Register */
  107. #define UART_MCR_MODE_MASK (BIT(7)|BIT(6))
  108. #define UART_MCR_MODE_RS485 (2 << 6)
  109. #define UART_MCR_MODE_SIRE (1 << 6)
  110. #define UART_MCR_MODE_UART (0 << 6)
  111. #define UART_MCR_AFE (BIT(5))
  112. #define UART_MCR_LOOP (BIT(4))
  113. #define UART_MCR_RTS (BIT(1))
  114. #define UART_MCR_DTR (BIT(0))
  115. /* Line Status Rigster */
  116. #define UART_LSR_RXFIFOE (BIT(7))
  117. #define UART_LSR_TEMT (BIT(6))
  118. #define UART_LSR_THRE (BIT(5))
  119. #define UART_LSR_BI (BIT(4))
  120. #define UART_LSR_FE (BIT(3))
  121. #define UART_LSR_PE (BIT(2))
  122. #define UART_LSR_OE (BIT(1))
  123. #define UART_LSR_DR (BIT(0))
  124. #define UART_LSR_BRK_ERROR_BITS (0x1E) /* BI, FE, PE, OE bits */
  125. /* Modem Status Register */
  126. #define UART_MSR_DCD (BIT(7))
  127. #define UART_MSR_RI (BIT(6))
  128. #define UART_MSR_DSR (BIT(5))
  129. #define UART_MSR_CTS (BIT(4))
  130. #define UART_MSR_DDCD (BIT(3))
  131. #define UART_MSR_TERI (BIT(2))
  132. #define UART_MSR_DDSR (BIT(1))
  133. #define UART_MSR_DCTS (BIT(0))
  134. #define UART_MSR_ANY_DELTA (0x0F)
  135. #define MSR_SAVE_FLAGS (UART_MSR_ANY_DELTA)
  136. /* Status Register */
  137. #define UART_USR_RFF (BIT(4))
  138. #define UART_USR_RFNE (BIT(3))
  139. #define UART_USR_TFE (BIT(2))
  140. #define UART_USR_TFNF (BIT(1))
  141. #define UART_USR_BUSY (BIT(0))
  142. /* Halt Register */
  143. #define UART_HALT_LCRUP (BIT(2))
  144. #define UART_HALT_FORCECFG (BIT(1))
  145. #define UART_HALT_HTX (BIT(0))
  146. /* RS485 Control and Status Register */
  147. #define UART_RS485_RXBFA (BIT(3))
  148. #define UART_RS485_RXAFA (BIT(2))
  149. #ifdef __cplusplus
  150. }
  151. #endif
  152. #endif /* __UART_I_H__ */