nios2-io.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*************************************************************************
  8. * Altera Nios2 Standard Peripherals
  9. ************************************************************************/
  10. #ifndef __NIOS2IO_H__
  11. #define __NIOS2IO_H__
  12. /*------------------------------------------------------------------------
  13. * UART (http://www.altera.com/literature/ds/ds_nios_uart.pdf)
  14. *----------------------------------------------------------------------*/
  15. typedef volatile struct nios_uart_t {
  16. unsigned rxdata; /* Rx data reg */
  17. unsigned txdata; /* Tx data reg */
  18. unsigned status; /* Status reg */
  19. unsigned control; /* Control reg */
  20. unsigned divisor; /* Baud rate divisor reg */
  21. unsigned endofpacket; /* End-of-packet reg */
  22. }nios_uart_t;
  23. /* status register */
  24. #define NIOS_UART_PE (1 << 0) /* parity error */
  25. #define NIOS_UART_FE (1 << 1) /* frame error */
  26. #define NIOS_UART_BRK (1 << 2) /* break detect */
  27. #define NIOS_UART_ROE (1 << 3) /* rx overrun */
  28. #define NIOS_UART_TOE (1 << 4) /* tx overrun */
  29. #define NIOS_UART_TMT (1 << 5) /* tx empty */
  30. #define NIOS_UART_TRDY (1 << 6) /* tx ready */
  31. #define NIOS_UART_RRDY (1 << 7) /* rx ready */
  32. #define NIOS_UART_E (1 << 8) /* exception */
  33. #define NIOS_UART_DCTS (1 << 10) /* cts change */
  34. #define NIOS_UART_CTS (1 << 11) /* cts */
  35. #define NIOS_UART_EOP (1 << 12) /* eop detected */
  36. /* control register */
  37. #define NIOS_UART_IPE (1 << 0) /* parity error int ena*/
  38. #define NIOS_UART_IFE (1 << 1) /* frame error int ena */
  39. #define NIOS_UART_IBRK (1 << 2) /* break detect int ena */
  40. #define NIOS_UART_IROE (1 << 3) /* rx overrun int ena */
  41. #define NIOS_UART_ITOE (1 << 4) /* tx overrun int ena */
  42. #define NIOS_UART_ITMT (1 << 5) /* tx empty int ena */
  43. #define NIOS_UART_ITRDY (1 << 6) /* tx ready int ena */
  44. #define NIOS_UART_IRRDY (1 << 7) /* rx ready int ena */
  45. #define NIOS_UART_IE (1 << 8) /* exception int ena */
  46. #define NIOS_UART_TBRK (1 << 9) /* transmit break */
  47. #define NIOS_UART_IDCTS (1 << 10) /* cts change int ena */
  48. #define NIOS_UART_RTS (1 << 11) /* rts */
  49. #define NIOS_UART_IEOP (1 << 12) /* eop detected int ena */
  50. /*------------------------------------------------------------------------
  51. * TIMER (http://www.altera.com/literature/ds/ds_nios_timer.pdf)
  52. *----------------------------------------------------------------------*/
  53. typedef volatile struct nios_timer_t {
  54. unsigned status; /* Timer status reg */
  55. unsigned control; /* Timer control reg */
  56. unsigned periodl; /* Timeout period low */
  57. unsigned periodh; /* Timeout period high */
  58. unsigned snapl; /* Snapshot low */
  59. unsigned snaph; /* Snapshot high */
  60. }nios_timer_t;
  61. /* status register */
  62. #define NIOS_TIMER_TO (1 << 0) /* Timeout */
  63. #define NIOS_TIMER_RUN (1 << 1) /* Timer running */
  64. /* control register */
  65. #define NIOS_TIMER_ITO (1 << 0) /* Timeout int ena */
  66. #define NIOS_TIMER_CONT (1 << 1) /* Continuous mode */
  67. #define NIOS_TIMER_START (1 << 2) /* Start timer */
  68. #define NIOS_TIMER_STOP (1 << 3) /* Stop timer */
  69. /*------------------------------------------------------------------------
  70. * PIO (http://www.altera.com/literature/ds/ds_nios_pio.pdf)
  71. *----------------------------------------------------------------------*/
  72. typedef volatile struct nios_pio_t {
  73. unsigned int data; /* Data value at each PIO in/out */
  74. unsigned int direction; /* Data direct. for each PIO bit */
  75. unsigned int interruptmask; /* Per-bit IRQ enable/disable */
  76. unsigned int edgecapture; /* Per-bit sync. edge detect & hold */
  77. }nios_pio_t;
  78. /* direction register */
  79. #define NIOS_PIO_OUT (1) /* PIO bit is output */
  80. #define NIOS_PIO_IN (0) /* PIO bit is input */
  81. /*------------------------------------------------------------------------
  82. * SPI (http://www.altera.com/literature/ds/ds_nios_spi.pdf)
  83. *----------------------------------------------------------------------*/
  84. typedef volatile struct nios_spi_t {
  85. unsigned rxdata; /* Rx data reg */
  86. unsigned txdata; /* Tx data reg */
  87. unsigned status; /* Status reg */
  88. unsigned control; /* Control reg */
  89. unsigned reserved; /* (master only) */
  90. unsigned slaveselect; /* SPI slave select mask (master only) */
  91. }nios_spi_t;
  92. /* status register */
  93. #define NIOS_SPI_ROE (1 << 3) /* rx overrun */
  94. #define NIOS_SPI_TOE (1 << 4) /* tx overrun */
  95. #define NIOS_SPI_TMT (1 << 5) /* tx empty */
  96. #define NIOS_SPI_TRDY (1 << 6) /* tx ready */
  97. #define NIOS_SPI_RRDY (1 << 7) /* rx ready */
  98. #define NIOS_SPI_E (1 << 8) /* exception */
  99. /* control register */
  100. #define NIOS_SPI_IROE (1 << 3) /* rx overrun int ena */
  101. #define NIOS_SPI_ITOE (1 << 4) /* tx overrun int ena */
  102. #define NIOS_SPI_ITRDY (1 << 6) /* tx ready int ena */
  103. #define NIOS_SPI_IRRDY (1 << 7) /* rx ready int ena */
  104. #define NIOS_SPI_IE (1 << 8) /* exception int ena */
  105. #define NIOS_SPI_SSO (1 << 10) /* override SS_n output */
  106. /*------------------------------------------------------------------------
  107. * JTAG UART
  108. *----------------------------------------------------------------------*/
  109. typedef volatile struct nios_jtag_t {
  110. unsigned data; /* Data register */
  111. unsigned control; /* Control register */
  112. }nios_jtag_t;
  113. /* data register */
  114. #define NIOS_JTAG_RVALID (1<<15) /* Read valid */
  115. #define NIOS_JTAG_DATA(d) ((d)&0x0ff) /* Read data */
  116. #define NIOS_JTAG_RAVAIL(d) ((d)>>16) /* Read space avail */
  117. /* control register */
  118. #define NIOS_JTAG_RE (1 << 0) /* read intr enable */
  119. #define NIOS_JTAG_WE (1 << 1) /* write intr enable */
  120. #define NIOS_JTAG_RI (1 << 8) /* read intr pending */
  121. #define NIOS_JTAG_WI (1 << 9) /* write intr pending*/
  122. #define NIOS_JTAG_AC (1 << 10) /* activity indicator */
  123. #define NIOS_JTAG_RRDY (1 << 12) /* read available */
  124. #define NIOS_JTAG_WSPACE(d) ((d)>>16) /* Write space avail */
  125. /*------------------------------------------------------------------------
  126. * SYSTEM ID
  127. *----------------------------------------------------------------------*/
  128. typedef volatile struct nios_sysid_t {
  129. unsigned id; /* The system build id*/
  130. unsigned timestamp; /* Timestamp */
  131. }nios_sysid_t;
  132. #endif /* __NIOS2IO_H__ */