]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Library/HdLcd/HdLcd.c
ArmPlatformPkg: Add PCD to select pixel format
[mirror_edk2.git] / ArmPlatformPkg / Library / HdLcd / HdLcd.c
index be4ccfdc1f421060faec792c8e8acfcfb3232014..96f2bf437fbabd2509f860c67c5442def5b5f03d 100644 (file)
 \r
 #include "HdLcd.h"\r
 \r
-STATIC\r
-UINTN\r
-GetBytesPerPixel (\r
-  IN  LCD_BPP       Bpp\r
-  )\r
-{\r
-  switch (Bpp) {\r
-  case LCD_BITS_PER_PIXEL_24:\r
-    return 4;\r
-\r
-  case LCD_BITS_PER_PIXEL_16_565:\r
-  case LCD_BITS_PER_PIXEL_16_555:\r
-  case LCD_BITS_PER_PIXEL_12_444:\r
-    return 2;\r
-\r
-  case LCD_BITS_PER_PIXEL_8:\r
-  case LCD_BITS_PER_PIXEL_4:\r
-  case LCD_BITS_PER_PIXEL_2:\r
-  case LCD_BITS_PER_PIXEL_1:\r
-    return 1;\r
-\r
-  default:\r
-    return 0;\r
-  }\r
-}\r
+#define BYTES_PER_PIXEL 4\r
 \r
 /** Initialize display.\r
 \r
@@ -78,10 +54,6 @@ LcdInitialize (
     HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL\r
     );\r
 \r
-  MmioWrite32 (HDLCD_REG_RED_SELECT,   (0 << 16 | 8 << 8 | 0));\r
-  MmioWrite32 (HDLCD_REG_GREEN_SELECT, (0 << 16 | 8 << 8 | 8));\r
-  MmioWrite32 (HDLCD_REG_BLUE_SELECT,  (0 << 16 | 8 << 8 | 16));\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -90,8 +62,7 @@ LcdInitialize (
   @param[in] ModeNumber          Display mode number.\r
 \r
   @retval EFI_SUCCESS            Display mode set successfully.\r
-  @retval EFI_DEVICE_ERROR       Reurns an error if display timing\r
-                                 information is not available.\r
+  @retval !(EFI_SUCCESS)         Other errors.\r
 **/\r
 EFI_STATUS\r
 LcdSetMode (\r
@@ -99,61 +70,69 @@ LcdSetMode (
   )\r
 {\r
   EFI_STATUS        Status;\r
-  UINT32            HRes;\r
-  UINT32            HSync;\r
-  UINT32            HBackPorch;\r
-  UINT32            HFrontPorch;\r
-  UINT32            VRes;\r
-  UINT32            VSync;\r
-  UINT32            VBackPorch;\r
-  UINT32            VFrontPorch;\r
-  UINT32            BytesPerPixel;\r
-  LCD_BPP           LcdBpp;\r
+  SCAN_TIMINGS      *Horizontal;\r
+  SCAN_TIMINGS      *Vertical;\r
+\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  ModeInfo;\r
 \r
   // Set the video mode timings and other relevant information\r
   Status = LcdPlatformGetTimings (\r
              ModeNumber,\r
-             &HRes,\r
-             &HSync,\r
-             &HBackPorch,\r
-             &HFrontPorch,\r
-             &VRes,\r
-             &VSync,\r
-             &VBackPorch,\r
-             &VFrontPorch\r
+             &Horizontal,\r
+             &Vertical\r
              );\r
-  ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_DEVICE_ERROR;\r
+    ASSERT_EFI_ERROR (Status);\r
+    return Status;\r
   }\r
 \r
-  Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);\r
-  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (Horizontal != NULL);\r
+  ASSERT (Vertical != NULL);\r
+\r
+  // Get the pixel format information.\r
+  Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_DEVICE_ERROR;\r
+    ASSERT_EFI_ERROR (Status);\r
+    return Status;\r
+  }\r
+\r
+  if (ModeInfo.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {\r
+    MmioWrite32 (HDLCD_REG_RED_SELECT,  (8 << 8) | 16);\r
+    MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 0);\r
+  } else {\r
+    MmioWrite32 (HDLCD_REG_BLUE_SELECT, (8 << 8) | 16);\r
+    MmioWrite32 (HDLCD_REG_RED_SELECT,  (8 << 8) | 0);\r
   }\r
 \r
