]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/PL111Lcd/PL111Lcd.c
ArmPlatformPkg: Redefine LcdPlatformGetTimings function
[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
GP
78 @retval !(EFI_SUCCESS) Other errors.\r
79\r
4257dfaa 80**/\r
27f9f349
AB
81EFI_STATUS\r
82LcdSetMode (\r
83 IN UINT32 ModeNumber\r
84 )\r
85{\r
86 EFI_STATUS Status;\r
262c8846
GP
87 SCAN_TIMINGS *Horizontal;\r
88 SCAN_TIMINGS *Vertical;\r
27f9f349
AB
89 UINT32 LcdControl;\r
90 LCD_BPP LcdBpp;\r
91\r
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
112 // Disable the CLCD_LcdEn bit\r
d1ee57e5 113 MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);\r
27f9f349
AB
114\r
115 // Set Timings\r
b1b69d26
GP
116 MmioWrite32 (\r
117 PL111_REG_LCD_TIMING_0,\r
262c8846
GP
118 HOR_AXIS_PANEL (\r
119 Horizontal->BackPorch,\r
120 Horizontal->FrontPorch,\r
121 Horizontal->Sync,\r
122 Horizontal->Resolution\r
123 )\r
b1b69d26
GP
124 );\r
125\r
126 MmioWrite32 (\r
127 PL111_REG_LCD_TIMING_1,\r
262c8846
GP
128 VER_AXIS_PANEL (\r
129 Vertical->BackPorch,\r
130 Vertical->FrontPorch,\r
131 Vertical->Sync,\r
132 Vertical->Resolution\r
133 )\r
134 );\r
135\r
136 MmioWrite32 (\r
137 PL111_REG_LCD_TIMING_2,\r
138 CLK_SIG_POLARITY (Horizontal->Resolution)\r
b1b69d26
GP
139 );\r
140\r
27f9f349
AB
141 MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);\r
142\r
143 // PL111_REG_LCD_CONTROL\r
b1b69d26 144 LcdControl = PL111_CTRL_LCD_EN | PL111_CTRL_LCD_BPP (LcdBpp) |\r
b5daabdc 145 PL111_CTRL_LCD_TFT | PL111_CTRL_LCD_PWR | PL111_CTRL_BGR;\r
b1b69d26 146 MmioWrite32 (PL111_REG_LCD_CONTROL, LcdControl);\r
27f9f349
AB
147\r
148 return EFI_SUCCESS;\r
149}\r
150\r
4257dfaa
GP
151/** De-initializes the display.\r
152*/\r
27f9f349
AB
153VOID\r
154LcdShutdown (\r
155 VOID\r
156 )\r
157{\r
158 // Disable the controller\r
159 MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);\r
160}\r