LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Stanley Chu <stanley.chu@mediatek.com>
To: <linux-scsi@vger.kernel.org>, <martin.petersen@oracle.com>,
<avri.altman@wdc.com>, <alim.akhtar@samsung.com>,
<jejb@linux.ibm.com>
Cc: <beanhuo@micron.com>, <asutoshd@codeaurora.org>,
<cang@codeaurora.org>, <matthias.bgg@gmail.com>,
<bvanassche@acm.org>, <linux-mediatek@lists.infradead.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <kuohong.wang@mediatek.com>,
<peter.wang@mediatek.com>, <chun-hung.wu@mediatek.com>,
<andy.teng@mediatek.com>, Stanley Chu <stanley.chu@mediatek.com>
Subject: [PATCH v4 4/8] scsi: ufs: introduce common delay function
Date: Fri, 13 Mar 2020 17:00:59 +0800 [thread overview]
Message-ID: <20200313090103.15390-5-stanley.chu@mediatek.com> (raw)
In-Reply-To: <20200313090103.15390-1-stanley.chu@mediatek.com>
Introduce common delay function to collect all delay requirements
to simplify driver and take choices of udelay and usleep_range into
consideration.
Signed-off-by: Stanley Chu <stanley.chu@mediatek.com>
---
drivers/scsi/ufs/ufshcd.c | 27 ++++++++++++++++++---------
drivers/scsi/ufs/ufshcd.h | 1 +
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index b4988b9ee36c..ce65d321a73f 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -597,6 +597,18 @@ static void ufshcd_print_pwr_info(struct ufs_hba *hba)
hba->pwr_info.hs_rate);
}
+void ufshcd_wait_us(unsigned long us, unsigned long tolerance, bool can_sleep)
+{
+ if (!us)
+ return;
+
+ if (us < 10 || !can_sleep)
+ udelay(us);
+ else
+ usleep_range(us, us + tolerance);
+}
+EXPORT_SYMBOL_GPL(ufshcd_wait_us);
+
/*
* ufshcd_wait_for_register - wait for register value to change
* @hba - per-adapter interface
@@ -620,10 +632,7 @@ int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
val = val & mask;
while ((ufshcd_readl(hba, reg) & mask) != val) {
- if (can_sleep)
- usleep_range(interval_us, interval_us + 50);
- else
- udelay(interval_us);
+ ufshcd_wait_us(interval_us, 50, can_sleep);
if (time_after(jiffies, timeout)) {
if ((ufshcd_readl(hba, reg) & mask) != val)
err = -ETIMEDOUT;
@@ -3565,7 +3574,7 @@ static inline void ufshcd_add_delay_before_dme_cmd(struct ufs_hba *hba)
}
/* allow sleep for extra 50us if needed */
- usleep_range(min_sleep_time_us, min_sleep_time_us + 50);
+ ufshcd_wait_us(min_sleep_time_us, 50, true);
}
/**
@@ -4289,7 +4298,7 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
* instruction might be read back.
* This delay can be changed based on the controller.
*/
- usleep_range(1000, 1100);
+ ufshcd_wait_us(1000, 100, true);
/* wait for the host controller to complete initialization */
retry = 10;
@@ -4301,7 +4310,7 @@ int ufshcd_hba_enable(struct ufs_hba *hba)
"Controller enable failed\n");
return -EIO;
}
- usleep_range(5000, 5100);
+ ufshcd_wait_us(5000, 100, true);
}
/* enable UIC related interrupts */
@@ -6224,7 +6233,7 @@ static int ufshcd_abort(struct scsi_cmnd *cmd)
reg = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
if (reg & (1 << tag)) {
/* sleep for max. 200us to stabilize */
- usleep_range(100, 200);
+ ufshcd_wait_us(100, 100, true);
continue;
}
/* command completed already */
@@ -7783,7 +7792,7 @@ static void ufshcd_vreg_set_lpm(struct ufs_hba *hba)
*/
if (!ufshcd_is_link_active(hba) &&
hba->dev_quirks & UFS_DEVICE_QUIRK_DELAY_BEFORE_LPM)
- usleep_range(2000, 2100);
+ ufshcd_wait_us(2000, 100, true);
/*
* If UFS device is either in UFS_Sleep turn off VCC rail to save some
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index fec004cd8054..4683e7bf6640 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -781,6 +781,7 @@ int ufshcd_init(struct ufs_hba * , void __iomem * , unsigned int);
int ufshcd_make_hba_operational(struct ufs_hba *hba);
void ufshcd_remove(struct ufs_hba *);
int ufshcd_uic_hibern8_exit(struct ufs_hba *hba);
+void ufshcd_wait_us(unsigned long us, unsigned long tolerance, bool can_sleep);
int ufshcd_wait_for_register(struct ufs_hba *hba, u32 reg, u32 mask,
u32 val, unsigned long interval_us,
unsigned long timeout_ms, bool can_sleep);
--
2.18.0
next prev parent reply other threads:[~2020-03-13 9:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-13 9:00 [PATCH v4 0/8] scsi: ufs: some cleanups and make the delay for host enabling customizable Stanley Chu
2020-03-13 9:00 ` [PATCH v4 1/8] scsi: ufs: fix uninitialized tx_lanes in ufshcd_disable_tx_lcc() Stanley Chu
2020-03-13 9:00 ` [PATCH v4 2/8] scsi: ufs: remove init_prefetch_data in struct ufs_hba Stanley Chu
2020-03-13 9:00 ` [PATCH v4 3/8] scsi: ufs: use an enum for host capabilities Stanley Chu
2020-03-13 9:00 ` Stanley Chu [this message]
2020-03-13 9:01 ` [PATCH v4 5/8] scsi: ufs-mediatek: replace all delay places by common delay function Stanley Chu
2020-03-13 9:01 ` [PATCH v4 6/8] scsi: ufs: allow customized delay for host enabling Stanley Chu
2020-03-13 9:01 ` [PATCH v4 7/8] scsi: ufs: make HCE polling more compact to improve initializatoin latency Stanley Chu
2020-03-13 9:01 ` [PATCH v4 8/8] scsi: ufs-mediatek: customize the delay for host enabling Stanley Chu
2020-03-14 9:47 ` [PATCH v4 0/8] scsi: ufs: some cleanups and make the delay for host enabling customizable Avri Altman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200313090103.15390-5-stanley.chu@mediatek.com \
--to=stanley.chu@mediatek.com \
--cc=alim.akhtar@samsung.com \
--cc=andy.teng@mediatek.com \
--cc=asutoshd@codeaurora.org \
--cc=avri.altman@wdc.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=cang@codeaurora.org \
--cc=chun-hung.wu@mediatek.com \
--cc=jejb@linux.ibm.com \
--cc=kuohong.wang@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=matthias.bgg@gmail.com \
--cc=peter.wang@mediatek.com \
--subject='Re: [PATCH v4 4/8] scsi: ufs: introduce common delay function' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).