blob: f55143abbc05e17d7cc2bf5022bf6140ab06cbbf [file] [log] [blame]
From 3fd9815ef932f7bd2f83d9914168ca3301e3a686 Mon Sep 17 00:00:00 2001
From: Marc Jones <marc.jones@scarletltd.com>
Date: Wed, 11 Jul 2018 16:13:13 -0600
Subject: [PATCH] edk2-SdMMcPciHcDxe: Add Bayhub support
Adds Bayhub support to the general SD driver.
Source has been provided by Bayhub.
BUG=109777514
TEST=Id and boot chromeos on the emmc.
Change-Id: I3f001f9021d9577720e2fe18e99d67eee17b6468
Signed-off-by: Marc Jones <marc.jones@scarletltd.com>
---
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c | 8 +++-
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 2 +-
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 2 +-
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 54 ++++++++++++++++++++--
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h | 14 ++++++
5 files changed, 74 insertions(+), 6 deletions(-)
mode change 100755 => 100644 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
old mode 100755
new mode 100644
index c5fd214..8b6e802
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -51,6 +51,7 @@ EmmcReset (
SdMmcCmdBlk.ResponseType = 0;
SdMmcCmdBlk.CommandArgument = 0;
+
gBS->Stall (1000);
Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
@@ -1125,7 +1126,12 @@ EmmcSetBusMode (
//
// Execute HS200 timing switch procedure
//
- Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, BusWidth);
+ if (!VendorPciSupport(PciIo)){
+ Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, 4);
+ Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, FALSE, 8);
+ }else{
+ Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, 8);
+ }
} else {
//
// Execute High Speed timing switch procedure
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 9e70de9..cc8924c 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -1085,7 +1085,7 @@ SdCardIdentification (
return Status;
}
- if ((ControllerVer & 0xFF) == 2) {
+ if (((ControllerVer & 0xFF) == 2) || ((ControllerVer & 0xFF) == 3)) {
S18r = TRUE;
} else if (((ControllerVer & 0xFF) == 0) || ((ControllerVer & 0xFF) == 1)) {
S18r = FALSE;
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index 23faec5..6cd2fc2 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -115,7 +115,7 @@ InitializeSdMmcPciHcDxe (
)
{
EFI_STATUS Status;
-
+ Print(L"Install SdMmcPciHcDxe Driver");
Status = EfiLibInstallDriverBindingComponentName2 (
ImageHandle,
SystemTable,
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index aa75aa8..e59a9f5 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -741,7 +741,7 @@ SdMmcHcClockSupply (
//
// Set SDCLK Frequency Select and Internal Clock Enable fields in Clock Control register.
//
- if ((ControllerVer & 0xFF) == 2) {
+ if (((ControllerVer & 0xFF) == 2) || ((ControllerVer & 0xFF) == 3)) {
ASSERT (Divisor <= 0x3FF);
ClockCtrl = ((Divisor & 0xFF) << 8) | ((Divisor & 0x300) >> 2);
} else if (((ControllerVer & 0xFF) == 0) || ((ControllerVer & 0xFF) == 1)) {
@@ -987,6 +987,15 @@ SdMmcHcInitPowerVoltage (
//
Status = SdMmcHcPowerControl (PciIo, Slot, MaxVoltage);
+ if (!VendorPciSupport(PciIo)){
+ HostCtrl2 = BIT3;
+ Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
+ gBS->Stall (5000);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
return Status;
}
@@ -1037,15 +1046,24 @@ SdMmcHcInitHost (
)
{
EFI_STATUS Status;
+
+ if (!VendorPciSupport(PciIo)){
+ Status = SdMmcHcInitPowerVoltage (PciIo, Slot, Capability);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
Status = SdMmcHcInitClockFreq (PciIo, Slot, Capability);
if (EFI_ERROR (Status)) {
return Status;
}
+ if (VendorPciSupport(PciIo)){
Status = SdMmcHcInitPowerVoltage (PciIo, Slot, Capability);
- if (EFI_ERROR (Status)) {
- return Status;
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
}
Status = SdMmcHcInitTimeoutCtrl (PciIo, Slot);
@@ -1929,3 +1947,33 @@ SdMmcWaitTrbResult (
return EFI_TIMEOUT;
}
+
+int VendorPciSupport(EFI_PCI_IO_PROTOCOL *PciIo)
+{
+ PCI_TYPE00 Pci;
+
+ PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32,
+ 0, sizeof Pci / sizeof (UINT32), &Pci);
+
+ Print(L"check device %04x:%04x\n", Pci.Hdr.VendorId, Pci.Hdr.DeviceId);
+
+ if (Pci.Hdr.VendorId != 0x1217)
+ goto end;
+
+ switch (Pci.Hdr.DeviceId)
+ {
+ case 0x8420: //PCI_DEV_ID_SDS0
+ case 0x8421: //PCI_DEV_ID_SDS1
+ case 0x8520: //PCI_DEV_ID_FJ2
+ case 0x8620: //PCI_DEV_ID_SB0
+ case 0x8621: //PCI_DEV_ID_SB1
+ return 0;
+ default:
+ break;
+ }
+
+end:
+ return -1;
+}
+
+
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
index fb62758..9c42eb4 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h
@@ -542,5 +542,19 @@ SdMmcHcInitHost (
IN UINT8 Slot,
IN SD_MMC_HC_SLOT_CAP Capability
);
+/**
+Through Device ID and Vendor ID to decide if Controller should run as default
+or special defined
+
+@param[in] PciIo The PCI IO protocol instance.
+
+@retval 0 The host controller should run as special defined.
+@retval Others The host controller should run as default.
+
+**/
+
+int
+VendorPciSupport(EFI_PCI_IO_PROTOCOL *PciIo);
+
#endif
--
2.7.4