]> git.proxmox.com Git - mirror_edk2.git/blob - OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.h
f7d92821aa0d043c6cfe4750f5221abf07bc308c
[mirror_edk2.git] / OptionRomPkg / CirrusLogic5430Dxe / CirrusLogic5430.h
1 /** @file
2 Cirrus Logic 5430 Controller Driver
3
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. 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 //
16 // Cirrus Logic 5430 Controller Driver
17 //
18
19 #ifndef _CIRRUS_LOGIC_5430_H_
20 #define _CIRRUS_LOGIC_5430_H_
21
22
23 #include <Uefi.h>
24 #include <Protocol/UgaDraw.h>
25 #include <Protocol/GraphicsOutput.h>
26 #include <Protocol/PciIo.h>
27 #include <Protocol/DriverSupportedEfiVersion.h>
28 #include <Protocol/EdidOverride.h>
29 #include <Protocol/EdidDiscovered.h>
30 #include <Protocol/EdidActive.h>
31 #include <Protocol/DevicePath.h>
32
33 #include <Library/DebugLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiLib.h>
36 #include <Library/PcdLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/DevicePathLib.h>
41 #include <Library/DxeI2cLib.h>
42
43 #include <IndustryStandard/pci22.h>
44 //
45 // Cirrus Logic 5430 PCI Configuration Header values
46 //
47 #define CIRRUS_LOGIC_VENDOR_ID 0x1013
48 #define CIRRUS_LOGIC_5430_DEVICE_ID 0x00a8
49 #define CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID 0x00a0
50 #define CIRRUS_LOGIC_5446_DEVICE_ID 0x00b8
51
52 //
53 // Cirrus Logic Graphical Mode Data
54 //
55 #define CIRRUS_LOGIC_5430_MODE_COUNT 3
56
57 typedef struct {
58 UINT32 ModeNumber;
59 UINT32 HorizontalResolution;
60 UINT32 VerticalResolution;
61 UINT32 ColorDepth;
62 UINT32 RefreshRate;
63 } CIRRUS_LOGIC_5430_MODE_DATA;
64
65 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
66
67 //
68 // Cirrus Logic 5440 Private Data Structure
69 //
70 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('C', 'L', '5', '4')
71
72 typedef struct {
73 UINT64 Signature;
74 EFI_HANDLE Handle;
75 EFI_PCI_IO_PROTOCOL *PciIo;
76 UINT64 OriginalPciAttributes;
77 EFI_UGA_DRAW_PROTOCOL UgaDraw;
78 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
79 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
80 EFI_EDID_ACTIVE_PROTOCOL EdidActive;
81 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
82 EFI_DEVICE_PATH_PROTOCOL *UgaDevicePath;
83 UINTN CurrentMode;
84 UINTN MaxMode;
85 CIRRUS_LOGIC_5430_MODE_DATA ModeData[CIRRUS_LOGIC_5430_MODE_COUNT];
86 UINT8 *LineBuffer;
87 BOOLEAN HardwareNeedsStarting;
88 } CIRRUS_LOGIC_5430_PRIVATE_DATA;
89
90 ///
91 /// Video Mode structure
92 ///
93 typedef struct {
94 UINT32 Width;
95 UINT32 Height;
96 UINT32 ColorDepth;
97 UINT32 RefreshRate;
98 UINT8 *CrtcSettings;
99 UINT16 *SeqSettings;
100 UINT8 MiscSetting;
101 } CIRRUS_LOGIC_5430_VIDEO_MODES;
102
103 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS(a) \
104 CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, UgaDraw, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
105
106 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
107 CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, GraphicsOutput, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
108
109
110 //
111 // Global Variables
112 //
113 extern UINT8 AttributeController[];
114 extern UINT8 GraphicsController[];
115 extern UINT8 Crtc_640_480_256_60[];
116 extern UINT16 Seq_640_480_256_60[];
117 extern UINT8 Crtc_800_600_256_60[];
118 extern UINT16 Seq_800_600_256_60[];
119 extern UINT8 Crtc_1024_768_256_60[];
120 extern UINT16 Seq_1024_768_256_60[];
121 extern CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[];
122 extern EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding;
123 extern EFI_COMPONENT_NAME_PROTOCOL gCirrusLogic5430ComponentName;
124 extern EFI_COMPONENT_NAME2_PROTOCOL gCirrusLogic5430ComponentName2;
125 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gCirrusLogic5430DriverSupportedEfiVersion;
126
127 //
128 // Io Registers defined by VGA
129 //
130 #define CRTC_ADDRESS_REGISTER 0x3d4
131 #define CRTC_DATA_REGISTER 0x3d5
132 #define SEQ_ADDRESS_REGISTER 0x3c4
133 #define SEQ_DATA_REGISTER 0x3c5
134 #define GRAPH_ADDRESS_REGISTER 0x3ce
135 #define GRAPH_DATA_REGISTER 0x3cf
136 #define ATT_ADDRESS_REGISTER 0x3c0
137 #define MISC_OUTPUT_REGISTER 0x3c2
138 #define INPUT_STATUS_1_REGISTER 0x3da
139 #define DAC_PIXEL_MASK_REGISTER 0x3c6
140 #define PALETTE_INDEX_REGISTER 0x3c8
141 #define PALETTE_DATA_REGISTER 0x3c9
142
143 #define ACPI_ADR_DISPLAY_TYPE_VGA 1
144
145 #define ACPI_DISPLAY_ADR(_DeviceIdScheme, _HeadId, _NonVgaOutput, _BiosCanDetect, _VendorInfo, _Type, _Port, _Index) \
146 ((UINT32) ( (((_DeviceIdScheme) & 0x1) << 31) | \
147 (((_HeadId) & 0x7) << 18) | \
148 (((_NonVgaOutput) & 0x1) << 17) | \
149 (((_BiosCanDetect) & 0x1) << 16) | \
150 (((_VendorInfo) & 0xf) << 12) | \
151 (((_Type) & 0xf) << 8) | \
152 (((_Port) & 0xf) << 4) | \
153 ((_Index) & 0xf) ))
154
155 //
156 // UGA Draw Hardware abstraction internal worker functions
157 //
158 EFI_STATUS
159 CirrusLogic5430UgaDrawConstructor (
160 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
161 )
162 ;
163
164 EFI_STATUS
165 CirrusLogic5430UgaDrawDestructor (
166 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
167 )
168 ;
169
170 //
171 // Graphics Output Hardware abstraction internal worker functions
172 //
173 EFI_STATUS
174 CirrusLogic5430GraphicsOutputConstructor (
175 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
176 )
177 ;
178
179 EFI_STATUS
180 CirrusLogic5430GraphicsOutputDestructor (
181 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
182 )
183 ;
184
185
186 //
187 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
188 //
189 /**
190 TODO: Add function description
191
192 @param This TODO: add argument description
193 @param Controller TODO: add argument description
194 @param RemainingDevicePath TODO: add argument description
195
196 TODO: add return values
197
198 **/
199 EFI_STATUS
200 EFIAPI
201 CirrusLogic5430ControllerDriverSupported (
202 IN EFI_DRIVER_BINDING_PROTOCOL *This,
203 IN EFI_HANDLE Controller,
204 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
205 )
206 ;
207
208 /**
209 TODO: Add function description
210
211 @param This TODO: add argument description
212 @param Controller TODO: add argument description
213 @param RemainingDevicePath TODO: add argument description
214
215 TODO: add return values
216
217 **/
218 EFI_STATUS
219 EFIAPI
220 CirrusLogic5430ControllerDriverStart (
221 IN EFI_DRIVER_BINDING_PROTOCOL *This,
222 IN EFI_HANDLE Controller,
223 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
224 )
225 ;
226
227 /**
228 TODO: Add function description
229
230 @param This TODO: add argument description
231 @param Controller TODO: add argument description
232 @param NumberOfChildren TODO: add argument description
233 @param ChildHandleBuffer TODO: add argument description
234
235 TODO: add return values
236
237 **/
238 EFI_STATUS
239 EFIAPI
240 CirrusLogic5430ControllerDriverStop (
241 IN EFI_DRIVER_BINDING_PROTOCOL *This,
242 IN EFI_HANDLE Controller,
243 IN UINTN NumberOfChildren,
244 IN EFI_HANDLE *ChildHandleBuffer
245 )
246 ;
247
248 //
249 // EFI Component Name Functions
250 //
251 /**
252 Retrieves a Unicode string that is the user readable name of the driver.
253
254 This function retrieves the user readable name of a driver in the form of a
255 Unicode string. If the driver specified by This has a user readable name in
256 the language specified by Language, then a pointer to the driver name is
257 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
258 by This does not support the language specified by Language,
259 then EFI_UNSUPPORTED is returned.
260
261 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
262 EFI_COMPONENT_NAME_PROTOCOL instance.
263
264 @param Language[in] A pointer to a Null-terminated ASCII string
265 array indicating the language. This is the
266 language of the driver name that the caller is
267 requesting, and it must match one of the
268 languages specified in SupportedLanguages. The
269 number of languages supported by a driver is up
270 to the driver writer. Language is specified
271 in RFC 3066 or ISO 639-2 language code format.
272
273 @param DriverName[out] A pointer to the Unicode string to return.
274 This Unicode string is the name of the
275 driver specified by This in the language
276 specified by Language.
277
278 @retval EFI_SUCCESS The Unicode string for the Driver specified by
279 This and the language specified by Language was
280 returned in DriverName.
281
282 @retval EFI_INVALID_PARAMETER Language is NULL.
283
284 @retval EFI_INVALID_PARAMETER DriverName is NULL.
285
286 @retval EFI_UNSUPPORTED The driver specified by This does not support
287 the language specified by Language.
288
289 **/
290 EFI_STATUS
291 EFIAPI
292 CirrusLogic5430ComponentNameGetDriverName (
293 IN EFI_COMPONENT_NAME_PROTOCOL *This,
294 IN CHAR8 *Language,
295 OUT CHAR16 **DriverName
296 );
297
298
299 /**
300 Retrieves a Unicode string that is the user readable name of the controller
301 that is being managed by a driver.
302
303 This function retrieves the user readable name of the controller specified by
304 ControllerHandle and ChildHandle in the form of a Unicode string. If the
305 driver specified by This has a user readable name in the language specified by
306 Language, then a pointer to the controller name is returned in ControllerName,
307 and EFI_SUCCESS is returned. If the driver specified by This is not currently
308 managing the controller specified by ControllerHandle and ChildHandle,
309 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
310 support the language specified by Language, then EFI_UNSUPPORTED is returned.
311
312 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
313 EFI_COMPONENT_NAME_PROTOCOL instance.
314
315 @param ControllerHandle[in] The handle of a controller that the driver
316 specified by This is managing. This handle
317 specifies the controller whose name is to be
318 returned.
319
320 @param ChildHandle[in] The handle of the child controller to retrieve
321 the name of. This is an optional parameter that
322 may be NULL. It will be NULL for device
323 drivers. It will also be NULL for a bus drivers
324 that wish to retrieve the name of the bus
325 controller. It will not be NULL for a bus
326 driver that wishes to retrieve the name of a
327 child controller.
328
329 @param Language[in] A pointer to a Null-terminated ASCII string
330 array indicating the language. This is the
331 language of the driver name that the caller is
332 requesting, and it must match one of the
333 languages specified in SupportedLanguages. The
334 number of languages supported by a driver is up
335 to the driver writer. Language is specified in
336 RFC 3066 or ISO 639-2 language code format.
337
338 @param ControllerName[out] A pointer to the Unicode string to return.
339 This Unicode string is the name of the
340 controller specified by ControllerHandle and
341 ChildHandle in the language specified by
342 Language from the point of view of the driver
343 specified by This.
344
345 @retval EFI_SUCCESS The Unicode string for the user readable name in
346 the language specified by Language for the
347 driver specified by This was returned in
348 DriverName.
349
350 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
351
352 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
353 EFI_HANDLE.
354
355 @retval EFI_INVALID_PARAMETER Language is NULL.
356
357 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
358
359 @retval EFI_UNSUPPORTED The driver specified by This is not currently
360 managing the controller specified by
361 ControllerHandle and ChildHandle.
362
363 @retval EFI_UNSUPPORTED The driver specified by This does not support
364 the language specified by Language.
365
366 **/
367 EFI_STATUS
368 EFIAPI
369 CirrusLogic5430ComponentNameGetControllerName (
370 IN EFI_COMPONENT_NAME_PROTOCOL *This,
371 IN EFI_HANDLE ControllerHandle,
372 IN EFI_HANDLE ChildHandle OPTIONAL,
373 IN CHAR8 *Language,
374 OUT CHAR16 **ControllerName
375 );
376
377
378 //
379 // Local Function Prototypes
380 //
381 VOID
382 InitializeGraphicsMode (
383 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
384 CIRRUS_LOGIC_5430_VIDEO_MODES *ModeData
385 );
386
387 VOID
388 SetPaletteColor (
389 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
390 UINTN Index,
391 UINT8 Red,
392 UINT8 Green,
393 UINT8 Blue
394 );
395
396 VOID
397 SetDefaultPalette (
398 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
399 );
400
401 VOID
402 DrawLogo (
403 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
404 UINTN ScreenWidth,
405 UINTN ScreenHeight
406 );
407
408 VOID
409 outb (
410 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
411 UINTN Address,
412 UINT8 Data
413 );
414
415 VOID
416 outw (
417 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
418 UINTN Address,
419 UINT16 Data
420 );
421
422 UINT8
423 inb (
424 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
425 UINTN Address
426 );
427
428 UINT16
429 inw (
430 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
431 UINTN Address
432 );
433
434 EFI_STATUS
435 CirrusLogic5430VideoModeSetup (
436 CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
437 );
438
439 #endif