2 This file contains the platform independent parts of HdLcd
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/DebugLib.h>
11 #include <Library/IoLib.h>
12 #include <Library/LcdHwLib.h>
13 #include <Library/LcdPlatformLib.h>
14 #include <Library/MemoryAllocationLib.h>
15 #include <Library/PcdLib.h>
19 #define BYTES_PER_PIXEL 4
21 /** Initialize display.
23 @param[in] VramBaseAddress Address of the framebuffer.
25 @retval EFI_SUCCESS Display initialization successful.
29 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
32 // Disable the controller
33 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
35 // Disable all interrupts
36 MmioWrite32 (HDLCD_REG_INT_MASK
, 0);
38 // Define start of the VRAM. This never changes for any graphics mode
39 MmioWrite32 (HDLCD_REG_FB_BASE
, (UINT32
)VramBaseAddress
);
41 // Setup various registers that never change
42 MmioWrite32 (HDLCD_REG_BUS_OPTIONS
, (4 << 8) | HDLCD_BURST_8
);
44 MmioWrite32 (HDLCD_REG_POLARITIES
, HDLCD_DEFAULT_POLARITIES
);
47 HDLCD_REG_PIXEL_FORMAT
,
48 HDLCD_LITTLE_ENDIAN
| HDLCD_4BYTES_PER_PIXEL
54 /** Set requested mode of the display.
56 @param[in] ModeNumber Display mode number.
58 @retval EFI_SUCCESS Display mode set successfully.
59 @retval !(EFI_SUCCESS) Other errors.
67 SCAN_TIMINGS
*Horizontal
;
68 SCAN_TIMINGS
*Vertical
;
70 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
72 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo
;
74 // Set the video mode timings and other relevant information
75 Status
= LcdPlatformGetTimings (
80 if (EFI_ERROR (Status
)) {
81 ASSERT_EFI_ERROR (Status
);
85 ASSERT (Horizontal
!= NULL
);
86 ASSERT (Vertical
!= NULL
);
88 // Get the pixel format information.
89 Status
= LcdPlatformQueryMode (ModeNumber
, &ModeInfo
);
90 if (EFI_ERROR (Status
)) {
91 ASSERT_EFI_ERROR (Status
);
95 // By default PcdArmHdLcdSwapBlueRedSelect is set to false
96 // However on the Juno platform HW lines for BLUE and RED are swapped
97 // Therefore PcdArmHdLcdSwapBlueRedSelect is set to TRUE for the Juno platform
98 PixelFormat
= FixedPcdGetBool (PcdArmHdLcdSwapBlueRedSelect
)
99 ? PixelRedGreenBlueReserved8BitPerColor
100 : PixelBlueGreenRedReserved8BitPerColor
;
102 if (ModeInfo
.PixelFormat
== PixelFormat
) {
103 MmioWrite32 (HDLCD_REG_RED_SELECT
, (8 << 8) | 16);
104 MmioWrite32 (HDLCD_REG_BLUE_SELECT
, (8 << 8) | 0);
106 MmioWrite32 (HDLCD_REG_BLUE_SELECT
, (8 << 8) | 16);
107 MmioWrite32 (HDLCD_REG_RED_SELECT
, (8 << 8) | 0);
110 MmioWrite32 (HDLCD_REG_GREEN_SELECT
, (8 << 8) | 8);
112 // Disable the controller
113 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
115 // Update the frame buffer information with the new settings
117 HDLCD_REG_FB_LINE_LENGTH
,
118 Horizontal
->Resolution
* BYTES_PER_PIXEL
122 HDLCD_REG_FB_LINE_PITCH
,
123 Horizontal
->Resolution
* BYTES_PER_PIXEL
126 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT
, Vertical
->Resolution
- 1);
128 // Set the vertical timing information
129 MmioWrite32 (HDLCD_REG_V_SYNC
, Vertical
->Sync
);
130 MmioWrite32 (HDLCD_REG_V_BACK_PORCH
, Vertical
->BackPorch
);
131 MmioWrite32 (HDLCD_REG_V_DATA
, Vertical
->Resolution
- 1);
132 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH
, Vertical
->FrontPorch
);
134 // Set the horizontal timing information
135 MmioWrite32 (HDLCD_REG_H_SYNC
, Horizontal
->Sync
);
136 MmioWrite32 (HDLCD_REG_H_BACK_PORCH
, Horizontal
->BackPorch
);
137 MmioWrite32 (HDLCD_REG_H_DATA
, Horizontal
->Resolution
- 1);
138 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH
, Horizontal
->FrontPorch
);
140 // Enable the controller
141 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_ENABLE
);
146 /** De-initializes the display.
153 // Disable the controller
154 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
157 /** Check for presence of HDLCD.
159 @retval EFI_SUCCESS Returns success if platform implements a HDLCD
161 @retval EFI_NOT_FOUND HDLCD display controller not found on the
169 if ((MmioRead32 (HDLCD_REG_VERSION
) >> 16) == HDLCD_PRODUCT_ID
) {
173 return EFI_NOT_FOUND
;