Skip to contentSkip to conversation

UFS: Add reference clock support for AMD Versal2

PATCH In review Ajay Neeli 2 participants 4 messages Nov 27

Subsystems (4)
lore
Share & tools
lore

Ajay Neeli

author maintainer
#0 lore raw

v3 cover UFS: Add reference clock support for AMD Versal2

This series adds reference clock support for AMD Versal2 UFS.

The first patch updates the common UFS code to recognize "ref" as the reference clock name while retaining support for "ref_clk" for existing devicetree users.

The second patch adds the optional reference clock to the AMD Versal2 UFS devicetree binding.

---
Changes in v3:
- Add a helper for the "ref"/"ref_clk" name check and use it in all places that handle the reference clock.
- Keep the reference clock optional (minItems: 1) so that existing single-clock devicetrees continue to validate.
- Link to v2: https://lore.kernel.org/all/[email protected]

Changes in v2:
- Add descriptions for individual clocks.
- Use "ref" instead of "ref_clk" for the AMD binding.
- Update the common UFS platform code to support "ref" while retaining compatibility with existing "ref_clk" users.
- Link to v1: https://lore.kernel.org/all/[email protected]/
---

Ajay Neeli (2):
scsi: ufs: core: Support "ref" clock name
dt-bindings: ufs: amd,versal2-ufs: Add reference clock

 .../devicetree/bindings/ufs/amd,versal2-ufs.yaml    | 13 +++++++++----
 drivers/ufs/core/ufshcd.c                           |  4 ++--
 drivers/ufs/host/ufshcd-pltfrm.c                    |  4 ++--
 include/ufs/ufshcd.h                                | 12 ++++++++++++
 4 files changed, 25 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.7
author maintainer
#1 lore raw

PATCH v3 1/2 scsi: ufs: core: Support "ref" clock name

The UFS core identifies the device reference clock by the "ref_clk" clock name when determining its frequency and whether the clock must remain active.

Allow "ref" to identify the device reference clock in both the freq-table-hz and operating-points-v2 paths, and when determining the device reference clock frequency.

Retain support for "ref_clk" for compatibility with existing devicetree bindings.

---
 drivers/ufs/core/ufshcd.c        |  4 ++--
 drivers/ufs/host/ufshcd-pltfrm.c |  4 ++--
 include/ufs/ufshcd.h             | 12 ++++++++++++
 3 files changed, 16 insertions(+), 4 deletions(-)
drivers/ufs/core/ufshcd.c +2 -2
index ee643830a57a..fcc65e30cfc7 100644
@@ -9992,11 +9992,11 @@ static int ufshcd_init_clocks(struct ufs_hba *hba)
 		}
 
 		/*
-		 * Parse device ref clk freq as per device tree "ref_clk".
+		 * Parse device ref clk freq as per device tree "ref" or "ref_clk".
 		 * Default dev_ref_clk_freq is set to REF_CLK_FREQ_INVAL
 		 * in ufshcd_alloc_host().
 		 */
-		if (!strcmp(clki->name, "ref_clk"))
+		if (ufshcd_is_ref_clk_name(clki->name))
 			ufshcd_parse_dev_ref_clk_freq(hba, clki->clk);
 
 		if (clki->max_freq) {
drivers/ufs/host/ufshcd-pltfrm.c +2 -2
index 169dbc1a75fe..77ea84a28975 100644
@@ -96,7 +96,7 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
 			goto out;
 		}
 
-		if (!strcmp(name, "ref_clk"))
+		if (ufshcd_is_ref_clk_name(name))
 			clki->keep_link_active = true;
 		dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz",
 				clki->min_freq, clki->max_freq, clki->name);
@@ -462,7 +462,7 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba)
 		if (!clki->name)
 			return -ENOMEM;
 
-		if (!strcmp(clk_names[i], "ref_clk"))
+		if (ufshcd_is_ref_clk_name(clk_names[i]))
 			clki->keep_link_active = true;
 
 		list_add_tail(&clki->list, &hba->clk_list_head);
