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