diff options
author | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-01-03 06:44:03 +0000 |
---|---|---|
committer | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-01-03 06:44:03 +0000 |
commit | 31f9e631176ef02829edcb537ec5caf04026c3f2 (patch) | |
tree | a9dadefcb240ef2830e33edbb1e4fdc29ebf9049 | |
parent | b7bef2a9fb22c891eb2a8284132bf67574d82839 (diff) | |
download | edk2-platforms-31f9e631176ef02829edcb537ec5caf04026c3f2.tar.xz |
1. add DxeI2c Library in OptionRomPkg.
2. produce EFI_EDID_DISCOVERED_PROTOCOL and EFI_EDID_ACTIVE_PROTOCOL in CirrusLogic5430 module.
3. consume EFI_OVERRIDE_PROTOCOL in CirrusLogic5430 module.
4. setup video mode according to EDID information in CirrusLogic5430 module.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4479 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r-- | OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.c | 123 | ||||
-rw-r--r-- | OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.h | 31 | ||||
-rw-r--r-- | OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf | 16 | ||||
-rw-r--r-- | OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430GraphicsOutput.c | 38 | ||||
-rw-r--r-- | OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430UgaDraw.c | 31 | ||||
-rw-r--r-- | OptionRomPkg/CirrusLogic5430Dxe/Edid.c | 531 | ||||
-rw-r--r-- | OptionRomPkg/Include/Library/DxeI2cLib.h | 64 | ||||
-rw-r--r-- | OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.c | 447 | ||||
-rw-r--r-- | OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.inf | 45 | ||||
-rw-r--r-- | OptionRomPkg/OptionRomPkg.dec | 10 | ||||
-rw-r--r-- | OptionRomPkg/OptionRomPkg.dsc | 10 |
11 files changed, 1255 insertions, 91 deletions
diff --git a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.c b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.c index 424e19df1e..1507b55ee7 100644 --- a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.c +++ b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.c @@ -106,6 +106,7 @@ CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = { { 1024, 768, 8, 60, Crtc_1024_768_256_60, Seq_1024_768_256_60, 0xef }
};
+
/**
CirrusLogic5430ControllerDriverSupported
@@ -212,6 +213,8 @@ CirrusLogic5430ControllerDriverStart ( EFI_STATUS Status;
CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;
BOOLEAN PciAttributesSaved;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ ACPI_ADR_DEVICE_PATH AcpiDeviceNode;
PciAttributesSaved = FALSE;
//
@@ -227,7 +230,7 @@ CirrusLogic5430ControllerDriverStart ( // Set up context record
//
Private->Signature = CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE;
- Private->Handle = Controller;
+ Private->Handle = NULL;
//
// Open PCI I/O Protocol
@@ -269,52 +272,98 @@ CirrusLogic5430ControllerDriverStart ( goto Error;
}
+ //
+ // Get ParentDevicePath
+ //
+ Status = gBS->HandleProtocol (
+ Controller,
+ &gEfiDevicePathProtocolGuid,
+ (VOID **) &ParentDevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ if (FeaturePcdGet (PcdSupportGop)) {
+ //
+ // Set Gop Device Path
+ //
+ if (RemainingDevicePath == NULL) {
+ ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));
+ AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;
+ AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;
+ AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);
+ SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof (ACPI_ADR_DEVICE_PATH));
+
+ Private->GopDevicePath = AppendDevicePathNode (
+ ParentDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &AcpiDeviceNode
+ );
+ } else {
+ Private->GopDevicePath = AppendDevicePathNode (ParentDevicePath, RemainingDevicePath);
+ }
+
+ //
+ // Creat child handle and device path protocol firstly
+ //
+ Private->Handle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Private->Handle,
+ &gEfiDevicePathProtocolGuid,
+ Private->GopDevicePath,
+ NULL
+ );
+ }
+
+ //
+ // Construct video mode buffer
+ //
+ Status = CirrusLogic5430VideoModeSetup (Private);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
if (FeaturePcdGet (PcdSupportUga)) {
//
// Start the UGA Draw software stack.
//
Status = CirrusLogic5430UgaDrawConstructor (Private);
ASSERT_EFI_ERROR (Status);
- if (FeaturePcdGet (PcdSupportGop)) {
- Status = CirrusLogic5430GraphicsOutputConstructor (Private);
- ASSERT_EFI_ERROR (Status);
- Status = gBS->InstallMultipleProtocolInterfaces (
- &Private->Handle,
- &gEfiUgaDrawProtocolGuid,
- &Private->UgaDraw,
- &gEfiGraphicsOutputProtocolGuid,
- &Private->GraphicsOutput,
- NULL
- );
- } else {
- Status = gBS->InstallMultipleProtocolInterfaces (
- &Private->Handle,
- &gEfiUgaDrawProtocolGuid,
- &Private->UgaDraw,
- NULL
- );
+ Private->UgaDevicePath = ParentDevicePath;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Controller,
+ &gEfiUgaDrawProtocolGuid,
+ &Private->UgaDraw,
+ &gEfiDevicePathProtocolGuid,
+ Private->UgaDevicePath,
+ NULL
+ );
- }
- } else {
- if (FeaturePcdGet (PcdSupportGop)) {
- Status = CirrusLogic5430GraphicsOutputConstructor (Private);
- ASSERT_EFI_ERROR (Status);
+ } else if (FeaturePcdGet (PcdSupportGop)) {
+ //
+ // Start the GOP software stack.
+ //
+ Status = CirrusLogic5430GraphicsOutputConstructor (Private);
+ ASSERT_EFI_ERROR (Status);
- Status = gBS->InstallMultipleProtocolInterfaces (
- &Private->Handle,
- &gEfiGraphicsOutputProtocolGuid,
- &Private->GraphicsOutput,
- NULL
- );
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Private->Handle,
+ &gEfiGraphicsOutputProtocolGuid,
+ &Private->GraphicsOutput,
+ &gEfiEdidDiscoveredProtocolGuid,
+ &Private->EdidDiscovered,
+ &gEfiEdidActiveProtocolGuid,
+ &Private->EdidActive,
+ NULL
+ );
- } else {
- //
- // This driver must support eithor GOP or UGA or both.
- //
- ASSERT (FALSE);
- Status = EFI_UNSUPPORTED;
- }
+ } else {
+ //
+ // This driver must support eithor GOP or UGA or both.
+ //
+ ASSERT (FALSE);
+ Status = EFI_UNSUPPORTED;
}
diff --git a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.h b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.h index 719cf7c9cb..f7d92821aa 100644 --- a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.h +++ b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430.h @@ -1,7 +1,7 @@ /** @file
Cirrus Logic 5430 Controller Driver
- Copyright (c) 2006, Intel Corporation
+ Copyright (c) 2006 - 2007, Intel Corporation
All rights reserved. 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
@@ -25,6 +25,10 @@ #include <Protocol/GraphicsOutput.h>
#include <Protocol/PciIo.h>
#include <Protocol/DriverSupportedEfiVersion.h>
+#include <Protocol/EdidOverride.h>
+#include <Protocol/EdidDiscovered.h>
+#include <Protocol/EdidActive.h>
+#include <Protocol/DevicePath.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
@@ -32,6 +36,9 @@ #include <Library/PcdLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/DxeI2cLib.h>
#include <IndustryStandard/pci22.h>
//
@@ -48,6 +55,7 @@ #define CIRRUS_LOGIC_5430_MODE_COUNT 3
typedef struct {
+ UINT32 ModeNumber;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINT32 ColorDepth;
@@ -68,6 +76,10 @@ typedef struct { UINT64 OriginalPciAttributes;
EFI_UGA_DRAW_PROTOCOL UgaDraw;
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
+ EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
+ EFI_EDID_ACTIVE_PROTOCOL EdidActive;
+ EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *UgaDevicePath;
UINTN CurrentMode;
UINTN MaxMode;
CIRRUS_LOGIC_5430_MODE_DATA ModeData[CIRRUS_LOGIC_5430_MODE_COUNT];
@@ -128,6 +140,18 @@ extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gCirrusLogic5430DriverSupporte #define PALETTE_INDEX_REGISTER 0x3c8
#define PALETTE_DATA_REGISTER 0x3c9
+#define ACPI_ADR_DISPLAY_TYPE_VGA 1
+
+#define ACPI_DISPLAY_ADR(_DeviceIdScheme, _HeadId, _NonVgaOutput, _BiosCanDetect, _VendorInfo, _Type, _Port, _Index) \
+ ((UINT32) ( (((_DeviceIdScheme) & 0x1) << 31) | \
+ (((_HeadId) & 0x7) << 18) | \
+ (((_NonVgaOutput) & 0x1) << 17) | \
+ (((_BiosCanDetect) & 0x1) << 16) | \
+ (((_VendorInfo) & 0xf) << 12) | \
+ (((_Type) & 0xf) << 8) | \
+ (((_Port) & 0xf) << 4) | \
+ ((_Index) & 0xf) ))
+
//
// UGA Draw Hardware abstraction internal worker functions
//
@@ -407,4 +431,9 @@ inw ( UINTN Address
);
+EFI_STATUS
+CirrusLogic5430VideoModeSetup (
+ CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
+ );
+
#endif
diff --git a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf index 8749727e4d..dca2b1184f 100644 --- a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf +++ b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf @@ -37,8 +37,8 @@ #
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
-# DRIVER_BINDING = gCirrusLogic5430DriverBinding
-# COMPONENT_NAME = gCirrusLogic5430ComponentName
+# DRIVER_BINDING = gCirrusLogic5430DriverBinding
+# COMPONENT_NAME = gCirrusLogic5430ComponentName
#
[Sources.common]
@@ -48,6 +48,7 @@ CirrusLogic5430GraphicsOutput.c
CirrusLogic5430.c
CirrusLogic5430.h
+ Edid.c
[Packages]
MdePkg/MdePkg.dec
@@ -59,14 +60,21 @@ UefiLib
UefiDriverEntryPoint
DebugLib
-
+ BaseMemoryLib
+ DevicePathLib
+ DxeI2cLib
[Protocols]
gEfiDriverSupportedEfiVersionProtocolGuid # PROTOCOL ALWAYS_PRODUCED
gEfiUgaDrawProtocolGuid # PROTOCOL BY_START
gEfiGraphicsOutputProtocolGuid # PROTOCOL BY_START
+ gEfiEdidDiscoveredProtocolGuid # PROTOCOL BY_START
+ gEfiEdidActiveProtocolGuid # PROTOCOL BY_START
+ gEfiDevicePathProtocolGuid # PROTOCOL BY_START
gEfiPciIoProtocolGuid # PROTOCOL TO_START
-
+ gEfiEdidOverrideProtocolGuid # PROTOCOL TO_START
+
+
[FeaturePcd.common]
gOptionRomPkgTokenSpaceGuid.PcdSupportGop
gOptionRomPkgTokenSpaceGuid.PcdSupportUga
diff --git a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430GraphicsOutput.c b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430GraphicsOutput.c index 7fdb3e0f0a..b639edb4a8 100644 --- a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430GraphicsOutput.c +++ b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430GraphicsOutput.c @@ -1,13 +1,13 @@ /*++
-Copyright (c) 2007, Intel Corporation
-All rights reserved. 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.
+Copyright (c) 2007, Intel Corporation
+All rights reserved. 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.
Module Name:
@@ -15,8 +15,8 @@ Module Name: Abstract:
- This file produces the graphics abstration of Graphics Output Protocol. It is called by
- CirrusLogic5430.c file which deals with the EFI 1.1 driver model.
+ This file produces the graphics abstration of Graphics Output Protocol. It is called by
+ CirrusLogic5430.c file which deals with the EFI 1.1 driver model.
This file just does graphics.
--*/
@@ -127,7 +127,7 @@ Routine Description: return EFI_OUT_OF_RESOURCES;
}
- InitializeGraphicsMode (Private, &CirrusLogic5430VideoModes[ModeNumber]);
+ InitializeGraphicsMode (Private, &CirrusLogic5430VideoModes[ModeData->ModeNumber]);
This->Mode->Mode = ModeNumber;
This->Mode->Info->HorizontalResolution = ModeData->HorizontalResolution;
@@ -444,7 +444,6 @@ CirrusLogic5430GraphicsOutputConstructor ( {
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
- UINTN Index;
GraphicsOutput = &Private->GraphicsOutput;
@@ -471,17 +470,10 @@ CirrusLogic5430GraphicsOutputConstructor ( if (EFI_ERROR (Status)) {
return Status;
}
- Private->GraphicsOutput.Mode->MaxMode = CIRRUS_LOGIC_5430_MODE_COUNT;
- Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER;
- for (Index = 0; Index < Private->GraphicsOutput.Mode->MaxMode; Index++) {
- Private->ModeData[Index].HorizontalResolution = CirrusLogic5430VideoModes[Index].Width;
- Private->ModeData[Index].VerticalResolution = CirrusLogic5430VideoModes[Index].Height;
- Private->ModeData[Index].ColorDepth = 32;
- Private->ModeData[Index].RefreshRate = CirrusLogic5430VideoModes[Index].RefreshRate;
- }
-
- Private->HardwareNeedsStarting = TRUE;
- Private->LineBuffer = NULL;
+ Private->GraphicsOutput.Mode->MaxMode = (UINT32) Private->MaxMode;
+ Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER;
+ Private->HardwareNeedsStarting = TRUE;
+ Private->LineBuffer = NULL;
//
// Initialize the hardware
diff --git a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430UgaDraw.c b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430UgaDraw.c index 75b1d24c8a..59613fb5f0 100644 --- a/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430UgaDraw.c +++ b/OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430UgaDraw.c @@ -1,16 +1,16 @@ /** @file
- This file produces the graphics abstration of UGA Draw. It is called by
- CirrusLogic5430.c file which deals with the EFI 1.1 driver model.
+ This file produces the graphics abstration of UGA Draw. It is called by
+ CirrusLogic5430.c file which deals with the EFI 1.1 driver model.
This file just does graphics.
- Copyright (c) 2006, Intel Corporation
- All rights reserved. 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
+ Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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.
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
@@ -95,7 +95,7 @@ CirrusLogic5430UgaDrawSetMode ( return EFI_OUT_OF_RESOURCES;
}
- InitializeGraphicsMode (Private, &CirrusLogic5430VideoModes[Index]);
+ InitializeGraphicsMode (Private, &CirrusLogic5430VideoModes[Private->ModeData[Index].ModeNumber]);
Private->CurrentMode = Index;
@@ -380,7 +380,6 @@ CirrusLogic5430UgaDrawConstructor ( )
{
EFI_UGA_DRAW_PROTOCOL *UgaDraw;
- UINTN Index;
//
// Fill in Private->UgaDraw protocol
@@ -394,15 +393,7 @@ CirrusLogic5430UgaDrawConstructor ( //
// Initialize the private data
//
- Private->MaxMode = CIRRUS_LOGIC_5430_MODE_COUNT;
- Private->CurrentMode = 0;
- for (Index = 0; Index < Private->MaxMode; Index++) {
- Private->ModeData[Index].HorizontalResolution = CirrusLogic5430VideoModes[Index].Width;
- Private->ModeData[Index].VerticalResolution = CirrusLogic5430VideoModes[Index].Height;
- Private->ModeData[Index].ColorDepth = 32;
- Private->ModeData[Index].RefreshRate = CirrusLogic5430VideoModes[Index].RefreshRate;
- }
-
+ Private->CurrentMode = 0;
Private->HardwareNeedsStarting = TRUE;
Private->LineBuffer = NULL;
diff --git a/OptionRomPkg/CirrusLogic5430Dxe/Edid.c b/OptionRomPkg/CirrusLogic5430Dxe/Edid.c new file mode 100644 index 0000000000..4ef733b509 --- /dev/null +++ b/OptionRomPkg/CirrusLogic5430Dxe/Edid.c @@ -0,0 +1,531 @@ +/** @file
+ Read EDID information and parse EDID information.
+
+ Copyright (c) 2008, Intel Corporation
+ All rights reserved. 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 "CirrusLogic5430.h"
+
+//
+// EDID block
+//
+typedef struct {
+ UINT8 Header[8]; //EDID header "00 FF FF FF FF FF FF 00"
+ UINT16 ManufactureName; //EISA 3-character ID
+ UINT16 ProductCode; //Vendor assigned code
+ UINT32 SerialNumber; //32-bit serial number
+ UINT8 WeekOfManufacture; //Week number
+ UINT8 YearOfManufacture; //Year
+ UINT8 EdidVersion; //EDID Structure Version
+ UINT8 EdidRevision; //EDID Structure Revision
+ UINT8 VideoInputDefinition;
+ UINT8 MaxHorizontalImageSize; //cm
+ UINT8 MaxVerticalImageSize; //cm
+ UINT8 DisplayTransferCharacteristic;
+ UINT8 FeatureSupport;
+ UINT8 RedGreenLowBits; //Rx1 Rx0 Ry1 Ry0 Gx1 Gx0 Gy1Gy0
+ UINT8 BlueWhiteLowBits; //Bx1 Bx0 By1 By0 Wx1 Wx0 Wy1 Wy0
+ UINT8 RedX; //Red-x Bits 9 - 2
+ UINT8 RedY; //Red-y Bits 9 - 2
+ UINT8 GreenX; //Green-x Bits 9 - 2
+ UINT8 GreenY; //Green-y Bits 9 - 2
+ UINT8 BlueX; //Blue-x Bits 9 - 2
+ UINT8 BlueY; //Blue-y Bits 9 - 2
+ UINT8 WhiteX; //White-x Bits 9 - 2
+ UINT8 WhiteY; //White-x Bits 9 - 2
+ UINT8 EstablishedTimings[3];
+ UINT8 StandardTimingIdentification[16];
+ UINT8 DetailedTimingDescriptions[72];
+ UINT8 ExtensionFlag; //Number of (optional) 128-byte EDID extension blocks to follow
+ UINT8 Checksum;
+} EDID_BLOCK;
+
+#define EDID_BLOCK_SIZE 128
+#define VBE_EDID_ESTABLISHED_TIMING_MAX_NUMBER 17
+
+typedef struct {
+ UINT16 HorizontalResolution;
+ UINT16 VerticalResolution;
+ UINT16 RefreshRate;
+} EDID_TIMING;
+
+typedef struct {
+ UINT32 ValidNumber;
+ UINT32 Key[VBE_EDID_ESTABLISHED_TIMING_MAX_NUMBER];
+} VALID_EDID_TIMING;
+
+//
+// Standard timing defined by VESA EDID
+//
+EDID_TIMING mVbeEstablishedEdidTiming[] = {
+ //
+ // Established Timing I
+ //
+ {800, 600, 60},
+ {800, 600, 56},
+ {640, 480, 75},
+ {640, 480, 72},
+ {640, 480, 67},
+ {640, 480, 60},
+ {720, 400, 88},
+ {720, 400, 70},
+ //
+ // Established Timing II
+ //
+ {1280, 1024, 75},
+ {1024, 768, 75},
+ {1024, 768, 70},
+ {1024, 768, 60},
+ {1024, 768, 87},
+ {832, 624, 75},
+ {800, 600, 75},
+ {800, 600, 72},
+ //
+ // Established Timing III
+ //
+ {1152, 870, 75}
+};
+
+/**
+ Read EDID information from I2C Bus on CirrusLogic.
+
+ @param Private Pointer to CIRRUS_LOGIC_5430_PRIVATE_DATA.
+ @param EdidDataBlock Pointer to EDID data block.
+ @param EdidSize Returned EDID block size.
+
+ @retval EFI_UNSUPPORTED
+ @retval EFI_SUCCESS
+
+**/
+STATIC
+EFI_STATUS
+ReadEdidData (
+ CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
+ UINT8 **EdidDataBlock,
+ UINTN *EdidSize
+ )
+{
+ UINT8 Index;
+ UINT8 EdidData[EDID_BLOCK_SIZE * 2];
+ UINT8 *ValidEdid;
+ UINT64 Signature;
+
+ for (Index = 0; Index < EDID_BLOCK_SIZE * 2; Index ++) {
+ I2cReadByte (Private->PciIo, 0xa0, Index, &EdidData[Index]);
+ }
+
+ //
+ // Search for the EDID signature
+ //
+ ValidEdid = &EdidData[0];
+ Signature = 0x00ffffffffffff00ull;
+ for (Index = 0; Index < EDID_BLOCK_SIZE * 2; Index ++, ValidEdid ++) {
+ if (CompareMem (ValidEdid, &Signature, 8) == 0) {
+ break;
+ }
+ }
+
+ if (Index == 256) {
+ //
+ // No EDID signature found
+ //
+ return EFI_UNSUPPORTED;
+ }
+
+ *EdidDataBlock = AllocateCopyPool (
+ sizeof (EDID_BLOCK_SIZE),
+ ValidEdid
+ );
+ if (*EdidDataBlock == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Currently only support EDID 1.x
+ //
+ *EdidSize = EDID_BLOCK_SIZE;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Generate a search key for a specified timing data.
+
+ @param EdidTiming Pointer to EDID timing
+
+ @return The 32 bit unique key for search.
+
+**/
+STATIC
+UINT32
+CalculateEdidKey (
+ EDID_TIMING *EdidTiming
+ )
+{
+ UINT32 Key;
+
+ //
+ // Be sure no conflicts for all standard timing defined by VESA.
+ //
+ Key = (EdidTiming->HorizontalResolution * 2) + EdidTiming->VerticalResolution;
+ return Key;
+}
+
+/**
+ Search a specified Timing in all the valid EDID timings.
+
+ @param ValidEdidTiming All valid EDID timing information.
+ @param EdidTiming The Timing to search for.
+
+ @retval TRUE Found.
+ @retval FALSE Not found.
+
+**/
+STATIC
+BOOLEAN
+SearchEdidTiming (
+ VALID_EDID_TIMING *ValidEdidTiming,
+ EDID_TIMING *EdidTiming
+ )
+{
+ UINT32 Index;
+ UINT32 Key;
+
+ Key = CalculateEdidKey (EdidTiming);
+
+ for (Index = 0; Index < ValidEdidTiming->ValidNumber; Index ++) {
+ if (Key == ValidEdidTiming->Key[Index]) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/**
+ Parse the Established Timing and Standard Timing in EDID data block.
+
+ @param EdidBuffer Pointer to EDID data block
+ @param ValidEdidTiming Valid EDID timing information
+
+ @retval TRUE The EDID data is valid.
+ @retval FALSE The EDID data is invalid.
+
+**/
+STATIC
+BOOLEAN
+ParseEdidData (
+ UINT8 *EdidBuffer,
+ VALID_EDID_TIMING *ValidEdidTiming
+ )
+{
+ UINT8 CheckSum;
+ UINT32 Index;
+ UINT32 ValidNumber;
+ UINT32 TimingBits;
+ UINT8 *BufferIndex;
+ UINT16 HorizontalResolution;
+ UINT16 VerticalResolution;
+ UINT8 AspectRatio;
+ UINT8 RefreshRate;
+ EDID_TIMING TempTiming;
+ EDID_BLOCK *EdidDataBlock;
+
+ EdidDataBlock = (EDID_BLOCK *) EdidBuffer;
+
+ //
+ // Check the checksum of EDID data
+ //
+ CheckSum = 0;
+ for (Index = 0; Index < EDID_BLOCK_SIZE; Index ++) {
+ CheckSum = (UINT8) (CheckSum + EdidBuffer[Index]);
+ }
+ if (CheckSum != 0) {
+ return FALSE;
+ }
+
+ ValidNumber = 0;
+ SetMem (ValidEdidTiming, sizeof (VALID_EDID_TIMING), 0);
+
+ if ((EdidDataBlock->EstablishedTimings[0] != 0) ||
+ (EdidDataBlock->EstablishedTimings[1] != 0) ||
+ (EdidDataBlock->EstablishedTimings[2] != 0)
+ ) {
+ //
+ // Established timing data
+ //
+ TimingBits = EdidDataBlock->EstablishedTimings[0] |
+ (EdidDataBlock->EstablishedTimings[1] << 8) |
+ ((EdidDataBlock->EstablishedTimings[2] & 0x80) << 9) ;
+ for (Index = 0; Index < VBE_EDID_ESTABLISHED_TIMING_MAX_NUMBER; Index ++) {
+ if (TimingBits & 0x1) {
+ ValidEdidTiming->Key[ValidNumber] = CalculateEdidKey (&mVbeEstablishedEdidTiming[Index]);
+ ValidNumber ++;
+ }
+ TimingBits = TimingBits >> 1;
+ }
+ } else {
+ //
+ // If no Established timing data, read the standard timing data
+ //
+ BufferIndex = &EdidDataBlock->StandardTimingIdentification[0];
+ for (Index = 0; Index < 8; Index ++) {
+ if ((BufferIndex[0] != 0x1) && (BufferIndex[1] != 0x1)){
+ //
+ // A valid Standard Timing
+ //
+ HorizontalResolution = (UINT16) (BufferIndex[0] * 8 + 248);
+ AspectRatio = (UINT8) (BufferIndex[1] >> 6);
+ switch (AspectRatio) {
+ case 0:
+ VerticalResolution = (UINT16) (HorizontalResolution / 16 * 10);
+ break;
+ case 1:
+ VerticalResolution = (UINT16) (HorizontalResolution / 4 * 3);
+ break;
+ case 2:
+ VerticalResolution = (UINT16) (HorizontalResolution / 5 * 4);
+ break;
+ case 3:
+ VerticalResolution = (UINT16) (HorizontalResolution / 16 * 9);
+ break;
+ default:
+ VerticalResolution = (UINT16) (HorizontalResolution / 4 * 3);
+ break;
+ }
+ RefreshRate = (UINT8) ((BufferIndex[1] & 0x1f) + 60);
+ TempTiming.HorizontalResolution = HorizontalResolution;
+ TempTiming.VerticalResolution = VerticalResolution;
+ TempTiming.RefreshRate = RefreshRate;
+ ValidEdidTiming->Key[ValidNumber] = CalculateEdidKey (&TempTiming);
+ ValidNumber ++;
+ }
+ BufferIndex += 2;
+ }
+ }
+
+ ValidEdidTiming->ValidNumber = ValidNumber;
+ return TRUE;
+}
+
+/**
+ Construct the valid video modes for CirrusLogic5430.
+
+**/
+EFI_STATUS
+CirrusLogic5430VideoModeSetup (
+ CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Index;
+ BOOLEAN EdidFound;
+ EFI_EDID_OVERRIDE_PROTOCOL *EdidOverride;
+ UINT32 EdidAttributes;
+ BOOLEAN EdidOverrideFound;
+ UINTN EdidOverrideDataSize;
+ UINT8 *EdidOverrideDataBlock;
+ UINTN EdidDiscoveredDataSize;
+ UINT8 *EdidDiscoveredDataBlock;
+ UINTN EdidActiveDataSize;
+ UINT8 *EdidActiveDataBlock;
+ VALID_EDID_TIMING ValidEdidTiming;
+ UINT32 ValidModeCount;
+ CIRRUS_LOGIC_5430_MODE_DATA *ModeData;
+ BOOLEAN TimingMatch;
+ CIRRUS_LOGIC_5430_VIDEO_MODES *VideoMode;
+ EDID_TIMING TempTiming;
+
+ //
+ // setup EDID information
+ //
+ Private->EdidDiscovered.Edid = NULL;
+ Private->EdidDiscovered.SizeOfEdid = 0;
+ Private->EdidActive.Edid = NULL;
+ Private->EdidActive.SizeOfEdid = 0;
+
+ EdidFound = FALSE;
+ EdidOverrideFound = FALSE;
+ EdidAttributes = 0xff;
+ EdidOverrideDataSize = 0;
+ EdidOverrideDataBlock = NULL;
+ EdidActiveDataSize = 0;
+ EdidActiveDataBlock = NULL;
+ EdidDiscoveredDataBlock = NULL;
+
+ //
+ // Find EDID Override protocol firstly, this protocol is installed by platform if needed.
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiEdidOverrideProtocolGuid,
+ NULL,
+ (VOID **) &EdidOverride
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // Allocate double size of VESA_BIOS_EXTENSIONS_EDID_BLOCK_SIZE to avoid overflow
+ //
+ EdidOverrideDataBlock = AllocatePool (sizeof (EDID_BLOCK_SIZE * 2));
+ if (NULL == EdidOverrideDataBlock) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+
+ Status = EdidOverride->GetEdid (
+ EdidOverride,
+ Private->Handle,
+ &EdidAttributes,
+ &EdidOverrideDataSize,
+ (UINT8 **) &EdidOverrideDataBlock
+ );
+ if (!EFI_ERROR (Status) &&
+ EdidAttributes == 0 &&
+ EdidOverrideDataSize != 0) {
+ //
+ // Succeeded to get EDID Override Data
+ //
+ EdidOverrideFound = TRUE;
+ }
+ }
+
+ if (EdidOverrideFound != TRUE || EdidAttributes == EFI_EDID_OVERRIDE_DONT_OVERRIDE) {
+ //
+ // If EDID Override data doesn't exist or EFI_EDID_OVERRIDE_DONT_OVERRIDE returned,
+ // read EDID information through I2C Bus
+ //
+ if (ReadEdidData (Private, &EdidDiscoveredDataBlock, &EdidDiscoveredDataSize) == EFI_SUCCESS) {;
+ Private->EdidDiscovered.SizeOfEdid = (UINT32) EdidDiscoveredDataSize;
+ Private->EdidDiscovered.Edid = (UINT8 *) AllocateCopyPool (
+ EdidDiscoveredDataSize,
+ EdidDiscoveredDataBlock
+ );
+
+ if (NULL == Private->EdidDiscovered.Edid) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+
+ EdidActiveDataSize = Private->EdidDiscovered.SizeOfEdid;
+ EdidActiveDataBlock = Private->EdidDiscovered.Edid;
+
+ EdidFound = TRUE;
+ }
+ }
+
+ if (EdidFound != TRUE && EdidOverrideFound == TRUE) {
+ EdidActiveDataSize = EdidOverrideDataSize;
+ EdidActiveDataBlock = EdidOverrideDataBlock;
+ EdidFound = TRUE;
+ }
+
+ if (EdidFound == TRUE) {
+ //
+ // Parse EDID data structure to retrieve modes supported by monitor
+ //
+ if (ParseEdidData ((UINT8 *) EdidActiveDataBlock, &ValidEdidTiming) == TRUE) {
+ //
+ // Copy EDID Override Data to EDID Active Data
+ //
+ Private->EdidActive.SizeOfEdid = (UINT32) EdidActiveDataSize;
+ Private->EdidActive.Edid = (UINT8 *) AllocateCopyPool (
+ EdidActiveDataSize,
+ EdidActiveDataBlock
+ );
+ if (NULL == Private->EdidActive.Edid) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+ }
+ } else {
+ Private->EdidActive.SizeOfEdid = 0;
+ Private->EdidActive.Edid = NULL;
+ EdidFound = FALSE;
+ }
+
+ if (EdidFound) {
+ //
+ // Initialize the private mode data with the supported modes.
+ //
+ ValidModeCount = 0;
+ ModeData = &Private->ModeData[0];
+ VideoMode = &CirrusLogic5430VideoModes[0];
+ for (Index = 0; Index < CIRRUS_LOGIC_5430_MODE_COUNT; Index++) {
+
+ TimingMatch = TRUE;
+
+ //
+ // Check whether match with CirrusLogic5430 video mode
+ //
+ TempTiming.HorizontalResolution = (UINT16) VideoMode->Width;
+ TempTiming.VerticalResolution = (UINT16) VideoMode->Height;
+ TempTiming.RefreshRate = (UINT16) VideoMode->RefreshRate;
+ if (SearchEdidTiming (&ValidEdidTiming, &TempTiming) != TRUE) {
+ TimingMatch = FALSE;
+ }
+
+ //
+ // Not export Mode 0x0 as GOP mode, this is not defined in spec.
+ //
+ if ((VideoMode->Width == 0) || (VideoMode->Height == 0)) {
+ TimingMatch = FALSE;
+ }
+
+ if (TimingMatch) {
+ ModeData->ModeNumber = Index;
+ ModeData->HorizontalResolution = VideoMode->Width;
+ ModeData->VerticalResolution = VideoMode->Height;
+ ModeData->ColorDepth = VideoMode->ColorDepth;
+ ModeData->RefreshRate = VideoMode->RefreshRate;
+
+ ModeData ++;
+ ValidModeCount ++;
+ }
+
+ VideoMode ++;
+ }
+
+ Private->MaxMode = ValidModeCount;
+
+ } else {
+ //
+ // If EDID information wasn't found
+ //
+ ModeData = &Private->ModeData[0];
+ VideoMode = &CirrusLogic5430VideoModes[0];
+ for (Index = 0; Index < CIRRUS_LOGIC_5430_MODE_COUNT; Index ++) {
+ ModeData->ModeNumber = Index;
+ ModeData->HorizontalResolution = VideoMode->Width;
+ ModeData->VerticalResolution = VideoMode->Height;
+ ModeData->ColorDepth = VideoMode->ColorDepth;
+ ModeData->RefreshRate = VideoMode->RefreshRate;
+
+ ModeData ++ ;
+ VideoMode ++;
+ }
+ Private->MaxMode = CIRRUS_LOGIC_5430_MODE_COUNT;
+ }
+
+ FreePool (EdidOverrideDataBlock);
+ return EFI_SUCCESS;
+
+Done:
+ if (EdidOverrideDataBlock != NULL) {
+ FreePool (EdidOverrideDataBlock);
+ }
+ if (Private->EdidDiscovered.Edid != NULL) {
+ FreePool (Private->EdidDiscovered.Edid);
+ }
+ if (Private->EdidDiscovered.Edid != NULL) {
+ FreePool (Private->EdidActive.Edid);
+ }
+
+ return EFI_DEVICE_ERROR;
+}
diff --git a/OptionRomPkg/Include/Library/DxeI2cLib.h b/OptionRomPkg/Include/Library/DxeI2cLib.h new file mode 100644 index 0000000000..5325560cb9 --- /dev/null +++ b/OptionRomPkg/Include/Library/DxeI2cLib.h @@ -0,0 +1,64 @@ +/** @file + I2c Bus byte read/write functions. + + Copyright (c) 2008, Intel Corporation + All rights reserved. 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 <Protocol/PciIo.h>
+
+/**
+ Read one byte data on I2C Bus.
+
+ Read one byte data from the slave device connectet to I2C Bus.
+ If Data is NULL, then ASSERT().
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param DeviceAddress Slave device's address.
+ @param RegisterAddress The register address on slave device.
+ @param Data The pointer to returned data if EFI_SUCCESS returned.
+
+ @retval EFI_DEVICE_ERROR
+ @retval EFI_SUCCESS
+
+**/
+EFI_STATUS
+EFIAPI
+I2cReadByte (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 DeviceAddress,
+ UINT8 RegisterAddress,
+ UINT8 *Data
+ );
+
+/**
+ Write one byte data onto I2C Bus.
+
+ Write one byte data to the slave device connectet to I2C Bus.
+ If Data is NULL, then ASSERT().
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param DeviceAddress Slave device's address.
+ @param RegisterAddress The register address on slave device.
+ @param Data The pointer to write data.
+
+ @retval EFI_DEVICE_ERROR
+ @retval EFI_SUCCESS
+
+**/
+EFI_STATUS
+EFIAPI
+I2cWriteByte (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 DeviceAddress,
+ UINT8 RegisterAddress,
+ UINT8 *Data
+ );
+
diff --git a/OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.c b/OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.c new file mode 100644 index 0000000000..2a693cef5a --- /dev/null +++ b/OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.c @@ -0,0 +1,447 @@ +/** @file
+ I2C Bus Libary implementation upon CirrusLogic.
+
+ Copyright (c) 2008, Intel Corporation
+ All rights reserved. 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/DxeI2cLib.h>
+#include <Library/TimerLib.h>
+#include <Library/DebugLib.h>
+
+#define SEQ_ADDRESS_REGISTER 0x3c4
+#define SEQ_DATA_REGISTER 0x3c5
+
+#define I2C_CONTROL 0x08
+#define I2CDAT_IN 7
+#define I2CCLK_IN 2
+#define I2CDAT_OUT 1
+#define I2CCLK_OUT 0
+
+#define I2C_BUS_SPEED 100 //100kbps
+
+/**
+ PCI I/O byte write function.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param Address The bit map of I2C Data or I2C Clock pins.
+ @param Data The date to write.
+
+**/
+STATIC
+VOID
+outb (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINTN Address,
+ UINT8 Data
+ )
+{
+ PciIo->Io.Write (
+ PciIo,
+ EfiPciIoWidthUint8,
+ EFI_PCI_IO_PASS_THROUGH_BAR,
+ Address,
+ 1,
+ &Data
+ );
+}
+/**
+ PCI I/O byte read function.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param Address The bit map of I2C Data or I2C Clock pins.
+
+ return byte value read from PCI I/O space.
+
+**/
+STATIC
+UINT8
+inb (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINTN Address
+ )
+{
+ UINT8 Data;
+
+ PciIo->Io.Read (
+ PciIo,
+ EfiPciIoWidthUint8,
+ EFI_PCI_IO_PASS_THROUGH_BAR,
+ Address,
+ 1,
+ &Data
+ );
+ return Data;
+}
+
+/**
+ Read status of I2C Data and I2C Clock Pins.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param Blt The bit map of I2C Data or I2C Clock pins.
+
+ @retval 0 Low on I2C Data or I2C Clock Pin.
+ @retval 1 High on I2C Data or I2C Clock Pin.
+
+**/
+STATIC
+UINT8
+I2cPinRead (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 Bit
+ )
+{
+ outb (PciIo, SEQ_ADDRESS_REGISTER, I2C_CONTROL);
+ return (UINT8) ((inb (PciIo, SEQ_DATA_REGISTER) >> Bit ) & 0xfe);
+}
+
+
+/**
+ Set/Clear I2C Data and I2C Clock Pins.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param Blt The bit map to controller I2C Data or I2C Clock pins.
+ @param Value 1 or 0 stands for Set or Clear I2C Data and I2C Clock Pins.
+
+**/
+STATIC
+VOID
+I2cPinWrite (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 Bit,
+ UINT8 Value
+ )
+{
+ UINT8 Byte;
+ outb (PciIo, SEQ_ADDRESS_REGISTER, I2C_CONTROL);
+ Byte = (UINT8) (inb (PciIo, SEQ_DATA_REGISTER) & (UINT8) ~(1 << Bit)) ;
+ Byte = (UINT8) (Byte | ((Value & 0x01) << Bit));
+ outb (PciIo, SEQ_DATA_REGISTER, (UINT8) (Byte | 0x40));
+ return;
+}
+
+/**
+ Read/write delay acoording to I2C Bus Speed.
+
+**/
+STATIC
+VOID
+I2cDelay (
+ VOID
+ )
+{
+ MicroSecondDelay (1000 / I2C_BUS_SPEED);
+}
+
+/**
+ Write a 8-bit data onto I2C Data Pin.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param Data The byte data to write.
+
+**/
+STATIC
+VOID
+I2cSendByte (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 Data
+ )
+{
+ UINTN Index;
+ //
+ // Send byte data onto I2C Bus
+ //
+ for (Index = 0; Index < 8; Index --) {
+ I2cPinWrite (PciIo, I2CDAT_OUT, (UINT8) (Data >> (7 - Index)));
+ I2cPinWrite (PciIo, I2CCLK_OUT, 1);
+ I2cDelay ();
+ I2cPinWrite (PciIo, I2CCLK_OUT, 0);
+ }
+}
+
+/**
+ Read a 8-bit data from I2C Data Pin.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+
+ Return the byte data read from I2C Data Pin.
+**/
+STATIC
+UINT8
+I2cReceiveByte (
+ EFI_PCI_IO_PROTOCOL *PciIo
+ )
+{
+ UINT8 Data;
+ UINTN Index;
+
+ Data = 0;
+ //
+ // Read byte data from I2C Bus
+ //
+ for (Index = 0; Index < 8; Index --) {
+ I2cPinWrite (PciIo, I2CCLK_OUT, 1);
+ I2cDelay ();
+ Data = (UINT8) (Data << 1);
+ Data = (UINT8) (Data | I2cPinRead (PciIo, I2CDAT_IN));
+ I2cPinWrite (PciIo, I2CCLK_OUT, 0);
+ }
+
+ return Data;
+}
+
+/**
+ Receive an ACK signal from I2C Bus.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+
+**/
+STATIC
+BOOLEAN
+I2cWaitAck (
+ EFI_PCI_IO_PROTOCOL *PciIo
+ )
+{
+ //
+ // Wait for ACK signal
+ //
+ I2cPinWrite (PciIo, I2CDAT_OUT, 1);
+ I2cPinWrite (PciIo, I2CCLK_OUT, 1);
+ I2cDelay ();
+ if (I2cPinRead (PciIo, I2CDAT_IN) == 0) {
+ I2cPinWrite (PciIo, I2CDAT_OUT, 1);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ Send an ACK signal onto I2C Bus.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+
+**/
+STATIC
+VOID
+I2cSendAck (
+ EFI_PCI_IO_PROTOCOL *PciIo
+ )
+{
+ I2cPinWrite (PciIo, I2CCLK_OUT, 1);
+ I2cPinWrite (PciIo, I2CDAT_OUT, 1);
+ I2cPinWrite (PciIo, I2CDAT_OUT, 0);
+ I2cPinWrite (PciIo, I2CCLK_OUT, 0);
+}
+
+/**
+ Start a I2C transfer on I2C Bus.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+
+**/
+STATIC
+VOID
+I2cStart (
+ EFI_PCI_IO_PROTOCOL *PciIo
+ )
+{
+ //
+ // Init CLK and DAT pins
+ //
+ I2cPinWrite (PciIo, I2CCLK_OUT, 1);
+ I2cPinWrite (PciIo, I2CDAT_OUT, 1);
+ //
+ // Start a I2C transfer, set SDA low from high, when SCL is high
+ //
+ I2cPinWrite (PciIo, I2CDAT_OUT, 0);
+ I2cPinWrite (PciIo, I2CCLK_OUT, 0);
+}
+
+/**
+ Stop a I2C transfer on I2C Bus.
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+
+**/
+STATIC
+VOID
+I2cStop (
+ EFI_PCI_IO_PROTOCOL *PciIo
+ )
+{
+ //
+ // Stop a I2C transfer, set SDA high from low, when SCL is high
+ //
+ I2cPinWrite (PciIo, I2CDAT_OUT, 0);
+ I2cPinWrite (PciIo, I2CCLK_OUT, 1);
+ I2cPinWrite (PciIo, I2CDAT_OUT, 1);
+}
+
+/**
+ Read one byte data on I2C Bus.
+
+ Read one byte data from the slave device connectet to I2C Bus.
+ If Data is NULL, then ASSERT().
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param DeviceAddress Slave device's address.
+ @param RegisterAddress The register address on slave device.
+ @param Data The pointer to returned data if EFI_SUCCESS returned.
+
+ @retval EFI_DEVICE_ERROR
+ @retval EFI_SUCCESS
+
+**/
+EFI_STATUS
+EFIAPI
+I2cReadByte (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 DeviceAddress,
+ UINT8 RegisterAddress,
+ UINT8 *Data
+ )
+{
+ ASSERT (Data != NULL);
+
+ //
+ // Start I2C transfer
+ //
+ I2cStart (PciIo);
+
+ //
+ // Send slave address with enabling write flag
+ //
+ I2cSendByte (PciIo, (UINT8) (DeviceAddress & 0xfe));
+
+ //
+ // Wait for ACK signal
+ //
+ if (I2cWaitAck (PciIo) == FALSE) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Send register address
+ //
+ I2cSendByte (PciIo, RegisterAddress);
+
+ //
+ // Wait for ACK signal
+ //
+ if (I2cWaitAck (PciIo) == FALSE) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Send slave address with enabling read flag
+ //
+ I2cSendByte (PciIo, (UINT8) (DeviceAddress | 0x01));
+
+ //
+ // Wait for ACK signal
+ //
+ if (I2cWaitAck (PciIo) == FALSE) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Read byte data from I2C Bus
+ //
+ *Data = I2cReceiveByte (PciIo);
+
+ //
+ // Send ACK signal onto I2C Bus
+ //
+ I2cSendAck (PciIo);
+
+ //
+ // Stop a I2C transfer
+ //
+ I2cStop (PciIo);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Write one byte data onto I2C Bus.
+
+ Write one byte data to the slave device connectet to I2C Bus.
+ If Data is NULL, then ASSERT().
+
+ @param PciIo The pointer to PCI_IO_PROTOCOL.
+ @param DeviceAddress Slave device's address.
+ @param RegisterAddress The register address on slave device.
+ @param Data The pointer to write data.
+
+ @retval EFI_DEVICE_ERROR
+ @retval EFI_SUCCESS
+
+**/
+EFI_STATUS
+EFIAPI
+I2cWriteByte (
+ EFI_PCI_IO_PROTOCOL *PciIo,
+ UINT8 DeviceAddress,
+ UINT8 RegisterAddress,
+ UINT8 *Data
+ )
+{
+ ASSERT (Data != NULL);
+
+ I2cStart (PciIo);
+ //
+ // Send slave address with enabling write flag
+ //
+ I2cSendByte (PciIo, (UINT8) (DeviceAddress & 0xfe));
+
+ //
+ // Wait for ACK signal
+ //
+ if (I2cWaitAck (PciIo) == FALSE) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Send register address
+ //
+ I2cSendByte (PciIo, RegisterAddress);
+
+ //
+ // Wait for ACK signal
+ //
+ if (I2cWaitAck (PciIo) == FALSE) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Send byte data onto I2C Bus
+ //
+ I2cSendByte (PciIo, *Data);
+
+ //
+ // Wait for ACK signal
+ //
+ if (I2cWaitAck (PciIo) == FALSE) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Stop a I2C transfer
+ //
+ I2cStop (PciIo);
+
+ return EFI_SUCCESS;
+}
+
+
+
diff --git a/OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.inf b/OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.inf new file mode 100644 index 0000000000..7474a4f05f --- /dev/null +++ b/OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.inf @@ -0,0 +1,45 @@ +#/** @file
+# DxeI2c Library implementation on CirrusLogic.
+#
+# Provides I2c Bus byte read/write functions upon CirrusLogic5430.
+# Copyright (c) 2008, Intel Corporation.
+#
+# All rights reserved. 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = CirrusLogic5430I2cLib
+ FILE_GUID = 0C86ADD7-ED2A-4b9a-ABC9-D932E8AA349B
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DxeI2cLib
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ CirrusLogic5430I2cLib.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OptionRomPkg/OptionRomPkg.dec
+
+
+[LibraryClasses]
+ TimerLib
+ DebugLib
+
+
diff --git a/OptionRomPkg/OptionRomPkg.dec b/OptionRomPkg/OptionRomPkg.dec index 281b4d5d28..539138b804 100644 --- a/OptionRomPkg/OptionRomPkg.dec +++ b/OptionRomPkg/OptionRomPkg.dec @@ -4,9 +4,9 @@ # This package is designed to interoperate with the EDK II open source project
# at http://www.tianocore.org, and this package is required to build PCI compliant
# Option ROM image for all CPU architectures, including EBC target.
-# A single driver can support mixes of EFI 1.1, UEFI 2.0 and UEFI 2.1.
+# A single driver can support mixes of EFI 1.1, UEFI 2.0 and UEFI 2.1.
#
-# Copyright (c) 2007, Intel Corporation.
+# Copyright (c) 2007 - 2008, Intel Corporation.
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -24,6 +24,12 @@ PACKAGE_GUID = AA3865E8-7F30-4f59-8696-99F560101852
PACKAGE_VERSION = 0.1
+[Includes.common]
+ Include
+
+[LibraryClasses.common]
+ DxeI2cLib|Include/Library/DxeI2cLib.h
+
[PcdsFeatureFlag.common]
gOptionRomPkgTokenSpaceGuid.PcdSupportScsiPassThru|TRUE|BOOLEAN|0x00010001
gOptionRomPkgTokenSpaceGuid.PcdSupportExtScsiPassThru|TRUE|BOOLEAN|0x00010002
diff --git a/OptionRomPkg/OptionRomPkg.dsc b/OptionRomPkg/OptionRomPkg.dsc index 9a19b79b0c..c4bf1ca1bb 100644 --- a/OptionRomPkg/OptionRomPkg.dsc +++ b/OptionRomPkg/OptionRomPkg.dsc @@ -4,9 +4,9 @@ # This package is designed to interoperate with the EDK II open source project
# at http://www.tianocore.org, and this package is required to build PCI compliant
# Option ROM image for all CPU architectures, including EBC target.
-# A single driver can support mixes of EFI 1.1, UEFI 2.0 and UEFI 2.1.
+# A single driver can support mixes of EFI 1.1, UEFI 2.0 and UEFI 2.1.
#
-# Copyright (c) 2007, Intel Corporation
+# Copyright (c) 2007 - 2008, Intel Corporation
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -57,7 +57,9 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
-
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ DxeI2cLib|OptionRomPkg/Library/CirrusLogicI2cLib/CirrusLogic5430I2cLib.inf
+
################################################################################
#
# Pcd Section - list of all EDK II PCD Entries defined by this Platform
@@ -91,4 +93,4 @@ [Components.common]
OptionRomPkg/AtapiPassThruDxe/AtapiPassThruDxe.inf
OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf
-
+
|