Merge tag 'char-misc-3.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregk...
[cascardo/linux.git] / include / linux / clk-provider.h
index fb4eca6..411dd7e 100644 (file)
@@ -40,14 +40,14 @@ struct dentry;
  * through the clk_* api.
  *
  * @prepare:   Prepare the clock for enabling. This must not return until
- *             the clock is fully prepared, and it's safe to call clk_enable.
- *             This callback is intended to allow clock implementations to
- *             do any initialisation that may sleep. Called with
- *             prepare_lock held.
+ *             the clock is fully prepared, and it's safe to call clk_enable.
+ *             This callback is intended to allow clock implementations to
+ *             do any initialisation that may sleep. Called with
+ *             prepare_lock held.
  *
  * @unprepare: Release the clock from its prepared state. This will typically
- *             undo any work done in the @prepare callback. Called with
- *             prepare_lock held.
+ *             undo any work done in the @prepare callback. Called with
+ *             prepare_lock held.
  *
  * @is_prepared: Queries the hardware to determine if the clock is prepared.
  *             This function is allowed to sleep. Optional, if this op is not
@@ -58,16 +58,16 @@ struct dentry;
  *             Called with prepare mutex held. This function may sleep.
  *
  * @enable:    Enable the clock atomically. This must not return until the
- *             clock is generating a valid clock signal, usable by consumer
- *             devices. Called with enable_lock held. This function must not
- *             sleep.
+ *             clock is generating a valid clock signal, usable by consumer
+ *             devices. Called with enable_lock held. This function must not
+ *             sleep.
  *
  * @disable:   Disable the clock atomically. Called with enable_lock held.
- *             This function must not sleep.
+ *             This function must not sleep.
  *
  * @is_enabled:        Queries the hardware to determine if the clock is enabled.
- *             This function must not sleep. Optional, if this op is not
- *             set then the enable count will be used.
+ *             This function must not sleep. Optional, if this op is not
+ *             set then the enable count will be used.
  *
  * @disable_unused: Disable the clock atomically.  Only called from
  *             clk_disable_unused for gate clocks with special needs.
@@ -75,34 +75,35 @@ struct dentry;
  *             sleep.
  *
  * @recalc_rate        Recalculate the rate of this clock, by querying hardware. The
- *             parent rate is an input parameter.  It is up to the caller to
- *             ensure that the prepare_mutex is held across this call.
- *             Returns the calculated rate.  Optional, but recommended - if
- *             this op is not set then clock rate will be initialized to 0.
+ *             parent rate is an input parameter.  It is up to the caller to
+ *             ensure that the prepare_mutex is held across this call.
+ *             Returns the calculated rate.  Optional, but recommended - if
+ *             this op is not set then clock rate will be initialized to 0.
  *
  * @round_rate:        Given a target rate as input, returns the closest rate actually
- *             supported by the clock.
+ *             supported by the clock. The parent rate is an input/output
+ *             parameter.
  *
  * @determine_rate: Given a target rate as input, returns the closest rate
  *             actually supported by the clock, and optionally the parent clock
  *             that should be used to provide the clock rate.
  *
- * @get_parent:        Queries the hardware to determine the parent of a clock.  The
- *             return value is a u8 which specifies the index corresponding to
- *             the parent clock.  This index can be applied to either the
- *             .parent_names or .parents arrays.  In short, this function
- *             translates the parent value read from hardware into an array
- *             index.  Currently only called when the clock is initialized by
- *             __clk_init.  This callback is mandatory for clocks with
- *             multiple parents.  It is optional (and unnecessary) for clocks
- *             with 0 or 1 parents.
- *
  * @set_parent:        Change the input source of this clock; for clocks with multiple
