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