2 * mmp APB clock operation source file
4 * Copyright (C) 2012 Marvell
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
12 #include <linux/kernel.h>
13 #include <linux/clk.h>
15 #include <linux/err.h>
16 #include <linux/delay.h>
17 #include <linux/slab.h>
21 /* Common APB clock register bit definitions */
22 #define APBC_APBCLK (1 << 0) /* APB Bus Clock Enable */
23 #define APBC_FNCLK (1 << 1) /* Functional Clock Enable */
24 #define APBC_RST (1 << 2) /* Reset Generation */
25 #define APBC_POWER (1 << 7) /* Reset Generation */
27 #define to_clk_apbc(hw) container_of(hw, struct clk_apbc, hw)
36 static int clk_apbc_prepare(struct clk_hw *hw)
38 struct clk_apbc *apbc = to_clk_apbc(hw);
40 unsigned long flags = 0;
43 * It may share same register as MUX clock,
44 * and it will impact FNCLK enable. Spinlock is needed
47 spin_lock_irqsave(apbc->lock, flags);
49 data = readl_relaxed(apbc->base);
50 if (apbc->flags & APBC_POWER_CTRL)
53 writel_relaxed(data, apbc->base);
56 spin_unlock_irqrestore(apbc->lock, flags);
61 spin_lock_irqsave(apbc->lock, flags);
63 data = readl_relaxed(apbc->base);
65 writel_relaxed(data, apbc->base);
68 spin_unlock_irqrestore(apbc->lock, flags);
72 if (!(apbc->flags & APBC_NO_BUS_CTRL)) {
74 spin_lock_irqsave(apbc->lock, flags);
76 data = readl_relaxed(apbc->base);
78 writel_relaxed(data, apbc->base);
81 spin_unlock_irqrestore(apbc->lock, flags);
87 static void clk_apbc_unprepare(struct clk_hw *hw)
89 struct clk_apbc *apbc = to_clk_apbc(hw);
91 unsigned long flags = 0;
94 spin_lock_irqsave(apbc->lock, flags);
96 data = readl_relaxed(apbc->base);
97 if (apbc->flags & APBC_POWER_CTRL)
100 writel_relaxed(data, apbc->base);
103 spin_unlock_irqrestore(apbc->lock, flags);
108 spin_lock_irqsave(apbc->lock, flags);
110 data = readl_relaxed(apbc->base);
111 data &= ~APBC_APBCLK;
112 writel_relaxed(data, apbc->base);
115 spin_unlock_irqrestore(apbc->lock, flags);
118 struct clk_ops clk_apbc_ops = {
119 .prepare = clk_apbc_prepare,
120 .unprepare = clk_apbc_unprepare,
123 struct clk *mmp_clk_register_apbc(const char *name, const char *parent_name,
124 void __iomem *base, unsigned int delay,
125 unsigned int apbc_flags, spinlock_t *lock)
127 struct clk_apbc *apbc;
129 struct clk_init_data init;
131 apbc = kzalloc(sizeof(*apbc), GFP_KERNEL);
136 init.ops = &clk_apbc_ops;
137 init.flags = CLK_SET_RATE_PARENT;
138 init.parent_names = (parent_name ? &parent_name : NULL);
139 init.num_parents = (parent_name ? 1 : 0);
143 apbc->flags = apbc_flags;
145 apbc->hw.init = &init;
147 clk = clk_register(NULL, &apbc->hw);