uart.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef UART_H
  7. #define UART_H
  8. #include <platform_def.h>
  9. /* UART HW information */
  10. #define HW_SUPPORT_UART_PORTS 2
  11. #define DRV_SUPPORT_UART_PORTS 2
  12. /* console UART clock cg */
  13. #define UART_CLOCK_GATE_SET (INFRACFG_AO_BASE + 0x80)
  14. #define UART_CLOCK_GATE_CLR (INFRACFG_AO_BASE + 0x84)
  15. #define UART_CLOCK_GATE_STA (INFRACFG_AO_BASE + 0x90)
  16. #define UART0_CLOCK_GATE_BIT (1U<<22)
  17. #define UART1_CLOCK_GATE_BIT (1U<<23)
  18. /* UART registers */
  19. #define UART_RBR(_baseaddr) (_baseaddr + 0x0)
  20. #define UART_THR(_baseaddr) (_baseaddr + 0x0)
  21. #define UART_IER(_baseaddr) (_baseaddr + 0x4)
  22. #define UART_IIR(_baseaddr) (_baseaddr + 0x8)
  23. #define UART_FCR(_baseaddr) (_baseaddr + 0x8)
  24. #define UART_LCR(_baseaddr) (_baseaddr + 0xc)
  25. #define UART_MCR(_baseaddr) (_baseaddr + 0x10)
  26. #define UART_LSR(_baseaddr) (_baseaddr + 0x14)
  27. #define UART_MSR(_baseaddr) (_baseaddr + 0x18)
  28. #define UART_SCR(_baseaddr) (_baseaddr + 0x1c)
  29. #define UART_DLL(_baseaddr) (_baseaddr + 0x0)
  30. #define UART_DLH(_baseaddr) (_baseaddr + 0x4)
  31. #define UART_EFR(_baseaddr) (_baseaddr + 0x8)
  32. #define UART_XON1(_baseaddr) (_baseaddr + 0x10)
  33. #define UART_XON2(_baseaddr) (_baseaddr + 0x14)
  34. #define UART_XOFF1(_baseaddr) (_baseaddr + 0x18)
  35. #define UART_XOFF2(_baseaddr) (_baseaddr + 0x1c)
  36. #define UART_AUTOBAUD(_baseaddr) (_baseaddr + 0x20)
  37. #define UART_HIGHSPEED(_baseaddr) (_baseaddr + 0x24)
  38. #define UART_SAMPLE_COUNT(_baseaddr) (_baseaddr + 0x28)
  39. #define UART_SAMPLE_POINT(_baseaddr) (_baseaddr + 0x2c)
  40. #define UART_AUTOBAUD_REG(_baseaddr) (_baseaddr + 0x30)
  41. #define UART_RATE_FIX_REG(_baseaddr) (_baseaddr + 0x34)
  42. #define UART_AUTO_BAUDSAMPLE(_baseaddr) (_baseaddr + 0x38)
  43. #define UART_GUARD(_baseaddr) (_baseaddr + 0x3c)
  44. #define UART_ESCAPE_DAT(_baseaddr) (_baseaddr + 0x40)
  45. #define UART_ESCAPE_EN(_baseaddr) (_baseaddr + 0x44)
  46. #define UART_SLEEP_EN(_baseaddr) (_baseaddr + 0x48)
  47. #define UART_DMA_EN(_baseaddr) (_baseaddr + 0x4c)
  48. #define UART_RXTRI_AD(_baseaddr) (_baseaddr + 0x50)
  49. #define UART_FRACDIV_L(_baseaddr) (_baseaddr + 0x54)
  50. #define UART_FRACDIV_M(_baseaddr) (_baseaddr + 0x58)
  51. #define UART_FCR_RD(_baseaddr) (_baseaddr + 0x5C)
  52. #define UART_USB_RX_SEL(_baseaddr) (_baseaddr + 0xB0)
  53. #define UART_SLEEP_REQ(_baseaddr) (_baseaddr + 0xB4)
  54. #define UART_SLEEP_ACK(_baseaddr) (_baseaddr + 0xB8)
  55. #define UART_SPM_SEL(_baseaddr) (_baseaddr + 0xBC)
  56. #define UART_LCR_DLAB 0x0080
  57. #define UART_LCR_MODE_B 0x00bf
  58. enum uart_port_ID {
  59. UART_PORT0 = 0,
  60. UART_PORT1
  61. };
  62. struct mt_uart_register {
  63. uint32_t dll;
  64. uint32_t dlh;
  65. uint32_t ier;
  66. uint32_t lcr;
  67. uint32_t mcr;
  68. uint32_t fcr;
  69. uint32_t lsr;
  70. uint32_t scr;
  71. uint32_t efr;
  72. uint32_t highspeed;
  73. uint32_t sample_count;
  74. uint32_t sample_point;
  75. uint32_t fracdiv_l;
  76. uint32_t fracdiv_m;
  77. uint32_t escape_en;
  78. uint32_t guard;
  79. uint32_t rx_sel;
  80. };
  81. struct mt_uart {
  82. unsigned long base;
  83. struct mt_uart_register registers;
  84. };
  85. /* external API */
  86. void mt_uart_save(void);
  87. void mt_uart_restore(void);
  88. void mt_console_uart_cg(int on);
  89. uint32_t mt_console_uart_cg_status(void);
  90. #endif /* __UART_H__ */