]> git.proxmox.com Git - mirror_edk2.git/commitdiff
QuarkPlatformPkg/PlatformHelperLib: Move PCAL functions for PEI use
authorMichael Kinney <michael.d.kinney@intel.com>
Thu, 7 Jan 2016 22:43:11 +0000 (22:43 +0000)
committermdkinney <mdkinney@Edk2>
Thu, 7 Jan 2016 22:43:11 +0000 (22:43 +0000)
The functions used to manage the PCAL GPIO I2C expander are located
in a DXE specific source file.  Move these functions to a source
file that is common to both the PEI and DXE versions of this library
so these GPIO pins can be managed from PEIMs.

Cc: Kelly Steele <kelly.steele@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Kelly Steele <kelly.steele@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19619 6f19259b-4bc3-4df7-8a09-765794883524

QuarkPlatformPkg/Library/PlatformHelperLib/PlatformHelperDxe.c
QuarkPlatformPkg/Library/PlatformHelperLib/PlatformHelperLib.c

index 9cfbc0716c4fcfcb7a3dcb82c6041740f8eb4cf7..18dbd8b89e7e46eadf0aa2103017168d62239f01 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation of helper routines for DXE environment.\r
 \r
-Copyright (c) 2013 Intel Corporation.\r
+Copyright (c) 2013 - 2016 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
@@ -19,7 +19,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/S3BootScriptLib.h>\r
 #include <Library/DxeServicesLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/I2cLib.h>\r
 #include <Protocol/SmmBase2.h>\r
 #include <Protocol/Spi.h>\r
 #include <Protocol/VariableLock.h>\r
@@ -48,135 +47,6 @@ EFI_SPI_PROTOCOL                    *mPlatHelpSpiProtocolRef = NULL;
 // Routines shared with other souce modules in this component.\r
 //\r
 \r
