]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add bRefClkFreq card attribute programming support
authorBandaru, Purna Chandra Rao <Purna.Chandra.Rao.Bandaru@intel.com>
Tue, 8 Mar 2022 12:19:35 +0000 (20:19 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 10 Mar 2022 01:45:14 +0000 (01:45 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3851

When the UFS card comes out of Manufacturer, bRefClkFreq attribute is set
to 1h on the UFS card as per the Manufacturer Default Value
specified by the spec JESD220*. However, depends on the UFS host system
environment, it need to be set to the correct value.

Reference Clock Frequency value
0h:19.2 MHz
1h: 26 MHz
2h: 38.4 MHz
3h: Obsolete
Others: Reserved

Cc: Wu Hao A <hao.a.wu@intel.com>
Cc: Albecki Mateusz <mateusz.albecki@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Purna Chandra Rao Bandaru <purna.chandra.rao.bandaru@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c
MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
MdeModulePkg/Include/Protocol/UfsHostControllerPlatform.h

index 4c2d6ae27f100da0a4b91ec0072c94a3be553456..dc78e09678e677a2a8e96034e079a432beffe18b 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) Microsoft Corporation.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -834,15 +834,17 @@ UfsPassThruDriverBindingStart (
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  EDKII_UFS_HOST_CONTROLLER_PROTOCOL  *UfsHc;\r
-  UFS_PASS_THRU_PRIVATE_DATA          *Private;\r
-  UINTN                               UfsHcBase;\r
-  UINT32                              Index;\r
-  UFS_UNIT_DESC                       UnitDescriptor;\r
-  UFS_DEV_DESC                        DeviceDescriptor;\r
-  UINT32                              UnitDescriptorSize;\r
-  UINT32                              DeviceDescriptorSize;\r
+  EFI_STATUS                             Status;\r
+  EDKII_UFS_HOST_CONTROLLER_PROTOCOL     *UfsHc;\r
+  UFS_PASS_THRU_PRIVATE_DATA             *Private;\r
+  UINTN                                  UfsHcBase;\r
+  UINT32                                 Index;\r
+  UFS_UNIT_DESC                          UnitDescriptor;\r
+  UFS_DEV_DESC                           DeviceDescriptor;\r
+  UINT32                                 UnitDescriptorSize;\r
+  UINT32                                 DeviceDescriptorSize;\r
+  EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE  Attributes;\r
+  UINT8                                  RefClkAttr;\r
 \r
   Status    = EFI_SUCCESS;\r
   UfsHc     = NULL;\r
@@ -917,6 +919,54 @@ UfsPassThruDriverBindingStart (
     goto Error;\r
   }\r
 \r
+  if ((mUfsHcPlatform != NULL) &&\r
+      ((mUfsHcPlatform->RefClkFreq == EdkiiUfsCardRefClkFreq19p2Mhz) ||\r
+       (mUfsHcPlatform->RefClkFreq == EdkiiUfsCardRefClkFreq26Mhz) ||\r
+       (mUfsHcPlatform->RefClkFreq == EdkiiUfsCardRefClkFreq38p4Mhz)))\r
+  {\r
+    RefClkAttr = UfsAttrRefClkFreq;\r
+    Attributes = EdkiiUfsCardRefClkFreqObsolete;\r
+    Status     = UfsRwAttributes (Private, TRUE, RefClkAttr, 0, 0, (UINT32 *)&Attributes);\r
+    if (!EFI_ERROR (Status)) {\r
+      if (Attributes != mUfsHcPlatform->RefClkFreq) {\r
+        Attributes = mUfsHcPlatform->RefClkFreq;\r
+        DEBUG (\r
+          (DEBUG_INFO,\r
+           "Setting bRefClkFreq attribute(%x) to %x\n  0 -> 19.2 Mhz\n  1 -> 26 Mhz\n  2 -> 38.4 Mhz\n  3 -> Obsolete\n",\r
+           RefClkAttr,\r
+           Attributes)\r
+          );\r
+        Status = UfsRwAttributes (Private, FALSE, RefClkAttr, 0, 0, (UINT32 *)&Attributes);\r
+        if (EFI_ERROR (Status)) {\r
+          DEBUG (\r
+            (DEBUG_ERROR,\r
+             "Failed to Change Reference Clock Attribute to %d, Status = %r \n",\r
+             mUfsHcPlatform->RefClkFreq,\r
+             Status)\r
+            );\r
+        }\r
+      }\r
+    } else {\r
+      DEBUG (\r
+        (DEBUG_ERROR,\r
+         "Failed to Read Reference Clock Attribute, Status = %r \n",\r
+         Status)\r
+        );\r
+    }\r
+  }\r
+\r
+  if ((mUfsHcPlatform != NULL) && (mUfsHcPlatform->Callback != NULL)) {\r
+    Status = mUfsHcPlatform->Callback (Private->Handle, EdkiiUfsHcPostLinkStartup, &Private->UfsHcDriverInterface);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG (\r
+        (DEBUG_ERROR,\r
+         "Failure from platform driver during EdkiiUfsHcPostLinkStartup, Status = %r\n",\r
+         Status)\r
+        );\r
+      return Status;\r
+    }\r
+  }\r
+\r
   //\r
   // UFS 2.0 spec Section 13.1.3.3:\r
   // At the end of the UFS Interconnect Layer initialization on both host and device side,\r
index eba35cc669f52cc4c0655f1c3315e873dc9feca3..4a9fa01e7d8177f816283c23b3b1ad09011eaf7d 100644 (file)
@@ -2,7 +2,7 @@
   UfsPassThruDxe driver is used to produce EFI_EXT_SCSI_PASS_THRU protocol interface\r
   for upper layer application to execute UFS-supported SCSI cmds.\r
 \r
-  Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) Microsoft Corporation.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -1970,14 +1970,6 @@ UfsDeviceDetection (
         return EFI_DEVICE_ERROR;\r
       }\r
     } else {\r
-      if ((mUfsHcPlatform != NULL) && (mUfsHcPlatform->Callback != NULL)) {\r
-        Status = mUfsHcPlatform->Callback (Private->Handle, EdkiiUfsHcPostLinkStartup, &Private->UfsHcDriverInterface);\r
-        if (EFI_ERROR (Status)) {\r
-          DEBUG ((DEBUG_ERROR, "Failure from platform driver during EdkiiUfsHcPostLinkStartup, Status = %r\n", Status));\r
-          return Status;\r
-        }\r
-      }\r
-\r
       return EFI_SUCCESS;\r
     }\r
   }\r
