]> git.proxmox.com Git - mirror_edk2.git/commitdiff
QuarkPlatformPkg/PlatformEarlyInit: Configure GPIO expander
authorMichael Kinney <michael.d.kinney@intel.com>
Thu, 7 Jan 2016 22:43:22 +0000 (22:43 +0000)
committermdkinney <mdkinney@Edk2>
Thu, 7 Jan 2016 22:43:22 +0000 (22:43 +0000)
Configure GPIO expander in PEI phase
1) Configure all GPIO expander pins connected to Reset Button as inputs
2) Configure multiplexer for I2C to route I2C bus to Arduino Header

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@19620 6f19259b-4bc3-4df7-8a09-765794883524

QuarkPlatformPkg/Platform/Pei/PlatformInit/CommonHeader.h
QuarkPlatformPkg/Platform/Pei/PlatformInit/PlatformEarlyInit.c
QuarkPlatformPkg/Platform/Pei/PlatformInit/PlatformEarlyInit.inf

index 3630f347b6eaff5b08532530c820f199317d1117..98284958a4151eced3235d5c655753489cea42fc 100644 (file)
@@ -3,7 +3,7 @@ Common header file shared by all source files.
 \r
 This file includes package header files, library classes and protocol, PPI & GUID definitions.\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
@@ -78,6 +78,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/QNCAccessLib.h>\r
 #include <Library/PlatformHelperLib.h>\r
 #include <Library/PlatformPcieHelperLib.h>\r
+#include <Library/I2cLib.h>\r
 \r
 #include <Register/Cpuid.h>\r
 \r
index 32ae3e089189d2537ea14391c6f10bd0f4d96dbe..756cc4a7a33337e0d50600c972588fbcd6ffe256 100644 (file)
@@ -6,7 +6,7 @@ This PEIM initialize platform for MRC, following action is performed,
 4. Calls MRC to initialize memory and install a PPI notify to do post memory initialization.\r
 This file contains the main entrypoint of the PEIM.\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
@@ -192,6 +192,212 @@ SetLanControllerMacAddr (
   PciWrite16 (DevPcieAddr + PCI_COMMAND_OFFSET, SaveCmdReg);\r
 }\r
 \r
