]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/PL111Lcd/PL111Lcd.c
ArmPlatformPkg: Add PCD to select pixel format
[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
AB
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15#include <Library/DebugLib.h>\r
16#include <Library/IoLib.h>\r
17#include <Library/LcdHwLib.h>\r
18#include <Library/LcdPlatformLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20\r
21#include "PL111Lcd.h"\r
22\r
4257dfaa 23/** Check for presence of PL111.\r
27f9f349 24\r
4257dfaa
GP
25 @retval EFI_SUCCESS Returns success if platform implements a\r
26 PL111 controller.\r
27\r
28 @retval EFI_NOT_FOUND PL111 display controller not found the plaform.\r
b1b69d26 29**/\r
27f9f349
AB
30EFI_STATUS\r
31LcdIdentify (\r
32 VOID\r
33 )\r
34{\r
35 DEBUG ((EFI_D_WARN, "Probing ID registers at 0x%lx for a PL111\n",\r
36 PL111_REG_CLCD_PERIPH_ID_0));\r
37\r
38 // Check if this is a PL111\r
39 if (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0) == PL111_CLCD_PERIPH_ID_0 &&\r
40 MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1) == PL111_CLCD_PERIPH_ID_1 &&\r
41 (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2) & 0xf) == PL111_CLCD_PERIPH_ID_2 &&\r
42 MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3) == PL111_CLCD_PERIPH_ID_3 &&\r
43 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0) == PL111_CLCD_P_CELL_ID_0 &&\r
44 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1) == PL111_CLCD_P_CELL_ID_1 &&\r
45 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2) == PL111_CLCD_P_CELL_ID_2 &&\r
46 MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3) == PL111_CLCD_P_CELL_ID_3) {\r
47 return EFI_SUCCESS;\r
48 }\r
49 return EFI_NOT_FOUND;\r
50}\r
51\r
4257dfaa
GP
52/** Initialize display.\r
53\r
54 @param[in] VramBaseAddress Address of the framebuffer.\r
55\r
56 @retval EFI_SUCCESS Initialization of display successful.\r
57**/\r
27f9f349
AB
58EFI_STATUS\r
59LcdInitialize (\r
60 IN EFI_PHYSICAL_ADDRESS VramBaseAddress\r
61 )\r
62{\r
63 // Define start of the VRAM. This never changes for any graphics mode\r
b1b69d26
GP
64 MmioWrite32 (PL111_REG_LCD_UP_BASE, (UINT32)VramBaseAddress);\r
65 MmioWrite32 (PL111_REG_LCD_LP_BASE, 0); // We are not using a double buffer\r
27f9f349
AB
66\r
67 // Disable all interrupts from the PL111\r
b1b69d26 68 MmioWrite32 (PL111_REG_LCD_IMSC, 0);\r
27f9f349
AB
69\r
70 return EFI_SUCCESS;\r
71}\r
72\r
4257dfaa
GP
73/** Set requested mode of the display.\r
74\r
75 @param[in] ModeNumbe Display mode number.\r
76\r
77 @retval EFI_SUCCESS Display mode set successfuly.\r
3da4193b 78 @retval !(EFI_SUCCESS) Other errors.\r
4257dfaa 79**/\r
27f9f349
AB
80EFI_STATUS\r
81LcdSetMode (\r
82 IN UINT32 ModeNumber\r
83 )\r
84{\r
85 EFI_STATUS Status;\r
262c8846
GP
86 SCAN_TIMINGS *Horizontal;\r
87 SCAN_TIMINGS *Vertical;\r
27f9f349
AB
88 UINT32 LcdControl;\r
89 LCD_BPP LcdBpp;\r
90\r
fe787dfb
GP
91 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;\r
92\r
27f9f349 93 // Set the video mode timings and other relevant information\r
b1b69d26
GP
94 Status = LcdPlatformGetTimings (\r
95 ModeNumber,\r
262c8846
GP
96 &Horizontal,\r
97 &Vertical\r
b1b69d26 98 );\r
b1b69d26 99 if (EFI_ERROR (Status)) {\r
3da4193b
GP
100 ASSERT_EFI_ERROR (Status);\r
101 return Status;\r
27f9f349
AB
102 }\r
103\r
262c8846
GP
104 ASSERT (Horizontal != NULL);\r
105 ASSERT (Vertical != NULL);\r
106\r
b1b69d26 107 Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);\r
b1b69d26 108 if (EFI_ERROR (Status)) {\r
3da4193b
GP
109 ASSERT_EFI_ERROR (Status);\r
110 return Status;\r
27f9f349
AB
111 }\r
112\r
fe787dfb
GP
113 // Get the pixel format information\r
114 Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);\r
115 if (EFI_ERROR (Status)) {\r
116 ASSERT_EFI_ERROR (Status);\r
117 return Status;\r
118 }\r
119\r
27f9f349 120 // Disable the CLCD_LcdEn bit\r
d1ee57e5 121 MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);\r
27f9f349
AB
122\r
123 // Set Timings\r
b1b69d26
GP
124 MmioWrite32 (\r
125 PL111_REG_LCD_TIMING_0,\r
262c8846
GP
126 HOR_AXIS_PANEL (\r
127 Horizontal->BackPorch,\r
128 Horizontal->FrontPorch,\r
129 Horizontal->Sync,\r
130 Horizontal->Resolution\r
131 )\r
b1b69d26
GP
132 );\r
133\r
134 MmioWrite32 (\r
135 PL111_REG_LCD_TIMING_1,\r
262c8846
GP
136 VER_AXIS_PANEL (\r
137 Vertical->BackPorch,\r
138 Vertical->FrontPorch,\r
139 Vertical->Sync,\r
140 Vertical->Resolution\r
141 )\r
142 );\r
143\r
144 MmioWrite32 (\r
145 PL111_REG_LCD_TIMING_2,\r
146 CLK_SIG_POLARITY (Horizontal->Resolution)\r
b1b69d26
GP
147 );\r
148\r
27f9f349
AB
149 MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);\r
150\r
151 // PL111_REG_LCD_CONTROL\r
b1b69d26 152 LcdControl = PL111_CTRL_LCD_EN | PL111_CTRL_LCD_BPP (LcdBpp) |\r
fe787dfb
GP
153 PL111_CTRL_LCD_TFT | PL111_CTRL_LCD_PWR;\r
154 if (ModeInfo.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {\r
155 LcdControl |= PL111_CTRL_BGR;\r
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