dw_spi.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* ------------------------------------------
  2. * Copyright (c) 2017, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2017.03
  25. * \date 2014-06-25
  26. * \author Huaqi Fang(Huaqi.Fang@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \file
  30. * \brief DesignWare SPI driver header file
  31. * \ingroup DEVICE_DW_SPI
  32. */
  33. #ifndef _DEVICE_DW_SPI_H_
  34. #define _DEVICE_DW_SPI_H_
  35. #include "device/device_hal/inc/dev_spi.h"
  36. /**
  37. * if this header file is included,
  38. * will indicate that this designware spi device
  39. * is used
  40. */
  41. #define DEVICE_USE_DESIGNWARE_SPI
  42. #define DW_SPI_IN_FREE (0) /*!< Currently not in spi transfer */
  43. #define DW_SPI_IN_XFER (DEV_IN_TX|DEV_IN_RX|DEV_IN_XFER) /*!< Currently in spi transfer */
  44. #define DW_SPI_IN_TX (DEV_IN_TX|DEV_IN_XFER) /*!< Currently in spi tx */
  45. #define DW_SPI_IN_RX (DEV_IN_RX|DEV_IN_XFER) /*!< Currently in spi rx */
  46. #define DW_SPI_GINT_DISABLED (0) /*!< designware interrupt disabled for control iic irq/fiq */
  47. #define DW_SPI_GINT_ENABLE (1<<0) /*!< designware interrupt enabled for control iic irq/fiq */
  48. #define DW_SPI_MASTER_SUPPORTED (0x1) /*!< Support Designware SPI Master Mode */
  49. #define DW_SPI_SLAVE_SUPPORTED (0x2) /*!< Support Designware SPI Slave Mode */
  50. /*!< Support Designware SPI Both Master and Slave Mode */
  51. #define DW_SPI_BOTH_SUPPORTED (DW_SPI_MASTER_SUPPORTED|DW_SPI_SLAVE_SUPPORTED)
  52. /**
  53. * \defgroup DEVICE_DW_SPI_REGSTRUCT DesignWare SPI Register Structure
  54. * \ingroup DEVICE_DW_SPI
  55. * \brief contains definitions of DesignWare SPI register structure.
  56. * \details detailed description of DesignWare SPI register information
  57. * @{
  58. */
  59. /**
  60. * \brief DesignWare SPI register structure
  61. * \details Detailed struct description of DesignWare SPI
  62. * block register information, implementation of dev_spi_info::spi_regs
  63. */
  64. typedef volatile struct dw_spi_reg
  65. {
  66. /*!< Control Register */
  67. /*!< SPI Control Register 0 (0x0) */
  68. uint32_t CTRLR0;
  69. /*!< SPI Control Register 1 (0x4) */
  70. uint32_t CTRLR1;
  71. /*!< Enable Register */
  72. /*!< SPI Enable Register (0x8) */
  73. uint32_t SSIENR;
  74. /*!< SPI Microwire Control Register (0xC) */
  75. uint32_t MWCR;
  76. /*!< SPI Slave Enable Register (0x10) */
  77. uint32_t SER;
  78. /*!< SPI Baud Rate Select Register (0x14) */
  79. uint32_t BAUDR;
  80. /*!< TX and RX FIFO Control Register */
  81. /*!< SPI Transmit FIFO Threshold Level Register (0x18) */
  82. uint32_t TXFTLR;
  83. /*!< SPI Receive FIFO Threshold Level Register (0x1C) */
  84. uint32_t RXFTLR;
  85. /*!< SPI Transmit FIFO Level Register (0x20) */
  86. uint32_t TXFLR;
  87. /*!< SPI Receive FIFO Level Register (0x24) */
  88. uint32_t RXFLR;
  89. /*!< SPI Status Register (0x28) */
  90. uint32_t SR;
  91. /*!< Interrupt Enable/Disable/Control Registers */
  92. /*!< SPI Interrupt Mask Register (0x2C) */
  93. uint32_t IMR;
  94. /*!< SPI Interrupt Status Register (0x30) */
  95. uint32_t ISR;
  96. /*!< SPI Raw Interrupt Status Register (0x34) */
  97. uint32_t RISR;
  98. /*!< SPI Transmit FIFO Overflow Interrupt Clear Register (0x38) */
  99. uint32_t TXOICR;
  100. /*!< SPI Receive FIFO Overflow Interrupt Clear Register (0x3C) */
  101. uint32_t RXOICR;
  102. /*!< SPI Receive FIFO Underflow Interrupt Clear Register (0x40) */
  103. uint32_t RXUICR;
  104. /*!< SPI Multi-Master Interrupt Clear Register (0x44) */
  105. uint32_t MSTICR;
  106. /*!< SPI Interrupt Clear Register (0x48) */
  107. uint32_t ICR;
  108. /*!< DMA Control Register (0x4C) */
  109. uint32_t DMACR;
  110. /*!< DMA Transmit Data Level (0x50) */
  111. uint32_t DMATDLR;
  112. /*!< DMA Receive Data Level (0x54) */
  113. uint32_t DMARDLR;
  114. /*!< SPI Identification Register (0x58) */
  115. uint32_t IDR;
  116. /*!< SPI CoreKit ID Register (Value after Reset : 0x3332322A) (0x5C) */
  117. uint32_t SSI_VER_ID;
  118. /*!< Data Register */
  119. /*!< SPI DATA Register for both Read and Write (0x60) */
  120. uint32_t DATAREG;
  121. } DW_SPI_REG, *DW_SPI_REG_PTR;
  122. /** @} */
  123. /** Designware SPI Message Transfer */
  124. typedef struct dw_spi_transfer {
  125. uint32_t xfer_len;
  126. uint32_t tx_idx;
  127. uint32_t rx_idx;
  128. uint32_t nbytes;
  129. DEV_SPI_TRANSFER *tx_xfer;
  130. DEV_SPI_TRANSFER *rx_xfer;
  131. } DW_SPI_TRANSFER, *DW_SPI_TRANSFER_PTR;
  132. /**
  133. * \brief DesignWare SPI control structure definition
  134. * \details implement of dev_spi_info::dev_spi_info
  135. */
  136. typedef struct dw_spi_ctrl {
  137. DW_SPI_REG *dw_spi_regs; /*!< spi register */
  138. /* Variables which should be set during object implementation */
  139. uint32_t support_modes; /*!< supported spi modes */
  140. uint32_t intno; /*!< interrupt no */
  141. uint32_t dw_apb_bus_freq; /*!< spi ip apb bus frequency */
  142. uint32_t tx_fifo_len; /*!< transmit fifo length */
  143. uint32_t rx_fifo_len; /*!< receive fifo length */
  144. INT_HANDLER dw_spi_int_handler; /*!< spi interrupt handler */
  145. /* Variables which always change during iic operation */
  146. uint32_t int_status; /*!< iic interrupt status */
  147. DW_SPI_TRANSFER dw_xfer; /*!< designware spi transfer */
  148. } DW_SPI_CTRL, *DW_SPI_CTRL_PTR;
  149. #ifdef __cplusplus
  150. extern "C" {
  151. #endif
  152. /**
  153. * \defgroup DEVICE_DW_SPI_FUNCDLR DesignWare SPI Function Declaration
  154. * \ingroup DEVICE_DW_SPI
  155. * \brief contains declarations of designware spi functions.
  156. * \details This are only used in \ref dw_spi_obj.c
  157. * @{
  158. */
  159. extern int32_t dw_spi_open (DEV_SPI *spi_obj, uint32_t mode, uint32_t param);
  160. extern int32_t dw_spi_close (DEV_SPI *spi_obj);
  161. extern int32_t dw_spi_control (DEV_SPI *spi_obj, uint32_t ctrl_cmd, void *param);
  162. extern int32_t dw_spi_write (DEV_SPI *spi_obj, const void *data, uint32_t len);
  163. extern int32_t dw_spi_read (DEV_SPI *spi_obj, void *data, uint32_t len);
  164. extern void dw_spi_isr(DEV_SPI *spi_obj, void *ptr);
  165. /** @} */
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. /** @} */
  170. #endif /* _DEVICE_DW_SPI_H_ */