pic32_uart.h 3.4 KB

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