]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/HdLcd/HdLcd.c
ArmPlatformPkg: Redefine LcdPlatformGetTimings function
[mirror_edk2.git] / ArmPlatformPkg / Library / HdLcd / HdLcd.c
CommitLineData
b1b69d26 1/** @file\r
4257dfaa 2 This file contains the platform independent parts of HdLcd\r
3e7105bb 3\r
b1b69d26 4 Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>\r
3e7105bb
AB
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Library/DebugLib.h>\r
17#include <Library/IoLib.h>\r
18#include <Library/LcdHwLib.h>\r
19#include <Library/LcdPlatformLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/PcdLib.h>\r
22\r
23#include "HdLcd.h"\r
24\r
3e7105bb
AB
25STATIC\r
26UINTN\r
27GetBytesPerPixel (\r
28 IN LCD_BPP Bpp\r
29 )\r
30{\r
b1b69d26 31 switch (Bpp) {\r
3e7105bb
AB
32 case LCD_BITS_PER_PIXEL_24:\r
33 return 4;\r
34\r
35 case LCD_BITS_PER_PIXEL_16_565:\r
36 case LCD_BITS_PER_PIXEL_16_555:\r
37 case LCD_BITS_PER_PIXEL_12_444:\r
38 return 2;\r
39\r
40 case LCD_BITS_PER_PIXEL_8:\r
41 case LCD_BITS_PER_PIXEL_4:\r
42 case LCD_BITS_PER_PIXEL_2:\r
43 case LCD_BITS_PER_PIXEL_1:\r
44 return 1;\r
45\r
46 default:\r
47 return 0;\r
48 }\r
49}\r
50\r
4257dfaa
GP
51/** Initialize display.\r
52\r
53 @param[in] VramBaseAddress Address of the framebuffer.\r
54\r
55 @retval EFI_SUCCESS Display initialization successful.\r
56**/\r
3e7105bb
AB
57EFI_STATUS\r
58LcdInitialize (\r
59 IN EFI_PHYSICAL_ADDRESS VramBaseAddress\r
60 )\r
61{\r
62 // Disable the controller\r
b1b69d26 63 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
3e7105bb
AB
64\r
65 // Disable all interrupts\r
b1b69d26 66 MmioWrite32 (HDLCD_REG_INT_MASK, 0);\r
3e7105bb
AB
67\r
68 // Define start of the VRAM. This never changes for any graphics mode\r
b1b69d26 69 MmioWrite32 (HDLCD_REG_FB_BASE, (UINT32)VramBaseAddress);\r
3e7105bb
AB
70\r
71 // Setup various registers that never change\r
b1b69d26
GP
72 MmioWrite32 (HDLCD_REG_BUS_OPTIONS, (4 << 8) | HDLCD_BURST_8);\r
73\r
74 MmioWrite32 (HDLCD_REG_POLARITIES, HDLCD_DEFAULT_POLARITIES);\r
75\r
76 MmioWrite32 (\r
77 HDLCD_REG_PIXEL_FORMAT,\r
78 HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL\r
79 );\r
80\r
81 MmioWrite32 (HDLCD_REG_RED_SELECT, (0 << 16 | 8 << 8 | 0));\r
82 MmioWrite32 (HDLCD_REG_GREEN_SELECT, (0 << 16 | 8 << 8 | 8));\r
83 MmioWrite32 (HDLCD_REG_BLUE_SELECT, (0 << 16 | 8 << 8 | 16));\r
3e7105bb
AB
84\r
85 return EFI_SUCCESS;\r
86}\r
87\r
4257dfaa
GP
88/** Set requested mode of the display.\r
89\r
90 @param[in] ModeNumber Display mode number.\r
91\r
92 @retval EFI_SUCCESS Display mode set successfully.\r
3da4193b 93 @retval !(EFI_SUCCESS) Other errors.\r
4257dfaa 94**/\r
3e7105bb
AB
95EFI_STATUS\r
96LcdSetMode (\r
97 IN UINT32 ModeNumber\r
98 )\r
99{\r
100 EFI_STATUS Status;\r
262c8846
GP
101 SCAN_TIMINGS *Horizontal;\r
102 SCAN_TIMINGS *Vertical;\r
3e7105bb
AB
103 UINT32 BytesPerPixel;\r
104 LCD_BPP LcdBpp;\r
105\r
3e7105bb 106 // Set the video mode timings and other relevant information\r
b1b69d26
GP
107 Status = LcdPlatformGetTimings (\r
108 ModeNumber,\r
262c8846
GP
109 &Horizontal,\r
110 &Vertical\r
b1b69d26 111 );\r
b1b69d26 112 if (EFI_ERROR (Status)) {\r
3da4193b
GP
113 ASSERT_EFI_ERROR (Status);\r
114 return Status;\r
3e7105bb
AB
115 }\r
116\r
262c8846
GP
117 ASSERT (Horizontal != NULL);\r
118 ASSERT (Vertical != NULL);\r
119\r
b1b69d26 120 Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);\r
b1b69d26 121 if (EFI_ERROR (Status)) {\r
3da4193b
GP
122 ASSERT_EFI_ERROR (Status);\r
123 return Status;\r
3e7105bb
AB
124 }\r
125\r
b1b69d26 126 BytesPerPixel = GetBytesPerPixel (LcdBpp);\r
3e7105bb
AB
127\r
128 // Disable the controller\r
b1b69d26 129 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
3e7105bb
AB
130\r
131 // Update the frame buffer information with the new settings\r
262c8846
GP
132 MmioWrite32 (\r
133 HDLCD_REG_FB_LINE_LENGTH,\r
134 Horizontal->Resolution * BytesPerPixel\r
135 );\r
136\r
137 MmioWrite32 (HDLCD_REG_FB_LINE_PITCH, Horizontal->Resolution * BytesPerPixel);\r
138\r
139 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT, Vertical->Resolution - 1);\r
3e7105bb
AB
140\r
141 // Set the vertical timing information\r
262c8846
GP
142 MmioWrite32 (HDLCD_REG_V_SYNC, Vertical->Sync);\r
143 MmioWrite32 (HDLCD_REG_V_BACK_PORCH, Vertical->BackPorch);\r
144 MmioWrite32 (HDLCD_REG_V_DATA, Vertical->Resolution - 1);\r
145 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH, Vertical->FrontPorch);\r
3e7105bb
AB
146\r
147 // Set the horizontal timing information\r
262c8846
GP
148 MmioWrite32 (HDLCD_REG_H_SYNC, Horizontal->Sync);\r
149 MmioWrite32 (HDLCD_REG_H_BACK_PORCH, Horizontal->BackPorch);\r
150 MmioWrite32 (HDLCD_REG_H_DATA, Horizontal->Resolution - 1);\r
151 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH, Horizontal->FrontPorch);\r
3e7105bb
AB
152\r
153 // Enable the controller\r
b1b69d26 154 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_ENABLE);\r
3e7105bb
AB
155\r
156 return EFI_SUCCESS;\r
157}\r
158\r
4257dfaa
GP
159/** De-initializes the display.\r
160**/\r
3e7105bb
AB
161VOID\r
162LcdShutdown (\r
163 VOID\r
164 )\r
165{\r
166 // Disable the controller\r
167 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
168}\r
169\r
4257dfaa
GP
170/** Check for presence of HDLCD.\r
171\r
172 @retval EFI_SUCCESS Returns success if platform implements a HDLCD\r
173 controller.\r
c18ef81e
GP
174 @retval EFI_NOT_FOUND HDLCD display controller not found on the\r
175 platform.\r
4257dfaa 176**/\r
3e7105bb
AB
177EFI_STATUS\r
178LcdIdentify (\r
179 VOID\r
180 )\r
181{\r
c18ef81e
GP
182 if ((MmioRead32 (HDLCD_REG_VERSION) >> 16) == HDLCD_PRODUCT_ID) {\r
183 return EFI_SUCCESS;\r
184 }\r
185\r
186 return EFI_NOT_FOUND;\r
3e7105bb 187}\r