i2c-designware-core.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Synopsys DesignWare I2C adapter driver (master only).
  3. *
  4. * Based on the TI DAVINCI I2C adapter driver.
  5. *
  6. * Copyright (C) 2006 Texas Instruments.
  7. * Copyright (C) 2007 MontaVista Software Inc.
  8. * Copyright (C) 2009 Provigent Ltd.
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. * ----------------------------------------------------------------------------
  26. *
  27. */
  28. /*
  29. * Registers offset
  30. */
  31. #define DW_IC_CON 0x0
  32. #define DW_IC_TAR 0x4
  33. #define DW_IC_DATA_CMD 0x10
  34. #define DW_IC_SS_SCL_HCNT 0x14
  35. #define DW_IC_SS_SCL_LCNT 0x18
  36. #define DW_IC_FS_SCL_HCNT 0x1c
  37. #define DW_IC_FS_SCL_LCNT 0x20
  38. #define DW_IC_INTR_STAT 0x2c
  39. #define DW_IC_INTR_MASK 0x30
  40. #define DW_IC_RAW_INTR_STAT 0x34
  41. #define DW_IC_RX_TL 0x38
  42. #define DW_IC_TX_TL 0x3c
  43. #define DW_IC_CLR_INTR 0x40
  44. #define DW_IC_CLR_RX_UNDER 0x44
  45. #define DW_IC_CLR_RX_OVER 0x48
  46. #define DW_IC_CLR_TX_OVER 0x4c
  47. #define DW_IC_CLR_RD_REQ 0x50
  48. #define DW_IC_CLR_TX_ABRT 0x54
  49. #define DW_IC_CLR_RX_DONE 0x58
  50. #define DW_IC_CLR_ACTIVITY 0x5c
  51. #define DW_IC_CLR_STOP_DET 0x60
  52. #define DW_IC_CLR_START_DET 0x64
  53. #define DW_IC_CLR_GEN_CALL 0x68
  54. #define DW_IC_ENABLE 0x6c
  55. #define DW_IC_STATUS 0x70
  56. #define DW_IC_TXFLR 0x74
  57. #define DW_IC_RXFLR 0x78
  58. #define DW_IC_TX_ABRT_SOURCE 0x80
  59. #define DW_IC_COMP_PARAM_1 0xf4
  60. #define DW_IC_COMP_TYPE 0xfc
  61. #define DW_IC_COMP_TYPE_VALUE 0x44570140
  62. #define DW_IC_CON_MASTER 0x1
  63. #define DW_IC_CON_SPEED_STD 0x2
  64. #define DW_IC_CON_SPEED_FAST 0x4
  65. #define DW_IC_CON_10BITADDR_MASTER 0x10
  66. #define DW_IC_CON_RESTART_EN 0x20
  67. #define DW_IC_CON_SLAVE_DISABLE 0x40
  68. #define DW_IC_INTR_RX_UNDER 0x001
  69. #define DW_IC_INTR_RX_OVER 0x002
  70. #define DW_IC_INTR_RX_FULL 0x004
  71. #define DW_IC_INTR_TX_OVER 0x008
  72. #define DW_IC_INTR_TX_EMPTY 0x010
  73. #define DW_IC_INTR_RD_REQ 0x020
  74. #define DW_IC_INTR_TX_ABRT 0x040
  75. #define DW_IC_INTR_RX_DONE 0x080
  76. #define DW_IC_INTR_ACTIVITY 0x100
  77. #define DW_IC_INTR_STOP_DET 0x200
  78. #define DW_IC_INTR_START_DET 0x400
  79. #define DW_IC_INTR_GEN_CALL 0x800
  80. #define DW_IC_INTR_DEFAULT_MASK (DW_IC_INTR_RX_FULL | \
  81. DW_IC_INTR_TX_EMPTY | \
  82. DW_IC_INTR_TX_ABRT | \
  83. DW_IC_INTR_STOP_DET)
  84. #define DW_IC_STATUS_ACTIVITY 0x1
  85. #define DW_IC_ERR_TX_ABRT 0x1
  86. /*
  87. * status codes
  88. */
  89. #define STATUS_IDLE 0x0
  90. #define STATUS_WRITE_IN_PROGRESS 0x1
  91. #define STATUS_READ_IN_PROGRESS 0x2
  92. #define TIMEOUT 20 /* ms */
  93. /*
  94. * hardware abort codes from the DW_IC_TX_ABRT_SOURCE register
  95. *
  96. * only expected abort codes are listed here
  97. * refer to the datasheet for the full list
  98. */
  99. #define ABRT_7B_ADDR_NOACK 0
  100. #define ABRT_10ADDR1_NOACK 1
  101. #define ABRT_10ADDR2_NOACK 2
  102. #define ABRT_TXDATA_NOACK 3
  103. #define ABRT_GCALL_NOACK 4
  104. #define ABRT_GCALL_READ 5
  105. #define ABRT_SBYTE_ACKDET 7
  106. #define ABRT_SBYTE_NORSTRT 9
  107. #define ABRT_10B_RD_NORSTRT 10
  108. #define ABRT_MASTER_DIS 11
  109. #define ARB_LOST 12
  110. #define DW_IC_TX_ABRT_7B_ADDR_NOACK (1UL << ABRT_7B_ADDR_NOACK)
  111. #define DW_IC_TX_ABRT_10ADDR1_NOACK (1UL << ABRT_10ADDR1_NOACK)
  112. #define DW_IC_TX_ABRT_10ADDR2_NOACK (1UL << ABRT_10ADDR2_NOACK)
  113. #define DW_IC_TX_ABRT_TXDATA_NOACK (1UL << ABRT_TXDATA_NOACK)
  114. #define DW_IC_TX_ABRT_GCALL_NOACK (1UL << ABRT_GCALL_NOACK)
  115. #define DW_IC_TX_ABRT_GCALL_READ (1UL << ABRT_GCALL_READ)
  116. #define DW_IC_TX_ABRT_SBYTE_ACKDET (1UL << ABRT_SBYTE_ACKDET)
  117. #define DW_IC_TX_ABRT_SBYTE_NORSTRT (1UL << ABRT_SBYTE_NORSTRT)
  118. #define DW_IC_TX_ABRT_10B_RD_NORSTRT (1UL << ABRT_10B_RD_NORSTRT)
  119. #define DW_IC_TX_ABRT_MASTER_DIS (1UL << ABRT_MASTER_DIS)
  120. #define DW_IC_TX_ARB_LOST (1UL << ARB_LOST)
  121. #define DW_IC_TX_ABRT_NOACK (DW_IC_TX_ABRT_7B_ADDR_NOACK | \
  122. DW_IC_TX_ABRT_10ADDR1_NOACK | \
  123. DW_IC_TX_ABRT_10ADDR2_NOACK | \
  124. DW_IC_TX_ABRT_TXDATA_NOACK | \
  125. DW_IC_TX_ABRT_GCALL_NOACK)
  126. /**
  127. * struct dw_i2c_dev - private i2c-designware data
  128. * @dev: driver model device node
  129. * @base: IO registers pointer
  130. * @cmd_complete: tx completion indicator
  131. * @lock: protect this struct and IO registers
  132. * @clk: input reference clock
  133. * @cmd_err: run time hadware error code
  134. * @msgs: points to an array of messages currently being transfered
  135. * @msgs_num: the number of elements in msgs
  136. * @msg_write_idx: the element index of the current tx message in the msgs
  137. * array
  138. * @tx_buf_len: the length of the current tx buffer
  139. * @tx_buf: the current tx buffer
  140. * @msg_read_idx: the element index of the current rx message in the msgs
  141. * array
  142. * @rx_buf_len: the length of the current rx buffer
  143. * @rx_buf: the current rx buffer
  144. * @msg_err: error status of the current transfer
  145. * @status: i2c master status, one of STATUS_*
  146. * @abort_source: copy of the TX_ABRT_SOURCE register
  147. * @irq: interrupt number for the i2c master
  148. * @adapter: i2c subsystem adapter node
  149. * @tx_fifo_depth: depth of the hardware tx fifo
  150. * @rx_fifo_depth: depth of the hardware rx fifo
  151. */
  152. struct dw_i2c_dev {
  153. struct device *dev;
  154. void __iomem *base;
  155. struct completion cmd_complete;
  156. struct mutex lock;
  157. struct clk *clk;
  158. int cmd_err;
  159. struct i2c_msg *msgs;
  160. int msgs_num;
  161. int msg_write_idx;
  162. u32 tx_buf_len;
  163. u8 *tx_buf;
  164. int msg_read_idx;
  165. u32 rx_buf_len;
  166. u8 *rx_buf;
  167. int msg_err;
  168. unsigned int status;
  169. u32 abort_source;
  170. int irq;
  171. int swab;
  172. struct i2c_adapter adapter;
  173. unsigned int tx_fifo_depth;
  174. unsigned int rx_fifo_depth;
  175. };
  176. extern u32 dw_readl(struct dw_i2c_dev *dev, int offset);
  177. extern void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset);
  178. extern int i2c_dw_init(struct dw_i2c_dev *dev);
  179. extern int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
  180. int num);
  181. extern u32 i2c_dw_func(struct i2c_adapter *adap);
  182. extern irqreturn_t i2c_dw_isr(int this_irq, void *dev_id);