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