-BOOLEAN\r
-Pcal9555GetPortRegBit (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum,\r
-  IN CONST UINT8                          RegBase\r
-  )\r
-{\r
-  EFI_STATUS                        Status;\r
-  UINTN                             ReadLength;\r
-  UINTN                             WriteLength;\r
-  UINT8                             Data[2];\r
-  EFI_I2C_DEVICE_ADDRESS            I2cDeviceAddr;\r
-  EFI_I2C_ADDR_MODE                 I2cAddrMode;\r
-  UINT8                             *RegValuePtr;\r
-  UINT8                             GpioNumMask;\r
-  UINT8                             SubAddr;\r
-\r
-  I2cDeviceAddr.I2CDeviceAddress = (UINTN) Pcal9555SlaveAddr;\r
-  I2cAddrMode = EfiI2CSevenBitAddrMode;\r
-\r
-  if (GpioNum < 8) {\r
-    SubAddr = RegBase;\r
-    GpioNumMask = (UINT8) (1 << GpioNum);\r
-  } else {\r
-    SubAddr = RegBase + 1;\r
-    GpioNumMask = (UINT8) (1 << (GpioNum - 8));\r
-  }\r
-\r
-  //\r
-  // Output port value always at 2nd byte in Data variable.\r
-  //\r
-  RegValuePtr = &Data[1];\r
-\r
-  //\r
-  // On read entry sub address at 2nd byte, on read exit output\r
-  // port value in 2nd byte.\r
-  //\r
-  Data[1] = SubAddr;\r
-  WriteLength = 1;\r
-  ReadLength = 1;\r
-  Status = I2cReadMultipleByte (\r
-             I2cDeviceAddr,\r
-             I2cAddrMode,\r
-             &WriteLength,\r
-             &ReadLength,\r
-             &Data[1]\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Adjust output port bit given callers request.\r
-  //\r
-  return ((*RegValuePtr & GpioNumMask) != 0);\r
-}\r
-\r
-VOID\r
-Pcal9555SetPortRegBit (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum,\r
-  IN CONST UINT8                          RegBase,\r
-  IN CONST BOOLEAN                        LogicOne\r
-  )\r
-{\r
-  EFI_STATUS                        Status;\r
-  UINTN                             ReadLength;\r
-  UINTN                             WriteLength;\r
-  UINT8                             Data[2];\r
-  EFI_I2C_DEVICE_ADDRESS            I2cDeviceAddr;\r
-  EFI_I2C_ADDR_MODE                 I2cAddrMode;\r
-  UINT8                             *RegValuePtr;\r
-  UINT8                             GpioNumMask;\r
-  UINT8                             SubAddr;\r
-\r
-  I2cDeviceAddr.I2CDeviceAddress = (UINTN) Pcal9555SlaveAddr;\r
-  I2cAddrMode = EfiI2CSevenBitAddrMode;\r
-\r
-  if (GpioNum < 8) {\r
-    SubAddr = RegBase;\r
-    GpioNumMask = (UINT8) (1 << GpioNum);\r
-  } else {\r
-    SubAddr = RegBase + 1;\r
-    GpioNumMask = (UINT8) (1 << (GpioNum - 8));\r
-  }\r
-\r
-  //\r
-  // Output port value always at 2nd byte in Data variable.\r
-  //\r
-  RegValuePtr = &Data[1];\r
-\r
-  //\r
-  // On read entry sub address at 2nd byte, on read exit output\r
-  // port value in 2nd byte.\r
-  //\r
-  Data[1] = SubAddr;\r
-  WriteLength = 1;\r
-  ReadLength = 1;\r
-  Status = I2cReadMultipleByte (\r
-             I2cDeviceAddr,\r
-             I2cAddrMode,\r
-             &WriteLength,\r
-             &ReadLength,\r
-             &Data[1]\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Adjust output port bit given callers request.\r
-  //\r
-  if (LogicOne) {\r
-    *RegValuePtr = *RegValuePtr | GpioNumMask;\r
-  } else {\r
-    *RegValuePtr = *RegValuePtr & ~(GpioNumMask);\r
-  }\r
-\r
-  //\r
-  // Update register. Sub address at 1st byte, value at 2nd byte.\r
-  //\r
-  WriteLength = 2;\r
-  Data[0] = SubAddr;\r
-  Status = I2cWriteMultipleByte (\r
-             I2cDeviceAddr,\r
-             I2cAddrMode,\r
-             &WriteLength,\r
-             Data\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-}\r
-\r
-\r
 EFI_SPI_PROTOCOL *\r
 LocateSpiProtocol (\r
   IN  EFI_SMM_SYSTEM_TABLE2             *Smst\r
@@ -612,121 +482,3 @@ PlatformIsBootWithRecoveryStage1 (
   return FALSE;\r
 }\r
 \r
-/**\r
-  Set the direction of Pcal9555 IO Expander GPIO pin.\r
-\r
-  @param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
-  @param  GpioNum            Gpio direction to configure - values 0-7 for Port0\r
-                             and 8-15 for Port1.\r
-  @param  CfgAsInput         If TRUE set pin direction as input else set as output.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PlatformPcal9555GpioSetDir (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum,\r
-  IN CONST BOOLEAN                        CfgAsInput\r
-  )\r
-{\r
-  Pcal9555SetPortRegBit (\r
-    Pcal9555SlaveAddr,\r
-    GpioNum,\r
-    PCAL9555_REG_CFG_PORT0,\r
-    CfgAsInput\r
-    );\r
-}\r
-\r
-/**\r
-  Set the level of Pcal9555 IO Expander GPIO high or low.\r
-\r
-  @param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
-  @param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
-                             for Port1.\r
-  @param  HighLevel          If TRUE set pin high else set pin low.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PlatformPcal9555GpioSetLevel (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum,\r
-  IN CONST BOOLEAN                        HighLevel\r
-  )\r
-{\r
-  Pcal9555SetPortRegBit (\r
-    Pcal9555SlaveAddr,\r
-    GpioNum,\r
-    PCAL9555_REG_OUT_PORT0,\r
-    HighLevel\r
-    );\r
-}\r
-\r
-/**\r
-\r
-  Enable pull-up/pull-down resistors of Pcal9555 GPIOs.\r
-\r
-  @param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
-  @param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
-                             for Port1.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PlatformPcal9555GpioEnablePull (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum\r
-  )\r
-{\r
-  Pcal9555SetPortRegBit (\r
-    Pcal9555SlaveAddr,\r
-    GpioNum,\r
-    PCAL9555_REG_PULL_EN_PORT0,\r
-    TRUE\r
-    );\r
-}\r
-\r
-/**\r
-\r
-  Disable pull-up/pull-down resistors of Pcal9555 GPIOs.\r
-\r
-  @param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
-  @param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
-                             for Port1.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-PlatformPcal9555GpioDisablePull (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum\r
-  )\r
-{\r
-  Pcal9555SetPortRegBit (\r
-    Pcal9555SlaveAddr,\r
-    GpioNum,\r
-    PCAL9555_REG_PULL_EN_PORT0,\r
-    FALSE\r
-    );\r
-}\r
-\r
-/**\r
-\r
-  Get state of Pcal9555 GPIOs.\r
-\r
-  @param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
-  @param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
-                             for Port1.\r
-\r
-  @retval TRUE               GPIO pin is high\r
-  @retval FALSE              GPIO pin is low\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-PlatformPcal9555GpioGetState (\r
-  IN CONST UINT32                         Pcal9555SlaveAddr,\r
-  IN CONST UINT32                         GpioNum\r
-  )\r
-{\r
-  return Pcal9555GetPortRegBit (Pcal9555SlaveAddr, GpioNum, PCAL9555_REG_IN_PORT0);\r
-}\r
index 6aefdb37943279f230b5551195ddb1958f75ba68..f9ceda4aaf5d3057d700ac2cdc6bbc5336926468 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Helper routines with common PEI / DXE implementation.\r
 \r
-Copyright (c) 2013-2015 Intel Corporation.\r
+Copyright (c) 2013-2016 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
@@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 \r
 #include "CommonHeader.h"\r
+#include <Library/I2cLib.h>\r
 \r
 CHAR16 *mPlatTypeNameTable[]  = { EFI_PLATFORM_TYPE_NAME_TABLE_DEFINITION };\r
 UINTN mPlatTypeNameTableLen  = ((sizeof(mPlatTypeNameTable)) / sizeof (CHAR16 *));\r
@@ -261,3 +262,253 @@ PlatformLegacyGpioGetLevel (
   GpioNumMask = (1 << GpioNum);\r
   return ((RegValue & GpioNumMask) != 0);\r
 }\r
+\r
+\r
+BOOLEAN\r
+Pcal9555GetPortRegBit (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum,\r
+  IN CONST UINT8                          RegBase\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  UINTN                             ReadLength;\r
+  UINTN                             WriteLength;\r
+  UINT8                             Data[2];\r
+  EFI_I2C_DEVICE_ADDRESS            I2cDeviceAddr;\r
+  EFI_I2C_ADDR_MODE                 I2cAddrMode;\r
+  UINT8                             *RegValuePtr;\r
+  UINT8                             GpioNumMask;\r
+  UINT8                             SubAddr;\r
+\r
+  I2cDeviceAddr.I2CDeviceAddress = (UINTN)Pcal9555SlaveAddr;\r
+  I2cAddrMode = EfiI2CSevenBitAddrMode;\r
+\r
+  if (GpioNum < 8) {\r
+    SubAddr = RegBase;\r
+    GpioNumMask = (UINT8)(1 << GpioNum);\r
+  } else {\r
+    SubAddr = RegBase + 1;\r
+    GpioNumMask = (UINT8)(1 << (GpioNum - 8));\r
+  }\r
+\r
+  //\r
+  // Output port value always at 2nd byte in Data variable.\r
+  //\r
+  RegValuePtr = &Data[1];\r
+\r
+  //\r
+  // On read entry sub address at 2nd byte, on read exit output\r
+  // port value in 2nd byte.\r
+  //\r
+  Data[1] = SubAddr;\r
+  WriteLength = 1;\r
+  ReadLength = 1;\r
+  Status = I2cReadMultipleByte (\r
+    I2cDeviceAddr,\r
+    I2cAddrMode,\r
+    &WriteLength,\r
+    &ReadLength,\r
+    &Data[1]\r
+    );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Adjust output port bit given callers request.\r
+  //\r
+  return ((*RegValuePtr & GpioNumMask) != 0);\r
+}\r
+\r
+VOID\r
+Pcal9555SetPortRegBit (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum,\r
+  IN CONST UINT8                          RegBase,\r
+  IN CONST BOOLEAN                        LogicOne\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  UINTN                             ReadLength;\r
+  UINTN                             WriteLength;\r
+  UINT8                             Data[2];\r
+  EFI_I2C_DEVICE_ADDRESS            I2cDeviceAddr;\r
+  EFI_I2C_ADDR_MODE                 I2cAddrMode;\r
+  UINT8                             *RegValuePtr;\r
+  UINT8                             GpioNumMask;\r
+  UINT8                             SubAddr;\r
+\r
+  I2cDeviceAddr.I2CDeviceAddress = (UINTN)Pcal9555SlaveAddr;\r
+  I2cAddrMode = EfiI2CSevenBitAddrMode;\r
+\r
+  if (GpioNum < 8) {\r
+    SubAddr = RegBase;\r
+    GpioNumMask = (UINT8)(1 << GpioNum);\r
+  } else {\r
+    SubAddr = RegBase + 1;\r
+    GpioNumMask = (UINT8)(1 << (GpioNum - 8));\r
+  }\r
+\r
+  //\r
+  // Output port value always at 2nd byte in Data variable.\r
+  //\r
+  RegValuePtr = &Data[1];\r
+\r
+  //\r
+  // On read entry sub address at 2nd byte, on read exit output\r
+  // port value in 2nd byte.\r
+  //\r
+  Data[1] = SubAddr;\r
+  WriteLength = 1;\r
+  ReadLength = 1;\r
+  Status = I2cReadMultipleByte (\r
+    I2cDeviceAddr,\r
+    I2cAddrMode,\r
+    &WriteLength,\r
+    &ReadLength,\r
+    &Data[1]\r
+    );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Adjust output port bit given callers request.\r
+  //\r
+  if (LogicOne) {\r
+    *RegValuePtr = *RegValuePtr | GpioNumMask;\r
+  } else {\r
+    *RegValuePtr = *RegValuePtr & ~(GpioNumMask);\r
+  }\r
+\r
+  //\r
+  // Update register. Sub address at 1st byte, value at 2nd byte.\r
+  //\r
+  WriteLength = 2;\r
+  Data[0] = SubAddr;\r
+  Status = I2cWriteMultipleByte (\r
+    I2cDeviceAddr,\r
+    I2cAddrMode,\r
+    &WriteLength,\r
+    Data\r
+    );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+/**\r
+Set the direction of Pcal9555 IO Expander GPIO pin.\r
+\r
+@param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
+@param  GpioNum            Gpio direction to configure - values 0-7 for Port0\r
+and 8-15 for Port1.\r
+@param  CfgAsInput         If TRUE set pin direction as input else set as output.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformPcal9555GpioSetDir (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum,\r
+  IN CONST BOOLEAN                        CfgAsInput\r
+  )\r
+{\r
+  Pcal9555SetPortRegBit (\r
+    Pcal9555SlaveAddr,\r
+    GpioNum,\r
+    PCAL9555_REG_CFG_PORT0,\r
+    CfgAsInput\r
+    );\r
+}\r
+\r
+/**\r
+Set the level of Pcal9555 IO Expander GPIO high or low.\r
+\r
+@param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
+@param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
+for Port1.\r
+@param  HighLevel          If TRUE set pin high else set pin low.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformPcal9555GpioSetLevel (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum,\r
+  IN CONST BOOLEAN                        HighLevel\r
+  )\r
+{\r
+  Pcal9555SetPortRegBit (\r
+    Pcal9555SlaveAddr,\r
+    GpioNum,\r
+    PCAL9555_REG_OUT_PORT0,\r
+    HighLevel\r
+    );\r
+}\r
+\r
+/**\r
+\r
+Enable pull-up/pull-down resistors of Pcal9555 GPIOs.\r
+\r
+@param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
+@param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
+for Port1.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformPcal9555GpioEnablePull (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum\r
+  )\r
+{\r
+  Pcal9555SetPortRegBit (\r
+    Pcal9555SlaveAddr,\r
+    GpioNum,\r
+    PCAL9555_REG_PULL_EN_PORT0,\r
+    TRUE\r
+    );\r
+}\r
+\r
+/**\r
+\r
+Disable pull-up/pull-down resistors of Pcal9555 GPIOs.\r
+\r
+@param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
+@param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
+for Port1.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PlatformPcal9555GpioDisablePull (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum\r
+  )\r
+{\r
+  Pcal9555SetPortRegBit (\r
+    Pcal9555SlaveAddr,\r
+    GpioNum,\r
+    PCAL9555_REG_PULL_EN_PORT0,\r
+    FALSE\r
+    );\r
+}\r
+\r
+/**\r
+\r
+Get state of Pcal9555 GPIOs.\r
+\r
+@param  Pcal9555SlaveAddr  I2c Slave address of Pcal9555 Io Expander.\r
+@param  GpioNum            Gpio to change values 0-7 for Port0 and 8-15\r
+for Port1.\r
+\r
+@retval TRUE               GPIO pin is high\r
+@retval FALSE              GPIO pin is low\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+PlatformPcal9555GpioGetState (\r
+  IN CONST UINT32                         Pcal9555SlaveAddr,\r
+  IN CONST UINT32                         GpioNum\r
+  )\r
+{\r
+  return Pcal9555GetPortRegBit (Pcal9555SlaveAddr, GpioNum, PCAL9555_REG_IN_PORT0);\r
+}\r
+\r
+\r