2 Cirrus Logic 5430 Controller Driver
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
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
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.
16 // Cirrus Logic 5430 Controller Driver
19 #ifndef _CIRRUS_LOGIC_5430_H_
20 #define _CIRRUS_LOGIC_5430_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>
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/TimerLib.h>
43 #include <IndustryStandard/Pci.h>
45 // Cirrus Logic 5430 PCI Configuration Header values
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
53 // Cirrus Logic Graphical Mode Data
55 #define CIRRUS_LOGIC_5430_MODE_COUNT 3
59 UINT32 HorizontalResolution
;
60 UINT32 VerticalResolution
;
63 } CIRRUS_LOGIC_5430_MODE_DATA
;
65 #define PIXEL_RED_SHIFT 0
66 #define PIXEL_GREEN_SHIFT 3
67 #define PIXEL_BLUE_SHIFT 6
69 #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
70 #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
71 #define PIXEL_BLUE_MASK (BIT1 | BIT0)
73 #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
74 #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
75 #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
76 #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
78 #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
79 (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
80 (((Green) >> PIXEL_GREEN_SHIFT) & PIXEL_GREEN_MASK) | \
81 (((Blue) >> PIXEL_BLUE_SHIFT) & PIXEL_BLUE_MASK) )
83 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
86 // Cirrus Logic 5440 Private Data Structure
88 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('C', 'L', '5', '4')
93 EFI_PCI_IO_PROTOCOL
*PciIo
;
94 UINT64 OriginalPciAttributes
;
95 EFI_UGA_DRAW_PROTOCOL UgaDraw
;
96 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
97 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered
;
98 EFI_EDID_ACTIVE_PROTOCOL EdidActive
;
99 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
100 EFI_DEVICE_PATH_PROTOCOL
*UgaDevicePath
;
103 CIRRUS_LOGIC_5430_MODE_DATA ModeData
[CIRRUS_LOGIC_5430_MODE_COUNT
];
105 BOOLEAN HardwareNeedsStarting
;
106 } CIRRUS_LOGIC_5430_PRIVATE_DATA
;
109 /// Video Mode structure
119 } CIRRUS_LOGIC_5430_VIDEO_MODES
;
121 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS(a) \
122 CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, UgaDraw, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
124 #define CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
125 CR(a, CIRRUS_LOGIC_5430_PRIVATE_DATA, GraphicsOutput, CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE)
131 extern UINT8 AttributeController
[];
132 extern UINT8 GraphicsController
[];
133 extern UINT8 Crtc_640_480_256_60
[];
134 extern UINT16 Seq_640_480_256_60
[];
135 extern UINT8 Crtc_800_600_256_60
[];
136 extern UINT16 Seq_800_600_256_60
[];
137 extern UINT8 Crtc_1024_768_256_60
[];
138 extern UINT16 Seq_1024_768_256_60
[];
139 extern CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes
[];
140 extern EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding
;
141 extern EFI_COMPONENT_NAME_PROTOCOL gCirrusLogic5430ComponentName
;
142 extern EFI_COMPONENT_NAME2_PROTOCOL gCirrusLogic5430ComponentName2
;
143 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gCirrusLogic5430DriverSupportedEfiVersion
;
146 // Io Registers defined by VGA
148 #define CRTC_ADDRESS_REGISTER 0x3d4
149 #define CRTC_DATA_REGISTER 0x3d5
150 #define SEQ_ADDRESS_REGISTER 0x3c4
151 #define SEQ_DATA_REGISTER 0x3c5
152 #define GRAPH_ADDRESS_REGISTER 0x3ce
153 #define GRAPH_DATA_REGISTER 0x3cf
154 #define ATT_ADDRESS_REGISTER 0x3c0
155 #define MISC_OUTPUT_REGISTER 0x3c2
156 #define INPUT_STATUS_1_REGISTER 0x3da
157 #define DAC_PIXEL_MASK_REGISTER 0x3c6
158 #define PALETTE_INDEX_REGISTER 0x3c8
159 #define PALETTE_DATA_REGISTER 0x3c9
162 // UGA Draw Hardware abstraction internal worker functions
165 CirrusLogic5430UgaDrawConstructor (
166 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
170 CirrusLogic5430UgaDrawDestructor (
171 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
175 // Graphics Output Hardware abstraction internal worker functions
178 CirrusLogic5430GraphicsOutputConstructor (
179 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
183 CirrusLogic5430GraphicsOutputDestructor (
184 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
189 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
192 TODO: Add function description
194 @param This TODO: add argument description
195 @param Controller TODO: add argument description
196 @param RemainingDevicePath TODO: add argument description
198 TODO: add return values
203 CirrusLogic5430ControllerDriverSupported (
204 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
205 IN EFI_HANDLE Controller
,
206 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
210 TODO: Add function description
212 @param This TODO: add argument description
213 @param Controller TODO: add argument description
214 @param RemainingDevicePath TODO: add argument description
216 TODO: add return values
221 CirrusLogic5430ControllerDriverStart (
222 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
223 IN EFI_HANDLE Controller
,
224 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
228 TODO: Add function description
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
235 TODO: add return values
240 CirrusLogic5430ControllerDriverStop (
241 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
242 IN EFI_HANDLE Controller
,
243 IN UINTN NumberOfChildren
,
244 IN EFI_HANDLE
*ChildHandleBuffer
248 // EFI Component Name Functions
251 Retrieves a Unicode string that is the user readable name of the driver.
253 This function retrieves the user readable name of a driver in the form of a
254 Unicode string. If the driver specified by This has a user readable name in
255 the language specified by Language, then a pointer to the driver name is
256 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
257 by This does not support the language specified by Language,
258 then EFI_UNSUPPORTED is returned.
260 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
261 EFI_COMPONENT_NAME_PROTOCOL instance.
263 @param Language[in] A pointer to a Null-terminated ASCII string
264 array indicating the language. This is the
265 language of the driver name that the caller is
266 requesting, and it must match one of the
267 languages specified in SupportedLanguages. The
268 number of languages supported by a driver is up
269 to the driver writer. Language is specified
270 in RFC 4646 or ISO 639-2 language code format.
272 @param DriverName[out] A pointer to the Unicode string to return.
273 This Unicode string is the name of the
274 driver specified by This in the language
275 specified by Language.
277 @retval EFI_SUCCESS The Unicode string for the Driver specified by
278 This and the language specified by Language was
279 returned in DriverName.
281 @retval EFI_INVALID_PARAMETER Language is NULL.
283 @retval EFI_INVALID_PARAMETER DriverName is NULL.
285 @retval EFI_UNSUPPORTED The driver specified by This does not support
286 the language specified by Language.
291 CirrusLogic5430ComponentNameGetDriverName (
292 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
294 OUT CHAR16
**DriverName
299 Retrieves a Unicode string that is the user readable name of the controller
300 that is being managed by a driver.
302 This function retrieves the user readable name of the controller specified by
303 ControllerHandle and ChildHandle in the form of a Unicode string. If the
304 driver specified by This has a user readable name in the language specified by
305 Language, then a pointer to the controller name is returned in ControllerName,
306 and EFI_SUCCESS is returned. If the driver specified by This is not currently
307 managing the controller specified by ControllerHandle and ChildHandle,
308 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
309 support the language specified by Language, then EFI_UNSUPPORTED is returned.
311 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
312 EFI_COMPONENT_NAME_PROTOCOL instance.
314 @param ControllerHandle[in] The handle of a controller that the driver
315 specified by This is managing. This handle
316 specifies the controller whose name is to be
319 @param ChildHandle[in] The handle of the child controller to retrieve
320 the name of. This is an optional parameter that
321 may be NULL. It will be NULL for device
322 drivers. It will also be NULL for a bus drivers
323 that wish to retrieve the name of the bus
324 controller. It will not be NULL for a bus
325 driver that wishes to retrieve the name of a
328 @param Language[in] A pointer to a Null-terminated ASCII string
329 array indicating the language. This is the
330 language of the driver name that the caller is
331 requesting, and it must match one of the
332 languages specified in SupportedLanguages. The
333 number of languages supported by a driver is up
334 to the driver writer. Language is specified in
335 RFC 4646 or ISO 639-2 language code format.
337 @param ControllerName[out] A pointer to the Unicode string to return.
338 This Unicode string is the name of the
339 controller specified by ControllerHandle and
340 ChildHandle in the language specified by
341 Language from the point of view of the driver
344 @retval EFI_SUCCESS The Unicode string for the user readable name in
345 the language specified by Language for the
346 driver specified by This was returned in
349 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
351 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
354 @retval EFI_INVALID_PARAMETER Language is NULL.
356 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
358 @retval EFI_UNSUPPORTED The driver specified by This is not currently
359 managing the controller specified by
360 ControllerHandle and ChildHandle.
362 @retval EFI_UNSUPPORTED The driver specified by This does not support
363 the language specified by Language.
368 CirrusLogic5430ComponentNameGetControllerName (
369 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
370 IN EFI_HANDLE ControllerHandle
,
371 IN EFI_HANDLE ChildHandle OPTIONAL
,
373 OUT CHAR16
**ControllerName
378 // Local Function Prototypes
381 InitializeGraphicsMode (
382 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
383 CIRRUS_LOGIC_5430_VIDEO_MODES
*ModeData
388 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
397 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
402 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
409 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
416 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
423 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
429 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
,
434 CirrusLogic5430VideoModeSetup (
435 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private