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