dw_iic.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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-30
  26. * \author Huaqi Fang(Huaqi.Fang@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \file
  30. * \brief designware iic driver header file
  31. * \ingroup DEVICE_DW_IIC
  32. */
  33. #ifndef _DW_IIC_H_
  34. #define _DW_IIC_H_
  35. #include "device/device_hal/inc/dev_iic.h"
  36. #include "inc/arc/arc_exception.h"
  37. /**
  38. * If this header file is included,
  39. * will indicate that this designware iic device
  40. * is used
  41. */
  42. #define DEVICE_USE_DESIGNWARE_IIC
  43. /**
  44. * \defgroup DEVICE_DW_IIC_INFO DesignWare IIC Related Information
  45. * \ingroup DEVICE_DW_IIC
  46. * \brief Defines some macros of DesignWare IIC need.
  47. * \details macros like, iic number
  48. * @{
  49. */
  50. #define DW_IIC_MASTER_SUPPORTED (0x1) /*!< Support Designware IIC Master Mode */
  51. #define DW_IIC_SLAVE_SUPPORTED (0x2) /*!< Support Designware IIC Slave Mode */
  52. /*!< Support Designware IIC Both Master and Slave Mode */
  53. #define DW_IIC_BOTH_SUPPORTED (DW_IIC_MASTER_SUPPORTED|DW_IIC_SLAVE_SUPPORTED)
  54. /** @} */
  55. /**
  56. * \defgroup DEVICE_DW_IIC_REGSTRUCT DesignWare IIC Register Structure
  57. * \ingroup DEVICE_DW_IIC
  58. * \brief contains definitions of DesignWare IIC register structure.
  59. * \details detailed description of DesignWare IIC register information
  60. * @{
  61. */
  62. /**
  63. * \brief DesignWare IIC register structure
  64. * \details Detailed struct description of DesignWare IIC
  65. * block register information, implementation of dev_iic_info::iic_regs
  66. */
  67. typedef volatile struct dw_iic_reg {
  68. uint32_t IC_CON; /*!< (0x00) : IIC control */
  69. uint32_t IC_TAR; /*!< (0x04) : IIC target address */
  70. uint32_t IC_SAR; /*!< (0x08) : IIC slave address */
  71. uint32_t IC_HS_MADDR; /*!< (0x0c) : IIC HS Master Mode Code address */
  72. uint32_t IC_DATA_CMD; /*!< (0x10) : IIC Rx/Tx Data Buffer and Command */
  73. uint32_t IC_SS_SCL_HCNT; /*!< (0x14) : Standard Speed IIC clock SCL High Count */
  74. uint32_t IC_SS_SCL_LCNT; /*!< (0x18) : Standard Speed IIC clock SCL Low Count */
  75. uint32_t IC_FS_SCL_HCNT; /*!< (0x1c) : Fast Speed IIC clock SCL Low Count */
  76. uint32_t IC_FS_SCL_LCNT; /*!< (0x20) : Fast Speed IIC clock SCL Low Count */
  77. uint32_t IC_HS_SCL_HCNT; /*!< (0x24) : High Speed IIC clock SCL Low Count */
  78. uint32_t IC_HS_SCL_LCNT; /*!< (0x28) : High Speed IIC clock SCL Low Count */
  79. uint32_t IC_INTR_STAT; /*!< (0x2c) : IIC Interrupt Status */
  80. uint32_t IC_INTR_MASK; /*!< (0x30) : IIC Interrupt Mask */
  81. uint32_t IC_RAW_INTR_STAT; /*!< (0x34) : IIC Raw Interrupt Status */
  82. uint32_t IC_RX_TL; /*!< (0x38) : IIC Receive FIFO Threshold */
  83. uint32_t IC_TX_TL; /*!< (0x3c) : IIC Transmit FIFO Threshold */
  84. uint32_t IC_CLR_INTR; /*!< (0x40) : Clear combined and Individual Interrupts */
  85. uint32_t IC_CLR_RX_UNDER; /*!< (0x44) : Clear RX_UNDER Interrupt */
  86. uint32_t IC_CLR_RX_OVER; /*!< (0x48) : Clear RX_OVER Interrupt */
  87. uint32_t IC_CLR_TX_OVER; /*!< (0x4c) : Clear TX_OVER Interrupt */
  88. uint32_t IC_CLR_RD_REQ; /*!< (0x50) : Clear RQ_REQ Interrupt */
  89. uint32_t IC_CLR_TX_ABRT; /*!< (0x54) : Clear TX_ABRT Interrupt */
  90. uint32_t IC_CLR_RX_DONE; /*!< (0x58) : Clear RX_DONE Interrupt */
  91. uint32_t IC_CLR_ACTIVITY; /*!< (0x5c) : Clear ACTIVITY Interrupt */
  92. uint32_t IC_CLR_STOP_DET; /*!< (0x60) : Clear STOP_DET Interrupt */
  93. uint32_t IC_CLR_START_DET; /*!< (0x64) : Clear START_DET Interrupt */
  94. uint32_t IC_CLR_GEN_CALL; /*!< (0x68) : Clear GEN_CALL Interrupt */
  95. uint32_t IC_ENABLE; /*!< (0x6c) : IIC Enable */
  96. uint32_t IC_STATUS; /*!< (0x70) : IIC Status */
  97. uint32_t IC_TXFLR; /*!< (0x74) : Transmit FIFO Level Register */
  98. uint32_t IC_RXFLR; /*!< (0x78) : Receive FIFO Level Register */
  99. uint32_t IC_SDA_HOLD; /*!< (0x7c) : SDA Hold Time Length Reg */
  100. uint32_t IC_TX_ABRT_SOURCE; /*!< (0x80) : IIC Transmit Abort Status Reg */
  101. uint32_t IC_SLV_DATA_NACK_ONLY; /*!< (0x84) : Generate SLV_DATA_NACK Register */
  102. uint32_t IC_DMA_CR; /*!< (0x88) : DMA Control Register */
  103. uint32_t IC_DMA_TDLR; /*!< (0x8c) : DMA Transmit Data Level */
  104. uint32_t IC_DMA_RDLR; /*!< (0x90) : DMA Receive Data Level */
  105. uint32_t IC_SDA_SETUP; /*!< (0x94) : SDA Setup Register */
  106. uint32_t IC_ACK_GENERAL_CALL; /*!< (0x98) : ACK General Call Register */
  107. uint32_t IC_ENABLE_STATUS; /*!< (0x9c) : Enable Status Register */
  108. uint32_t IC_FS_SPKLEN; /*!< (0xa0) : ISS and FS spike suppression limit */
  109. uint32_t IC_HS_SPKLEN; /*!< (0xa4) : HS spike suppression limit */
  110. uint32_t RESERVED[19]; /*!< (0xa8) : Reserved */
  111. uint32_t IC_COMP_PARAM_1; /*!< (0xf4) : Component Parameter Register */
  112. uint32_t IC_COMP_VERSION; /*!< (0xf8) : Component Version ID Reg */
  113. uint32_t IC_COMP_TYPE; /*!< (0xfc) : Component Type Reg */
  114. } DW_IIC_REG, *DW_IIC_REG_PTR;
  115. /** @} */
  116. /** Spike Suppression Limit Configurations */
  117. typedef struct dw_iic_spklen {
  118. uint32_t fs_spklen; /*!< value for IC_FS_SPKLEN, Tsp for fast mode is 50ns */
  119. uint32_t hs_spklen; /*!< value for IC_HS_SPKLEN, Tsp for high-speed mode is 10ns */
  120. } DW_IIC_SPKLEN, *DW_IIC_SPKLEN_PTR;
  121. /** IIC Clock SCL High and Low Count Configurations for Different Speed */
  122. typedef struct dw_iic_scl_cnt {
  123. uint32_t ss_scl_hcnt; /*!< value for IC_SS_SCL_HCNT */
  124. uint32_t ss_scl_lcnt; /*!< value for IC_SS_SCL_LCNT */
  125. uint32_t fs_scl_hcnt; /*!< value for IC_FS_SCL_HCNT */
  126. uint32_t fs_scl_lcnt; /*!< value for IC_FS_SCL_LCNT */
  127. uint32_t hs_scl_hcnt; /*!< value for IC_HS_SCL_HCNT */
  128. uint32_t hs_scl_lcnt; /*!< value for IC_HS_SCL_LCNT */
  129. } DW_IIC_SCL_CNT, *DW_IIC_SCL_CNT_PTR;
  130. #define DW_IIC_GINT_DISABLED (0) /*!< designware interrupt disabled for control iic irq/fiq */
  131. #define DW_IIC_GINT_ENABLE (1<<0) /*!< designware interrupt enabled for control iic irq/fiq */
  132. #define DW_IIC_TXINT_ENABLE (1<<1) /*!< designware interrupt enabled for control transmit process */
  133. #define DW_IIC_RXINT_ENABLE (1<<2) /*!< designware interrupt enabled for control transmit process */
  134. typedef struct dw_iic_buffer {
  135. DEV_BUFFER *buf;
  136. uint32_t ofs;
  137. uint32_t len;
  138. } DW_IIC_BUFFER, *DW_IIC_BUFFER_PTR;
  139. /**
  140. * \brief DesignWare IIC control structure definition
  141. * \details implement of dev_iic_info::iic_ctrl
  142. */
  143. typedef struct dw_iic_ctrl {
  144. DW_IIC_REG *dw_iic_regs; /*!< iic device registers */
  145. /* Variables which should be set during object implementation */
  146. uint32_t support_modes; /*!< supported iic modes */
  147. uint32_t tx_fifo_len; /*!< transmit fifo length */
  148. uint32_t rx_fifo_len; /*!< receive fifo length */
  149. uint32_t iic_master_code; /*!< value for IC_HS_MADDR */
  150. uint32_t retry_cnt; /*!< retry count for TX or RX */
  151. uint32_t intno; /*!< iic interrupt vector number */
  152. INT_HANDLER dw_iic_int_handler; /*!< iic interrupt handler */
  153. DW_IIC_SPKLEN iic_spklen; /*!< iic spike suppression length settings */
  154. DW_IIC_SCL_CNT iic_scl_cnt; /*!< iic scl count settings */
  155. /* Variables which always change during iic operation */
  156. uint32_t int_status; /*!< iic interrupt status */
  157. uint32_t iic_tx_over; /*!< iic tx overflow count */
  158. uint32_t iic_rx_over; /*!< iic rx overflow count */
  159. DW_IIC_BUFFER dw_iic_rxbuf; /*!< iic read buffer for receive data */
  160. } DW_IIC_CTRL, *DW_IIC_CTRL_PTR;
  161. /*!< One possible value for \ref dw_iic_ctrl::retry_cnt */
  162. #define DW_IIC_MAX_RETRY_COUNT (100000)
  163. #if DW_IIC_USE_IC_CLK_MHZ == 100 /*!< 100MHz */
  164. /*!< One possible value for \ref dw_iic_ctrl::iic_spklen */
  165. static const DW_IIC_SPKLEN dw_iic_spklen_const = {5, 1};
  166. /*!< One possible value for \ref dw_iic_ctrl::iic_spklen */
  167. #if DW_IIC_USE_HS_BUS_LOADING_100PF
  168. static const DW_IIC_SCL_CNT dw_iic_sclcnt_const = {0x0190, 0x01d6, 0x003c, 0x0082, 0x6, 0x10};
  169. #else
  170. static const DW_IIC_SCL_CNT dw_iic_sclcnt_const = {0x0190, 0x01d6, 0x003c, 0x0082, 0xc, 0x20};
  171. #endif
  172. #elif DW_IIC_USE_IC_CLK_MHZ == 50 /* 50MHz */
  173. /*!< One possible value for \ref dw_iic_ctrl::iic_spklen */
  174. static const DW_IIC_SPKLEN dw_iic_spklen_const = {5, 1};
  175. /*!< One possible value for \ref dw_iic_ctrl::iic_spklen */
  176. #if DW_IIC_USE_HS_BUS_LOADING_100PF
  177. static const DW_IIC_SCL_CNT dw_iic_sclcnt_const = {0x00c8, 0x00eb, 0x001e, 0x0041, 0x6, 0x8};
  178. #else
  179. static const DW_IIC_SCL_CNT dw_iic_sclcnt_const = {0x00c8, 0x00eb, 0x001e, 0x0041, 0x6, 0x10};
  180. #endif
  181. #else /* Default 100MHz */
  182. /*!< One possible value for \ref dw_iic_ctrl::iic_spklen */
  183. static const DW_IIC_SPKLEN dw_iic_spklen_const = {5, 1};
  184. /*!< One possible value for \ref dw_iic_ctrl::iic_spklen */
  185. #if DW_IIC_USE_HS_BUS_LOADING_100PF
  186. static const DW_IIC_SCL_CNT dw_iic_sclcnt_const = {0x0190, 0x01d6, 0x003c, 0x0082, 0x6, 0x10};
  187. #else
  188. static const DW_IIC_SCL_CNT dw_iic_sclcnt_const = {0x0190, 0x01d6, 0x003c, 0x0082, 0xc, 0x20};
  189. #endif
  190. #endif
  191. #ifdef __cplusplus
  192. extern "C" {
  193. #endif
  194. /**
  195. * \defgroup DEVICE_DW_IIC_FUNCDLR DesignWare IIC Function Declaration
  196. * \ingroup DEVICE_DW_IIC
  197. * \brief Contains declarations of designware iic functions.
  198. * \details This are only used in iic object implementation source file
  199. * @{
  200. */
  201. extern int32_t dw_iic_open (DEV_IIC *iic_obj, uint32_t mode, uint32_t param);
  202. extern int32_t dw_iic_close (DEV_IIC *iic_obj);
  203. extern int32_t dw_iic_control (DEV_IIC *iic_obj, uint32_t ctrl_cmd, void *param);
  204. extern int32_t dw_iic_write (DEV_IIC *iic_obj, const void *data, uint32_t len);
  205. extern int32_t dw_iic_read (DEV_IIC *iic_obj, void *data, uint32_t len);
  206. extern void dw_iic_isr(DEV_IIC *iic_obj, void *ptr);
  207. #ifdef __cplusplus
  208. }
  209. #endif
  210. /** @} */
  211. #endif /* _DW_IIC_H_ */