HdLcd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /** @file
  2. This file contains the platform independent parts of HdLcd
  3. Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Library/DebugLib.h>
  7. #include <Library/IoLib.h>
  8. #include <Library/LcdHwLib.h>
  9. #include <Library/LcdPlatformLib.h>
  10. #include <Library/MemoryAllocationLib.h>
  11. #include <Library/PcdLib.h>
  12. #include "HdLcd.h"
  13. #define BYTES_PER_PIXEL 4
  14. /** Initialize display.
  15. @param[in] VramBaseAddress Address of the framebuffer.
  16. @retval EFI_SUCCESS Display initialization successful.
  17. **/
  18. EFI_STATUS
  19. LcdInitialize (
  20. IN EFI_PHYSICAL_ADDRESS VramBaseAddress
  21. )
  22. {
  23. // Disable the controller
  24. MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);
  25. // Disable all interrupts
  26. MmioWrite32 (HDLCD_REG_INT_MASK, 0);
  27. // Define start of the VRAM. This never changes for any graphics mode
  28. MmioWrite32 (HDLCD_REG_FB_BASE, (UINT32)VramBaseAddress);
  29. // Setup various registers that never change
  30. MmioWrite32 (HDLCD_REG_BUS_OPTIONS, (4 << 8) | HDLCD_BURST_8);
  31. MmioWrite32 (HDLCD_REG_POLARITIES, HDLCD_DEFAULT_POLARITIES);
  32. MmioWrite32 (
  33. HDLCD_REG_PIXEL_FORMAT,
  34. HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL
  35. );
  36. return EFI_SUCCESS;
  37. }
  38. /** Set requested mode of the display.
  39. @param[in] ModeNumber Display mode number.
  40. @retval EFI_SUCCESS Display mode set successfully.
  41. @retval !(EFI_SUCCESS) Other errors.
  42. **/
  43. EFI_STATUS
  44. LcdSetMode (
  45. IN UINT32 ModeNumber
  46. )
  47. {
  48. EFI_STATUS Status;
  49. SCAN_TIMINGS *Horizontal;
  50. SCAN_TIMINGS *Vertical;
  51. EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  52. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;
  53. // Set the video mode timings and other relevant information
  54. Status = LcdPlatformGetTimings (
  55. ModeNumber,
  56. &Horizontal,
  57. &Vertical
  58. );
  59. if (EFI_ERROR (Status)) {
  60. ASSERT_EFI_ERROR (Status);
  61. return Status;
  62. }
  63. ASSERT (Horizontal != NULL);
  64. ASSERT (Vertical != NULL);
  65. // Get the pixel format information.
  66. Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);
  67. if (EFI_ERROR (Status)) {
  68. ASSERT_EFI_ERROR (Status);
  69. return Status;
  70. }
  71. // By default PcdArmHdLcdSwapBlueRedSelect is set to false
  72. // However on the Juno platform HW lines for BLUE and RED are swapped
  73. // Therefore PcdArmHdLcdSwapBlueRedSelect is set to TRUE for the Juno platform
  74. PixelFormat = FixedPcdGetBool (PcdArmHdLcdSwapBlueRedSelect)
  75. ? PixelRedGreenBlueReserved8BitPerColor
  76. : PixelBlueGreenRedReserved8BitPerColor;
  77. if (ModeInfo.PixelFormat == PixelFormat) {
  78. MmioWrite32 (HDLCD_REG_RED_SELECT, (8 << 8) | 16);
  79. MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 0);
  80. } else {
  81. MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 16);
  82. MmioWrite32 (HDLCD_REG_RED_SELECT, (8 << 8) | 0);
  83. }
  84. MmioWrite32 (HDLCD_REG_GREEN_SELECT, (8 << 8) | 8);
  85. // Disable the controller
  86. MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);
  87. // Update the frame buffer information with the new settings
  88. MmioWrite32 (
  89. HDLCD_REG_FB_LINE_LENGTH,
  90. Horizontal->Resolution * BYTES_PER_PIXEL
  91. );
  92. MmioWrite32 (
  93. HDLCD_REG_FB_LINE_PITCH,
  94. Horizontal->Resolution * BYTES_PER_PIXEL
  95. );
  96. MmioWrite32 (HDLCD_REG_FB_LINE_COUNT, Vertical->Resolution - 1);
  97. // Set the vertical timing information
  98. MmioWrite32 (HDLCD_REG_V_SYNC, Vertical->Sync);
  99. MmioWrite32 (HDLCD_REG_V_BACK_PORCH, Vertical->BackPorch);
  100. MmioWrite32 (HDLCD_REG_V_DATA, Vertical->Resolution - 1);
  101. MmioWrite32 (HDLCD_REG_V_FRONT_PORCH, Vertical->FrontPorch);
  102. // Set the horizontal timing information
  103. MmioWrite32 (HDLCD_REG_H_SYNC, Horizontal->Sync);
  104. MmioWrite32 (HDLCD_REG_H_BACK_PORCH, Horizontal->BackPorch);
  105. MmioWrite32 (HDLCD_REG_H_DATA, Horizontal->Resolution - 1);
  106. MmioWrite32 (HDLCD_REG_H_FRONT_PORCH, Horizontal->FrontPorch);
  107. // Enable the controller
  108. MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_ENABLE);
  109. return EFI_SUCCESS;
  110. }
  111. /** De-initializes the display.
  112. **/
  113. VOID
  114. LcdShutdown (
  115. VOID
  116. )
  117. {
  118. // Disable the controller
  119. MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);
  120. }
  121. /** Check for presence of HDLCD.
  122. @retval EFI_SUCCESS Returns success if platform implements a HDLCD
  123. controller.
  124. @retval EFI_NOT_FOUND HDLCD display controller not found on the
  125. platform.
  126. **/
  127. EFI_STATUS
  128. LcdIdentify (
  129. VOID
  130. )
  131. {
  132. if ((MmioRead32 (HDLCD_REG_VERSION) >> 16) == HDLCD_PRODUCT_ID) {
  133. return EFI_SUCCESS;
  134. }
  135. return EFI_NOT_FOUND;
  136. }