Commit fb43337c authored by Stanley Chu's avatar Stanley Chu Committed by Martin K. Petersen

scsi: ufs-mediatek: Fix imprecise waiting time for ref-clk control

Currently ref-clk control timeout is implemented by jiffies. However
jiffies is not accurate enough thus "false timeout" may happen.

Use more accurate delay mechanism instead, i.e. ktime.

Link: https://lore.kernel.org/r/20200601104646.15436-2-stanley.chu@mediatek.comReviewed-by: default avatarAndy Teng <andy.teng@mediatek.com>
Reviewed-by: default avatarAvri Altman <avri.altman@wdc.com>
Signed-off-by: default avatarStanley Chu <stanley.chu@mediatek.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 55f4b1f7
...@@ -120,7 +120,7 @@ static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on) ...@@ -120,7 +120,7 @@ static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on)
{ {
struct ufs_mtk_host *host = ufshcd_get_variant(hba); struct ufs_mtk_host *host = ufshcd_get_variant(hba);
struct arm_smccc_res res; struct arm_smccc_res res;
unsigned long timeout; ktime_t timeout, time_checked;
u32 value; u32 value;
if (host->ref_clk_enabled == on) if (host->ref_clk_enabled == on)
...@@ -135,8 +135,9 @@ static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on) ...@@ -135,8 +135,9 @@ static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on)
} }
/* Wait for ack */ /* Wait for ack */
timeout = jiffies + msecs_to_jiffies(REFCLK_REQ_TIMEOUT_MS); timeout = ktime_add_us(ktime_get(), REFCLK_REQ_TIMEOUT_US);
do { do {
time_checked = ktime_get();
value = ufshcd_readl(hba, REG_UFS_REFCLK_CTRL); value = ufshcd_readl(hba, REG_UFS_REFCLK_CTRL);
/* Wait until ack bit equals to req bit */ /* Wait until ack bit equals to req bit */
...@@ -144,7 +145,7 @@ static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on) ...@@ -144,7 +145,7 @@ static int ufs_mtk_setup_ref_clk(struct ufs_hba *hba, bool on)
goto out; goto out;
usleep_range(100, 200); usleep_range(100, 200);
} while (time_before(jiffies, timeout)); } while (ktime_before(time_checked, timeout));
dev_err(hba->dev, "missing ack of refclk req, reg: 0x%x\n", value); dev_err(hba->dev, "missing ack of refclk req, reg: 0x%x\n", value);
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#define REFCLK_REQUEST BIT(0) #define REFCLK_REQUEST BIT(0)
#define REFCLK_ACK BIT(1) #define REFCLK_ACK BIT(1)
#define REFCLK_REQ_TIMEOUT_MS 3 #define REFCLK_REQ_TIMEOUT_US 3000
/* /*
* Vendor specific pre-defined parameters * Vendor specific pre-defined parameters
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment