]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Library/HdLcd/HdLcd.c
ArmPlatformPkg: implement LcdHwLib for HdLcd
[mirror_edk2.git] / ArmPlatformPkg / Library / HdLcd / HdLcd.c
CommitLineData
3e7105bb
AB
1/** @file Lcd.c\r
2\r
3 Copyright (c) 2011-2012, ARM Ltd. All rights reserved.<BR>\r
4\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Library/DebugLib.h>\r
16#include <Library/IoLib.h>\r
17#include <Library/LcdHwLib.h>\r
18#include <Library/LcdPlatformLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20#include <Library/PcdLib.h>\r
21\r
22#include "HdLcd.h"\r
23\r
24/**********************************************************************\r
25 *\r
26 * This file contains all the bits of the Lcd that are\r
27 * platform independent.\r
28 *\r
29 **********************************************************************/\r
30\r
31STATIC\r
32UINTN\r
33GetBytesPerPixel (\r
34 IN LCD_BPP Bpp\r
35 )\r
36{\r
37 switch(Bpp) {\r
38 case LCD_BITS_PER_PIXEL_24:\r
39 return 4;\r
40\r
41 case LCD_BITS_PER_PIXEL_16_565:\r
42 case LCD_BITS_PER_PIXEL_16_555:\r
43 case LCD_BITS_PER_PIXEL_12_444:\r
44 return 2;\r
45\r
46 case LCD_BITS_PER_PIXEL_8:\r
47 case LCD_BITS_PER_PIXEL_4:\r
48 case LCD_BITS_PER_PIXEL_2:\r
49 case LCD_BITS_PER_PIXEL_1:\r
50 return 1;\r
51\r
52 default:\r
53 return 0;\r
54 }\r
55}\r
56\r
57EFI_STATUS\r
58LcdInitialize (\r
59 IN EFI_PHYSICAL_ADDRESS VramBaseAddress\r
60 )\r
61{\r
62 // Disable the controller\r
63 MmioWrite32(HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
64\r
65 // Disable all interrupts\r
66 MmioWrite32(HDLCD_REG_INT_MASK, 0);\r
67\r
68 // Define start of the VRAM. This never changes for any graphics mode\r
69 MmioWrite32(HDLCD_REG_FB_BASE, (UINT32) VramBaseAddress);\r
70\r
71 // Setup various registers that never change\r
72 MmioWrite32(HDLCD_REG_BUS_OPTIONS, (4 << 8) | HDLCD_BURST_8);\r
73 MmioWrite32(HDLCD_REG_POLARITIES, HDLCD_PXCLK_LOW | HDLCD_DATA_HIGH | HDLCD_DATEN_HIGH | HDLCD_HSYNC_LOW | HDLCD_VSYNC_HIGH);\r
74 MmioWrite32(HDLCD_REG_PIXEL_FORMAT, HDLCD_LITTLE_ENDIAN | HDLCD_4BYTES_PER_PIXEL);\r
75 MmioWrite32(HDLCD_REG_RED_SELECT, (0 << 16 | 8 << 8 | 0));\r
76 MmioWrite32(HDLCD_REG_GREEN_SELECT, (0 << 16 | 8 << 8 | 8));\r
77 MmioWrite32(HDLCD_REG_BLUE_SELECT, (0 << 16 | 8 << 8 | 16));\r
78\r
79 return EFI_SUCCESS;\r
80}\r
81\r
82EFI_STATUS\r
83LcdSetMode (\r
84 IN UINT32 ModeNumber\r
85 )\r
86{\r
87 EFI_STATUS Status;\r
88 UINT32 HRes;\r
89 UINT32 HSync;\r
90 UINT32 HBackPorch;\r
91 UINT32 HFrontPorch;\r
92 UINT32 VRes;\r
93 UINT32 VSync;\r
94 UINT32 VBackPorch;\r
95 UINT32 VFrontPorch;\r
96 UINT32 BytesPerPixel;\r
97 LCD_BPP LcdBpp;\r
98\r
99\r
100 // Set the video mode timings and other relevant information\r
101 Status = LcdPlatformGetTimings (ModeNumber,\r
102 &HRes,&HSync,&HBackPorch,&HFrontPorch,\r
103 &VRes,&VSync,&VBackPorch,&VFrontPorch);\r
104 ASSERT_EFI_ERROR (Status);\r
105 if (EFI_ERROR( Status )) {\r
106 return EFI_DEVICE_ERROR;\r
107 }\r
108\r
109 Status = LcdPlatformGetBpp (ModeNumber,&LcdBpp);\r
110 ASSERT_EFI_ERROR (Status);\r
111 if (EFI_ERROR( Status )) {\r
112 return EFI_DEVICE_ERROR;\r
113 }\r
114\r
115 BytesPerPixel = GetBytesPerPixel(LcdBpp);\r
116\r
117 // Disable the controller\r
118 MmioWrite32(HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
119\r
120 // Update the frame buffer information with the new settings\r
121 MmioWrite32(HDLCD_REG_FB_LINE_LENGTH, HRes * BytesPerPixel);\r
122 MmioWrite32(HDLCD_REG_FB_LINE_PITCH, HRes * BytesPerPixel);\r
123 MmioWrite32(HDLCD_REG_FB_LINE_COUNT, VRes - 1);\r
124\r
125 // Set the vertical timing information\r
126 MmioWrite32(HDLCD_REG_V_SYNC, VSync);\r
127 MmioWrite32(HDLCD_REG_V_BACK_PORCH, VBackPorch);\r
128 MmioWrite32(HDLCD_REG_V_DATA, VRes - 1);\r
129 MmioWrite32(HDLCD_REG_V_FRONT_PORCH, VFrontPorch);\r
130\r
131 // Set the horizontal timing information\r
132 MmioWrite32(HDLCD_REG_H_SYNC, HSync);\r
133 MmioWrite32(HDLCD_REG_H_BACK_PORCH, HBackPorch);\r
134 MmioWrite32(HDLCD_REG_H_DATA, HRes - 1);\r
135 MmioWrite32(HDLCD_REG_H_FRONT_PORCH, HFrontPorch);\r
136\r
137 // Enable the controller\r
138 MmioWrite32(HDLCD_REG_COMMAND, HDLCD_ENABLE);\r
139\r
140 return EFI_SUCCESS;\r
141}\r
142\r
143VOID\r
144LcdShutdown (\r
145 VOID\r
146 )\r
147{\r
148 // Disable the controller\r
149 MmioWrite32 (HDLCD_REG_COMMAND, HDLCD_DISABLE);\r
150}\r
151\r
152EFI_STATUS\r
153LcdIdentify (\r
154 VOID\r
155 )\r
156{\r
157 return EFI_SUCCESS;\r
158}\r