2 #include <linux/clk-provider.h>
4 #include <linux/slab.h>
5 #include <linux/kernel.h>
15 * @clk_hw clock source
16 * @parent the parent clock name
17 * @base base address of pll registers
19 * PLL clock version 1, found on i.MX1/21/25/27/31/35
23 #define MFN_SIGN (BIT(MFN_BITS - 1))
24 #define MFN_MASK (MFN_SIGN - 1)
29 enum imx_pllv1_type type
;
32 #define to_clk_pllv1(clk) (container_of(clk, struct clk_pllv1, clk))
34 static inline bool is_imx1_pllv1(struct clk_pllv1
*pll
)
36 return pll
->type
== IMX_PLLV1_IMX1
;
39 static inline bool is_imx21_pllv1(struct clk_pllv1
*pll
)
41 return pll
->type
== IMX_PLLV1_IMX21
;
44 static inline bool is_imx27_pllv1(struct clk_pllv1
*pll
)
46 return pll
->type
== IMX_PLLV1_IMX27
;
49 static inline bool mfn_is_negative(struct clk_pllv1
*pll
, unsigned int mfn
)
51 return !is_imx1_pllv1(pll
) && !is_imx21_pllv1(pll
) && (mfn
& MFN_SIGN
);
54 static unsigned long clk_pllv1_recalc_rate(struct clk_hw
*hw
,
55 unsigned long parent_rate
)
57 struct clk_pllv1
*pll
= to_clk_pllv1(hw
);
60 unsigned int mfi
, mfn
, mfd
, pd
;
64 reg
= readl(pll
->base
);
67 * Get the resulting clock rate from a PLL register value and the input
68 * frequency. PLLs with this register layout can be found on i.MX1,
69 * i.MX21, i.MX27 and i,MX31
71 * mfi + mfn / (mfd + 1)
72 * f = 2 * f_ref * --------------------
76 mfi
= (reg
>> 10) & 0xf;
78 mfd
= (reg
>> 16) & 0x3ff;
79 pd
= (reg
>> 26) & 0xf;
81 mfi
= mfi
<= 5 ? 5 : mfi
;
86 * On all i.MXs except i.MX1 and i.MX21 mfn is a 10bit
87 * 2's complements number.
88 * On i.MX27 the bit 9 is the sign bit.
90 if (mfn_is_negative(pll
, mfn
)) {
91 if (is_imx27_pllv1(pll
))
92 mfn_abs
= mfn
& MFN_MASK
;
94 mfn_abs
= BIT(MFN_BITS
) - mfn
;
97 rate
= parent_rate
* 2;
100 ll
= (unsigned long long)rate
* mfn_abs
;
104 if (mfn_is_negative(pll
, mfn
))
107 ll
= (rate
* mfi
) + ll
;
112 static struct clk_ops clk_pllv1_ops
= {
113 .recalc_rate
= clk_pllv1_recalc_rate
,
116 struct clk
*imx_clk_pllv1(enum imx_pllv1_type type
, const char *name
,
117 const char *parent
, void __iomem
*base
)
119 struct clk_pllv1
*pll
;
121 struct clk_init_data init
;
123 pll
= kmalloc(sizeof(*pll
), GFP_KERNEL
);
125 return ERR_PTR(-ENOMEM
);
131 init
.ops
= &clk_pllv1_ops
;
133 init
.parent_names
= &parent
;
134 init
.num_parents
= 1;
136 pll
->hw
.init
= &init
;
138 clk
= clk_register(NULL
, &pll
->hw
);
This page took 0.118234 seconds and 5 git commands to generate.