2 * Copyright 2012 Freescale Semiconductor, Inc.
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
12 #include <linux/clk.h>
13 #include <linux/clk-provider.h>
14 #include <linux/delay.h>
15 #include <linux/err.h>
17 #include <linux/slab.h>
21 * struct clk_pll - mxs pll clock
22 * @hw: clk_hw for the pll
23 * @base: base address of the pll
24 * @power: the shift of power bit
25 * @rate: the clock rate of the pll
27 * The mxs pll is a fixed rate clock with power and gate control,
28 * and the shift of gate bit is always 31.
37 #define to_clk_pll(_hw) container_of(_hw, struct clk_pll, hw)
39 static int clk_pll_prepare(struct clk_hw
*hw
)
41 struct clk_pll
*pll
= to_clk_pll(hw
);
43 writel_relaxed(1 << pll
->power
, pll
->base
+ SET
);
50 static void clk_pll_unprepare(struct clk_hw
*hw
)
52 struct clk_pll
*pll
= to_clk_pll(hw
);
54 writel_relaxed(1 << pll
->power
, pll
->base
+ CLR
);
57 static int clk_pll_enable(struct clk_hw
*hw
)
59 struct clk_pll
*pll
= to_clk_pll(hw
);
61 writel_relaxed(1 << 31, pll
->base
+ CLR
);
66 static void clk_pll_disable(struct clk_hw
*hw
)
68 struct clk_pll
*pll
= to_clk_pll(hw
);
70 writel_relaxed(1 << 31, pll
->base
+ SET
);
73 static unsigned long clk_pll_recalc_rate(struct clk_hw
*hw
,
74 unsigned long parent_rate
)
76 struct clk_pll
*pll
= to_clk_pll(hw
);
81 static const struct clk_ops clk_pll_ops
= {
82 .prepare
= clk_pll_prepare
,
83 .unprepare
= clk_pll_unprepare
,
84 .enable
= clk_pll_enable
,
85 .disable
= clk_pll_disable
,
86 .recalc_rate
= clk_pll_recalc_rate
,
89 struct clk
*mxs_clk_pll(const char *name
, const char *parent_name
,
90 void __iomem
*base
, u8 power
, unsigned long rate
)
94 struct clk_init_data init
;
96 pll
= kzalloc(sizeof(*pll
), GFP_KERNEL
);
98 return ERR_PTR(-ENOMEM
);
101 init
.ops
= &clk_pll_ops
;
103 init
.parent_names
= (parent_name
? &parent_name
: NULL
);
104 init
.num_parents
= (parent_name
? 1 : 0);
109 pll
->hw
.init
= &init
;
111 clk
= clk_register(NULL
, &pll
->hw
);