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