1 #include <linux/kernel.h>
4 #include <linux/errno.h>
6 #include <linux/slab.h>
13 #define to_clk_pllv2(clk) (container_of(clk, struct clk_pllv2, clk))
16 #define MXC_PLL_DP_CTL 0x00
17 #define MXC_PLL_DP_CONFIG 0x04
18 #define MXC_PLL_DP_OP 0x08
19 #define MXC_PLL_DP_MFD 0x0C
20 #define MXC_PLL_DP_MFN 0x10
21 #define MXC_PLL_DP_MFNMINUS 0x14
22 #define MXC_PLL_DP_MFNPLUS 0x18
23 #define MXC_PLL_DP_HFS_OP 0x1C
24 #define MXC_PLL_DP_HFS_MFD 0x20
25 #define MXC_PLL_DP_HFS_MFN 0x24
26 #define MXC_PLL_DP_MFN_TOGC 0x28
27 #define MXC_PLL_DP_DESTAT 0x2c
30 #define MXC_PLL_DP_CTL_MUL_CTRL 0x2000
31 #define MXC_PLL_DP_CTL_DPDCK0_2_EN 0x1000
32 #define MXC_PLL_DP_CTL_DPDCK0_2_OFFSET 12
33 #define MXC_PLL_DP_CTL_ADE 0x800
34 #define MXC_PLL_DP_CTL_REF_CLK_DIV 0x400
35 #define MXC_PLL_DP_CTL_REF_CLK_SEL_MASK (3 << 8)
36 #define MXC_PLL_DP_CTL_REF_CLK_SEL_OFFSET 8
37 #define MXC_PLL_DP_CTL_HFSM 0x80
38 #define MXC_PLL_DP_CTL_PRE 0x40
39 #define MXC_PLL_DP_CTL_UPEN 0x20
40 #define MXC_PLL_DP_CTL_RST 0x10
41 #define MXC_PLL_DP_CTL_RCP 0x8
42 #define MXC_PLL_DP_CTL_PLM 0x4
43 #define MXC_PLL_DP_CTL_BRM0 0x2
44 #define MXC_PLL_DP_CTL_LRF 0x1
46 #define MXC_PLL_DP_CONFIG_BIST 0x8
47 #define MXC_PLL_DP_CONFIG_SJC_CE 0x4
48 #define MXC_PLL_DP_CONFIG_AREN 0x2
49 #define MXC_PLL_DP_CONFIG_LDREQ 0x1
51 #define MXC_PLL_DP_OP_MFI_OFFSET 4
52 #define MXC_PLL_DP_OP_MFI_MASK (0xF << 4)
53 #define MXC_PLL_DP_OP_PDF_OFFSET 0
54 #define MXC_PLL_DP_OP_PDF_MASK 0xF
56 #define MXC_PLL_DP_MFD_OFFSET 0
57 #define MXC_PLL_DP_MFD_MASK 0x07FFFFFF
59 #define MXC_PLL_DP_MFN_OFFSET 0x0
60 #define MXC_PLL_DP_MFN_MASK 0x07FFFFFF
62 #define MXC_PLL_DP_MFN_TOGC_TOG_DIS (1 << 17)
63 #define MXC_PLL_DP_MFN_TOGC_TOG_EN (1 << 16)
64 #define MXC_PLL_DP_MFN_TOGC_CNT_OFFSET 0x0
65 #define MXC_PLL_DP_MFN_TOGC_CNT_MASK 0xFFFF
67 #define MXC_PLL_DP_DESTAT_TOG_SEL (1 << 31)
68 #define MXC_PLL_DP_DESTAT_MFN 0x07FFFFFF
70 #define MAX_DPLL_WAIT_TRIES 1000
77 static unsigned long __clk_pllv2_recalc_rate(
unsigned long parent_rate,
80 long mfi, mfn, mfd, pdf, ref_clk, mfn_abs;
88 mfi = (mfi <= 5) ? 5 : mfi;
92 if (mfn >= 0x04000000) {
97 ref_clk = 2 * parent_rate;
101 ref_clk /= (pdf + 1);
102 temp = (
u64) ref_clk * mfn_abs;
106 temp = (ref_clk * mfi) + temp;
111 static unsigned long clk_pllv2_recalc_rate(
struct clk_hw *
hw,
112 unsigned long parent_rate)
125 return __clk_pllv2_recalc_rate(parent_rate, dp_ctl, dp_op, dp_mfd, dp_mfn);
128 static int __clk_pllv2_set_rate(
unsigned long rate,
unsigned long parent_rate,
132 long mfi, pdf, mfn, mfd = 999999;
134 unsigned long quad_parent_rate;
136 quad_parent_rate = 4 * parent_rate;
138 while (++pdf < 16 && mfi < 5)
139 mfi = rate * (pdf+1) / quad_parent_rate;
144 temp64 = rate * (pdf + 1) - quad_parent_rate * mfi;
145 do_div(temp64, quad_parent_rate / 1000000);
148 reg = mfi << 4 | pdf;
157 static int clk_pllv2_set_rate(
struct clk_hw *
hw,
unsigned long rate,
158 unsigned long parent_rate)
168 ret = __clk_pllv2_set_rate(rate, parent_rate, &dp_op, &dp_mfd, &dp_mfn);
183 static long clk_pllv2_round_rate(
struct clk_hw *hw,
unsigned long rate,
184 unsigned long *
prate)
188 __clk_pllv2_set_rate(rate, *prate, &dp_op, &dp_mfd, &dp_mfn);
189 return __clk_pllv2_recalc_rate(*prate, MXC_PLL_DP_CTL_DPDCK0_2_EN,
190 dp_op, dp_mfd, dp_mfn);
193 static int clk_pllv2_prepare(
struct clk_hw *hw)
214 pr_err(
"MX5: pll locking failed\n");
221 static void clk_pllv2_unprepare(
struct clk_hw *hw)
233 .prepare = clk_pllv2_prepare,
234 .unprepare = clk_pllv2_unprepare,
235 .recalc_rate = clk_pllv2_recalc_rate,
236 .round_rate = clk_pllv2_round_rate,
237 .set_rate = clk_pllv2_set_rate,
245 struct clk_init_data init;
256 init.parent_names = &parent;
257 init.num_parents = 1;
259 pll->hw.init = &
init;