index faa82d0c4ee34f542935888a56e563edfc8797f7..32e9f6488c907065b36a8c8ae7938ef992ece101 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EDKII_UFS_HC_PLATFORM_PROTOCOL definition.\r
 \r
-Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2019 - 2022, Intel Corporation. All rights reserved.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -11,7 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 \r
 #include <Protocol/UfsHostController.h>\r
 \r
-#define EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION  1\r
+#define EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION  2\r
 \r
 extern EFI_GUID  gEdkiiUfsHcPlatformProtocolGuid;\r
 \r
@@ -83,6 +83,13 @@ typedef enum {
   EdkiiUfsHcPostLinkStartup\r
 } EDKII_UFS_HC_PLATFORM_CALLBACK_PHASE;\r
 \r
+typedef enum {\r
+  EdkiiUfsCardRefClkFreq19p2Mhz,\r
+  EdkiiUfsCardRefClkFreq26Mhz,\r
+  EdkiiUfsCardRefClkFreq38p4Mhz,\r
+  EdkiiUfsCardRefClkFreqObsolete\r
+} EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE;\r
+\r
 /**\r
   Callback function for platform driver.\r
 \r
@@ -118,6 +125,10 @@ struct _EDKII_UFS_HC_PLATFORM_PROTOCOL {
   /// for host controller.\r
   ///\r
   EDKII_UFS_HC_PLATFORM_CALLBACK            Callback;\r
+  ///\r
+  /// Reference Clock Frequency Ufs Card Attribute that need to be set in this Ufs Host Environment.\r
+  ///\r
+  EDKII_UFS_CARD_REF_CLK_FREQ_ATTRIBUTE     RefClkFreq;\r
 };\r
 \r
 #endif\r