dw_iic_hal.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. * \ingroup DEVICE_DW_IIC
  31. * \brief DesignWare IIC driver hardware description related header file
  32. * \details detailed hardware related definitions of DesignWare IIC driver
  33. */
  34. #ifndef _DEVICE_DW_IIC_HAL_H_
  35. #define _DEVICE_DW_IIC_HAL_H_
  36. #include "device/designware/iic/dw_iic_hal_cfg.h"
  37. /** Enable Designware IIC */
  38. #define DW_IIC_ENABLE (1)
  39. /** Disable Designware IIC */
  40. #define DW_IIC_DISABLE (0)
  41. /** Stop Condition issue after this byte */
  42. #define IC_DATA_CMD_STOP (1 << 9)
  43. /** Restart Condition issue after this byte */
  44. #define IC_DATA_CMD_RESTART (1 << 10)
  45. /** No Restart or stop condition after this byte */
  46. #define IC_DATA_CMD_NONE (0)
  47. /** Perform a write request */
  48. #define IC_DATA_CMD_WRITE_REQ (0)
  49. /** Perform a read request */
  50. #define IC_DATA_CMD_READ_REQ (1 << 8)
  51. /** Fields of IC_CON register */
  52. /* DW_APB I2C IP Config Dependencies. */
  53. #if DW_IIC_ALLOW_RESTART
  54. #define IC_CON_RESTART_EN (1 << 5)
  55. #else
  56. #define IC_CON_RESTART_EN (0x00)
  57. #endif
  58. /* Master Addressing Mode Config */
  59. #if DW_IIC_MST_10_BIT_ADDR_SUPPORT
  60. #define MST_10_BIT_ADDR_MODE (1 << 4)
  61. #define IC_10BITADDR_MASTER (1 << 12)
  62. #else
  63. #define MST_10_BIT_ADDR_MODE (0x00)
  64. #define IC_10BITADDR_MASTER (0x00)
  65. #endif
  66. /* Slave Addressing Mode Config */
  67. #if DW_IIC_SLV_10_BIT_ADDR_SUPPORT
  68. #define SLV_10_BIT_ADDR_MODE (1 << 3)
  69. #else
  70. #define SLV_10_BIT_ADDR_MODE (0x00)
  71. #endif
  72. #if DW_IIC_SPECIAL_START_BYTE
  73. #define IC_TAR_SPECIAL (1 << 11)
  74. #define IC_TAR_GC_OR_START (1 << 10)
  75. #else
  76. #define IC_TAR_SPECIAL (0x00)
  77. #define IC_TAR_GC_OR_START (0x00)
  78. #endif
  79. /** 7bit IIC address mask for target address register */
  80. #define IC_TAR_7BIT_ADDR_MASK (0x7F)
  81. /** 7bit IIC address mask for slave address register */
  82. #define IC_SAR_7BIT_ADDR_MASK (0x7F)
  83. /** 10bit IIC address mask for target address register */
  84. #define IC_TAR_10BIT_ADDR_MASK (0x3FF)
  85. /** 10bit IIC address mask for slave address register */
  86. #define IC_SAR_10BIT_ADDR_MASK (0x3FF)
  87. /** Speed modes of IC_CON */
  88. #define IC_CON_SPEED_MASK (0x6)
  89. #define IC_CON_SPEED_STANDARD (0x2)
  90. #define IC_CON_SPEED_FAST (0x4)
  91. #define IC_CON_SPEED_HIGH (0x6)
  92. /** Working mode of IC_CON */
  93. #define IC_CON_MST_SLV_MODE_MASK (0x41)
  94. #define IC_CON_ENA_MASTER_MODE (0x41)
  95. #define IC_CON_ENA_SLAVE_MODE (0)
  96. /* IIC interrupt control */
  97. #define IC_INT_DISABLE_ALL (0x0)
  98. #define IC_INT_ENABLE_ALL (0x7FF)
  99. /* Interrupt Register Fields */
  100. #define IC_INTR_STAT_GEN_CALL (1 << 11)
  101. #define IC_INTR_STAT_START_DET (1 << 10)
  102. #define IC_INTR_STAT_STOP_DET (1 << 9)
  103. #define IC_INTR_STAT_ACTIVITY (1 << 8)
  104. #define IC_INTR_STAT_RX_DONE (1 << 7)
  105. #define IC_INTR_STAT_TX_ABRT (1 << 6)
  106. #define IC_INTR_STAT_RD_REQ (1 << 5)
  107. #define IC_INTR_STAT_TX_EMPTY (1 << 4)
  108. #define IC_INTR_STAT_TX_OVER (1 << 3)
  109. #define IC_INTR_STAT_RX_FULL (1 << 2)
  110. #define IC_INTR_STAT_RX_OVER (1 << 1)
  111. #define IC_INTR_STAT_RX_UNDER (1 << 0)
  112. /* Interrupt enable mask as master */
  113. #define IC_INT_MST_TX_ENABLE (IC_INTR_STAT_TX_EMPTY|IC_INTR_STAT_TX_OVER|IC_INTR_STAT_TX_ABRT)
  114. #define IC_INT_MST_RX_ENABLE (IC_INTR_STAT_TX_EMPTY|IC_INTR_STAT_RX_FULL|IC_INTR_STAT_RX_OVER|IC_INTR_STAT_RX_UNDER|IC_INTR_STAT_TX_ABRT)
  115. /* Interrupt enable mask as master */
  116. #define IC_INT_SLV_COMMON_ENABLE (IC_INTR_STAT_START_DET|IC_INTR_STAT_STOP_DET)
  117. #define IC_INT_SLV_TX_ENABLE (IC_INTR_STAT_RD_REQ|IC_INTR_STAT_TX_ABRT)
  118. #define IC_INT_SLV_RX_ENABLE (IC_INTR_STAT_RX_FULL|IC_INTR_STAT_RX_OVER|IC_INTR_STAT_RX_UNDER)
  119. /* IC_ENABLE_STATUS Bits */
  120. #define IC_ENABLE_STATUS_IC_EN (1 << 0)
  121. #define IC_ENABLE_STATUS_SLV_DIS (1 << 1)
  122. #define IC_ENABLE_STATUS_SLV_RX_LOST (1 << 2)
  123. /* IIC TX & RX threshold settings */
  124. #define IIC_TX_THRESHOLD (0)
  125. #define IIC_RX_THRESHOLD (0)
  126. /* DW_APB IIC (DW_IC_STATUS) Status Register Fields. */
  127. #define IC_STATUS_ACTIVITY (0x01)
  128. #define IC_STATUS_TFNF (0x02) /* (1 << 1) */
  129. #define IC_STATUS_TFE (0x04) /* (1 << 2) */
  130. #define IC_STATUS_RFNE (0x08) /* (1 << 3) */
  131. #define IC_STATUS_RFF (0x10) /* (1 << 4) */
  132. #define IC_STATUS_MASTER_ACT (0x20) /* (1 << 5) */
  133. #define IC_STATUS_SLAVE_ACT (0x40) /* (1 << 6) */
  134. /* IC_TX_ABRT_SOURCE Register Bit Fields */
  135. #define IC_TX_ABRT_7B_ADDR_NOACK (1 << 0)
  136. #define IC_TX_ABRT_10ADDR1_NOACK (1 << 1)
  137. #define IC_TX_ABRT_10ADDR2_NOACK (1 << 2)
  138. #define IC_TX_ABRT_TXDATA_NOACK (1 << 3)
  139. #define IC_TX_ABRT_GCALL_NOACK (1 << 4)
  140. #define IC_TX_ABRT_GCALL_READ (1 << 5)
  141. #define IC_TX_ABRT_HS_ACKDET (1 << 6)
  142. #define IC_TX_ABRT_SBYTE_ACKDET (1 << 7)
  143. #define IC_TX_ABRT_HS_NORSTRT (1 << 8)
  144. #define IC_TX_ABRT_SBYTE_NORSTRT (1 << 9)
  145. #define IC_TX_ABRT_10B_RD_NORSTRT (1 << 10)
  146. #define IC_TX_ABRT_MASTER_DIS (1 << 11)
  147. #define IC_TX_ABRT_ARB_LOST (1 << 12)
  148. #define IC_TX_ABRT_SLVFLUSH_TXFIFO (1 << 13)
  149. #define IC_TX_ABRT_SLV_ARBLOST (1 << 14)
  150. #define IC_TX_ABRT_SLVRD_INTX (1 << 15)
  151. /* Combined bits for iic abort source as master */
  152. #define IIC_MST_ABRT_ADDR_NOACK (IC_TX_ABRT_7B_ADDR_NOACK|IC_TX_ABRT_10ADDR1_NOACK|IC_TX_ABRT_10ADDR1_NOACK)
  153. #define IIC_MST_ABRT_LOST_BUS (IC_TX_ABRT_ARB_LOST)
  154. #define IIC_MST_ABRT_DATA_NOACK (IC_TX_ABRT_TXDATA_NOACK)
  155. /* Combined bits for iic abort source as slave */
  156. #define IIC_SLV_ABRT_LOST_BUS (IC_TX_ABRT_ARB_LOST|IC_TX_ABRT_SLV_ARBLOST)
  157. /** @} */
  158. #endif /* _DEVICE_DW_IIC_HAL_H_ */