public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings
@ 2023-01-13 17:56 Benjamin Doron
  2023-01-13 21:05 ` Isaac Oram
  2023-01-18  0:44 ` Nate DeSimone
  0 siblings, 2 replies; 4+ messages in thread
From: Benjamin Doron @ 2023-01-13 17:56 UTC (permalink / raw)
  To: devel; +Cc: Sai Chaganty, Isaac Oram, Nate DeSimone, Chasel Chiu

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>
---
 .../DxeI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../Library/I2cHdmiDebugSerialPortLib/Gmbus.c |  9 +++++++--
 .../I2cDebugPortProtocol.c                    | 12 +++++++++---
 .../PeiI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SecI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SmmI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../KabylakeOpenBoardPkg/OpenBoardPkg.dec     | 19 +++++++++++++++++++
 7 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
index 736b11a561f0..e8af25161008 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
index c6453117843a..31965a1b3a54 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
+++ b/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;
   }
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
index f76bcf364cd1..d64251b75b4e 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
+++ b/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 ();
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
index c82e0c9e9b76..c141521a0cd9 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
@@ -52,3 +52,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
index 3b84b25c3148..ed755699c312 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
index 68ff31495071..9f46d45b8a38 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES
   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES
+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMES
diff --git a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec b/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
index 448eafacbfcd..401f6416aa1c 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
+++ b/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
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings
  2023-01-13 17:56 [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings Benjamin Doron
@ 2023-01-13 21:05 ` Isaac Oram
  2023-01-18  0:44 ` Nate DeSimone
  1 sibling, 0 replies; 4+ messages in thread
From: Isaac Oram @ 2023-01-13 21:05 UTC (permalink / raw)
  To: Benjamin Doron, devel@edk2.groups.io
  Cc: Chaganty, Rangasai V, Desimone, Nathaniel L, Chiu, Chasel

Reviewed-by: Isaac Oram <isaac.w.oram@intel.com>

-----Original Message-----
From: Benjamin Doron <benjamin.doron00@gmail.com> 
Sent: Friday, January 13, 2023 9:56 AM
To: devel@edk2.groups.io
Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Oram, Isaac W <isaac.w.oram@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>
Subject: [edk2-devel][edk2-platforms][PATCH v2] 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>
---
 .../DxeI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../Library/I2cHdmiDebugSerialPortLib/Gmbus.c |  9 +++++++--
 .../I2cDebugPortProtocol.c                    | 12 +++++++++---
 .../PeiI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SecI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SmmI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../KabylakeOpenBoardPkg/OpenBoardPkg.dec     | 19 +++++++++++++++++++
 7 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
index 736b11a561f0..e8af25161008 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/DxeI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
index c6453117843a..31965a1b3a54 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/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;   }diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
index f76bcf364cd1..d64251b75b4e 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/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 ();diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
index c82e0c9e9b76..c141521a0cd9 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/PeiI2cHdmiDebugSerialPortLib.inf
@@ -52,3 +52,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
index 3b84b25c3148..ed755699c312 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/SecI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
index 68ff31495071..9f46d45b8a38 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/SmmI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec b/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
index 448eafacbfcd..401f6416aa1c 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
+++ b/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--
2.39.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings
  2023-01-13 17:56 [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings Benjamin Doron
  2023-01-13 21:05 ` Isaac Oram
@ 2023-01-18  0:44 ` Nate DeSimone
  2023-01-18  0:47   ` Isaac Oram
  1 sibling, 1 reply; 4+ messages in thread
From: Nate DeSimone @ 2023-01-18  0:44 UTC (permalink / raw)
  To: Benjamin Doron, devel@edk2.groups.io
  Cc: Chaganty, Rangasai V, Oram, Isaac W, Chiu, Chasel

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: Benjamin Doron <benjamin.doron00@gmail.com> 
Sent: Friday, January 13, 2023 9:56 AM
To: devel@edk2.groups.io
Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Oram, Isaac W <isaac.w.oram@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>
Subject: [edk2-devel][edk2-platforms][PATCH v2] 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>
---
 .../DxeI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../Library/I2cHdmiDebugSerialPortLib/Gmbus.c |  9 +++++++--
 .../I2cDebugPortProtocol.c                    | 12 +++++++++---
 .../PeiI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SecI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SmmI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../KabylakeOpenBoardPkg/OpenBoardPkg.dec     | 19 +++++++++++++++++++
 7 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
index 736b11a561f0..e8af25161008 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/DxeI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
index c6453117843a..31965a1b3a54 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/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;   }diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
index f76bcf364cd1..d64251b75b4e 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/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 ();diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
index c82e0c9e9b76..c141521a0cd9 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/PeiI2cHdmiDebugSerialPortLib.inf
@@ -52,3 +52,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
index 3b84b25c3148..ed755699c312 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/SecI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
index 68ff31495071..9f46d45b8a38 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/SmmI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec b/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
index 448eafacbfcd..401f6416aa1c 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
+++ b/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--
2.39.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings
  2023-01-18  0:44 ` Nate DeSimone
@ 2023-01-18  0:47   ` Isaac Oram
  0 siblings, 0 replies; 4+ messages in thread
From: Isaac Oram @ 2023-01-18  0:47 UTC (permalink / raw)
  To: Desimone, Nathaniel L, Benjamin Doron, devel@edk2.groups.io
  Cc: Chaganty, Rangasai V, Chiu, Chasel

Pushed as 8e927b0f42..e43a63746f

-----Original Message-----
From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com> 
Sent: Tuesday, January 17, 2023 4:45 PM
To: Benjamin Doron <benjamin.doron00@gmail.com>; devel@edk2.groups.io
Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Oram, Isaac W <isaac.w.oram@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>
Subject: RE: [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: Benjamin Doron <benjamin.doron00@gmail.com> 
Sent: Friday, January 13, 2023 9:56 AM
To: devel@edk2.groups.io
Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Oram, Isaac W <isaac.w.oram@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>
Subject: [edk2-devel][edk2-platforms][PATCH v2] 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>
---
 .../DxeI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../Library/I2cHdmiDebugSerialPortLib/Gmbus.c |  9 +++++++--
 .../I2cDebugPortProtocol.c                    | 12 +++++++++---
 .../PeiI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SecI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../SmmI2cHdmiDebugSerialPortLib.inf          |  2 ++
 .../KabylakeOpenBoardPkg/OpenBoardPkg.dec     | 19 +++++++++++++++++++
 7 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
index 736b11a561f0..e8af25161008 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/DxeI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/DxeI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
index c6453117843a..31965a1b3a54 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/Gmbus.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/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;   }diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
index f76bcf364cd1..d64251b75b4e 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/I2cDebugPortProtocol.c
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/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 ();diff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
index c82e0c9e9b76..c141521a0cd9 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/PeiI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/PeiI2cHdmiDebugSerialPortLib.inf
@@ -52,3 +52,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
index 3b84b25c3148..ed755699c312 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SecI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/SecI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
index 68ff31495071..9f46d45b8a38 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPortLib/SmmI2cHdmiDebugSerialPortLib.inf
+++ b/Platform/Intel/KabylakeOpenBoardPkg/Library/I2cHdmiDebugSerialPort
+++ Lib/SmmI2cHdmiDebugSerialPortLib.inf
@@ -51,3 +51,5 @@
 [Pcd]   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortDdcI2cChannel    ## CONSUMES   gKabylakeOpenBoardPkgTokenSpaceGuid.PcdGttMmAddress                     ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortGmbusClockRate   ## CONSUMES+  gKabylakeOpenBoardPkgTokenSpaceGuid.PcdI2cHdmiDebugPortPacketStallUs    ## CONSUMESdiff --git a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec b/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
index 448eafacbfcd..401f6416aa1c 100644
--- a/Platform/Intel/KabylakeOpenBoardPkg/OpenBoardPkg.dec
+++ b/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--
2.39.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-18  0:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-13 17:56 [edk2-devel][edk2-platforms][PATCH v2] KabylakeOpenBoardPkg/I2cHdmiDebugSerialPortLib: Configurable timings Benjamin Doron
2023-01-13 21:05 ` Isaac Oram
2023-01-18  0:44 ` Nate DeSimone
2023-01-18  0:47   ` Isaac Oram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox