]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/HdLcd/HdLcd.c
MdeModulePkg/PciBus: Change PCI_IO_DEVICE.RomSize to UINT32 type
[mirror_edk2.git] / ArmPlatformPkg / Library / HdLcd / HdLcd.c
CommitLineData
b1b69d26 1/** @file\r
4257dfaa 2 This file contains the platform independent parts of HdLcd\r
3e7105bb 3\r
b1b69d26 4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>\r
3e7105bb
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\r
16#include <Library/DebugLib.h>\r
17#include <Library/IoLib.h>\r
18#include <Library/LcdHwLib.h>\r
19#include <Library/LcdPlatformLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/PcdLib.h>\r
22\r
23#include "HdLcd.h"\r
24\r
fe787dfb 25#define BYTES_PER_PIXEL 4\r
3e7105bb 26\r
4257dfaa
GP
27/** Initialize display.\r
28\r
29 @param[in] VramBaseAddress Address of the framebuffer.\r
30\r
31 @retval EFI_SUCCESS Display initialization successful.\r
32**/\r
3e7105bb
AB
33EFI_STATUS\r
34LcdInitialize (\r
35 IN EFI_PHYSICAL_ADDRESS VramBaseAddress\r
36 )\r
37{\r
38 // Disable the controller\r
b1b69d26 39 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
3e7105bb
AB
40\r
41 // Disable all interrupts\r
b1b69d26 42 MmioWrite32 (HDLCD_REG_INT_MASK, 0);\r
3e7105bb
AB
43\r
44 // Define start of the VRAM. This never changes for any graphics mode\r
b1b69d26 45 MmioWrite32 (HDLCD_REG_FB_BASE, (UINT32)VramBaseAddress);\r
3e7105bb
AB
46\r
47 // Setup various registers that never change\r
b1b69d26
GP
48 MmioWrite32 (HDLCD_REG_BUS_OPTIONS, (4 << 8) | HDLCD_BURST_8);\r
49\r
50 MmioWrite32 (HDLCD_REG_POLARITIES, HDLCD_DEFAULT_POLARITIES);\r
51\r
52 MmioWrite32 (\r
53 HDLCD_REG_PIXEL_FORMAT,\r
54 HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL\r
55 );\r
56\r
3e7105bb
AB
57 return EFI_SUCCESS;\r
58}\r
59\r
4257dfaa
GP
60/** Set requested mode of the display.\r
61\r
62 @param[in] ModeNumber Display mode number.\r
63\r
64 @retval EFI_SUCCESS Display mode set successfully.\r
3da4193b 65 @retval !(EFI_SUCCESS) Other errors.\r
4257dfaa 66**/\r
3e7105bb
AB
67EFI_STATUS\r
68LcdSetMode (\r
69 IN UINT32 ModeNumber\r
70 )\r
71{\r
72 EFI_STATUS Status;\r
262c8846
GP
73 SCAN_TIMINGS *Horizontal;\r
74 SCAN_TIMINGS *Vertical;\r
fe787dfb 75\r
268aad67
GP
76 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;\r
77\r
fe787dfb 78 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;\r
3e7105bb 79\r
3e7105bb 80 // Set the video mode timings and other relevant information\r
b1b69d26
GP
81 Status = LcdPlatformGetTimings (\r
82 ModeNumber,\r
262c8846
GP
83 &Horizontal,\r
84 &Vertical\r
b1b69d26 85 );\r
b1b69d26 86 if (EFI_ERROR (Status)) {\r
3da4193b
GP
87 ASSERT_EFI_ERROR (Status);\r
88 return Status;\r
3e7105bb
AB
89 }\r
90\r
262c8846
GP
91 ASSERT (Horizontal != NULL);\r
92 ASSERT (Vertical != NULL);\r
93\r
fe787dfb
GP
94 // Get the pixel format information.\r
95 Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);\r
b1b69d26 96 if (EFI_ERROR (Status)) {\r
3da4193b
GP
97 ASSERT_EFI_ERROR (Status);\r
98 return Status;\r
3e7105bb
AB
99 }\r
100\r
268aad67
GP
101 // By default PcdArmHdLcdSwapBlueRedSelect is set to false\r
102 // However on the Juno platform HW lines for BLUE and RED are swapped\r
103 // Therefore PcdArmHdLcdSwapBlueRedSelect is set to TRUE for the Juno platform\r
104 PixelFormat = FixedPcdGetBool (PcdArmHdLcdSwapBlueRedSelect)\r
105 ? PixelRedGreenBlueReserved8BitPerColor\r
106 : PixelBlueGreenRedReserved8BitPerColor;\r
107\r
108 if (ModeInfo.PixelFormat == PixelFormat) {\r
fe787dfb
GP
109 MmioWrite32 (HDLCD_REG_RED_SELECT, (8 << 8) | 16);\r
110 MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 0);\r
111 } else {\r
112 MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 16);\r
113 MmioWrite32 (HDLCD_REG_RED_SELECT, (8 << 8) | 0);\r
114 }\r
115\r
116 MmioWrite32 (HDLCD_REG_GREEN_SELECT, (8 << 8) | 8);\r
3e7105bb
AB
117\r
118 // Disable the controller\r
b1b69d26 119 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
3e7105bb
AB
120\r
121 // Update the frame buffer information with the new settings\r
262c8846
GP
122 MmioWrite32 (\r
123 HDLCD_REG_FB_LINE_LENGTH,\r
fe787dfb 124 Horizontal->Resolution * BYTES_PER_PIXEL\r
262c8846
GP
125 );\r
126\r
fe787dfb
GP
127 MmioWrite32 (\r
128 HDLCD_REG_FB_LINE_PITCH,\r
129 Horizontal->Resolution * BYTES_PER_PIXEL\r
130 );\r
262c8846
GP
131\r
132 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT, Vertical->Resolution - 1);\r
3e7105bb
AB
133\r
134 // Set the vertical timing information\r
262c8846
GP
135 MmioWrite32 (HDLCD_REG_V_SYNC, Vertical->Sync);\r
136 MmioWrite32 (HDLCD_REG_V_BACK_PORCH, Vertical->BackPorch);\r
137 MmioWrite32 (HDLCD_REG_V_DATA, Vertical->Resolution - 1);\r
138 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH, Vertical->FrontPorch);\r
3e7105bb
AB
139\r
140 // Set the horizontal timing information\r
262c8846
GP
141 MmioWrite32 (HDLCD_REG_H_SYNC, Horizontal->Sync);\r
142 MmioWrite32 (HDLCD_REG_H_BACK_PORCH, Horizontal->BackPorch);\r
143 MmioWrite32 (HDLCD_REG_H_DATA, Horizontal->Resolution - 1);\r
144 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH, Horizontal->FrontPorch);\r
3e7105bb
AB
145\r
146 // Enable the controller\r
b1b69d26 147 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_ENABLE);\r
3e7105bb
AB
148\r
149 return EFI_SUCCESS;\r
150}\r
151\r
4257dfaa
GP
152/** De-initializes the display.\r
153**/\r
3e7105bb
AB
154VOID\r
155LcdShutdown (\r
156 VOID\r
157 )\r
158{\r
159 // Disable the controller\r
160 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
161}\r
162\r
4257dfaa
GP
163/** Check for presence of HDLCD.\r
164\r
165 @retval EFI_SUCCESS Returns success if platform implements a HDLCD\r
166 controller.\r
c18ef81e
GP
167 @retval EFI_NOT_FOUND HDLCD display controller not found on the\r
168 platform.\r
4257dfaa 169**/\r
3e7105bb
AB
170EFI_STATUS\r
171LcdIdentify (\r
172 VOID\r
173 )\r
174{\r
c18ef81e
GP
175 if ((MmioRead32 (HDLCD_REG_VERSION) >> 16) == HDLCD_PRODUCT_ID) {\r
176 return EFI_SUCCESS;\r
177 }\r
178\r
179 return EFI_NOT_FOUND;\r
3e7105bb 180}\r