2 Provides definition of entry point to the common I2C module that produces
3 common I2C Controller functions used by I2C library services.
6 Copyright (c) 2013-2015 Intel Corporation.
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 #include <Library/DebugLib.h>
26 #include <Library/TimerLib.h>
27 #include <Library/I2cLib.h>
28 #include <IohAccess.h>
29 #include <IohCommonDefinitions.h>
33 // Constants that define I2C Controller timeout and max. polling time.
35 #define MAX_T_POLL_COUNT 100
36 #define TI2C_POLL 25 // microseconds
37 #define MAX_STOP_DET_POLL_COUNT ((1000 * 1000) / TI2C_POLL) // Extreme for expected Stop detect.
40 The GetI2CIoPortBaseAddress() function gets IO port base address of I2C Controller.
42 Always reads PCI configuration space to get MMIO base address of I2C Controller.
44 @return The IO port base address of I2C controller.
48 GetI2CIoPortBaseAddress (
53 The EnableI2CMmioSpace() function enables access to I2C MMIO space.
62 The DisableI2CController() functions disables I2C Controller.
66 DisableI2CController (
71 The EnableI2CController() function enables the I2C Controller.
80 The WaitForStopDet() function waits until I2C STOP Condition occurs,
81 indicating transfer completion.
83 @retval EFI_SUCCESS Stop detected.
84 @retval EFI_TIMEOUT Timeout while waiting for stop condition.
85 @retval EFI_ABORTED Tx abort signaled in HW status register.
86 @retval EFI_DEVICE_ERROR Tx or Rx overflow detected.
96 The InitializeInternal() function initialises internal I2C Controller
97 register values that are commonly required for I2C Write and Read transfers.
99 @param AddrMode I2C Addressing Mode: 7-bit or 10-bit address.
101 @retval EFI_SUCCESS I2C Operation completed successfully.
106 IN EFI_I2C_ADDR_MODE AddrMode
111 The WriteByte() function provides a standard way to execute a
112 standard single byte write to an IC2 device (without accessing
113 sub-addresses), as defined in the I2C Specification.
115 @param I2CAddress I2C Slave device address
116 @param Value The 8-bit value to write.
118 @retval EFI_SUCCESS Transfer success.
119 @retval EFI_UNSUPPORTED Unsupported input param.
120 @retval EFI_TIMEOUT Timeout while waiting xfer.
121 @retval EFI_ABORTED Controller aborted xfer.
122 @retval EFI_DEVICE_ERROR Device error detected by controller.
134 The ReadByte() function provides a standard way to execute a
135 standard single byte read to an IC2 device (without accessing
136 sub-addresses), as defined in the I2C Specification.
138 @param I2CAddress I2C Slave device address
139 @param ReturnDataPtr Pointer to location to receive read byte.
141 @retval EFI_SUCCESS Transfer success.
142 @retval EFI_UNSUPPORTED Unsupported input param.
143 @retval EFI_TIMEOUT Timeout while waiting xfer.
144 @retval EFI_ABORTED Controller aborted xfer.
145 @retval EFI_DEVICE_ERROR Device error detected by controller.
152 OUT UINT8
*ReturnDataPtr
157 The WriteMultipleByte() function provides a standard way to execute
158 multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or
159 when writing block of data), as defined in the I2C Specification.
161 @param I2CAddress The I2C slave address of the device
162 with which to communicate.
164 @param WriteBuffer Contains the value of byte to be written to the
167 @param Length No. of bytes to be written.
169 @retval EFI_SUCCESS Transfer success.
170 @retval EFI_UNSUPPORTED Unsupported input param.
171 @retval EFI_TIMEOUT Timeout while waiting xfer.
172 @retval EFI_ABORTED Tx abort signaled in HW status register.
173 @retval EFI_DEVICE_ERROR Tx overflow detected.
180 IN UINT8
*WriteBuffer
,
186 The ReadMultipleByte() function provides a standard way to execute
187 multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or
188 when reading block of data), as defined in the I2C Specification (I2C combined
189 write/read protocol).
191 @param I2CAddress The I2C slave address of the device
192 with which to communicate.
194 @param Buffer Contains the value of byte data written or read from the
197 @param WriteLength No. of bytes to be written. In this case data
198 written typically contains sub-address or sub-addresses
199 in Hi-Lo format, that need to be read (I2C combined
200 write/read protocol).
202 @param ReadLength No. of bytes to be read from I2C slave device.
204 @retval EFI_SUCCESS Transfer success.
205 @retval EFI_UNSUPPORTED Unsupported input param.
206 @retval EFI_TIMEOUT Timeout while waiting xfer.
207 @retval EFI_ABORTED Tx abort signaled in HW status register.
208 @retval EFI_DEVICE_ERROR Rx underflow or Rx/Tx overflow detected.
215 IN OUT UINT8
*Buffer
,
216 IN UINTN WriteLength
,