2 Cirrus Logic 5430 Controller Driver
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 // Cirrus Logic 5430 Controller Driver
13 #ifndef _CIRRUS_LOGIC_5430_H_
14 #define _CIRRUS_LOGIC_5430_H_
18 #include <Protocol/UgaDraw.h>
19 #include <Protocol/GraphicsOutput.h>
20 #include <Protocol/PciIo.h>
21 #include <Protocol/DriverSupportedEfiVersion.h>
22 #include <Protocol/EdidOverride.h>
23 #include <Protocol/EdidDiscovered.h>
24 #include <Protocol/EdidActive.h>
25 #include <Protocol/DevicePath.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiLib.h>
30 #include <Library/PcdLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/TimerLib.h>
37 #include <IndustryStandard/Pci.h>
39 // Cirrus Logic 5430 PCI Configuration Header values
41 #define CIRRUS_LOGIC_VENDOR_ID 0x1013
42 #define CIRRUS_LOGIC_5430_DEVICE_ID 0x00a8
43 #define CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID 0x00a0
44 #define CIRRUS_LOGIC_5446_DEVICE_ID 0x00b8
47 // Cirrus Logic Graphical Mode Data
49 #define CIRRUS_LOGIC_5430_MODE_COUNT 3
53 UINT32 HorizontalResolution
;
54 UINT32 VerticalResolution
;
57 } CIRRUS_LOGIC_5430_MODE_DATA
;
59 #define PIXEL_RED_SHIFT 0
60 #define PIXEL_GREEN_SHIFT 3
61 #define PIXEL_BLUE_SHIFT 6
63 #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
64 #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
65 #define PIXEL_BLUE_MASK (BIT1 | BIT0)
67 #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
68 #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
69 #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
70 #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
72 #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
73 (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
74 (((Green) >> PIXEL_GREEN_SHIFT) & PIXEL_GREEN_MASK) | \
75 (((Blue) >> PIXEL_BLUE_SHIFT) & PIXEL_BLUE_MASK) )
77 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
80 // Cirrus Logic 5440 Private Data Structure
82 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('C', 'L', '5', '4')
87 EFI_PCI_IO_PROTOCOL
*PciIo
;
88 UINT64 OriginalPciAttributes
;
89 EFI_UGA_DRAW_PROTOCOL UgaDraw
;
90 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
91 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
92 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
93 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
94 EFI_DEVICE_PATH_PROTOCOL
*UgaDevicePath
;
97 CIRRUS_LOGIC_5430_MODE_DATA ModeData
[CIRRUS_LOGIC_5430_MODE_COUNT
];
99 BOOLEAN HardwareNeedsStarting
;
100 } CIRRUS_LOGIC_5430_PRIVATE_DATA
;
103 /// Video Mode structure
113 } CIRRUS_LOGIC_5430_VIDEO_MODES
;
115 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS(a) \
116 CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, UgaDraw, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
118 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
119 CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, GraphicsOutput, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
125 extern UINT8 AttributeController
[];
126 extern UINT8 GraphicsController
[];
127 extern UINT8 Crtc_640_480_256_60
[];
128 extern UINT16 Seq_640_480_256_60
[];
129 extern UINT8 Crtc_800_600_256_60
[];
130 extern UINT16 Seq_800_600_256_60
[];
131 extern UINT8 Crtc_1024_768_256_60
[];
132 extern UINT16 Seq_1024_768_256_60
[];
133 extern CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes
[];
134 extern EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding
;
135 extern EFI_COMPONENT_NAME_PROTOCOL gCirrusLogic5430ComponentName
;
136 extern EFI_COMPONENT_NAME2_PROTOCOL gCirrusLogic5430ComponentName2
;
137 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gCirrusLogic5430DriverSupportedEfiVersion
;
140 // Io Registers defined by VGA
142 #define CRTC_ADDRESS_REGISTER 0x3d4
143 #define CRTC_DATA_REGISTER 0x3d5
144 #define SEQ_ADDRESS_REGISTER 0x3c4
145 #define SEQ_DATA_REGISTER 0x3c5
146 #define GRAPH_ADDRESS_REGISTER 0x3ce
147 #define GRAPH_DATA_REGISTER 0x3cf
148 #define ATT_ADDRESS_REGISTER 0x3c0
149 #define MISC_OUTPUT_REGISTER 0x3c2
150 #define INPUT_STATUS_1_REGISTER 0x3da
151 #define DAC_PIXEL_MASK_REGISTER 0x3c6
152 #define PALETTE_INDEX_REGISTER 0x3c8
153 #define PALETTE_DATA_REGISTER 0x3c9
156 // UGA Draw Hardware abstraction internal worker functions
159 CirrusLogic5430UgaDrawConstructor (
160 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
164 CirrusLogic5430UgaDrawDestructor (
165 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
169 // Graphics Output Hardware abstraction internal worker functions
172 CirrusLogic5430GraphicsOutputConstructor (
173 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
177 CirrusLogic5430GraphicsOutputDestructor (
178 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
183 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
186 TODO: Add function description
188 @param This TODO: add argument description
189 @param Controller TODO: add argument description
190 @param RemainingDevicePath TODO: add argument description
192 TODO: add return values
197 CirrusLogic5430ControllerDriverSupported (
198 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
199 IN EFI_HANDLE Controller
,
200 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
204 TODO: Add function description
206 @param This TODO: add argument description
207 @param Controller TODO: add argument description
208 @param RemainingDevicePath TODO: add argument description
210 TODO: add return values
215 CirrusLogic5430ControllerDriverStart (
216 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
217 IN EFI_HANDLE Controller
,
218 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
222 TODO: Add function description
224 @param This TODO: add argument description
225 @param Controller TODO: add argument description
226 @param NumberOfChildren TODO: add argument description
227 @param ChildHandleBuffer TODO: add argument description
229 TODO: add return values
234 CirrusLogic5430ControllerDriverStop (
235 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
236 IN EFI_HANDLE Controller
,
237 IN UINTN NumberOfChildren
,
238 IN EFI_HANDLE
*ChildHandleBuffer
242 // EFI Component Name Functions
245 Retrieves a Unicode string that is the user readable name of the driver.
247 This function retrieves the user readable name of a driver in the form of a
248 Unicode string. If the driver specified by This has a user readable name in
249 the language specified by Language, then a pointer to the driver name is
250 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
251 by This does not support the language specified by Language,
252 then EFI_UNSUPPORTED is returned.
254 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
255 EFI_COMPONENT_NAME_PROTOCOL instance.
257 @param Language[in] A pointer to a Null-terminated ASCII string
258 array indicating the language. This is the
259 language of the driver name that the caller is
260 requesting, and it must match one of the
261 languages specified in SupportedLanguages. The
262 number of languages supported by a driver is up
263 to the driver writer. Language is specified
264 in RFC 4646 or ISO 639-2 language code format.
266 @param DriverName[out] A pointer to the Unicode string to return.
267 This Unicode string is the name of the
268 driver specified by This in the language
269 specified by Language.
271 @retval EFI_SUCCESS The Unicode string for the Driver specified by
272 This and the language specified by Language was
273 returned in DriverName.
275 @retval EFI_INVALID_PARAMETER Language is NULL.
277 @retval EFI_INVALID_PARAMETER DriverName is NULL.
279 @retval EFI_UNSUPPORTED The driver specified by This does not support
280 the language specified by Language.
285 CirrusLogic5430ComponentNameGetDriverName (
286 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
288 OUT CHAR16
**DriverName
293 Retrieves a Unicode string that is the user readable name of the controller
294 that is being managed by a driver.
296 This function retrieves the user readable name of the controller specified by
297 ControllerHandle and ChildHandle in the form of a Unicode string. If the
298 driver specified by This has a user readable name in the language specified by
299 Language, then a pointer to the controller name is returned in ControllerName,
300 and EFI_SUCCESS is returned. If the driver specified by This is not currently
301 managing the controller specified by ControllerHandle and ChildHandle,
302 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
303 support the language specified by Language, then EFI_UNSUPPORTED is returned.
305 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
306 EFI_COMPONENT_NAME_PROTOCOL instance.
308 @param ControllerHandle[in] The handle of a controller that the driver
309 specified by This is managing. This handle
310 specifies the controller whose name is to be
313 @param ChildHandle[in] The handle of the child controller to retrieve
314 the name of. This is an optional parameter that
315 may be NULL. It will be NULL for device
316 drivers. It will also be NULL for a bus drivers
317 that wish to retrieve the name of the bus
318 controller. It will not be NULL for a bus
319 driver that wishes to retrieve the name of a
322 @param Language[in] A pointer to a Null-terminated ASCII string
323 array indicating the language. This is the
324 language of the driver name that the caller is
325 requesting, and it must match one of the
326 languages specified in SupportedLanguages. The
327 number of languages supported by a driver is up
328 to the driver writer. Language is specified in
329 RFC 4646 or ISO 639-2 language code format.
331 @param ControllerName[out] A pointer to the Unicode string to return.
332 This Unicode string is the name of the
333 controller specified by ControllerHandle and
334 ChildHandle in the language specified by
335 Language from the point of view of the driver
338 @retval EFI_SUCCESS The Unicode string for the user readable name in
339 the language specified by Language for the
340 driver specified by This was returned in
343 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
345 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
348 @retval EFI_INVALID_PARAMETER Language is NULL.
350 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
352 @retval EFI_UNSUPPORTED The driver specified by This is not currently
353 managing the controller specified by
354 ControllerHandle and ChildHandle.
356 @retval EFI_UNSUPPORTED The driver specified by This does not support
357 the language specified by Language.
362 CirrusLogic5430ComponentNameGetControllerName (
363 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
364 IN EFI_HANDLE ControllerHandle
,
365 IN EFI_HANDLE ChildHandle OPTIONAL
,
367 OUT CHAR16
**ControllerName
372 // Local Function Prototypes
375 InitializeGraphicsMode (
376 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
377 CIRRUS_LOGIC_5430_VIDEO_MODES
*ModeData
382 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
391 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
396 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
403 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
410 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
417 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
423 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
428 CirrusLogic5430VideoModeSetup (
429 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private