.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com> |
---|
3 | 4 | * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org> |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License version 2 as |
---|
7 | | - * published by the Free Software Foundation. |
---|
8 | 5 | * |
---|
9 | 6 | * Gated clock implementation |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
12 | 9 | #include <linux/clk-provider.h> |
---|
| 10 | +#include <linux/export.h> |
---|
13 | 11 | #include <linux/module.h> |
---|
14 | 12 | #include <linux/slab.h> |
---|
15 | 13 | #include <linux/io.h> |
---|
.. | .. |
---|
18 | 16 | #include "clk.h" |
---|
19 | 17 | |
---|
20 | 18 | /** |
---|
21 | | - * DOC: basic gatable clock which can gate and ungate it's ouput |
---|
| 19 | + * DOC: basic gateable clock which can gate and ungate its output |
---|
22 | 20 | * |
---|
23 | 21 | * Traits of this clock: |
---|
24 | 22 | * prepare - clk_(un)prepare only ensures parent is (un)prepared |
---|
.. | .. |
---|
43 | 41 | { |
---|
44 | 42 | struct clk_gate2 *gate = to_clk_gate2(hw); |
---|
45 | 43 | u32 reg; |
---|
46 | | - unsigned long flags = 0; |
---|
| 44 | + unsigned long flags; |
---|
| 45 | + int ret = 0; |
---|
47 | 46 | |
---|
48 | 47 | spin_lock_irqsave(gate->lock, flags); |
---|
49 | 48 | |
---|
50 | 49 | if (gate->share_count && (*gate->share_count)++ > 0) |
---|
51 | 50 | goto out; |
---|
52 | 51 | |
---|
53 | | - reg = readl(gate->reg); |
---|
54 | | - reg &= ~(3 << gate->bit_idx); |
---|
55 | | - reg |= gate->cgr_val << gate->bit_idx; |
---|
56 | | - writel(reg, gate->reg); |
---|
| 52 | + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) { |
---|
| 53 | + ret = clk_gate_ops.enable(hw); |
---|
| 54 | + } else { |
---|
| 55 | + reg = readl(gate->reg); |
---|
| 56 | + reg &= ~(3 << gate->bit_idx); |
---|
| 57 | + reg |= gate->cgr_val << gate->bit_idx; |
---|
| 58 | + writel(reg, gate->reg); |
---|
| 59 | + } |
---|
57 | 60 | |
---|
58 | 61 | out: |
---|
59 | 62 | spin_unlock_irqrestore(gate->lock, flags); |
---|
60 | 63 | |
---|
61 | | - return 0; |
---|
| 64 | + return ret; |
---|
62 | 65 | } |
---|
63 | 66 | |
---|
64 | 67 | static void clk_gate2_disable(struct clk_hw *hw) |
---|
65 | 68 | { |
---|
66 | 69 | struct clk_gate2 *gate = to_clk_gate2(hw); |
---|
67 | 70 | u32 reg; |
---|
68 | | - unsigned long flags = 0; |
---|
| 71 | + unsigned long flags; |
---|
69 | 72 | |
---|
70 | 73 | spin_lock_irqsave(gate->lock, flags); |
---|
71 | 74 | |
---|
.. | .. |
---|
76 | 79 | goto out; |
---|
77 | 80 | } |
---|
78 | 81 | |
---|
79 | | - reg = readl(gate->reg); |
---|
80 | | - reg &= ~(3 << gate->bit_idx); |
---|
81 | | - writel(reg, gate->reg); |
---|
| 82 | + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) { |
---|
| 83 | + clk_gate_ops.disable(hw); |
---|
| 84 | + } else { |
---|
| 85 | + reg = readl(gate->reg); |
---|
| 86 | + reg &= ~(3 << gate->bit_idx); |
---|
| 87 | + writel(reg, gate->reg); |
---|
| 88 | + } |
---|
82 | 89 | |
---|
83 | 90 | out: |
---|
84 | 91 | spin_unlock_irqrestore(gate->lock, flags); |
---|
.. | .. |
---|
98 | 105 | { |
---|
99 | 106 | struct clk_gate2 *gate = to_clk_gate2(hw); |
---|
100 | 107 | |
---|
| 108 | + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) |
---|
| 109 | + return clk_gate_ops.is_enabled(hw); |
---|
| 110 | + |
---|
101 | 111 | return clk_gate2_reg_is_enabled(gate->reg, gate->bit_idx); |
---|
102 | 112 | } |
---|
103 | 113 | |
---|
104 | 114 | static void clk_gate2_disable_unused(struct clk_hw *hw) |
---|
105 | 115 | { |
---|
106 | 116 | struct clk_gate2 *gate = to_clk_gate2(hw); |
---|
107 | | - unsigned long flags = 0; |
---|
| 117 | + unsigned long flags; |
---|
108 | 118 | u32 reg; |
---|
| 119 | + |
---|
| 120 | + if (gate->flags & IMX_CLK_GATE2_SINGLE_BIT) |
---|
| 121 | + return; |
---|
109 | 122 | |
---|
110 | 123 | spin_lock_irqsave(gate->lock, flags); |
---|
111 | 124 | |
---|
.. | .. |
---|
125 | 138 | .is_enabled = clk_gate2_is_enabled, |
---|
126 | 139 | }; |
---|
127 | 140 | |
---|
128 | | -struct clk *clk_register_gate2(struct device *dev, const char *name, |
---|
| 141 | +struct clk_hw *clk_hw_register_gate2(struct device *dev, const char *name, |
---|
129 | 142 | const char *parent_name, unsigned long flags, |
---|
130 | 143 | void __iomem *reg, u8 bit_idx, u8 cgr_val, |
---|
131 | 144 | u8 clk_gate2_flags, spinlock_t *lock, |
---|
132 | 145 | unsigned int *share_count) |
---|
133 | 146 | { |
---|
134 | 147 | struct clk_gate2 *gate; |
---|
135 | | - struct clk *clk; |
---|
136 | | - struct clk_init_data init = {}; |
---|
| 148 | + struct clk_hw *hw; |
---|
| 149 | + struct clk_init_data init; |
---|
| 150 | + int ret; |
---|
137 | 151 | |
---|
138 | 152 | gate = kzalloc(sizeof(struct clk_gate2), GFP_KERNEL); |
---|
139 | 153 | if (!gate) |
---|
.. | .. |
---|
154 | 168 | init.num_parents = parent_name ? 1 : 0; |
---|
155 | 169 | |
---|
156 | 170 | gate->hw.init = &init; |
---|
| 171 | + hw = &gate->hw; |
---|
157 | 172 | |
---|
158 | | - clk = clk_register(dev, &gate->hw); |
---|
159 | | - if (IS_ERR(clk)) |
---|
| 173 | + ret = clk_hw_register(dev, hw); |
---|
| 174 | + if (ret) { |
---|
160 | 175 | kfree(gate); |
---|
| 176 | + return ERR_PTR(ret); |
---|
| 177 | + } |
---|
161 | 178 | |
---|
162 | | - return clk; |
---|
| 179 | + return hw; |
---|
163 | 180 | } |
---|
| 181 | +EXPORT_SYMBOL_GPL(clk_hw_register_gate2); |
---|