1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
4 * Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
5 */
6 #ifndef __LINUX_CLK_PROVIDER_H
7 #define __LINUX_CLK_PROVIDER_H
8
9 #include <linux/of.h>
10 #include <linux/of_clk.h>
11
12 /*
13 * flags used across common struct clk. these flags should only affect the
14 * top-level framework. custom flags for dealing with hardware specifics
15 * belong in struct clk_foo
16 *
17 * Please update clk_flags[] in drivers/clk/clk.c when making changes here!
18 */
19 #define CLK_SET_RATE_GATE BIT(0) /* must be gated across rate change */
20 #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
21 #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
22 #define CLK_IGNORE_UNUSED BIT(3) /* do not gate even if unused */
23 /* unused */
24 /* unused */
25 #define CLK_GET_RATE_NOCACHE BIT(6) /* do not use the cached clk rate */
26 #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
27 #define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
28 #define CLK_RECALC_NEW_RATES BIT(9) /* recalc rates after notifications */
29 #define CLK_SET_RATE_UNGATE BIT(10) /* clock needs to run to set rate */
30 #define CLK_IS_CRITICAL BIT(11) /* do not gate, ever */
31 /* parents need enable during gate/ungate, set rate and re-parent */
32 #define CLK_OPS_PARENT_ENABLE BIT(12)
33 /* duty cycle call may be forwarded to the parent clock */
34 #define CLK_DUTY_CYCLE_PARENT BIT(13)
35 #define CLK_DONT_HOLD_STATE BIT(14) /* Don't hold state */
36
37 struct clk;
38 struct clk_hw;
39 struct clk_core;
40 struct dentry;
41
42 /**
43 * struct clk_rate_request - Structure encoding the clk constraints that
44 * a clock user might require.
45 *
46 * Should be initialized by calling clk_hw_init_rate_request().
47 *
48 * @core: Pointer to the struct clk_core affected by this request
49 * @rate: Requested clock rate. This field will be adjusted by
50 * clock drivers according to hardware capabilities.
51 * @min_rate: Minimum rate imposed by clk users.
52 * @max_rate: Maximum rate imposed by clk users.
53 * @best_parent_rate: The best parent rate a parent can provide to fulfill the
54 * requested constraints.
55 * @best_parent_hw: The most appropriate parent clock that fulfills the
56 * requested constraints.
57 *
58 */
59 struct clk_rate_request {
60 struct clk_core *core;
61 unsigned long rate;
62 unsigned long min_rate;
63 unsigned long max_rate;
64 unsigned long best_parent_rate;
65 struct clk_hw *best_parent_hw;
66 };
67
68 void clk_hw_init_rate_request(const struct clk_hw *hw,
69 struct clk_rate_request *req,
70 unsigned long rate);
71 void clk_hw_forward_rate_request(const struct clk_hw *core,
72 const struct clk_rate_request *old_req,
73 const struct clk_hw *parent,
74 struct clk_rate_request *req,
75 unsigned long parent_rate);
76
77 /**
78 * struct clk_duty - Structure encoding the duty cycle ratio of a clock
79 *
80 * @num: Numerator of the duty cycle ratio
81 * @den: Denominator of the duty cycle ratio
82 */
83 struct clk_duty {
84 unsigned int num;
85 unsigned int den;
86 };
87
88 /**
89 * struct clk_ops - Callback operations for hardware clocks; these are to
90 * be provided by the clock implementation, and will be called by drivers
91 * through the clk_* api.
92 *
93 * @prepare: Prepare the clock for enabling. This must not return until
94 * the clock is fully prepared, and it's safe to call clk_enable.
95 * This callback is intended to allow clock implementations to
96 * do any initialisation that may sleep. Called with
97 * prepare_lock held.
98 *
99 * @unprepare: Release the clock from its prepared state. This will typically
100 * undo any work done in the @prepare callback. Called with
101 * prepare_lock held.
102 *
103 * @is_prepared: Queries the hardware to determine if the clock is prepared.
104 * This function is allowed to sleep. Optional, if this op is not
105 * set then the prepare count will be used.
106 *
107 * @unprepare_unused: Unprepare the clock atomically. Only called from
108 * clk_disable_unused for prepare clocks with special needs.
109 * Called with prepare mutex held. This function may sleep.
110 *
111 * @enable: Enable the clock atomically. This must not return until the
112 * clock is generating a valid clock signal, usable by consumer
113 * devices. Called with enable_lock held. This function must not
114 * sleep.
115 *
116 * @disable: Disable the clock atomically. Called with enable_lock held.
117 * This function must not sleep.
118 *
119 * @is_enabled: Queries the hardware to determine if the clock is enabled.
120 * This function must not sleep. Optional, if this op is not
121 * set then the enable count will be used.
122 *
123 * @disable_unused: Disable the clock atomically. Only called from
124 * clk_disable_unused for gate clocks with special needs.
125 * Called with enable_lock held. This function must not
126 * sleep.
127 *
128 * @save_context: Save the context of the clock in prepration for poweroff.
129 *
130 * @restore_context: Restore the context of the clock after a restoration
131 * of power.
132 *
133 * @recalc_rate: Recalculate the rate of this clock, by querying hardware. The
134 * parent rate is an input parameter. It is up to the caller to
135 * ensure that the prepare_mutex is held across this call. If the
136 * driver cannot figure out a rate for this clock, it must return
137 * 0. Returns the calculated rate. Optional, but recommended - if
138 * this op is not set then clock rate will be initialized to 0.
139 *
140 * @round_rate: Given a target rate as input, returns the closest rate actually
141 * supported by the clock. The parent rate is an input/output
142 * parameter.
143 *
144 * @determine_rate: Given a target rate as input, returns the closest rate
145 * actually supported by the clock, and optionally the parent clock
146 * that should be used to provide the clock rate.
147 *
148 * @set_parent: Change the input source of this clock; for clocks with multiple
149 * possible parents specify a new parent by passing in the index
150 * as a u8 corresponding to the parent in either the .parent_names
151 * or .parents arrays. This function in affect translates an
152 * array index into the value programmed into the hardware.
153 * Returns 0 on success, -EERROR otherwise.
154 *
155 * @get_parent: Queries the hardware to determine the parent of a clock. The
156 * return value is a u8 which specifies the index corresponding to
157 * the parent clock. This index can be applied to either the
158 * .parent_names or .parents arrays. In short, this function
159 * translates the parent value read from hardware into an array
160 * index. Currently only called when the clock is initialized by
161 * __clk_init. This callback is mandatory for clocks with
162 * multiple parents. It is optional (and unnecessary) for clocks
163 * with 0 or 1 parents.
164 *
165 * @set_rate: Change the rate of this clock. The requested rate is specified
166 * by the second argument, which should typically be the return
167 * of .round_rate call. The third argument gives the parent rate
168 * which is likely helpful for most .set_rate implementation.
169 * Returns 0 on success, -EERROR otherwise.
170 *
171 * @set_rate_and_parent: Change the rate and the parent of this clock. The
172 * requested rate is specified by the second argument, which
173 * should typically be the return of .round_rate call. The
174 * third argument gives the parent rate which is likely helpful
175 * for most .set_rate_and_parent implementation. The fourth
176 * argument gives the parent index. This callback is optional (and
177 * unnecessary) for clocks with 0 or 1 parents as well as
178 * for clocks that can tolerate switching the rate and the parent
179 * separately via calls to .set_parent and .set_rate.
180 * Returns 0 on success, -EERROR otherwise.
181 *
182 * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy
183 * is expressed in ppb (parts per billion). The parent accuracy is
184 * an input parameter.
185 * Returns the calculated accuracy. Optional - if this op is not
186 * set then clock accuracy will be initialized to parent accuracy
187 * or 0 (perfect clock) if clock has no parent.
188 *
189 * @get_phase: Queries the hardware to get the current phase of a clock.
190 * Returned values are 0-359 degrees on success, negative
191 * error codes on failure.
192 *
193 * @set_phase: Shift the phase this clock signal in degrees specified
194 * by the second argument. Valid values for degrees are
195 * 0-359. Return 0 on success, otherwise -EERROR.
196 *
197 * @get_duty_cycle: Queries the hardware to get the current duty cycle ratio
198 * of a clock. Returned values denominator cannot be 0 and must be
199 * superior or equal to the numerator.
200 *
201 * @set_duty_cycle: Apply the duty cycle ratio to this clock signal specified by
202 * the numerator (2nd argurment) and denominator (3rd argument).
203 * Argument must be a valid ratio (denominator > 0
204 * and >= numerator) Return 0 on success, otherwise -EERROR.
205 *
206 * @init: Perform platform-specific initialization magic.
207 * This is not used by any of the basic clock types.
208 * This callback exist for HW which needs to perform some
209 * initialisation magic for CCF to get an accurate view of the
210 * clock. It may also be used dynamic resource allocation is
211 * required. It shall not used to deal with clock parameters,
212 * such as rate or parents.
213 * Returns 0 on success, -EERROR otherwise.
214 *
215 * @terminate: Free any resource allocated by init.
216 *
217 * @debug_init: Set up type-specific debugfs entries for this clock. This
218 * is called once, after the debugfs directory entry for this
219 * clock has been created. The dentry pointer representing that
220 * directory is provided as an argument. Called with
221 * prepare_lock held. Returns 0 on success, -EERROR otherwise.
222 *
223 * @pre_rate_change: Optional callback for a clock to fulfill its rate
224 * change requirements before any rate change has occurred in
225 * its clock tree. Returns 0 on success, -EERROR otherwise.
226 *
227 * @post_rate_change: Optional callback for a clock to clean up any
228 * requirements that were needed while the clock and its tree
229 * was changing states. Returns 0 on success, -EERROR otherwise.
230 *
231 * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow
232 * implementations to split any work between atomic (enable) and sleepable
233 * (prepare) contexts. If enabling a clock requires code that might sleep,
234 * this must be done in clk_prepare. Clock enable code that will never be
235 * called in a sleepable context may be implemented in clk_enable.
236 *
237 * Typically, drivers will call clk_prepare when a clock may be needed later
238 * (eg. when a device is opened), and clk_enable when the clock is actually
239 * required (eg. from an interrupt). Note that clk_prepare MUST have been
240 * called before clk_enable.
241 */
242 struct clk_ops {
243 int (*prepare)(struct clk_hw *hw);
244 void (*unprepare)(struct clk_hw *hw);
245 int (*is_prepared)(struct clk_hw *hw);
246 void (*unprepare_unused)(struct clk_hw *hw);
247 int (*enable)(struct clk_hw *hw);
248 void (*disable)(struct clk_hw *hw);
249 int (*is_enabled)(struct clk_hw *hw);
250 void (*disable_unused)(struct clk_hw *hw);
251 int (*save_context)(struct clk_hw *hw);
252 void (*restore_context)(struct clk_hw *hw);
253 unsigned long (*recalc_rate)(struct clk_hw *hw,
254 unsigned long parent_rate);
255 long (*round_rate)(struct clk_hw *hw, unsigned long rate,
256 unsigned long *parent_rate);
257 int (*determine_rate)(struct clk_hw *hw,
258 struct clk_rate_request *req);
259 int (*set_parent)(struct clk_hw *hw, u8 index);
260 u8 (*get_parent)(struct clk_hw *hw);
261 int (*set_rate)(struct clk_hw *hw, unsigned long rate,
262 unsigned long parent_rate);
263 int (*set_rate_and_parent)(struct clk_hw *hw,
264 unsigned long rate,
265 unsigned long parent_rate, u8 index);
266 unsigned long (*recalc_accuracy)(struct clk_hw *hw,
267 unsigned long parent_accuracy);
268 int (*get_phase)(struct clk_hw *hw);
269 int (*set_phase)(struct clk_hw *hw, int degrees);
270 int (*get_duty_cycle)(struct clk_hw *hw,
271 struct clk_duty *duty);
272 int (*set_duty_cycle)(struct clk_hw *hw,
273 struct clk_duty *duty);
274 int (*init)(struct clk_hw *hw);
275 void (*terminate)(struct clk_hw *hw);
276 void (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
277 int (*pre_rate_change)(struct clk_hw *hw,
278 unsigned long rate,
279 unsigned long new_rate);
280 int (*post_rate_change)(struct clk_hw *hw,
281 unsigned long old_rate,
282 unsigned long rate);
283 };
284
285 /**
286 * struct clk_parent_data - clk parent information
287 * @hw: parent clk_hw pointer (used for clk providers with internal clks)
288 * @fw_name: parent name local to provider registering clk
289 * @name: globally unique parent name (used as a fallback)
290 * @index: parent index local to provider registering clk (if @fw_name absent)
291 */
292 struct clk_parent_data {
293 const struct clk_hw *hw;
294 const char *fw_name;
295 const char *name;
296 int index;
297 };
298
299 /**
300 * struct clk_init_data - holds init data that's common to all clocks and is
301 * shared between the clock provider and the common clock framework.
302 *
303 * @name: clock name
304 * @ops: operations this clock supports
305 * @parent_names: array of string names for all possible parents
306 * @parent_data: array of parent data for all possible parents (when some
307 * parents are external to the clk controller)
308 * @parent_hws: array of pointers to all possible parents (when all parents
309 * are internal to the clk controller)
310 * @num_parents: number of possible parents
311 * @flags: framework-level hints and quirks
312 */
313 struct clk_init_data {
314 const char *name;
315 const struct clk_ops *ops;
316 /* Only one of the following three should be assigned */
317 const char * const *parent_names;
318 const struct clk_parent_data *parent_data;
319 const struct clk_hw **parent_hws;
320 u8 num_parents;
321 unsigned long flags;
322 };
323
324 /**
325 * struct clk_hw - handle for traversing from a struct clk to its corresponding
326 * hardware-specific structure. struct clk_hw should be declared within struct
327 * clk_foo and then referenced by the struct clk instance that uses struct
328 * clk_foo's clk_ops
329 *
330 * @core: pointer to the struct clk_core instance that points back to this
331 * struct clk_hw instance
332 *
333 * @clk: pointer to the per-user struct clk instance that can be used to call
334 * into the clk API
335 *
336 * @init: pointer to struct clk_init_data that contains the init data shared
337 * with the common clock framework. This pointer will be set to NULL once
338 * a clk_register() variant is called on this clk_hw pointer.
339 */
340 struct clk_hw {
341 struct clk_core *core;
342 struct clk *clk;
343 const struct clk_init_data *init;
344 };
345
346 /*
347 * DOC: Basic clock implementations common to many platforms
348 *
349 * Each basic clock hardware type is comprised of a structure describing the
350 * clock hardware, implementations of the relevant callbacks in struct clk_ops,
351 * unique flags for that hardware type, a registration function and an
352 * alternative macro for static initialization
353 */
354
355 /**
356 * struct clk_fixed_rate - fixed-rate clock
357 * @hw: handle between common and hardware-specific interfaces
358 * @fixed_rate: constant frequency of clock
359 * @fixed_accuracy: constant accuracy of clock in ppb (parts per billion)
360 * @flags: hardware specific flags
361 *
362 * Flags:
363 * * CLK_FIXED_RATE_PARENT_ACCURACY - Use the accuracy of the parent clk
364 * instead of what's set in @fixed_accuracy.
365 */
366 struct clk_fixed_rate {
367 struct clk_hw hw;
368 unsigned long fixed_rate;
369 unsigned long fixed_accuracy;
370 unsigned long flags;
371 };
372
373 #define CLK_FIXED_RATE_PARENT_ACCURACY BIT(0)
374
375 extern const struct clk_ops clk_fixed_rate_ops;
376 struct clk_hw *__clk_hw_register_fixed_rate(struct device *dev,
377 struct device_node *np, const char *name,
378 const char *parent_name, const struct clk_hw *parent_hw,
379 const struct clk_parent_data *parent_data, unsigned long flags,
380 unsigned long fixed_rate, unsigned long fixed_accuracy,
381 unsigned long clk_fixed_flags, bool devm);
382 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
383 const char *parent_name, unsigned long flags,
384 unsigned long fixed_rate);
385 /**
386 * clk_hw_register_fixed_rate - register fixed-rate clock with the clock
387 * framework
388 * @dev: device that is registering this clock
389 * @name: name of this clock
390 * @parent_name: name of clock's parent
391 * @flags: framework-specific flags
392 * @fixed_rate: non-adjustable clock rate
393 */
394 #define clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate) \
395 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
396 NULL, (flags), (fixed_rate), 0, 0, false)
397
398 /**
399 * devm_clk_hw_register_fixed_rate - register fixed-rate clock with the clock
400 * framework
401 * @dev: device that is registering this clock
402 * @name: name of this clock
403 * @parent_name: name of clock's parent
404 * @flags: framework-specific flags
405 * @fixed_rate: non-adjustable clock rate
406 */
407 #define devm_clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate) \
408 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
409 NULL, (flags), (fixed_rate), 0, 0, true)
410 /**
411 * devm_clk_hw_register_fixed_rate_parent_data - register fixed-rate clock with
412 * the clock framework
413 * @dev: device that is registering this clock
414 * @name: name of this clock
415 * @parent_data: parent clk data
416 * @flags: framework-specific flags
417 * @fixed_rate: non-adjustable clock rate
418 */
419 #define devm_clk_hw_register_fixed_rate_parent_data(dev, name, parent_data, flags, \
420 fixed_rate) \
421 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
422 (parent_data), (flags), (fixed_rate), 0, \
423 0, true)
424 /**
425 * clk_hw_register_fixed_rate_parent_hw - register fixed-rate clock with
426 * the clock framework
427 * @dev: device that is registering this clock
428 * @name: name of this clock
429 * @parent_hw: pointer to parent clk
430 * @flags: framework-specific flags
431 * @fixed_rate: non-adjustable clock rate
432 */
433 #define clk_hw_register_fixed_rate_parent_hw(dev, name, parent_hw, flags, \
434 fixed_rate) \
435 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw), \
436 NULL, (flags), (fixed_rate), 0, 0, false)
437 /**
438 * clk_hw_register_fixed_rate_parent_data - register fixed-rate clock with
439 * the clock framework
440 * @dev: device that is registering this clock
441 * @name: name of this clock
442 * @parent_data: parent clk data
443 * @flags: framework-specific flags
444 * @fixed_rate: non-adjustable clock rate
445 */
446 #define clk_hw_register_fixed_rate_parent_data(dev, name, parent_data, flags, \
447 fixed_rate) \
448 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
449 (parent_data), (flags), (fixed_rate), 0, \
450 0, false)
451 /**
452 * clk_hw_register_fixed_rate_with_accuracy - register fixed-rate clock with
453 * the clock framework
454 * @dev: device that is registering this clock
455 * @name: name of this clock
456 * @parent_name: name of clock's parent
457 * @flags: framework-specific flags
458 * @fixed_rate: non-adjustable clock rate
459 * @fixed_accuracy: non-adjustable clock accuracy
460 */
461 #define clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name, \
462 flags, fixed_rate, \
463 fixed_accuracy) \
464 __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), \
465 NULL, NULL, (flags), (fixed_rate), \
466 (fixed_accuracy), 0, false)
467 /**
468 * clk_hw_register_fixed_rate_with_accuracy_parent_hw - register fixed-rate
469 * clock with the clock framework
470 * @dev: device that is registering this clock
471 * @name: name of this clock
472 * @parent_hw: pointer to parent clk
473 * @flags: framework-specific flags
474 * @fixed_rate: non-adjustable clock rate
475 * @fixed_accuracy: non-adjustable clock accuracy
476 */
477 #define clk_hw_register_fixed_rate_with_accuracy_parent_hw(dev, name, \
478 parent_hw, flags, fixed_rate, fixed_accuracy) \
479 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw), \
480 NULL, (flags), (fixed_rate), \
481 (fixed_accuracy), 0, false)
482 /**
483 * clk_hw_register_fixed_rate_with_accuracy_parent_data - register fixed-rate
484 * clock with the clock framework
485 * @dev: device that is registering this clock
486 * @name: name of this clock
487 * @parent_data: name of clock's parent
488 * @flags: framework-specific flags
489 * @fixed_rate: non-adjustable clock rate
490 * @fixed_accuracy: non-adjustable clock accuracy
491 */
492 #define clk_hw_register_fixed_rate_with_accuracy_parent_data(dev, name, \
493 parent_data, flags, fixed_rate, fixed_accuracy) \
494 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
495 (parent_data), NULL, (flags), \
496 (fixed_rate), (fixed_accuracy), 0, false)
497 /**
498 * clk_hw_register_fixed_rate_parent_accuracy - register fixed-rate clock with
499 * the clock framework
500 * @dev: device that is registering this clock
501 * @name: name of this clock
502 * @parent_data: name of clock's parent
503 * @flags: framework-specific flags
504 * @fixed_rate: non-adjustable clock rate
505 */
506 #define clk_hw_register_fixed_rate_parent_accuracy(dev, name, parent_data, \
507 flags, fixed_rate) \
508 __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL, \
509 (parent_data), (flags), (fixed_rate), 0, \
510 CLK_FIXED_RATE_PARENT_ACCURACY, false)
511
512 void clk_unregister_fixed_rate(struct clk *clk);
513 void clk_hw_unregister_fixed_rate(struct clk_hw *hw);
514
515 void of_fixed_clk_setup(struct device_node *np);
516
517 /**
518 * struct clk_gate - gating clock
519 *
520 * @hw: handle between common and hardware-specific interfaces
521 * @reg: register controlling gate
522 * @bit_idx: single bit controlling gate
523 * @flags: hardware-specific flags
524 * @lock: register lock
525 *
526 * Clock which can gate its output. Implements .enable & .disable
527 *
528 * Flags:
529 * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to
530 * enable the clock. Setting this flag does the opposite: setting the bit
531 * disable the clock and clearing it enables the clock
532 * CLK_GATE_HIWORD_MASK - The gate settings are only in lower 16-bit
533 * of this register, and mask of gate bits are in higher 16-bit of this
534 * register. While setting the gate bits, higher 16-bit should also be
535 * updated to indicate changing gate bits.
536 * CLK_GATE_BIG_ENDIAN - by default little endian register accesses are used for
537 * the gate register. Setting this flag makes the register accesses big
538 * endian.
539 */
540 struct clk_gate {
541 struct clk_hw hw;
542 void __iomem *reg;
543 u8 bit_idx;
544 u8 flags;
545 spinlock_t *lock;
546 };
547
548 #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
549
550 #define CLK_GATE_SET_TO_DISABLE BIT(0)
551 #define CLK_GATE_HIWORD_MASK BIT(1)
552 #define CLK_GATE_BIG_ENDIAN BIT(2)
553
554 extern const struct clk_ops clk_gate_ops;
555 struct clk_hw *__clk_hw_register_gate(struct device *dev,
556 struct device_node *np, const char *name,
557 const char *parent_name, const struct clk_hw *parent_hw,
558 const struct clk_parent_data *parent_data,
559 unsigned long flags,
560 void __iomem *reg, u8 bit_idx,
561 u8 clk_gate_flags, spinlock_t *lock);
562 struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
563 struct device_node *np, const char *name,
564 const char *parent_name, const struct clk_hw *parent_hw,
565 const struct clk_parent_data *parent_data,
566 unsigned long flags,
567 void __iomem *reg, u8 bit_idx,
568 u8 clk_gate_flags, spinlock_t *lock);
569 struct clk *clk_register_gate(struct device *dev, const char *name,
570 const char *parent_name, unsigned long flags,
571 void __iomem *reg, u8 bit_idx,
572 u8 clk_gate_flags, spinlock_t *lock);
573 /**
574 * clk_hw_register_gate - register a gate clock with the clock framework
575 * @dev: device that is registering this clock
576 * @name: name of this clock
577 * @parent_name: name of this clock's parent
578 * @flags: framework-specific flags for this clock
579 * @reg: register address to control gating of this clock
580 * @bit_idx: which bit in the register controls gating of this clock
581 * @clk_gate_flags: gate-specific flags for this clock
582 * @lock: shared register lock for this clock
583 */
584 #define clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx, \
585 clk_gate_flags, lock) \
586 __clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
587 NULL, (flags), (reg), (bit_idx), \
588 (clk_gate_flags), (lock))
589 /**
590 * clk_hw_register_gate_parent_hw - register a gate clock with the clock
591 * framework
592 * @dev: device that is registering this clock
593 * @name: name of this clock
594 * @parent_hw: pointer to parent clk
595 * @flags: framework-specific flags for this clock
596 * @reg: register address to control gating of this clock
597 * @bit_idx: which bit in the register controls gating of this clock
598 * @clk_gate_flags: gate-specific flags for this clock
599 * @lock: shared register lock for this clock
600 */
601 #define clk_hw_register_gate_parent_hw(dev, name, parent_hw, flags, reg, \
602 bit_idx, clk_gate_flags, lock) \
603 __clk_hw_register_gate((dev), NULL, (name), NULL, (parent_hw), \
604 NULL, (flags), (reg), (bit_idx), \
605 (clk_gate_flags), (lock))
606 /**
607 * clk_hw_register_gate_parent_data - register a gate clock with the clock
608 * framework
609 * @dev: device that is registering this clock
610 * @name: name of this clock
611 * @parent_data: parent clk data
612 * @flags: framework-specific flags for this clock
613 * @reg: register address to control gating of this clock
614 * @bit_idx: which bit in the register controls gating of this clock
615 * @clk_gate_flags: gate-specific flags for this clock
616 * @lock: shared register lock for this clock
617 */
618 #define clk_hw_register_gate_parent_data(dev, name, parent_data, flags, reg, \
619 bit_idx, clk_gate_flags, lock) \
620 __clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
621 (flags), (reg), (bit_idx), \
622 (clk_gate_flags), (lock))
623 /**
624 * devm_clk_hw_register_gate - register a gate clock with the clock framework
625 * @dev: device that is registering this clock
626 * @name: name of this clock
627 * @parent_name: name of this clock's parent
628 * @flags: framework-specific flags for this clock
629 * @reg: register address to control gating of this clock
630 * @bit_idx: which bit in the register controls gating of this clock
631 * @clk_gate_flags: gate-specific flags for this clock
632 * @lock: shared register lock for this clock
633 */
634 #define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
635 clk_gate_flags, lock) \
636 __devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
637 NULL, (flags), (reg), (bit_idx), \
638 (clk_gate_flags), (lock))
639 /**
640 * devm_clk_hw_register_gate_parent_data - register a gate clock with the
641 * clock framework
642 * @dev: device that is registering this clock
643 * @name: name of this clock
644 * @parent_data: parent clk data
645 * @flags: framework-specific flags for this clock
646 * @reg: register address to control gating of this clock
647 * @bit_idx: which bit in the register controls gating of this clock
648 * @clk_gate_flags: gate-specific flags for this clock
649 * @lock: shared register lock for this clock
650 */
651 #define devm_clk_hw_register_gate_parent_data(dev, name, parent_data, flags, \
652 reg, bit_idx, clk_gate_flags, \
653 lock) \
654 __devm_clk_hw_register_gate((dev), NULL, (name), NULL, NULL, \
655 (parent_data), (flags), (reg), (bit_idx), \
656 (clk_gate_flags), (lock))
657
658 void clk_unregister_gate(struct clk *clk);
659 void clk_hw_unregister_gate(struct clk_hw *hw);
660 int clk_gate_is_enabled(struct clk_hw *hw);
661
662 struct clk_div_table {
663 unsigned int val;
664 unsigned int div;
665 };
666
667 /**
668 * struct clk_divider - adjustable divider clock
669 *
670 * @hw: handle between common and hardware-specific interfaces
671 * @reg: register containing the divider
672 * @shift: shift to the divider bit field
673 * @width: width of the divider bit field
674 * @table: array of value/divider pairs, last entry should have div = 0
675 * @lock: register lock
676 *
677 * Clock with an adjustable divider affecting its output frequency. Implements
678 * .recalc_rate, .set_rate and .round_rate
679 *
680 * @flags:
681 * CLK_DIVIDER_ONE_BASED - by default the divisor is the value read from the
682 * register plus one. If CLK_DIVIDER_ONE_BASED is set then the divider is
683 * the raw value read from the register, with the value of zero considered
684 * invalid, unless CLK_DIVIDER_ALLOW_ZERO is set.
685 * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from
686 * the hardware register
687 * CLK_DIVIDER_ALLOW_ZERO - Allow zero divisors. For dividers which have
688 * CLK_DIVIDER_ONE_BASED set, it is possible to end up with a zero divisor.
689 * Some hardware implementations gracefully handle this case and allow a
690 * zero divisor by not modifying their input clock
691 * (divide by one / bypass).
692 * CLK_DIVIDER_HIWORD_MASK - The divider settings are only in lower 16-bit
693 * of this register, and mask of divider bits are in higher 16-bit of this
694 * register. While setting the divider bits, higher 16-bit should also be
695 * updated to indicate changing divider bits.
696 * CLK_DIVIDER_ROUND_CLOSEST - Makes the best calculated divider to be rounded
697 * to the closest integer instead of the up one.
698 * CLK_DIVIDER_READ_ONLY - The divider settings are preconfigured and should
699 * not be changed by the clock framework.
700 * CLK_DIVIDER_MAX_AT_ZERO - For dividers which are like CLK_DIVIDER_ONE_BASED
701 * except when the value read from the register is zero, the divisor is
702 * 2^width of the field.
703 * CLK_DIVIDER_BIG_ENDIAN - By default little endian register accesses are used
704 * for the divider register. Setting this flag makes the register accesses
705 * big endian.
706 */
707 struct clk_divider {
708 struct clk_hw hw;
709 void __iomem *reg;
710 u8 shift;
711 u8 width;
712 u8 flags;
713 const struct clk_div_table *table;
714 spinlock_t *lock;
715 };
716
717 #define clk_div_mask(width) ((1 << (width)) - 1)
718 #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
719
720 #define CLK_DIVIDER_ONE_BASED BIT(0)
721 #define CLK_DIVIDER_POWER_OF_TWO BIT(1)
722 #define CLK_DIVIDER_ALLOW_ZERO BIT(2)
723 #define CLK_DIVIDER_HIWORD_MASK BIT(3)
724 #define CLK_DIVIDER_ROUND_CLOSEST BIT(4)
725 #define CLK_DIVIDER_READ_ONLY BIT(5)
726 #define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
727 #define CLK_DIVIDER_BIG_ENDIAN BIT(7)
728
729 extern const struct clk_ops clk_divider_ops;
730 extern const struct clk_ops clk_divider_ro_ops;
731
732 unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
733 unsigned int val, const struct clk_div_table *table,
734 unsigned long flags, unsigned long width);
735 long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
736 unsigned long rate, unsigned long *prate,
737 const struct clk_div_table *table,
738 u8 width, unsigned long flags);
739 long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
740 unsigned long rate, unsigned long *prate,
741 const struct clk_div_table *table, u8 width,
742 unsigned long flags, unsigned int val);
743 int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
744 const struct clk_div_table *table, u8 width,
745 unsigned long flags);
746 int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
747 const struct clk_div_table *table, u8 width,
748 unsigned long flags, unsigned int val);
749 int divider_get_val(unsigned long rate, unsigned long parent_rate,
750 const struct clk_div_table *table, u8 width,
751 unsigned long flags);
752
753 struct clk_hw *__clk_hw_register_divider(struct device *dev,
754 struct device_node *np, const char *name,
755 const char *parent_name, const struct clk_hw *parent_hw,
756 const struct clk_parent_data *parent_data, unsigned long flags,
757 void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
758 const struct clk_div_table *table, spinlock_t *lock);
759 struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
760 struct device_node *np, const char *name,
761 const char *parent_name, const struct clk_hw *parent_hw,
762 const struct clk_parent_data *parent_data, unsigned long flags,
763 void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
764 const struct clk_div_table *table, spinlock_t *lock);
765 struct clk *clk_register_divider_table(struct device *dev, const char *name,
766 const char *parent_name, unsigned long flags,
767 void __iomem *reg, u8 shift, u8 width,
768 u8 clk_divider_flags, const struct clk_div_table *table,
769 spinlock_t *lock);
770 /**
771 * clk_register_divider - register a divider clock with the clock framework
772 * @dev: device registering this clock
773 * @name: name of this clock
774 * @parent_name: name of clock's parent
775 * @flags: framework-specific flags
776 * @reg: register address to adjust divider
777 * @shift: number of bits to shift the bitfield
778 * @width: width of the bitfield
779 * @clk_divider_flags: divider-specific flags for this clock
780 * @lock: shared register lock for this clock
781 */
782 #define clk_register_divider(dev, name, parent_name, flags, reg, shift, width, \
783 clk_divider_flags, lock) \
784 clk_register_divider_table((dev), (name), (parent_name), (flags), \
785 (reg), (shift), (width), \
786 (clk_divider_flags), NULL, (lock))
787 /**
788 * clk_hw_register_divider - register a divider clock with the clock framework
789 * @dev: device registering this clock
790 * @name: name of this clock
791 * @parent_name: name of clock's parent
792 * @flags: framework-specific flags
793 * @reg: register address to adjust divider
794 * @shift: number of bits to shift the bitfield
795 * @width: width of the bitfield
796 * @clk_divider_flags: divider-specific flags for this clock
797 * @lock: shared register lock for this clock
798 */
799 #define clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
800 width, clk_divider_flags, lock) \
801 __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
802 NULL, (flags), (reg), (shift), (width), \
803 (clk_divider_flags), NULL, (lock))
804 /**
805 * clk_hw_register_divider_parent_hw - register a divider clock with the clock
806 * framework
807 * @dev: device registering this clock
808 * @name: name of this clock
809 * @parent_hw: pointer to parent clk
810 * @flags: framework-specific flags
811 * @reg: register address to adjust divider
812 * @shift: number of bits to shift the bitfield
813 * @width: width of the bitfield
814 * @clk_divider_flags: divider-specific flags for this clock
815 * @lock: shared register lock for this clock
816 */
817 #define clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, reg, \
818 shift, width, clk_divider_flags, \
819 lock) \
820 __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
821 NULL, (flags), (reg), (shift), (width), \
822 (clk_divider_flags), NULL, (lock))
823 /**
824 * clk_hw_register_divider_parent_data - register a divider clock with the clock
825 * framework
826 * @dev: device registering this clock
827 * @name: name of this clock
828 * @parent_data: parent clk data
829 * @flags: framework-specific flags
830 * @reg: register address to adjust divider
831 * @shift: number of bits to shift the bitfield
832 * @width: width of the bitfield
833 * @clk_divider_flags: divider-specific flags for this clock
834 * @lock: shared register lock for this clock
835 */
836 #define clk_hw_register_divider_parent_data(dev, name, parent_data, flags, \
837 reg, shift, width, \
838 clk_divider_flags, lock) \
839 __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
840 (parent_data), (flags), (reg), (shift), \
841 (width), (clk_divider_flags), NULL, (lock))
842 /**
843 * clk_hw_register_divider_table - register a table based divider clock with
844 * the clock framework
845 * @dev: device registering this clock
846 * @name: name of this clock
847 * @parent_name: name of clock's parent
848 * @flags: framework-specific flags
849 * @reg: register address to adjust divider
850 * @shift: number of bits to shift the bitfield
851 * @width: width of the bitfield
852 * @clk_divider_flags: divider-specific flags for this clock
853 * @table: array of divider/value pairs ending with a div set to 0
854 * @lock: shared register lock for this clock
855 */
856 #define clk_hw_register_divider_table(dev, name, parent_name, flags, reg, \
857 shift, width, clk_divider_flags, table, \
858 lock) \
859 __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
860 NULL, (flags), (reg), (shift), (width), \
861 (clk_divider_flags), (table), (lock))
862 /**
863 * clk_hw_register_divider_table_parent_hw - register a table based divider
864 * clock with the clock framework
865 * @dev: device registering this clock
866 * @name: name of this clock
867 * @parent_hw: pointer to parent clk
868 * @flags: framework-specific flags
869 * @reg: register address to adjust divider
870 * @shift: number of bits to shift the bitfield
871 * @width: width of the bitfield
872 * @clk_divider_flags: divider-specific flags for this clock
873 * @table: array of divider/value pairs ending with a div set to 0
874 * @lock: shared register lock for this clock
875 */
876 #define clk_hw_register_divider_table_parent_hw(dev, name, parent_hw, flags, \
877 reg, shift, width, \
878 clk_divider_flags, table, \
879 lock) \
880 __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw), \
881 NULL, (flags), (reg), (shift), (width), \
882 (clk_divider_flags), (table), (lock))
883 /**
884 * clk_hw_register_divider_table_parent_data - register a table based divider
885 * clock with the clock framework
886 * @dev: device registering this clock
887 * @name: name of this clock
888 * @parent_data: parent clk data
889 * @flags: framework-specific flags
890 * @reg: register address to adjust divider
891 * @shift: number of bits to shift the bitfield
892 * @width: width of the bitfield
893 * @clk_divider_flags: divider-specific flags for this clock
894 * @table: array of divider/value pairs ending with a div set to 0
895 * @lock: shared register lock for this clock
896 */
897 #define clk_hw_register_divider_table_parent_data(dev, name, parent_data, \
898 flags, reg, shift, width, \
899 clk_divider_flags, table, \
900 lock) \
901 __clk_hw_register_divider((dev), NULL, (name), NULL, NULL, \
902 (parent_data), (flags), (reg), (shift), \
903 (width), (clk_divider_flags), (table), \
904 (lock))
905 /**
906 * devm_clk_hw_register_divider - register a divider clock with the clock framework
907 * @dev: device registering this clock
908 * @name: name of this clock
909 * @parent_name: name of clock's parent
910 * @flags: framework-specific flags
911 * @reg: register address to adjust divider
912 * @shift: number of bits to shift the bitfield
913 * @width: width of the bitfield
914 * @clk_divider_flags: divider-specific flags for this clock
915 * @lock: shared register lock for this clock
916 */
917 #define devm_clk_hw_register_divider(dev, name, parent_name, flags, reg, shift, \
918 width, clk_divider_flags, lock) \
919 __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL, \
920 NULL, (flags), (reg), (shift), (width), \
921 (clk_divider_flags), NULL, (lock))
922 /**
923 * devm_clk_hw_register_divider_parent_hw - register a divider clock with the clock framework
924 * @dev: device registering this clock
925 * @name: name of this clock
926 * @parent_hw: pointer to parent clk
927 * @flags: framework-specific flags
928 * @reg: register address to adjust divider
929 * @shift: number of bits to shift the bitfield
930 * @width: width of the bitfield
931 * @clk_divider_flags: divider-specific flags for this clock
932 * @lock: shared register lock for this clock
933 */
934 #define devm_clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, \
935 reg, shift, width, \
936 clk_divider_flags, lock) \
937 __devm_clk_hw_register_divider((dev), NULL, (name), NULL, \
938 (parent_hw), NULL, (flags), (reg), \
939 (shift), (width), (clk_divider_flags), \
940 NULL, (lock))
941 /**
942 * devm_clk_hw_register_divider_table - register a table based divider clock
943 * with the clock framework (devres variant)
944 * @dev: device registering this clock
945 * @name: name of this clock
946 * @parent_name: name of clock's parent
947 * @flags: framework-specific flags
948 * @reg: register address to adjust divider
949 * @shift: number of bits to shift the bitfield
950 * @width: width of the bitfield
951 * @clk_divider_flags: divider-specific flags for this clock
952 * @table: array of divider/value pairs ending with a div set to 0
953 * @lock: shared register lock for this clock
954 */
955 #define devm_clk_hw_register_divider_table(dev, name, parent_name, flags, \
956 reg, shift, width, \
957 clk_divider_flags, table, lock) \
958 __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), \
959 NULL, NULL, (flags), (reg), (shift), \
960 (width), (clk_divider_flags), (table), \
961 (lock))
962
963 void clk_unregister_divider(struct clk *clk);
964 void clk_hw_unregister_divider(struct clk_hw *hw);
965
966 /**
967 * struct clk_mux - multiplexer clock
968 *
969 * @hw: handle between common and hardware-specific interfaces
970 * @reg: register controlling multiplexer
971 * @table: array of register values corresponding to the parent index
972 * @shift: shift to multiplexer bit field
973 * @mask: mask of mutliplexer bit field
974 * @flags: hardware-specific flags
975 * @lock: register lock
976 *
977 * Clock with multiple selectable parents. Implements .get_parent, .set_parent
978 * and .recalc_rate
979 *
980 * Flags:
981 * CLK_MUX_INDEX_ONE - register index starts at 1, not 0
982 * CLK_MUX_INDEX_BIT - register index is a single bit (power of two)
983 * CLK_MUX_HIWORD_MASK - The mux settings are only in lower 16-bit of this
984 * register, and mask of mux bits are in higher 16-bit of this register.
985 * While setting the mux bits, higher 16-bit should also be updated to
986 * indicate changing mux bits.
987 * CLK_MUX_READ_ONLY - The mux registers can't be written, only read in the
988 * .get_parent clk_op.
989 * CLK_MUX_ROUND_CLOSEST - Use the parent rate that is closest to the desired
990 * frequency.
991 * CLK_MUX_BIG_ENDIAN - By default little endian register accesses are used for
992 * the mux register. Setting this flag makes the register accesses big
993 * endian.
994 */
995 struct clk_mux {
996 struct clk_hw hw;
997 void __iomem *reg;
998 const u32 *table;
999 u32 mask;
1000 u8 shift;
1001 u8 flags;
1002 spinlock_t *lock;
1003 };
1004
1005 #define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
1006
1007 #define CLK_MUX_INDEX_ONE BIT(0)
1008 #define CLK_MUX_INDEX_BIT BIT(1)
1009 #define CLK_MUX_HIWORD_MASK BIT(2)
1010 #define CLK_MUX_READ_ONLY BIT(3) /* mux can't be changed */
1011 #define CLK_MUX_ROUND_CLOSEST BIT(4)
1012 #define CLK_MUX_BIG_ENDIAN BIT(5)
1013
1014 extern const struct clk_ops clk_mux_ops;
1015 extern const struct clk_ops clk_mux_ro_ops;
1016
1017 struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
1018 const char *name, u8 num_parents,
1019 const char * const *parent_names,
1020 const struct clk_hw **parent_hws,
1021 const struct clk_parent_data *parent_data,
1022 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
1023 u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
1024 struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node *np,
1025 const char *name, u8 num_parents,
1026 const char * const *parent_names,
1027 const struct clk_hw **parent_hws,
1028 const struct clk_parent_data *parent_data,
1029 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
1030 u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
1031 struct clk *clk_register_mux_table(struct device *dev, const char *name,
1032 const char * const *parent_names, u8 num_parents,
1033 unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
1034 u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
1035
1036 #define clk_register_mux(dev, name, parent_names, num_parents, flags, reg, \
1037 shift, width, clk_mux_flags, lock) \
1038 clk_register_mux_table((dev), (name), (parent_names), (num_parents), \
1039 (flags), (reg), (shift), BIT((width)) - 1, \
1040 (clk_mux_flags), NULL, (lock))
1041 #define clk_hw_register_mux_table(dev, name, parent_names, num_parents, \
1042 flags, reg, shift, mask, clk_mux_flags, \
1043 table, lock) \
1044 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
1045 (parent_names), NULL, NULL, (flags), (reg), \
1046 (shift), (mask), (clk_mux_flags), (table), \
1047 (lock))
1048 #define clk_hw_register_mux_table_parent_data(dev, name, parent_data, \
1049 num_parents, flags, reg, shift, mask, \
1050 clk_mux_flags, table, lock) \
1051 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
1052 NULL, NULL, (parent_data), (flags), (reg), \
1053 (shift), (mask), (clk_mux_flags), (table), \
1054 (lock))
1055 #define clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
1056 shift, width, clk_mux_flags, lock) \
1057 __clk_hw_register_mux((dev), NULL, (name), (num_parents), \
1058 (parent_names), NULL, NULL, (flags), (reg), \
1059 (shift), BIT((width)) - 1, (clk_mux_flags), \
1060 NULL, (lock))
1061 #define clk_hw_register_mux_hws(dev, name, parent_hws, num_parents, flags, \
1062 reg, shift, width, clk_mux_flags, lock) \
1063 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
1064 (parent_hws), NULL, (flags), (reg), (shift), \
1065 BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
1066 #define clk_hw_register_mux_parent_data(dev, name, parent_data, num_parents, \
1067 flags, reg, shift, width, \
1068 clk_mux_flags, lock) \
1069 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
1070 (parent_data), (flags), (reg), (shift), \
1071 BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
1072 #define clk_hw_register_mux_parent_data_table(dev, name, parent_data, \
1073 num_parents, flags, reg, shift, \
1074 width, clk_mux_flags, table, \
1075 lock) \
1076 __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
1077 (parent_data), (flags), (reg), (shift), \
1078 BIT((width)) - 1, (clk_mux_flags), table, (lock))
1079 #define devm_clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
1080 shift, width, clk_mux_flags, lock) \
1081 __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), \
1082 (parent_names), NULL, NULL, (flags), (reg), \
1083 (shift), BIT((width)) - 1, (clk_mux_flags), \
1084 NULL, (lock))
1085 #define devm_clk_hw_register_mux_parent_hws(dev, name, parent_hws, \
1086 num_parents, flags, reg, shift, \
1087 width, clk_mux_flags, lock) \
1088 __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
1089 (parent_hws), NULL, (flags), (reg), \
1090 (shift), BIT((width)) - 1, \
1091 (clk_mux_flags), NULL, (lock))
1092 #define devm_clk_hw_register_mux_parent_data_table(dev, name, parent_data, \
1093 num_parents, flags, reg, shift, \
1094 width, clk_mux_flags, table, \
1095 lock) \
1096 __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, \
1097 NULL, (parent_data), (flags), (reg), (shift), \
1098 BIT((width)) - 1, (clk_mux_flags), table, (lock))
1099
1100 int clk_mux_val_to_index(struct clk_hw *hw, const u32 *table, unsigned int flags,
1101 unsigned int val);
1102 unsigned int clk_mux_index_to_val(const u32 *table, unsigned int flags, u8 index);
1103
1104 void clk_unregister_mux(struct clk *clk);
1105 void clk_hw_unregister_mux(struct clk_hw *hw);
1106
1107 void of_fixed_factor_clk_setup(struct device_node *node);
1108
1109 /**
1110 * struct clk_fixed_factor - fixed multiplier and divider clock
1111 *
1112 * @hw: handle between common and hardware-specific interfaces
1113 * @mult: multiplier
1114 * @div: divider
1115 * @acc: fixed accuracy in ppb
1116 * @flags: behavior modifying flags
1117 *
1118 * Clock with a fixed multiplier and divider. The output frequency is the
1119 * parent clock rate divided by div and multiplied by mult.
1120 * Implements .recalc_rate, .set_rate, .round_rate and .recalc_accuracy
1121 *
1122 * Flags:
1123 * * CLK_FIXED_FACTOR_FIXED_ACCURACY - Use the value in @acc instead of the
1124 * parent clk accuracy.
1125 */
1126
1127 struct clk_fixed_factor {
1128 struct clk_hw hw;
1129 unsigned int mult;
1130 unsigned int div;
1131 unsigned long acc;
1132 unsigned int flags;
1133 };
1134
1135 #define CLK_FIXED_FACTOR_FIXED_ACCURACY BIT(0)
1136
1137 #define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
1138
1139 extern const struct clk_ops clk_fixed_factor_ops;
1140 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
1141 const char *parent_name, unsigned long flags,
1142 unsigned int mult, unsigned int div);
1143 void clk_unregister_fixed_factor(struct clk *clk);
1144 struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
1145 const char *name, const char *parent_name, unsigned long flags,
1146 unsigned int mult, unsigned int div);
1147 struct clk_hw *clk_hw_register_fixed_factor_fwname(struct device *dev,
1148 struct device_node *np, const char *name, const char *fw_name,
1149 unsigned long flags, unsigned int mult, unsigned int div);
1150 struct clk_hw *clk_hw_register_fixed_factor_with_accuracy_fwname(struct device *dev,
1151 struct device_node *np, const char *name, const char *fw_name,
1152 unsigned long flags, unsigned int mult, unsigned int div,
1153 unsigned long acc);
1154 void clk_hw_unregister_fixed_factor(struct clk_hw *hw);
1155 struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
1156 const char *name, const char *parent_name, unsigned long flags,
1157 unsigned int mult, unsigned int div);
1158 struct clk_hw *devm_clk_hw_register_fixed_factor_fwname(struct device *dev,
1159 struct device_node *np, const char *name, const char *fw_name,
1160 unsigned long flags, unsigned int mult, unsigned int div);
1161 struct clk_hw *devm_clk_hw_register_fixed_factor_with_accuracy_fwname(struct device *dev,
1162 struct device_node *np, const char *name, const char *fw_name,
1163 unsigned long flags, unsigned int mult, unsigned int div,
1164 unsigned long acc);
1165 struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
1166 const char *name, unsigned int index, unsigned long flags,
1167 unsigned int mult, unsigned int div);
1168
1169 struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
1170 const char *name, const struct clk_hw *parent_hw,
1171 unsigned long flags, unsigned int mult, unsigned int div);
1172
1173 struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
1174 const char *name, const struct clk_hw *parent_hw,
1175 unsigned long flags, unsigned int mult, unsigned int div);
1176 /**
1177 * struct clk_fractional_divider - adjustable fractional divider clock
1178 *
1179 * @hw: handle between common and hardware-specific interfaces
1180 * @reg: register containing the divider
1181 * @mshift: shift to the numerator bit field
1182 * @mwidth: width of the numerator bit field
1183 * @nshift: shift to the denominator bit field
1184 * @nwidth: width of the denominator bit field
1185 * @approximation: clk driver's callback for calculating the divider clock
1186 * @lock: register lock
1187 *
1188 * Clock with adjustable fractional divider affecting its output frequency.
1189 *
1190 * @flags:
1191 * CLK_FRAC_DIVIDER_ZERO_BASED - by default the numerator and denominator
1192 * is the value read from the register. If CLK_FRAC_DIVIDER_ZERO_BASED
1193 * is set then the numerator and denominator are both the value read
1194 * plus one.
1195 * CLK_FRAC_DIVIDER_BIG_ENDIAN - By default little endian register accesses are
1196 * used for the divider register. Setting this flag makes the register
1197 * accesses big endian.
1198 * CLK_FRAC_DIVIDER_POWER_OF_TWO_PS - By default the resulting fraction might
1199 * be saturated and the caller will get quite far from the good enough
1200 * approximation. Instead the caller may require, by setting this flag,
1201 * to shift left by a few bits in case, when the asked one is quite small
1202 * to satisfy the desired range of denominator. It assumes that on the
1203 * caller's side the power-of-two capable prescaler exists.
1204 */
1205 struct clk_fractional_divider {
1206 struct clk_hw hw;
1207 void __iomem *reg;
1208 u8 mshift;
1209 u8 mwidth;
1210 u8 nshift;
1211 u8 nwidth;
1212 u8 flags;
1213 void (*approximation)(struct clk_hw *hw,
1214 unsigned long rate, unsigned long *parent_rate,
1215 unsigned long *m, unsigned long *n);
1216 spinlock_t *lock;
1217 };
1218
1219 #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
1220
1221 #define CLK_FRAC_DIVIDER_ZERO_BASED BIT(0)
1222 #define CLK_FRAC_DIVIDER_BIG_ENDIAN BIT(1)
1223 #define CLK_FRAC_DIVIDER_POWER_OF_TWO_PS BIT(2)
1224
1225 struct clk *clk_register_fractional_divider(struct device *dev,
1226 const char *name, const char *parent_name, unsigned long flags,
1227 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1228 u8 clk_divider_flags, spinlock_t *lock);
1229 struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
1230 const char *name, const char *parent_name, unsigned long flags,
1231 void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1232 u8 clk_divider_flags, spinlock_t *lock);
1233 void clk_hw_unregister_fractional_divider(struct clk_hw *hw);
1234
1235 /**
1236 * struct clk_multiplier - adjustable multiplier clock
1237 *
1238 * @hw: handle between common and hardware-specific interfaces
1239 * @reg: register containing the multiplier
1240 * @shift: shift to the multiplier bit field
1241 * @width: width of the multiplier bit field
1242 * @lock: register lock
1243 *
1244 * Clock with an adjustable multiplier affecting its output frequency.
1245 * Implements .recalc_rate, .set_rate and .round_rate
1246 *
1247 * @flags:
1248 * CLK_MULTIPLIER_ZERO_BYPASS - By default, the multiplier is the value read
1249 * from the register, with 0 being a valid value effectively
1250 * zeroing the output clock rate. If CLK_MULTIPLIER_ZERO_BYPASS is
1251 * set, then a null multiplier will be considered as a bypass,
1252 * leaving the parent rate unmodified.
1253 * CLK_MULTIPLIER_ROUND_CLOSEST - Makes the best calculated divider to be
1254 * rounded to the closest integer instead of the down one.
1255 * CLK_MULTIPLIER_BIG_ENDIAN - By default little endian register accesses are
1256 * used for the multiplier register. Setting this flag makes the register
1257 * accesses big endian.
1258 */
1259 struct clk_multiplier {
1260 struct clk_hw hw;
1261 void __iomem *reg;
1262 u8 shift;
1263 u8 width;
1264 u8 flags;
1265 spinlock_t *lock;
1266 };
1267
1268 #define to_clk_multiplier(_hw) container_of(_hw, struct clk_multiplier, hw)
1269
1270 #define CLK_MULTIPLIER_ZERO_BYPASS BIT(0)
1271 #define CLK_MULTIPLIER_ROUND_CLOSEST BIT(1)
1272 #define CLK_MULTIPLIER_BIG_ENDIAN BIT(2)
1273
1274 extern const struct clk_ops clk_multiplier_ops;
1275
1276 /***
1277 * struct clk_composite - aggregate clock of mux, divider and gate clocks
1278 *
1279 * @hw: handle between common and hardware-specific interfaces
1280 * @mux_hw: handle between composite and hardware-specific mux clock
1281 * @rate_hw: handle between composite and hardware-specific rate clock
1282 * @gate_hw: handle between composite and hardware-specific gate clock
1283 * @mux_ops: clock ops for mux
1284 * @rate_ops: clock ops for rate
1285 * @gate_ops: clock ops for gate
1286 */
1287 struct clk_composite {
1288 struct clk_hw hw;
1289 struct clk_ops ops;
1290
1291 struct clk_hw *mux_hw;
1292 struct clk_hw *rate_hw;
1293 struct clk_hw *gate_hw;
1294
1295 const struct clk_ops *mux_ops;
1296 const struct clk_ops *rate_ops;
1297 const struct clk_ops *gate_ops;
1298 };
1299
1300 #define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
1301
1302 struct clk *clk_register_composite(struct device *dev, const char *name,
1303 const char * const *parent_names, int num_parents,
1304 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1305 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1306 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1307 unsigned long flags);
1308 struct clk *clk_register_composite_pdata(struct device *dev, const char *name,
1309 const struct clk_parent_data *parent_data, int num_parents,
1310 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1311 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1312 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1313 unsigned long flags);
1314 void clk_unregister_composite(struct clk *clk);
1315 struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
1316 const char * const *parent_names, int num_parents,
1317 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1318 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1319 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1320 unsigned long flags);
1321 struct clk_hw *clk_hw_register_composite_pdata(struct device *dev,
1322 const char *name,
1323 const struct clk_parent_data *parent_data, int num_parents,
1324 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1325 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1326 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1327 unsigned long flags);
1328 struct clk_hw *devm_clk_hw_register_composite_pdata(struct device *dev,
1329 const char *name, const struct clk_parent_data *parent_data,
1330 int num_parents,
1331 struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1332 struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1333 struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1334 unsigned long flags);
1335 void clk_hw_unregister_composite(struct clk_hw *hw);
1336
1337 struct clk *clk_register(struct device *dev, struct clk_hw *hw);
1338 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
1339
1340 int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
1341 int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
1342 int __must_check of_clk_hw_register(struct device_node *node, struct clk_hw *hw);
1343
1344 void clk_unregister(struct clk *clk);
1345
1346 void clk_hw_unregister(struct clk_hw *hw);
1347 void clk_sync_state(struct device *dev);
1348
1349 /* helper functions */
1350 const char *__clk_get_name(const struct clk *clk);
1351 const char *clk_hw_get_name(const struct clk_hw *hw);
1352 #ifdef CONFIG_COMMON_CLK
1353 struct clk_hw *__clk_get_hw(struct clk *clk);
1354 #else
__clk_get_hw(struct clk * clk)1355 static inline struct clk_hw *__clk_get_hw(struct clk *clk)
1356 {
1357 return (struct clk_hw *)clk;
1358 }
1359 #endif
1360
1361 struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id);
1362 struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
1363 const char *con_id);
1364
1365 unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
1366 struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
1367 struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
1368 unsigned int index);
1369 int clk_hw_get_parent_index(struct clk_hw *hw);
1370 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *new_parent);
1371 unsigned int __clk_get_enable_count(struct clk *clk);
1372 unsigned long clk_hw_get_rate(const struct clk_hw *hw);
1373 unsigned long clk_hw_get_flags(const struct clk_hw *hw);
1374 #define clk_hw_can_set_rate_parent(hw) \
1375 (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT)
1376
1377 bool clk_hw_is_prepared(const struct clk_hw *hw);
1378 bool clk_hw_rate_is_protected(const struct clk_hw *hw);
1379 bool clk_hw_is_enabled(const struct clk_hw *hw);
1380 bool __clk_is_enabled(struct clk *clk);
1381 struct clk *__clk_lookup(const char *name);
1382 int __clk_mux_determine_rate(struct clk_hw *hw,
1383 struct clk_rate_request *req);
1384 int __clk_determine_rate(struct clk_hw *core, struct clk_rate_request *req);
1385 int __clk_mux_determine_rate_closest(struct clk_hw *hw,
1386 struct clk_rate_request *req);
1387 int clk_mux_determine_rate_flags(struct clk_hw *hw,
1388 struct clk_rate_request *req,
1389 unsigned long flags);
1390 int clk_hw_determine_rate_no_reparent(struct clk_hw *hw,
1391 struct clk_rate_request *req);
1392 void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent);
1393 void clk_hw_get_rate_range(struct clk_hw *hw, unsigned long *min_rate,
1394 unsigned long *max_rate);
1395 void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate,
1396 unsigned long max_rate);
1397
__clk_hw_set_clk(struct clk_hw * dst,struct clk_hw * src)1398 static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src)
1399 {
1400 dst->clk = src->clk;
1401 dst->core = src->core;
1402 }
1403
divider_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * prate,const struct clk_div_table * table,u8 width,unsigned long flags)1404 static inline long divider_round_rate(struct clk_hw *hw, unsigned long rate,
1405 unsigned long *prate,
1406 const struct clk_div_table *table,
1407 u8 width, unsigned long flags)
1408 {
1409 return divider_round_rate_parent(hw, clk_hw_get_parent(hw),
1410 rate, prate, table, width, flags);
1411 }
1412
divider_ro_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * prate,const struct clk_div_table * table,u8 width,unsigned long flags,unsigned int val)1413 static inline long divider_ro_round_rate(struct clk_hw *hw, unsigned long rate,
1414 unsigned long *prate,
1415 const struct clk_div_table *table,
1416 u8 width, unsigned long flags,
1417 unsigned int val)
1418 {
1419 return divider_ro_round_rate_parent(hw, clk_hw_get_parent(hw),
1420 rate, prate, table, width, flags,
1421 val);
1422 }
1423
1424 /*
1425 * FIXME clock api without lock protection
1426 */
1427 unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate);
1428
1429 struct clk_onecell_data {
1430 struct clk **clks;
1431 unsigned int clk_num;
1432 };
1433
1434 struct clk_hw_onecell_data {
1435 unsigned int num;
1436 struct clk_hw *hws[] __counted_by(num);
1437 };
1438
1439 #define CLK_OF_DECLARE(name, compat, fn) \
1440 static void __init __##name##_of_clk_init_declare(struct device_node *np) \
1441 { \
1442 fn(np); \
1443 fwnode_dev_initialized(of_fwnode_handle(np), true); \
1444 } \
1445 OF_DECLARE_1(clk, name, compat, __##name##_of_clk_init_declare)
1446
1447 /*
1448 * Use this macro when you have a driver that requires two initialization
1449 * routines, one at of_clk_init(), and one at platform device probe
1450 */
1451 #define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
1452 static void __init name##_of_clk_init_driver(struct device_node *np) \
1453 { \
1454 of_node_clear_flag(np, OF_POPULATED); \
1455 fn(np); \
1456 } \
1457 OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
1458
1459 #define CLK_HW_INIT(_name, _parent, _ops, _flags) \
1460 (&(struct clk_init_data) { \
1461 .flags = _flags, \
1462 .name = _name, \
1463 .parent_names = (const char *[]) { _parent }, \
1464 .num_parents = 1, \
1465 .ops = _ops, \
1466 })
1467
1468 #define CLK_HW_INIT_HW(_name, _parent, _ops, _flags) \
1469 (&(struct clk_init_data) { \
1470 .flags = _flags, \
1471 .name = _name, \
1472 .parent_hws = (const struct clk_hw*[]) { _parent }, \
1473 .num_parents = 1, \
1474 .ops = _ops, \
1475 })
1476
1477 /*
1478 * This macro is intended for drivers to be able to share the otherwise
1479 * individual struct clk_hw[] compound literals created by the compiler
1480 * when using CLK_HW_INIT_HW. It does NOT support multiple parents.
1481 */
1482 #define CLK_HW_INIT_HWS(_name, _parent, _ops, _flags) \
1483 (&(struct clk_init_data) { \
1484 .flags = _flags, \
1485 .name = _name, \
1486 .parent_hws = _parent, \
1487 .num_parents = 1, \
1488 .ops = _ops, \
1489 })
1490
1491 #define CLK_HW_INIT_FW_NAME(_name, _parent, _ops, _flags) \
1492 (&(struct clk_init_data) { \
1493 .flags = _flags, \
1494 .name = _name, \
1495 .parent_data = (const struct clk_parent_data[]) { \
1496 { .fw_name = _parent }, \
1497 }, \
1498 .num_parents = 1, \
1499 .ops = _ops, \
1500 })
1501
1502 #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags) \
1503 (&(struct clk_init_data) { \
1504 .flags = _flags, \
1505 .name = _name, \
1506 .parent_names = _parents, \
1507 .num_parents = ARRAY_SIZE(_parents), \
1508 .ops = _ops, \
1509 })
1510
1511 #define CLK_HW_INIT_PARENTS_HW(_name, _parents, _ops, _flags) \
1512 (&(struct clk_init_data) { \
1513 .flags = _flags, \
1514 .name = _name, \
1515 .parent_hws = _parents, \
1516 .num_parents = ARRAY_SIZE(_parents), \
1517 .ops = _ops, \
1518 })
1519
1520 #define CLK_HW_INIT_PARENTS_DATA(_name, _parents, _ops, _flags) \
1521 (&(struct clk_init_data) { \
1522 .flags = _flags, \
1523 .name = _name, \
1524 .parent_data = _parents, \
1525 .num_parents = ARRAY_SIZE(_parents), \
1526 .ops = _ops, \
1527 })
1528
1529 #define CLK_HW_INIT_NO_PARENT(_name, _ops, _flags) \
1530 (&(struct clk_init_data) { \
1531 .flags = _flags, \
1532 .name = _name, \
1533 .parent_names = NULL, \
1534 .num_parents = 0, \
1535 .ops = _ops, \
1536 })
1537
1538 #define CLK_FIXED_FACTOR(_struct, _name, _parent, \
1539 _div, _mult, _flags) \
1540 struct clk_fixed_factor _struct = { \
1541 .div = _div, \
1542 .mult = _mult, \
1543 .hw.init = CLK_HW_INIT(_name, \
1544 _parent, \
1545 &clk_fixed_factor_ops, \
1546 _flags), \
1547 }
1548
1549 #define CLK_FIXED_FACTOR_HW(_struct, _name, _parent, \
1550 _div, _mult, _flags) \
1551 struct clk_fixed_factor _struct = { \
1552 .div = _div, \
1553 .mult = _mult, \
1554 .hw.init = CLK_HW_INIT_HW(_name, \
1555 _parent, \
1556 &clk_fixed_factor_ops, \
1557 _flags), \
1558 }
1559
1560 /*
1561 * This macro allows the driver to reuse the _parent array for multiple
1562 * fixed factor clk declarations.
1563 */
1564 #define CLK_FIXED_FACTOR_HWS(_struct, _name, _parent, \
1565 _div, _mult, _flags) \
1566 struct clk_fixed_factor _struct = { \
1567 .div = _div, \
1568 .mult = _mult, \
1569 .hw.init = CLK_HW_INIT_HWS(_name, \
1570 _parent, \
1571 &clk_fixed_factor_ops, \
1572 _flags), \
1573 }
1574
1575 #define CLK_FIXED_FACTOR_FW_NAME(_struct, _name, _parent, \
1576 _div, _mult, _flags) \
1577 struct clk_fixed_factor _struct = { \
1578 .div = _div, \
1579 .mult = _mult, \
1580 .hw.init = CLK_HW_INIT_FW_NAME(_name, \
1581 _parent, \
1582 &clk_fixed_factor_ops, \
1583 _flags), \
1584 }
1585
1586 #ifdef CONFIG_OF
1587 int of_clk_add_provider(struct device_node *np,
1588 struct clk *(*clk_src_get)(struct of_phandle_args *args,
1589 void *data),
1590 void *data);
1591 int of_clk_add_hw_provider(struct device_node *np,
1592 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1593 void *data),
1594 void *data);
1595 int devm_of_clk_add_hw_provider(struct device *dev,
1596 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1597 void *data),
1598 void *data);
1599 void of_clk_del_provider(struct device_node *np);
1600
1601 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
1602 void *data);
1603 struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
1604 void *data);
1605 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
1606 struct clk_hw *of_clk_hw_onecell_get(struct of_phandle_args *clkspec,
1607 void *data);
1608 int of_clk_parent_fill(struct device_node *np, const char **parents,
1609 unsigned int size);
1610 int of_clk_detect_critical(struct device_node *np, int index,
1611 unsigned long *flags);
1612
1613 #else /* !CONFIG_OF */
1614
of_clk_add_provider(struct device_node * np,struct clk * (* clk_src_get)(struct of_phandle_args * args,void * data),void * data)1615 static inline int of_clk_add_provider(struct device_node *np,
1616 struct clk *(*clk_src_get)(struct of_phandle_args *args,
1617 void *data),
1618 void *data)
1619 {
1620 return 0;
1621 }
of_clk_add_hw_provider(struct device_node * np,struct clk_hw * (* get)(struct of_phandle_args * clkspec,void * data),void * data)1622 static inline int of_clk_add_hw_provider(struct device_node *np,
1623 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1624 void *data),
1625 void *data)
1626 {
1627 return 0;
1628 }
devm_of_clk_add_hw_provider(struct device * dev,struct clk_hw * (* get)(struct of_phandle_args * clkspec,void * data),void * data)1629 static inline int devm_of_clk_add_hw_provider(struct device *dev,
1630 struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1631 void *data),
1632 void *data)
1633 {
1634 return 0;
1635 }
of_clk_del_provider(struct device_node * np)1636 static inline void of_clk_del_provider(struct device_node *np) {}
1637
of_clk_src_simple_get(struct of_phandle_args * clkspec,void * data)1638 static inline struct clk *of_clk_src_simple_get(
1639 struct of_phandle_args *clkspec, void *data)
1640 {
1641 return ERR_PTR(-ENOENT);
1642 }
1643 static inline struct clk_hw *
of_clk_hw_simple_get(struct of_phandle_args * clkspec,void * data)1644 of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
1645 {
1646 return ERR_PTR(-ENOENT);
1647 }
of_clk_src_onecell_get(struct of_phandle_args * clkspec,void * data)1648 static inline struct clk *of_clk_src_onecell_get(
1649 struct of_phandle_args *clkspec, void *data)
1650 {
1651 return ERR_PTR(-ENOENT);
1652 }
1653 static inline struct clk_hw *
of_clk_hw_onecell_get(struct of_phandle_args * clkspec,void * data)1654 of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
1655 {
1656 return ERR_PTR(-ENOENT);
1657 }
of_clk_parent_fill(struct device_node * np,const char ** parents,unsigned int size)1658 static inline int of_clk_parent_fill(struct device_node *np,
1659 const char **parents, unsigned int size)
1660 {
1661 return 0;
1662 }
of_clk_detect_critical(struct device_node * np,int index,unsigned long * flags)1663 static inline int of_clk_detect_critical(struct device_node *np, int index,
1664 unsigned long *flags)
1665 {
1666 return 0;
1667 }
1668 #endif /* CONFIG_OF */
1669
1670 void clk_gate_restore_context(struct clk_hw *hw);
1671
1672 #endif /* CLK_PROVIDER_H */
1673