Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  Copyright (c) 2010-2011 Jeremy Kerr <jeremy.kerr@canonical.com>
0004  *  Copyright (C) 2011-2012 Linaro Ltd <mturquette@linaro.org>
0005  */
0006 #ifndef __LINUX_CLK_PROVIDER_H
0007 #define __LINUX_CLK_PROVIDER_H
0008 
0009 #include <linux/of.h>
0010 #include <linux/of_clk.h>
0011 
0012 /*
0013  * flags used across common struct clk.  these flags should only affect the
0014  * top-level framework.  custom flags for dealing with hardware specifics
0015  * belong in struct clk_foo
0016  *
0017  * Please update clk_flags[] in drivers/clk/clk.c when making changes here!
0018  */
0019 #define CLK_SET_RATE_GATE   BIT(0) /* must be gated across rate change */
0020 #define CLK_SET_PARENT_GATE BIT(1) /* must be gated across re-parent */
0021 #define CLK_SET_RATE_PARENT BIT(2) /* propagate rate change up one level */
0022 #define CLK_IGNORE_UNUSED   BIT(3) /* do not gate even if unused */
0023                 /* unused */
0024                 /* unused */
0025 #define CLK_GET_RATE_NOCACHE    BIT(6) /* do not use the cached clk rate */
0026 #define CLK_SET_RATE_NO_REPARENT BIT(7) /* don't re-parent on rate change */
0027 #define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
0028 #define CLK_RECALC_NEW_RATES    BIT(9) /* recalc rates after notifications */
0029 #define CLK_SET_RATE_UNGATE BIT(10) /* clock needs to run to set rate */
0030 #define CLK_IS_CRITICAL     BIT(11) /* do not gate, ever */
0031 /* parents need enable during gate/ungate, set rate and re-parent */
0032 #define CLK_OPS_PARENT_ENABLE   BIT(12)
0033 /* duty cycle call may be forwarded to the parent clock */
0034 #define CLK_DUTY_CYCLE_PARENT   BIT(13)
0035 
0036 struct clk;
0037 struct clk_hw;
0038 struct clk_core;
0039 struct dentry;
0040 
0041 /**
0042  * struct clk_rate_request - Structure encoding the clk constraints that
0043  * a clock user might require.
0044  *
0045  * @rate:       Requested clock rate. This field will be adjusted by
0046  *          clock drivers according to hardware capabilities.
0047  * @min_rate:       Minimum rate imposed by clk users.
0048  * @max_rate:       Maximum rate imposed by clk users.
0049  * @best_parent_rate:   The best parent rate a parent can provide to fulfill the
0050  *          requested constraints.
0051  * @best_parent_hw: The most appropriate parent clock that fulfills the
0052  *          requested constraints.
0053  *
0054  */
0055 struct clk_rate_request {
0056     unsigned long rate;
0057     unsigned long min_rate;
0058     unsigned long max_rate;
0059     unsigned long best_parent_rate;
0060     struct clk_hw *best_parent_hw;
0061 };
0062 
0063 /**
0064  * struct clk_duty - Struture encoding the duty cycle ratio of a clock
0065  *
0066  * @num:    Numerator of the duty cycle ratio
0067  * @den:    Denominator of the duty cycle ratio
0068  */
0069 struct clk_duty {
0070     unsigned int num;
0071     unsigned int den;
0072 };
0073 
0074 /**
0075  * struct clk_ops -  Callback operations for hardware clocks; these are to
0076  * be provided by the clock implementation, and will be called by drivers
0077  * through the clk_* api.
0078  *
0079  * @prepare:    Prepare the clock for enabling. This must not return until
0080  *      the clock is fully prepared, and it's safe to call clk_enable.
0081  *      This callback is intended to allow clock implementations to
0082  *      do any initialisation that may sleep. Called with
0083  *      prepare_lock held.
0084  *
0085  * @unprepare:  Release the clock from its prepared state. This will typically
0086  *      undo any work done in the @prepare callback. Called with
0087  *      prepare_lock held.
0088  *
0089  * @is_prepared: Queries the hardware to determine if the clock is prepared.
0090  *      This function is allowed to sleep. Optional, if this op is not
0091  *      set then the prepare count will be used.
0092  *
0093  * @unprepare_unused: Unprepare the clock atomically.  Only called from
0094  *      clk_disable_unused for prepare clocks with special needs.
0095  *      Called with prepare mutex held. This function may sleep.
0096  *
0097  * @enable: Enable the clock atomically. This must not return until the
0098  *      clock is generating a valid clock signal, usable by consumer
0099  *      devices. Called with enable_lock held. This function must not
0100  *      sleep.
0101  *
0102  * @disable:    Disable the clock atomically. Called with enable_lock held.
0103  *      This function must not sleep.
0104  *
0105  * @is_enabled: Queries the hardware to determine if the clock is enabled.
0106  *      This function must not sleep. Optional, if this op is not
0107  *      set then the enable count will be used.
0108  *
0109  * @disable_unused: Disable the clock atomically.  Only called from
0110  *      clk_disable_unused for gate clocks with special needs.
0111  *      Called with enable_lock held.  This function must not
0112  *      sleep.
0113  *
0114  * @save_context: Save the context of the clock in prepration for poweroff.
0115  *
0116  * @restore_context: Restore the context of the clock after a restoration
0117  *      of power.
0118  *
0119  * @recalc_rate Recalculate the rate of this clock, by querying hardware. The
0120  *      parent rate is an input parameter.  It is up to the caller to
0121  *      ensure that the prepare_mutex is held across this call.
0122  *      Returns the calculated rate.  Optional, but recommended - if
0123  *      this op is not set then clock rate will be initialized to 0.
0124  *
0125  * @round_rate: Given a target rate as input, returns the closest rate actually
0126  *      supported by the clock. The parent rate is an input/output
0127  *      parameter.
0128  *
0129  * @determine_rate: Given a target rate as input, returns the closest rate
0130  *      actually supported by the clock, and optionally the parent clock
0131  *      that should be used to provide the clock rate.
0132  *
0133  * @set_parent: Change the input source of this clock; for clocks with multiple
0134  *      possible parents specify a new parent by passing in the index
0135  *      as a u8 corresponding to the parent in either the .parent_names
0136  *      or .parents arrays.  This function in affect translates an
0137  *      array index into the value programmed into the hardware.
0138  *      Returns 0 on success, -EERROR otherwise.
0139  *
0140  * @get_parent: Queries the hardware to determine the parent of a clock.  The
0141  *      return value is a u8 which specifies the index corresponding to
0142  *      the parent clock.  This index can be applied to either the
0143  *      .parent_names or .parents arrays.  In short, this function
0144  *      translates the parent value read from hardware into an array
0145  *      index.  Currently only called when the clock is initialized by
0146  *      __clk_init.  This callback is mandatory for clocks with
0147  *      multiple parents.  It is optional (and unnecessary) for clocks
0148  *      with 0 or 1 parents.
0149  *
0150  * @set_rate:   Change the rate of this clock. The requested rate is specified
0151  *      by the second argument, which should typically be the return
0152  *      of .round_rate call.  The third argument gives the parent rate
0153  *      which is likely helpful for most .set_rate implementation.
0154  *      Returns 0 on success, -EERROR otherwise.
0155  *
0156  * @set_rate_and_parent: Change the rate and the parent of this clock. The
0157  *      requested rate is specified by the second argument, which
0158  *      should typically be the return of .round_rate call.  The
0159  *      third argument gives the parent rate which is likely helpful
0160  *      for most .set_rate_and_parent implementation. The fourth
0161  *      argument gives the parent index. This callback is optional (and
0162  *      unnecessary) for clocks with 0 or 1 parents as well as
0163  *      for clocks that can tolerate switching the rate and the parent
0164  *      separately via calls to .set_parent and .set_rate.
0165  *      Returns 0 on success, -EERROR otherwise.
0166  *
0167  * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy
0168  *      is expressed in ppb (parts per billion). The parent accuracy is
0169  *      an input parameter.
0170  *      Returns the calculated accuracy.  Optional - if this op is not
0171  *      set then clock accuracy will be initialized to parent accuracy
0172  *      or 0 (perfect clock) if clock has no parent.
0173  *
0174  * @get_phase:  Queries the hardware to get the current phase of a clock.
0175  *      Returned values are 0-359 degrees on success, negative
0176  *      error codes on failure.
0177  *
0178  * @set_phase:  Shift the phase this clock signal in degrees specified
0179  *      by the second argument. Valid values for degrees are
0180  *      0-359. Return 0 on success, otherwise -EERROR.
0181  *
0182  * @get_duty_cycle: Queries the hardware to get the current duty cycle ratio
0183  *              of a clock. Returned values denominator cannot be 0 and must be
0184  *              superior or equal to the numerator.
0185  *
0186  * @set_duty_cycle: Apply the duty cycle ratio to this clock signal specified by
0187  *              the numerator (2nd argurment) and denominator (3rd  argument).
0188  *              Argument must be a valid ratio (denominator > 0
0189  *              and >= numerator) Return 0 on success, otherwise -EERROR.
0190  *
0191  * @init:   Perform platform-specific initialization magic.
0192  *      This is not used by any of the basic clock types.
0193  *      This callback exist for HW which needs to perform some
0194  *      initialisation magic for CCF to get an accurate view of the
0195  *      clock. It may also be used dynamic resource allocation is
0196  *      required. It shall not used to deal with clock parameters,
0197  *      such as rate or parents.
0198  *      Returns 0 on success, -EERROR otherwise.
0199  *
0200  * @terminate:  Free any resource allocated by init.
0201  *
0202  * @debug_init: Set up type-specific debugfs entries for this clock.  This
0203  *      is called once, after the debugfs directory entry for this
0204  *      clock has been created.  The dentry pointer representing that
0205  *      directory is provided as an argument.  Called with
0206  *      prepare_lock held.  Returns 0 on success, -EERROR otherwise.
0207  *
0208  *
0209  * The clk_enable/clk_disable and clk_prepare/clk_unprepare pairs allow
0210  * implementations to split any work between atomic (enable) and sleepable
0211  * (prepare) contexts.  If enabling a clock requires code that might sleep,
0212  * this must be done in clk_prepare.  Clock enable code that will never be
0213  * called in a sleepable context may be implemented in clk_enable.
0214  *
0215  * Typically, drivers will call clk_prepare when a clock may be needed later
0216  * (eg. when a device is opened), and clk_enable when the clock is actually
0217  * required (eg. from an interrupt). Note that clk_prepare MUST have been
0218  * called before clk_enable.
0219  */
0220 struct clk_ops {
0221     int     (*prepare)(struct clk_hw *hw);
0222     void        (*unprepare)(struct clk_hw *hw);
0223     int     (*is_prepared)(struct clk_hw *hw);
0224     void        (*unprepare_unused)(struct clk_hw *hw);
0225     int     (*enable)(struct clk_hw *hw);
0226     void        (*disable)(struct clk_hw *hw);
0227     int     (*is_enabled)(struct clk_hw *hw);
0228     void        (*disable_unused)(struct clk_hw *hw);
0229     int     (*save_context)(struct clk_hw *hw);
0230     void        (*restore_context)(struct clk_hw *hw);
0231     unsigned long   (*recalc_rate)(struct clk_hw *hw,
0232                     unsigned long parent_rate);
0233     long        (*round_rate)(struct clk_hw *hw, unsigned long rate,
0234                     unsigned long *parent_rate);
0235     int     (*determine_rate)(struct clk_hw *hw,
0236                       struct clk_rate_request *req);
0237     int     (*set_parent)(struct clk_hw *hw, u8 index);
0238     u8      (*get_parent)(struct clk_hw *hw);
0239     int     (*set_rate)(struct clk_hw *hw, unsigned long rate,
0240                     unsigned long parent_rate);
0241     int     (*set_rate_and_parent)(struct clk_hw *hw,
0242                     unsigned long rate,
0243                     unsigned long parent_rate, u8 index);
0244     unsigned long   (*recalc_accuracy)(struct clk_hw *hw,
0245                        unsigned long parent_accuracy);
0246     int     (*get_phase)(struct clk_hw *hw);
0247     int     (*set_phase)(struct clk_hw *hw, int degrees);
0248     int     (*get_duty_cycle)(struct clk_hw *hw,
0249                       struct clk_duty *duty);
0250     int     (*set_duty_cycle)(struct clk_hw *hw,
0251                       struct clk_duty *duty);
0252     int     (*init)(struct clk_hw *hw);
0253     void        (*terminate)(struct clk_hw *hw);
0254     void        (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
0255 };
0256 
0257 /**
0258  * struct clk_parent_data - clk parent information
0259  * @hw: parent clk_hw pointer (used for clk providers with internal clks)
0260  * @fw_name: parent name local to provider registering clk
0261  * @name: globally unique parent name (used as a fallback)
0262  * @index: parent index local to provider registering clk (if @fw_name absent)
0263  */
0264 struct clk_parent_data {
0265     const struct clk_hw *hw;
0266     const char      *fw_name;
0267     const char      *name;
0268     int         index;
0269 };
0270 
0271 /**
0272  * struct clk_init_data - holds init data that's common to all clocks and is
0273  * shared between the clock provider and the common clock framework.
0274  *
0275  * @name: clock name
0276  * @ops: operations this clock supports
0277  * @parent_names: array of string names for all possible parents
0278  * @parent_data: array of parent data for all possible parents (when some
0279  *               parents are external to the clk controller)
0280  * @parent_hws: array of pointers to all possible parents (when all parents
0281  *              are internal to the clk controller)
0282  * @num_parents: number of possible parents
0283  * @flags: framework-level hints and quirks
0284  */
0285 struct clk_init_data {
0286     const char      *name;
0287     const struct clk_ops    *ops;
0288     /* Only one of the following three should be assigned */
0289     const char      * const *parent_names;
0290     const struct clk_parent_data    *parent_data;
0291     const struct clk_hw     **parent_hws;
0292     u8          num_parents;
0293     unsigned long       flags;
0294 };
0295 
0296 /**
0297  * struct clk_hw - handle for traversing from a struct clk to its corresponding
0298  * hardware-specific structure.  struct clk_hw should be declared within struct
0299  * clk_foo and then referenced by the struct clk instance that uses struct
0300  * clk_foo's clk_ops
0301  *
0302  * @core: pointer to the struct clk_core instance that points back to this
0303  * struct clk_hw instance
0304  *
0305  * @clk: pointer to the per-user struct clk instance that can be used to call
0306  * into the clk API
0307  *
0308  * @init: pointer to struct clk_init_data that contains the init data shared
0309  * with the common clock framework. This pointer will be set to NULL once
0310  * a clk_register() variant is called on this clk_hw pointer.
0311  */
0312 struct clk_hw {
0313     struct clk_core *core;
0314     struct clk *clk;
0315     const struct clk_init_data *init;
0316 };
0317 
0318 /*
0319  * DOC: Basic clock implementations common to many platforms
0320  *
0321  * Each basic clock hardware type is comprised of a structure describing the
0322  * clock hardware, implementations of the relevant callbacks in struct clk_ops,
0323  * unique flags for that hardware type, a registration function and an
0324  * alternative macro for static initialization
0325  */
0326 
0327 /**
0328  * struct clk_fixed_rate - fixed-rate clock
0329  * @hw:     handle between common and hardware-specific interfaces
0330  * @fixed_rate: constant frequency of clock
0331  * @fixed_accuracy: constant accuracy of clock in ppb (parts per billion)
0332  * @flags:  hardware specific flags
0333  *
0334  * Flags:
0335  * * CLK_FIXED_RATE_PARENT_ACCURACY - Use the accuracy of the parent clk
0336  *                                    instead of what's set in @fixed_accuracy.
0337  */
0338 struct clk_fixed_rate {
0339     struct      clk_hw hw;
0340     unsigned long   fixed_rate;
0341     unsigned long   fixed_accuracy;
0342     unsigned long   flags;
0343 };
0344 
0345 #define CLK_FIXED_RATE_PARENT_ACCURACY  BIT(0)
0346 
0347 extern const struct clk_ops clk_fixed_rate_ops;
0348 struct clk_hw *__clk_hw_register_fixed_rate(struct device *dev,
0349         struct device_node *np, const char *name,
0350         const char *parent_name, const struct clk_hw *parent_hw,
0351         const struct clk_parent_data *parent_data, unsigned long flags,
0352         unsigned long fixed_rate, unsigned long fixed_accuracy,
0353         unsigned long clk_fixed_flags);
0354 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
0355         const char *parent_name, unsigned long flags,
0356         unsigned long fixed_rate);
0357 /**
0358  * clk_hw_register_fixed_rate - register fixed-rate clock with the clock
0359  * framework
0360  * @dev: device that is registering this clock
0361  * @name: name of this clock
0362  * @parent_name: name of clock's parent
0363  * @flags: framework-specific flags
0364  * @fixed_rate: non-adjustable clock rate
0365  */
0366 #define clk_hw_register_fixed_rate(dev, name, parent_name, flags, fixed_rate)  \
0367     __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name), NULL, \
0368                      NULL, (flags), (fixed_rate), 0, 0)
0369 /**
0370  * clk_hw_register_fixed_rate_parent_hw - register fixed-rate clock with
0371  * the clock framework
0372  * @dev: device that is registering this clock
0373  * @name: name of this clock
0374  * @parent_hw: pointer to parent clk
0375  * @flags: framework-specific flags
0376  * @fixed_rate: non-adjustable clock rate
0377  */
0378 #define clk_hw_register_fixed_rate_parent_hw(dev, name, parent_hw, flags,     \
0379                          fixed_rate)              \
0380     __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw),  \
0381                      NULL, (flags), (fixed_rate), 0, 0)
0382 /**
0383  * clk_hw_register_fixed_rate_parent_data - register fixed-rate clock with
0384  * the clock framework
0385  * @dev: device that is registering this clock
0386  * @name: name of this clock
0387  * @parent_data: parent clk data
0388  * @flags: framework-specific flags
0389  * @fixed_rate: non-adjustable clock rate
0390  */
0391 #define clk_hw_register_fixed_rate_parent_data(dev, name, parent_hw, flags,   \
0392                          fixed_rate)              \
0393     __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL,         \
0394                      (parent_data), (flags), (fixed_rate), 0, \
0395                      0)
0396 /**
0397  * clk_hw_register_fixed_rate_with_accuracy - register fixed-rate clock with
0398  * the clock framework
0399  * @dev: device that is registering this clock
0400  * @name: name of this clock
0401  * @parent_name: name of clock's parent
0402  * @flags: framework-specific flags
0403  * @fixed_rate: non-adjustable clock rate
0404  * @fixed_accuracy: non-adjustable clock accuracy
0405  */
0406 #define clk_hw_register_fixed_rate_with_accuracy(dev, name, parent_name,      \
0407                          flags, fixed_rate,       \
0408                          fixed_accuracy)          \
0409     __clk_hw_register_fixed_rate((dev), NULL, (name), (parent_name),      \
0410                      NULL, NULL, (flags), (fixed_rate),       \
0411                      (fixed_accuracy), 0)
0412 /**
0413  * clk_hw_register_fixed_rate_with_accuracy_parent_hw - register fixed-rate
0414  * clock with the clock framework
0415  * @dev: device that is registering this clock
0416  * @name: name of this clock
0417  * @parent_hw: pointer to parent clk
0418  * @flags: framework-specific flags
0419  * @fixed_rate: non-adjustable clock rate
0420  * @fixed_accuracy: non-adjustable clock accuracy
0421  */
0422 #define clk_hw_register_fixed_rate_with_accuracy_parent_hw(dev, name,         \
0423         parent_hw, flags, fixed_rate, fixed_accuracy)             \
0424     __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, (parent_hw)   \
0425                      NULL, NULL, (flags), (fixed_rate),       \
0426                      (fixed_accuracy), 0)
0427 /**
0428  * clk_hw_register_fixed_rate_with_accuracy_parent_data - register fixed-rate
0429  * clock with the clock framework
0430  * @dev: device that is registering this clock
0431  * @name: name of this clock
0432  * @parent_name: name of clock's parent
0433  * @flags: framework-specific flags
0434  * @fixed_rate: non-adjustable clock rate
0435  * @fixed_accuracy: non-adjustable clock accuracy
0436  */
0437 #define clk_hw_register_fixed_rate_with_accuracy_parent_data(dev, name,       \
0438         parent_data, flags, fixed_rate, fixed_accuracy)           \
0439     __clk_hw_register_fixed_rate((dev), NULL, (name), NULL, NULL,         \
0440                      (parent_data), NULL, (flags),        \
0441                      (fixed_rate), (fixed_accuracy), 0)
0442 
0443 void clk_unregister_fixed_rate(struct clk *clk);
0444 void clk_hw_unregister_fixed_rate(struct clk_hw *hw);
0445 
0446 void of_fixed_clk_setup(struct device_node *np);
0447 
0448 /**
0449  * struct clk_gate - gating clock
0450  *
0451  * @hw:     handle between common and hardware-specific interfaces
0452  * @reg:    register controlling gate
0453  * @bit_idx:    single bit controlling gate
0454  * @flags:  hardware-specific flags
0455  * @lock:   register lock
0456  *
0457  * Clock which can gate its output.  Implements .enable & .disable
0458  *
0459  * Flags:
0460  * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to
0461  *  enable the clock.  Setting this flag does the opposite: setting the bit
0462  *  disable the clock and clearing it enables the clock
0463  * CLK_GATE_HIWORD_MASK - The gate settings are only in lower 16-bit
0464  *  of this register, and mask of gate bits are in higher 16-bit of this
0465  *  register.  While setting the gate bits, higher 16-bit should also be
0466  *  updated to indicate changing gate bits.
0467  * CLK_GATE_BIG_ENDIAN - by default little endian register accesses are used for
0468  *  the gate register.  Setting this flag makes the register accesses big
0469  *  endian.
0470  */
0471 struct clk_gate {
0472     struct clk_hw hw;
0473     void __iomem    *reg;
0474     u8      bit_idx;
0475     u8      flags;
0476     spinlock_t  *lock;
0477 };
0478 
0479 #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
0480 
0481 #define CLK_GATE_SET_TO_DISABLE     BIT(0)
0482 #define CLK_GATE_HIWORD_MASK        BIT(1)
0483 #define CLK_GATE_BIG_ENDIAN     BIT(2)
0484 
0485 extern const struct clk_ops clk_gate_ops;
0486 struct clk_hw *__clk_hw_register_gate(struct device *dev,
0487         struct device_node *np, const char *name,
0488         const char *parent_name, const struct clk_hw *parent_hw,
0489         const struct clk_parent_data *parent_data,
0490         unsigned long flags,
0491         void __iomem *reg, u8 bit_idx,
0492         u8 clk_gate_flags, spinlock_t *lock);
0493 struct clk_hw *__devm_clk_hw_register_gate(struct device *dev,
0494         struct device_node *np, const char *name,
0495         const char *parent_name, const struct clk_hw *parent_hw,
0496         const struct clk_parent_data *parent_data,
0497         unsigned long flags,
0498         void __iomem *reg, u8 bit_idx,
0499         u8 clk_gate_flags, spinlock_t *lock);
0500 struct clk *clk_register_gate(struct device *dev, const char *name,
0501         const char *parent_name, unsigned long flags,
0502         void __iomem *reg, u8 bit_idx,
0503         u8 clk_gate_flags, spinlock_t *lock);
0504 /**
0505  * clk_hw_register_gate - register a gate clock with the clock framework
0506  * @dev: device that is registering this clock
0507  * @name: name of this clock
0508  * @parent_name: name of this clock's parent
0509  * @flags: framework-specific flags for this clock
0510  * @reg: register address to control gating of this clock
0511  * @bit_idx: which bit in the register controls gating of this clock
0512  * @clk_gate_flags: gate-specific flags for this clock
0513  * @lock: shared register lock for this clock
0514  */
0515 #define clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,     \
0516                  clk_gate_flags, lock)                \
0517     __clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL,      \
0518                    NULL, (flags), (reg), (bit_idx),           \
0519                    (clk_gate_flags), (lock))
0520 /**
0521  * clk_hw_register_gate_parent_hw - register a gate clock with the clock
0522  * framework
0523  * @dev: device that is registering this clock
0524  * @name: name of this clock
0525  * @parent_hw: pointer to parent clk
0526  * @flags: framework-specific flags for this clock
0527  * @reg: register address to control gating of this clock
0528  * @bit_idx: which bit in the register controls gating of this clock
0529  * @clk_gate_flags: gate-specific flags for this clock
0530  * @lock: shared register lock for this clock
0531  */
0532 #define clk_hw_register_gate_parent_hw(dev, name, parent_hw, flags, reg,      \
0533                        bit_idx, clk_gate_flags, lock)         \
0534     __clk_hw_register_gate((dev), NULL, (name), NULL, (parent_hw),        \
0535                    NULL, (flags), (reg), (bit_idx),           \
0536                    (clk_gate_flags), (lock))
0537 /**
0538  * clk_hw_register_gate_parent_data - register a gate clock with the clock
0539  * framework
0540  * @dev: device that is registering this clock
0541  * @name: name of this clock
0542  * @parent_data: parent clk data
0543  * @flags: framework-specific flags for this clock
0544  * @reg: register address to control gating of this clock
0545  * @bit_idx: which bit in the register controls gating of this clock
0546  * @clk_gate_flags: gate-specific flags for this clock
0547  * @lock: shared register lock for this clock
0548  */
0549 #define clk_hw_register_gate_parent_data(dev, name, parent_data, flags, reg,  \
0550                        bit_idx, clk_gate_flags, lock)         \
0551     __clk_hw_register_gate((dev), NULL, (name), NULL, NULL, (parent_data), \
0552                    (flags), (reg), (bit_idx),             \
0553                    (clk_gate_flags), (lock))
0554 /**
0555  * devm_clk_hw_register_gate - register a gate clock with the clock framework
0556  * @dev: device that is registering this clock
0557  * @name: name of this clock
0558  * @parent_name: name of this clock's parent
0559  * @flags: framework-specific flags for this clock
0560  * @reg: register address to control gating of this clock
0561  * @bit_idx: which bit in the register controls gating of this clock
0562  * @clk_gate_flags: gate-specific flags for this clock
0563  * @lock: shared register lock for this clock
0564  */
0565 #define devm_clk_hw_register_gate(dev, name, parent_name, flags, reg, bit_idx,\
0566                   clk_gate_flags, lock)               \
0567     __devm_clk_hw_register_gate((dev), NULL, (name), (parent_name), NULL, \
0568                    NULL, (flags), (reg), (bit_idx),           \
0569                    (clk_gate_flags), (lock))
0570 void clk_unregister_gate(struct clk *clk);
0571 void clk_hw_unregister_gate(struct clk_hw *hw);
0572 int clk_gate_is_enabled(struct clk_hw *hw);
0573 
0574 struct clk_div_table {
0575     unsigned int    val;
0576     unsigned int    div;
0577 };
0578 
0579 /**
0580  * struct clk_divider - adjustable divider clock
0581  *
0582  * @hw:     handle between common and hardware-specific interfaces
0583  * @reg:    register containing the divider
0584  * @shift:  shift to the divider bit field
0585  * @width:  width of the divider bit field
0586  * @table:  array of value/divider pairs, last entry should have div = 0
0587  * @lock:   register lock
0588  *
0589  * Clock with an adjustable divider affecting its output frequency.  Implements
0590  * .recalc_rate, .set_rate and .round_rate
0591  *
0592  * Flags:
0593  * CLK_DIVIDER_ONE_BASED - by default the divisor is the value read from the
0594  *  register plus one.  If CLK_DIVIDER_ONE_BASED is set then the divider is
0595  *  the raw value read from the register, with the value of zero considered
0596  *  invalid, unless CLK_DIVIDER_ALLOW_ZERO is set.
0597  * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from
0598  *  the hardware register
0599  * CLK_DIVIDER_ALLOW_ZERO - Allow zero divisors.  For dividers which have
0600  *  CLK_DIVIDER_ONE_BASED set, it is possible to end up with a zero divisor.
0601  *  Some hardware implementations gracefully handle this case and allow a
0602  *  zero divisor by not modifying their input clock
0603  *  (divide by one / bypass).
0604  * CLK_DIVIDER_HIWORD_MASK - The divider settings are only in lower 16-bit
0605  *  of this register, and mask of divider bits are in higher 16-bit of this
0606  *  register.  While setting the divider bits, higher 16-bit should also be
0607  *  updated to indicate changing divider bits.
0608  * CLK_DIVIDER_ROUND_CLOSEST - Makes the best calculated divider to be rounded
0609  *  to the closest integer instead of the up one.
0610  * CLK_DIVIDER_READ_ONLY - The divider settings are preconfigured and should
0611  *  not be changed by the clock framework.
0612  * CLK_DIVIDER_MAX_AT_ZERO - For dividers which are like CLK_DIVIDER_ONE_BASED
0613  *  except when the value read from the register is zero, the divisor is
0614  *  2^width of the field.
0615  * CLK_DIVIDER_BIG_ENDIAN - By default little endian register accesses are used
0616  *  for the divider register.  Setting this flag makes the register accesses
0617  *  big endian.
0618  */
0619 struct clk_divider {
0620     struct clk_hw   hw;
0621     void __iomem    *reg;
0622     u8      shift;
0623     u8      width;
0624     u8      flags;
0625     const struct clk_div_table  *table;
0626     spinlock_t  *lock;
0627 };
0628 
0629 #define clk_div_mask(width) ((1 << (width)) - 1)
0630 #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
0631 
0632 #define CLK_DIVIDER_ONE_BASED       BIT(0)
0633 #define CLK_DIVIDER_POWER_OF_TWO    BIT(1)
0634 #define CLK_DIVIDER_ALLOW_ZERO      BIT(2)
0635 #define CLK_DIVIDER_HIWORD_MASK     BIT(3)
0636 #define CLK_DIVIDER_ROUND_CLOSEST   BIT(4)
0637 #define CLK_DIVIDER_READ_ONLY       BIT(5)
0638 #define CLK_DIVIDER_MAX_AT_ZERO     BIT(6)
0639 #define CLK_DIVIDER_BIG_ENDIAN      BIT(7)
0640 
0641 extern const struct clk_ops clk_divider_ops;
0642 extern const struct clk_ops clk_divider_ro_ops;
0643 
0644 unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate,
0645         unsigned int val, const struct clk_div_table *table,
0646         unsigned long flags, unsigned long width);
0647 long divider_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
0648                    unsigned long rate, unsigned long *prate,
0649                    const struct clk_div_table *table,
0650                    u8 width, unsigned long flags);
0651 long divider_ro_round_rate_parent(struct clk_hw *hw, struct clk_hw *parent,
0652                   unsigned long rate, unsigned long *prate,
0653                   const struct clk_div_table *table, u8 width,
0654                   unsigned long flags, unsigned int val);
0655 int divider_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
0656                const struct clk_div_table *table, u8 width,
0657                unsigned long flags);
0658 int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req,
0659                   const struct clk_div_table *table, u8 width,
0660                   unsigned long flags, unsigned int val);
0661 int divider_get_val(unsigned long rate, unsigned long parent_rate,
0662         const struct clk_div_table *table, u8 width,
0663         unsigned long flags);
0664 
0665 struct clk_hw *__clk_hw_register_divider(struct device *dev,
0666         struct device_node *np, const char *name,
0667         const char *parent_name, const struct clk_hw *parent_hw,
0668         const struct clk_parent_data *parent_data, unsigned long flags,
0669         void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
0670         const struct clk_div_table *table, spinlock_t *lock);
0671 struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
0672         struct device_node *np, const char *name,
0673         const char *parent_name, const struct clk_hw *parent_hw,
0674         const struct clk_parent_data *parent_data, unsigned long flags,
0675         void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
0676         const struct clk_div_table *table, spinlock_t *lock);
0677 struct clk *clk_register_divider_table(struct device *dev, const char *name,
0678         const char *parent_name, unsigned long flags,
0679         void __iomem *reg, u8 shift, u8 width,
0680         u8 clk_divider_flags, const struct clk_div_table *table,
0681         spinlock_t *lock);
0682 /**
0683  * clk_register_divider - register a divider clock with the clock framework
0684  * @dev: device registering this clock
0685  * @name: name of this clock
0686  * @parent_name: name of clock's parent
0687  * @flags: framework-specific flags
0688  * @reg: register address to adjust divider
0689  * @shift: number of bits to shift the bitfield
0690  * @width: width of the bitfield
0691  * @clk_divider_flags: divider-specific flags for this clock
0692  * @lock: shared register lock for this clock
0693  */
0694 #define clk_register_divider(dev, name, parent_name, flags, reg, shift, width, \
0695                  clk_divider_flags, lock)                  \
0696     clk_register_divider_table((dev), (name), (parent_name), (flags),      \
0697                    (reg), (shift), (width),            \
0698                    (clk_divider_flags), NULL, (lock))
0699 /**
0700  * clk_hw_register_divider - register a divider clock with the clock framework
0701  * @dev: device registering this clock
0702  * @name: name of this clock
0703  * @parent_name: name of clock's parent
0704  * @flags: framework-specific flags
0705  * @reg: register address to adjust divider
0706  * @shift: number of bits to shift the bitfield
0707  * @width: width of the bitfield
0708  * @clk_divider_flags: divider-specific flags for this clock
0709  * @lock: shared register lock for this clock
0710  */
0711 #define clk_hw_register_divider(dev, name, parent_name, flags, reg, shift,    \
0712                 width, clk_divider_flags, lock)           \
0713     __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL,   \
0714                   NULL, (flags), (reg), (shift), (width),     \
0715                   (clk_divider_flags), NULL, (lock))
0716 /**
0717  * clk_hw_register_divider_parent_hw - register a divider clock with the clock
0718  * framework
0719  * @dev: device registering this clock
0720  * @name: name of this clock
0721  * @parent_hw: pointer to parent clk
0722  * @flags: framework-specific flags
0723  * @reg: register address to adjust divider
0724  * @shift: number of bits to shift the bitfield
0725  * @width: width of the bitfield
0726  * @clk_divider_flags: divider-specific flags for this clock
0727  * @lock: shared register lock for this clock
0728  */
0729 #define clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags, reg,   \
0730                       shift, width, clk_divider_flags,    \
0731                       lock)                   \
0732     __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw),     \
0733                   NULL, (flags), (reg), (shift), (width),     \
0734                   (clk_divider_flags), NULL, (lock))
0735 /**
0736  * clk_hw_register_divider_parent_data - register a divider clock with the clock
0737  * framework
0738  * @dev: device registering this clock
0739  * @name: name of this clock
0740  * @parent_data: parent clk data
0741  * @flags: framework-specific flags
0742  * @reg: register address to adjust divider
0743  * @shift: number of bits to shift the bitfield
0744  * @width: width of the bitfield
0745  * @clk_divider_flags: divider-specific flags for this clock
0746  * @lock: shared register lock for this clock
0747  */
0748 #define clk_hw_register_divider_parent_data(dev, name, parent_data, flags,    \
0749                         reg, shift, width,            \
0750                         clk_divider_flags, lock)          \
0751     __clk_hw_register_divider((dev), NULL, (name), NULL, NULL,        \
0752                   (parent_data), (flags), (reg), (shift),     \
0753                   (width), (clk_divider_flags), NULL, (lock))
0754 /**
0755  * clk_hw_register_divider_table - register a table based divider clock with
0756  * the clock framework
0757  * @dev: device registering this clock
0758  * @name: name of this clock
0759  * @parent_name: name of clock's parent
0760  * @flags: framework-specific flags
0761  * @reg: register address to adjust divider
0762  * @shift: number of bits to shift the bitfield
0763  * @width: width of the bitfield
0764  * @clk_divider_flags: divider-specific flags for this clock
0765  * @table: array of divider/value pairs ending with a div set to 0
0766  * @lock: shared register lock for this clock
0767  */
0768 #define clk_hw_register_divider_table(dev, name, parent_name, flags, reg,     \
0769                       shift, width, clk_divider_flags, table, \
0770                       lock)                   \
0771     __clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL,   \
0772                   NULL, (flags), (reg), (shift), (width),     \
0773                   (clk_divider_flags), (table), (lock))
0774 /**
0775  * clk_hw_register_divider_table_parent_hw - register a table based divider
0776  * clock with the clock framework
0777  * @dev: device registering this clock
0778  * @name: name of this clock
0779  * @parent_hw: pointer to parent clk
0780  * @flags: framework-specific flags
0781  * @reg: register address to adjust divider
0782  * @shift: number of bits to shift the bitfield
0783  * @width: width of the bitfield
0784  * @clk_divider_flags: divider-specific flags for this clock
0785  * @table: array of divider/value pairs ending with a div set to 0
0786  * @lock: shared register lock for this clock
0787  */
0788 #define clk_hw_register_divider_table_parent_hw(dev, name, parent_hw, flags,  \
0789                         reg, shift, width,        \
0790                         clk_divider_flags, table,     \
0791                         lock)                 \
0792     __clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw),     \
0793                   NULL, (flags), (reg), (shift), (width),     \
0794                   (clk_divider_flags), (table), (lock))
0795 /**
0796  * clk_hw_register_divider_table_parent_data - register a table based divider
0797  * clock with the clock framework
0798  * @dev: device registering this clock
0799  * @name: name of this clock
0800  * @parent_data: parent clk data
0801  * @flags: framework-specific flags
0802  * @reg: register address to adjust divider
0803  * @shift: number of bits to shift the bitfield
0804  * @width: width of the bitfield
0805  * @clk_divider_flags: divider-specific flags for this clock
0806  * @table: array of divider/value pairs ending with a div set to 0
0807  * @lock: shared register lock for this clock
0808  */
0809 #define clk_hw_register_divider_table_parent_data(dev, name, parent_data,     \
0810                           flags, reg, shift, width,   \
0811                           clk_divider_flags, table,   \
0812                           lock)               \
0813     __clk_hw_register_divider((dev), NULL, (name), NULL, NULL,        \
0814                   (parent_data), (flags), (reg), (shift),     \
0815                   (width), (clk_divider_flags), (table),      \
0816                   (lock))
0817 /**
0818  * devm_clk_hw_register_divider - register a divider clock with the clock framework
0819  * @dev: device registering this clock
0820  * @name: name of this clock
0821  * @parent_name: name of clock's parent
0822  * @flags: framework-specific flags
0823  * @reg: register address to adjust divider
0824  * @shift: number of bits to shift the bitfield
0825  * @width: width of the bitfield
0826  * @clk_divider_flags: divider-specific flags for this clock
0827  * @lock: shared register lock for this clock
0828  */
0829 #define devm_clk_hw_register_divider(dev, name, parent_name, flags, reg, shift,    \
0830                 width, clk_divider_flags, lock)           \
0831     __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), NULL,   \
0832                   NULL, (flags), (reg), (shift), (width),     \
0833                   (clk_divider_flags), NULL, (lock))
0834 /**
0835  * devm_clk_hw_register_divider_parent_hw - register a divider clock with the clock framework
0836  * @dev: device registering this clock
0837  * @name: name of this clock
0838  * @parent_hw: pointer to parent clk
0839  * @flags: framework-specific flags
0840  * @reg: register address to adjust divider
0841  * @shift: number of bits to shift the bitfield
0842  * @width: width of the bitfield
0843  * @clk_divider_flags: divider-specific flags for this clock
0844  * @lock: shared register lock for this clock
0845  */
0846 #define devm_clk_hw_register_divider_parent_hw(dev, name, parent_hw, flags,   \
0847                            reg, shift, width,         \
0848                            clk_divider_flags, lock)       \
0849     __devm_clk_hw_register_divider((dev), NULL, (name), NULL,         \
0850                        (parent_hw), NULL, (flags), (reg),     \
0851                        (shift), (width), (clk_divider_flags), \
0852                        NULL, (lock))
0853 /**
0854  * devm_clk_hw_register_divider_table - register a table based divider clock
0855  * with the clock framework (devres variant)
0856  * @dev: device registering this clock
0857  * @name: name of this clock
0858  * @parent_name: name of clock's parent
0859  * @flags: framework-specific flags
0860  * @reg: register address to adjust divider
0861  * @shift: number of bits to shift the bitfield
0862  * @width: width of the bitfield
0863  * @clk_divider_flags: divider-specific flags for this clock
0864  * @table: array of divider/value pairs ending with a div set to 0
0865  * @lock: shared register lock for this clock
0866  */
0867 #define devm_clk_hw_register_divider_table(dev, name, parent_name, flags,     \
0868                        reg, shift, width,             \
0869                        clk_divider_flags, table, lock)    \
0870     __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name),    \
0871                        NULL, NULL, (flags), (reg), (shift),   \
0872                        (width), (clk_divider_flags), (table), \
0873                        (lock))
0874 
0875 void clk_unregister_divider(struct clk *clk);
0876 void clk_hw_unregister_divider(struct clk_hw *hw);
0877 
0878 /**
0879  * struct clk_mux - multiplexer clock
0880  *
0881  * @hw:     handle between common and hardware-specific interfaces
0882  * @reg:    register controlling multiplexer
0883  * @table:  array of register values corresponding to the parent index
0884  * @shift:  shift to multiplexer bit field
0885  * @mask:   mask of mutliplexer bit field
0886  * @flags:  hardware-specific flags
0887  * @lock:   register lock
0888  *
0889  * Clock with multiple selectable parents.  Implements .get_parent, .set_parent
0890  * and .recalc_rate
0891  *
0892  * Flags:
0893  * CLK_MUX_INDEX_ONE - register index starts at 1, not 0
0894  * CLK_MUX_INDEX_BIT - register index is a single bit (power of two)
0895  * CLK_MUX_HIWORD_MASK - The mux settings are only in lower 16-bit of this
0896  *  register, and mask of mux bits are in higher 16-bit of this register.
0897  *  While setting the mux bits, higher 16-bit should also be updated to
0898  *  indicate changing mux bits.
0899  * CLK_MUX_READ_ONLY - The mux registers can't be written, only read in the
0900  *  .get_parent clk_op.
0901  * CLK_MUX_ROUND_CLOSEST - Use the parent rate that is closest to the desired
0902  *  frequency.
0903  * CLK_MUX_BIG_ENDIAN - By default little endian register accesses are used for
0904  *  the mux register.  Setting this flag makes the register accesses big
0905  *  endian.
0906  */
0907 struct clk_mux {
0908     struct clk_hw   hw;
0909     void __iomem    *reg;
0910     const u32   *table;
0911     u32     mask;
0912     u8      shift;
0913     u8      flags;
0914     spinlock_t  *lock;
0915 };
0916 
0917 #define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
0918 
0919 #define CLK_MUX_INDEX_ONE       BIT(0)
0920 #define CLK_MUX_INDEX_BIT       BIT(1)
0921 #define CLK_MUX_HIWORD_MASK     BIT(2)
0922 #define CLK_MUX_READ_ONLY       BIT(3) /* mux can't be changed */
0923 #define CLK_MUX_ROUND_CLOSEST       BIT(4)
0924 #define CLK_MUX_BIG_ENDIAN      BIT(5)
0925 
0926 extern const struct clk_ops clk_mux_ops;
0927 extern const struct clk_ops clk_mux_ro_ops;
0928 
0929 struct clk_hw *__clk_hw_register_mux(struct device *dev, struct device_node *np,
0930         const char *name, u8 num_parents,
0931         const char * const *parent_names,
0932         const struct clk_hw **parent_hws,
0933         const struct clk_parent_data *parent_data,
0934         unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
0935         u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
0936 struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct device_node *np,
0937         const char *name, u8 num_parents,
0938         const char * const *parent_names,
0939         const struct clk_hw **parent_hws,
0940         const struct clk_parent_data *parent_data,
0941         unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
0942         u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
0943 struct clk *clk_register_mux_table(struct device *dev, const char *name,
0944         const char * const *parent_names, u8 num_parents,
0945         unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
0946         u8 clk_mux_flags, const u32 *table, spinlock_t *lock);
0947 
0948 #define clk_register_mux(dev, name, parent_names, num_parents, flags, reg,    \
0949              shift, width, clk_mux_flags, lock)           \
0950     clk_register_mux_table((dev), (name), (parent_names), (num_parents),  \
0951                    (flags), (reg), (shift), BIT((width)) - 1,     \
0952                    (clk_mux_flags), NULL, (lock))
0953 #define clk_hw_register_mux_table(dev, name, parent_names, num_parents,       \
0954                   flags, reg, shift, mask, clk_mux_flags,     \
0955                   table, lock)                    \
0956     __clk_hw_register_mux((dev), NULL, (name), (num_parents),         \
0957                   (parent_names), NULL, NULL, (flags), (reg),     \
0958                   (shift), (mask), (clk_mux_flags), (table),      \
0959                   (lock))
0960 #define clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
0961                 shift, width, clk_mux_flags, lock)            \
0962     __clk_hw_register_mux((dev), NULL, (name), (num_parents),         \
0963                   (parent_names), NULL, NULL, (flags), (reg),     \
0964                   (shift), BIT((width)) - 1, (clk_mux_flags),     \
0965                   NULL, (lock))
0966 #define clk_hw_register_mux_hws(dev, name, parent_hws, num_parents, flags,    \
0967                 reg, shift, width, clk_mux_flags, lock)       \
0968     __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL,       \
0969                   (parent_hws), NULL, (flags), (reg), (shift),    \
0970                   BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
0971 #define clk_hw_register_mux_parent_data(dev, name, parent_data, num_parents,  \
0972                     flags, reg, shift, width,         \
0973                     clk_mux_flags, lock)              \
0974     __clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
0975                   (parent_data), (flags), (reg), (shift),         \
0976                   BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
0977 #define devm_clk_hw_register_mux(dev, name, parent_names, num_parents, flags, reg, \
0978                 shift, width, clk_mux_flags, lock)            \
0979     __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents),        \
0980                   (parent_names), NULL, NULL, (flags), (reg),     \
0981                   (shift), BIT((width)) - 1, (clk_mux_flags),     \
0982                   NULL, (lock))
0983 #define devm_clk_hw_register_mux_parent_hws(dev, name, parent_hws,        \
0984                         num_parents, flags, reg, shift,   \
0985                         width, clk_mux_flags, lock)       \
0986     __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL,  \
0987                    (parent_hws), NULL, (flags), (reg),        \
0988                    (shift), BIT((width)) - 1,             \
0989                    (clk_mux_flags), NULL, (lock))
0990 
0991 int clk_mux_val_to_index(struct clk_hw *hw, const u32 *table, unsigned int flags,
0992              unsigned int val);
0993 unsigned int clk_mux_index_to_val(const u32 *table, unsigned int flags, u8 index);
0994 
0995 void clk_unregister_mux(struct clk *clk);
0996 void clk_hw_unregister_mux(struct clk_hw *hw);
0997 
0998 void of_fixed_factor_clk_setup(struct device_node *node);
0999 
1000 /**
1001  * struct clk_fixed_factor - fixed multiplier and divider clock
1002  *
1003  * @hw:     handle between common and hardware-specific interfaces
1004  * @mult:   multiplier
1005  * @div:    divider
1006  *
1007  * Clock with a fixed multiplier and divider. The output frequency is the
1008  * parent clock rate divided by div and multiplied by mult.
1009  * Implements .recalc_rate, .set_rate and .round_rate
1010  */
1011 
1012 struct clk_fixed_factor {
1013     struct clk_hw   hw;
1014     unsigned int    mult;
1015     unsigned int    div;
1016 };
1017 
1018 #define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw)
1019 
1020 extern const struct clk_ops clk_fixed_factor_ops;
1021 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
1022         const char *parent_name, unsigned long flags,
1023         unsigned int mult, unsigned int div);
1024 void clk_unregister_fixed_factor(struct clk *clk);
1025 struct clk_hw *clk_hw_register_fixed_factor(struct device *dev,
1026         const char *name, const char *parent_name, unsigned long flags,
1027         unsigned int mult, unsigned int div);
1028 void clk_hw_unregister_fixed_factor(struct clk_hw *hw);
1029 struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev,
1030         const char *name, const char *parent_name, unsigned long flags,
1031         unsigned int mult, unsigned int div);
1032 struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev,
1033         const char *name, unsigned int index, unsigned long flags,
1034         unsigned int mult, unsigned int div);
1035 
1036 struct clk_hw *devm_clk_hw_register_fixed_factor_parent_hw(struct device *dev,
1037         const char *name, const struct clk_hw *parent_hw,
1038         unsigned long flags, unsigned int mult, unsigned int div);
1039 
1040 struct clk_hw *clk_hw_register_fixed_factor_parent_hw(struct device *dev,
1041         const char *name, const struct clk_hw *parent_hw,
1042         unsigned long flags, unsigned int mult, unsigned int div);
1043 /**
1044  * struct clk_fractional_divider - adjustable fractional divider clock
1045  *
1046  * @hw:     handle between common and hardware-specific interfaces
1047  * @reg:    register containing the divider
1048  * @mshift: shift to the numerator bit field
1049  * @mwidth: width of the numerator bit field
1050  * @nshift: shift to the denominator bit field
1051  * @nwidth: width of the denominator bit field
1052  * @lock:   register lock
1053  *
1054  * Clock with adjustable fractional divider affecting its output frequency.
1055  *
1056  * Flags:
1057  * CLK_FRAC_DIVIDER_ZERO_BASED - by default the numerator and denominator
1058  *  is the value read from the register. If CLK_FRAC_DIVIDER_ZERO_BASED
1059  *  is set then the numerator and denominator are both the value read
1060  *  plus one.
1061  * CLK_FRAC_DIVIDER_BIG_ENDIAN - By default little endian register accesses are
1062  *  used for the divider register.  Setting this flag makes the register
1063  *  accesses big endian.
1064  * CLK_FRAC_DIVIDER_POWER_OF_TWO_PS - By default the resulting fraction might
1065  *  be saturated and the caller will get quite far from the good enough
1066  *  approximation. Instead the caller may require, by setting this flag,
1067  *  to shift left by a few bits in case, when the asked one is quite small
1068  *  to satisfy the desired range of denominator. It assumes that on the
1069  *  caller's side the power-of-two capable prescaler exists.
1070  */
1071 struct clk_fractional_divider {
1072     struct clk_hw   hw;
1073     void __iomem    *reg;
1074     u8      mshift;
1075     u8      mwidth;
1076     u32     mmask;
1077     u8      nshift;
1078     u8      nwidth;
1079     u32     nmask;
1080     u8      flags;
1081     void        (*approximation)(struct clk_hw *hw,
1082                 unsigned long rate, unsigned long *parent_rate,
1083                 unsigned long *m, unsigned long *n);
1084     spinlock_t  *lock;
1085 };
1086 
1087 #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
1088 
1089 #define CLK_FRAC_DIVIDER_ZERO_BASED     BIT(0)
1090 #define CLK_FRAC_DIVIDER_BIG_ENDIAN     BIT(1)
1091 #define CLK_FRAC_DIVIDER_POWER_OF_TWO_PS    BIT(2)
1092 
1093 struct clk *clk_register_fractional_divider(struct device *dev,
1094         const char *name, const char *parent_name, unsigned long flags,
1095         void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1096         u8 clk_divider_flags, spinlock_t *lock);
1097 struct clk_hw *clk_hw_register_fractional_divider(struct device *dev,
1098         const char *name, const char *parent_name, unsigned long flags,
1099         void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth,
1100         u8 clk_divider_flags, spinlock_t *lock);
1101 void clk_hw_unregister_fractional_divider(struct clk_hw *hw);
1102 
1103 /**
1104  * struct clk_multiplier - adjustable multiplier clock
1105  *
1106  * @hw:     handle between common and hardware-specific interfaces
1107  * @reg:    register containing the multiplier
1108  * @shift:  shift to the multiplier bit field
1109  * @width:  width of the multiplier bit field
1110  * @lock:   register lock
1111  *
1112  * Clock with an adjustable multiplier affecting its output frequency.
1113  * Implements .recalc_rate, .set_rate and .round_rate
1114  *
1115  * Flags:
1116  * CLK_MULTIPLIER_ZERO_BYPASS - By default, the multiplier is the value read
1117  *  from the register, with 0 being a valid value effectively
1118  *  zeroing the output clock rate. If CLK_MULTIPLIER_ZERO_BYPASS is
1119  *  set, then a null multiplier will be considered as a bypass,
1120  *  leaving the parent rate unmodified.
1121  * CLK_MULTIPLIER_ROUND_CLOSEST - Makes the best calculated divider to be
1122  *  rounded to the closest integer instead of the down one.
1123  * CLK_MULTIPLIER_BIG_ENDIAN - By default little endian register accesses are
1124  *  used for the multiplier register.  Setting this flag makes the register
1125  *  accesses big endian.
1126  */
1127 struct clk_multiplier {
1128     struct clk_hw   hw;
1129     void __iomem    *reg;
1130     u8      shift;
1131     u8      width;
1132     u8      flags;
1133     spinlock_t  *lock;
1134 };
1135 
1136 #define to_clk_multiplier(_hw) container_of(_hw, struct clk_multiplier, hw)
1137 
1138 #define CLK_MULTIPLIER_ZERO_BYPASS  BIT(0)
1139 #define CLK_MULTIPLIER_ROUND_CLOSEST    BIT(1)
1140 #define CLK_MULTIPLIER_BIG_ENDIAN   BIT(2)
1141 
1142 extern const struct clk_ops clk_multiplier_ops;
1143 
1144 /***
1145  * struct clk_composite - aggregate clock of mux, divider and gate clocks
1146  *
1147  * @hw:     handle between common and hardware-specific interfaces
1148  * @mux_hw: handle between composite and hardware-specific mux clock
1149  * @rate_hw:    handle between composite and hardware-specific rate clock
1150  * @gate_hw:    handle between composite and hardware-specific gate clock
1151  * @mux_ops:    clock ops for mux
1152  * @rate_ops:   clock ops for rate
1153  * @gate_ops:   clock ops for gate
1154  */
1155 struct clk_composite {
1156     struct clk_hw   hw;
1157     struct clk_ops  ops;
1158 
1159     struct clk_hw   *mux_hw;
1160     struct clk_hw   *rate_hw;
1161     struct clk_hw   *gate_hw;
1162 
1163     const struct clk_ops    *mux_ops;
1164     const struct clk_ops    *rate_ops;
1165     const struct clk_ops    *gate_ops;
1166 };
1167 
1168 #define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
1169 
1170 struct clk *clk_register_composite(struct device *dev, const char *name,
1171         const char * const *parent_names, int num_parents,
1172         struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1173         struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1174         struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1175         unsigned long flags);
1176 struct clk *clk_register_composite_pdata(struct device *dev, const char *name,
1177         const struct clk_parent_data *parent_data, int num_parents,
1178         struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1179         struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1180         struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1181         unsigned long flags);
1182 void clk_unregister_composite(struct clk *clk);
1183 struct clk_hw *clk_hw_register_composite(struct device *dev, const char *name,
1184         const char * const *parent_names, int num_parents,
1185         struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1186         struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1187         struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1188         unsigned long flags);
1189 struct clk_hw *clk_hw_register_composite_pdata(struct device *dev,
1190         const char *name,
1191         const struct clk_parent_data *parent_data, int num_parents,
1192         struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1193         struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1194         struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1195         unsigned long flags);
1196 struct clk_hw *devm_clk_hw_register_composite_pdata(struct device *dev,
1197         const char *name, const struct clk_parent_data *parent_data,
1198         int num_parents,
1199         struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
1200         struct clk_hw *rate_hw, const struct clk_ops *rate_ops,
1201         struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
1202         unsigned long flags);
1203 void clk_hw_unregister_composite(struct clk_hw *hw);
1204 
1205 struct clk *clk_register(struct device *dev, struct clk_hw *hw);
1206 struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw);
1207 
1208 int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw);
1209 int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw);
1210 int __must_check of_clk_hw_register(struct device_node *node, struct clk_hw *hw);
1211 
1212 void clk_unregister(struct clk *clk);
1213 
1214 void clk_hw_unregister(struct clk_hw *hw);
1215 
1216 /* helper functions */
1217 const char *__clk_get_name(const struct clk *clk);
1218 const char *clk_hw_get_name(const struct clk_hw *hw);
1219 #ifdef CONFIG_COMMON_CLK
1220 struct clk_hw *__clk_get_hw(struct clk *clk);
1221 #else
1222 static inline struct clk_hw *__clk_get_hw(struct clk *clk)
1223 {
1224     return (struct clk_hw *)clk;
1225 }
1226 #endif
1227 
1228 struct clk *clk_hw_get_clk(struct clk_hw *hw, const char *con_id);
1229 struct clk *devm_clk_hw_get_clk(struct device *dev, struct clk_hw *hw,
1230                 const char *con_id);
1231 
1232 unsigned int clk_hw_get_num_parents(const struct clk_hw *hw);
1233 struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw);
1234 struct clk_hw *clk_hw_get_parent_by_index(const struct clk_hw *hw,
1235                       unsigned int index);
1236 int clk_hw_get_parent_index(struct clk_hw *hw);
1237 int clk_hw_set_parent(struct clk_hw *hw, struct clk_hw *new_parent);
1238 unsigned int __clk_get_enable_count(struct clk *clk);
1239 unsigned long clk_hw_get_rate(const struct clk_hw *hw);
1240 unsigned long clk_hw_get_flags(const struct clk_hw *hw);
1241 #define clk_hw_can_set_rate_parent(hw) \
1242     (clk_hw_get_flags((hw)) & CLK_SET_RATE_PARENT)
1243 
1244 bool clk_hw_is_prepared(const struct clk_hw *hw);
1245 bool clk_hw_rate_is_protected(const struct clk_hw *hw);
1246 bool clk_hw_is_enabled(const struct clk_hw *hw);
1247 bool __clk_is_enabled(struct clk *clk);
1248 struct clk *__clk_lookup(const char *name);
1249 int __clk_mux_determine_rate(struct clk_hw *hw,
1250                  struct clk_rate_request *req);
1251 int __clk_determine_rate(struct clk_hw *core, struct clk_rate_request *req);
1252 int __clk_mux_determine_rate_closest(struct clk_hw *hw,
1253                      struct clk_rate_request *req);
1254 int clk_mux_determine_rate_flags(struct clk_hw *hw,
1255                  struct clk_rate_request *req,
1256                  unsigned long flags);
1257 void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent);
1258 void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate,
1259                unsigned long max_rate);
1260 
1261 static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src)
1262 {
1263     dst->clk = src->clk;
1264     dst->core = src->core;
1265 }
1266 
1267 static inline long divider_round_rate(struct clk_hw *hw, unsigned long rate,
1268                       unsigned long *prate,
1269                       const struct clk_div_table *table,
1270                       u8 width, unsigned long flags)
1271 {
1272     return divider_round_rate_parent(hw, clk_hw_get_parent(hw),
1273                      rate, prate, table, width, flags);
1274 }
1275 
1276 static inline long divider_ro_round_rate(struct clk_hw *hw, unsigned long rate,
1277                      unsigned long *prate,
1278                      const struct clk_div_table *table,
1279                      u8 width, unsigned long flags,
1280                      unsigned int val)
1281 {
1282     return divider_ro_round_rate_parent(hw, clk_hw_get_parent(hw),
1283                         rate, prate, table, width, flags,
1284                         val);
1285 }
1286 
1287 /*
1288  * FIXME clock api without lock protection
1289  */
1290 unsigned long clk_hw_round_rate(struct clk_hw *hw, unsigned long rate);
1291 
1292 struct clk_onecell_data {
1293     struct clk **clks;
1294     unsigned int clk_num;
1295 };
1296 
1297 struct clk_hw_onecell_data {
1298     unsigned int num;
1299     struct clk_hw *hws[];
1300 };
1301 
1302 #define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
1303 
1304 /*
1305  * Use this macro when you have a driver that requires two initialization
1306  * routines, one at of_clk_init(), and one at platform device probe
1307  */
1308 #define CLK_OF_DECLARE_DRIVER(name, compat, fn) \
1309     static void __init name##_of_clk_init_driver(struct device_node *np) \
1310     {                               \
1311         of_node_clear_flag(np, OF_POPULATED);           \
1312         fn(np);                         \
1313     }                               \
1314     OF_DECLARE_1(clk, name, compat, name##_of_clk_init_driver)
1315 
1316 #define CLK_HW_INIT(_name, _parent, _ops, _flags)       \
1317     (&(struct clk_init_data) {              \
1318         .flags      = _flags,           \
1319         .name       = _name,            \
1320         .parent_names   = (const char *[]) { _parent }, \
1321         .num_parents    = 1,                \
1322         .ops        = _ops,             \
1323     })
1324 
1325 #define CLK_HW_INIT_HW(_name, _parent, _ops, _flags)            \
1326     (&(struct clk_init_data) {                  \
1327         .flags      = _flags,               \
1328         .name       = _name,                \
1329         .parent_hws = (const struct clk_hw*[]) { _parent }, \
1330         .num_parents    = 1,                    \
1331         .ops        = _ops,                 \
1332     })
1333 
1334 /*
1335  * This macro is intended for drivers to be able to share the otherwise
1336  * individual struct clk_hw[] compound literals created by the compiler
1337  * when using CLK_HW_INIT_HW. It does NOT support multiple parents.
1338  */
1339 #define CLK_HW_INIT_HWS(_name, _parent, _ops, _flags)           \
1340     (&(struct clk_init_data) {                  \
1341         .flags      = _flags,               \
1342         .name       = _name,                \
1343         .parent_hws = _parent,              \
1344         .num_parents    = 1,                    \
1345         .ops        = _ops,                 \
1346     })
1347 
1348 #define CLK_HW_INIT_FW_NAME(_name, _parent, _ops, _flags)       \
1349     (&(struct clk_init_data) {                  \
1350         .flags      = _flags,               \
1351         .name       = _name,                \
1352         .parent_data    = (const struct clk_parent_data[]) {    \
1353                     { .fw_name = _parent },     \
1354                   },                    \
1355         .num_parents    = 1,                    \
1356         .ops        = _ops,                 \
1357     })
1358 
1359 #define CLK_HW_INIT_PARENTS(_name, _parents, _ops, _flags)  \
1360     (&(struct clk_init_data) {              \
1361         .flags      = _flags,           \
1362         .name       = _name,            \
1363         .parent_names   = _parents,         \
1364         .num_parents    = ARRAY_SIZE(_parents),     \
1365         .ops        = _ops,             \
1366     })
1367 
1368 #define CLK_HW_INIT_PARENTS_HW(_name, _parents, _ops, _flags)   \
1369     (&(struct clk_init_data) {              \
1370         .flags      = _flags,           \
1371         .name       = _name,            \
1372         .parent_hws = _parents,         \
1373         .num_parents    = ARRAY_SIZE(_parents),     \
1374         .ops        = _ops,             \
1375     })
1376 
1377 #define CLK_HW_INIT_PARENTS_DATA(_name, _parents, _ops, _flags) \
1378     (&(struct clk_init_data) {              \
1379         .flags      = _flags,           \
1380         .name       = _name,            \
1381         .parent_data    = _parents,         \
1382         .num_parents    = ARRAY_SIZE(_parents),     \
1383         .ops        = _ops,             \
1384     })
1385 
1386 #define CLK_HW_INIT_NO_PARENT(_name, _ops, _flags)  \
1387     (&(struct clk_init_data) {          \
1388         .flags          = _flags,       \
1389         .name           = _name,        \
1390         .parent_names   = NULL,         \
1391         .num_parents    = 0,            \
1392         .ops            = _ops,         \
1393     })
1394 
1395 #define CLK_FIXED_FACTOR(_struct, _name, _parent,           \
1396             _div, _mult, _flags)                \
1397     struct clk_fixed_factor _struct = {             \
1398         .div        = _div,                 \
1399         .mult       = _mult,                \
1400         .hw.init    = CLK_HW_INIT(_name,            \
1401                           _parent,          \
1402                           &clk_fixed_factor_ops,    \
1403                           _flags),          \
1404     }
1405 
1406 #define CLK_FIXED_FACTOR_HW(_struct, _name, _parent,            \
1407                 _div, _mult, _flags)            \
1408     struct clk_fixed_factor _struct = {             \
1409         .div        = _div,                 \
1410         .mult       = _mult,                \
1411         .hw.init    = CLK_HW_INIT_HW(_name,         \
1412                          _parent,       \
1413                          &clk_fixed_factor_ops, \
1414                          _flags),       \
1415     }
1416 
1417 /*
1418  * This macro allows the driver to reuse the _parent array for multiple
1419  * fixed factor clk declarations.
1420  */
1421 #define CLK_FIXED_FACTOR_HWS(_struct, _name, _parent,           \
1422                  _div, _mult, _flags)           \
1423     struct clk_fixed_factor _struct = {             \
1424         .div        = _div,                 \
1425         .mult       = _mult,                \
1426         .hw.init    = CLK_HW_INIT_HWS(_name,        \
1427                           _parent,      \
1428                           &clk_fixed_factor_ops, \
1429                           _flags),  \
1430     }
1431 
1432 #define CLK_FIXED_FACTOR_FW_NAME(_struct, _name, _parent,       \
1433                  _div, _mult, _flags)           \
1434     struct clk_fixed_factor _struct = {             \
1435         .div        = _div,                 \
1436         .mult       = _mult,                \
1437         .hw.init    = CLK_HW_INIT_FW_NAME(_name,        \
1438                               _parent,      \
1439                               &clk_fixed_factor_ops, \
1440                               _flags),      \
1441     }
1442 
1443 #ifdef CONFIG_OF
1444 int of_clk_add_provider(struct device_node *np,
1445             struct clk *(*clk_src_get)(struct of_phandle_args *args,
1446                            void *data),
1447             void *data);
1448 int of_clk_add_hw_provider(struct device_node *np,
1449                struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1450                          void *data),
1451                void *data);
1452 int devm_of_clk_add_hw_provider(struct device *dev,
1453                struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1454                          void *data),
1455                void *data);
1456 void of_clk_del_provider(struct device_node *np);
1457 void devm_of_clk_del_provider(struct device *dev);
1458 struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
1459                   void *data);
1460 struct clk_hw *of_clk_hw_simple_get(struct of_phandle_args *clkspec,
1461                     void *data);
1462 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
1463 struct clk_hw *of_clk_hw_onecell_get(struct of_phandle_args *clkspec,
1464                      void *data);
1465 int of_clk_parent_fill(struct device_node *np, const char **parents,
1466                unsigned int size);
1467 int of_clk_detect_critical(struct device_node *np, int index,
1468                 unsigned long *flags);
1469 
1470 #else /* !CONFIG_OF */
1471 
1472 static inline int of_clk_add_provider(struct device_node *np,
1473             struct clk *(*clk_src_get)(struct of_phandle_args *args,
1474                            void *data),
1475             void *data)
1476 {
1477     return 0;
1478 }
1479 static inline int of_clk_add_hw_provider(struct device_node *np,
1480             struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1481                           void *data),
1482             void *data)
1483 {
1484     return 0;
1485 }
1486 static inline int devm_of_clk_add_hw_provider(struct device *dev,
1487                struct clk_hw *(*get)(struct of_phandle_args *clkspec,
1488                          void *data),
1489                void *data)
1490 {
1491     return 0;
1492 }
1493 static inline void of_clk_del_provider(struct device_node *np) {}
1494 static inline void devm_of_clk_del_provider(struct device *dev) {}
1495 static inline struct clk *of_clk_src_simple_get(
1496     struct of_phandle_args *clkspec, void *data)
1497 {
1498     return ERR_PTR(-ENOENT);
1499 }
1500 static inline struct clk_hw *
1501 of_clk_hw_simple_get(struct of_phandle_args *clkspec, void *data)
1502 {
1503     return ERR_PTR(-ENOENT);
1504 }
1505 static inline struct clk *of_clk_src_onecell_get(
1506     struct of_phandle_args *clkspec, void *data)
1507 {
1508     return ERR_PTR(-ENOENT);
1509 }
1510 static inline struct clk_hw *
1511 of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
1512 {
1513     return ERR_PTR(-ENOENT);
1514 }
1515 static inline int of_clk_parent_fill(struct device_node *np,
1516                      const char **parents, unsigned int size)
1517 {
1518     return 0;
1519 }
1520 static inline int of_clk_detect_critical(struct device_node *np, int index,
1521                       unsigned long *flags)
1522 {
1523     return 0;
1524 }
1525 #endif /* CONFIG_OF */
1526 
1527 void clk_gate_restore_context(struct clk_hw *hw);
1528 
1529 #endif /* CLK_PROVIDER_H */