iproc_i2c.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2018 Broadcom
  4. *
  5. */
  6. #ifndef __IPROC_I2C_H__
  7. #define __IPROC_I2C_H__
  8. /* Registers */
  9. #define CCB_SMB_CFG_REG 0x0
  10. #define CCB_SMB_CFG_RST_MASK 0x80000000
  11. #define CCB_SMB_CFG_RST_SHIFT 31
  12. #define CCB_SMB_CFG_SMBEN_MASK 0x40000000
  13. #define CCB_SMB_CFG_SMBEN_SHIFT 30
  14. #define CCB_SMB_CFG_BITBANGEN_MASK 0x20000000
  15. #define CCB_SMB_CFG_BITBANGEN_SHIFT 29
  16. #define CCB_SMB_CFG_EN_NIC_SMBADDR0_MASK 0x10000000
  17. #define CCB_SMB_CFG_EN_NIC_SMBADDR0_SHIFT 28
  18. #define CCB_SMB_CFG_PROMISCMODE_MASK 0x08000000
  19. #define CCB_SMB_CFG_PROMISCMODE_SHIFT 27
  20. #define CCB_SMB_CFG_TSTMPCNTEN_MASK 0x04000000
  21. #define CCB_SMB_CFG_TSTMPCNTEN_SHIFT 26
  22. #define CCB_SMB_CFG_MSTRRTRYCNT_MASK 0x000F0000
  23. #define CCB_SMB_CFG_MSTRRTRYCNT_SHIFT 16
  24. #define CCB_SMB_TIMGCFG_REG 0x4
  25. #define CCB_SMB_TIMGCFG_MODE400_MASK 0x80000000
  26. #define CCB_SMB_TIMGCFG_MODE400_SHIFT 31
  27. #define CCB_SMB_TIMGCFG_RNDSLVSTR_MASK 0x7F000000
  28. #define CCB_SMB_TIMGCFG_RNDSLVSTR_SHIFT 24
  29. #define CCB_SMB_TIMGCFG_PERSLVSTR_MASK 0x00FF0000
  30. #define CCB_SMB_TIMGCFG_PERSLVSTR_SHIFT 16
  31. #define CCB_SMB_TIMGCFG_IDLTIME_MASK 0x0000FF00
  32. #define CCB_SMB_TIMGCFG_IDLTIME_SHIFT 8
  33. #define CCB_SMB_ADDR_REG 0x8
  34. #define CCB_SMB_EN_NIC_SMBADDR3_MASK 0x80000000
  35. #define CCB_SMB_EN_NIC_SMBADDR3_SHIFT 31
  36. #define CCB_SMB_NIC_SMBADDR3_MASK 0x7F000000
  37. #define CCB_SMB_NIC_SMBADDR3_SHIFT 24
  38. #define CCB_SMB_EN_NIC_SMBADDR2_MASK 0x00800000
  39. #define CCB_SMB_EN_NIC_SMBADDR2_SHIFT 23
  40. #define CCB_SMB_NIC_SMBADDR2_MASK 0x007F0000
  41. #define CCB_SMB_NIC_SMBADDR2_SHIFT 16
  42. #define CCB_SMB_EN_NIC_SMBADDR1_MASK 0x00008000
  43. #define CCB_SMB_EN_NIC_SMBADDR1_SHIFT 15
  44. #define CCB_SMB_NIC_SMBADDR1_MASK 0x00007F00
  45. #define CCB_SMB_NIC_SMBADDR1_SHIFT 8
  46. #define CCB_SMB_EN_NIC_SMBADDR0_MASK 0x00000080
  47. #define CCB_SMB_EN_NIC_SMBADDR0_SHIFT 7
  48. #define CCB_SMB_NIC_SMBADDR0_MASK 0x0000007F
  49. #define CCB_SMB_NIC_SMBADDR0_SHIFT 0
  50. #define CCB_SMB_MSTRFIFOCTL_REG 0xC
  51. #define CCB_SMB_MSTRRXFIFOFLSH_MASK 0x80000000
  52. #define CCB_SMB_MSTRRXFIFOFLSH_SHIFT 31
  53. #define CCB_SMB_MSTRTXFIFOFLSH_MASK 0x40000000
  54. #define CCB_SMB_MSTRTXFIFOFLSH_SHIFT 30
  55. #define CCB_SMB_MSTRRXPKTCNT_MASK 0x007F0000
  56. #define CCB_SMB_MSTRRXPKTCNT_SHIFT 16
  57. #define CCB_SMB_MSTRRXFIFOTHR_MASK 0x00003F00
  58. #define CCB_SMB_MSTRRXFIFOTHR_SHIFT 8
  59. #define CCB_SMB_SLVFIFOCTL_REG 0x10
  60. #define CCB_SMB_SLVRXFIFOFLSH_MASK 0x80000000
  61. #define CCB_SMB_SLVRXFIFOFLSH_SHIFT 31
  62. #define CCB_SMB_SLVTXFIFOFLSH_MASK 0x40000000
  63. #define CCB_SMB_SLVTXFIFOFLSH_SHIFT 30
  64. #define CCB_SMB_SLVRXPKTCNT_MASK 0x007F0000
  65. #define CCB_SMB_SLVRXPKTCNT_SHIFT 16
  66. #define CCB_SMB_SLVRXFIFOTHR_MASK 0x00003F00
  67. #define CCB_SMB_SLVRXFIFOTHR_SHIFT 8
  68. #define CCB_SMB_BITBANGCTL_REG 0x14
  69. #define CCB_SMB_SMBCLKIN_MASK 0x80000000
  70. #define CCB_SMB_SMBCLKIN_SHIFT 31
  71. #define CCB_SMB_SMBCLKOUTEN_MASK 0x40000000
  72. #define CCB_SMB_SMBCLKOUTEN_SHIFT 30
  73. #define CCB_SMB_SMBDATAIN_MASK 0x20000000
  74. #define CCB_SMB_SMBDATAIN_SHIFT 29
  75. #define CCB_SMB_SMBDATAOUTEN_MASK 0x10000000
  76. #define CCB_SMB_SMBDATAOUTEN_SHIFT 28
  77. #define CCB_SMB_MSTRCMD_REG 0x30
  78. #define CCB_SMB_MSTRSTARTBUSYCMD_MASK 0x80000000
  79. #define CCB_SMB_MSTRSTARTBUSYCMD_SHIFT 31
  80. #define CCB_SMB_MSTRABORT_MASK 0x40000000
  81. #define CCB_SMB_MSTRABORT_SHIFT 30
  82. #define CCB_SMB_MSTRSTS_MASK 0x0E000000
  83. #define CCB_SMB_MSTRSTS_SHIFT 25
  84. #define CCB_SMB_MSTRSMBUSPROTO_MASK 0x00001E00
  85. #define CCB_SMB_MSTRSMBUSPROTO_SHIFT 9
  86. #define CCB_SMB_MSTRPEC_MASK 0x00000100
  87. #define CCB_SMB_MSTRPEC_SHIFT 8
  88. #define CCB_SMB_MSTRRDBYTECNT_MASK 0x000000FF
  89. #define CCB_SMB_MSTRRDBYTECNT_SHIFT 0
  90. #define CCB_SMB_SLVCMD_REG 0x34
  91. #define CCB_SMB_SLVSTARTBUSYCMD_MASK 0x80000000
  92. #define CCB_SMB_SLVSTARTBUSYCMD_SHIFT 31
  93. #define CCB_SMB_SLVABORT_MASK 0x40000000
  94. #define CCB_SMB_SLVABORT_SHIFT 30
  95. #define CCB_SMB_SLVSTS_MASK 0x03800000
  96. #define CCB_SMB_SLVSTS_SHIFT 23
  97. #define CCB_SMB_SLVPEC_MASK 0x00000100
  98. #define CCB_SMB_SLVPEC_SHIFT 8
  99. #define CCB_SMB_EVTEN_REG 0x38
  100. #define CCB_SMB_MSTRRXFIFOFULLEN_MASK 0x80000000
  101. #define CCB_SMB_MSTRRXFIFOFULLEN_SHIFT 31
  102. #define CCB_SMB_MSTRRXFIFOTHRHITEN_MASK 0x40000000
  103. #define CCB_SMB_MSTRRXFIFOTHRHITEN_SHIFT 30
  104. #define CCB_SMB_MSTRRXEVTEN_MASK 0x20000000
  105. #define CCB_SMB_MSTRRXEVTEN_SHIFT 29
  106. #define CCB_SMB_MSTRSTARTBUSYEN_MASK 0x10000000
  107. #define CCB_SMB_MSTRSTARTBUSYEN_SHIFT 28
  108. #define CCB_SMB_MSTRTXUNDEN_MASK 0x08000000
  109. #define CCB_SMB_MSTRTXUNDEN_SHIFT 27
  110. #define CCB_SMB_SLVRXFIFOFULLEN_MASK 0x04000000
  111. #define CCB_SMB_SLVRXFIFOFULLEN_SHIFT 26
  112. #define CCB_SMB_SLVRXFIFOTHRHITEN_MASK 0x02000000
  113. #define CCB_SMB_SLVRXFIFOTHRHITEN_SHIFT 25
  114. #define CCB_SMB_SLVRXEVTEN_MASK 0x01000000
  115. #define CCB_SMB_SLVRXEVTEN_SHIFT 24
  116. #define CCB_SMB_SLVSTARTBUSYEN_MASK 0x00800000
  117. #define CCB_SMB_SLVSTARTBUSYEN_SHIFT 23
  118. #define CCB_SMB_SLVTXUNDEN_MASK 0x00400000
  119. #define CCB_SMB_SLVTXUNDEN_SHIFT 22
  120. #define CCB_SMB_SLVRDEVTEN_MASK 0x00200000
  121. #define CCB_SMB_SLVRDEVTEN_SHIFT 21
  122. #define CCB_SMB_EVTSTS_REG 0x3C
  123. #define CCB_SMB_MSTRRXFIFOFULLSTS_MASK 0x80000000
  124. #define CCB_SMB_MSTRRXFIFOFULLSTS_SHIFT 31
  125. #define CCB_SMB_MSTRRXFIFOTHRHITSTS_MASK 0x40000000
  126. #define CCB_SMB_MSTRRXFIFOTHRHITSTS_SHIFT 30
  127. #define CCB_SMB_MSTRRXEVTSTS_MASK 0x20000000
  128. #define CCB_SMB_MSTRRXEVTSTS_SHIFT 29
  129. #define CCB_SMB_MSTRSTARTBUSYSTS_MASK 0x10000000
  130. #define CCB_SMB_MSTRSTARTBUSYSTS_SHIFT 28
  131. #define CCB_SMB_MSTRTXUNDSTS_MASK 0x08000000
  132. #define CCB_SMB_MSTRTXUNDSTS_SHIFT 27
  133. #define CCB_SMB_SLVRXFIFOFULLSTS_MASK 0x04000000
  134. #define CCB_SMB_SLVRXFIFOFULLSTS_SHIFT 26
  135. #define CCB_SMB_SLVRXFIFOTHRHITSTS_MASK 0x02000000
  136. #define CCB_SMB_SLVRXFIFOTHRHITSTS_SHIFT 25
  137. #define CCB_SMB_SLVRXEVTSTS_MASK 0x01000000
  138. #define CCB_SMB_SLVRXEVTSTS_SHIFT 24
  139. #define CCB_SMB_SLVSTARTBUSYSTS_MASK 0x00800000
  140. #define CCB_SMB_SLVSTARTBUSYSTS_SHIFT 23
  141. #define CCB_SMB_SLVTXUNDSTS_MASK 0x00400000
  142. #define CCB_SMB_SLVTXUNDSTS_SHIFT 22
  143. #define CCB_SMB_SLVRDEVTSTS_MASK 0x00200000
  144. #define CCB_SMB_SLVRDEVTSTS_SHIFT 21
  145. #define CCB_SMB_MSTRDATAWR_REG 0x40
  146. #define CCB_SMB_MSTRWRSTS_MASK 0x80000000
  147. #define CCB_SMB_MSTRWRSTS_SHIFT 31
  148. #define CCB_SMB_MSTRWRDATA_MASK 0x000000FF
  149. #define CCB_SMB_MSTRWRDATA_SHIFT 0
  150. #define CCB_SMB_MSTRDATARD_REG 0x44
  151. #define CCB_SMB_MSTRRDSTS_MASK 0xC0000000
  152. #define CCB_SMB_MSTRRDSTS_SHIFT 30
  153. #define CCB_SMB_MSTRRDPECERR_MASK 0x20000000
  154. #define CCB_SMB_MSTRRDPECERR_SHIFT 29
  155. #define CCB_SMB_MSTRRDDATA_MASK 0x000000FF
  156. #define CCB_SMB_MSTRRDDATA_SHIFT 0
  157. #define CCB_SMB_SLVDATAWR_REG 0x48
  158. #define CCB_SMB_SLVWRSTS_MASK 0x80000000
  159. #define CCB_SMB_SLVWRSTS_SHIFT 31
  160. #define CCB_SMB_SLVWRDATA_MASK 0x000000FF
  161. #define CCB_SMB_SLVWRDATA_SHIFT 0
  162. #define CCB_SMB_SLVDATARD_REG 0x4C
  163. #define CCB_SMB_SLVRDSTS_MASK 0xC0000000
  164. #define CCB_SMB_SLVRDSTS_SHIFT 30
  165. #define CCB_SMB_SLVRDERRSTS_MASK 0x30000000
  166. #define CCB_SMB_SLVRDERRSTS_SHIFT 28
  167. #define CCB_SMB_SLVRDDATA_MASK 0x000000FF
  168. #define CCB_SMB_SLVRDDATA_SHIFT 0
  169. /* --Registers-- */
  170. /* Transaction error codes defined in Master command register (0x30) */
  171. #define MSTR_STS_XACT_SUCCESS 0
  172. #define MSTR_STS_LOST_ARB 1
  173. #define MSTR_STS_NACK_FIRST_BYTE 2
  174. /* NACK on a byte other than
  175. * the first byte
  176. */
  177. #define MSTR_STS_NACK_NON_FIRST_BYTE 3
  178. #define MSTR_STS_TTIMEOUT_EXCEEDED 4
  179. #define MSTR_STS_TX_TLOW_MEXT_EXCEEDED 5
  180. #define MSTR_STS_RX_TLOW_MEXT_EXCEEDED 6
  181. /* SMBUS protocol values defined in register 0x30 */
  182. #define SMBUS_PROT_QUICK_CMD 0
  183. #define SMBUS_PROT_SEND_BYTE 1
  184. #define SMBUS_PROT_RECV_BYTE 2
  185. #define SMBUS_PROT_WR_BYTE 3
  186. #define SMBUS_PROT_RD_BYTE 4
  187. #define SMBUS_PROT_WR_WORD 5
  188. #define SMBUS_PROT_RD_WORD 6
  189. #define SMBUS_PROT_BLK_WR 7
  190. #define SMBUS_PROT_BLK_RD 8
  191. #define SMBUS_PROT_PROC_CALL 9
  192. #define SMBUS_PROT_BLK_WR_BLK_RD_PROC_CALL 10
  193. /* SMBUS Block speed mode */
  194. #define SMBUS_BLOCK_MODE_100 0
  195. #define SMBUS_BLOCK_MODE_400 1
  196. #define BUS_BUSY_COUNT 100000 /* Number can be changed later */
  197. #define IPROC_I2C_INVALID_ADDR 0xFF
  198. #define IPROC_SMB_MAX_RETRIES 35
  199. #define I2C_SMBUS_BLOCK_MAX 32
  200. #define GETREGFLDVAL(regval, mask, startbit) \
  201. (((regval) & (mask)) >> (startbit))
  202. /* This enum will be used to notify the user of status of a data transfer
  203. * request
  204. */
  205. enum iproc_smb_error_code {
  206. I2C_NO_ERR = 0,
  207. I2C_TIMEOUT_ERR = 1,
  208. /* Invalid parameter(s) passed to the driver */
  209. I2C_INVALID_PARAM_ERR = 2,
  210. /* The driver API was called before the present
  211. * transfer was completed
  212. */
  213. I2C_OPER_IN_PROGRESS = 3,
  214. /* Transfer aborted unexpectedly, for example a NACK
  215. * received, before last byte was read/written
  216. */
  217. I2C_OPER_ABORT_ERR = 4,
  218. /* Feature or function not supported
  219. * (e.g., 10-bit addresses, or clock speeds
  220. * other than 100KHz, 400KHz)
  221. */
  222. I2C_FUNC_NOT_SUPPORTED = 5,
  223. };
  224. /* Structure used to pass information to read/write functions. */
  225. struct iproc_xact_info {
  226. unsigned char command;
  227. unsigned char *data;
  228. unsigned int size;
  229. unsigned short flags; /* used for specifying PEC, 10-bit addresses */
  230. unsigned char smb_proto; /* SMBus protocol */
  231. unsigned int cmd_valid; /* true if command is valid else false */
  232. };
  233. #endif /* __IPROC_I2C_H__ */