This adds support for processing EDID data on NXP i.MX platforms. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Christopher Co <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Leif Lindholm <[email protected]> Cc: Michael D Kinney <[email protected]> --- 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 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

