]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/Library/I2CLibPei/I2CLibPei.h
47536aebf72df802c77d6f76bd2d1d822caeb496
[mirror_edk2.git] / Vlv2TbltDevicePkg / Library / I2CLibPei / I2CLibPei.h
1 /** @file
2 I2C PEI Lib Instance.
3
4 Copyright (c) 1999- 2015, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef I2C_PEI_REGS_H
10 #define I2C_PEI_REGS_H
11
12 #include "PiPei.h"
13
14 #define R_PCH_LPC_PMC_BASE 0x44
15 #define B_PCH_LPC_PMC_BASE_BAR 0xFFFFFE00
16 #define R_PCH_PMC_FUNC_DIS 0x34 // Function Disable Register
17 #define PCIEX_BASE_ADDRESS 0xE0000000
18 #define PciD31F0RegBase PCIEX_BASE_ADDRESS + (UINT32) (31 << 15)
19 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC7 BIT7 // LPSS SPI Disable
20 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC6 BIT6 // LPSS HSUART #2 Disable
21 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC5 BIT5 // LPSS HSUART #1 Disable
22 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC4 BIT4 // LPSS I2S Disable
23 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC3 BIT3 // LPSS PCM Disable
24 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC2 BIT2 // LPSS I2C #2 Disable
25 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC1 BIT1 // LPSS I2C #1 Disable
26 #define B_PCH_PMC_FUNC_DIS_LPSS_FUNC0 BIT0 // LPSS DMA Disable
27
28
29 #define DEFAULT_PCI_BUS_NUMBER_PCH 0
30
31 #define R_PCH_LPSS_I2C_STSCMD 0x04 // Status & Command
32 #define B_PCH_LPSS_I2C_STSCMD_RMA BIT29 // RMA
33 #define B_PCH_LPSS_I2C_STSCMD_RCA BIT28 // RCA
34 #define B_PCH_LPSS_I2C_STSCMD_CAPLIST BIT20 // Capability List
35 #define B_PCH_LPSS_I2C_STSCMD_INTRSTS BIT19 // Interrupt Status
36 #define B_PCH_LPSS_I2C_STSCMD_INTRDIS BIT10 // Interrupt Disable
37 #define B_PCH_LPSS_I2C_STSCMD_SERREN BIT8 // SERR# Enable
38 #define B_PCH_LPSS_I2C_STSCMD_BME BIT2 // Bus Master Enable
39 #define B_PCH_LPSS_I2C_STSCMD_MSE BIT1 // Memory Space Enable
40
41 #define R_PCH_LPSS_I2C_BAR 0x10 // BAR
42 #define B_PCH_LPSS_I2C_BAR_BA 0xFFFFF000 // Base Address
43 #define B_PCH_LPSS_I2C_BAR_SI 0x00000FF0 // Size Indicator
44 #define B_PCH_LPSS_I2C_BAR_PF BIT3 // Prefetchable
45 #define B_PCH_LPSS_I2C_BAR_TYPE (BIT2 | BIT1) // Type
46 #define B_PCH_LPSS_I2C_BAR_MS BIT0 // Message Space
47
48 #define R_PCH_LPSS_I2C_BAR1 0x14 // BAR 1
49 #define B_PCH_LPSS_I2C_BAR1_BA 0xFFFFF000 // Base Address
50 #define B_PCH_LPSS_I2C_BAR1_SI 0x00000FF0 // Size Indicator
51 #define B_PCH_LPSS_I2C_BAR1_PF BIT3 // Prefetchable
52 #define B_PCH_LPSS_I2C_BAR1_TYPE (BIT2 | BIT1) // Type
53 #define B_PCH_LPSS_I2C_BAR1_MS BIT0 // Message Space
54
55 #define NUM_RETRIES 0xFFFF
56
57 //
58 // LPIO I2C Module Memory Space Registers
59 //
60 #define R_PCH_LPIO_I2C_MEM_RESETS 0x804 // Software Reset
61 #define B_PCH_LPIO_I2C_MEM_RESETS_FUNC BIT1 // Function Clock Domain Reset
62 #define B_PCH_LPIO_I2C_MEM_RESETS_APB BIT0 // APB Domain Reset
63
64 #define R_PCH_LPSS_I2C_MEM_PCP 0x800 // Private Clock Parameters
65
66 #define bit(a) 1 << (a)
67
68 //
69 // MMIO Register Definitions
70 //
71
72 #define I2C0_REG_SPACE_ADDR_BASE 0xFF138000 //01K
73
74 #define R_IC_CON ( 0x00) // I2C Control
75 #define B_IC_RESTART_EN BIT5
76 #define B_IC_SLAVE_DISABLE BIT6
77 #define V_SPEED_STANDARD 0x02
78 #define V_SPEED_FAST 0x04
79 #define V_SPEED_HIGH 0x06
80 #define B_MASTER_MODE BIT0
81
82 #define R_IC_TAR ( 0x04) // I2C Target Address
83 #define IC_TAR_10BITADDR_MASTER BIT12
84
85 #define R_IC_SAR ( 0x08) // I2C Slave Address
86 #define R_IC_HS_MADDR ( 0x0C) // I2C HS MasterMode Code Address
87 #define R_IC_DATA_CMD ( 0x10) // I2C Rx/Tx Data Buffer and Command
88
89 #define B_READ_CMD BIT8 // 1 = read, 0 = write
90 #define B_CMD_STOP BIT9 // 1 = STOP
91 #define B_CMD_RESTART BIT10 // 1 = IC_RESTART_EN
92
93 #define V_WRITE_CMD_MASK ( 0xFF)
94
95 #define R_IC_SS_SCL_HCNT ( 0x14) // Standard Speed I2C Clock SCL High Count
96 #define R_IC_SS_SCL_LCNT ( 0x18) // Standard Speed I2C Clock SCL Low Count
97 #define R_IC_FS_SCL_HCNT ( 0x1C) // Full Speed I2C Clock SCL High Count
98 #define R_IC_FS_SCL_LCNT ( 0x20) // Full Speed I2C Clock SCL Low Count
99 #define R_IC_HS_SCL_HCNT ( 0x24) // High Speed I2C Clock SCL High Count
100 #define R_IC_HS_SCL_LCNT ( 0x28) // High Speed I2C Clock SCL Low Count
101 #define R_IC_INTR_STAT ( 0x2C) // I2C Inetrrupt Status
102 #define R_IC_INTR_MASK ( 0x30) // I2C Interrupt Mask
103 #define I2C_INTR_GEN_CALL BIT11 // General call received
104 #define I2C_INTR_START_DET BIT10
105 #define I2C_INTR_STOP_DET BIT9
106 #define I2C_INTR_ACTIVITY BIT8
107 #define I2C_INTR_TX_ABRT BIT6 // Set on NACK
108 #define I2C_INTR_TX_EMPTY BIT4
109 #define I2C_INTR_TX_OVER BIT3
110 #define I2C_INTR_RX_FULL BIT2 // Data bytes in RX FIFO over threshold
111 #define I2C_INTR_RX_OVER BIT1
112 #define I2C_INTR_RX_UNDER BIT0
113 #define R_IC_RawIntrStat ( 0x34) // I2C Raw Interrupt Status
114 #define R_IC_RX_TL ( 0x38) // I2C Receive FIFO Threshold
115 #define R_IC_TX_TL ( 0x3C) // I2C Transmit FIFO Threshold
116 #define R_IC_CLR_INTR ( 0x40) // Clear Combined and Individual Interrupts
117 #define R_IC_CLR_RX_UNDER ( 0x44) // Clear RX_UNDER Interrupt
118 #define R_IC_CLR_RX_OVER ( 0x48) // Clear RX_OVERinterrupt
119 #define R_IC_CLR_TX_OVER ( 0x4C) // Clear TX_OVER interrupt
120 #define R_IC_CLR_RD_REQ ( 0x50) // Clear RD_REQ interrupt
121 #define R_IC_CLR_TX_ABRT ( 0x54) // Clear TX_ABRT interrupt
122 #define R_IC_CLR_RX_DONE ( 0x58) // Clear RX_DONE interrupt
123 #define R_IC_CLR_ACTIVITY ( 0x5C) // Clear ACTIVITY interrupt
124 #define R_IC_CLR_STOP_DET ( 0x60) // Clear STOP_DET interrupt
125 #define R_IC_CLR_START_DET ( 0x64) // Clear START_DET interrupt
126 #define R_IC_CLR_GEN_CALL ( 0x68) // Clear GEN_CALL interrupt
127 #define R_IC_ENABLE ( 0x6C) // I2C Enable
128 #define R_IC_STATUS ( 0x70) // I2C Status
129
130 #define R_IC_SDA_HOLD ( 0x7C) // I2C IC_DEFAULT_SDA_HOLD//16bits
131
132 #define STAT_MST_ACTIVITY BIT5 // Master FSM Activity Status.
133 #define STAT_RFF BIT4 // RX FIFO is completely full
134 #define STAT_RFNE BIT3 // RX FIFO is not empty
135 #define STAT_TFE BIT2 // TX FIFO is completely empty
136 #define STAT_TFNF BIT1 // TX FIFO is not full
137
138 #define R_IC_TXFLR ( 0x74) // Transmit FIFO Level Register
139 #define R_IC_RXFLR ( 0x78) // Receive FIFO Level Register
140 #define R_IC_TX_ABRT_SOURCE ( 0x80) // I2C Transmit Abort Status Register
141 #define R_IC_SLV_DATA_NACK_ONLY ( 0x84) // Generate SLV_DATA_NACK Register
142 #define R_IC_DMA_CR ( 0x88) // DMA Control Register
143 #define R_IC_DMA_TDLR ( 0x8C) // DMA Transmit Data Level
144 #define R_IC_DMA_RDLR ( 0x90) // DMA Receive Data Level
145 #define R_IC_SDA_SETUP ( 0x94) // I2C SDA Setup Register
146 #define R_IC_ACK_GENERAL_CALL ( 0x98) // I2C ACK General Call Register
147 #define R_IC_ENABLE_STATUS ( 0x9C) // I2C Enable Status Register
148 #define R_IC_COMP_PARAM ( 0xF4) // Component Parameter Register
149 #define R_IC_COMP_VERSION ( 0xF8) // Component Version ID
150 #define R_IC_COMP_TYPE ( 0xFC) // Component Type
151
152 #define I2C_SS_SCL_HCNT_VALUE_100M 0x1DD
153 #define I2C_SS_SCL_LCNT_VALUE_100M 0x1E4
154 #define I2C_FS_SCL_HCNT_VALUE_100M 0x54
155 #define I2C_FS_SCL_LCNT_VALUE_100M 0x9a
156 #define I2C_HS_SCL_HCNT_VALUE_100M 0x7
157 #define I2C_HS_SCL_LCNT_VALUE_100M 0xE
158
159 //
160 // FIFO write workaround value.
161 //
162 #define FIFO_WRITE_DELAY 2
163 #define IC_TAR_10BITADDR_MASTER BIT12
164 #define FIFO_SIZE 32
165 #define R_IC_INTR_STAT ( 0x2C) // I2c Inetrrupt Status
166 #define R_IC_INTR_MASK ( 0x30) // I2c Interrupt Mask
167 #define I2C_INTR_GEN_CALL BIT11 // General call received
168 #define I2C_INTR_START_DET BIT10
169 #define I2C_INTR_STOP_DET BIT9
170 #define I2C_INTR_ACTIVITY BIT8
171 #define I2C_INTR_TX_ABRT BIT6 // Set on NACK
172 #define I2C_INTR_TX_EMPTY BIT4
173 #define I2C_INTR_TX_OVER BIT3
174 #define I2C_INTR_RX_FULL BIT2 // Data bytes in RX FIFO over threshold
175 #define I2C_INTR_RX_OVER BIT1
176 #define I2C_INTR_RX_UNDER BIT0
177
178 /**
179 Programe all I2C controllers on LPSS.
180
181 I2C0 is function 1 of LPSS. I2C1 is function 2 of LPSS, etc..
182
183 @param VOID
184
185 @return EFI_SUCCESS
186 **/
187 EFI_STATUS
188 ProgramPciLpssI2C (
189 VOID
190 );
191
192 /**
193 Reads a Byte from I2C Device.
194
195 @param I2cControllerIndex I2C Bus no to which the I2C device has been connected
196 @param SlaveAddress Device Address from which the byte value has to be read
197 @param Offset Offset from which the data has to be read
198 @param *Byte Address to which the value read has to be stored
199 @param Start Whether a RESTART is issued before the byte is sent or received
200 @param End Whether STOP is generated after a data byte is sent or received
201
202 @return EFI_SUCCESS If the byte value has been successfully read
203 @return EFI_DEVICE_ERROR Operation Failed, Device Error
204 **/
205 EFI_STATUS
206 ByteReadI2CBasic(
207 IN UINT8 I2cControllerIndex,
208 IN UINT8 SlaveAddress,
209 IN UINTN ReadBytes,
210 OUT UINT8 *ReadBuffer,
211 IN UINT8 Start,
212 IN UINT8 End
213 );
214
215 /**
216 Writes a Byte to I2C Device.
217
218 @param I2cControllerIndex I2C Bus no to which the I2C device has been connected
219 @param SlaveAddress Device Address from which the byte value has to be written
220 @param Offset Offset from which the data has to be read
221 @param *Byte Address to which the value written is stored
222 @param Start Whether a RESTART is issued before the byte is sent or received
223 @param End Whether STOP is generated after a data byte is sent or received
224
225 @return EFI_SUCCESS IF the byte value has been successfully written
226 @return EFI_DEVICE_ERROR Operation Failed, Device Error
227 **/
228 EFI_STATUS
229 ByteWriteI2CBasic(
230 IN UINT8 I2cControllerIndex,
231 IN UINT8 SlaveAddress,
232 IN UINTN WriteBytes,
233 IN UINT8 *WriteBuffer,
234 IN UINT8 Start,
235 IN UINT8 End
236 );
237
238 /**
239 Reads a Byte from I2C Device.
240
241 @param I2cControllerIndex I2C Bus no to which the I2C device has been connected
242 @param SlaveAddress Device Address from which the byte value has to be read
243 @param Offset Offset from which the data has to be read
244 @param ReadBytes Number of bytes to be read
245 @param *ReadBuffer Address to which the value read has to be stored
246
247 @return EFI_SUCCESS IF the byte value has been successfully read
248 @return EFI_DEVICE_ERROR Operation Failed, Device Error
249 **/
250 EFI_STATUS
251 ByteReadI2C(
252 IN UINT8 I2cControllerIndex,
253 IN UINT8 SlaveAddress,
254 IN UINT8 Offset,
255 IN UINTN ReadBytes,
256 OUT UINT8 *ReadBuffer
257 );
258
259 /**
260 Writes a Byte to I2C Device.
261
262 @param I2cControllerIndex I2C Bus no to which the I2C device has been connected
263 @param SlaveAddress Device Address from which the byte value has to be written
264 @param Offset Offset from which the data has to be written
265 @param WriteBytes Number of bytes to be written
266 @param *Byte Address to which the value written is stored
267
268 @return EFI_SUCCESS IF the byte value has been successfully read
269 @return EFI_DEVICE_ERROR Operation Failed, Device Error
270 **/
271 EFI_STATUS
272 ByteWriteI2C(
273 IN UINT8 I2cControllerIndex,
274 IN UINT8 SlaveAddress,
275 IN UINT8 Offset,
276 IN UINTN WriteBytes,
277 IN UINT8 *WriteBuffer
278 );
279
280 #endif