2 This file contains the platform independent parts of HdLcd
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/DebugLib.h>
17 #include <Library/IoLib.h>
18 #include <Library/LcdHwLib.h>
19 #include <Library/LcdPlatformLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/PcdLib.h>
25 #define BYTES_PER_PIXEL 4
27 /** Initialize display.
29 @param[in] VramBaseAddress Address of the framebuffer.
31 @retval EFI_SUCCESS Display initialization successful.
35 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
38 // Disable the controller
39 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
41 // Disable all interrupts
42 MmioWrite32 (HDLCD_REG_INT_MASK
, 0);
44 // Define start of the VRAM. This never changes for any graphics mode
45 MmioWrite32 (HDLCD_REG_FB_BASE
, (UINT32
)VramBaseAddress
);
47 // Setup various registers that never change
48 MmioWrite32 (HDLCD_REG_BUS_OPTIONS
, (4 << 8) | HDLCD_BURST_8
);
50 MmioWrite32 (HDLCD_REG_POLARITIES
, HDLCD_DEFAULT_POLARITIES
);
53 HDLCD_REG_PIXEL_FORMAT
,
54 HDLCD_LITTLE_ENDIAN
| HDLCD_4BYTES_PER_PIXEL
60 /** Set requested mode of the display.
62 @param[in] ModeNumber Display mode number.
64 @retval EFI_SUCCESS Display mode set successfully.
65 @retval !(EFI_SUCCESS) Other errors.
73 SCAN_TIMINGS
*Horizontal
;
74 SCAN_TIMINGS
*Vertical
;
76 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
;
78 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo
;
80 // Set the video mode timings and other relevant information
81 Status
= LcdPlatformGetTimings (
86 if (EFI_ERROR (Status
)) {
87 ASSERT_EFI_ERROR (Status
);
91 ASSERT (Horizontal
!= NULL
);
92 ASSERT (Vertical
!= NULL
);
94 // Get the pixel format information.
95 Status
= LcdPlatformQueryMode (ModeNumber
, &ModeInfo
);
96 if (EFI_ERROR (Status
)) {
97 ASSERT_EFI_ERROR (Status
);
101 // By default PcdArmHdLcdSwapBlueRedSelect is set to false
102 // However on the Juno platform HW lines for BLUE and RED are swapped
103 // Therefore PcdArmHdLcdSwapBlueRedSelect is set to TRUE for the Juno platform
104 PixelFormat
= FixedPcdGetBool (PcdArmHdLcdSwapBlueRedSelect
)
105 ? PixelRedGreenBlueReserved8BitPerColor
106 : PixelBlueGreenRedReserved8BitPerColor
;
108 if (ModeInfo
.PixelFormat
== PixelFormat
) {
109 MmioWrite32 (HDLCD_REG_RED_SELECT
, (8 << 8) | 16);
110 MmioWrite32 (HDLCD_REG_BLUE_SELECT
, (8 << 8) | 0);
112 MmioWrite32 (HDLCD_REG_BLUE_SELECT
, (8 << 8) | 16);
113 MmioWrite32 (HDLCD_REG_RED_SELECT
, (8 << 8) | 0);
116 MmioWrite32 (HDLCD_REG_GREEN_SELECT
, (8 << 8) | 8);
118 // Disable the controller
119 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
121 // Update the frame buffer information with the new settings
123 HDLCD_REG_FB_LINE_LENGTH
,
124 Horizontal
->Resolution
* BYTES_PER_PIXEL
128 HDLCD_REG_FB_LINE_PITCH
,
129 Horizontal
->Resolution
* BYTES_PER_PIXEL
132 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT
, Vertical
->Resolution
- 1);
134 // Set the vertical timing information
135 MmioWrite32 (HDLCD_REG_V_SYNC
, Vertical
->Sync
);
136 MmioWrite32 (HDLCD_REG_V_BACK_PORCH
, Vertical
->BackPorch
);
137 MmioWrite32 (HDLCD_REG_V_DATA
, Vertical
->Resolution
- 1);
138 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH
, Vertical
->FrontPorch
);
140 // Set the horizontal timing information
141 MmioWrite32 (HDLCD_REG_H_SYNC
, Horizontal
->Sync
);
142 MmioWrite32 (HDLCD_REG_H_BACK_PORCH
, Horizontal
->BackPorch
);
143 MmioWrite32 (HDLCD_REG_H_DATA
, Horizontal
->Resolution
- 1);
144 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH
, Horizontal
->FrontPorch
);
146 // Enable the controller
147 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_ENABLE
);
152 /** De-initializes the display.
159 // Disable the controller
160 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
163 /** Check for presence of HDLCD.
165 @retval EFI_SUCCESS Returns success if platform implements a HDLCD
167 @retval EFI_NOT_FOUND HDLCD display controller not found on the
175 if ((MmioRead32 (HDLCD_REG_VERSION
) >> 16) == HDLCD_PRODUCT_ID
) {
179 return EFI_NOT_FOUND
;