PL111Lcd.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /** @file
  2. This file contains the platform independent parts of PL111Lcd
  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 "PL111Lcd.h"
  12. /** Check for presence of PL111.
  13. @retval EFI_SUCCESS Returns success if platform implements a
  14. PL111 controller.
  15. @retval EFI_NOT_FOUND PL111 display controller not found the plaform.
  16. **/
  17. EFI_STATUS
  18. LcdIdentify (
  19. VOID
  20. )
  21. {
  22. DEBUG ((EFI_D_WARN, "Probing ID registers at 0x%lx for a PL111\n",
  23. PL111_REG_CLCD_PERIPH_ID_0));
  24. // Check if this is a PL111
  25. if (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0) == PL111_CLCD_PERIPH_ID_0 &&
  26. MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1) == PL111_CLCD_PERIPH_ID_1 &&
  27. (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2) & 0xf) == PL111_CLCD_PERIPH_ID_2 &&
  28. MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3) == PL111_CLCD_PERIPH_ID_3 &&
  29. MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0) == PL111_CLCD_P_CELL_ID_0 &&
  30. MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1) == PL111_CLCD_P_CELL_ID_1 &&
  31. MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2) == PL111_CLCD_P_CELL_ID_2 &&
  32. MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3) == PL111_CLCD_P_CELL_ID_3) {
  33. return EFI_SUCCESS;
  34. }
  35. return EFI_NOT_FOUND;
  36. }
  37. /** Initialize display.
  38. @param[in] VramBaseAddress Address of the framebuffer.
  39. @retval EFI_SUCCESS Initialization of display successful.
  40. **/
  41. EFI_STATUS
  42. LcdInitialize (
  43. IN EFI_PHYSICAL_ADDRESS VramBaseAddress
  44. )
  45. {
  46. // Define start of the VRAM. This never changes for any graphics mode
  47. MmioWrite32 (PL111_REG_LCD_UP_BASE, (UINT32)VramBaseAddress);
  48. MmioWrite32 (PL111_REG_LCD_LP_BASE, 0); // We are not using a double buffer
  49. // Disable all interrupts from the PL111
  50. MmioWrite32 (PL111_REG_LCD_IMSC, 0);
  51. return EFI_SUCCESS;
  52. }
  53. /** Set requested mode of the display.
  54. @param[in] ModeNumbe Display mode number.
  55. @retval EFI_SUCCESS Display mode set successfuly.
  56. @retval !(EFI_SUCCESS) Other errors.
  57. **/
  58. EFI_STATUS
  59. LcdSetMode (
  60. IN UINT32 ModeNumber
  61. )
  62. {
  63. EFI_STATUS Status;
  64. SCAN_TIMINGS *Horizontal;
  65. SCAN_TIMINGS *Vertical;
  66. UINT32 LcdControl;
  67. LCD_BPP LcdBpp;
  68. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;
  69. // Set the video mode timings and other relevant information
  70. Status = LcdPlatformGetTimings (
  71. ModeNumber,
  72. &Horizontal,
  73. &Vertical
  74. );
  75. if (EFI_ERROR (Status)) {
  76. ASSERT_EFI_ERROR (Status);
  77. return Status;
  78. }
  79. ASSERT (Horizontal != NULL);
  80. ASSERT (Vertical != NULL);
  81. Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);
  82. if (EFI_ERROR (Status)) {
  83. ASSERT_EFI_ERROR (Status);
  84. return Status;
  85. }
  86. // Get the pixel format information
  87. Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);
  88. if (EFI_ERROR (Status)) {
  89. ASSERT_EFI_ERROR (Status);
  90. return Status;
  91. }
  92. // Disable the CLCD_LcdEn bit
  93. MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);
  94. // Set Timings
  95. MmioWrite32 (
  96. PL111_REG_LCD_TIMING_0,
  97. HOR_AXIS_PANEL (
  98. Horizontal->BackPorch,
  99. Horizontal->FrontPorch,
  100. Horizontal->Sync,
  101. Horizontal->Resolution
  102. )
  103. );
  104. MmioWrite32 (
  105. PL111_REG_LCD_TIMING_1,
  106. VER_AXIS_PANEL (
  107. Vertical->BackPorch,
  108. Vertical->FrontPorch,
  109. Vertical->Sync,
  110. Vertical->Resolution
  111. )
  112. );
  113. MmioWrite32 (
  114. PL111_REG_LCD_TIMING_2,
  115. CLK_SIG_POLARITY (Horizontal->Resolution)
  116. );
  117. MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);
  118. // PL111_REG_LCD_CONTROL
  119. LcdControl = PL111_CTRL_LCD_EN | PL111_CTRL_LCD_BPP (LcdBpp) |
  120. PL111_CTRL_LCD_TFT | PL111_CTRL_LCD_PWR;
  121. if (ModeInfo.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
  122. LcdControl |= PL111_CTRL_BGR;
  123. }
  124. MmioWrite32 (PL111_REG_LCD_CONTROL, LcdControl);
  125. return EFI_SUCCESS;
  126. }
  127. /** De-initializes the display.
  128. */
  129. VOID
  130. LcdShutdown (
  131. VOID
  132. )
  133. {
  134. // Disable the controller
  135. MmioAnd32 (PL111_REG_LCD_CONTROL, ~PL111_CTRL_LCD_EN);
  136. }