From patchwork Sat Apr 28 05:24:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 134642 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1507477lji; Fri, 27 Apr 2018 22:24:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpot6xEIwxWkhdVCOLrfdfl/ipUdLzR5AJaX9CPygVVk5kupOV6VjPS4QoHABaifFh0wK7U X-Received: by 2002:a17:902:595e:: with SMTP id e30-v6mr4750171plj.233.1524893070668; Fri, 27 Apr 2018 22:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524893070; cv=none; d=google.com; s=arc-20160816; b=BYBswZFGU+1DZbTqakz1WSb2O6dWd/Sjyxo2eLoG8TrEBsbKSiUUGTWNRlyxyvOUbg cF98u+RmyU4TSStieMs3jWH4Xq4SB+Idz+ZQXf9CJrzJcVtBG2TBNYCNLJGn3FAHnu4D WFHOCK5MoGa5XudWcUwM8vkS3X8wq+ThLsnZxtSj9ZSALgjK8r2WpRdBkzJ4PVPRmcNx q+HztP+8v3u6jAaGm5Mud3mvCXCTFDcbx5yuIE3zQEutPJFfHr2vInlT+dGhRnGJPXBK 7eTYtIh3uaAedxf1qMDIUqjMVvvgpJnj3zSwNX8SmsObD/pWdDpgF8rM0QYpmrx7YywV waQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=bkOHNIBh5A8aVl9JpgJmn2oAhm+dN3Gh3TSP1j/ppcM=; b=zfpVHLFg9wH412+7XqZq65x8J5YYwRdTumrzssiGklZ23W7Z4T/913Z85ADzMbisVW D+tUBWIwUi42meyN37/KgcFQR9YHUrN8krW8vMFtmc8BZGdt4RobgqqOuPS6eHwcptKw cgYpLegSESQNyXCxqI8USH+6RNHKeC+4zHaKaSugOAUcunA1HQNlZinK+yqBjrenIuIJ VSI02gw1OM2YxmDxQ545wcArXDvtw7kYbaMh2tKle39YafUzphiUHFDTXEgFe8Y9AdfB VMJNkLgioHGIig7xwe80oOPc3Mx7bkX+07qbQb/ZTclxTK5Y2nL4QV+rcSffSfMNcWgV X4Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N1GTRlaa; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id b65-v6si2480963pgc.325.2018.04.27.22.24.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 22:24:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N1GTRlaa; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 351122034C8A6; Fri, 27 Apr 2018 22:24:30 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::241; helo=mail-pg0-x241.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::241]) (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 190E9207DF47A for ; Fri, 27 Apr 2018 22:24:28 -0700 (PDT) Received: by mail-pg0-x241.google.com with SMTP id l2-v6so2954088pgc.7 for ; Fri, 27 Apr 2018 22:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=0RE/xnE0yr8zv0ckO+R9+sOdYbSpPXJBkEzO8xMOQpI=; b=N1GTRlaaoM68kJsoph+E0YKOFX8fq5IZ7jqpQfCZxc02gDgM2Mv6LM2qt17tfqyvmz qQ0C5frcDnHqe1//C3DOTQ7QxRrPHBLEBX9lPGAwR2p3+QsH5NaVI73A+D2CK9Vb7uqD 6WpJ4Do8srRw0QtcCeESgtoX2QakKTMsiAcg4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0RE/xnE0yr8zv0ckO+R9+sOdYbSpPXJBkEzO8xMOQpI=; b=p0KYd+q7LB/6seUEI0y+yF5goS0GBScG/pt2kN3+DgOfOgLqNhKjBOtZg6r9AJHSAE Ik/gNoIWdYFjw8y4vMz8ZzNvbwnk/hkfIyhjN8oan/oohOb/MSlrNtn39rlsq19Jgq8m 3nzPhh5DwI1L8FfQmXLqB+OT1L2YreH/r2V4DjAxpRPBYAoseboz1Y4a+Cq7F6z7kf6h uTCQ9lYsILwnp/FDf9SP7o0wG+LF0nF30Ez3DXcaE9pmgs08p06JHC6XViZrsEgRIyPH IQwYMx7HQvOb5ytERFpGUmRNAs8T8Yq5oY3TT1mDHX+lX1Ql86ZerhNxZK97hVIsAzpO 4+vA== X-Gm-Message-State: ALQs6tAjzdiensugXGxzaJRVehYalolP4YjoU9LYAccuvNjY8ddkfHnZ JWmtRxoRrguoCGW6Z8X2iobx1jZF5aw= X-Received: by 2002:a17:902:5ac1:: with SMTP id g1-v6mr4811730plm.43.1524893068227; Fri, 27 Apr 2018 22:24:28 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.61]) by smtp.gmail.com with ESMTPSA id o64sm5196892pfb.62.2018.04.27.22.24.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Apr 2018 22:24:27 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Sat, 28 Apr 2018 13:24:20 +0800 Message-Id: <1524893061-3080-1-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [PATCH edk2-platforms 1/2] Platform/HiKey: enable SD/MMC controller on HiKey X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haojian Zhuang , Leif Lindholm , Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 | 19 ++- Platform/Hisilicon/HiKey/HiKey.fdf | 15 ++- Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c | 26 ++++ Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf | 1 + Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.c | 139 +++++++++++++++++++++ .../Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf | 45 +++++++ 6 files changed, 228 insertions(+), 17 deletions(-) create mode 100644 Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.c create mode 100644 Platform/Hisilicon/HiKey/HiKeyMmcDxe/HiKeyMmcDxe.inf -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/HiKey/HiKey.dsc b/Platform/Hisilicon/HiKey/HiKey.dsc index 9c1fc2e1b40d..0635e16c4141 100644 --- a/Platform/Hisilicon/HiKey/HiKey.dsc +++ b/Platform/Hisilicon/HiKey/HiKey.dsc @@ -69,7 +69,7 @@ [LibraryClasses.common.SEC] PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf [BuildOptions] - GCC:*_*_*_PLATFORM_FLAGS = -I$(WORKSPACE)/Silicon/Hisilicon/Hi6220/Include -I$(WORKSPACE)/Platform/Hisilicon/HiKey/Include + GCC:*_*_*_PLATFORM_FLAGS = -I$(WORKSPACE)/Silicon/Hisilicon/Hi6220/Include -I$(WORKSPACE)/Platform/Hisilicon/HiKey/Include -I$(WORKSPACE)/ArmPkg/Include -I$(WORKSPACE)/EmbeddedPkg/Include ################################################################################ # @@ -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 + MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.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..afc6a1a6e6e1 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 MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.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.c b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c index fec43f3fb4c1..5f1904cec805 100644 --- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -378,6 +379,31 @@ HiKeyEntryPoint ( return Status; } + Status = RegisterNonDiscoverableMmioDevice ( + NonDiscoverableDeviceTypeSdhci, + NonDiscoverableDeviceDmaTypeNonCoherent, + NULL, + NULL, + 1, + 0xF723D000, // eMMC + SIZE_4KB + ); + if (EFI_ERROR (Status)) { + return Status; + } + Status = RegisterNonDiscoverableMmioDevice ( + NonDiscoverableDeviceTypeSdhci, + NonDiscoverableDeviceDmaTypeNonCoherent, + NULL, + NULL, + 1, + 0xF723E000, // SD + SIZE_4KB + ); + if (EFI_ERROR (Status)) { + return Status; + } + Status = gBS->InstallProtocolInterface ( &ImageHandle, &gPlatformVirtualKeyboardProtocolGuid, diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf index e97afab8785a..a217e2fb7033 100644 --- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf @@ -37,6 +37,7 @@ [LibraryClasses] DxeServicesTableLib FdtLib IoLib + NonDiscoverableDeviceRegistrationLib PcdLib PrintLib SerialPortLib 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 + +DW_MMC_HC_SLOT_CAP +DwMmcCapability[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)); + } 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; +} 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. +# +# 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 + OpenPlatformPkg/Drivers/SdMmc/DwMmcHcDxe/DwMmcHcDxe.dec + +[Depex] + TRUE From patchwork Sat Apr 28 05:24:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 134643 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1507505lji; Fri, 27 Apr 2018 22:24:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrSy1ZzT74+8E5PKVwXPepX/zfGplMT+rr82rXwIamTyl2lgahU3NHhdSKaV+MyD1ofiEs6 X-Received: by 2002:a17:902:bd0a:: with SMTP id p10-v6mr4850030pls.69.1524893073738; Fri, 27 Apr 2018 22:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524893073; cv=none; d=google.com; s=arc-20160816; b=vPmd8WRJpX17OXktyIdC0PI7q8mm3K910sOnFibEmzqzMy0prBq3JMXXnMy9m163kO /bF5y09NU8a6KkoMbOfBJFAyDQe31J4wUTKji58A1d/hdkWvVXmX9EZlKNF3BsIZBP7F GSiO4jY3GlDWHso7bR8om96l0oBdpvPlg52eavX3Qyhcg5Evxfe0mtmwU3/syicqWnqO m/NvI5+3BkI6PEG35/nYrcBuFUGSeK1f79Kyw34+8tc80fa3rsK/g3H4PxHE8CRoMkH5 Ush/8X3ghEoQ4O7WF5v059NkOuhcw/FS1mwluy+m1lziACWtn7qtq96GLLi6h8Uv07r6 obTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=uCO7PHlzfm3+rGnjzy1JbWDiPqNEx4hyxrhZBXZP/w8=; b=y6L41to/gL9hyPRQvrEfhWGHp+kpclPhJVIDaBTVi6cxdDCXGuzOl+ztlZAlihUCtz yxvA+M5g4e3RKj7gUVAuq2lmKBkhc25+0674Ht4eRkwZmLyuwI7e+bG88DF0KUC1315H 75seziNr8Fa0FanF9HRZXIJHGrDcljlxpM44fSIhIbg/biH28XhBvZBh8Zi9aaluxAN4 Hz9HvClxKkX7h3H2lp0UzRkGT8slYwbd4GYE9ldWSDoI7HLW+6NytgMdKLVXMEtGO/gR hmN98verPQvzRQ043+p4XHaJ5SaM6xJbUZb/n3oUr4IPeEgIRYNblIsJcCqqjI1V0rsL sTcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dhp+V/Mo; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id r7-v6si2752949ple.585.2018.04.27.22.24.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 22:24:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dhp+V/Mo; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5EC012034C8BE; Fri, 27 Apr 2018 22:24:33 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c00::241; helo=mail-pf0-x241.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (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 E5468207DF47A for ; Fri, 27 Apr 2018 22:24:31 -0700 (PDT) Received: by mail-pf0-x241.google.com with SMTP id a11so2944871pfn.9 for ; Fri, 27 Apr 2018 22:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LJuvtLhx0XYE7ZqXmUyLNJa4EKjrsVJdhssAy2I57fY=; b=dhp+V/MoijpI1x2DZ+QLL4Wu0WgtWKvs/eWTJSMIfc1bu3xtAAqQWVU8J+tCYst+yH O+pe+nJ9rjDN6HMm4gPyS7dlkZfB62cUmgL82E4uTNjz1+IXIFBREjApH/WGgm9kKNyA NZR1HInznvBMezYLKlCCCl76CSe41pmopc6xI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LJuvtLhx0XYE7ZqXmUyLNJa4EKjrsVJdhssAy2I57fY=; b=kzuWwuVXvWN1Gbp8ZHf2UU2+yDsnj+3Uhb7197AZbh6P9rBgUbJLB8RMULId/K87OP D5MAT2ohX48vCJmb6WX4gOVSXg6lHyCD7X76R10ptqOanQglXCXev10K6T141f5HxXWI 734MyN/NRqSimg40EGOIP/J+Z0oOdrGP982acPa2COLrS0AmgoPMMn5ai4dsakqbzjBK cOlWwP7PqVfjtIVrHWuVFVjY56EC45A4shzxZ6zWLmqzKTGtjtK6khE6NUDPMRtBibI8 F7wi2WWnI+pkLttXK4NixpoYhKXJINepEEjmATjqZ4GQiStfVOTDwvHC+a5lRSFJinyx 2fnA== X-Gm-Message-State: ALQs6tAqqr4wVuBoAdFbGttx+Ftub1KgOfBE0kkOngBZcigl1OdXTAl1 2X39rX3JFtOdvAkJmfml+qty7BZ1m34= X-Received: by 2002:a63:9557:: with SMTP id t23-v6mr4176891pgn.77.1524893071131; Fri, 27 Apr 2018 22:24:31 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.61]) by smtp.gmail.com with ESMTPSA id o64sm5196892pfb.62.2018.04.27.22.24.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Apr 2018 22:24:30 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Sat, 28 Apr 2018 13:24:21 +0800 Message-Id: <1524893061-3080-2-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524893061-3080-1-git-send-email-haojian.zhuang@linaro.org> References: <1524893061-3080-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk2-platforms 2/2] Platform/HiKey960: enable SD controller X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haojian Zhuang , Leif Lindholm , Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 | 10 +- Platform/Hisilicon/HiKey960/HiKey960.fdf | 8 ++ .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c | 13 +++ .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf | 1 + .../HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.c | 125 +++++++++++++++++++++ .../HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf | 45 ++++++++ 6 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.c create mode 100644 Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/HiKey960/HiKey960.dsc b/Platform/Hisilicon/HiKey960/HiKey960.dsc index 4097fbfd77f5..646de759d46c 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960.dsc +++ b/Platform/Hisilicon/HiKey960/HiKey960.dsc @@ -69,7 +69,7 @@ [LibraryClasses.common.SEC] PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf [BuildOptions] - GCC:*_*_*_PLATFORM_FLAGS = -I$(WORKSPACE)/Silicon/Hisilicon/Hi3660/Include + GCC:*_*_*_PLATFORM_FLAGS = -I$(WORKSPACE)/Silicon/Hisilicon/Hi3660/Include -I$(WORKSPACE)/ArmPkg/Include -I$(WORKSPACE)/EmbeddedPkg/Include ################################################################################ # @@ -196,6 +196,14 @@ [Components.common] # EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf + # + # MMC/SD + # + Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf + MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.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..61fd9121ac3e 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 MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.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.c b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c index b6a88daf4f99..cc27f0b9c8f8 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c +++ b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c @@ -641,6 +641,19 @@ HiKey960EntryPoint ( return Status; } + Status = RegisterNonDiscoverableMmioDevice ( + NonDiscoverableDeviceTypeSdhci, + NonDiscoverableDeviceDmaTypeNonCoherent, + NULL, + NULL, + 1, + 0xFF37F000, // SD + SIZE_4KB + ); + if (EFI_ERROR (Status)) { + return Status; + } + Status = gBS->InstallProtocolInterface ( &ImageHandle, &gPlatformVirtualKeyboardProtocolGuid, diff --git a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf index 5adedd79d3e8..56836590ddea 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf +++ b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf @@ -34,6 +34,7 @@ [LibraryClasses] DxeServicesTableLib FdtLib IoLib + NonDiscoverableDeviceRegistrationLib PcdLib PrintLib SerialPortLib 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 + +DW_MMC_HC_SLOT_CAP +DwMmcCapability[] = { + { + .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 + ) +{ + 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 { + 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; +} diff --git a/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf b/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf new file mode 100644 index 000000000000..fabafaf479ba --- /dev/null +++ b/Platform/Hisilicon/HiKey960/HiKey960MmcDxe/HiKey960MmcDxe.inf @@ -0,0 +1,45 @@ +#/** @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 + +[Depex] + TRUE