summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg/ArmRealViewEbPkg/Library/PL111LcdArmRealViewEbLib/PL111LcdArmRealViewEb.c
blob: c4140150f8d34f5d23c995fdb55da4f3be55c6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/** @file

  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <PiDxe.h>

#include <Library/LcdPlatformLib.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>

#include <Drivers/PL111Lcd.h>

#include <ArmPlatform.h>

typedef struct {
  UINT32                     Mode;
  UINT32                     HorizontalResolution;
  UINT32                     VerticalResolution;
  LCD_BPP                    Bpp;
  UINT32                     ClcdClk;

  UINT32                     HSync;
  UINT32                     HBackPorch;
  UINT32                     HFrontPorch;
  UINT32                     VSync;
  UINT32                     VBackPorch;
  UINT32                     VFrontPorch;
} CLCD_RESOLUTION;


CLCD_RESOLUTION mResolutions[] = {
    { // Mode 0 : VGA : 640 x 480 x 24 bpp
        VGA, VGA_H_RES_PIXELS, VGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, 0x2C77,
        VGA_H_SYNC, VGA_H_BACK_PORCH, VGA_H_FRONT_PORCH,
        VGA_V_SYNC, VGA_V_BACK_PORCH, VGA_V_FRONT_PORCH
    },
    { // Mode 1 : SVGA : 800 x 600 x 24 bpp
        SVGA, SVGA_H_RES_PIXELS, SVGA_V_RES_PIXELS, LCD_BITS_PER_PIXEL_24, 0x2CAC,
        SVGA_H_SYNC, SVGA_H_BACK_PORCH, SVGA_H_FRONT_PORCH,
        SVGA_V_SYNC, SVGA_V_BACK_PORCH, SVGA_V_FRONT_PORCH
    }
};


EFI_STATUS
LcdPlatformInitializeDisplay (
  VOID
  )
{
  MmioWrite32(ARM_EB_SYS_CLCD_REG, 1);

  return EFI_SUCCESS;
}

EFI_STATUS
LcdPlatformGetVram (
  OUT EFI_PHYSICAL_ADDRESS*  VramBaseAddress,
  OUT UINTN*                 VramSize
  )
{
  *VramBaseAddress = PL111_CLCD_VRAM_BASE;
  *VramSize = SIZE_8MB; //FIXME: Can this size change ?
  return EFI_SUCCESS;
}

UINT32
LcdPlatformGetMaxMode (
  VOID
  )
{
  return (sizeof(mResolutions) / sizeof(CLCD_RESOLUTION));
}

EFI_STATUS
LcdPlatformSetMode (
  IN UINT32                         ModeNumber
  )
{
  if (ModeNumber >= LcdPlatformGetMaxMode ()) {
    return EFI_INVALID_PARAMETER;
  }

  MmioWrite32(ARM_EB_SYS_LOCK_REG,0x0000A05F);
  MmioWrite32(ARM_EB_SYS_OSC4_REG,mResolutions[ModeNumber].ClcdClk);
  MmioWrite32(ARM_EB_SYS_LOCK_REG,0x0);

  return EFI_SUCCESS;
}

EFI_STATUS
LcdPlatformQueryMode (
  IN  UINT32                                ModeNumber,
  OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION  *Info
  )
{
  EFI_STATUS    Status;

  if (ModeNumber >= LcdPlatformGetMaxMode ()) {
    return EFI_INVALID_PARAMETER;
  }

  Status = EFI_UNSUPPORTED;

  Info->Version = 0;
  Info->HorizontalResolution = mResolutions[ModeNumber].HorizontalResolution;
  Info->VerticalResolution = mResolutions[ModeNumber].VerticalResolution;
  Info->PixelsPerScanLine = mResolutions[ModeNumber].HorizontalResolution;

  switch (mResolutions[ModeNumber].Bpp) {
    case LCD_BITS_PER_PIXEL_24:
      Info->PixelFormat                   = PixelRedGreenBlueReserved8BitPerColor;
      Info->PixelInformation.RedMask      = LCD_24BPP_RED_MASK;
      Info->PixelInformation.GreenMask    = LCD_24BPP_GREEN_MASK;
      Info->PixelInformation.BlueMask     = LCD_24BPP_BLUE_MASK;
      Info->PixelInformation.ReservedMask = LCD_24BPP_RESERVED_MASK;
      Status = EFI_SUCCESS;
      break;

    case LCD_BITS_PER_PIXEL_16_555:
      Info->PixelFormat                   = PixelBitMask;
      Info->PixelInformation.RedMask      = LCD_16BPP_555_RED_MASK;
      Info->PixelInformation.GreenMask    = LCD_16BPP_555_GREEN_MASK;
      Info->PixelInformation.BlueMask     = LCD_16BPP_555_BLUE_MASK;
      Info->PixelInformation.ReservedMask = LCD_16BPP_555_RESERVED_MASK;
      Status = EFI_SUCCESS;
      break;

    case LCD_BITS_PER_PIXEL_16_565:
      Info->PixelFormat                   = PixelBitMask;
      Info->PixelInformation.RedMask      = LCD_16BPP_565_RED_MASK;
      Info->PixelInformation.GreenMask    = LCD_16BPP_565_GREEN_MASK;
      Info->PixelInformation.BlueMask     = LCD_16BPP_565_BLUE_MASK;
      Info->PixelInformation.ReservedMask = LCD_16BPP_565_RESERVED_MASK;
      Status = EFI_SUCCESS;
      break;

    case LCD_BITS_PER_PIXEL_12_444:
      Info->PixelFormat                   = PixelBitMask;
      Info->PixelInformation.RedMask      = LCD_12BPP_444_RED_MASK;
      Info->PixelInformation.GreenMask    = LCD_12BPP_444_GREEN_MASK;
      Info->PixelInformation.BlueMask     = LCD_12BPP_444_BLUE_MASK;
      Info->PixelInformation.ReservedMask = LCD_12BPP_444_RESERVED_MASK;
      Status = EFI_SUCCESS;
      break;

    case LCD_BITS_PER_PIXEL_8:
    case LCD_BITS_PER_PIXEL_4:
    case LCD_BITS_PER_PIXEL_2:
    case LCD_BITS_PER_PIXEL_1:
    default:
      // These are not supported
      break;
  }

  return Status;
}

EFI_STATUS
LcdPlatformGetTimings (
  IN  UINT32                              ModeNumber,
  OUT UINT32*                             HRes,
  OUT UINT32*                             HSync,
  OUT UINT32*                             HBackPorch,
  OUT UINT32*                             HFrontPorch,
  OUT UINT32*                             VRes,
  OUT UINT32*                             VSync,
  OUT UINT32*                             VBackPorch,
  OUT UINT32*                             VFrontPorch
  )
{
  if (ModeNumber >= LcdPlatformGetMaxMode ()) {
    return EFI_INVALID_PARAMETER;
  }

  *HRes           = mResolutions[ModeNumber].HorizontalResolution;
  *HSync          = mResolutions[ModeNumber].HSync;
  *HBackPorch     = mResolutions[ModeNumber].HBackPorch;
  *HFrontPorch    = mResolutions[ModeNumber].HFrontPorch;
  *VRes           = mResolutions[ModeNumber].VerticalResolution;
  *VSync          = mResolutions[ModeNumber].VSync;
  *VBackPorch     = mResolutions[ModeNumber].VBackPorch;
  *VFrontPorch    = mResolutions[ModeNumber].VFrontPorch;

  return EFI_SUCCESS;
}

EFI_STATUS
LcdPlatformGetBpp (
  IN  UINT32                              ModeNumber,
  OUT LCD_BPP  *                          Bpp
  )
{
  if (ModeNumber >= LcdPlatformGetMaxMode ()) {
    return EFI_INVALID_PARAMETER;
  }

  *Bpp = mResolutions[ModeNumber].Bpp;

  return EFI_SUCCESS;
}