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::343; helo=mail-wm1-x343.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 B66622117FD5D for ; Wed, 31 Oct 2018 10:26:11 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id y144-v6so15231586wmd.4 for ; Wed, 31 Oct 2018 10:26:11 -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=sQfzfMRQMrAmQyVVAiX6NrOzgWKM+qUnEYOxLX+LePk=; b=LnEGwQMGuBHyv+5MKrX7OnpikSf+KZT5jX/qdvGpDplhIYGs9+CEO1FtRmx1NjUgUf YXp4ZnDSJx7jnIyoGChGAEn0EbmEp8ORtjN3U8r7HPGc067pkKFO1q4gaaFX6HreXw7q JCwA5EiPS8fs7CyM4n7+PRDoiw1OO0MAUct9s= 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=sQfzfMRQMrAmQyVVAiX6NrOzgWKM+qUnEYOxLX+LePk=; b=fRi4HPvzbcQzbxs/uvWiuqbV7VmCc82qVtDX3QFRqWBatCs36jDyC4dgRjXygPOaW+ s61HUuwOkDLdzDBhaiLZNXacPmj8uWBNT8M6Ai50bPTp7PuSZ5nZZygtN/ugzV/faOS8 rWoh/UzVYm/UCaGbA/h7yiaIDi9IuRpNGa/tP4plj34oVgwNFQNAeo8WB6oC++5AFdQ4 kTUTsIg900dlIMCpkWqoT6G0pYIalo/6OqqlPNnwSKBPUE1BGH+VcSRBLW21hnOxTgcQ mnQd4rZOQi2I5moWoUFdEjNmohUxVoyEHuRbwSQOaqy+eAxdszcHx81MwYnwP47pymIS 3u2A== X-Gm-Message-State: AGRZ1gJnYWlJ+xwN3VNaCUyPQTlOpon3uu5rNzwRg3YVQiddvfqwR+Ry MXyMK6OIGQmWwfGa25vqF3hVfU7dYB4= X-Google-Smtp-Source: AJdET5eiYeh7yTyuk5Fbfh58BBQBMdOpto4sTPA3/7M4y9hqvdBkQRM0cT3m9nFg6mpG4VI3ROo1wg== X-Received: by 2002:a1c:a342:: with SMTP id m63-v6mr3271533wme.54.1541006769768; Wed, 31 Oct 2018 10:26:09 -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 n76-v6sm9998429wmd.47.2018.10.31.10.26.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Oct 2018 10:26:08 -0700 (PDT) Date: Wed, 31 Oct 2018 17:26:07 +0000 From: Leif Lindholm To: Haojian Zhuang Cc: edk2-devel@lists.01.org, Ard Biesheuvel Message-ID: <20181031172606.se3epuy6xbnzw4rr@bivouac.eciton.net> References: <1534384166-15673-1-git-send-email-haojian.zhuang@linaro.org> <1534384166-15673-3-git-send-email-haojian.zhuang@linaro.org> MIME-Version: 1.0 In-Reply-To: <1534384166-15673-3-git-send-email-haojian.zhuang@linaro.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH v2 edk-platforms 2/3] Platform/HiKey960: enable SD controller 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:26:12 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Apologies for ridiculously slow response, On Thu, Aug 16, 2018 at 09:49:25AM +0800, Haojian Zhuang wrote: > Enable DwMmcHcDxe driver on HiKey960 platform. > > Cc: Leif Lindholm > Cc: Ard Biesheuvel > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Haojian Zhuang > --- > Platform/Hisilicon/HiKey960/HiKey960.dsc | 8 ++ > Platform/Hisilicon/HiKey960/HiKey960.fdf | 8 ++ > Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf | 1 + > Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf | 46 +++++++ > Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c | 15 +++ > Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.c | 125 ++++++++++++++++++++ > 6 files changed, 203 insertions(+) > > diff --git a/Platform/Hisilicon/HiKey960/HiKey960.dsc b/Platform/Hisilicon/HiKey960/HiKey960.dsc > index be13714b9c19..1ce306da5b50 100644 > --- a/Platform/Hisilicon/HiKey960/HiKey960.dsc > +++ b/Platform/Hisilicon/HiKey960/HiKey960.dsc > @@ -193,6 +193,14 @@ [Components.common] > # > EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf > > + # > + # MMC/SD > + # > + Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf > + EmbeddedPkg/Universal/NonDiscoverableDeviceDxe/NonDiscoverableDeviceDxe.inf > + EmbeddedPkg/Drivers/DwMmcHcDxe/DwMmcHcDxe.inf > + MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf > + > Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf > > # > diff --git a/Platform/Hisilicon/HiKey960/HiKey960.fdf b/Platform/Hisilicon/HiKey960/HiKey960.fdf > index d65f77878575..d4fe4c46b818 100644 > --- a/Platform/Hisilicon/HiKey960/HiKey960.fdf > +++ b/Platform/Hisilicon/HiKey960/HiKey960.fdf > @@ -128,6 +128,14 @@ [FV.FvMain] > # > INF EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf > > + # > + # MMC/SD > + # > + INF Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf > + INF EmbeddedPkg/Universal/NonDiscoverableDeviceDxe/NonDiscoverableDeviceDxe.inf > + INF EmbeddedPkg/Drivers/DwMmcHcDxe/DwMmcHcDxe.inf > + INF MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf > + > INF Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf > > # > diff --git a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf > index 54105bdb3c94..9d66c028832e 100644 > --- a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf > +++ b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf > @@ -33,6 +33,7 @@ [LibraryClasses] > CacheMaintenanceLib > DxeServicesTableLib > IoLib > + NonDiscoverableDeviceRegistrationLib > PcdLib > TimerLib > UefiBootManagerLib > diff --git a/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf b/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf > new file mode 100644 > index 000000000000..3e4bc807956e > --- /dev/null > +++ b/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf > @@ -0,0 +1,46 @@ > +#/** @file > +# > +# Copyright (c) 2018, 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. > +# > +# > +#**/ > + > +[Defines] > + INF_VERSION = 0x00010019 > + BASE_NAME = HiKey960MmcDxe > + FILE_GUID = e10d1dea-2f00-4eea-ac5d-9d6cfa7831a0 > + MODULE_TYPE = UEFI_DRIVER > + VERSION_STRING = 1.0 > + ENTRY_POINT = HiKey960MmcEntryPoint > + > +[Sources.common] > + HiKey960MmcDxe.c > + > +[LibraryClasses] > + DebugLib > + IoLib > + TimerLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + > +[Protocols] > + gEfiDriverBindingProtocolGuid > + gEmbeddedGpioProtocolGuid > + gPlatformDwMmcProtocolGuid > + > +[Packages] > + EmbeddedPkg/Drivers/DwMmcHcDxe/DwMmcHcDxe.dec > + EmbeddedPkg/EmbeddedPkg.dec > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec Swap order of the two above lines? > + Silicon/Hisilicon/Hi3660/Hi3660.dec > + > +[Depex] > + TRUE > diff --git a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c > index 47ec879861bd..75627d5d6665 100644 > --- a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c > +++ b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -33,6 +34,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -447,6 +449,19 @@ HiKey960EntryPoint ( > return Status; > } > > + Status = RegisterNonDiscoverableMmioDevice ( > + NonDiscoverableDeviceTypeSdhci, > + NonDiscoverableDeviceDmaTypeNonCoherent, > + NULL, > + NULL, > + 1, Can you either make a #define or add a comment explaining why there's a live-coded integer here? > + 0xFF37F000, // SD And could you add the appropriate #defines to Silicon/Hisilicon/Hi3660/Include/Hi3660.h and use that instead? > + SIZE_4KB > + ); > + if (EFI_ERROR (Status)) { > + return Status; > + } > + > Status = gBS->InstallProtocolInterface ( > &ImageHandle, > &gPlatformVirtualKeyboardProtocolGuid, > diff --git a/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.c b/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.c > new file mode 100644 > index 000000000000..0a2b60edf352 > --- /dev/null > +++ b/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.c > @@ -0,0 +1,125 @@ > +/** @file > +* > +* Copyright (c) 2018, 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 203 // GPIO 25_3 And could you move this to a local .h file? > + > +DW_MMC_HC_SLOT_CAP Where is this struct defined? > +DwMmcCapability[] = { 'm' prefix for global variable. And STATIC unless it is intended for use outside this file. > + { > + .HighSpeed = 1, > + .BusWidth = 4, > + .SlotType = RemovableSlot, > + .CardType = SdCardType, > + .Voltage30 = 1, > + .BaseClkFreq = 3200 > + } > +}; > + > +EFI_STATUS > +EFIAPI > +HiKey960GetCapability ( > + IN EFI_HANDLE Controller, > + IN UINT8 Slot, > + OUT DW_MMC_HC_SLOT_CAP *Capability Is the placement of that OUT intentional? I don't think I've seen that before, but it sort of makes sense. > + ) > +{ > + if (Capability == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + if (DwMmcCapability[0].Controller == 0) { Pretty sure that should be NULL? Why is DwMmcCapability being treated as a single-entry array? And why is Slot ignored? / Leif > + 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 { > + return EFI_INVALID_PARAMETER; > + } > + return EFI_SUCCESS; > +} > + > +BOOLEAN > +EFIAPI > +HiKey960CardDetect ( > + IN EFI_HANDLE Controller, > + IN UINT8 Slot > + ) > +{ > + EFI_STATUS Status; > + EMBEDDED_GPIO *Gpio; > + UINTN Value; > + > + if (Slot == 0) { > + Status = gBS->LocateProtocol (&gEmbeddedGpioProtocolGuid, NULL, (VOID **)&Gpio); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to get GPIO protocol: %r\n", Status)); > + goto Exit; > + } > + 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)); > + goto Exit; > + } > + Status = Gpio->Get (Gpio, DETECT_SD_CARD, &Value); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed to get GPIO value: %r\n", Status)); > + goto Exit; > + } > + if (Value == 0) { > + return TRUE; > + } > + } > +Exit: > + return FALSE; > +} > + > +PLATFORM_DW_MMC_PROTOCOL mDwMmcDevice = { > + HiKey960GetCapability, > + HiKey960CardDetect > +}; > + > +EFI_STATUS > +EFIAPI > +HiKey960MmcEntryPoint ( > + 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 >