From nobody Tue Apr 16 21:08:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51545+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51545+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1575307003; cv=none; d=zohomail.com; s=zohoarc; b=Fqch8MHlAYgzZBzuQaUkDgrzKOLLRoL9div+dF0dL8MOqHB3D1x5AsOI0oWBXlKw3xdqfORrxPVXKJWGoe0KOPCaIKa4A4jd6MiGWn7INkKBdYebnKx+AqUOcF/rHY11NkGmT0Xheo5d9vFR+9Az4I47+Nyi7agEHh3DZ21SumM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575307003; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5PzrkP4c2A7p1KV6yDPiIMFlCCO6EozGSU2ZZTFi5i8=; b=JQ177xFR0duNLp55uT3d/nt2PMcQpTxhsHoYJnefPBC5CHehyo+9SSrF4rqNEML1+vzP9q0MNJTsOd/LmeAj1R6GnM55kF17ywFnpNuF+VQba/8bR4H/rO0XTkpWAK2PO6Ke/2LHMsxtW/vdBqPG1ExQ84AHeCeUDKTJxXYCXqE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51545+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1575307003652432.06558278252703; Mon, 2 Dec 2019 09:16:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Mon, 02 Dec 2019 09:16:42 -0800 X-Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.groups.io with SMTP id smtpd.web12.4237.1575307001845958514 for ; Mon, 02 Dec 2019 09:16:42 -0800 X-Received: by mail-wm1-f48.google.com with SMTP id p9so75359wmc.2 for ; Mon, 02 Dec 2019 09:16:41 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqxlaqbULvpimlwXKJE5mFQhqTUC/hgZqWOXOh98XU+8FQy716u13IkMyw7wHTZUp3oksRKpuQ== X-Received: by 2002:a7b:c055:: with SMTP id u21mr30758404wmc.55.1575306998419; Mon, 02 Dec 2019 09:16:38 -0800 (PST) X-Received: from localhost.localdomain ([84.203.45.230]) by smtp.gmail.com with ESMTPSA id 205sm496035wmb.3.2019.12.02.09.16.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2019 09:16:37 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH v2 1/3] Platform/RPi/MmcDxe: Factorize SCR call and clean up MMC init Date: Mon, 2 Dec 2019 17:16:20 +0000 Message-Id: <20191202171622.10980-2-pete@akeo.ie> In-Reply-To: <20191202171622.10980-1-pete@akeo.ie> References: <20191202171622.10980-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1575307002; bh=hrFcM+bEun2QMr1/nkGYKEE8hcx8ftiDSd8FHmaeObo=; h=Cc:Date:From:Reply-To:Subject:To; b=g/LkisU6/YofyH3dhnEBeZa7Qb06EtbeOvZT/4IMD8PQZRBe/2ca9RwpAta0uyf+s3H BAHkLEPMrQU+eVp1UdRF4O+NXCqtCkmolX7ZnE+wmZsGcUJihF6z1o0xiMGE52O5grG52 pxJ7fWzXsh9NDCfMlnkspQSPNs27SA19FME= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Andrei Warkentin This is mostly a maintainability improvement for the InitializeSdMmcDevice () call achieved by factorizing the code related to SCR execution into a new SdExecuteScr () call. Signed-off-by: Pete Batard Reviewed-by: Ard Biesheuvel --- Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c | 105 ++++++++++++= -------- 1 file changed, 62 insertions(+), 43 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c b/Plat= form/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c index 4ee5c5ca6fb2..34a97e954220 100644 --- a/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c +++ b/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c @@ -1,5 +1,6 @@ /** @file * + * Copyright (c) 2019, Andrei Warkentin * Copyright (c) 2011-2015, ARM Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -567,6 +568,48 @@ SdSetSpeed ( return EFI_SUCCESS; } =20 +STATIC +EFI_STATUS +SdExecuteScr ( + IN MMC_HOST_INSTANCE *MmcHostInstance, + OUT SCR *Scr + ) +{ + EFI_STATUS Status; + UINT32 Response[4]; + EFI_MMC_HOST_PROTOCOL *MmcHost =3D MmcHostInstance->MmcHost; + + Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD55, + MmcHostInstance->CardInfo.RCA << 16); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); + return Status; + } + Status =3D MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Resp= onse); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); + return Status; + } + if ((Response[0] & MMC_STATUS_APP_CMD) =3D=3D 0) { + return EFI_SUCCESS; + } + + /* SCR */ + Status =3D MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): Error and Status =3D %r\n", __fu= nc__, Status)); + return Status; + } + + Status =3D MmcHost->ReadBlockData (MmcHost, 0, 8, (VOID *) Scr); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status = =3D %r\n", __func__, Status)); + return Status; + } + + return EFI_SUCCESS; +} + STATIC EFI_STATUS InitializeSdMmcDevice ( @@ -574,7 +617,6 @@ InitializeSdMmcDevice ( ) { UINT32 Response[4]; - UINT32 Buffer[128]; UINTN BlockSize; UINTN CardSize; UINTN NumBlocks; @@ -621,58 +663,35 @@ InitializeSdMmcDevice ( return Status; } =20 - Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD55, - MmcHostInstance->CardInfo.RCA << 16); + Status =3D SdExecuteScr (MmcHostInstance, &Scr); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); - return Status; - } - Status =3D MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Resp= onse); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status =3D %r\n", __FU= NCTION__, Status)); - return Status; - } - if ((Response[0] & MMC_STATUS_APP_CMD) =3D=3D 0) { - return EFI_SUCCESS; + return Status; } =20 - /* SCR */ - Status =3D MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): Error and Status =3D %r\n", __fu= nc__, Status)); - return Status; - } else { - Status =3D MmcHost->ReadBlockData (MmcHost, 0, 8, Buffer); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status= =3D %r\n", __func__, Status)); - return Status; - } - CopyMem (&Scr, Buffer, 8); - if (Scr.SD_SPEC =3D=3D 2) { - if (Scr.SD_SPEC3 =3D=3D 1) { - if (Scr.SD_SPEC4 =3D=3D 1) { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 4.xx\n")); - } else { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 3.0x\n")); - } + if (Scr.SD_SPEC =3D=3D 2) { + if (Scr.SD_SPEC3 =3D=3D 1) { + if (Scr.SD_SPEC4 =3D=3D 1) { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 4.xx\n")); } else { - if (Scr.SD_SPEC4 =3D=3D 0) { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 2.0\n")); - } else { - DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n")); - } + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 3.0x\n")); } } else { - if ((Scr.SD_SPEC3 =3D=3D 0) && (Scr.SD_SPEC4 =3D=3D 0)) { - if (Scr.SD_SPEC =3D=3D 1) { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.10\n")); - } else { - DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.0\n")); - } + if (Scr.SD_SPEC4 =3D=3D 0) { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 2.0\n")); } else { DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n")); } } + } else { + if ((Scr.SD_SPEC3 =3D=3D 0) && (Scr.SD_SPEC4 =3D=3D 0)) { + if (Scr.SD_SPEC =3D=3D 1) { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.10\n")); + } else { + DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.0\n")); + } + } else { + DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n")); + } } =20 Status =3D SdSetSpeed (MmcHostInstance, CccSwitch); --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51545): https://edk2.groups.io/g/devel/message/51545 Mute This Topic: https://groups.io/mt/65063354/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 16 21:08:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51546+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51546+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1575307003; cv=none; d=zohomail.com; s=zohoarc; b=gxJxDnP7eIG0qh3OpG1YLHWQW3zpgO88nvq6gn/MPbtWS1ucLoWxpx85wMbgVAhd3/qGAZYkLvCVsU94OPjD8vx4SajaPBTO11Zpl79HNUeKeICCT/OjrNfhGe9NCf2AsshytB3IAwTt11qfPha2bgjdl/Kni/Rb/jWa36lxG1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575307003; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5pdzo63/rTRF9NSa1OM0JqG1p9rL7h0eobLO35878Mc=; b=mNwj5R6cElZC2eyNPNxTf086VcWi7IeYW/SM/nZZZFAE0cOizEOy3mrOxrDBFYNFW2tTZXuqhD6GK78fE9icwDFFkoEZIl2JR+GqJdzYszAWHrXIBZzVV/8IfFcj6zkkL6GsZ4uZ8H9SSTvCHDMJaAWCJr7W4Wc+RRM87YTP12o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51546+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1575307003579822.3200081905237; Mon, 2 Dec 2019 09:16:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Mon, 02 Dec 2019 09:16:43 -0800 X-Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web10.4345.1575307002183637071 for ; Mon, 02 Dec 2019 09:16:42 -0800 X-Received: by mail-wr1-f65.google.com with SMTP id q10so721wrm.11 for ; Mon, 02 Dec 2019 09:16:41 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqztbcvon1rDSBnB9GV1+n1DjEunPqH3OO2p5KwF8AaigZGLaPJYUC8lv7Fd/JlESOxL9SSjdA== X-Received: by 2002:adf:fd91:: with SMTP id d17mr15992354wrr.340.1575307000270; Mon, 02 Dec 2019 09:16:40 -0800 (PST) X-Received: from localhost.localdomain ([84.203.45.230]) by smtp.gmail.com with ESMTPSA id 205sm496035wmb.3.2019.12.02.09.16.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2019 09:16:39 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH v2 2/3] Platform/RPi/MmcDxe: Improve MMC driver stability Date: Mon, 2 Dec 2019 17:16:21 +0000 Message-Id: <20191202171622.10980-3-pete@akeo.ie> In-Reply-To: <20191202171622.10980-1-pete@akeo.ie> References: <20191202171622.10980-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1575307003; bh=3iH6jk5uSlwN0T+2At5hGK2aYe7hHX/U8696JkfRSAc=; h=Cc:Date:From:Reply-To:Subject:To; b=Z1KISt7L6ob6/zrjzGebS8i+9DchCm9K5LimnUw6ayPmGZIxGJN39mDL0MXPUgYZzUM A8l50E3g9WdkY9d1so3MqvjVKe4R7MYfEle1Rkpb2I3X7ks5lsBLRt/UbWo69ENNzOEFz pnZxgNOfl3UBuisX/k03jom93etF9UA/ivw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Andrei Warkentin For reasons that aren't entirely understood, SCR reads can randomly fail on the Raspberry Pi 4. It can be on the first boot or during subsequent reboots. To alleviate this, and improve the overall behavior of the code, we modify CheckCardsCallback () to retry InitializeMmcDevice () in case of failure. Signed-off-by: Pete Batard Reviewed-by: Ard Biesheuvel --- Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c b/Platform/Raspberry= Pi/Drivers/MmcDxe/Mmc.c index c3c7279e4707..f6c4cc7bc3a3 100644 --- a/Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c +++ b/Platform/RaspberryPi/Drivers/MmcDxe/Mmc.c @@ -2,6 +2,7 @@ * * Main file of the MMC Dxe driver. The driver entrypoint is defined into= this file. * + * Copyright (c) 2019, Andrei Warkentin * Copyright (c) 2011-2013, ARM Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -367,7 +368,11 @@ CheckCardsCallback ( MmcHostInstance->Initialized =3D !MmcHostInstance->Initialized; =20 if (MmcHostInstance->BlockIo.Media->MediaPresent) { - InitializeMmcDevice (MmcHostInstance); + Status =3D InitializeMmcDevice (MmcHostInstance); + if (EFI_ERROR (Status)) { + MmcHostInstance->Initialized =3D !MmcHostInstance->Initialized; + continue; + } } =20 Status =3D gBS->ReinstallProtocolInterface ( --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51546): https://edk2.groups.io/g/devel/message/51546 Mute This Topic: https://groups.io/mt/65063358/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Tue Apr 16 21:08:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+51547+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51547+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1575307005; cv=none; d=zohomail.com; s=zohoarc; b=bF4G3f9OsKogszlLttfGTtvWCfAOJ7zIGie7RAEbFdG+b1eVoUCF7VIasGwTxaxDB5jk1UGjaWKsOesaveL9KF/lymfGiGW0DvCge46XIg9IcquokZfVzYUFBCo+ck+m058jRyIf9wK6nfuu5mJO+/0fRjPGaQxZgo+17GqhHgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575307005; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=HTexUvuOCmxYE2Q59gO/lkzG0M4yzkGDJn6gk3V8z3s=; b=KYcBuM4awBVQ/UHv6A5Ip81wWmdZRiziZ712y+yHWbTJFWu+wOJ27SGwI/AXFQEYxkM7/5ZNuPu5o0gb23hIEWnW8Nx4fuFzAYFB0Ub2wdaOW9Bx0B3kwannBqKb6ihFHq7+KD6nlRwm3ZPpS2cUbZYBDPYKkrZqjyfN/aUXx3I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+51547+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1575307005913991.5320195840071; Mon, 2 Dec 2019 09:16:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Mon, 02 Dec 2019 09:16:45 -0800 X-Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.groups.io with SMTP id smtpd.web10.4347.1575307004630821218 for ; Mon, 02 Dec 2019 09:16:45 -0800 X-Received: by mail-wm1-f67.google.com with SMTP id f129so181843wmf.2 for ; Mon, 02 Dec 2019 09:16:44 -0800 (PST) X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= X-Google-Smtp-Source: APXvYqwq/wefhMiIn/hmvodO7DSIk3CGMVo+NwzcTW6RJNiAaOzJaOyvIavCPFvBFsh5ha2/QnAKVg== X-Received: by 2002:a05:600c:1051:: with SMTP id 17mr29264607wmx.49.1575307002362; Mon, 02 Dec 2019 09:16:42 -0800 (PST) X-Received: from localhost.localdomain ([84.203.45.230]) by smtp.gmail.com with ESMTPSA id 205sm496035wmb.3.2019.12.02.09.16.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2019 09:16:41 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, samer.el-haj-mahmoud@arm.com, andrey.warkentin@gmail.com Subject: [edk2-devel] [edk2-platforms][PATCH v2 3/3] Platform/RPi: Set SD routing according to model Date: Mon, 2 Dec 2019 17:16:22 +0000 Message-Id: <20191202171622.10980-4-pete@akeo.ie> In-Reply-To: <20191202171622.10980-1-pete@akeo.ie> References: <20191202171622.10980-1-pete@akeo.ie> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pete@akeo.ie Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1575307005; bh=2FysQEWvlNgBToCt4aKI+HqBEYBPQIaOl7S/bsBoULk=; h=Cc:Date:From:Reply-To:Subject:To; b=FAhac1AR339xAJhSyOoW+aGPBFh3g7AuEDTq1O7FbQyc9Kgw3pbw6Fv9XRIHJeQF3XB l8EYrouel6j/QZMILbQUB58jmiQaXsGvHqbOR109wqnLmzozsh3xd/2o5hXYUQRl1LP07 C12Kns8f+MSmkRCedq72t6IhIZ12xaTVmHY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Samer El-Haj-Mahmoud The Raspberry Pi 4 has a new SD controller. As a result we must handle SD routing according to the model, which we perform in the Config driver by using the GetModelFamily () call that was recently introduced. Signed-off-by: Pete Batard Reviewed-by: Ard Biesheuvel --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 137 ++++++++++++++---= --- 1 file changed, 96 insertions(+), 41 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index 98e58a560ed4..f92ac709a3d8 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -1,6 +1,7 @@ /** @file * - * Copyright (c) 2018, Andrei Warkentin + * Copyright (c) 2019, ARM Limited. All rights reserved. + * Copyright (c) 2018 - 2019, Andrei Warkentin * * SPDX-License-Identifier: BSD-2-Clause-Patent * @@ -9,10 +10,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -212,6 +215,7 @@ ApplyVariables ( UINT32 CpuClock =3D PcdGet32 (PcdCpuClock); UINT32 CustomCpuClock =3D PcdGet32 (PcdCustomCpuClock); UINT32 Rate =3D 0; + UINT32 ModelFamily =3D 0; =20 if (CpuClock !=3D 0) { if (CpuClock =3D=3D 2) { @@ -245,51 +249,102 @@ ApplyVariables ( DEBUG ((DEBUG_INFO, "Current CPU speed is %uHz\n", Rate)); } =20 - /* - * Switching two groups around, so disable both first. - * - * No, I've not seen a problem, but having a group be - * routed to two sets of pins seems like asking for trouble. - */ - GpioPinFuncSet (34, GPIO_FSEL_INPUT); - GpioPinFuncSet (35, GPIO_FSEL_INPUT); - GpioPinFuncSet (36, GPIO_FSEL_INPUT); - GpioPinFuncSet (37, GPIO_FSEL_INPUT); - GpioPinFuncSet (38, GPIO_FSEL_INPUT); - GpioPinFuncSet (39, GPIO_FSEL_INPUT); - GpioPinFuncSet (48, GPIO_FSEL_INPUT); - GpioPinFuncSet (49, GPIO_FSEL_INPUT); - GpioPinFuncSet (50, GPIO_FSEL_INPUT); - GpioPinFuncSet (51, GPIO_FSEL_INPUT); - GpioPinFuncSet (52, GPIO_FSEL_INPUT); - GpioPinFuncSet (53, GPIO_FSEL_INPUT); - if (PcdGet32 (PcdSdIsArasan)) { - DEBUG ((DEBUG_INFO, "Routing SD to Arasan\n")); - Gpio48Group =3D GPIO_FSEL_ALT3; + Status =3D mFwProtocol->GetModelFamily (&ModelFamily); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi model family: %r\n= ", Status)); + } else { + DEBUG ((DEBUG_INFO, "Current Raspberry Pi model family is 0x%x\n", Mod= elFamily)); + } + + + if (ModelFamily =3D=3D 3) { /* - * Route SDIO to SdHost. + * Pi 3: either Arasan or SdHost goes to SD card. + * + * Switching two groups around, so disable both first. + * + * No, I've not seen a problem, but having a group be + * routed to two sets of pins seems like asking for trouble. */ - Gpio34Group =3D GPIO_FSEL_ALT0; - } else { - DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n")); - Gpio48Group =3D GPIO_FSEL_ALT0; + GpioPinFuncSet (34, GPIO_FSEL_INPUT); + GpioPinFuncSet (35, GPIO_FSEL_INPUT); + GpioPinFuncSet (36, GPIO_FSEL_INPUT); + GpioPinFuncSet (37, GPIO_FSEL_INPUT); + GpioPinFuncSet (38, GPIO_FSEL_INPUT); + GpioPinFuncSet (39, GPIO_FSEL_INPUT); + GpioPinFuncSet (48, GPIO_FSEL_INPUT); + GpioPinFuncSet (49, GPIO_FSEL_INPUT); + GpioPinFuncSet (50, GPIO_FSEL_INPUT); + GpioPinFuncSet (51, GPIO_FSEL_INPUT); + GpioPinFuncSet (52, GPIO_FSEL_INPUT); + GpioPinFuncSet (53, GPIO_FSEL_INPUT); + + if (PcdGet32 (PcdSdIsArasan)) { + DEBUG ((DEBUG_INFO, "Routing SD to Arasan\n")); + Gpio48Group =3D GPIO_FSEL_ALT3; + /* + * Route SDIO to SdHost. + */ + Gpio34Group =3D GPIO_FSEL_ALT0; + } else { + DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n")); + Gpio48Group =3D GPIO_FSEL_ALT0; + /* + * Route SDIO to Arasan. + */ + Gpio34Group =3D GPIO_FSEL_ALT3; + } + GpioPinFuncSet (34, Gpio34Group); + GpioPinFuncSet (35, Gpio34Group); + GpioPinFuncSet (36, Gpio34Group); + GpioPinFuncSet (37, Gpio34Group); + GpioPinFuncSet (38, Gpio34Group); + GpioPinFuncSet (39, Gpio34Group); + GpioPinFuncSet (48, Gpio48Group); + GpioPinFuncSet (49, Gpio48Group); + GpioPinFuncSet (50, Gpio48Group); + GpioPinFuncSet (51, Gpio48Group); + GpioPinFuncSet (52, Gpio48Group); + GpioPinFuncSet (53, Gpio48Group); + + } else if (ModelFamily =3D=3D 4) { /* - * Route SDIO to Arasan. + * Pi 4: either Arasan or eMMC2 goes to SD card. */ - Gpio34Group =3D GPIO_FSEL_ALT3; + if (PcdGet32 (PcdSdIsArasan)) { + /* + * WiFi disabled. + */ + GpioPinFuncSet (34, GPIO_FSEL_INPUT); + GpioPinFuncSet (35, GPIO_FSEL_INPUT); + GpioPinFuncSet (36, GPIO_FSEL_INPUT); + GpioPinFuncSet (37, GPIO_FSEL_INPUT); + GpioPinFuncSet (38, GPIO_FSEL_INPUT); + GpioPinFuncSet (39, GPIO_FSEL_INPUT); + /* + * SD card pins go to Arasan. + */ + MmioWrite32((GPIO_BASE_ADDRESS + 0xD0), + MmioRead32(GPIO_BASE_ADDRESS + 0xD0) | 0x2); + } else { + /* + * SD card pins back to eMMC2. + */ + MmioWrite32((GPIO_BASE_ADDRESS + 0xD0), + MmioRead32(GPIO_BASE_ADDRESS + 0xD0) & ~0x2); + /* + * WiFi back to Arasan. + */ + GpioPinFuncSet (34, GPIO_FSEL_ALT3); + GpioPinFuncSet (35, GPIO_FSEL_ALT3); + GpioPinFuncSet (36, GPIO_FSEL_ALT3); + GpioPinFuncSet (37, GPIO_FSEL_ALT3); + GpioPinFuncSet (38, GPIO_FSEL_ALT3); + GpioPinFuncSet (39, GPIO_FSEL_ALT3); + } + } else { + DEBUG ((DEBUG_ERROR, "Model Family %d not supported...\n", ModelFamily= )); } - GpioPinFuncSet (34, Gpio34Group); - GpioPinFuncSet (35, Gpio34Group); - GpioPinFuncSet (36, Gpio34Group); - GpioPinFuncSet (37, Gpio34Group); - GpioPinFuncSet (38, Gpio34Group); - GpioPinFuncSet (39, Gpio34Group); - GpioPinFuncSet (48, Gpio48Group); - GpioPinFuncSet (49, Gpio48Group); - GpioPinFuncSet (50, Gpio48Group); - GpioPinFuncSet (51, Gpio48Group); - GpioPinFuncSet (52, Gpio48Group); - GpioPinFuncSet (53, Gpio48Group); =20 /* * JTAG pin JTAG sig GPIO Mode Header pin --=20 2.21.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51547): https://edk2.groups.io/g/devel/message/51547 Mute This Topic: https://groups.io/mt/65063384/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-