[PATCH v2 4/7] PCI: brcmstb: Replace msleep(5) with usleep_range() for precise link up checking

Hans Zhang posted 7 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 4/7] PCI: brcmstb: Replace msleep(5) with usleep_range() for precise link up checking
Posted by Hans Zhang 1 month, 1 week ago
The msleep(5) in brcm_pcie_start_link() may sleep longer than intended
due to timer granularity, which can cause unnecessary delays in PCIe link
up detection. Replace it with usleep_range() for a more precise delay of
approximately 5ms.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
 drivers/pci/controller/pcie-brcmstb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
index 9afbd02ded35..6e34a052b02e 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -214,6 +214,8 @@
 #define  PCIE_DVT_PMU_PCIE_PHY_CTRL_DAST_PWRDN_MASK		0x1
 #define  PCIE_DVT_PMU_PCIE_PHY_CTRL_DAST_PWRDN_SHIFT		0x0
 
+#define PCIE_LINK_UP_CHECK_US	5000
+
 /* Forward declarations */
 struct brcm_pcie;
 
@@ -1365,7 +1367,8 @@ static int brcm_pcie_start_link(struct brcm_pcie *pcie)
 	 * total of 100ms.
 	 */
 	for (i = 0; i < 100 && !brcm_pcie_link_up(pcie); i += 5)
-		msleep(5);
+		usleep_range(PCIE_LINK_UP_CHECK_US,
+			     PCIE_LINK_UP_CHECK_US + 100);
 
 	if (!brcm_pcie_link_up(pcie)) {
 		dev_err(dev, "link down\n");
-- 
2.25.1