[edk2-devel] [edk2-platforms][PATCH 5/5] Platform/RPi: Set SD routing according to model

Pete Batard via Groups.Io pete=akeo.ie at groups.io
Wed Nov 27 12:37:06 UTC 2019


From: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud at arm.com>

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 <pete at akeo.ie>
---
 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..26bc92f28185 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 <andrey.warkentin at gmail.com>
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
+ *  Copyright (c) 2018 - 2019, Andrei Warkentin <andrey.warkentin at gmail.com>
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
  *
@@ -9,10 +10,12 @@
 #include <Uefi.h>
 #include <Library/HiiLib.h>
 #include <Library/DebugLib.h>
+#include <Library/IoLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiRuntimeServicesTableLib.h>
 #include <Library/DevicePathLib.h>
 #include <IndustryStandard/RpiMbox.h>
+#include <IndustryStandard/Bcm2836.h>
 #include <IndustryStandard/Bcm2836Gpio.h>
 #include <Library/GpioLib.h>
 #include <Protocol/RpiFirmware.h>
@@ -212,6 +215,7 @@ ApplyVariables (
   UINT32 CpuClock = PcdGet32 (PcdCpuClock);
   UINT32 CustomCpuClock = PcdGet32 (PcdCustomCpuClock);
   UINT32 Rate = 0;
+  UINT32 ModelFamily = 0;
 
   if (CpuClock != 0) {
     if (CpuClock == 2) {
@@ -245,51 +249,102 @@ ApplyVariables (
     DEBUG ((DEBUG_INFO, "Current CPU speed is %uHz\n", Rate));
   }
 
-  /*
-   * 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 = GPIO_FSEL_ALT3;
+  Status = mFwProtocol->GetModelFamily (&ModelFamily);
+  if (Status != 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", ModelFamily));
+  }
+
+
+  if (ModelFamily == 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 = GPIO_FSEL_ALT0;
-  } else {
-    DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n"));
-    Gpio48Group = 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 = GPIO_FSEL_ALT3;
+      /*
+       * Route SDIO to SdHost.
+       */
+      Gpio34Group = GPIO_FSEL_ALT0;
+    } else {
+      DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n"));
+      Gpio48Group = GPIO_FSEL_ALT0;
+      /*
+       * Route SDIO to Arasan.
+       */
+      Gpio34Group = 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 == 4){
     /*
-     * Route SDIO to Arasan.
+     * Pi 4: either Arasan or eMMC2 goes to SD card.
      */
-    Gpio34Group = 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);
 
   /*
    * JTAG pin    JTAG sig    GPIO      Mode    Header pin
-- 
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#51339): https://edk2.groups.io/g/devel/message/51339
Mute This Topic: https://groups.io/mt/62504750/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list