+/**\r
+  Initialize state of I2C GPIO expanders.\r
+\r
+  @param  PlatformType  Platform type for GPIO expander init.\r
+\r
+**/\r
+EFI_STATUS\r
+EarlyPlatformConfigGpioExpanders (\r
+  IN CONST EFI_PLATFORM_TYPE              PlatformType\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_I2C_DEVICE_ADDRESS  I2CSlaveAddress;\r
+  UINTN                   Length;\r
+  UINTN                   ReadLength;\r
+  UINT8                   Buffer[2];\r
+\r
+  //\r
+  // Configure GPIO expanders for Galileo Gen 2\r
+  // Route I2C pins to Arduino header\r
+  // Set all GPIO expander pins connected to the Reset Button as inputs\r
+  //\r
+  if (PlatformType == GalileoGen2) {\r
+    //\r
+    // Configure AMUX1_IN (EXP2.P1_4) as an output\r
+    //\r
+    PlatformPcal9555GpioSetDir (\r
+      GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR,  // IO Expander 2.\r
+      12,                                   // P1-4.\r
+      FALSE                                 // Configure as output\r
+      );\r
+\r
+    //\r
+    // Set AMUX1_IN(EXP2.P1_4) low to route I2C to Arduino Shield connector\r
+    //\r
+    PlatformPcal9555GpioSetLevel (\r
+      GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR,  // IO Expander 2.\r
+      12,                                   // P1-4. \r
+      FALSE                                 // Set pin low\r
+      );\r
+\r
+    //\r
+    // Configure Reset Button(EXP1.P1_7) as an input\r
+    //\r
+    PlatformPcal9555GpioSetDir (\r
+      GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR,  // IO Expander 1.\r
+      15,                                   // P1-7.\r
+      TRUE\r
+      );\r
+\r
+    //\r
+    // Disable pullup on Reset Button(EXP1.P1_7)\r
+    //\r
+    PlatformPcal9555GpioDisablePull (\r
+      GALILEO_GEN2_IOEXP1_7BIT_SLAVE_ADDR,  // IO Expander 1.\r
+      15                                    // P1-7.\r
+      );\r
+\r
+    //\r
+    // Configure Reset Button(EXP2.P1_7) as an input\r
+    //\r
+    PlatformPcal9555GpioSetDir (\r
+      GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR,  // IO Expander 2.\r
+      15,                                   // P1-7.\r
+      TRUE\r
+      );\r
+\r
+    //\r
+    // Disable pullup on Reset Button(EXP2.P1_7)\r
+    //\r
+    PlatformPcal9555GpioDisablePull (\r
+      GALILEO_GEN2_IOEXP2_7BIT_SLAVE_ADDR,  // IO Expander 2.\r
+      15                                    // P1-7.\r
+      );\r
+  }\r
+\r
+  //\r
+  // Configure GPIO expanders for Galileo Gen 2\r
+  // Set all GPIO expander pins connected to the Reset Button as inputs\r
+  // Route I2C pins to Arduino header\r
+  //\r
+  if (PlatformType == Galileo) {\r
+    //\r
+    // Detect the I2C Slave Address of the GPIO Expander\r
+    //\r
+    if (PlatformLegacyGpioGetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_DETERMINE_IOEXP_SLA_RESUMEWELL_GPIO)) {\r
+      I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2HI_7BIT_SLAVE_ADDR;\r
+    } else {\r
+      I2CSlaveAddress.I2CDeviceAddress = GALILEO_IOEXP_J2LO_7BIT_SLAVE_ADDR;\r
+    }\r
+    DEBUG ((EFI_D_INFO, "Galileo GPIO Expender Slave Address = %02x\n", I2CSlaveAddress.I2CDeviceAddress));\r
+\r
+    //\r
+    // Set I2C_MUX (GPORT1_BIT5) low to route I2C to Arduino Shield connector\r
+    //\r
+\r
+    //\r
+    // Select GPIO Expander GPORT1\r
+    //\r
+    Length = 2;\r
+    Buffer[0] = 0x18; //sub-address\r
+    Buffer[1] = 0x01; //data\r
+    Status = I2cWriteMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &Buffer\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Read "Pin Direction" of GPIO Expander GPORT1\r
+    //\r
+    Length = 1;\r
+    ReadLength = 1;\r
+    Buffer[1] = 0x1C;\r
+    Status = I2cReadMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &ReadLength,\r
+      &Buffer[1]\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Configure GPIO Expander GPORT1_BIT5 as an output\r
+    //\r
+    Length = 2;\r
+    Buffer[0] = 0x1C; //sub-address\r
+    Buffer[1] = (UINT8)(Buffer[1] & (~BIT5)); //data\r
+\r
+    Status = I2cWriteMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &Buffer\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Set GPIO Expander GPORT1_BIT5 low\r
+    //\r
+    Length = 2;\r
+    Buffer[0] = 0x09; //sub-address\r
+    Buffer[1] = (UINT8)(~BIT5); //data\r
+\r
+    Status = I2cWriteMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &Buffer\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Configure RESET_N_SHLD (GPORT5_BIT0) and SW_RESET_N_SHLD (GPORT5_BIT1) as inputs\r
+    //\r
+\r
+    //\r
+    // Select GPIO Expander GPORT5\r
+    //\r
+    Length = 2;\r
+    Buffer[0] = 0x18;\r
+    Buffer[1] = 0x05;\r
+    Status = I2cWriteMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &Buffer\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Read "Pin Direction" of GPIO Expander GPORT5\r
+    //\r
+    Length = 1;\r
+    ReadLength = 1;\r
+    Buffer[1] = 0x1C;\r
+    Status = I2cReadMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &ReadLength,\r
+      &Buffer[1]\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    //\r
+    // Configure GPIO Expander GPORT5_BIT0 and GPORT5_BIT1 as inputs\r
+    //\r
+    Length = 2;\r
+    Buffer[0] = 0x1C;\r
+    Buffer[1] = Buffer[1] | BIT0 | BIT1;\r
+    Status = I2cWriteMultipleByte (\r
+      I2CSlaveAddress,\r
+      EfiI2CSevenBitAddrMode,\r
+      &Length,\r
+      &Buffer\r
+      );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   This is the entrypoint of PEIM\r
 \r
@@ -304,6 +510,12 @@ PeiInitPlatform (
   DEBUG ((EFI_D_INFO, "Platform Erratas After MRC\n"));\r
   PlatformErratasPostMrc ();\r
 \r
+  //\r
+  //\r
+  //\r
+  DEBUG ((EFI_D_INFO, "EarlyPlatformConfigGpioExpanders ()\n"));\r
+  EarlyPlatformConfigGpioExpanders (PlatformType);\r
+\r
   //\r
   // Now that all of the pre-permanent memory activities have\r
   // been taken care of, post a call-back for the permanent-memory\r
index dd373defdb58f7072c44e965287f3166ef010857..1de8efd33e1f411e076099d8b2176c7dce0af69b 100644 (file)
@@ -36,7 +36,7 @@
 #     memory specific stuff like build memory map, build\r
 #     resource description hob for DXE phase,etc.\r
 #  Bootmode.c - Detect boot mode.\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
   QNCAccessLib\r
   PlatformHelperLib\r
   PlatformPcieHelperLib\r
+  I2cLib\r
 \r
 [Guids]\r
   gEfiMemoryConfigDataGuid                      # ALWAYS_CONSUMED L"MemoryConfig"\r