TianoCore EDK2 master
Loading...
Searching...
No Matches
HdLcd.c
Go to the documentation of this file.
1
10#include <Library/DebugLib.h>
11#include <Library/IoLib.h>
12#include <Library/LcdHwLib.h>
15#include <Library/PcdLib.h>
16
17#include "HdLcd.h"
18
19#define BYTES_PER_PIXEL 4
20
29 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
30 )
31{
32 // Disable the controller
33 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);
34
35 // Disable all interrupts
36 MmioWrite32 (HDLCD_REG_INT_MASK, 0);
37
38 // Define start of the VRAM. This never changes for any graphics mode
39 MmioWrite32 (HDLCD_REG_FB_BASE, (UINT32)VramBaseAddress);
40
41 // Setup various registers that never change
42 MmioWrite32 (HDLCD_REG_BUS_OPTIONS, (4 << 8) | HDLCD_BURST_8);
43
44 MmioWrite32 (HDLCD_REG_POLARITIES, HDLCD_DEFAULT_POLARITIES);
45
47 HDLCD_REG_PIXEL_FORMAT,
48 HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL
49 );
50
51 return EFI_SUCCESS;
52}
53
63 IN UINT32 ModeNumber
64 )
65{
66 EFI_STATUS Status;
67 SCAN_TIMINGS *Horizontal;
68 SCAN_TIMINGS *Vertical;
69
70 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
71
73
74 // Set the video mode timings and other relevant information
75 Status = LcdPlatformGetTimings (
76 ModeNumber,
77 &Horizontal,
78 &Vertical
79 );
80 if (EFI_ERROR (Status)) {
81 ASSERT_EFI_ERROR (Status);
82 return Status;
83 }
84
85 ASSERT (Horizontal != NULL);
86 ASSERT (Vertical != NULL);
87
88 // Get the pixel format information.
89 Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);
90 if (EFI_ERROR (Status)) {
91 ASSERT_EFI_ERROR (Status);
92 return Status;
93 }
94
95 // By default PcdArmHdLcdSwapBlueRedSelect is set to false
96 // However on the Juno platform HW lines for BLUE and RED are swapped
97 // Therefore PcdArmHdLcdSwapBlueRedSelect is set to TRUE for the Juno platform
98 PixelFormat = FixedPcdGetBool (PcdArmHdLcdSwapBlueRedSelect)
101
102 if (ModeInfo.PixelFormat == PixelFormat) {
103 MmioWrite32 (HDLCD_REG_RED_SELECT, (8 << 8) | 16);
104 MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 0);
105 } else {
106 MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 16);
107 MmioWrite32 (HDLCD_REG_RED_SELECT, (8 << 8) | 0);
108 }
109
110 MmioWrite32 (HDLCD_REG_GREEN_SELECT, (8 << 8) | 8);
111
112 // Disable the controller
113 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);
114
115 // Update the frame buffer information with the new settings
117 HDLCD_REG_FB_LINE_LENGTH,
118 Horizontal->Resolution * BYTES_PER_PIXEL
119 );
120
122 HDLCD_REG_FB_LINE_PITCH,
123 Horizontal->Resolution * BYTES_PER_PIXEL
124 );
125
126 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT, Vertical->Resolution - 1);
127
128 // Set the vertical timing information
129 MmioWrite32 (HDLCD_REG_V_SYNC, Vertical->Sync);
130 MmioWrite32 (HDLCD_REG_V_BACK_PORCH, Vertical->BackPorch);
131 MmioWrite32 (HDLCD_REG_V_DATA, Vertical->Resolution - 1);
132 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH, Vertical->FrontPorch);
133
134 // Set the horizontal timing information
135 MmioWrite32 (HDLCD_REG_H_SYNC, Horizontal->Sync);
136 MmioWrite32 (HDLCD_REG_H_BACK_PORCH, Horizontal->BackPorch);
137 MmioWrite32 (HDLCD_REG_H_DATA, Horizontal->Resolution - 1);
138 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH, Horizontal->FrontPorch);
139
140 // Enable the controller
141 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_ENABLE);
142
143 return EFI_SUCCESS;
144}
145
148VOID
150 VOID
151 )
152{
153 // Disable the controller
154 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);
155}
156
166 VOID
167 )
168{
169 if ((MmioRead32 (HDLCD_REG_VERSION) >> 16) == HDLCD_PRODUCT_ID) {
170 return EFI_SUCCESS;
171 }
172
173 return EFI_NOT_FOUND;
174}
EFI_STATUS LcdSetMode(IN UINT32 ModeNumber)
Definition: HdLcd.c:62
VOID LcdShutdown(VOID)
Definition: HdLcd.c:149
EFI_STATUS LcdIdentify(VOID)
Definition: HdLcd.c:165
EFI_STATUS LcdInitialize(IN EFI_PHYSICAL_ADDRESS VramBaseAddress)
Definition: HdLcd.c:28
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
Definition: IoLib.c:309
EFI_STATUS LcdPlatformQueryMode(IN UINT32 ModeNumber, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info)
EFI_STATUS LcdPlatformGetTimings(IN UINT32 ModeNumber, OUT SCAN_TIMINGS **Horizontal, OUT SCAN_TIMINGS **Vertical)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
EFI_GRAPHICS_PIXEL_FORMAT
@ PixelRedGreenBlueReserved8BitPerColor
@ PixelBlueGreenRedReserved8BitPerColor
#define FixedPcdGetBool(TokenName)
Definition: PcdLib.h:120
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat