Browse Source

KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings

Now that an implementation of the HDMI debug port is available at high
speed, make the timing parameters configurable. As this is
implementation, not board dependent, perhaps these could become
dynamic PCDs.

Arduino sketch available at
https://github.com/benjamindoron/i2c_debug_port.

Tested on Adafruit ItsyBitsy M4, using 1 MHz clock and 60 us delay.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
Reviewed-by: Isaac Oram <isaac.w.oram@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Benjamin Doron 1 year ago
parent
commit
e43a63746f

+ 2 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf

@@ -51,3 +51,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES

+ 7 - 2
Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c

@@ -443,6 +443,7 @@ GmbusRead (
 {
   EFI_STATUS              Status;
   EFI_STATUS              Status2;
+  UINT8                   GmbusClockRate;
   UINT32                  Index;
   UINT32                  GmbusCmdSts;
   UINT32                  GmbusStatus;
@@ -472,7 +473,8 @@ GmbusRead (
   //
   // Configure Gmbus port and clock speed
   //
-  Status = GmbusPrepare (GMBUS_CLOCK_RATE_50K, (DdcBusPinPair & B_SA_GTTMMADR_GMBUS0_PIN_PAIR_MASK));
+  GmbusClockRate = FixedPcdGet8 (PcdI2cHdmiDebugPortGmbusClockRate);
+  Status = GmbusPrepare (GmbusClockRate, (DdcBusPinPair & B_SA_GTTMMADR_GMBUS0_PIN_PAIR_MASK));
   if (EFI_ERROR (Status)) {
     goto Done;
   }
@@ -607,6 +609,7 @@ GmbusWrite (
 {
   EFI_STATUS              Status;
   EFI_STATUS              Status2;
+  UINT8                   GmbusClockRate;
   UINT32                  Index;
   UINT32                  GmbusCmdSts;
   UINT32                  GmbusStatus;
@@ -637,7 +640,9 @@ GmbusWrite (
 
   //
   // Configure Gmbus port and clock speed
-  Status = GmbusPrepare (GMBUS_CLOCK_RATE_50K, (DdcBusPinPair & B_SA_GTTMMADR_GMBUS0_PIN_PAIR_MASK));
+  //
+  GmbusClockRate = FixedPcdGet8 (PcdI2cHdmiDebugPortGmbusClockRate);
+  Status = GmbusPrepare (GmbusClockRate, (DdcBusPinPair & B_SA_GTTMMADR_GMBUS0_PIN_PAIR_MASK));
   if (EFI_ERROR (Status)) {
     goto Done;
   }

+ 9 - 3
Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c

@@ -38,6 +38,7 @@ I2cDebugPortWrite (
   UINT8       WriteBuffer[I2C_DEBUG_PORT_MAX_DATA_SIZE + 1];
   EFI_STATUS  Status;
   UINT32      Index;
+  UINT32      ImplementationDelayUs;
   UINT8       CurrentSize;
   UINT8       DdcBusPinPair;
 
@@ -51,9 +52,10 @@ I2cDebugPortWrite (
   if (EFI_ERROR (Status)) {
     return Status;
   }
+  ImplementationDelayUs = FixedPcdGet32 (PcdI2cHdmiDebugPortPacketStallUs);  //BP: 3ms stall to catch up
   RaiseTplForI2cDebugPortAccess ();
   for (Index = 0; Index < Count; Index += I2C_DEBUG_PORT_MAX_DATA_SIZE) {
-    MicroSecondDelay (3000);  //3ms stall to let the BusPirate catch up
+    MicroSecondDelay (ImplementationDelayUs);
     if ((Index + I2C_DEBUG_PORT_MAX_DATA_SIZE) >= Count) {
       CurrentSize = (UINT8) (Count - Index);
     } else {
@@ -95,6 +97,7 @@ I2cDebugPortRead (
   EFI_STATUS  Status;
   UINT32      Index;
   UINT32      BytesRead;
+  UINT32      ImplementationDelayUs;
   UINT32      CurrentSize;
   UINT8       DdcBusPinPair;
   UINT8       GmbusIndexData;
@@ -110,9 +113,10 @@ I2cDebugPortRead (
   if (EFI_ERROR (Status)) {
     return Status;
   }
+  ImplementationDelayUs = FixedPcdGet32 (PcdI2cHdmiDebugPortPacketStallUs);  //BP: 3ms stall to catch up
   RaiseTplForI2cDebugPortAccess ();
   for (Index = 0; Index < (*Count); Index += I2C_DEBUG_PORT_MAX_DATA_SIZE) {
-    MicroSecondDelay (3000);  //3ms stall to let the BusPirate catch up
+    MicroSecondDelay (ImplementationDelayUs);
     if ((Index + I2C_DEBUG_PORT_MAX_DATA_SIZE) >= (*Count)) {
       CurrentSize = (*Count) - Index;
     } else {
@@ -163,6 +167,7 @@ I2cDebugPortReadyToRead (
   EFI_STATUS  Status;
   UINT32      BytesRead;
   UINT8       DdcBusPinPair;
+  UINT32      ImplementationDelayUs;
   UINT8       GmbusIndexData;
 
   BytesRead = 1;
@@ -173,7 +178,8 @@ I2cDebugPortReadyToRead (
   if (EFI_ERROR (Status)) {
     return Status;
   }
-  MicroSecondDelay (3000);  //3ms stall to let the BusPirate catch up
+  ImplementationDelayUs = FixedPcdGet32 (PcdI2cHdmiDebugPortPacketStallUs);  //BP: 3ms stall to catch up
+  MicroSecondDelay (ImplementationDelayUs);
   GmbusIndexData  = (I2C_DEBUG_PORT_READY_TO_READ_COMMAND << I2C_DEBUG_PORT_COMMAND_BIT_POSITION) |
                     (1 & I2C_DEBUG_PORT_DATA_SIZE_BIT_MASK); //READY_TO_READ always returns 1 byte
   RaiseTplForI2cDebugPortAccess ();

+ 2 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf

@@ -52,3 +52,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES

+ 2 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf

@@ -51,3 +51,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES

+ 2 - 0
Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf

@@ -51,3 +51,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES

+ 19 - 0
Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec

@@ -102,6 +102,25 @@ gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortSerialTerminalEnable|FALS
 # @Prompt DDC I2C channel to claim as the HDMI debug port
 gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel|0x00000000|UINT32|0x90000035
 
+## Specifies the DDC I2C speed to use for the HDMI debug port
+#  The value is defined as below.
+#  0: I2C speed 100K
+#  1: I2C speed 50K
+#  2: I2C speed 400K
+#  3: I2C speed 1M
+#  Recommendations as below:
+#  BusPirate: 50K. Increase internal baudrate generator for 100K, maybe 400K. Potentially less stable
+#  Atmel SAMD boards: 1M
+# @Prompt DDC I2C speed to use for the HDMI debug port
+gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate|0x01|UINT8|0x90000036
+
+## Specifies the stall in microsends between packets on the HDMI debug port
+#  Recommendations as below:
+#  BusPirate: 3000
+#  Atmel SAMD boards: 60
+# @Prompt Stall in microsends between packets on the HDMI debug port
+gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs|3000|UINT32|0x90000037
+
 [PcdsDynamic]
 
 # Board GPIO Table