.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify it |
---|
5 | | - * under the terms and conditions of the GNU General Public License, |
---|
6 | | - * version 2, as published by the Free Software Foundation. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
---|
9 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
10 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
11 | | - * more details. |
---|
12 | | - * |
---|
13 | | - * You should have received a copy of the GNU General Public License |
---|
14 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | 4 | */ |
---|
16 | 5 | |
---|
17 | 6 | #include <linux/clk-provider.h> |
---|
.. | .. |
---|
59 | 48 | return state; |
---|
60 | 49 | } |
---|
61 | 50 | |
---|
62 | | -static int clk_periph_enable(struct clk_hw *hw) |
---|
| 51 | +static void clk_periph_enable_locked(struct clk_hw *hw) |
---|
63 | 52 | { |
---|
64 | 53 | struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); |
---|
65 | | - unsigned long flags = 0; |
---|
66 | | - |
---|
67 | | - spin_lock_irqsave(&periph_ref_lock, flags); |
---|
68 | | - |
---|
69 | | - gate->enable_refcnt[gate->clk_num]++; |
---|
70 | | - if (gate->enable_refcnt[gate->clk_num] > 1) { |
---|
71 | | - spin_unlock_irqrestore(&periph_ref_lock, flags); |
---|
72 | | - return 0; |
---|
73 | | - } |
---|
74 | 54 | |
---|
75 | 55 | write_enb_set(periph_clk_to_bit(gate), gate); |
---|
76 | 56 | udelay(2); |
---|
.. | .. |
---|
89 | 69 | udelay(1); |
---|
90 | 70 | writel_relaxed(0, gate->clk_base + LVL2_CLK_GATE_OVRE); |
---|
91 | 71 | } |
---|
| 72 | +} |
---|
| 73 | + |
---|
| 74 | +static void clk_periph_disable_locked(struct clk_hw *hw) |
---|
| 75 | +{ |
---|
| 76 | + struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); |
---|
| 77 | + |
---|
| 78 | + /* |
---|
| 79 | + * If peripheral is in the APB bus then read the APB bus to |
---|
| 80 | + * flush the write operation in apb bus. This will avoid the |
---|
| 81 | + * peripheral access after disabling clock |
---|
| 82 | + */ |
---|
| 83 | + if (gate->flags & TEGRA_PERIPH_ON_APB) |
---|
| 84 | + tegra_read_chipid(); |
---|
| 85 | + |
---|
| 86 | + write_enb_clr(periph_clk_to_bit(gate), gate); |
---|
| 87 | +} |
---|
| 88 | + |
---|
| 89 | +static int clk_periph_enable(struct clk_hw *hw) |
---|
| 90 | +{ |
---|
| 91 | + struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); |
---|
| 92 | + unsigned long flags = 0; |
---|
| 93 | + |
---|
| 94 | + spin_lock_irqsave(&periph_ref_lock, flags); |
---|
| 95 | + |
---|
| 96 | + if (!gate->enable_refcnt[gate->clk_num]++) |
---|
| 97 | + clk_periph_enable_locked(hw); |
---|
92 | 98 | |
---|
93 | 99 | spin_unlock_irqrestore(&periph_ref_lock, flags); |
---|
94 | 100 | |
---|
.. | .. |
---|
102 | 108 | |
---|
103 | 109 | spin_lock_irqsave(&periph_ref_lock, flags); |
---|
104 | 110 | |
---|
105 | | - gate->enable_refcnt[gate->clk_num]--; |
---|
106 | | - if (gate->enable_refcnt[gate->clk_num] > 0) { |
---|
107 | | - spin_unlock_irqrestore(&periph_ref_lock, flags); |
---|
108 | | - return; |
---|
109 | | - } |
---|
| 111 | + WARN_ON(!gate->enable_refcnt[gate->clk_num]); |
---|
| 112 | + |
---|
| 113 | + if (--gate->enable_refcnt[gate->clk_num] == 0) |
---|
| 114 | + clk_periph_disable_locked(hw); |
---|
| 115 | + |
---|
| 116 | + spin_unlock_irqrestore(&periph_ref_lock, flags); |
---|
| 117 | +} |
---|
| 118 | + |
---|
| 119 | +static void clk_periph_disable_unused(struct clk_hw *hw) |
---|
| 120 | +{ |
---|
| 121 | + struct tegra_clk_periph_gate *gate = to_clk_periph_gate(hw); |
---|
| 122 | + unsigned long flags = 0; |
---|
| 123 | + |
---|
| 124 | + spin_lock_irqsave(&periph_ref_lock, flags); |
---|
110 | 125 | |
---|
111 | 126 | /* |
---|
112 | | - * If peripheral is in the APB bus then read the APB bus to |
---|
113 | | - * flush the write operation in apb bus. This will avoid the |
---|
114 | | - * peripheral access after disabling clock |
---|
| 127 | + * Some clocks are duplicated and some of them are marked as critical, |
---|
| 128 | + * like fuse and fuse_burn for example, thus the enable_refcnt will |
---|
| 129 | + * be non-zero here if the "unused" duplicate is disabled by CCF. |
---|
115 | 130 | */ |
---|
116 | | - if (gate->flags & TEGRA_PERIPH_ON_APB) |
---|
117 | | - tegra_read_chipid(); |
---|
118 | | - |
---|
119 | | - write_enb_clr(periph_clk_to_bit(gate), gate); |
---|
| 131 | + if (!gate->enable_refcnt[gate->clk_num]) |
---|
| 132 | + clk_periph_disable_locked(hw); |
---|
120 | 133 | |
---|
121 | 134 | spin_unlock_irqrestore(&periph_ref_lock, flags); |
---|
122 | 135 | } |
---|
.. | .. |
---|
125 | 138 | .is_enabled = clk_periph_is_enabled, |
---|
126 | 139 | .enable = clk_periph_enable, |
---|
127 | 140 | .disable = clk_periph_disable, |
---|
| 141 | + .disable_unused = clk_periph_disable_unused, |
---|
128 | 142 | }; |
---|
129 | 143 | |
---|
130 | 144 | struct clk *tegra_clk_register_periph_gate(const char *name, |
---|
.. | .. |
---|
133 | 147 | { |
---|
134 | 148 | struct tegra_clk_periph_gate *gate; |
---|
135 | 149 | struct clk *clk; |
---|
136 | | - struct clk_init_data init = {}; |
---|
| 150 | + struct clk_init_data init; |
---|
137 | 151 | const struct tegra_clk_periph_regs *pregs; |
---|
138 | 152 | |
---|
139 | 153 | pregs = get_reg_bank(clk_num); |
---|
.. | .. |
---|
158 | 172 | gate->flags = gate_flags; |
---|
159 | 173 | gate->enable_refcnt = enable_refcnt; |
---|
160 | 174 | gate->regs = pregs; |
---|
161 | | - |
---|
162 | | - if (read_enb(gate) & periph_clk_to_bit(gate)) |
---|
163 | | - enable_refcnt[clk_num]++; |
---|
164 | 175 | |
---|
165 | 176 | /* Data in .init is copied by clk_register(), so stack variable OK */ |
---|
166 | 177 | gate->hw.init = &init; |
---|