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.
31 "Probing ID registers at 0x%lx for a PL111\n",
32 PL111_REG_CLCD_PERIPH_ID_0
35 // Check if this is a PL111
36 if ((MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0
) == PL111_CLCD_PERIPH_ID_0
) &&
37 (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1
) == PL111_CLCD_PERIPH_ID_1
) &&
38 ((MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2
) & 0xf) == PL111_CLCD_PERIPH_ID_2
) &&
39 (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3
) == PL111_CLCD_PERIPH_ID_3
) &&
40 (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0
) == PL111_CLCD_P_CELL_ID_0
) &&
41 (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1
) == PL111_CLCD_P_CELL_ID_1
) &&
42 (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2
) == PL111_CLCD_P_CELL_ID_2
) &&
43 (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3
) == PL111_CLCD_P_CELL_ID_3
))
51 /** Initialize display.
53 @param[in] VramBaseAddress Address of the framebuffer.
55 @retval EFI_SUCCESS Initialization of display successful.
59 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
62 // Define start of the VRAM. This never changes for any graphics mode
63 MmioWrite32 (PL111_REG_LCD_UP_BASE
, (UINT32
)VramBaseAddress
);
64 MmioWrite32 (PL111_REG_LCD_LP_BASE
, 0); // We are not using a double buffer
66 // Disable all interrupts from the PL111
67 MmioWrite32 (PL111_REG_LCD_IMSC
, 0);
72 /** Set requested mode of the display.
74 @param[in] ModeNumbe Display mode number.
76 @retval EFI_SUCCESS Display mode set successfuly.
77 @retval !(EFI_SUCCESS) Other errors.
85 SCAN_TIMINGS
*Horizontal
;
86 SCAN_TIMINGS
*Vertical
;
90 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo
;
92 // Set the video mode timings and other relevant information
93 Status
= LcdPlatformGetTimings (
98 if (EFI_ERROR (Status
)) {
99 ASSERT_EFI_ERROR (Status
);
103 ASSERT (Horizontal
!= NULL
);
104 ASSERT (Vertical
!= NULL
);
106 Status
= LcdPlatformGetBpp (ModeNumber
, &LcdBpp
);
107 if (EFI_ERROR (Status
)) {
108 ASSERT_EFI_ERROR (Status
);
112 // Get the pixel format information
113 Status
= LcdPlatformQueryMode (ModeNumber
, &ModeInfo
);
114 if (EFI_ERROR (Status
)) {
115 ASSERT_EFI_ERROR (Status
);
119 // Disable the CLCD_LcdEn bit
120 MmioAnd32 (PL111_REG_LCD_CONTROL
, ~PL111_CTRL_LCD_EN
);
124 PL111_REG_LCD_TIMING_0
,
126 Horizontal
->BackPorch
,
127 Horizontal
->FrontPorch
,
129 Horizontal
->Resolution
134 PL111_REG_LCD_TIMING_1
,
137 Vertical
->FrontPorch
,
144 PL111_REG_LCD_TIMING_2
,
145 CLK_SIG_POLARITY (Horizontal
->Resolution
)
148 MmioWrite32 (PL111_REG_LCD_TIMING_3
, 0);
150 // PL111_REG_LCD_CONTROL
151 LcdControl
= PL111_CTRL_LCD_EN
| PL111_CTRL_LCD_BPP (LcdBpp
) |
152 PL111_CTRL_LCD_TFT
| PL111_CTRL_LCD_PWR
;
153 if (ModeInfo
.PixelFormat
== PixelBlueGreenRedReserved8BitPerColor
) {
154 LcdControl
|= PL111_CTRL_BGR
;
157 MmioWrite32 (PL111_REG_LCD_CONTROL
, LcdControl
);
162 /** De-initializes the display.
169 // Disable the controller
170 MmioAnd32 (PL111_REG_LCD_CONTROL
, ~PL111_CTRL_LCD_EN
);