xref: /OK3568_Linux_fs/kernel/drivers/clk/mxs/clk.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2012 Freescale Semiconductor, Inc.
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #include <linux/err.h>
7*4882a593Smuzhiyun #include <linux/io.h>
8*4882a593Smuzhiyun #include <linux/jiffies.h>
9*4882a593Smuzhiyun #include <linux/spinlock.h>
10*4882a593Smuzhiyun #include "clk.h"
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun DEFINE_SPINLOCK(mxs_lock);
13*4882a593Smuzhiyun 
mxs_clk_wait(void __iomem * reg,u8 shift)14*4882a593Smuzhiyun int mxs_clk_wait(void __iomem *reg, u8 shift)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun 	unsigned long timeout = jiffies + msecs_to_jiffies(10);
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun 	while (readl_relaxed(reg) & (1 << shift))
19*4882a593Smuzhiyun 		if (time_after(jiffies, timeout))
20*4882a593Smuzhiyun 			return -ETIMEDOUT;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun 	return 0;
23*4882a593Smuzhiyun }
24