1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/* SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause */
/*
* Copyright (C) STMicroelectronics 2022 - All Rights Reserved
* Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
*/
struct stm32_clock_match_data;
/**
* struct stm32_mux_cfg - multiplexer configuration
*
* @parent_names: array of string names for all possible parents
* @num_parents: number of possible parents
* @reg_off: register controlling multiplexer
* @shift: shift to multiplexer bit field
* @width: width of the multiplexer bit field
* @mux_flags: hardware-specific flags
* @table: array of register values corresponding to the parent
* index
*/
struct stm32_mux_cfg {
const char * const *parent_names;
u8 num_parents;
u32 reg_off;
u8 shift;
u8 width;
u8 mux_flags;
u32 *table;
};
/**
* struct stm32_gate_cfg - gating configuration
*
* @reg_off: register controlling gate
* @bit_idx: single bit controlling gate
* @gate_flags: hardware-specific flags
* @set_clr: 0 : normal gate, 1 : has a register to clear the gate
*/
struct stm32_gate_cfg {
u32 reg_off;
u8 bit_idx;
u8 gate_flags;
u8 set_clr;
};
/**
* struct stm32_div_cfg - divider configuration
*
* @reg_off: register containing the divider
* @shift: shift to the divider bit field
* @width: width of the divider bit field
* @table: array of value/divider pairs, last entry should have div = 0
*/
struct stm32_div_cfg {
u32 reg_off;
u8 shift;
u8 width;
u8 div_flags;
const struct clk_div_table *table;
};
#define NO_STM32_MUX -1
#define NO_STM32_DIV -1
#define NO_STM32_GATE -1
/**
* struct stm32_composite_cfg - composite configuration
*
* @mux: index of a multiplexer
* @gate: index of a gate
* @div: index of a divider
*/
struct stm32_composite_cfg {
int mux;
int gate;
int div;
};
/**
* struct clock_config - clock configuration
*
* @id: binding id of the clock
* @name: clock name
* @parent_name: name of the clock parent
* @flags: framework-specific flags
* @sec_id: secure id (use to known if the clock is secured or not)
* @clock_cfg: specific clock data configuration
* @setup: specific call back to reister the clock (will use
* clock_cfg data as input)
*/
struct clock_config {
unsigned long id;
const char *name;
const char *parent_name;
unsigned long flags;
int sec_id;
void *clock_cfg;
struct clk *(*setup)(struct udevice *dev,
const struct clock_config *cfg);
};
/**
* struct clk_stm32_clock_data - clock data
*
* @num_gates: number of defined gates
* @gates: array of gate configuration
* @muxes: array of multiplexer configuration
* @dividers: array of divider configuration
*/
struct clk_stm32_clock_data {
unsigned int num_gates;
const struct stm32_gate_cfg *gates;
const struct stm32_mux_cfg *muxes;
const struct stm32_div_cfg *dividers;
};
/**
* struct stm32_clock_match_data - clock match data
*
* @num_gates: number of clocks
* @tab_clocks: array of clock configuration
* @clock_data: definition of all gates / dividers / multiplexers
* @check_security: call back to check if clock is secured or not
*/
struct stm32_clock_match_data {
unsigned int num_clocks;
const struct clock_config *tab_clocks;
const struct clk_stm32_clock_data *clock_data;
int (*check_security)(void __iomem *base,
const struct clock_config *cfg);
};
/**
* struct stm32mp_rcc_priv - private struct for stm32mp clocks
*
* @base: base register of RCC driver
* @gate_cpt: array of refcounting for gate with more than one
* clocks as input. See explanation of Peripheral clock enabling
* below.
* @data: data for gate / divider / multiplexer configuration
*/
struct stm32mp_rcc_priv {
void __iomem *base;
u8 *gate_cpt;
const struct clk_stm32_clock_data *data;
};
int stm32_rcc_init(struct udevice *dev,
const struct stm32_clock_match_data *data);
/**
* STM32 Gate
*
* PCE (Peripheral Clock Enabling) Peripheral
*
* ------------------------------ ----------
* | | | |
* | | | PERx |
* bus_ck | ----- | | |
* ------------->|------------------| | | ckg_bus_perx | |
* | | AND |-----|---------------->| |
* | -----------| | | | |
* | | ----- | | |
* | | | | |
* | ----- | | |
* Perx_EN |-----|---| GCL | Gating | | |
* | ----- Control | | |
* | | Logic | | |
* | | | | |
* | | ----- | | |
* | -----------| | | ckg_ker_perx | |
* perx_ker_ck | | AND |-----|---------------->| |
* ------------->|------------------| | | | |
* | ----- | | |
* | | | |
* | | | |
* ------------------------------ ----------
* Each peripheral requires a bus interface clock, named ckg_bus_perx
* (for peripheral `x').
* Some peripherals (SAI, UART...) need also a dedicated clock for their
* communication interface, this clock is generally asynchronous with respect to
* the bus interface clock, and is named kernel clock (ckg_ker_perx).
* Both clocks can be gated by one Perx_EN enable bit.
* Then we have to manage a refcounting on gate level to avoid gate if one
* the bus or the Kernel was enable.
*
* Example:
* 1) enable the bus clock
* --> bus_clk ref_counting = 1, gate_ref_count = 1
* 2) enable the kernel clock
* --> perx_ker_ck ref_counting = 1, gate_ref_count = 2
* 3) disable kernel clock
* ---> perx_ker_ck ref_counting = 0, gate_ref_count = 1
* ==> then i will not gate because gate_ref_count > 0
* 4) disable bus clock
* --> bus_clk ref_counting = 0, gate_ref_count = 0
* ==> then i can gate (write in the register) because
* gate_ref_count = 0
*/
struct clk_stm32_gate {
struct clk clk;
struct stm32mp_rcc_priv *priv;
int gate_id;
};
#define to_clk_stm32_gate(_clk) container_of(_clk, struct clk_stm32_gate, clk)
struct clk *
clk_stm32_gate_register(struct udevice *dev,
const struct clock_config *cfg);
struct clk *
clk_stm32_register_composite(struct udevice *dev,
const struct clock_config *cfg);
struct stm32_clk_gate_cfg {
int gate_id;
};
#define STM32_GATE(_id, _name, _parent, _flags, _gate_id, _sec_id) \
{ \
.id = _id, \
.sec_id = _sec_id, \
.name = _name, \
.parent_name = _parent, \
.flags = _flags, \
.clock_cfg = &(struct stm32_clk_gate_cfg) { \
.gate_id = _gate_id, \
}, \
.setup = clk_stm32_gate_register, \
}
struct stm32_clk_composite_cfg {
int gate_id;
int mux_id;
int div_id;
};
#define STM32_COMPOSITE(_id, _name, _flags, _sec_id, \
_gate_id, _mux_id, _div_id) \
{ \
.id = _id, \
.name = _name, \
.sec_id = _sec_id, \
.flags = _flags, \
.clock_cfg = &(struct stm32_clk_composite_cfg) { \
.gate_id = _gate_id, \
.mux_id = _mux_id, \
.div_id = _div_id, \
}, \
.setup = clk_stm32_register_composite, \
}
#define STM32_COMPOSITE_NOMUX(_id, _name, _parent, _flags, _sec_id, \
_gate_id, _div_id) \
{ \
.id = _id, \
.name = _name, \
.parent_name = _parent, \
.sec_id = _sec_id, \
.flags = _flags, \
.clock_cfg = &(struct stm32_clk_composite_cfg) { \
.gate_id = _gate_id, \
.mux_id = NO_STM32_MUX, \
.div_id = _div_id, \
}, \
.setup = clk_stm32_register_composite, \
}
extern const struct clk_ops stm32_clk_ops;
ulong clk_stm32_get_rate_by_name(const char *name);
|