]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
scsi: ufs: pltfrm: Add DT support to limit HS gear and gear rate
authorRam Kumar Dwivedi <quic_rdwivedi@quicinc.com>
Wed, 17 Sep 2025 14:09:32 +0000 (19:39 +0530)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 25 Sep 2025 02:27:47 +0000 (22:27 -0400)
Introduce parsing of 'limit-hs-gear' and 'limit-gear-rate' device tree
properties to restrict high-speed gear and rate during initialization.

This is useful in cases where the customer board may have signal
integrity, clock configuration or layout issues that prevent reliable
operation at higher gears. Such limitations are especially critical in
those platforms, where stability is prioritized over peak performance.

Co-developed-by: Nitin Rawat <quic_nitirawa@quicinc.com>
Signed-off-by: Nitin Rawat <quic_nitirawa@quicinc.com>
Signed-off-by: Ram Kumar Dwivedi <quic_rdwivedi@quicinc.com>
Reviewed-by: Alim Akhtar <alim.akhtar@samsung.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ufs/host/ufshcd-pltfrm.c
drivers/ufs/host/ufshcd-pltfrm.h

index ffe5d1d2b2158882d369e4d3c902633b81378dba..c2dafb583cf5157d219bf2bf24d3f54741b7f4bc 100644 (file)
@@ -430,6 +430,39 @@ int ufshcd_negotiate_pwr_params(const struct ufs_host_params *host_params,
 }
 EXPORT_SYMBOL_GPL(ufshcd_negotiate_pwr_params);
 
+/**
+ * ufshcd_parse_gear_limits - Parse DT-based gear and rate limits for UFS
+ * @hba: Pointer to UFS host bus adapter instance
+ * @host_params: Pointer to UFS host parameters structure to be updated
+ *
+ * This function reads optional device tree properties to apply
+ * platform-specific constraints.
+ *
+ * "limit-hs-gear": Specifies the max HS gear.
+ * "limit-gear-rate": Specifies the max High-Speed rate.
+ */
+void ufshcd_parse_gear_limits(struct ufs_hba *hba, struct ufs_host_params *host_params)
+{
+       struct device_node *np = hba->dev->of_node;
+       u32 hs_gear;
+       const char *hs_rate;
+
+       if (!of_property_read_u32(np, "limit-hs-gear", &hs_gear)) {
+               host_params->hs_tx_gear = hs_gear;
+               host_params->hs_rx_gear = hs_gear;
+       }
+
+       if (!of_property_read_string(np, "limit-gear-rate", &hs_rate)) {
+               if (!strcmp(hs_rate, "rate-a"))
+                       host_params->hs_rate = PA_HS_MODE_A;
+               else if (!strcmp(hs_rate, "rate-b"))
+                       host_params->hs_rate = PA_HS_MODE_B;
+               else
+                       dev_warn(hba->dev, "Invalid rate: %s\n", hs_rate);
+       }
+}
+EXPORT_SYMBOL_GPL(ufshcd_parse_gear_limits);
+
 void ufshcd_init_host_params(struct ufs_host_params *host_params)
 {
        *host_params = (struct ufs_host_params){
index 3017f8e8f93c678bf4071924ed2ef54395354a5f..0a18a8aed94d09887152e9be2848b4d1d6208e80 100644 (file)
@@ -29,6 +29,7 @@ int ufshcd_negotiate_pwr_params(const struct ufs_host_params *host_params,
                                const struct ufs_pa_layer_attr *dev_max,
                                struct ufs_pa_layer_attr *agreed_pwr);
 void ufshcd_init_host_params(struct ufs_host_params *host_params);
+void ufshcd_parse_gear_limits(struct ufs_hba *hba, struct ufs_host_params *host_params);
 int ufshcd_pltfrm_init(struct platform_device *pdev,
                       const struct ufs_hba_variant_ops *vops);
 void ufshcd_pltfrm_remove(struct platform_device *pdev);