1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #define I2C_DW_COMP_TYPE_NUM    0x44570140
8 #define I2C_DW_MAX_TRANSFER     64 // Local buffer for transfer and receive. Matches FIFO size
9 #define I2C_ERROR_SIGNAL        ZX_USER_SIGNAL_0
10 #define I2C_TXN_COMPLETE_SIGNAL ZX_USER_SIGNAL_1
11 
12 #define I2C_DW_READ32(a)        readl(dev->regs_iobuff.vaddr + a)
13 #define I2C_DW_WRITE32(a, v)    writel(v, dev->regs_iobuff.vaddr + a)
14 
15 #define I2C_DW_MASK(start, count) (((1 << (count)) - 1) << (start))
16 #define I2C_DW_GET_BITS32(src, start, count) ((I2C_DW_READ32(src) & I2C_DW_MASK(start, count)) >> (start))
17 #define I2C_DW_SET_BITS32(dest, start, count, value) \
18             I2C_DW_WRITE32(dest, (I2C_DW_READ32(dest) & ~I2C_DW_MASK(start, count)) | \
19                                 (((value) << (start)) & I2C_DW_MASK(start, count)))
20 #define I2C_DW_SET_MASK(mask, start, count, value) \
21                         ((mask & ~I2C_DW_MASK(start, count)) | \
22                                 (((value) << (start)) & I2C_DW_MASK(start, count)))
23 
24 #define I2C_DISABLE         0
25 #define I2C_ENABLE          1
26 #define I2C_STD_MODE        1
27 #define I2C_FAST_MODE       2
28 #define I2C_HS_MODE         3
29 #define I2C_7BIT_ADDR       0
30 #define I2C_10BIT_ADDR      0
31 #define I2C_ACTIVE          1
32 
33 /* DesignWare I2C Resiter Offset*/
34 #define DW_I2C_CON                                  0x0     /* I2C Control */
35 #define DW_I2C_TAR                                  0x4     /* I2C Target Address */
36 #define DW_I2C_SAR                                  0x8     /* I2C Slave Address */
37 #define DW_I2C_HS_MADDR                             0xc     /* I2C HS Master Mode Code Address */
38 #define DW_I2C_DATA_CMD                             0x10    /* I2C Rx/Tx Data Buffer and Command */
39 #define DW_I2C_SS_SCL_HCNT                          0x14    /* SS I2C Clock SCL High Count */
40 #define DW_I2C_UFM_SCL_HCNT                         0x14    /* UFS I2C Clock SCL High Count */
41 #define DW_I2C_SS_SCL_LCNT                          0x18    /* SS I2C Clock SCL Low Count */
42 #define DW_I2C_UFM_SCL_LCNT                         0x18    /* UFS I2C Clock SCL Low Count */
43 #define DW_I2C_FS_SCL_HCNT                          0x1c    /* Fast Mode I2C Clock SCL High Cnt */
44 #define DW_I2C_UFM_TBUF_CNT                         0x1c    /* UFS mode TBuf Idle Count */
45 #define DW_I2C_FS_SCL_LCNT                          0x20    /* Fast Mode I2C Clock SCL Low Cnt */
46 #define DW_I2C_HS_SCL_HCNT                          0x24    /* High Speed I2C Clock SCL High Cnt */
47 #define DW_I2C_HS_SCL_LCNT                          0x28    /* High Speed I2C Clock SCL Low Cnt */
48 #define DW_I2C_INTR_STAT                            0x2c    /* I2C Interrupt Status */
49 #define DW_I2C_INTR_MASK                            0x30    /* I2C Interrupt Mask */
50 #define DW_I2C_RAW_INTR_STAT                        0x34    /* I2C Raw Interrupt Status */
51 #define DW_I2C_RX_TL                                0x38    /* I2C Receive FIFO Threshold */
52 #define DW_I2C_TX_TL                                0x3c    /* I2C Transmit FIFO Threshold */
53 #define DW_I2C_CLR_INTR                             0x40    /* Clear Combined and Individual Intr */
54 #define DW_I2C_CLR_RX_UNDER                         0x44    /* Clear RX_UNDER Interrupt */
55 #define DW_I2C_CLR_RX_OVER                          0x48    /* Clear RX_OVER Interrupt */
56 #define DW_I2C_CLR_TX_OVER                          0x4c    /* Clear TX_OVER Interrupt */
57 #define DW_I2C_CLR_RD_REQ                           0x50    /* Clear RD_REQ Interrupt */
58 #define DW_I2C_CLR_TX_ABRT                          0x54    /* Clear TX_ABRT Interrupt */
59 #define DW_I2C_CLR_RX_DONE                          0x58    /* Clear RX_DONE Interrupt */
60 #define DW_I2C_CLR_ACTIVITY                         0x5c    /* Clear ACTIVITY Interrupt */
61 #define DW_I2C_CLR_STOP_DET                         0x60    /* Clear STOP_DET Interrupt */
62 #define DW_I2C_CLR_START_DET                        0x64    /* Clear START_DET Interrupt */
63 #define DW_I2C_CLR_GEN_CALL                         0x68    /* Clear GEN_CALL Interrupt */
64 #define DW_I2C_ENABLE                               0x6c    /* I2C Enable */
65 #define DW_I2C_STATUS                               0x70    /* I2C Status */
66 #define DW_I2C_TXFLR                                0x74    /* I2C Transmit FIFO Level */
67 #define DW_I2C_RXFLR                                0x78    /* I2C Receive FIFO Level */
68 #define DW_I2C_SDA_HOLD                             0x7c    /* I2C SDA Hold Time Length */
69 #define DW_I2C_TX_ABRT_SOURCE                       0x80    /* I2C Transmit Abort Source */
70 #define DW_I2C_SLV_DATA_NACK_ONLY                   0x84    /* Generate Slave Data NACK */
71 #define DW_I2C_DMA_CR                               0x88    /* DMA Control */
72 #define DW_I2C_DMA_TDLR                             0x8c    /* DMA Transmit Data Level */
73 #define DW_I2C_DMA_RDLR                             0x90    /* I2C Receive Data Level */
74 #define DW_I2C_SDA_SETUP                            0x94    /* I2C SDA Setup */
75 #define DW_I2C_ACK_GENERAL_CALL                     0x98    /* I2C ACK General Call */
76 #define DW_I2C_ENABLE_STATUS                        0x9c    /* I2C Enable Status */
77 #define DW_I2C_FS_SPKLEN                            0xa0    /* I2C SS, FS spike suppression limit */
78 #define DW_I2C_UFM_SPKLEN                           0xa0    /* I2C UFM spike suppression limit */
79 #define DW_I2C_HS_SPKLEN                            0xa4    /* I2C HS spike suppression limit */
80 #define DW_I2C_CLR_RESTART_DET                      0xa8    /* Clear RESTART_DET Interrupt */
81 #define DW_I2C_SCL_STUCK_AT_LOW_TIMEOUT             0xac    /* I2C SCL Stuck at Low Timeout */
82 #define DW_I2C_SDA_STUCK_AT_LOW_TIMEOUT             0xb0    /* I2C SDA Stuck at Low Timeout */
83 #define DW_I2C_CLR_SCL_STUCK_DET                    0xb4    /* Clear SCL Stuck at Low Detect Intr */
84 #define DW_I2C_DEVICE_ID                            0xb8    /* I2C Device-ID */
85 #define DW_I2C_SMBUS_CLK_LOW_SEXT                   0xbc    /* SMBus Slave Clock Extend Timeout */
86 #define DW_I2C_SMBUS_CLK_LOW_MEXT                   0xc0    /* SMBus Master Clock Extend Timeout */
87 #define DW_I2C_SMBUS_THIGH_MAX_IDLE_COUNT           0xc4    /* SMBus Master High MAX Bus-idle cnt */
88 #define DW_I2C_SMBUS_INTR_STAT                      0xc8    /* SMBUS Interrupt Status */
89 #define DW_I2C_SMBUS_INTR_MASK                      0xcc    /* SMBus Interrupt Mask */
90 #define DW_I2C_SMBUS_RAW_INTR_STAT                  0xd0    /* SMBus Raw Interrupt Status */
91 #define DW_I2C_CLR_SMBUS_INTR                       0xd4    /* SMBus Clear Interrupt */
92 #define DW_I2C_OPTIONAL_SAR                         0xd8    /* I2C Optional Slave Address */
93 #define DW_I2C_SMBUS_UDID_LSB                       0xdc    /* SMBUS ARP UDID LSB */
94 #define DW_I2C_COMP_PARAM_1                         0xf4    /* Component Parameter */
95 #define DW_I2C_COMP_VERSION                         0xf8    /* I2C Component Version */
96 #define DW_I2C_COMP_TYPE                            0xfc
97 
98 
99 /* DW_I2C_CON Bit Definitions */
100 #define DW_I2C_CON_MASTER_MODE_START                0
101 #define DW_I2C_CON_MASTER_MODE_BITS                 1
102 #define DW_I2C_CON_SPEED_START                      1
103 #define DW_I2C_CON_SPEED_BITS                       2
104 #define DW_I2C_CON_10BITADDRSLAVE_START             3
105 #define DW_I2C_CON_10BITADDRSLAVE_BITS              1
106 #define DW_I2C_CON_10BITADDRMASTER_START            4
107 #define DW_I2C_CON_10BITADDRMASTER_BITS             1
108 #define DW_I2C_CON_RESTART_EN_START                 5
109 #define DW_I2C_CON_RESTART_EN_BITS                  1
110 #define DW_I2C_CON_SLAVE_DIS_START                  6
111 #define DW_I2C_CON_SLAVE_DIS_BITS                   1
112 #define DW_I2C_CON_TX_EMPTY_CTRL_START              8
113 #define DW_I2C_CON_TX_EMPTY_CTRL_BITS               1
114 
115 /* DW_I2C_TAR Bit Definitions */
116 #define DW_I2C_TAR_TAR_START                        0
117 #define DW_I2C_TAR_TAR_BITS                         10
118 #define DW_I2C_TAR_10BIT_START                      12
119 #define DW_I2C_TAR_10BIT_BITS                       1
120 
121 /* DW_I2C_DATA_CMD_DAT Bit Definitions */
122 #define DW_I2C_DATA_CMD_DAT_START                   0
123 #define DW_I2C_DATA_CMD_DAT_BITS                    8
124 #define DW_I2C_DATA_CMD_CMD_START                   8
125 #define DW_I2C_DATA_CMD_CMD_BITS                    1
126 #define DW_I2C_DATA_CMD_STOP_START                  9
127 #define DW_I2C_DATA_CMD_STOP_BITS                   1
128 #define DW_I2C_DATA_CMD_RESTART_START               10
129 #define DW_I2C_DATA_CMD_RESTART_BITS                1
130 #define DW_I2C_DATA_CMD_FRST_DAT_BYTE_START         11
131 #define DW_I2C_DATA_CMD_FRST_DAT_BYTE_BITS          1
132 
133 /* DW_I2C_SS/FS_SCL Bit Definitions */
134 #define DW_I2C_SS_SCL_HCNT_START                    0
135 #define DW_I2C_SS_SCL_HCNT_BITS                     16
136 #define DW_I2C_SS_SCL_LCNT_START                    0
137 #define DW_I2C_SS_SCL_LCNT_BITS                     16
138 #define DW_I2C_FS_SCL_HCNT_START                    0
139 #define DW_I2C_FS_SCL_HCNT_BITS                     16
140 #define DW_I2C_FS_SCL_LCNT_START                    0
141 #define DW_I2C_FS_SCL_LCNT_BITS                     16
142 
143 /* DW_I2C_INTR Bit Definitions */
144 #define DW_I2C_INTR_SCL_STUCK_LOW                   (0x4000)
145 #define DW_I2C_INTR_MSTR_ON_HOLD                    (0x2000)
146 #define DW_I2C_INTR_RESTART_DET                     (0x1000)
147 #define DW_I2C_INTR_GEN_CALL                        (0x0800)
148 #define DW_I2C_INTR_START_DET                       (0x0400)
149 #define DW_I2C_INTR_STOP_DET                        (0x0200)
150 #define DW_I2C_INTR_ACTIVITY                        (0x0100)
151 #define DW_I2C_INTR_RX_DONE                         (0x0080)
152 #define DW_I2C_INTR_TX_ABRT                         (0x0040)
153 #define DW_I2C_INTR_RD_REQ                          (0x0020)
154 #define DW_I2C_INTR_TX_EMPTY                        (0x0010)
155 #define DW_I2C_INTR_TX_OVER                         (0x0008)
156 #define DW_I2C_INTR_RX_FULL                         (0x0004)
157 #define DW_I2C_INTR_RX_OVER                         (0x0002)
158 #define DW_I2C_INTR_RX_UNDER                        (0x0001)
159 #define DW_I2C_INTR_DEFAULT_INTR_MASK               (DW_I2C_INTR_RX_FULL | \
160                                                     DW_I2C_INTR_TX_ABRT | \
161                                                     DW_I2C_INTR_STOP_DET | \
162                                                     DW_I2C_INTR_TX_EMPTY)
163 
164 #define DW_I2C_INTR_READ_INTR_MASK                  (DW_I2C_INTR_RX_FULL | \
165                                                     DW_I2C_INTR_TX_ABRT | \
166                                                     DW_I2C_INTR_STOP_DET )
167 
168 /* DW_I2C_RX/TX_TL Bit Definitions */
169 #define DW_I2C_RX_TL_START                          0
170 #define DW_I2C_RX_TL_BITS                           8
171 #define DW_I2C_TX_TL_START                          0
172 #define DW_I2C_TX_TL_BITS                           8
173 
174 /* DW_I2C_ENABLE Bit Definitions */
175 #define DW_I2C_ENABLE_ENABLE_START                  0
176 #define DW_I2C_ENABLE_ENABLE_BITS                   1
177 
178 /* DW_I2C_STATUS Bit Definitions */
179 #define DW_I2C_STATUS_ACTIVITY_START                0
180 #define DW_I2C_STATUS_ACTIVITY_BITS                 1
181 
182 /* DW_I2C_ENABLE_STATUS Bit Definitions */
183 #define DW_I2C_ENABLE_STATUS_EN_START               0
184 #define DW_I2C_ENABLE_STATUS_EN_BITS                1
185 
186 /* DW_I2C_COMP_PARAM_1 Bit Definitions */
187 #define DW_I2C_COMP_PARAM_1_RXFIFOSZ_START          8
188 #define DW_I2C_COMP_PARAM_1_RXFIFOSZ_BITS           8
189 #define DW_I2C_COMP_PARAM_1_TXFIFOSZ_START          16
190 #define DW_I2C_COMP_PARAM_1_TXFIFOSZ_BITS           8
191