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.
101 SCAN_TIMINGS
*Horizontal
;
102 SCAN_TIMINGS
*Vertical
;
103 UINT32 BytesPerPixel
;
106 // Set the video mode timings and other relevant information
107 Status
= LcdPlatformGetTimings (
112 if (EFI_ERROR (Status
)) {
113 ASSERT_EFI_ERROR (Status
);
117 ASSERT (Horizontal
!= NULL
);
118 ASSERT (Vertical
!= NULL
);
120 Status
= LcdPlatformGetBpp (ModeNumber
, &LcdBpp
);
121 if (EFI_ERROR (Status
)) {
122 ASSERT_EFI_ERROR (Status
);
126 BytesPerPixel
= GetBytesPerPixel (LcdBpp
);
128 // Disable the controller
129 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
131 // Update the frame buffer information with the new settings
133 HDLCD_REG_FB_LINE_LENGTH
,
134 Horizontal
->Resolution
* BytesPerPixel
137 MmioWrite32 (HDLCD_REG_FB_LINE_PITCH
, Horizontal
->Resolution
* BytesPerPixel
);
139 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT
, Vertical
->Resolution
- 1);
141 // Set the vertical timing information
142 MmioWrite32 (HDLCD_REG_V_SYNC
, Vertical
->Sync
);
143 MmioWrite32 (HDLCD_REG_V_BACK_PORCH
, Vertical
->BackPorch
);
144 MmioWrite32 (HDLCD_REG_V_DATA
, Vertical
->Resolution
- 1);
145 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH
, Vertical
->FrontPorch
);
147 // Set the horizontal timing information
148 MmioWrite32 (HDLCD_REG_H_SYNC
, Horizontal
->Sync
);
149 MmioWrite32 (HDLCD_REG_H_BACK_PORCH
, Horizontal
->BackPorch
);
150 MmioWrite32 (HDLCD_REG_H_DATA
, Horizontal
->Resolution
- 1);
151 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH
, Horizontal
->FrontPorch
);
153 // Enable the controller
154 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_ENABLE
);
159 /** De-initializes the display.
166 // Disable the controller
167 MmioWrite32 (HDLCD_REG_COMMAND
, HDLCD_DISABLE
);
170 /** Check for presence of HDLCD.
172 @retval EFI_SUCCESS Returns success if platform implements a HDLCD
174 @retval EFI_NOT_FOUND HDLCD display controller not found on the
182 if ((MmioRead32 (HDLCD_REG_VERSION
) >> 16) == HDLCD_PRODUCT_ID
) {
186 return EFI_NOT_FOUND
;