2 This file contains the platform independent parts of HdLcd
4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/DebugLib.h>
17 #include <Library/IoLib.h>
18 #include <Library/LcdHwLib.h>
19 #include <Library/LcdPlatformLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/PcdLib.h>
32 case LCD_BITS_PER_PIXEL_24
:
35 case LCD_BITS_PER_PIXEL_16_565
:
36 case LCD_BITS_PER_PIXEL_16_555
:
37 case LCD_BITS_PER_PIXEL_12_444
:
40 case LCD_BITS_PER_PIXEL_8
:
41 case LCD_BITS_PER_PIXEL_4
:
42 case LCD_BITS_PER_PIXEL_2
:
43 case LCD_BITS_PER_PIXEL_1
:
51 /** Initialize display.
53 @param[in] VramBaseAddress Address of the framebuffer.
55 @retval EFI_SUCCESS Display initialization successful.
59 IN EFI_PHYSICAL_ADDRESS VramBaseAddress
62 // Disable the controller
63 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
65 // Disable all interrupts
66 MmioWrite32 (HDLCD_REG_INT_MASK
, 0);
68 // Define start of the VRAM. This never changes for any graphics mode
69 MmioWrite32 (HDLCD_REG_FB_BASE
, (UINT32
)VramBaseAddress
);
71 // Setup various registers that never change
72 MmioWrite32 (HDLCD_REG_BUS_OPTIONS
, (4 << 8) | HDLCD_BURST_8
);
74 MmioWrite32 (HDLCD_REG_POLARITIES
, HDLCD_DEFAULT_POLARITIES
);
77 HDLCD_REG_PIXEL_FORMAT
,
78 HDLCD_LITTLE_ENDIAN
| HDLCD_4BYTES_PER_PIXEL
81 MmioWrite32 (HDLCD_REG_RED_SELECT
, (0 << 16 | 8 << 8 | 0));
82 MmioWrite32 (HDLCD_REG_GREEN_SELECT
, (0 << 16 | 8 << 8 | 8));
83 MmioWrite32 (HDLCD_REG_BLUE_SELECT
, (0 << 16 | 8 << 8 | 16));
88 /** Set requested mode of the display.
90 @param[in] ModeNumber Display mode number.
92 @retval EFI_SUCCESS Display mode set successfully.
93 @retval !(EFI_SUCCESS) Other errors.
109 UINT32 BytesPerPixel
;
112 // Set the video mode timings and other relevant information
113 Status
= LcdPlatformGetTimings (
124 if (EFI_ERROR (Status
)) {
125 ASSERT_EFI_ERROR (Status
);
129 Status
= LcdPlatformGetBpp (ModeNumber
, &LcdBpp
);
130 if (EFI_ERROR (Status
)) {
131 ASSERT_EFI_ERROR (Status
);
135 BytesPerPixel
= GetBytesPerPixel (LcdBpp
);
137 // Disable the controller
138 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
140 // Update the frame buffer information with the new settings
141 MmioWrite32 (HDLCD_REG_FB_LINE_LENGTH
, HRes
* BytesPerPixel
);
142 MmioWrite32 (HDLCD_REG_FB_LINE_PITCH
, HRes
* BytesPerPixel
);
143 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT
, VRes
- 1);
145 // Set the vertical timing information
146 MmioWrite32 (HDLCD_REG_V_SYNC
, VSync
);
147 MmioWrite32 (HDLCD_REG_V_BACK_PORCH
, VBackPorch
);
148 MmioWrite32 (HDLCD_REG_V_DATA
, VRes
- 1);
149 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH
, VFrontPorch
);
151 // Set the horizontal timing information
152 MmioWrite32 (HDLCD_REG_H_SYNC
, HSync
);
153 MmioWrite32 (HDLCD_REG_H_BACK_PORCH
, HBackPorch
);
154 MmioWrite32 (HDLCD_REG_H_DATA
, HRes
- 1);
155 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH
, HFrontPorch
);
157 // Enable the controller
158 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_ENABLE
);
163 /** De-initializes the display.
170 // Disable the controller
171 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
174 /** Check for presence of HDLCD.
176 @retval EFI_SUCCESS Returns success if platform implements a HDLCD
178 @retval EFI_NOT_FOUND HDLCD display controller not found on the
186 if ((MmioRead32 (HDLCD_REG_VERSION
) >> 16) == HDLCD_PRODUCT_ID
) {
190 return EFI_NOT_FOUND
;