3 ARM Mali DP 500/550/650 display controller driver
5 Copyright (c) 2017-2018, Arm Limited. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/IoLib.h>
13 #include <Library/LcdHwLib.h>
14 #include <Library/LcdPlatformLib.h>
15 #include <Library/MemoryAllocationLib.h>
17 #include "ArmMaliDp.h"
19 // CORE_ID of the MALI DP
20 STATIC UINT32 mDpDeviceId
;
22 /** Disable the graphics layer
24 This is done by clearing the EN bit of the LG_CONTROL register.
28 LayerGraphicsDisable (
32 MmioAnd32 (DP_BASE
+ DP_DE_LG_CONTROL
, ~DP_DE_LG_ENABLE
);
35 /** Enable the graphics layer
37 This is done by setting the EN bit of the LG_CONTROL register.
45 MmioOr32 (DP_BASE
+ DP_DE_LG_CONTROL
, DP_DE_LG_ENABLE
);
48 /** Set the frame address of the graphics layer.
50 @param[in] FrameBaseAddress Address of the data buffer to be used as
55 LayerGraphicsSetFrame (
56 IN CONST EFI_PHYSICAL_ADDRESS FrameBaseAddress
59 // Disable the graphics layer.
60 LayerGraphicsDisable ();
62 // Set up memory address of the data buffer for graphics layer.
63 // write lower bits of the address.
65 DP_BASE
+ DP_DE_LG_PTR_LOW
,
66 DP_DE_LG_PTR_LOW_MASK
& FrameBaseAddress
69 // Write higher bits of the address.
71 DP_BASE
+ DP_DE_LG_PTR_HIGH
,
72 (UINT32
)(FrameBaseAddress
>> DP_DE_LG_PTR_HIGH_SHIFT
)
75 // Enable the graphics layer.
76 LayerGraphicsEnable ();
79 /** Configures various graphics layer characteristics.
81 @param[in] UefiGfxPixelFormat This must be either
82 PixelBlueGreenRedReserved8BitPerColor
84 PixelRedGreenBlueReserved8BitPerColor
85 @param[in] HRes Horizontal resolution of the graphics layer.
86 @param[in] VRes Vertical resolution of the graphics layer.
91 IN CONST EFI_GRAPHICS_PIXEL_FORMAT UefiGfxPixelFormat
,
98 // Disable the graphics layer before configuring any settings.
99 LayerGraphicsDisable ();
101 // Setup graphics layer size.
102 MmioWrite32 (DP_BASE
+ DP_DE_LG_IN_SIZE
, FRAME_IN_SIZE (HRes
, VRes
));
104 // Setup graphics layer composition size.
105 MmioWrite32 (DP_BASE
+ DP_DE_LG_CMP_SIZE
, FRAME_CMP_SIZE (HRes
, VRes
));
107 // Setup memory stride (total visible pixels on a line * 4).
108 MmioWrite32 (DP_BASE
+ DP_DE_LG_H_STRIDE
, (HRes
* sizeof (UINT32
)));
112 // In PixelBlueGreenRedReserved8BitPerColor format, byte 0 represents blue,
113 // byte 1 represents green, byte 2 represents red, and byte 3 is reserved
114 // which is equivalent to XRGB format of the DP500/DP550/DP650. Whereas
115 // PixelRedGreenBlueReserved8BitPerColor is equivalent to XBGR of the
116 // DP500/DP550/DP650.
117 if (UefiGfxPixelFormat
== PixelBlueGreenRedReserved8BitPerColor
) {
118 PixelFormat
= (mDpDeviceId
== MALIDP_500
) ? DP_PIXEL_FORMAT_DP500_XRGB_8888
119 : DP_PIXEL_FORMAT_XRGB_8888
;
121 PixelFormat
= (mDpDeviceId
== MALIDP_500
) ? DP_PIXEL_FORMAT_DP500_XBGR_8888
122 : DP_PIXEL_FORMAT_XBGR_8888
;
125 MmioWrite32 (DP_BASE
+ DP_DE_LG_FORMAT
, PixelFormat
);
127 // Enable graphics layer.
128 LayerGraphicsEnable ();
131 /** Configure timing information of the display.
133 @param[in] Horizontal Pointer to horizontal timing parameters.
134 (Resolution, Sync, Back porch, Front porch)
135 @param[in] Vertical Pointer to vertical timing parameters.
136 (Resolution, Sync, Back porch, Front porch)
140 SetDisplayEngineTiming (
141 IN CONST SCAN_TIMINGS
*CONST Horizontal
,
142 IN CONST SCAN_TIMINGS
*CONST Vertical
147 UINTN RegSyncControl
;
148 UINTN RegHVActiveSize
;
150 if (mDpDeviceId
== MALIDP_500
) {
151 // MALI DP500 timing registers.
152 RegHIntervals
= DP_BASE
+ DP_DE_DP500_H_INTERVALS
;
153 RegVIntervals
= DP_BASE
+ DP_DE_DP500_V_INTERVALS
;
154 RegSyncControl
= DP_BASE
+ DP_DE_DP500_SYNC_CONTROL
;
155 RegHVActiveSize
= DP_BASE
+ DP_DE_DP500_HV_ACTIVESIZE
;
157 // MALI DP550/DP650 timing registers.
158 RegHIntervals
= DP_BASE
+ DP_DE_H_INTERVALS
;
159 RegVIntervals
= DP_BASE
+ DP_DE_V_INTERVALS
;
160 RegSyncControl
= DP_BASE
+ DP_DE_SYNC_CONTROL
;
161 RegHVActiveSize
= DP_BASE
+ DP_DE_HV_ACTIVESIZE
;
164 // Horizontal back porch and front porch.
167 H_INTERVALS (Horizontal
->FrontPorch
, Horizontal
->BackPorch
)
170 // Vertical back porch and front porch.
173 V_INTERVALS (Vertical
->FrontPorch
, Vertical
->BackPorch
)
176 // Sync control, Horizontal and Vertical sync.
179 SYNC_WIDTH (Horizontal
->Sync
, Vertical
->Sync
)
182 // Set up Horizontal and Vertical area size.
185 HV_ACTIVE (Horizontal
->Resolution
, Vertical
->Resolution
)
189 /** Return CORE_ID of the ARM Mali DP.
191 @retval 0xFFF No Mali DP found.
192 @retval 0x500 Mali DP core id for DP500.
193 @retval 0x550 Mali DP core id for DP550.
194 @retval 0x650 Mali DP core id for DP650.
203 // First check for DP500 as register offset for DP550/DP650 CORE_ID
204 // is beyond 3K/4K register space of the DP500.
205 DpCoreId
= MmioRead32 (DP_BASE
+ DP_DE_DP500_CORE_ID
);
206 DpCoreId
>>= DP_DE_DP500_CORE_ID_SHIFT
;
208 if (DpCoreId
== MALIDP_500
) {
212 // Check for DP550 or DP650.
213 DpCoreId
= MmioRead32 (DP_BASE
+ DP_DC_CORE_ID
);
214 DpCoreId
>>= DP_DC_CORE_ID_SHIFT
;
216 if ((DpCoreId
== MALIDP_550
) || (DpCoreId
== MALIDP_650
)) {
220 return MALIDP_NOT_PRESENT
;
223 /** Check for presence of MALI.
225 This function returns success if the platform implements
226 DP500/DP550/DP650 ARM Mali display processor.
228 @retval EFI_SUCCESS DP500/DP550/DP650 display processor found
230 @retval EFI_NOT_FOUND DP500/DP550/DP650 display processor not found
240 "Probing ARM Mali DP500/DP550/DP650 at base address 0x%p\n",
244 if (mDpDeviceId
== 0) {
245 mDpDeviceId
= ArmMaliDpGetCoreId ();
248 if (mDpDeviceId
== MALIDP_NOT_PRESENT
) {
249 DEBUG ((DEBUG_WARN
, "ARM Mali DP not found...\n"));
250 return EFI_NOT_FOUND
;
253 DEBUG ((DEBUG_WARN
, "Found ARM Mali DP %x\n", mDpDeviceId
));
257 /** Initialize platform display.
259 @param[in] FrameBaseAddress Address of the frame buffer.
261 @retval EFI_SUCCESS Display initialization successful.
262 @retval !(EFI_SUCCESS) Display initialization failure.
266 IN CONST EFI_PHYSICAL_ADDRESS FrameBaseAddress
269 DEBUG ((DEBUG_WARN
, "Framebuffer base address = %p\n", FrameBaseAddress
));
271 if (mDpDeviceId
== 0) {
272 mDpDeviceId
= ArmMaliDpGetCoreId ();
275 if (mDpDeviceId
== MALIDP_NOT_PRESENT
) {
278 "ARM Mali DP initialization failed,"
279 "no ARM Mali DP present\n"
281 return EFI_NOT_FOUND
;
284 // We are using graphics layer of the Mali DP as a main framebuffer.
285 LayerGraphicsSetFrame (FrameBaseAddress
);
290 /** Set ARM Mali DP in cofiguration mode.
292 The ARM Mali DP must be in the configuration mode for
293 configuration of the H_INTERVALS, V_INTERVALS, SYNC_CONTROL
298 SetConfigurationMode (
302 // Request configuration Mode.
303 if (mDpDeviceId
== MALIDP_500
) {
304 MmioOr32 (DP_BASE
+ DP_DE_DP500_CONTROL
, DP_DE_DP500_CONTROL_CONFIG_REQ
);
306 MmioOr32 (DP_BASE
+ DP_DC_CONTROL
, DP_DC_CONTROL_CM_ACTIVE
);
310 /** Set ARM Mali DP in normal mode.
312 Normal mode is the main operating mode of the display processor
313 in which display layer data is fetched from framebuffer and
322 // Disable configuration Mode.
323 if (mDpDeviceId
== MALIDP_500
) {
324 MmioAnd32 (DP_BASE
+ DP_DE_DP500_CONTROL
, ~DP_DE_DP500_CONTROL_CONFIG_REQ
);
326 MmioAnd32 (DP_BASE
+ DP_DC_CONTROL
, ~DP_DC_CONTROL_CM_ACTIVE
);
330 /** Set the global configuration valid flag.
332 Any new configuration parameters written to the display engine are not
333 activated until the global configuration valid flag is set in the
334 CONFIG_VALID register.
342 if (mDpDeviceId
== MALIDP_500
) {
343 MmioOr32 (DP_BASE
+ DP_DP500_CONFIG_VALID
, DP_DC_CONFIG_VALID
);
345 MmioOr32 (DP_BASE
+ DP_DC_CONFIG_VALID
, DP_DC_CONFIG_VALID
);
349 /** Set requested mode of the display.
351 @param[in] ModeNumber Display mode number.
353 @retval EFI_SUCCESS Display mode set successful.
354 @retval EFI_DEVICE_ERROR Display mode not found/supported.
358 IN CONST UINT32 ModeNumber
362 SCAN_TIMINGS
*Horizontal
;
363 SCAN_TIMINGS
*Vertical
;
365 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo
;
367 // Get the display mode timings and other relevant information.
368 Status
= LcdPlatformGetTimings (
373 if (EFI_ERROR (Status
)) {
374 ASSERT_EFI_ERROR (Status
);
378 ASSERT (Horizontal
!= NULL
);
379 ASSERT (Vertical
!= NULL
);
381 // Get the pixel format information.
382 Status
= LcdPlatformQueryMode (ModeNumber
, &ModeInfo
);
383 if (EFI_ERROR (Status
)) {
384 ASSERT_EFI_ERROR (Status
);
388 // Request configuration mode.
389 SetConfigurationMode ();
391 // Configure the graphics layer.
392 LayerGraphicsConfig (
393 ModeInfo
.PixelFormat
,
394 Horizontal
->Resolution
,
398 // Set the display engine timings.
399 SetDisplayEngineTiming (Horizontal
, Vertical
);
401 // After configuration, set Mali DP in normal mode.
404 // Any parameters written to the display engine are not activated until
405 // CONFIG_VALID is set.
411 /** This function de-initializes the display.
419 // Disable graphics layer.
420 LayerGraphicsDisable ();