Skip to content

Commit aa86602

Browse files
ptr324martinkpetersen
authored andcommitted
scsi: ufs: host: mediatek: Fix auto-hibern8 timer configuration
Move the configuration of the Auto-Hibern8 (AHIT) timer from the post-link stage to the 'fixup_dev_quirks' function. This change allows setting the AHIT based on the vendor requirements: (a) Samsung: 3.5 ms (b) Micron: 2 ms (c) Others: 1 ms Additionally, the clock gating timer is adjusted based on the AHIT scale, with a maximum setting of 10 ms. This ensures that the clock gating delay is appropriately configured to match the AHIT settings. Signed-off-by: Peter Wang <peter.wang@mediatek.com> Link: https://lore.kernel.org/r/20250811131423.3444014-3-peter.wang@mediatek.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 6c00c49 commit aa86602

1 file changed

Lines changed: 64 additions & 22 deletions

File tree

drivers/ufs/host/ufs-mediatek.c

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,69 @@ static void ufs_mtk_vreg_fix_vccqx(struct ufs_hba *hba)
10751075
}
10761076
}
10771077

1078+
static void ufs_mtk_setup_clk_gating(struct ufs_hba *hba)
1079+
{
1080+
unsigned long flags;
1081+
u32 ah_ms = 10;
1082+
u32 ah_scale, ah_timer;
1083+
u32 scale_us[] = {1, 10, 100, 1000, 10000, 100000};
1084+
1085+
if (ufshcd_is_clkgating_allowed(hba)) {
1086+
if (ufshcd_is_auto_hibern8_supported(hba) && hba->ahit) {
1087+
ah_scale = FIELD_GET(UFSHCI_AHIBERN8_SCALE_MASK,
1088+
hba->ahit);
1089+
ah_timer = FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK,
1090+
hba->ahit);
1091+
if (ah_scale <= 5)
1092+
ah_ms = ah_timer * scale_us[ah_scale] / 1000;
1093+
}
1094+
1095+
spin_lock_irqsave(hba->host->host_lock, flags);
1096+
hba->clk_gating.delay_ms = max(ah_ms, 10U);
1097+
spin_unlock_irqrestore(hba->host->host_lock, flags);
1098+
}
1099+
}
1100+
1101+
/* Convert microseconds to Auto-Hibernate Idle Timer register value */
1102+
static u32 ufs_mtk_us_to_ahit(unsigned int timer)
1103+
{
1104+
unsigned int scale;
1105+
1106+
for (scale = 0; timer > UFSHCI_AHIBERN8_TIMER_MASK; ++scale)
1107+
timer /= UFSHCI_AHIBERN8_SCALE_FACTOR;
1108+
1109+
return FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, timer) |
1110+
FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, scale);
1111+
}
1112+
1113+
static void ufs_mtk_fix_ahit(struct ufs_hba *hba)
1114+
{
1115+
unsigned int us;
1116+
1117+
if (ufshcd_is_auto_hibern8_supported(hba)) {
1118+
switch (hba->dev_info.wmanufacturerid) {
1119+
case UFS_VENDOR_SAMSUNG:
1120+
/* configure auto-hibern8 timer to 3.5 ms */
1121+
us = 3500;
1122+
break;
1123+
1124+
case UFS_VENDOR_MICRON:
1125+
/* configure auto-hibern8 timer to 2 ms */
1126+
us = 2000;
1127+
break;
1128+
1129+
default:
1130+
/* configure auto-hibern8 timer to 1 ms */
1131+
us = 1000;
1132+
break;
1133+
}
1134+
1135+
hba->ahit = ufs_mtk_us_to_ahit(us);
1136+
}
1137+
1138+
ufs_mtk_setup_clk_gating(hba);
1139+
}
1140+
10781141
static void ufs_mtk_init_mcq_irq(struct ufs_hba *hba)
10791142
{
10801143
struct ufs_mtk_host *host = ufshcd_get_variant(hba);
@@ -1369,32 +1432,10 @@ static int ufs_mtk_pre_link(struct ufs_hba *hba)
13691432

13701433
return ret;
13711434
}
1372-
1373-
static void ufs_mtk_setup_clk_gating(struct ufs_hba *hba)
1374-
{
1375-
u32 ah_ms;
1376-
1377-
if (ufshcd_is_clkgating_allowed(hba)) {
1378-
if (ufshcd_is_auto_hibern8_supported(hba) && hba->ahit)
1379-
ah_ms = FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK,
1380-
hba->ahit);
1381-
else
1382-
ah_ms = 10;
1383-
ufshcd_clkgate_delay_set(hba->dev, ah_ms + 5);
1384-
}
1385-
}
1386-
13871435
static void ufs_mtk_post_link(struct ufs_hba *hba)
13881436
{
13891437
/* enable unipro clock gating feature */
13901438
ufs_mtk_cfg_unipro_cg(hba, true);
1391-
1392-
/* will be configured during probe hba */
1393-
if (ufshcd_is_auto_hibern8_supported(hba))
1394-
hba->ahit = FIELD_PREP(UFSHCI_AHIBERN8_TIMER_MASK, 10) |
1395-
FIELD_PREP(UFSHCI_AHIBERN8_SCALE_MASK, 3);
1396-
1397-
ufs_mtk_setup_clk_gating(hba);
13981439
}
13991440

14001441
static int ufs_mtk_link_startup_notify(struct ufs_hba *hba,
@@ -1726,6 +1767,7 @@ static void ufs_mtk_fixup_dev_quirks(struct ufs_hba *hba)
17261767

17271768
ufs_mtk_vreg_fix_vcc(hba);
17281769
ufs_mtk_vreg_fix_vccqx(hba);
1770+
ufs_mtk_fix_ahit(hba);
17291771
}
17301772

17311773
static void ufs_mtk_event_notify(struct ufs_hba *hba,

0 commit comments

Comments
 (0)