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 2/7] Silicon/NXP: Add iMX display library support
Date: Thu, 19 Jul 2018 04:11:20 +0000	[thread overview]
Message-ID: <20180719041103.9072-3-christopher.co@microsoft.com> (raw)
In-Reply-To: <20180719041103.9072-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                    |  95 +++++++++++++++
 Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.c   | 125 ++++++++++++++++++++
 Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.inf |  31 +++++
 3 files changed, 251 insertions(+)

diff --git a/Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h b/Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h
new file mode 100644
index 000000000000..d805c6b4bc39
--- /dev/null
+++ b/Silicon/NXP/iMXPlatformPkg/Include/iMXDisplay.h
@@ -0,0 +1,95 @@
+/** @file
+*
+*  Copyright (c) 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
+//
+EFI_STATUS
+ConvertDTDToDisplayTiming (
+    DETAILED_TIMING_DESCRIPTOR* DTDPtr,
+    DISPLAY_TIMING* DisplayTimingPtr
+    );
+
+VOID
+PrintDisplayTiming (
+    char *DisplayTimingName,
+    DISPLAY_TIMING* DisplayTimingPtr
+    );
+
+EFI_STATUS
+ValidateEdidData (
+    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..67f3cd074cb5
--- /dev/null
+++ b/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.c
@@ -0,0 +1,125 @@
+/** @file
+*
+*  Copyright (c) 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>
+
+EFI_STATUS
+ConvertDTDToDisplayTiming(
+    DETAILED_TIMING_DESCRIPTOR* DTDPtr,
+    DISPLAY_TIMING* DisplayTimingPtr
+    )
+{
+    DEBUG((DEBUG_INFO,"++ConvertDTDToDisplayTiming()\r\n"));
+    // Refer to 3.10.2 VESA EDID spec
+    UINT32 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;
+}
+
+VOID
+PrintDisplayTiming (
+    char *DisplayTimingNamePtr,
+    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"));
+}
+
+EFI_STATUS
+ValidateEdidData (
+    UINT8* EdidDataPtr
+    )
+{
+    UINT8 checksum, index;
+    DEBUG((DEBUG_INFO,"++ValidateEdidData()\r\n"));
+
+    //
+    // Check if the EDID header matches
+    //
+    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..06a6ebaa10f9
--- /dev/null
+++ b/Silicon/NXP/iMXPlatformPkg/Library/iMXDisplayLib/iMXDisplayLib.inf
@@ -0,0 +1,31 @@
+## @file
+#
+#  Copyright (c) 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                    = 0x00010005
+  BASE_NAME                      = iMXDisplayLib
+  FILE_GUID                      = C0408490-F09B-4CFA-9A2F-5159F2705323
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = iMXDisplayLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  Silicon/NXP/iMXPlatformPkg/iMXPlatformPkg.dec
+
+[LibraryClasses]
+
+[Sources.common]
+  iMXDisplayLib.c
-- 
2.16.2.gvfs.1.33.gf5370f1



  parent reply	other threads:[~2018-07-19  4:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-19  4:11 [PATCH edk2-platforms 0/7] Silicon/NXP: Import NXP i.MX platform package Chris Co
2018-07-19  4:11 ` [PATCH edk2-platforms 1/7] Silicon/NXP: Add support for iMX SDHC Chris Co
2018-08-01 16:15   ` Leif Lindholm
2018-08-01 23:59     ` Chris Co
2018-07-19  4:11 ` Chris Co [this message]
2018-07-19  4:11 ` [PATCH edk2-platforms 3/7] Silicon/NXP: Add I2C library support for iMX platforms Chris Co
2018-07-19  4:11 ` [PATCH edk2-platforms 4/7] Silicon/NXP: Add UART " Chris Co
2018-07-19  4:11 ` [PATCH edk2-platforms 5/7] Silicon/NXP: Add Virtual RTC support for IMX platform Chris Co
2018-07-19  4:11 ` [PATCH edk2-platforms 6/7] Silicon/NXP: Add iMXPlatformPkg dec Chris Co
2018-07-19  4:11 ` [PATCH edk2-platforms 7/7] Silicon/NXP: Add headers for other iMX packages to use 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=20180719041103.9072-3-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