Skip to content

Commit a3ab984

Browse files
tretterbebarino
authored andcommitted
soc: xilinx: vcu: add helper to wait for PLL locked
Extract a helper function to wait until the PLL is locked. Also, disabling the bypass was buried in the exit path on the wait loop. Separate the different steps and add a helper function to make the code more readable. Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Acked-by: Michal Simek <michal.simek@xilinx.com> Link: https://lore.kernel.org/r/20210121071659.1226489-5-m.tretter@pengutronix.de Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent d387dfc commit a3ab984

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

drivers/soc/xilinx/xlnx_vcu.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ static void xvcu_write_field_reg(void __iomem *iomem, int offset,
256256
xvcu_write(iomem, offset, val);
257257
}
258258

259+
static int xvcu_pll_wait_for_lock(struct xvcu_device *xvcu)
260+
{
261+
void __iomem *base = xvcu->vcu_slcr_ba;
262+
unsigned long timeout;
263+
u32 lock_status;
264+
265+
timeout = jiffies + msecs_to_jiffies(2000);
266+
do {
267+
lock_status = xvcu_read(base, VCU_PLL_STATUS);
268+
if (lock_status & VCU_PLL_STATUS_LOCK_STATUS_MASK)
269+
return 0;
270+
} while (!time_after(jiffies, timeout));
271+
272+
return -ETIMEDOUT;
273+
}
274+
259275
/**
260276
* xvcu_set_vcu_pll_info - Set the VCU PLL info
261277
* @xvcu: Pointer to the xvcu_device structure
@@ -428,8 +444,6 @@ static int xvcu_set_vcu_pll_info(struct xvcu_device *xvcu)
428444
*/
429445
static int xvcu_set_pll(struct xvcu_device *xvcu)
430446
{
431-
u32 lock_status;
432-
unsigned long timeout;
433447
int ret;
434448

435449
ret = xvcu_set_vcu_pll_info(xvcu);
@@ -447,24 +461,18 @@ static int xvcu_set_pll(struct xvcu_device *xvcu)
447461
xvcu_write_field_reg(xvcu->vcu_slcr_ba, VCU_PLL_CTRL,
448462
0, VCU_PLL_CTRL_RESET_MASK,
449463
VCU_PLL_CTRL_RESET_SHIFT);
450-
/*
451-
* Defined the timeout for the max time to wait the
452-
* PLL_STATUS to be locked.
453-
*/
454-
timeout = jiffies + msecs_to_jiffies(2000);
455-
do {
456-
lock_status = xvcu_read(xvcu->vcu_slcr_ba, VCU_PLL_STATUS);
457-
if (lock_status & VCU_PLL_STATUS_LOCK_STATUS_MASK) {
458-
xvcu_write_field_reg(xvcu->vcu_slcr_ba, VCU_PLL_CTRL,
459-
0, VCU_PLL_CTRL_BYPASS_MASK,
460-
VCU_PLL_CTRL_BYPASS_SHIFT);
461-
return 0;
462-
}
463-
} while (!time_after(jiffies, timeout));
464464

465-
/* PLL is not locked even after the timeout of the 2sec */
466-
dev_err(xvcu->dev, "PLL is not locked\n");
467-
return -ETIMEDOUT;
465+
ret = xvcu_pll_wait_for_lock(xvcu);
466+
if (ret) {
467+
dev_err(xvcu->dev, "PLL is not locked\n");
468+
return ret;
469+
}
470+
471+
xvcu_write_field_reg(xvcu->vcu_slcr_ba, VCU_PLL_CTRL,
472+
0, VCU_PLL_CTRL_BYPASS_MASK,
473+
VCU_PLL_CTRL_BYPASS_SHIFT);
474+
475+
return ret;
468476
}
469477

470478
/**

0 commit comments

Comments
 (0)