]> git.proxmox.com Git - mirror_edk2.git/blobdiff - QuarkSocPkg/QuarkSouthCluster/Library/I2cLib/CommonHeader.h
QuarkSocPkg: Add new package for Quark SoC X1000
[mirror_edk2.git] / QuarkSocPkg / QuarkSouthCluster / Library / I2cLib / CommonHeader.h
diff --git a/QuarkSocPkg/QuarkSouthCluster/Library/I2cLib/CommonHeader.h b/QuarkSocPkg/QuarkSouthCluster/Library/I2cLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..facc00f
--- /dev/null
@@ -0,0 +1,220 @@
+/** @file\r
+Provides definition of entry point to the common I2C module that produces\r
+common I2C Controller functions used by I2C library services.\r
+\r
+\r
+Copyright (c) 2013-2015 Intel Corporation.\r
+\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+\r
+#ifndef _I2CCOMMON_H_\r
+#define _I2CCOMMON_H_\r
+\r
+#include <Uefi.h>\r
+#include <Base.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/I2cLib.h>\r
+#include <IohAccess.h>\r
+#include <IohCommonDefinitions.h>\r
+#include "I2cRegs.h"\r
+\r
+//\r
+// Constants that define I2C Controller timeout and max. polling time.\r
+//\r
+#define MAX_T_POLL_COUNT         100\r
+#define TI2C_POLL                25  // microseconds\r
+#define MAX_STOP_DET_POLL_COUNT ((1000 * 1000) / TI2C_POLL)  // Extreme for expected Stop detect.\r
+\r
+/**\r
+  The GetI2CIoPortBaseAddress() function gets IO port base address of I2C Controller.\r
+\r
+  Always reads PCI configuration space to get MMIO base address of I2C Controller.\r
+\r
+  @return The IO port base address of I2C controller.\r
+\r
+**/\r
+UINTN\r
+GetI2CIoPortBaseAddress (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  The EnableI2CMmioSpace() function enables access to I2C MMIO space.\r
+\r
+**/\r
+VOID\r
+EnableI2CMmioSpace (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  The DisableI2CController() functions disables I2C Controller.\r
+\r
+**/\r
+VOID\r
+DisableI2CController (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  The EnableI2CController() function enables the I2C Controller.\r
+\r
+**/\r
+VOID\r
+EnableI2CController (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  The WaitForStopDet() function waits until I2C STOP Condition occurs,\r
+  indicating transfer completion.\r
+\r
+  @retval EFI_SUCCESS           Stop detected.\r
+  @retval EFI_TIMEOUT           Timeout while waiting for stop condition.\r
+  @retval EFI_ABORTED           Tx abort signaled in HW status register.\r
+  @retval EFI_DEVICE_ERROR      Tx or Rx overflow detected.\r
+\r
+**/\r
+EFI_STATUS\r
+WaitForStopDet (\r
+  VOID\r
+  );\r
+\r
+/**\r
+\r
+  The InitializeInternal() function initialises internal I2C Controller\r
+  register values that are commonly required for I2C Write and Read transfers.\r
+\r
+  @param AddrMode     I2C Addressing Mode: 7-bit or 10-bit address.\r
+\r
+  @retval EFI_SUCCESS           I2C Operation completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+InitializeInternal (\r
+  IN EFI_I2C_ADDR_MODE  AddrMode\r
+  );\r
+\r
+/**\r
+\r
+  The WriteByte() function provides a standard way to execute a\r
+  standard single byte write to an IC2 device (without accessing\r
+  sub-addresses), as defined in the I2C Specification.\r
+\r
+  @param  I2CAddress      I2C Slave device address\r
+  @param  Value           The 8-bit value to write.\r
+\r
+  @retval EFI_SUCCESS           Transfer success.\r
+  @retval EFI_UNSUPPORTED       Unsupported input param.\r
+  @retval EFI_TIMEOUT           Timeout while waiting xfer.\r
+  @retval EFI_ABORTED           Controller aborted xfer.\r
+  @retval EFI_DEVICE_ERROR      Device error detected by controller.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WriteByte (\r
+  IN  UINTN          I2CAddress,\r
+  IN  UINT8          Value\r
+  );\r
+\r
+/**\r
+\r
+  The ReadByte() function provides a standard way to execute a\r
+  standard single byte read to an IC2 device (without accessing\r
+  sub-addresses), as defined in the I2C Specification.\r
+\r
+  @param  I2CAddress      I2C Slave device address\r
+  @param  ReturnDataPtr   Pointer to location to receive read byte.\r
+\r
+  @retval EFI_SUCCESS           Transfer success.\r
+  @retval EFI_UNSUPPORTED       Unsupported input param.\r
+  @retval EFI_TIMEOUT           Timeout while waiting xfer.\r
+  @retval EFI_ABORTED           Controller aborted xfer.\r
+  @retval EFI_DEVICE_ERROR      Device error detected by controller.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ReadByte (\r
+  IN  UINTN          I2CAddress,\r
+  OUT UINT8          *ReturnDataPtr\r
+  );\r
+\r
+/**\r
+\r
+  The WriteMultipleByte() function provides a standard way to execute\r
+  multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or\r
+  when writing block of data), as defined in the I2C Specification.\r
+\r
+  @param I2CAddress   The I2C slave address of the device\r
+                      with which to communicate.\r
+\r
+  @param WriteBuffer  Contains the value of byte to be written to the\r
+                      I2C slave device.\r
+\r
+  @param Length       No. of bytes to be written.\r
+\r
+  @retval EFI_SUCCESS           Transfer success.\r
+  @retval EFI_UNSUPPORTED       Unsupported input param.\r
+  @retval EFI_TIMEOUT           Timeout while waiting xfer.\r
+  @retval EFI_ABORTED           Tx abort signaled in HW status register.\r
+  @retval EFI_DEVICE_ERROR      Tx overflow detected.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WriteMultipleByte (\r
+  IN  UINTN          I2CAddress,\r
+  IN  UINT8          *WriteBuffer,\r
+  IN  UINTN          Length\r
+  );\r
+\r
+/**\r
+\r
+  The ReadMultipleByte() function provides a standard way to execute\r
+  multiple byte writes to an IC2 device (e.g. when accessing sub-addresses or\r
+  when reading block of data), as defined in the I2C Specification (I2C combined\r
+  write/read protocol).\r
+\r
+  @param I2CAddress   The I2C slave address of the device\r
+                      with which to communicate.\r
+\r
+  @param Buffer       Contains the value of byte data written or read from the\r
+                      I2C slave device.\r
+\r
+  @param WriteLength  No. of bytes to be written. In this case data\r
+                      written typically contains sub-address or sub-addresses\r
+                      in Hi-Lo format, that need to be read (I2C combined\r
+                      write/read protocol).\r
+\r
+  @param ReadLength   No. of bytes to be read from I2C slave device.\r
+\r
+  @retval EFI_SUCCESS           Transfer success.\r
+  @retval EFI_UNSUPPORTED       Unsupported input param.\r
+  @retval EFI_TIMEOUT           Timeout while waiting xfer.\r
+  @retval EFI_ABORTED           Tx abort signaled in HW status register.\r
+  @retval EFI_DEVICE_ERROR      Rx underflow or Rx/Tx overflow detected.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ReadMultipleByte (\r
+  IN  UINTN          I2CAddress,\r
+  IN  OUT UINT8      *Buffer,\r
+  IN  UINTN          WriteLength,\r
+  IN  UINTN          ReadLength\r
+  );\r
+\r
+#endif\r