|
12 | 12 | #include <linux/io.h>
|
13 | 13 | #include <linux/delay.h>
|
14 | 14 | #include <linux/clk-provider.h>
|
| 15 | +#include <linux/iopoll.h> |
15 | 16 | #include <linux/regmap.h>
|
16 | 17 | #include <linux/clk.h>
|
17 | 18 | #include "clk.h"
|
@@ -109,12 +110,31 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
|
109 | 110 | #define RK3036_PLLCON1_REFDIV_SHIFT 0
|
110 | 111 | #define RK3036_PLLCON1_POSTDIV2_MASK 0x7
|
111 | 112 | #define RK3036_PLLCON1_POSTDIV2_SHIFT 6
|
| 113 | +#define RK3036_PLLCON1_LOCK_STATUS BIT(10) |
112 | 114 | #define RK3036_PLLCON1_DSMPD_MASK 0x1
|
113 | 115 | #define RK3036_PLLCON1_DSMPD_SHIFT 12
|
| 116 | +#define RK3036_PLLCON1_PWRDOWN BIT(13) |
114 | 117 | #define RK3036_PLLCON2_FRAC_MASK 0xffffff
|
115 | 118 | #define RK3036_PLLCON2_FRAC_SHIFT 0
|
116 | 119 |
|
117 |
| -#define RK3036_PLLCON1_PWRDOWN (1 << 13) |
| 120 | +static int rockchip_rk3036_pll_wait_lock(struct rockchip_clk_pll *pll) |
| 121 | +{ |
| 122 | + u32 pllcon; |
| 123 | + int ret; |
| 124 | + |
| 125 | + /* |
| 126 | + * Lock time typical 250, max 500 input clock cycles @24MHz |
| 127 | + * So define a very safe maximum of 1000us, meaning 24000 cycles. |
| 128 | + */ |
| 129 | + ret = readl_relaxed_poll_timeout(pll->reg_base + RK3036_PLLCON(1), |
| 130 | + pllcon, |
| 131 | + pllcon & RK3036_PLLCON1_LOCK_STATUS, |
| 132 | + 0, 1000); |
| 133 | + if (ret) |
| 134 | + pr_err("%s: timeout waiting for pll to lock\n", __func__); |
| 135 | + |
| 136 | + return ret; |
| 137 | +} |
118 | 138 |
|
119 | 139 | static void rockchip_rk3036_pll_get_params(struct rockchip_clk_pll *pll,
|
120 | 140 | struct rockchip_pll_rate_table *rate)
|
@@ -212,7 +232,7 @@ static int rockchip_rk3036_pll_set_params(struct rockchip_clk_pll *pll,
|
212 | 232 | writel_relaxed(pllcon, pll->reg_base + RK3036_PLLCON(2));
|
213 | 233 |
|
214 | 234 | /* wait for the pll to lock */
|
215 |
| - ret = rockchip_pll_wait_lock(pll); |
| 235 | + ret = rockchip_rk3036_pll_wait_lock(pll); |
216 | 236 | if (ret) {
|
217 | 237 | pr_warn("%s: pll update unsuccessful, trying to restore old params\n",
|
218 | 238 | __func__);
|
@@ -251,7 +271,7 @@ static int rockchip_rk3036_pll_enable(struct clk_hw *hw)
|
251 | 271 |
|
252 | 272 | writel(HIWORD_UPDATE(0, RK3036_PLLCON1_PWRDOWN, 0),
|
253 | 273 | pll->reg_base + RK3036_PLLCON(1));
|
254 |
| - rockchip_pll_wait_lock(pll); |
| 274 | + rockchip_rk3036_pll_wait_lock(pll); |
255 | 275 |
|
256 | 276 | return 0;
|
257 | 277 | }
|
|
0 commit comments