]> 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 f5886848ce582b475b597ccca015c816707ade0e..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
@@ -100,8 +72,8 @@ LcdSetMode (
   EFI_STATUS        Status;\r
   SCAN_TIMINGS      *Horizontal;\r
   SCAN_TIMINGS      *Vertical;\r
-  UINT32            BytesPerPixel;\r
-  LCD_BPP           LcdBpp;\r
+\r
+  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  ModeInfo;\r
 \r
   // Set the video mode timings and other relevant information\r
   Status = LcdPlatformGetTimings (\r
@@ -117,13 +89,22 @@ LcdSetMode (
   ASSERT (Horizontal != NULL);\r
   ASSERT (Vertical != NULL);\r
 \r
-  Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);\r
+  // Get the pixel format information.\r
+  Status = LcdPlatformQueryMode (ModeNumber, &ModeInfo);\r
   if (EFI_ERROR (Status)) {\r
     ASSERT_EFI_ERROR (Status);\r
     return Status;\r
   }\r
 \r
-  BytesPerPixel = GetBytesPerPixel (LcdBpp);\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
+  MmioWrite32 (HDLCD_REG_GREEN_SELECT, (8 << 8) | 8);\r
 \r
   // Disable the controller\r
   MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
@@ -131,10 +112,13 @@ LcdSetMode (
   // Update the frame buffer information with the new settings\r
   MmioWrite32 (\r
     HDLCD_REG_FB_LINE_LENGTH,\r
-    Horizontal->Resolution * BytesPerPixel\r
+    Horizontal->Resolution * BYTES_PER_PIXEL\r
     );\r
 \r
-  MmioWrite32 (HDLCD_REG_FB_LINE_PITCH, Horizontal->Resolution * BytesPerPixel);\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