apbuart.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __GRLIB_APBUART_H__
  3. #define __GRLIB_APBUART_H__
  4. #include <asm/io.h>
  5. #define UART_NR 8
  6. static int grlib_apbuart_port_nr;
  7. struct grlib_apbuart_regs_map {
  8. u32 data;
  9. u32 status;
  10. u32 ctrl;
  11. u32 scaler;
  12. };
  13. struct amba_prom_registers {
  14. unsigned int phys_addr;
  15. unsigned int reg_size;
  16. };
  17. /*
  18. * The following defines the bits in the APBUART Status Registers.
  19. */
  20. #define UART_STATUS_DR 0x00000001 /* Data Ready */
  21. #define UART_STATUS_TSE 0x00000002 /* TX Send Register Empty */
  22. #define UART_STATUS_THE 0x00000004 /* TX Hold Register Empty */
  23. #define UART_STATUS_BR 0x00000008 /* Break Error */
  24. #define UART_STATUS_OE 0x00000010 /* RX Overrun Error */
  25. #define UART_STATUS_PE 0x00000020 /* RX Parity Error */
  26. #define UART_STATUS_FE 0x00000040 /* RX Framing Error */
  27. #define UART_STATUS_ERR 0x00000078 /* Error Mask */
  28. /*
  29. * The following defines the bits in the APBUART Ctrl Registers.
  30. */
  31. #define UART_CTRL_RE 0x00000001 /* Receiver enable */
  32. #define UART_CTRL_TE 0x00000002 /* Transmitter enable */
  33. #define UART_CTRL_RI 0x00000004 /* Receiver interrupt enable */
  34. #define UART_CTRL_TI 0x00000008 /* Transmitter irq */
  35. #define UART_CTRL_PS 0x00000010 /* Parity select */
  36. #define UART_CTRL_PE 0x00000020 /* Parity enable */
  37. #define UART_CTRL_FL 0x00000040 /* Flow control enable */
  38. #define UART_CTRL_LB 0x00000080 /* Loopback enable */
  39. #define APBBASE(port) ((struct grlib_apbuart_regs_map *)((port)->membase))
  40. #define APBBASE_DATA_P(port) (&(APBBASE(port)->data))
  41. #define APBBASE_STATUS_P(port) (&(APBBASE(port)->status))
  42. #define APBBASE_CTRL_P(port) (&(APBBASE(port)->ctrl))
  43. #define APBBASE_SCALAR_P(port) (&(APBBASE(port)->scaler))
  44. #define UART_GET_CHAR(port) (__raw_readl(APBBASE_DATA_P(port)))
  45. #define UART_PUT_CHAR(port, v) (__raw_writel(v, APBBASE_DATA_P(port)))
  46. #define UART_GET_STATUS(port) (__raw_readl(APBBASE_STATUS_P(port)))
  47. #define UART_PUT_STATUS(port, v)(__raw_writel(v, APBBASE_STATUS_P(port)))
  48. #define UART_GET_CTRL(port) (__raw_readl(APBBASE_CTRL_P(port)))
  49. #define UART_PUT_CTRL(port, v) (__raw_writel(v, APBBASE_CTRL_P(port)))
  50. #define UART_GET_SCAL(port) (__raw_readl(APBBASE_SCALAR_P(port)))
  51. #define UART_PUT_SCAL(port, v) (__raw_writel(v, APBBASE_SCALAR_P(port)))
  52. #define UART_RX_DATA(s) (((s) & UART_STATUS_DR) != 0)
  53. #define UART_TX_READY(s) (((s) & UART_STATUS_THE) != 0)
  54. #endif /* __GRLIB_APBUART_H__ */