public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Chris Co <Christopher.Co@microsoft.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	Michael D Kinney <michael.d.kinney@intel.com>
Subject: [PATCH edk2-platforms 07/27] Silicon/NXP: Add i.MX display library support
Date: Fri, 21 Sep 2018 08:25:58 +0000	[thread overview]
Message-ID: <20180921082542.35768-8-christopher.co@microsoft.com> (raw)
In-Reply-To: <20180921082542.35768-1-christopher.co@microsoft.com>

This adds support for processing EDID data on NXP i.MX platforms.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Christopher Co <christopher.co@microsoft.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
---
 Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h                    | 114 +++++++++++++++
 Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.c   | 152 ++++++++++++++++++++
 Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.inf |  31 ++++
 3 files changed, 297 insertions(+)

diff --git a/Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h b/Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h
new file mode 100644
index 000000000000..70ef8d0af97f
--- /dev/null
+++ b/Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h
@@ -0,0 +1,114 @@
+/** @file
+*
+*  Copyright (c) 2018 Microsoft Corporation. All rights reserved.
+*
+*  This program and the accompanying materials
+*  are licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#ifndef __IMX_DISPLAY_H__
+#define __IMX_DISPLAY_H__
+
+#define EDID_MIN_SIZE       128
+#define EDID_I2C_ADDRESS    0x50
+
+// The first DTD is the preferred timing, refer to 3.1 VESA EDID spec.
+#define EDID_DTD_1_OFFSET   0x36
+#define EDID_DTD_2_OFFSET   0x48
+#define EDID_DTD_3_OFFSET   0x5A
+#define EDID_DTD_4_OFFSET   0x6C
+
+typedef enum {
+  PIXEL_FORMAT_ARGB32,
+  PIXEL_FORMAT_BGRA32,
+} PIXEL_FORMAT;
+
+typedef struct _DISPLAY_TIMING {
+  UINT32 PixelClock;
+  UINT32 HActive;
+  UINT32 HBlank;
+  UINT32 VActive;
+  UINT32 VBlank;
+  UINT32 HSync;
+  UINT32 VSync;
+  UINT32 HSyncOffset;
+  UINT32 VSyncOffset;
+  UINT32 HImageSize;
+  UINT32 VImageSize;
+  UINT32 HBorder;
+  UINT32 VBorder;
+  UINT32 EdidFlags;
+  UINT32 Flags;
+  UINT32 PixelRepetition;
+  UINT32 Bpp;
+  PIXEL_FORMAT PixelFormat;
+} DISPLAY_TIMING, *PDISPLAY_TIMING, DTD;
+
+typedef struct _DETAILED_TIMING_DESCRIPTOR {
+  UINT8 PixelClock[2];
+  UINT8 HActive;
+  UINT8 HBlank;
+  UINT8 HActiveBlank;
+  UINT8 VActive;
+  UINT8 VBlank;
+  UINT8 VActiveBlank;
+  UINT8 HSyncOffset;
+  UINT8 HSyncWidth;
+  UINT8 VSyncOffsetWidth;
+  UINT8 HVOffsetWidth;
+  UINT8 HImageSize;
+  UINT8 VImageSize;
+  UINT8 HVImageSize;
+  UINT8 HBorder;
+  UINT8 VBorder;
+  UINT8 EdidFlags;
+} DETAILED_TIMING_DESCRIPTOR, *PDETAILED_TIMING_DESCRIPTOR;
+
+/**
+  Convert detailed timing descriptor to display timing format
+
+  @param[in]    DTDPtr            Pointer to detailed timing descriptor.
+  @param[out]   DisplayTimingPtr  Pointer to display timing structure.
+
+  @retval   EFI_SUCCESS   Detailed timing descriptor data was converted.
+
+**/
+EFI_STATUS
+ConvertDTDToDisplayTiming (
+  IN DETAILED_TIMING_DESCRIPTOR   *DTDPtr,
+  OUT DISPLAY_TIMING              *DisplayTimingPtr
+  );
+
+/**
+  Debug dump of Display Timing structure
+
+  @param[in]    DisplayTimingNamePtr  Name of display timing structure.
+  @param[in]    DisplayTimingPtr      Pointer to display timing structure.
+**/
+VOID
+PrintDisplayTiming (
+  IN CHAR8            *DisplayTimingNamePtr,
+  IN DISPLAY_TIMING   *DisplayTimingPtr
+  );
+
+/**
+  Check if EDID is valid
+
+  @param[in]    EdidDataPtr  Pointer to EDID data.
+
+  @retval   EFI_SUCCESS             EDID data is a valid EDID.
+  @retval   EFI_INVALID_PARAMETER   EDID data is invalid.
+
+**/
+EFI_STATUS
+ValidateEdidData (
+  IN UINT8 *EdidDataPtr
+  );
+
+#endif // __IMX_DISPLAY_H__
diff --git a/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.c b/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.c
new file mode 100644
index 000000000000..9e90ece96260
--- /dev/null
+++ b/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.c
@@ -0,0 +1,152 @@
+/** @file
+*
+*  Copyright (c) 2018 Microsoft Corporation. All rights reserved.
+*
+*  This program and the accompanying materials
+*  are licensed and made available under the terms and conditions of the BSD License
+*  which accompanies this distribution.  The full text of the license may be found at
+*  http://opensource.org/licenses/bsd-license.php
+*
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+*
+**/
+
+#include <Uefi.h>
+
+#include <Library/DebugLib.h>
+
+#include <iMXDisplay.h>
+
+/**
+  Convert detailed timing descriptor to display timing format
+
+  @param[in]    DTDPtr            Pointer to detailed timing descriptor.
+  @param[out]   DisplayTimingPtr  Pointer to display timing structure.
+
+  @retval   EFI_SUCCESS   Detailed timing descriptor data was converted.
+
+**/
+EFI_STATUS
+ConvertDTDToDisplayTiming (
+  IN DETAILED_TIMING_DESCRIPTOR   *DTDPtr,
+  OUT DISPLAY_TIMING              *DisplayTimingPtr
+  )
+{
+  UINT32  edidPixelClock;
+
+  DEBUG ((DEBUG_INFO, "++ConvertDTDToDisplayTiming()\r\n"));
+  // Refer to 3.10.2 VESA EDID spec
+  edidPixelClock = (DTDPtr->PixelClock[0] | (DTDPtr->PixelClock[1] << 8));
+  DisplayTimingPtr->PixelClock = edidPixelClock * 10000;
+  DisplayTimingPtr->HActive = (DTDPtr->HActiveBlank & 0xF0);
+  DisplayTimingPtr->HActive = (DisplayTimingPtr->HActive << 4) | DTDPtr->HActive;
+  DisplayTimingPtr->HBlank = (DTDPtr->HActiveBlank & 0x0F);
+  DisplayTimingPtr->HBlank = (DisplayTimingPtr->HBlank << 8) | DTDPtr->HBlank;
+  DisplayTimingPtr->VActive = (DTDPtr->VActiveBlank & 0xF0);
+  DisplayTimingPtr->VActive = (DisplayTimingPtr->VActive << 4) | DTDPtr->VActive;
+  DisplayTimingPtr->VBlank = (DTDPtr->VActiveBlank & 0x0F);
+  DisplayTimingPtr->VBlank = (DisplayTimingPtr->VBlank << 8) | DTDPtr->VBlank;
+  DisplayTimingPtr->HSyncOffset = (DTDPtr->HVOffsetWidth & 0xC0);
+  DisplayTimingPtr->HSyncOffset = (DisplayTimingPtr->HSyncOffset << 2) |
+                                  DTDPtr->HSyncOffset;
+  DisplayTimingPtr->VSyncOffset = (DTDPtr->HVOffsetWidth & 0x0C);
+  DisplayTimingPtr->VSyncOffset = (DisplayTimingPtr->VSyncOffset << 2) |
+                                  ((DTDPtr->VSyncOffsetWidth & 0xF0) >> 4);
+  DisplayTimingPtr->HSync = (DTDPtr->HVOffsetWidth & 0x30);
+  DisplayTimingPtr->HSync = (DisplayTimingPtr->HSync << 4) | DTDPtr->HSyncWidth;
+  DisplayTimingPtr->VSync = (DTDPtr->HVOffsetWidth & 0x03);
+  DisplayTimingPtr->VSync = (DisplayTimingPtr->VSync << 4) |
+                            (DTDPtr->VSyncOffsetWidth & 0x0F);
+  DisplayTimingPtr->HImageSize = ((DTDPtr->HVImageSize & 0xF0) << 4) |
+                                 DTDPtr->HImageSize;
+  DisplayTimingPtr->VImageSize = ((DTDPtr->HVImageSize & 0x0F) << 8) |
+                                 DTDPtr->VImageSize;
+  DisplayTimingPtr->HBorder = DTDPtr->HBorder;
+  DisplayTimingPtr->VBorder = DTDPtr->VBorder;
+  DisplayTimingPtr->EdidFlags = DTDPtr->EdidFlags;
+  DisplayTimingPtr->Flags = 0;
+
+  DEBUG ((DEBUG_INFO, "--ConvertDTDToDisplayTiming()=ok\r\n"));
+  return EFI_SUCCESS;
+}
+
+/**
+  Debug dump of Display Timing structure
+
+  @param[in]    DisplayTimingNamePtr  Name of display timing structure.
+  @param[in]    DisplayTimingPtr      Pointer to display timing structure.
+**/
+VOID
+PrintDisplayTiming (
+  IN CHAR8            *DisplayTimingNamePtr,
+  IN DISPLAY_TIMING   *DisplayTimingPtr
+  )
+{
+  DEBUG ((DEBUG_INFO, "**********************\n"));
+  DEBUG ((DEBUG_INFO, "%a\n", DisplayTimingNamePtr));
+  DEBUG ((DEBUG_INFO, "**********************\n"));
+  DEBUG ((DEBUG_INFO, "PixelClock %d\n", DisplayTimingPtr->PixelClock));
+  DEBUG ((DEBUG_INFO, "HActive %d\n", DisplayTimingPtr->HActive));
+  DEBUG ((DEBUG_INFO, "HBlank %d\n", DisplayTimingPtr->HBlank));
+  DEBUG ((DEBUG_INFO, "VActive %d\n", DisplayTimingPtr->VActive));
+  DEBUG ((DEBUG_INFO, "VBlank %d\n", DisplayTimingPtr->VBlank));
+  DEBUG ((DEBUG_INFO, "HSync %d\n", DisplayTimingPtr->HSync));
+  DEBUG ((DEBUG_INFO, "VSync %d\n", DisplayTimingPtr->VSync));
+  DEBUG ((DEBUG_INFO, "HSyncOffset %d\n", DisplayTimingPtr->HSyncOffset));
+  DEBUG ((DEBUG_INFO, "VSyncOffset %d\n", DisplayTimingPtr->VSyncOffset));
+  DEBUG ((DEBUG_INFO, "HBorder %d\n", DisplayTimingPtr->HBorder));
+  DEBUG ((DEBUG_INFO, "VBorder %d\n", DisplayTimingPtr->VBorder));
+  DEBUG ((DEBUG_INFO, "EdidFlags %d\n", DisplayTimingPtr->EdidFlags));
+  DEBUG ((DEBUG_INFO, "Flags %d\n", DisplayTimingPtr->Flags));
+  DEBUG ((DEBUG_INFO, "PixelRepetition %d\n", DisplayTimingPtr->PixelRepetition));
+  DEBUG ((DEBUG_INFO, "BPP %d\n", DisplayTimingPtr->Bpp));
+  DEBUG ((DEBUG_INFO, "PixelFormat %d\n", DisplayTimingPtr->PixelFormat));
+  DEBUG ((DEBUG_INFO, "**********************\n"));
+}
+
+/**
+  Check if EDID is valid
+
+  @param[in]    EdidDataPtr  Pointer to EDID data.
+
+  @retval   EFI_SUCCESS             EDID data is a valid EDID.
+  @retval   EFI_INVALID_PARAMETER   EDID data is invalid.
+
+**/
+EFI_STATUS
+ValidateEdidData (
+  IN UINT8 *EdidDataPtr
+  )
+{
+  UINT8   Checksum;
+  UINT8   Index;
+
+  DEBUG ((DEBUG_INFO, "++ValidateEdidData()\r\n"));
+
+  if (EdidDataPtr[0] != 0x00 ||
+      EdidDataPtr[1] != 0xFF ||
+      EdidDataPtr[2] != 0xFF ||
+      EdidDataPtr[3] != 0xFF ||
+      EdidDataPtr[4] != 0xFF ||
+      EdidDataPtr[5] != 0xFF ||
+      EdidDataPtr[6] != 0xFF ||
+      EdidDataPtr[7] != 0x00) {
+    DEBUG ((DEBUG_ERROR, "Invalid EDID header\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  // Validate EDID checksum
+  Checksum = 0;
+  for (Index = 0; Index < EDID_MIN_SIZE; Index++) {
+    Checksum += EdidDataPtr[Index];
+  }
+
+  if (Checksum != 0) {
+    DEBUG ((DEBUG_ERROR, "Invalid EDID checksum\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((DEBUG_INFO, "--ValidateEdidData()=ok\r\n"));
+  return EFI_SUCCESS;
+}
diff --git a/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.inf b/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.inf
new file mode 100644
index 000000000000..bd77d4159639
--- /dev/null
+++ b/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.inf
@@ -0,0 +1,31 @@
+## @file
+#
+#  Copyright (c) 2018 Microsoft Corporation. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = iMXDisplayLib
+  FILE_GUID                      = C0408490-F09B-4CFA-9A2F-5159F2705323
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = iMXDisplayLib
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/NXP/iMXPlatformPkg/iMXPlatformPkg.dec
+
+[LibraryClasses]
+
+[Sources.common]
+  iMXDisplayLib.c
-- 
2.16.2.gvfs.1.33.gf5370f1



  parent reply	other threads:[~2018-09-21  8:25 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21  8:25 [PATCH edk2-platforms 00/27] Import Hummingboard Edge platform for Windows IoT Core Chris Co
2018-09-21  8:25 ` [PATCH edk2-platforms 01/27] Platform/Microsoft: Add OpteeClientPkg dec Chris Co
2018-10-31 20:43   ` Leif Lindholm
2018-11-01 10:55     ` Sumit Garg
2018-11-02  0:41       ` Chris Co
2018-11-02  5:24         ` Sumit Garg
2018-11-02 23:55           ` Chris Co
2018-11-05 10:07             ` Sumit Garg
2018-11-06  1:53               ` Chris Co
2018-11-06 11:09                 ` Sumit Garg
2018-09-21  8:25 ` [PATCH edk2-platforms 02/27] Platform/Microsoft: Add SdMmc Dxe Driver Chris Co
2018-09-21  8:25 ` [PATCH edk2-platforms 04/27] Silicon/NXP: Add iMXPlatformPkg dec Chris Co
2018-09-21  8:25 ` [PATCH edk2-platforms 03/27] Platform/Microsoft: Add MsPkg Chris Co
2018-10-31 21:00   ` Leif Lindholm
2018-09-21  8:25 ` [PATCH edk2-platforms 05/27] Silicon/NXP: Add UART library support for i.MX platforms Chris Co
2018-11-01  8:59   ` Leif Lindholm
2018-11-02  1:46     ` Chris Co
2018-09-21  8:25 ` [PATCH edk2-platforms 06/27] Silicon/NXP: Add I2C " Chris Co
2018-11-01 17:53   ` Leif Lindholm
2018-09-21  8:25 ` Chris Co [this message]
2018-11-01 18:05   ` [PATCH edk2-platforms 07/27] Silicon/NXP: Add i.MX display library support Leif Lindholm
2018-11-29  0:55     ` Chris Co
2018-09-21  8:25 ` [PATCH edk2-platforms 08/27] Silicon/NXP: Add Virtual RTC support for i.MX platform Chris Co
2018-12-15 13:26   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 09/27] Silicon/NXP: Add headers for SoC-specific i.MX packages to use Chris Co
2018-11-01 18:20   ` Leif Lindholm
2018-12-01  0:22     ` Chris Co
2018-12-03  9:42       ` Leif Lindholm
2018-12-04  1:44         ` Chris Co
2018-12-04  9:33           ` Ard Biesheuvel
2018-12-04 12:22             ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 10/27] Silicon/NXP: Add iMX6Pkg dec Chris Co
2018-11-01 18:25   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 11/27] Silicon/NXP: Add i.MX6 SoC header files Chris Co
2018-12-13 17:11   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 12/27] Silicon/NXP: Add i.MX6 I/O MUX library Chris Co
2018-11-08 18:00   ` Leif Lindholm
2018-12-04  1:41     ` Chris Co
2018-09-21  8:26 ` [PATCH edk2-platforms 13/27] Silicon/NXP: Add support for iMX SDHC Chris Co
2018-12-05 10:31   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 14/27] Silicon/NXP: Add i.MX6 GPT and EPIT timer headers Chris Co
2018-11-08 18:14   ` Leif Lindholm
2018-12-04  2:06     ` Chris Co
2018-12-04 12:58       ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 15/27] Silicon/NXP: Add i.MX6 GPT Timer library Chris Co
2018-12-13 17:26   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 16/27] Silicon/NXP: Add i.MX6 Timer DXE driver Chris Co
2018-12-13 17:33   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 17/27] Silicon/NXP: Add i.MX6 USB Phy Library Chris Co
2018-12-14 17:10   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 18/27] Silicon/NXP: Add i.MX6 Clock Library Chris Co
2018-12-14 18:12   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 19/27] Silicon/NXP: Add i.MX6 ACPI tables Chris Co
2018-12-14 19:53   ` Leif Lindholm
2018-12-17 11:14   ` Ard Biesheuvel
2019-01-08 21:43     ` Chris Co
2019-01-29 14:09       ` Ard Biesheuvel
2018-09-21  8:26 ` [PATCH edk2-platforms 20/27] Silicon/NXP: Add i.MX6 Board init library Chris Co
2018-12-14 20:12   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 21/27] Silicon/NXP: Add i.MX6 PCIe DXE driver Chris Co
2018-12-14 21:59   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 23/27] Silicon/NXP: Add i.MX6 Smbios Driver Chris Co
2018-12-14 23:07   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 22/27] Silicon/NXP: Add i.MX6 GOP driver Chris Co
2018-12-14 22:37   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 24/27] Silicon/NXP: Add i.MX6 common dsc and fdf files Chris Co
2018-12-14 23:36   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 25/27] Platform/Solidrun: Add Hummingboard Peripheral Initialization Chris Co
2018-12-15 12:12   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 26/27] Platform/SolidRun: Add i.MX 6Quad Hummingboard Edge ACPI tables Chris Co
2018-12-15 12:19   ` Leif Lindholm
2018-09-21  8:26 ` [PATCH edk2-platforms 27/27] Platform/Solidrun: Add i.MX 6Quad Hummingboard Edge dsc and fdf files Chris Co
2018-12-15 12:28   ` Leif Lindholm
2018-12-15 13:32 ` [PATCH edk2-platforms 00/27] Import Hummingboard Edge platform for Windows IoT Core Leif Lindholm
2018-12-19 18:28   ` Chris Co

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180921082542.35768-8-christopher.co@microsoft.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox