drv_spi.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Copyright (c) 2023, Canaan Bright Sight Co., Ltd
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * 1. Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * 2. Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. *
  11. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  12. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  13. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  16. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /*
  26. * Copyright (c) 2006-2025 RT-Thread Development Team
  27. *
  28. * SPDX-License-Identifier: Apache-2.0
  29. */
  30. #ifndef __DRV_SPI_H__
  31. #define __DRV_SPI_H__
  32. #include <stdint.h>
  33. #include <stdbool.h>
  34. #define SSIC_HAS_DMA 2
  35. #define SSIC_AXI_BLW 8
  36. #define SSIC_TX_ABW 256
  37. #define SSIC_RX_ABW 256
  38. #define IRQN_SPI0 146
  39. #define IRQN_SPI1 155
  40. #define IRQN_SPI2 164
  41. #ifndef L1_CACHE_BYTES
  42. #define L1_CACHE_BYTES 64
  43. #endif
  44. #define CACHE_ALIGN_TOP(x) (((x) + L1_CACHE_BYTES - 1) & ~(L1_CACHE_BYTES - 1))
  45. #define CACHE_ALIGN_BOTTOM(x) ((x) & ~(L1_CACHE_BYTES - 1))
  46. #define BIT(n) (1UL << (n))
  47. enum
  48. {
  49. SSI_TXE = 0,
  50. SSI_TXO,
  51. SSI_RXF,
  52. SSI_RXO,
  53. SSI_TXU,
  54. SSI_RXU,
  55. SSI_MST,
  56. SSI_DONE,
  57. SSI_AXIE,
  58. };
  59. /* SPI mode */
  60. enum
  61. {
  62. SPI_FRF_STD_SPI,
  63. SPI_FRF_DUAL_SPI,
  64. SPI_FRF_QUAD_SPI,
  65. SPI_FRF_OCT_SPI,
  66. };
  67. /* SPI transmit mode */
  68. enum
  69. {
  70. SPI_TMOD_TR,
  71. SPI_TMOD_TO,
  72. SPI_TMOD_RO,
  73. SPI_TMOD_EPROMREAD,
  74. };
  75. /* Qspi register */
  76. typedef struct
  77. {
  78. /* SPI Control Register 0 (0x00)*/
  79. volatile uint32_t ctrlr0;
  80. /* SPI Control Register 1 (0x04)*/
  81. volatile uint32_t ctrlr1;
  82. /* SPI Enable Register (0x08)*/
  83. volatile uint32_t ssienr;
  84. /* SPI Microwire Control Register (0x0c)*/
  85. volatile uint32_t mwcr;
  86. /* SPI Slave Enable Register (0x10)*/
  87. volatile uint32_t ser;
  88. /* SPI Baud Rate Select (0x14)*/
  89. volatile uint32_t baudr;
  90. /* SPI Transmit FIFO Threshold Level (0x18)*/
  91. volatile uint32_t txftlr;
  92. /* SPI Receive FIFO Threshold Level (0x1c)*/
  93. volatile uint32_t rxftlr;
  94. /* SPI Transmit FIFO Level Register (0x20)*/
  95. volatile uint32_t txflr;
  96. /* SPI Receive FIFO Level Register (0x24)*/
  97. volatile uint32_t rxflr;
  98. /* SPI Status Register (0x28)*/
  99. volatile uint32_t sr;
  100. /* SPI Interrupt Mask Register (0x2c)*/
  101. volatile uint32_t imr;
  102. /* SPI Interrupt Status Register (0x30)*/
  103. volatile uint32_t isr;
  104. /* SPI Raw Interrupt Status Register (0x34)*/
  105. volatile uint32_t risr;
  106. /* SPI Transmit FIFO Underflow Interrupt Clear Register (0x38)*/
  107. volatile uint32_t txeicr;
  108. /* SPI Receive FIFO Overflow Interrupt Clear Register (0x3c)*/
  109. volatile uint32_t rxoicr;
  110. /* SPI Receive FIFO Underflow Interrupt Clear Register (0x40)*/
  111. volatile uint32_t rxuicr;
  112. /* SPI Multi-Master Interrupt Clear Register (0x44)*/
  113. volatile uint32_t msticr;
  114. /* SPI Interrupt Clear Register (0x48)*/
  115. volatile uint32_t icr;
  116. /* SPI DMA Control Register (0x4c)*/
  117. volatile uint32_t dmacr;
  118. #if SSIC_HAS_DMA == 1
  119. /* SPI DMA Transmit Data Level (0x50)*/
  120. volatile uint32_t dmatdlr;
  121. /* SPI DMA Receive Data Level (0x54)*/
  122. volatile uint32_t dmardlr;
  123. #elif SSIC_HAS_DMA == 2
  124. /* SPI Destination Burst Length (0x50)*/
  125. volatile uint32_t axiawlen;
  126. /* SPI Source Burst Length (0x54)*/
  127. volatile uint32_t axiarlen;
  128. #else
  129. uint32_t resv0[2];
  130. #endif
  131. /* SPI Identification Register (0x58)*/
  132. volatile const uint32_t idr;
  133. /* SPI DWC_ssi component version (0x5c)*/
  134. volatile uint32_t ssic_version_id;
  135. /* SPI Data Register 0-36 (0x60 -- 0xec)*/
  136. volatile uint32_t dr[36];
  137. /* SPI RX Sample Delay Register (0xf0)*/
  138. volatile uint32_t rx_sample_delay;
  139. /* SPI SPI Control Register (0xf4)*/
  140. volatile uint32_t spi_ctrlr0;
  141. /* SPI Transmit Drive Edge Register (0xf8)*/
  142. volatile uint32_t ddr_drive_edge;
  143. /* SPI XIP Mode bits (0xfc)*/
  144. volatile uint32_t xip_mode_bits;
  145. /* SPI XIP INCR transfer opcode (0x100)*/
  146. volatile uint32_t xip_incr_inst;
  147. /* SPI XIP WRAP transfer opcode (0x104)*/
  148. volatile uint32_t xip_wrap_inst;
  149. #if SSIC_CONCURRENT_XIP_EN
  150. /* SPI XIP Control Register (0x108)*/
  151. volatile uint32_t xip_ctrl;
  152. /* SPI XIP Slave Enable Register (0x10c)*/
  153. volatile uint32_t xip_ser;
  154. /* SPI XIP Receive FIFO Overflow Interrupt Clear Register (0x110)*/
  155. volatile uint32_t xrxoicr;
  156. /* SPI XIP time out register for continuous transfers (0x114)*/
  157. volatile uint32_t xip_cnt_time_out;
  158. /* not support dyn ws (0x118)*/
  159. uint32_t resv1[1];
  160. /* SPI Transmit Error Interrupt Clear Register (0x11c)*/
  161. volatile uint32_t spitecr;
  162. #else
  163. uint32_t resv1[6];
  164. #endif
  165. #if SSIC_HAS_DMA == 2
  166. /* SPI Device Register (0x120)*/
  167. volatile uint32_t spidr;
  168. /* SPI Device Address Register (0x124)*/
  169. volatile uint32_t spiar;
  170. /* AXI Address Register 0 (0x128)*/
  171. volatile uint32_t axiar0;
  172. /* AXI Address Register 1 (0x12c)*/
  173. volatile uint32_t axiar1;
  174. /* AXI Master Error Interrupt Clear Register (0x130)*/
  175. volatile uint32_t axiecr;
  176. /* Transfer Done Clear Interrupt Clear Register (0x134)*/
  177. volatile uint32_t donecr;
  178. #endif
  179. /* This register will not be used and is reserved. (0x138 ~ 0x13c)*/
  180. uint32_t resv3[2];
  181. #if SSIC_XIP_WRITE_REG_EN
  182. /* XIP_WRITE_INCR_INST - XIP Write INCR transfer opcode (0x140)*/
  183. volatile uint32_t xip_write_incr_inst;
  184. /* XIP_WRITE_WRAP_INST - XIP Write WRAP transfer opcode (0x144)*/
  185. volatile uint32_t xip_write_wrap_inst;
  186. /* XIP_WRITE_CTRL - XIP Write Control Register (0x148)*/
  187. volatile uint32_t xip_write_ctrl;
  188. #else
  189. uint32_t resv4[3];
  190. #endif
  191. // volatile uint32_t endian;
  192. } __attribute__((packed, aligned(4))) k230_spi_reg_t;
  193. #endif