Skip to content

Commit dc7c948

Browse files
Bao D. Nguyenmartinkpetersen
authored andcommitted
scsi: ufs: ufs-qcom: Add support for UFS device version detection
Start from HW ver 5, a spare register in UFS host controller is added and used to indicate the UFS device version. The spare register is populated by bootloader for now, but in future it will be populated by HW automatically during link startup with its best efforts in any boot stage prior to Linux. During host driver init, read the spare register, if it is not populated with a UFS device version, go ahead with the dual init mechanism. If a UFS device version is in there, use the UFS device version together with host controller's HW version to decide the proper PHY gear which should be used to configure the UFS PHY without going through the second init. Signed-off-by: Bao D. Nguyen <[email protected]> Signed-off-by: Can Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Nitin Rawat <[email protected]> Tested-by: Neil Armstrong <[email protected]> # on SM8550-QRD Signed-off-by: Martin K. Petersen <[email protected]>
1 parent a68abda commit dc7c948

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

drivers/ufs/host/ufs-qcom.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,17 +1065,38 @@ static void ufs_qcom_advertise_quirks(struct ufs_hba *hba)
10651065
static void ufs_qcom_set_phy_gear(struct ufs_qcom_host *host)
10661066
{
10671067
struct ufs_host_params *host_params = &host->host_params;
1068+
u32 val, dev_major;
10681069

10691070
host->phy_gear = host_params->hs_tx_gear;
10701071

1071-
/*
1072-
* For controllers whose major HW version is < 4, power up the PHY using
1073-
* minimum supported gear (UFS_HS_G2). Switching to max gear will be
1074-
* performed during reinit if supported. For newer controllers, whose
1075-
* major HW version is >= 4, power up the PHY using max supported gear.
1076-
*/
1077-
if (host->hw_ver.major < 0x4)
1072+
if (host->hw_ver.major < 0x4) {
1073+
/*
1074+
* For controllers whose major HW version is < 4, power up the
1075+
* PHY using minimum supported gear (UFS_HS_G2). Switching to
1076+
* max gear will be performed during reinit if supported.
1077+
* For newer controllers, whose major HW version is >= 4, power
1078+
* up the PHY using max supported gear.
1079+
*/
10781080
host->phy_gear = UFS_HS_G2;
1081+
} else if (host->hw_ver.major >= 0x5) {
1082+
val = ufshcd_readl(host->hba, REG_UFS_DEBUG_SPARE_CFG);
1083+
dev_major = FIELD_GET(UFS_DEV_VER_MAJOR_MASK, val);
1084+
1085+
/*
1086+
* Since the UFS device version is populated, let's remove the
1087+
* REINIT quirk as the negotiated gear won't change during boot.
1088+
* So there is no need to do reinit.
1089+
*/
1090+
if (dev_major != 0x0)
1091+
host->hba->quirks &= ~UFSHCD_QUIRK_REINIT_AFTER_MAX_GEAR_SWITCH;
1092+
1093+
/*
1094+
* For UFS 3.1 device and older, power up the PHY using HS-G4
1095+
* PHY gear to save power.
1096+
*/
1097+
if (dev_major > 0x0 && dev_major < 0x4)
1098+
host->phy_gear = UFS_HS_G4;
1099+
}
10791100
}
10801101

10811102
static void ufs_qcom_set_host_params(struct ufs_hba *hba)

drivers/ufs/host/ufs-qcom.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#define UFS_HW_VER_MINOR_MASK GENMASK(27, 16)
2424
#define UFS_HW_VER_STEP_MASK GENMASK(15, 0)
2525

26+
#define UFS_DEV_VER_MAJOR_MASK GENMASK(7, 4)
27+
2628
/* vendor specific pre-defined parameters */
2729
#define SLOW 1
2830
#define FAST 2
@@ -54,6 +56,8 @@ enum {
5456
UFS_AH8_CFG = 0xFC,
5557

5658
REG_UFS_CFG3 = 0x271C,
59+
60+
REG_UFS_DEBUG_SPARE_CFG = 0x284C,
5761
};
5862

5963
/* QCOM UFS host controller vendor specific debug registers */

0 commit comments

Comments
 (0)