include/ufs/ufshcd.h +12 -0
index be62165b785e..1b8193de27c9 100644
@@ -20,6 +20,7 @@
 #include <linux/debugfs.h>
 #include <linux/msi.h>
 #include <linux/pm_runtime.h>
+#include <linux/string.h>
 #include <linux/dma-direction.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
@@ -267,6 +268,17 @@ struct ufs_clk_info {
 	bool enabled;
 };
 
+/**
+ * ufshcd_is_ref_clk_name - check if a clock name is the device reference clock
+ * @name: clock name from devicetree
+ *
+ * Returns: true for "ref" or the legacy "ref_clk" name, false otherwise.
+ */
+static inline bool ufshcd_is_ref_clk_name(const char *name)
+{
+	return (!strcmp(name, "ref") || !strcmp(name, "ref_clk"));
+}
+
 enum ufs_notify_change_status {
 	PRE_CHANGE,
 	POST_CHANGE,
Signature · 1 line
2.43.7
#2 lore raw

Re: [PATCH v3 1/2] scsi: ufs: core: Support "ref" clock name

Quoted 8 lines · Ajay Neeli

The UFS core identifies the device reference clock by the "ref_clk" clock name when determining its frequency and whether the clock must remain active.

Allow "ref" to identify the device reference clock in both the freq-table-hz and operating-points-v2 paths, and when determining the device reference clock frequency.

Hi Ajay,

The commit message does not explain the motivation for adding "ref". Could you please add why the new clock name is needed?

include/ufs/ufshcd.h struct ufs_clk_info { · line 281

Quoted 6 lines
include/ufs/ufshcd.h +5 -0
+static inline bool ufshcd_is_ref_clk_name(const char *name)
+{
+	return (!strcmp(name, "ref") || !strcmp(name, "ref_clk"));
+}
+

The parentheses around the return expression in ufshcd_is_ref_clk_name() are redundant and can be removed.

Others look good to me.

Thanks,
Peter

author maintainer
#3 lore raw

PATCH v3 2/2 dt-bindings: ufs: amd,versal2-ufs: Add reference clock

In reply to Ajay Neeli

Add the reference clock supplied to the UFS device.

The AMD Versal2 UFS controller supplies a 26 MHz reference clock to the UFS device. The device bRefClkFreq attribute must match this frequency. UFS 3.x devices default to 26 MHz, but UFS 4.0 and later devices default to 52 MHz. A mismatch causes timing violations and link instability.

Describe the reference clock in devicetree so that the UFS driver can obtain its frequency and program the device bRefClkFreq attribute accordingly during initialization.

The reference clock is optional, as the binding previously described only the core clock.

---
 .../devicetree/bindings/ufs/amd,versal2-ufs.yaml    | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/ufs/amd,versal2-ufs.yaml +9 -4
index c00ec342d574..1f44df93c9a5 100644
@@ -20,11 +20,16 @@ properties:
     maxItems: 1
 
   clocks:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: UFS core clock
+      - description: UFS reference clock
 
   clock-names:
+    minItems: 1
     items:
       - const: core
+      - const: ref
 
   power-domains:
     maxItems: 1
@@ -52,10 +57,10 @@ examples:
     ufs@f10b0000 {
         compatible = "amd,versal2-ufs";
         reg = <0xf10b0000 0x1000>;
-        clocks = <&ufs_core_clk>;
-        clock-names = "core";
+        clocks = <&ufs_core_clk>, <&ufs_ref_clk>;
+        clock-names = "core", "ref";
         resets = <&scmi_reset 4>, <&scmi_reset 35>;
         reset-names = "host", "phy";
         interrupts = <GIC_SPI 234 IRQ_TYPE_LEVEL_HIGH>;
-        freq-table-hz = <0 0>;
+        freq-table-hz = <0 0>, <26000000 26000000>;
     };
Signature · 1 line
2.43.7