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-provider.h>
13 #include <linux/delay.h>
14 #include <linux/err.h>
16 #include <linux/slab.h>
20 * struct clk_pll - mxs pll clock
21 * @hw: clk_hw for the pll
22 * @base: base address of the pll
23 * @power: the shift of power bit
24 * @rate: the clock rate of the pll
26 * The mxs pll is a fixed rate clock with power and gate control,
27 * and the shift of gate bit is always 31.
36 #define to_clk_pll(_hw) container_of(_hw, struct clk_pll, hw)
38 static int clk_pll_prepare(struct clk_hw *hw)
40 struct clk_pll *pll = to_clk_pll(hw);
42 writel_relaxed(1 << pll->power, pll->base + SET);
49 static void clk_pll_unprepare(struct clk_hw *hw)
51 struct clk_pll *pll = to_clk_pll(hw);
53 writel_relaxed(1 << pll->power, pll->base + CLR);
56 static int clk_pll_enable(struct clk_hw *hw)
58 struct clk_pll *pll = to_clk_pll(hw);
60 writel_relaxed(1 << 31, pll->base + CLR);
65 static void clk_pll_disable(struct clk_hw *hw)
67 struct clk_pll *pll = to_clk_pll(hw);
69 writel_relaxed(1 << 31, pll->base + SET);
72 static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
73 unsigned long parent_rate)
75 struct clk_pll *pll = to_clk_pll(hw);
80 static const struct clk_ops clk_pll_ops = {
81 .prepare = clk_pll_prepare,
82 .unprepare = clk_pll_unprepare,
83 .enable = clk_pll_enable,
84 .disable = clk_pll_disable,
85 .recalc_rate = clk_pll_recalc_rate,
88 struct clk *mxs_clk_pll(const char *name, const char *parent_name,
89 void __iomem *base, u8 power, unsigned long rate)
93 struct clk_init_data init;
95 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
97 return ERR_PTR(-ENOMEM);
100 init.ops = &clk_pll_ops;
102 init.parent_names = (parent_name ? &parent_name: NULL);
103 init.num_parents = (parent_name ? 1 : 0);
108 pll->hw.init = &init;
110 clk = clk_register(NULL, &pll->hw);