pic32_uart.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PIC32 Integrated Serial Driver.
  4. *
  5. * Copyright (C) 2015 Microchip Technology, Inc.
  6. *
  7. * Authors:
  8. * Sorin-Andrei Pistirica <andrei.pistirica@microchip.com>
  9. */
  10. #ifndef __DT_PIC32_UART_H__
  11. #define __DT_PIC32_UART_H__
  12. #define PIC32_UART_DFLT_BRATE (9600)
  13. #define PIC32_UART_TX_FIFO_DEPTH (8)
  14. #define PIC32_UART_RX_FIFO_DEPTH (8)
  15. #define PIC32_UART_MODE 0x00
  16. #define PIC32_UART_STA 0x10
  17. #define PIC32_UART_TX 0x20
  18. #define PIC32_UART_RX 0x30
  19. #define PIC32_UART_BRG 0x40
  20. struct pic32_console_opt {
  21. int baud;
  22. int parity;
  23. int bits;
  24. int flow;
  25. };
  26. /* struct pic32_sport - pic32 serial port descriptor
  27. * @port: uart port descriptor
  28. * @idx: port index
  29. * @irq_fault: virtual fault interrupt number
  30. * @irqflags_fault: flags related to fault irq
  31. * @irq_fault_name: irq fault name
  32. * @irq_rx: virtual rx interrupt number
  33. * @irqflags_rx: flags related to rx irq
  34. * @irq_rx_name: irq rx name
  35. * @irq_tx: virtual tx interrupt number
  36. * @irqflags_tx: : flags related to tx irq
  37. * @irq_tx_name: irq tx name
  38. * @cts_gpio: clear to send gpio
  39. * @dev: device descriptor
  40. **/
  41. struct pic32_sport {
  42. struct uart_port port;
  43. struct pic32_console_opt opt;
  44. int idx;
  45. int irq_fault;
  46. int irqflags_fault;
  47. const char *irq_fault_name;
  48. int irq_rx;
  49. int irqflags_rx;
  50. const char *irq_rx_name;
  51. int irq_tx;
  52. int irqflags_tx;
  53. const char *irq_tx_name;
  54. u8 enable_tx_irq;
  55. bool hw_flow_ctrl;
  56. int cts_gpio;
  57. int ref_clk;
  58. struct clk *clk;
  59. struct device *dev;
  60. };
  61. #define to_pic32_sport(c) container_of(c, struct pic32_sport, port)
  62. #define pic32_get_port(sport) (&sport->port)
  63. #define pic32_get_opt(sport) (&sport->opt)
  64. #define tx_irq_enabled(sport) (sport->enable_tx_irq)
  65. static inline void pic32_uart_writel(struct pic32_sport *sport,
  66. u32 reg, u32 val)
  67. {
  68. struct uart_port *port = pic32_get_port(sport);
  69. __raw_writel(val, port->membase + reg);
  70. }
  71. static inline u32 pic32_uart_readl(struct pic32_sport *sport, u32 reg)
  72. {
  73. struct uart_port *port = pic32_get_port(sport);
  74. return __raw_readl(port->membase + reg);
  75. }
  76. /* pic32 uart mode register bits */
  77. #define PIC32_UART_MODE_ON BIT(15)
  78. #define PIC32_UART_MODE_FRZ BIT(14)
  79. #define PIC32_UART_MODE_SIDL BIT(13)
  80. #define PIC32_UART_MODE_IREN BIT(12)
  81. #define PIC32_UART_MODE_RTSMD BIT(11)
  82. #define PIC32_UART_MODE_RESV1 BIT(10)
  83. #define PIC32_UART_MODE_UEN1 BIT(9)
  84. #define PIC32_UART_MODE_UEN0 BIT(8)
  85. #define PIC32_UART_MODE_WAKE BIT(7)
  86. #define PIC32_UART_MODE_LPBK BIT(6)
  87. #define PIC32_UART_MODE_ABAUD BIT(5)
  88. #define PIC32_UART_MODE_RXINV BIT(4)
  89. #define PIC32_UART_MODE_BRGH BIT(3)
  90. #define PIC32_UART_MODE_PDSEL1 BIT(2)
  91. #define PIC32_UART_MODE_PDSEL0 BIT(1)
  92. #define PIC32_UART_MODE_STSEL BIT(0)
  93. /* pic32 uart status register bits */
  94. #define PIC32_UART_STA_UTXISEL1 BIT(15)
  95. #define PIC32_UART_STA_UTXISEL0 BIT(14)
  96. #define PIC32_UART_STA_UTXINV BIT(13)
  97. #define PIC32_UART_STA_URXEN BIT(12)
  98. #define PIC32_UART_STA_UTXBRK BIT(11)
  99. #define PIC32_UART_STA_UTXEN BIT(10)
  100. #define PIC32_UART_STA_UTXBF BIT(9)
  101. #define PIC32_UART_STA_TRMT BIT(8)
  102. #define PIC32_UART_STA_URXISEL1 BIT(7)
  103. #define PIC32_UART_STA_URXISEL0 BIT(6)
  104. #define PIC32_UART_STA_ADDEN BIT(5)
  105. #define PIC32_UART_STA_RIDLE BIT(4)
  106. #define PIC32_UART_STA_PERR BIT(3)
  107. #define PIC32_UART_STA_FERR BIT(2)
  108. #define PIC32_UART_STA_OERR BIT(1)
  109. #define PIC32_UART_STA_URXDA BIT(0)
  110. #endif /* __DT_PIC32_UART_H__ */