]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/PL111Lcd/PL111Lcd.c
ArmPlatformPkg: Add PCD to select pixel format
[mirror_edk2.git] / ArmPlatformPkg / Library / PL111Lcd / PL111Lcd.c
1 /** @file
2 This file contains the platform independent parts of PL111Lcd
3
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
5
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
10
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.
13
14 **/
15 #include <Library/DebugLib.h>
16 #include <Library/IoLib.h>
17 #include <Library/LcdHwLib.h>
18 #include <Library/LcdPlatformLib.h>
19 #include <Library/MemoryAllocationLib.h>
20
21 #include "PL111Lcd.h"
22
23 /** Check for presence of PL111.
24
25 @retval EFI_SUCCESS Returns success if platform implements a
26 PL111 controller.
27
28 @retval EFI_NOT_FOUND PL111 display controller not found the plaform.
29 **/
30 EFI_STATUS
31 LcdIdentify (
32 VOID
33 )
34 {
35 DEBUG ((EFI_D_WARN, "Probing ID registers at 0x%lx for a PL111\n",
36 PL111_REG_CLCD_PERIPH_ID_0));
37
38 // Check if this is a PL111
39 if (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0) == PL111_CLCD_PERIPH_ID_0 &&
40 MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1) == PL111_CLCD_PERIPH_ID_1 &&
41 (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2) & 0xf) == PL111_CLCD_PERIPH_ID_2 &&
42 MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3) == PL111_CLCD_PERIPH_ID_3 &&
43 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0) == PL111_CLCD_P_CELL_ID_0 &&
44 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1) == PL111_CLCD_P_CELL_ID_1 &&
45 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2) == PL111_CLCD_P_CELL_ID_2 &&
46 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3) == PL111_CLCD_P_CELL_ID_3) {
47 return EFI_SUCCESS;
48 }
49 return EFI_NOT_FOUND;
50 }
51
52 /** Initialize display.
53
54 @param[in] VramBaseAddress Address of the framebuffer.
55
56 @retval EFI_SUCCESS Initialization of display successful.
57 **/
58 EFI_STATUS
59 LcdInitialize (
60 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
61 )
62 {
63 // Define start of the VRAM. This never changes for any graphics mode
64 MmioWrite32 (PL111_REG_LCD_UP_BASE, (UINT32)VramBaseAddress);
65 MmioWrite32 (PL111_REG_LCD_LP_BASE, 0); // We are not using a double buffer
66
67 // Disable all interrupts from the PL111
68 MmioWrite32 (PL111_REG_LCD_IMSC, 0);
69
70 return EFI_SUCCESS;
71 }
72
73 /** Set requested mode of the display.
74
75 @param[in] ModeNumbe Display mode number.
76
77 @retval EFI_SUCCESS Display mode set successfuly.
78 @retval !(EFI_SUCCESS) Other errors.
79 **/
80 EFI_STATUS
81 LcdSetMode (
82 IN UINT32 ModeNumber
83 )
84 {
85 EFI_STATUS Status;
86 SCAN_TIMINGS *Horizontal;
87 SCAN_TIMINGS *Vertical;
88 UINT32 LcdControl;
89 LCD_BPP LcdBpp;
90
91 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;
92
93 // Set the video mode timings and other relevant information
94 Status = LcdPlatformGetTimings (
95 ModeNumber,
96 &Horizontal,
97 &Vertical
98 );
99 if (EFI_ERROR (Status)) {
100 ASSERT_EFI_ERROR (Status);
101 return Status;
102 }
103
104 ASSERT (Horizontal != NULL);
105 ASSERT (Vertical != NULL);
106
107 Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);
108 if (EFI_ERROR (Status)) {
109 ASSERT_EFI_ERROR (Status);
110 return Status;
111 }
112
113 // Get the pixel format information
114 Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);
115 if (EFI_ERROR (Status)) {
116 ASSERT_EFI_ERROR (Status);
117 return Status;
118 }
119
120 // Disable the CLCD_LcdEn bit
121 MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);
122
123 // Set Timings
124 MmioWrite32 (
125 PL111_REG_LCD_TIMING_0,
126 HOR_AXIS_PANEL (
127 Horizontal->BackPorch,
128 Horizontal->FrontPorch,
129 Horizontal->Sync,
130 Horizontal->Resolution
131 )
132 );
133
134 MmioWrite32 (
135 PL111_REG_LCD_TIMING_1,
136 VER_AXIS_PANEL (
137 Vertical->BackPorch,
138 Vertical->FrontPorch,
139 Vertical->Sync,
140 Vertical->Resolution
141 )
142 );
143
144 MmioWrite32 (
145 PL111_REG_LCD_TIMING_2,
146 CLK_SIG_POLARITY (Horizontal->Resolution)
147 );
148
149 MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);
150
151 // PL111_REG_LCD_CONTROL
152 LcdControl = PL111_CTRL_LCD_EN | PL111_CTRL_LCD_BPP (LcdBpp) |
153 PL111_CTRL_LCD_TFT | PL111_CTRL_LCD_PWR;
154 if (ModeInfo.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
155 LcdControl |= PL111_CTRL_BGR;
156 }
157 MmioWrite32 (PL111_REG_LCD_CONTROL, LcdControl);
158
159 return EFI_SUCCESS;
160 }
161
162 /** De-initializes the display.
163 */
164 VOID
165 LcdShutdown (
166 VOID
167 )
168 {
169 // Disable the controller
170 MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);
171 }