From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::342; helo=mail-wm1-x342.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B277721188C25 for ; Wed, 31 Oct 2018 10:34:18 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id p2-v6so15257966wmc.2 for ; Wed, 31 Oct 2018 10:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+1Edixs/hAa5Itg7kmMU5NiPl75jHFGg9IdZLqajYik=; b=HyY2/Be3jscerqvFfGS7IwE4TYCS+qeFgIeN7nEtd/cgpcPtSkhU8M60Gcmwz7pwl5 wcD8MGkikNiktigo4xuKMhugNJKyXGBniuJ3v27Ta0h99DM6yzPM6+ubaWpiXz6kS4/I F/HN8g26NPHngRc0pg/nuAtY/XdZKb4rO/JEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+1Edixs/hAa5Itg7kmMU5NiPl75jHFGg9IdZLqajYik=; b=qH7FyV8xUW2pNda9MkAd0IoDG2P3IFNnCVjfrhaHkx7S98qDgWGb4X9C/4pkJlz6XM WJMeY64dVG76dXZXKiP0Hno+3/g8W7Y7RRuoOkDzTilz3GIxRVHchkCinpQxAH/wbg1h /E12UcrvowZHYWp4dMOaqqgtboPgbJnfGKqWHZx1e98mQswRfqGU6j1V8QDuI6rkVu9U gR2xZ0AJZTq+FjtM/WAbMDNvEO5Rg77r71+kF3leTYsTrBY1fxb4crR6VMne1Ntndkj8 VOTnj3J+KcWfOeYm877Dnl9TZGrKJXGIPnpn8YlStV5EaDiGSxpvHwXZ3G9EyH+4CuFG dUug== X-Gm-Message-State: AGRZ1gIsifVGRCD1Ap7Ilb1FJ9d8s8JVvl11CnZX0oh9TtpRux5Fo0eD RhjHTF7enPVBa3zJNUkBU5OsorPHzXM= X-Google-Smtp-Source: AJdET5ejaqxEHYw9vOBb/UUGNWwCUHD/kuH0ClaereEBNJgzRYQT0fEuKgcwkMVUXjGafddxP9/ikw== X-Received: by 2002:a1c:1183:: with SMTP id 125-v6mr3247417wmr.103.1541007256783; Wed, 31 Oct 2018 10:34:16 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id v1-v6sm46140485wrd.24.2018.10.31.10.34.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 10:34:15 -0700 (PDT) Date: Wed, 31 Oct 2018 17:34:14 +0000 From: Leif Lindholm To: Haojian Zhuang Cc: edk2-devel@lists.01.org, Ard Biesheuvel Message-ID: <20181031173414.o5s7bidru5ajmxoi@bivouac.eciton.net> References: <1534384166-15673-1-git-send-email-haojian.zhuang@linaro.org> <1534384166-15673-4-git-send-email-haojian.zhuang@linaro.org> MIME-Version: 1.0 In-Reply-To: <1534384166-15673-4-git-send-email-haojian.zhuang@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH v2 edk-platforms 3/3] Platform/HiKey: enable SD/MMC controller on HiKey X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Oct 2018 17:34:19 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Aug 16, 2018 at 09:49:26AM +0800, Haojian Zhuang wrote: > Replace DwEmmcDxe driver by DwMmcHcDxe driver on HiKey platform. Since > the new driver could work on both eMMC and SD controller. > > Cc: Leif Lindholm > Cc: Ard Biesheuvel > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Haojian Zhuang > --- > Platform/Hisilicon/HiKey/HiKey.dsc | 17 +-- > Platform/Hisilicon/HiKey/HiKey.fdf | 15 ++- > Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf | 1 + > Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf | 45 +++++++ > Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c | 26 ++++ > Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.c | 139 ++++++++++++++++++++ > 6 files changed, 227 insertions(+), 16 deletions(-) > > diff --git a/Platform/Hisilicon/HiKey/HiKey.dsc b/Platform/Hisilicon/HiKey/HiKey.dsc > index 9c1fc2e1b40d..4b5b73c15afe 100644 > --- a/Platform/Hisilicon/HiKey/HiKey.dsc > +++ b/Platform/Hisilicon/HiKey/HiKey.dsc > @@ -126,12 +126,6 @@ [PcdsFixedAtBuild.common] > gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000 > > # > - # DW MMC/SD card controller > - # > - gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress|0xF723D000 > - gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz|100000000 > - > - # > # > # Fastboot > # > @@ -204,13 +198,16 @@ [Components.common] > # > EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf > > - Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf > - > # > # MMC/SD > # > - EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf > - EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf > + Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf > + EmbeddedPkg/Universal/NonDiscoverableDeviceDxe/NonDiscoverableDeviceDxe.inf > + EmbeddedPkg/Drivers/DwMmcHcDxe/DwMmcHcDxe.inf > + MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.inf > + MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf > + > + Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf > > # > # USB Host Support > diff --git a/Platform/Hisilicon/HiKey/HiKey.fdf b/Platform/Hisilicon/HiKey/HiKey.fdf > index 2bca7232b6e5..89d3e9280ff6 100644 > --- a/Platform/Hisilicon/HiKey/HiKey.fdf > +++ b/Platform/Hisilicon/HiKey/HiKey.fdf > @@ -128,15 +128,18 @@ [FV.FvMain] > # > INF EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf > > + # > + # MMC/SD > + # > + INF Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf > + INF EmbeddedPkg/Universal/NonDiscoverableDeviceDxe/NonDiscoverableDeviceDxe.inf > + INF EmbeddedPkg/Drivers/DwMmcHcDxe/DwMmcHcDxe.inf > + INF MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.inf > + INF MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf > + > INF Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf > > # > - # Multimedia Card Interface > - # > - INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf > - INF EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf > - > - # > # USB Host Support > # > INF MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf > diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf > index 4c4644a0fe51..3d2843fbc9f6 100644 > --- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf > +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf > @@ -32,6 +32,7 @@ [LibraryClasses] > CacheMaintenanceLib > DebugLib > IoLib > + NonDiscoverableDeviceRegistrationLib > UefiBootManagerLib > UefiLib > UefiDriverEntryPoint > diff --git a/Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf b/Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf > new file mode 100644 > index 000000000000..1b78d3228ccf > --- /dev/null > +++ b/Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf > @@ -0,0 +1,45 @@ > +#/** @file > +# > +# Copyright (c) 2017, Linaro. All rights reserved. 2018? > +# > +# 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 = 0x00010019 > + BASE_NAME = HiKeyMmcDxe > + FILE_GUID = a4f9bfb1-b3f8-4d4d-8c04-9539173fc1f2 > + MODULE_TYPE = UEFI_DRIVER > + VERSION_STRING = 1.0 > + ENTRY_POINT = HiKeyMmcEntryPoint > + > +[Sources.common] > + HiKeyMmcDxe.c > + > +[LibraryClasses] > + DebugLib > + IoLib > + TimerLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + > +[Protocols] > + gEfiDriverBindingProtocolGuid > + gEmbeddedGpioProtocolGuid > + gPlatformDwMmcProtocolGuid > + > +[Packages] > + EmbeddedPkg/EmbeddedPkg.dec > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec Swap above two lines around? > + OpenPlatformPkg/Drivers/SdMmc/DwMmcHcDxe/DwMmcHcDxe.dec > + > +[Depex] > + TRUE > diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c > index 2162b68529bd..cdec3f1dd0b0 100644 > --- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c > +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -351,6 +352,31 @@ HiKeyEntryPoint ( > return Status; > } > > + Status = RegisterNonDiscoverableMmioDevice ( > + NonDiscoverableDeviceTypeSdhci, > + NonDiscoverableDeviceDmaTypeNonCoherent, > + NULL, > + NULL, > + 1, #define in .h, or comment? > + 0xF723D000, // eMMC Define in Silicon/Hisilicon/Hi6220/Include/Hi6220.h and use that? > + SIZE_4KB > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + Status = RegisterNonDiscoverableMmioDevice ( > + NonDiscoverableDeviceTypeSdhci, > + NonDiscoverableDeviceDmaTypeNonCoherent, > + NULL, > + NULL, > + 1, #define in .h, or comment? > + 0xF723E000, // SD Define in Silicon/Hisilicon/Hi6220/Include/Hi6220.h and use that? > + SIZE_4KB > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > Status = gBS->InstallProtocolInterface ( > &ImageHandle, > &gPlatformVirtualKeyboardProtocolGuid, > diff --git a/Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.c b/Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.c > new file mode 100644 > index 000000000000..390c23018bc6 > --- /dev/null > +++ b/Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.c > @@ -0,0 +1,139 @@ > +/** @file > +* > +* Copyright (c) 2017, Linaro. 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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include > + > +#define DETECT_SD_CARD 8 // GPIO 1_0 Move to local .h. > + > +DW_MMC_HC_SLOT_CAP > +DwMmcCapability[2] = { #define for that 2. > + { > + .Ddr50 = 1, > + .HighSpeed = 1, > + .BusWidth = 8, > + .SlotType = EmbeddedSlot, > + .CardType = EmmcCardType, > + .BaseClkFreq = 100000 > + }, { > + .HighSpeed = 1, > + .BusWidth = 4, > + .SlotType = RemovableSlot, > + .CardType = SdCardType, > + .Voltage30 = 1, > + .BaseClkFreq = 100000 > + } > +}; > + > +EFI_STATUS > +EFIAPI > +HiKeyGetCapability ( > + IN EFI_HANDLE Controller, > + IN UINT8 Slot, > + OUT DW_MMC_HC_SLOT_CAP *Capability > + ) > +{ > + if (Capability == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + if (DwMmcCapability[0].Controller == 0) { > + DwMmcCapability[0].Controller = Controller; > + CopyMem (Capability, &DwMmcCapability[0], sizeof (DW_MMC_HC_SLOT_CAP)); > + } else if (DwMmcCapability[0].Controller == Controller) { > + CopyMem (Capability, &DwMmcCapability[0], sizeof (DW_MMC_HC_SLOT_CAP)); > + } else if (DwMmcCapability[1].Controller == 0) { > + DwMmcCapability[1].Controller = Controller; > + CopyMem (Capability, &DwMmcCapability[1], sizeof (DW_MMC_HC_SLOT_CAP)); > + } else if (DwMmcCapability[1].Controller == Controller) { > + CopyMem (Capability, &DwMmcCapability[1], sizeof (DW_MMC_HC_SLOT_CAP)); It looks to me like there are huge opportunities for reducing duplication between 960 version and this. I would suggest moving all of the common bits into a library and doing only the platform-specific registration here. / Leif > + } else { > + return EFI_INVALID_PARAMETER; > + } > + return EFI_SUCCESS; > +} > + > +BOOLEAN > +EFIAPI > +HiKeyCardDetect ( > + IN EFI_HANDLE Controller, > + IN UINT8 Slot > + ) > +{ > + EFI_STATUS Status; > + EMBEDDED_GPIO *Gpio; > + UINTN Value; > + > + if (DwMmcCapability[0].Controller == Controller) { > + return TRUE; > + } else if (DwMmcCapability[1].Controller == Controller) { > + Status = gBS->LocateProtocol (&gEmbeddedGpioProtocolGuid, NULL, (VOID **)&Gpio); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to get GPIO protocol: %r\n", Status)); > + return FALSE; > + } > + Status = Gpio->Set (Gpio, DETECT_SD_CARD, GPIO_MODE_INPUT); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to sed GPIO as input mode: %r\n", Status)); > + return FALSE; > + } > + Status = Gpio->Get (Gpio, DETECT_SD_CARD, &Value); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to get GPIO value: %r\n", Status)); > + return FALSE; > + } > + if (Value == 0) { > + return TRUE; > + } > + return FALSE; > + } > + return FALSE; > +} > + > +PLATFORM_DW_MMC_PROTOCOL mDwMmcDevice = { > + HiKeyGetCapability, > + HiKeyCardDetect > +}; > + > +EFI_STATUS > +EFIAPI > +HiKeyMmcEntryPoint ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + > + Status = gBS->InstallProtocolInterface ( > + &ImageHandle, > + &gPlatformDwMmcProtocolGuid, > + EFI_NATIVE_INTERFACE, > + &mDwMmcDevice > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + return Status; > +} > -- > 2.7.4 >