- *             possible parents specify a new parent by passing in the index
- *             as a u8 corresponding to the parent in either the .parent_names
- *             or .parents arrays.  This function in affect translates an
- *             array index into the value programmed into the hardware.
- *             Returns 0 on success, -EERROR otherwise.
+ *             possible parents specify a new parent by passing in the index
+ *             as a u8 corresponding to the parent in either the .parent_names
+ *             or .parents arrays.  This function in affect translates an
+ *             array index into the value programmed into the hardware.
+ *             Returns 0 on success, -EERROR otherwise.
+ *
+ * @get_parent:        Queries the hardware to determine the parent of a clock.  The
+ *             return value is a u8 which specifies the index corresponding to
+ *             the parent clock.  This index can be applied to either the
+ *             .parent_names or .parents arrays.  In short, this function
+ *             translates the parent value read from hardware into an array
+ *             index.  Currently only called when the clock is initialized by
+ *             __clk_init.  This callback is mandatory for clocks with
+ *             multiple parents.  It is optional (and unnecessary) for clocks
+ *             with 0 or 1 parents.
  *
  * @set_rate:  Change the rate of this clock. The requested rate is specified
  *             by the second argument, which should typically be the return
@@ -110,13 +111,6 @@ struct dentry;
  *             which is likely helpful for most .set_rate implementation.
  *             Returns 0 on success, -EERROR otherwise.
  *
- * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy
- *             is expressed in ppb (parts per billion). The parent accuracy is
- *             an input parameter.
- *             Returns the calculated accuracy.  Optional - if this op is not
- *             set then clock accuracy will be initialized to parent accuracy
- *             or 0 (perfect clock) if clock has no parent.
- *
  * @set_rate_and_parent: Change the rate and the parent of this clock. The
  *             requested rate is specified by the second argument, which
  *             should typically be the return of .round_rate call.  The
@@ -128,6 +122,18 @@ struct dentry;
  *             separately via calls to .set_parent and .set_rate.
  *             Returns 0 on success, -EERROR otherwise.
  *
+ * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy
+ *             is expressed in ppb (parts per billion). The parent accuracy is
+ *             an input parameter.
+ *             Returns the calculated accuracy.  Optional - if this op is not
+ *             set then clock accuracy will be initialized to parent accuracy
+ *             or 0 (perfect clock) if clock has no parent.
+ *
+ * @init:      Perform platform-specific initialization magic.
+ *             This is not not used by any of the basic clock types.
+ *             Please consider other ways of solving initialization problems
+ *             before using this callback, as its use is discouraged.
+ *
  * @debug_init:        Set up type-specific debugfs entries for this clock.  This
  *             is called once, after the debugfs directory entry for this
  *             clock has been created.  The dentry pointer representing that
