]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c
ArmPlatformPkg: Add support for PL111 Lcd driver
[mirror_edk2.git] / ArmPlatformPkg / Drivers / LcdGraphicsOutputDxe / PL111Lcd.c
CommitLineData
7d0f2f23 1/** @file PL111Lcd.c\r
2\r
3 Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include <Library/DebugLib.h>\r
15#include <Library/IoLib.h>\r
16#include <Library/LcdPlatformLib.h>\r
17#include <Library/MemoryAllocationLib.h>\r
18#include <Library/PcdLib.h>\r
19\r
20#include <Drivers/PL111Lcd.h>\r
21\r
22#include "LcdGraphicsOutputDxe.h"\r
23\r
24/**********************************************************************\r
25 *\r
26 * This file contains all the bits of the PL111 that are\r
27 * platform independent.\r
28 *\r
29 **********************************************************************/\r
30\r
31EFI_STATUS\r
32PL111Indentify (\r
33 VOID\r
34 )\r
35{\r
36 // Check if this is a PrimeCell Peripheral\r
37 if ( ( MmioRead8( PL111_REG_CLCD_P_CELL_ID_0 ) != 0x0D )\r
38 || ( MmioRead8( PL111_REG_CLCD_P_CELL_ID_1 ) != 0xF0 )\r
39 || ( MmioRead8( PL111_REG_CLCD_P_CELL_ID_2 ) != 0x05 )\r
40 || ( MmioRead8( PL111_REG_CLCD_P_CELL_ID_3 ) != 0xB1 ) ) {\r
41 return EFI_NOT_FOUND;\r
42 }\r
43\r
44 // Check if this PrimeCell Peripheral is the PL111 LCD\r
45 if ( ( MmioRead8( PL111_REG_CLCD_PERIPH_ID_0 ) != 0x11 )\r
46 || ( MmioRead8( PL111_REG_CLCD_PERIPH_ID_1 ) != 0x11 )\r
47 || ( (MmioRead8( PL111_REG_CLCD_PERIPH_ID_2 ) & 0xF) != 0x04 )\r
48 || ( MmioRead8( PL111_REG_CLCD_PERIPH_ID_3 ) != 0x00 ) ) {\r
49 return EFI_NOT_FOUND;\r
50 }\r
51\r
52 return EFI_SUCCESS;\r
53}\r
54\r
55EFI_STATUS\r
56LcdInitialize (\r
57 IN EFI_PHYSICAL_ADDRESS VramBaseAddress\r
58 )\r
59{\r
60 EFI_STATUS Status = EFI_SUCCESS;\r
61\r
62 // Check if the PL111 is fitted on this motherboard\r
63 Status = PL111Indentify();\r
64 if (EFI_ERROR( Status )) {\r
65 return EFI_DEVICE_ERROR;\r
66 }\r
67\r
68 // Define start of the VRAM. This never changes for any graphics mode\r
69 MmioWrite32(PL111_REG_LCD_UP_BASE, (UINT32) VramBaseAddress);\r
70 MmioWrite32(PL111_REG_LCD_LP_BASE, 0); // We are not using a double buffer\r
71\r
72 // Disable all interrupts from the PL111\r
73 MmioWrite32(PL111_REG_LCD_IMSC, 0);\r
74\r
75 return EFI_SUCCESS;\r
76}\r
77\r
78EFI_STATUS\r
79LcdSetMode (\r
80 IN UINT32 ModeNumber\r
81 )\r
82{\r
83 EFI_STATUS Status;\r
84 UINT32 HRes;\r
85 UINT32 HSync;\r
86 UINT32 HBackPorch;\r
87 UINT32 HFrontPorch;\r
88 UINT32 VRes;\r
89 UINT32 VSync;\r
90 UINT32 VBackPorch;\r
91 UINT32 VFrontPorch;\r
92 UINT32 LcdControl;\r
93 LCD_BPP LcdBpp;\r
94\r
95 // Set the video mode timings and other relevant information\r
96 Status = LcdPlatformGetTimings (ModeNumber,\r
97 &HRes,&HSync,&HBackPorch,&HFrontPorch,\r
98 &VRes,&VSync,&VBackPorch,&VFrontPorch);\r
99 ASSERT_EFI_ERROR (Status);\r
100 if (EFI_ERROR( Status )) {\r
101 return EFI_DEVICE_ERROR;\r
102 }\r
103\r
104 Status = LcdPlatformGetBpp (ModeNumber,&LcdBpp);\r
105 ASSERT_EFI_ERROR (Status);\r
106 if (EFI_ERROR( Status )) {\r
107 return EFI_DEVICE_ERROR;\r
108 }\r
109\r
110 // Disable the CLCD_LcdEn bit\r
111 LcdControl = MmioRead32( PL111_REG_LCD_CONTROL);\r
112 MmioWrite32(PL111_REG_LCD_CONTROL, LcdControl & ~1);\r
113\r
114 // Set Timings\r
115 MmioWrite32 (PL111_REG_LCD_TIMING_0, HOR_AXIS_PANEL(HBackPorch, HFrontPorch, HSync, HRes));\r
116 MmioWrite32 (PL111_REG_LCD_TIMING_1, VER_AXIS_PANEL(VBackPorch, VFrontPorch, VSync, VRes));\r
117 MmioWrite32 (PL111_REG_LCD_TIMING_2, CLK_SIG_POLARITY(HRes));\r
118 MmioWrite32 (PL111_REG_LCD_TIMING_3, 0);\r
119\r
120 // PL111_REG_LCD_CONTROL\r
121 LcdControl = PL111_CTRL_LCD_EN | PL111_CTRL_LCD_BPP(LcdBpp) | PL111_CTRL_LCD_TFT | PL111_CTRL_BGR;\r
122 MmioWrite32(PL111_REG_LCD_CONTROL, LcdControl);\r
123\r
124 // Turn on power to the LCD Panel\r
125 LcdControl |= PL111_CTRL_LCD_PWR;\r
126 MmioWrite32(PL111_REG_LCD_CONTROL, LcdControl);\r
127\r
128 return EFI_SUCCESS;\r
129}\r
130\r
131VOID\r
132LcdShutdown (\r
133 VOID\r
134 )\r
135{\r
136 // Nothing to do in terms of hardware.\r
137 // We could switch off the monitor display if required\r
138\r
139 //TODO: ImplementMe\r
140}\r