]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Library/PL111Lcd/PL111Lcd.c
ArmPlatformPkg: Apply uncrustify changes
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
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>
14
15 #include "PL111Lcd.h"
16
17 /** Check for presence of PL111.
18
19 @retval EFI_SUCCESS Returns success if platform implements a
20 PL111 controller.
21
22 @retval EFI_NOT_FOUND PL111 display controller not found the plaform.
23 **/
24 EFI_STATUS
25 LcdIdentify (
26 VOID
27 )
28 {
29 DEBUG ((
30 DEBUG_WARN,
31 "Probing ID registers at 0x%lx for a PL111\n",
32 PL111_REG_CLCD_PERIPH_ID_0
33 ));
34
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))
44 {
45 return EFI_SUCCESS;
46 }
47
48 return EFI_NOT_FOUND;
49 }
50
51 /** Initialize display.
52
53 @param[in] VramBaseAddress Address of the framebuffer.
54
55 @retval EFI_SUCCESS Initialization of display successful.
56 **/
57 EFI_STATUS
58 LcdInitialize (
59 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
60 )
61 {
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
65
66 // Disable all interrupts from the PL111
67 MmioWrite32 (PL111_REG_LCD_IMSC, 0);
68
69 return EFI_SUCCESS;
70 }
71
72 /** Set requested mode of the display.
73
74 @param[in] ModeNumbe Display mode number.
75
76 @retval EFI_SUCCESS Display mode set successfuly.
77 @retval !(EFI_SUCCESS) Other errors.
78 **/
79 EFI_STATUS
80 LcdSetMode (
81 IN UINT32 ModeNumber
82 )
83 {
84 EFI_STATUS Status;
85 SCAN_TIMINGS *Horizontal;
86 SCAN_TIMINGS *Vertical;
87 UINT32 LcdControl;
88 LCD_BPP LcdBpp;
89
90 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;
91
92 // Set the video mode timings and other relevant information
93 Status = LcdPlatformGetTimings (
94 ModeNumber,
95 &Horizontal,
96 &Vertical
97 );
98 if (EFI_ERROR (Status)) {
99 ASSERT_EFI_ERROR (Status);
100 return Status;
101 }
102
103 ASSERT (Horizontal != NULL);
104 ASSERT (Vertical != NULL);
105
106 Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);
107 if (EFI_ERROR (Status)) {
108 ASSERT_EFI_ERROR (Status);
109 return Status;
110 }
111
112 // Get the pixel format information
113 Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);
114 if (EFI_ERROR (Status)) {
115 ASSERT_EFI_ERROR (Status);
116 return Status;
117 }
118
119 // Disable the CLCD_LcdEn bit
120 MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);
121
122 // Set Timings
123 MmioWrite32 (
124 PL111_REG_LCD_TIMING_0,
125 HOR_AXIS_PANEL (
126 Horizontal->BackPorch,
127 Horizontal->FrontPorch,
128 Horizontal->Sync,
129 Horizontal->Resolution
130 )
131 );
132
133 MmioWrite32 (
134 PL111_REG_LCD_TIMING_1,
135 VER_AXIS_PANEL (
136 Vertical->BackPorch,
137 Vertical->FrontPorch,
138 Vertical->Sync,
139 Vertical->Resolution
140 )
141 );
142
143 MmioWrite32 (
144 PL111_REG_LCD_TIMING_2,
145 CLK_SIG_POLARITY (Horizontal->Resolution)
146 );
147
148 MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);
149
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;
155 }
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 }