2 This file contains the platform independent parts of PL111Lcd
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/DebugLib.h>
10 #include <Library/IoLib.h>
11 #include <Library/LcdHwLib.h>
12 #include <Library/LcdPlatformLib.h>
13 #include <Library/MemoryAllocationLib.h>
17 /** Check for presence of PL111.
19 @retval EFI_SUCCESS Returns success if platform implements a
22 @retval EFI_NOT_FOUND PL111 display controller not found the plaform.
29 DEBUG ((DEBUG_WARN
, "Probing ID registers at 0x%lx for a PL111\n",
30 PL111_REG_CLCD_PERIPH_ID_0
));
32 // Check if this is a PL111
33 if (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0
) == PL111_CLCD_PERIPH_ID_0
&&
34 MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1
) == PL111_CLCD_PERIPH_ID_1
&&
35 (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2
) & 0xf) == PL111_CLCD_PERIPH_ID_2
&&
36 MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3
) == PL111_CLCD_PERIPH_ID_3
&&
37 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0
) == PL111_CLCD_P_CELL_ID_0
&&
38 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1
) == PL111_CLCD_P_CELL_ID_1
&&
39 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2
) == PL111_CLCD_P_CELL_ID_2
&&
40 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3
) == PL111_CLCD_P_CELL_ID_3
) {
46 /** Initialize display.
48 @param[in] VramBaseAddress Address of the framebuffer.
50 @retval EFI_SUCCESS Initialization of display successful.
54 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
57 // Define start of the VRAM. This never changes for any graphics mode
58 MmioWrite32 (PL111_REG_LCD_UP_BASE
, (UINT32
)VramBaseAddress
);
59 MmioWrite32 (PL111_REG_LCD_LP_BASE
, 0); // We are not using a double buffer
61 // Disable all interrupts from the PL111
62 MmioWrite32 (PL111_REG_LCD_IMSC
, 0);
67 /** Set requested mode of the display.
69 @param[in] ModeNumbe Display mode number.
71 @retval EFI_SUCCESS Display mode set successfuly.
72 @retval !(EFI_SUCCESS) Other errors.
80 SCAN_TIMINGS
*Horizontal
;
81 SCAN_TIMINGS
*Vertical
;
85 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo
;
87 // Set the video mode timings and other relevant information
88 Status
= LcdPlatformGetTimings (
93 if (EFI_ERROR (Status
)) {
94 ASSERT_EFI_ERROR (Status
);
98 ASSERT (Horizontal
!= NULL
);
99 ASSERT (Vertical
!= NULL
);
101 Status
= LcdPlatformGetBpp (ModeNumber
, &LcdBpp
);
102 if (EFI_ERROR (Status
)) {
103 ASSERT_EFI_ERROR (Status
);
107 // Get the pixel format information
108 Status
= LcdPlatformQueryMode (ModeNumber
, &ModeInfo
);
109 if (EFI_ERROR (Status
)) {
110 ASSERT_EFI_ERROR (Status
);
114 // Disable the CLCD_LcdEn bit
115 MmioAnd32 (PL111_REG_LCD_CONTROL
, ~PL111_CTRL_LCD_EN
);
119 PL111_REG_LCD_TIMING_0
,
121 Horizontal
->BackPorch
,
122 Horizontal
->FrontPorch
,
124 Horizontal
->Resolution
129 PL111_REG_LCD_TIMING_1
,
132 Vertical
->FrontPorch
,
139 PL111_REG_LCD_TIMING_2
,
140 CLK_SIG_POLARITY (Horizontal
->Resolution
)
143 MmioWrite32 (PL111_REG_LCD_TIMING_3
, 0);
145 // PL111_REG_LCD_CONTROL
146 LcdControl
= PL111_CTRL_LCD_EN
| PL111_CTRL_LCD_BPP (LcdBpp
) |
147 PL111_CTRL_LCD_TFT
| PL111_CTRL_LCD_PWR
;
148 if (ModeInfo
.PixelFormat
== PixelBlueGreenRedReserved8BitPerColor
) {
149 LcdControl
|= PL111_CTRL_BGR
;
151 MmioWrite32 (PL111_REG_LCD_CONTROL
, LcdControl
);
156 /** De-initializes the display.
163 // Disable the controller
164 MmioAnd32 (PL111_REG_LCD_CONTROL
, ~PL111_CTRL_LCD_EN
);