]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/HdLcd/HdLcd.c
ArmPlatformPkg: Tidy Lcd code: Updated comments
[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
93 @retval EFI_DEVICE_ERROR Reurns an error if display timing\r
94 information is not available.\r
95**/\r
3e7105bb
AB
96EFI_STATUS\r
97LcdSetMode (\r
98 IN UINT32 ModeNumber\r
99 )\r
100{\r
101 EFI_STATUS Status;\r
102 UINT32 HRes;\r
103 UINT32 HSync;\r
104 UINT32 HBackPorch;\r
105 UINT32 HFrontPorch;\r
106 UINT32 VRes;\r
107 UINT32 VSync;\r
108 UINT32 VBackPorch;\r
109 UINT32 VFrontPorch;\r
110 UINT32 BytesPerPixel;\r
111 LCD_BPP LcdBpp;\r
112\r
3e7105bb 113 // Set the video mode timings and other relevant information\r
b1b69d26
GP
114 Status = LcdPlatformGetTimings (\r
115 ModeNumber,\r
116 &HRes,\r
117 &HSync,\r
118 &HBackPorch,\r
119 &HFrontPorch,\r
120 &VRes,\r
121 &VSync,\r
122 &VBackPorch,\r
123 &VFrontPorch\r
124 );\r
3e7105bb 125 ASSERT_EFI_ERROR (Status);\r
b1b69d26 126 if (EFI_ERROR (Status)) {\r
3e7105bb
AB
127 return EFI_DEVICE_ERROR;\r
128 }\r
129\r
b1b69d26 130 Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp);\r
3e7105bb 131 ASSERT_EFI_ERROR (Status);\r
b1b69d26 132 if (EFI_ERROR (Status)) {\r
3e7105bb
AB
133 return EFI_DEVICE_ERROR;\r
134 }\r
135\r
b1b69d26 136 BytesPerPixel = GetBytesPerPixel (LcdBpp);\r
3e7105bb
AB
137\r
138 // Disable the controller\r
b1b69d26 139 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
3e7105bb
AB
140\r
141 // Update the frame buffer information with the new settings\r
b1b69d26
GP
142 MmioWrite32 (HDLCD_REG_FB_LINE_LENGTH, HRes * BytesPerPixel);\r
143 MmioWrite32 (HDLCD_REG_FB_LINE_PITCH, HRes * BytesPerPixel);\r
144 MmioWrite32 (HDLCD_REG_FB_LINE_COUNT, VRes - 1);\r
3e7105bb
AB
145\r
146 // Set the vertical timing information\r
b1b69d26
GP
147 MmioWrite32 (HDLCD_REG_V_SYNC, VSync);\r
148 MmioWrite32 (HDLCD_REG_V_BACK_PORCH, VBackPorch);\r
149 MmioWrite32 (HDLCD_REG_V_DATA, VRes - 1);\r
150 MmioWrite32 (HDLCD_REG_V_FRONT_PORCH, VFrontPorch);\r
3e7105bb
AB
151\r
152 // Set the horizontal timing information\r
b1b69d26
GP
153 MmioWrite32 (HDLCD_REG_H_SYNC, HSync);\r
154 MmioWrite32 (HDLCD_REG_H_BACK_PORCH, HBackPorch);\r
155 MmioWrite32 (HDLCD_REG_H_DATA, HRes - 1);\r
156 MmioWrite32 (HDLCD_REG_H_FRONT_PORCH, HFrontPorch);\r
3e7105bb
AB
157\r
158 // Enable the controller\r
b1b69d26 159 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_ENABLE);\r
3e7105bb
AB
160\r
161 return EFI_SUCCESS;\r
162}\r
163\r
4257dfaa
GP
164/** De-initializes the display.\r
165**/\r
3e7105bb
AB
166VOID\r
167LcdShutdown (\r
168 VOID\r
169 )\r
170{\r
171 // Disable the controller\r
172 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
173}\r
174\r
4257dfaa
GP
175/** Check for presence of HDLCD.\r
176\r
177 @retval EFI_SUCCESS Returns success if platform implements a HDLCD\r
178 controller.\r
179**/\r
3e7105bb
AB
180EFI_STATUS\r
181LcdIdentify (\r
182 VOID\r
183 )\r
184{\r
185 return EFI_SUCCESS;\r
186}\r