@@ -157,15 +163,15 @@ struct clk_ops {
        void            (*disable_unused)(struct clk_hw *hw);
        unsigned long   (*recalc_rate)(struct clk_hw *hw,
                                        unsigned long parent_rate);
-       long            (*round_rate)(struct clk_hw *hw, unsigned long,
-                                       unsigned long *);
+       long            (*round_rate)(struct clk_hw *hw, unsigned long rate,
+                                       unsigned long *parent_rate);
        long            (*determine_rate)(struct clk_hw *hw, unsigned long rate,
                                        unsigned long *best_parent_rate,
                                        struct clk **best_parent_clk);
        int             (*set_parent)(struct clk_hw *hw, u8 index);
        u8              (*get_parent)(struct clk_hw *hw);
-       int             (*set_rate)(struct clk_hw *hw, unsigned long,
-                                   unsigned long);
+       int             (*set_rate)(struct clk_hw *hw, unsigned long rate,
+                                   unsigned long parent_rate);
        int             (*set_rate_and_parent)(struct clk_hw *hw,
                                    unsigned long rate,
                                    unsigned long parent_rate, u8 index);
@@ -254,12 +260,12 @@ void of_fixed_clk_setup(struct device_node *np);
  *
  * Flags:
  * CLK_GATE_SET_TO_DISABLE - by default this clock sets the bit at bit_idx to
- *     enable the clock.  Setting this flag does the opposite: setting the bit
- *     disable the clock and clearing it enables the clock
+ *     enable the clock.  Setting this flag does the opposite: setting the bit
+ *     disable the clock and clearing it enables the clock
  * CLK_GATE_HIWORD_MASK - The gate settings are only in lower 16-bit
- *   of this register, and mask of gate bits are in higher 16-bit of this
- *   register.  While setting the gate bits, higher 16-bit should also be
- *   updated to indicate changing gate bits.
+ *     of this register, and mask of gate bits are in higher 16-bit of this
+ *     register.  While setting the gate bits, higher 16-bit should also be
+ *     updated to indicate changing gate bits.
  */
 struct clk_gate {
        struct clk_hw hw;
@@ -298,20 +304,24 @@ struct clk_div_table {
  *
  * Flags:
  * CLK_DIVIDER_ONE_BASED - by default the divisor is the value read from the
- *     register plus one.  If CLK_DIVIDER_ONE_BASED is set then the divider is
- *     the raw value read from the register, with the value of zero considered
+ *     register plus one.  If CLK_DIVIDER_ONE_BASED is set then the divider is
+ *     the raw value read from the register, with the value of zero considered
  *     invalid, unless CLK_DIVIDER_ALLOW_ZERO is set.
  * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from
- *     the hardware register
+ *     the hardware register
  * CLK_DIVIDER_ALLOW_ZERO - Allow zero divisors.  For dividers which have
  *     CLK_DIVIDER_ONE_BASED set, it is possible to end up with a zero divisor.
  *     Some hardware implementations gracefully handle this case and allow a
  *     zero divisor by not modifying their input clock
  *     (divide by one / bypass).
  * CLK_DIVIDER_HIWORD_MASK - The divider settings are only in lower 16-bit
- *   of this register, and mask of divider bits are in higher 16-bit of this
- *   register.  While setting the divider bits, higher 16-bit should also be
- *   updated to indicate changing divider bits.
+ *     of this register, and mask of divider bits are in higher 16-bit of this
+ *     register.  While setting the divider bits, higher 16-bit should also be
+ *     updated to indicate changing divider bits.
+ * CLK_DIVIDER_ROUND_CLOSEST - Makes the best calculated divider to be rounded
+ *     to the closest integer instead of the up one.
+ * CLK_DIVIDER_READ_ONLY - The divider settings are preconfigured and should
+ *     not be changed by the clock framework.
  */
 struct clk_divider {
        struct clk_hw   hw;
@@ -327,8 +337,11 @@ struct clk_divider {
 #define CLK_DIVIDER_POWER_OF_TWO       BIT(1)
 #define CLK_DIVIDER_ALLOW_ZERO         BIT(2)
 #define CLK_DIVIDER_HIWORD_MASK                BIT(3)
+#define CLK_DIVIDER_ROUND_CLOSEST      BIT(4)
+#define CLK_DIVIDER_READ_ONLY          BIT(5)
 
 extern const struct clk_ops clk_divider_ops;
+extern const struct clk_ops clk_divider_ro_ops;
 struct clk *clk_register_divider(struct device *dev, const char *name,
                const char *parent_name, unsigned long flags,
                void __iomem *reg, u8 shift, u8 width,
@@ -356,9 +369,9 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name,
  * CLK_MUX_INDEX_ONE - register index starts at 1, not 0
  * CLK_MUX_INDEX_BIT - register index is a single bit (power of two)
  * CLK_MUX_HIWORD_MASK - The mux settings are only in lower 16-bit of this
- *   register, and mask of mux bits are in higher 16-bit of this register.
- *   While setting the mux bits, higher 16-bit should also be updated to
- *   indicate changing mux bits.
+ *     register, and mask of mux bits are in higher 16-bit of this register.
+ *     While setting the mux bits, higher 16-bit should also be updated to
+ *     indicate changing mux bits.
  */
 struct clk_mux {
        struct clk_hw   hw;
@@ -529,10 +542,7 @@ struct clk_onecell_data {
 
 extern struct of_device_id __clk_of_table;
 
-#define CLK_OF_DECLARE(name, compat, fn)                       \
-       static const struct of_device_id __clk_of_table_##name  \
-               __used __section(__clk_of_table)                \
-               = { .compatible = compat, .data = fn };
+#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
 
 #ifdef CONFIG_OF
 int of_clk_add_provider(struct device_node *np,
@@ -609,5 +619,10 @@ static inline void clk_writel(u32 val, u32 __iomem *reg)
 
 #endif /* platform dependent I/O accessors */
 
+#ifdef CONFIG_DEBUG_FS
+struct dentry *clk_debugfs_add_file(struct clk *clk, char *name, umode_t mode,
+                               void *data, const struct file_operations *fops);
+#endif
+
 #endif /* CONFIG_COMMON_CLK */
 #endif /* CLK_PROVIDER_H */