i2c.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * (C) Copyright 2004-2008
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _I2C_H_
  24. #define _I2C_H_
  25. #define I2C_DEFAULT_BASE I2C_BASE1
  26. struct i2c {
  27. unsigned short rev; /* 0x00 */
  28. unsigned short res1;
  29. unsigned short ie; /* 0x04 */
  30. unsigned short res2;
  31. unsigned short stat; /* 0x08 */
  32. unsigned short res3;
  33. unsigned short iv; /* 0x0C */
  34. unsigned short res4[3];
  35. unsigned short buf; /* 0x14 */
  36. unsigned short res5;
  37. unsigned short cnt; /* 0x18 */
  38. unsigned short res6;
  39. unsigned short data; /* 0x1C */
  40. unsigned short res7;
  41. unsigned short sysc; /* 0x20 */
  42. unsigned short res8;
  43. unsigned short con; /* 0x24 */
  44. unsigned short res9;
  45. unsigned short oa; /* 0x28 */
  46. unsigned short res10;
  47. unsigned short sa; /* 0x2C */
  48. unsigned short res11;
  49. unsigned short psc; /* 0x30 */
  50. unsigned short res12;
  51. unsigned short scll; /* 0x34 */
  52. unsigned short res13;
  53. unsigned short sclh; /* 0x38 */
  54. unsigned short res14;
  55. unsigned short systest; /* 0x3c */
  56. unsigned short res15;
  57. };
  58. #define I2C_BUS_MAX 3
  59. /* I2C masks */
  60. /* I2C Interrupt Enable Register (I2C_IE): */
  61. #define I2C_IE_GC_IE (1 << 5)
  62. #define I2C_IE_XRDY_IE (1 << 4) /* Transmit data ready interrupt enable */
  63. #define I2C_IE_RRDY_IE (1 << 3) /* Receive data ready interrupt enable */
  64. #define I2C_IE_ARDY_IE (1 << 2) /* Register access ready interrupt enable */
  65. #define I2C_IE_NACK_IE (1 << 1) /* No acknowledgment interrupt enable */
  66. #define I2C_IE_AL_IE (1 << 0) /* Arbitration lost interrupt enable */
  67. /* I2C Status Register (I2C_STAT): */
  68. #define I2C_STAT_SBD (1 << 15) /* Single byte data */
  69. #define I2C_STAT_BB (1 << 12) /* Bus busy */
  70. #define I2C_STAT_ROVR (1 << 11) /* Receive overrun */
  71. #define I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
  72. #define I2C_STAT_AAS (1 << 9) /* Address as slave */
  73. #define I2C_STAT_GC (1 << 5)
  74. #define I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
  75. #define I2C_STAT_RRDY (1 << 3) /* Receive data ready */
  76. #define I2C_STAT_ARDY (1 << 2) /* Register access ready */
  77. #define I2C_STAT_NACK (1 << 1) /* No acknowledgment interrupt enable */
  78. #define I2C_STAT_AL (1 << 0) /* Arbitration lost interrupt enable */
  79. /* I2C Interrupt Code Register (I2C_INTCODE): */
  80. #define I2C_INTCODE_MASK 7
  81. #define I2C_INTCODE_NONE 0
  82. #define I2C_INTCODE_AL 1 /* Arbitration lost */
  83. #define I2C_INTCODE_NAK 2 /* No acknowledgement/general call */
  84. #define I2C_INTCODE_ARDY 3 /* Register access ready */
  85. #define I2C_INTCODE_RRDY 4 /* Rcv data ready */
  86. #define I2C_INTCODE_XRDY 5 /* Xmit data ready */
  87. /* I2C Buffer Configuration Register (I2C_BUF): */
  88. #define I2C_BUF_RDMA_EN (1 << 15) /* Receive DMA channel enable */
  89. #define I2C_BUF_XDMA_EN (1 << 7) /* Transmit DMA channel enable */
  90. /* I2C Configuration Register (I2C_CON): */
  91. #define I2C_CON_EN (1 << 15) /* I2C module enable */
  92. #define I2C_CON_BE (1 << 14) /* Big endian mode */
  93. #define I2C_CON_STB (1 << 11) /* Start byte mode (master mode only) */
  94. #define I2C_CON_MST (1 << 10) /* Master/slave mode */
  95. #define I2C_CON_TRX (1 << 9) /* Transmitter/receiver mode */
  96. /* (master mode only) */
  97. #define I2C_CON_XA (1 << 8) /* Expand address */
  98. #define I2C_CON_STP (1 << 1) /* Stop condition (master mode only) */
  99. #define I2C_CON_STT (1 << 0) /* Start condition (master mode only) */
  100. /* I2C System Test Register (I2C_SYSTEST): */
  101. #define I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */
  102. #define I2C_SYSTEST_FREE (1 << 14) /* Free running mode, on brkpoint) */
  103. #define I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
  104. #define I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */
  105. #define I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense input value */
  106. #define I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive output value */
  107. #define I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense input value */
  108. #define I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive output value */
  109. #define I2C_SCLL_SCLL 0
  110. #define I2C_SCLL_SCLL_M 0xFF
  111. #define I2C_SCLL_HSSCLL 8
  112. #define I2C_SCLH_HSSCLL_M 0xFF
  113. #define I2C_SCLH_SCLH 0
  114. #define I2C_SCLH_SCLH_M 0xFF
  115. #define I2C_SCLH_HSSCLH 8
  116. #define I2C_SCLH_HSSCLH_M 0xFF
  117. #define OMAP_I2C_STANDARD 100000
  118. #define OMAP_I2C_FAST_MODE 400000
  119. #define OMAP_I2C_HIGH_SPEED 3400000
  120. #define SYSTEM_CLOCK_12 12000000
  121. #define SYSTEM_CLOCK_13 13000000
  122. #define SYSTEM_CLOCK_192 19200000
  123. #define SYSTEM_CLOCK_96 96000000
  124. /* Use the reference value of 96MHz if not explicitly set by the board */
  125. #ifndef I2C_IP_CLK
  126. #define I2C_IP_CLK SYSTEM_CLOCK_96
  127. #endif
  128. /*
  129. * The reference minimum clock for high speed is 19.2MHz.
  130. * The linux 2.6.30 kernel uses this value.
  131. * The reference minimum clock for fast mode is 9.6MHz
  132. * The reference minimum clock for standard mode is 4MHz
  133. * In TRM, the value of 12MHz is used.
  134. */
  135. #ifndef I2C_INTERNAL_SAMPLING_CLK
  136. #define I2C_INTERNAL_SAMPLING_CLK 19200000
  137. #endif
  138. /*
  139. * The equation for the low and high time is
  140. * tlow = scll + scll_trim = (sampling clock * tlow_duty) / speed
  141. * thigh = sclh + sclh_trim = (sampling clock * (1 - tlow_duty)) / speed
  142. *
  143. * If the duty cycle is 50%
  144. *
  145. * tlow = scll + scll_trim = sampling clock / (2 * speed)
  146. * thigh = sclh + sclh_trim = sampling clock / (2 * speed)
  147. *
  148. * In TRM
  149. * scll_trim = 7
  150. * sclh_trim = 5
  151. *
  152. * The linux 2.6.30 kernel uses
  153. * scll_trim = 6
  154. * sclh_trim = 6
  155. *
  156. * These are the trim values for standard and fast speed
  157. */
  158. #ifndef I2C_FASTSPEED_SCLL_TRIM
  159. #define I2C_FASTSPEED_SCLL_TRIM 6
  160. #endif
  161. #ifndef I2C_FASTSPEED_SCLH_TRIM
  162. #define I2C_FASTSPEED_SCLH_TRIM 6
  163. #endif
  164. /* These are the trim values for high speed */
  165. #ifndef I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM
  166. #define I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM I2C_FASTSPEED_SCLL_TRIM
  167. #endif
  168. #ifndef I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM
  169. #define I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM I2C_FASTSPEED_SCLH_TRIM
  170. #endif
  171. #ifndef I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM
  172. #define I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM I2C_FASTSPEED_SCLL_TRIM
  173. #endif
  174. #ifndef I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM
  175. #define I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM I2C_FASTSPEED_SCLH_TRIM
  176. #endif
  177. #define I2C_PSC_MAX 0x0f
  178. #define I2C_PSC_MIN 0x00
  179. #endif /* _I2C_H_ */