-  BytesPerPixel = GetBytesPerPixel (LcdBpp);\r
+  MmioWrite32 (HDLCD_REG_GREEN_SELECT, (8 << 8) | 8);\r
 \r
   // Disable the controller\r
   MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
 \r
   // Update the frame buffer information with the new settings\r
-  MmioWrite32 (HDLCD_REG_FB_LINE_LENGTH, HRes * BytesPerPixel);\r
-  MmioWrite32 (HDLCD_REG_FB_LINE_PITCH,  HRes * BytesPerPixel);\r
-  MmioWrite32 (HDLCD_REG_FB_LINE_COUNT,  VRes - 1);\r
+  MmioWrite32 (\r
+    HDLCD_REG_FB_LINE_LENGTH,\r
+    Horizontal->Resolution * BYTES_PER_PIXEL\r
+    );\r
+\r
+  MmioWrite32 (\r
+    HDLCD_REG_FB_LINE_PITCH,\r
+    Horizontal->Resolution * BYTES_PER_PIXEL\r
+    );\r
+\r
+  MmioWrite32 (HDLCD_REG_FB_LINE_COUNT, Vertical->Resolution - 1);\r
 \r
   // Set the vertical timing information\r
-  MmioWrite32 (HDLCD_REG_V_SYNC,         VSync);\r
-  MmioWrite32 (HDLCD_REG_V_BACK_PORCH,   VBackPorch);\r
-  MmioWrite32 (HDLCD_REG_V_DATA,         VRes - 1);\r
-  MmioWrite32 (HDLCD_REG_V_FRONT_PORCH,  VFrontPorch);\r
+  MmioWrite32 (HDLCD_REG_V_SYNC,        Vertical->Sync);\r
+  MmioWrite32 (HDLCD_REG_V_BACK_PORCH,  Vertical->BackPorch);\r
+  MmioWrite32 (HDLCD_REG_V_DATA,        Vertical->Resolution - 1);\r
+  MmioWrite32 (HDLCD_REG_V_FRONT_PORCH, Vertical->FrontPorch);\r
 \r
   // Set the horizontal timing information\r
-  MmioWrite32 (HDLCD_REG_H_SYNC,         HSync);\r
-  MmioWrite32 (HDLCD_REG_H_BACK_PORCH,   HBackPorch);\r
-  MmioWrite32 (HDLCD_REG_H_DATA,         HRes - 1);\r
-  MmioWrite32 (HDLCD_REG_H_FRONT_PORCH,  HFrontPorch);\r
+  MmioWrite32 (HDLCD_REG_H_SYNC,        Horizontal->Sync);\r
+  MmioWrite32 (HDLCD_REG_H_BACK_PORCH,  Horizontal->BackPorch);\r
+  MmioWrite32 (HDLCD_REG_H_DATA,        Horizontal->Resolution - 1);\r
+  MmioWrite32 (HDLCD_REG_H_FRONT_PORCH, Horizontal->FrontPorch);\r
 \r
   // Enable the controller\r
   MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_ENABLE);\r
@@ -176,11 +155,17 @@ LcdShutdown (
 \r
   @retval EFI_SUCCESS            Returns success if platform implements a HDLCD\r
                                  controller.\r
+  @retval EFI_NOT_FOUND          HDLCD display controller not found on the\r
+                                 platform.\r
 **/\r
 EFI_STATUS\r
 LcdIdentify (\r
   VOID\r
   )\r
 {\r
-  return EFI_SUCCESS;\r
+  if ((MmioRead32 (HDLCD_REG_VERSION) >> 16) == HDLCD_PRODUCT_ID) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
 }\r