Re: [PATCH v6 3/3] clk: basic clock hardware types

From: Matt Sealey
Date: Mon Mar 12 2012 - 23:58:12 EST


Hi Mike,

Can I suggest/we discuss that we support fractional (i.e. represented
by fixed point value with integer and fractional part) dividers in the
common divider clock case, simplistically just adding a divider
fractional width and shifting all the calculations by it (and fixing
the "maxdiv" calculation as in a fractional case width of the divider
area in the register is not an indicator of the actual maximum
divider)? (I guess for the standard integer divider case, it would be
continually shifting by 0 which might make the code a bit bigger, I
don't think that would truly be a concern though?)

Is there a particular reason why this case also cannot support set_parent?

I have a use case here (i.MX51/53/6 IPU DI output "pixel" clock) which
could be handled by this code if only those two were solved, it would
save reimplementing the whole thing as a special case. I am at a loss
to think of another particular case in any other SoC where there is a
fractional divider on a clock where it might come in handy, though, I
thought maybe someone could speak up and give an example that would
come in handy for them (I can think of Marvel PXA and OMAP DSS display
units having the exact same need which could be implemented using the
clock API rather than opencoded inside the framebuffer drivers, but
whether anyone actually cares about that is another matter
entirely...)

--
Matt Sealey <matt@xxxxxxxxxxxxxx>
Product Development Analyst, Genesi USA, Inc.



On Sat, Mar 10, 2012 at 1:54 AM, Mike Turquette <mturquette@xxxxxxxxxx> wrote:
> Many platforms support simple gateable clocks, fixed-rate clocks,
> adjustable divider clocks and multi-parent multiplexer clocks.
>
> This patch introduces basic clock types for the above-mentioned hardware
> which share some common characteristics.
>
> Based on original work by Jeremy Kerr and contribution by Jamie Iles.
> Dividers and multiplexor clocks originally contributed by Richard Zhao &
> Sascha Hauer.
>
> Signed-off-by: Mike Turquette <mturquette@xxxxxxxxxx>
> Signed-off-by: Mike Turquette <mturquette@xxxxxx>
> Cc: Russell King <linux@xxxxxxxxxxxxxxxx>
> Cc: Jeremy Kerr <jeremy.kerr@xxxxxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Arnd Bergman <arnd.bergmann@xxxxxxxxxx>
> Cc: Paul Walmsley <paul@xxxxxxxxx>
> Cc: Shawn Guo <shawn.guo@xxxxxxxxxxxxx>
> Cc: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> Cc: Jamie Iles <jamie@xxxxxxxxxxxxx>
> Cc: Richard Zhao <richard.zhao@xxxxxxxxxx>
> Cc: Saravana Kannan <skannan@xxxxxxxxxxxxxx>
> Cc: Magnus Damm <magnus.damm@xxxxxxxxx>
> Cc: Rob Herring <rob.herring@xxxxxxxxxxx>
> Cc: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> Cc: Linus Walleij <linus.walleij@xxxxxxxxxxxxxx>
> Cc: Stephen Boyd <sboyd@xxxxxxxxxxxxxx>
> Cc: Amit Kucheria <amit.kucheria@xxxxxxxxxx>
> Cc: Deepak Saxena <dsaxena@xxxxxxxxxx>
> Cc: Grant Likely <grant.likely@xxxxxxxxxxxx>
> Cc: Andrew Lunn <andrew@xxxxxxx>
> ---
> Changes since v5:
> Â* standardized the hw-specific locking in the basic clock types
> Â* export the individual ops for each basic clock type
> Â* improve registration for single-parent basic clocks (thanks Sascha)
> Â* fixed bugs in gate clock's static initializers (thanks Andrew)
>
> Âdrivers/clk/Makefile     |  Â3 +-
> Âdrivers/clk/clk-divider.c  Â| Â204 ++++++++++++++++++++++++++++++++++++++++++
> Âdrivers/clk/clk-fixed-rate.c | Â 82 +++++++++++++++++
> Âdrivers/clk/clk-gate.c    | Â157 ++++++++++++++++++++++++++++++++
> Âdrivers/clk/clk-mux.c    Â| Â123 +++++++++++++++++++++++++
> Âinclude/linux/clk-private.h Â| Â124 +++++++++++++++++++++++++
> Âinclude/linux/clk-provider.h | Â127 ++++++++++++++++++++++++++
> Â7 files changed, 819 insertions(+), 1 deletions(-)
> Âcreate mode 100644 drivers/clk/clk-divider.c
> Âcreate mode 100644 drivers/clk/clk-fixed-rate.c
> Âcreate mode 100644 drivers/clk/clk-gate.c
> Âcreate mode 100644 drivers/clk/clk-mux.c
>
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index ff362c4..1f736bc 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -1,3 +1,4 @@
>
> Âobj-$(CONFIG_CLKDEV_LOOKUP) Â Â+= clkdev.o
> -obj-$(CONFIG_COMMON_CLK) Â Â Â += clk.o
> +obj-$(CONFIG_COMMON_CLK) Â Â Â += clk.o clk-fixed-rate.o clk-gate.o \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âclk-mux.o clk-divider.o
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> new file mode 100644
> index 0000000..c0c4e0b
> --- /dev/null
> +++ b/drivers/clk/clk-divider.c
> @@ -0,0 +1,204 @@
> +/*
> + * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@xxxxxxxxxxxxxx>
> + * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@xxxxxxxxxx>
> + * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@xxxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Adjustable divider clock implementation
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/io.h>
> +#include <linux/err.h>
> +#include <linux/string.h>
> +
> +/*
> + * DOC: basic adjustable divider clock that cannot gate
> + *
> + * Traits of this clock:
> + * prepare - clk_prepare only ensures that parents are prepared
> + * enable - clk_enable only ensures that parents are enabled
> + * rate - rate is adjustable. Âclk->rate = parent->rate / divisor
> + * parent - fixed parent. ÂNo clk_set_parent support
> + */
> +
> +#define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw)
> +
> +static unsigned long clk_divider_recalc_rate(struct clk_hw *hw,
> + Â Â Â Â Â Â Â unsigned long parent_rate)
> +{
> + Â Â Â struct clk_divider *divider = to_clk_divider(hw);
> + Â Â Â unsigned int div;
> + Â Â Â unsigned long flags = 0;
> +
> + Â Â Â if (divider->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(divider->lock, flags);
> +
> + Â Â Â div = readl(divider->reg) >> divider->shift;
> + Â Â Â div &= (1 << divider->width) - 1;
> +
> + Â Â Â if (divider->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(divider->lock, flags);
> +
> + Â Â Â if (!(divider->flags & CLK_DIVIDER_ONE_BASED))
> + Â Â Â Â Â Â Â div++;
> +
> + Â Â Â return parent_rate / div;
> +}
> +EXPORT_SYMBOL_GPL(clk_divider_recalc_rate);
> +
> +static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
> + Â Â Â Â Â Â Â unsigned long *best_parent_rate)
> +{
> + Â Â Â struct clk_divider *divider = to_clk_divider(hw);
> + Â Â Â int i, bestdiv = 0;
> + Â Â Â unsigned long parent_rate, best = 0, now, maxdiv;
> +
> + Â Â Â maxdiv = (1 << divider->width);
> +
> + Â Â Â if (divider->flags & CLK_DIVIDER_ONE_BASED)
> + Â Â Â Â Â Â Â maxdiv--;
> +
> + Â Â Â if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) {
> + Â Â Â Â Â Â Â parent_rate = __clk_get_rate(__clk_get_parent(hw->clk));
> + Â Â Â Â Â Â Â bestdiv = parent_rate / rate;
> + Â Â Â Â Â Â Â bestdiv = bestdiv == 0 ? 1 : bestdiv;
> + Â Â Â Â Â Â Â bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â /*
> + Â Â Â Â* The maximum divider we can use without overflowing
> + Â Â Â Â* unsigned long in rate * i below
> + Â Â Â Â*/
> + Â Â Â maxdiv = min(ULONG_MAX / rate, maxdiv);
> +
> + Â Â Â for (i = 1; i <= maxdiv; i++) {
> + Â Â Â Â Â Â Â int div;
> + Â Â Â Â Â Â Â parent_rate = __clk_round_rate(__clk_get_parent(hw->clk),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rate * i);
> + Â Â Â Â Â Â Â div = parent_rate / rate;
> + Â Â Â Â Â Â Â div = div > maxdiv ? maxdiv : div;
> + Â Â Â Â Â Â Â div = div < 1 ? 1 : div;
> + Â Â Â Â Â Â Â now = parent_rate / div;
> +
> + Â Â Â Â Â Â Â if (now <= rate && now >= best) {
> + Â Â Â Â Â Â Â Â Â Â Â bestdiv = div;
> + Â Â Â Â Â Â Â Â Â Â Â best = now;
> + Â Â Â Â Â Â Â Â Â Â Â *best_parent_rate = parent_rate;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â if (!bestdiv) {
> + Â Â Â Â Â Â Â bestdiv = (1 << divider->width);
> + Â Â Â Â Â Â Â parent_rate = __clk_round_rate(__clk_get_parent(hw->clk), 1);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â parent_rate = best * bestdiv;
> + Â Â Â }
> +
> +out:
> + Â Â Â if (best_parent_rate)
> + Â Â Â Â Â Â Â *best_parent_rate = parent_rate;
> +
> + Â Â Â return bestdiv;
> +}
> +
> +static long clk_divider_round_rate(struct clk_hw *hw, unsigned long rate,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned long *prate)
> +{
> + Â Â Â unsigned long best_parent_rate;
> + Â Â Â int div = clk_divider_bestdiv(hw, rate, &best_parent_rate);
> + Â Â Â if (prate) {
> + Â Â Â Â Â Â Â if (best_parent_rate == __clk_get_rate(
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __clk_get_parent(hw->clk)))
> + Â Â Â Â Â Â Â Â Â Â Â *prate = 0;
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â *prate = best_parent_rate;
> + Â Â Â }
> +
> + Â Â Â return best_parent_rate / div;
> +}
> +EXPORT_SYMBOL_GPL(clk_divider_round_rate);
> +
> +static int clk_divider_set_rate(struct clk_hw *hw, unsigned long rate)
> +{
> + Â Â Â unsigned long best_parent_rate;
> + Â Â Â struct clk_divider *divider = to_clk_divider(hw);
> + Â Â Â unsigned int div;
> + Â Â Â unsigned long flags = 0;
> + Â Â Â u32 val;
> +
> + Â Â Â div = clk_divider_bestdiv(hw, rate, &best_parent_rate);
> +
> + Â Â Â if (divider->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(divider->lock, flags);
> +
> + Â Â Â if (!(divider->flags & CLK_DIVIDER_ONE_BASED))
> + Â Â Â Â Â Â Â div--;
> +
> + Â Â Â val = readl(divider->reg);
> + Â Â Â val &= ~(((1 << divider->width) - 1) << divider->shift);
> + Â Â Â val |= div << divider->shift;
> + Â Â Â writel(val, divider->reg);
> +
> + Â Â Â if (divider->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(divider->lock, flags);
> +
> + Â Â Â return 0;
> +}
> +EXPORT_SYMBOL_GPL(clk_divider_set_rate);
> +
> +struct clk_ops clk_divider_ops = {
> + Â Â Â .recalc_rate = clk_divider_recalc_rate,
> + Â Â Â .round_rate = clk_divider_round_rate,
> + Â Â Â .set_rate = clk_divider_set_rate,
> +};
> +EXPORT_SYMBOL_GPL(clk_divider_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,
> + Â Â Â Â Â Â Â u8 clk_divider_flags, spinlock_t *lock)
> +{
> + Â Â Â struct clk_divider *div;
> + Â Â Â struct clk *clk;
> +
> + Â Â Â div = kzalloc(sizeof(struct clk_divider), GFP_KERNEL);
> +
> + Â Â Â if (!div) {
> + Â Â Â Â Â Â Â pr_err("%s: could not allocate divider clk\n", __func__);
> + Â Â Â Â Â Â Â return NULL;
> + Â Â Â }
> +
> + Â Â Â /* struct clk_divider assignments */
> + Â Â Â div->reg = reg;
> + Â Â Â div->shift = shift;
> + Â Â Â div->width = width;
> + Â Â Â div->flags = clk_divider_flags;
> + Â Â Â div->lock = lock;
> +
> + Â Â Â if (parent_name) {
> + Â Â Â Â Â Â Â div->parent[0] = kstrdup(parent_name, GFP_KERNEL);
> + Â Â Â Â Â Â Â if (!div->parent[0])
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â clk = clk_register(dev, name,
> + Â Â Â Â Â Â Â Â Â Â Â &clk_divider_ops, &div->hw,
> + Â Â Â Â Â Â Â Â Â Â Â div->parent,
> + Â Â Â Â Â Â Â Â Â Â Â (parent_name ? 1 : 0),
> + Â Â Â Â Â Â Â Â Â Â Â flags);
> + Â Â Â if (clk)
> + Â Â Â Â Â Â Â return clk;
> +
> +out:
> + Â Â Â kfree(div->parent[0]);
> + Â Â Â kfree(div);
> +
> + Â Â Â return NULL;
> +}
> diff --git a/drivers/clk/clk-fixed-rate.c b/drivers/clk/clk-fixed-rate.c
> new file mode 100644
> index 0000000..90c79fb
> --- /dev/null
> +++ b/drivers/clk/clk-fixed-rate.c
> @@ -0,0 +1,82 @@
> +/*
> + * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@xxxxxxxxxxxxx>
> + * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@xxxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Fixed rate clock implementation
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/io.h>
> +#include <linux/err.h>
> +
> +/*
> + * DOC: basic fixed-rate clock that cannot gate
> + *
> + * Traits of this clock:
> + * prepare - clk_(un)prepare only ensures parents are prepared
> + * enable - clk_enable only ensures parents are enabled
> + * rate - rate is always a fixed value. ÂNo clk_set_rate support
> + * parent - fixed parent. ÂNo clk_set_parent support
> + */
> +
> +#define to_clk_fixed_rate(_hw) container_of(_hw, struct clk_fixed_rate, hw)
> +
> +static unsigned long clk_fixed_rate_recalc_rate(struct clk_hw *hw,
> + Â Â Â Â Â Â Â unsigned long parent_rate)
> +{
> + Â Â Â return to_clk_fixed_rate(hw)->fixed_rate;
> +}
> +EXPORT_SYMBOL_GPL(clk_fixed_rate_recalc_rate);
> +
> +struct clk_ops clk_fixed_rate_ops = {
> + Â Â Â .recalc_rate = clk_fixed_rate_recalc_rate,
> +};
> +EXPORT_SYMBOL_GPL(clk_fixed_rate_ops);
> +
> +struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
> + Â Â Â Â Â Â Â const char *parent_name, unsigned long flags,
> + Â Â Â Â Â Â Â unsigned long fixed_rate)
> +{
> + Â Â Â struct clk_fixed_rate *fixed;
> + Â Â Â char **parent_names = NULL;
> + Â Â Â u8 len;
> +
> + Â Â Â fixed = kzalloc(sizeof(struct clk_fixed_rate), GFP_KERNEL);
> +
> + Â Â Â if (!fixed) {
> + Â Â Â Â Â Â Â pr_err("%s: could not allocate fixed clk\n", __func__);
> + Â Â Â Â Â Â Â return ERR_PTR(-ENOMEM);
> + Â Â Â }
> +
> + Â Â Â /* struct clk_fixed_rate assignments */
> + Â Â Â fixed->fixed_rate = fixed_rate;
> +
> + Â Â Â if (parent_name) {
> + Â Â Â Â Â Â Â parent_names = kmalloc(sizeof(char *), GFP_KERNEL);
> +
> + Â Â Â Â Â Â Â if (! parent_names)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â len = sizeof(char) * strlen(parent_name);
> +
> + Â Â Â Â Â Â Â parent_names[0] = kmalloc(len, GFP_KERNEL);
> +
> + Â Â Â Â Â Â Â if (!parent_names[0])
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â strncpy(parent_names[0], parent_name, len);
> + Â Â Â }
> +
> +out:
> + Â Â Â return clk_register(dev, name,
> + Â Â Â Â Â Â Â Â Â Â Â &clk_fixed_rate_ops, &fixed->hw,
> + Â Â Â Â Â Â Â Â Â Â Â parent_names,
> + Â Â Â Â Â Â Â Â Â Â Â (parent_name ? 1 : 0),
> + Â Â Â Â Â Â Â Â Â Â Â flags);
> +}
> diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
> new file mode 100644
> index 0000000..5d50efa
> --- /dev/null
> +++ b/drivers/clk/clk-gate.c
> @@ -0,0 +1,157 @@
> +/*
> + * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@xxxxxxxxxxxxx>
> + * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@xxxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Gated clock implementation
> + */
> +
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/io.h>
> +#include <linux/err.h>
> +#include <linux/string.h>
> +
> +/**
> + * DOC: basic gatable clock which can gate and ungate it's ouput
> + *
> + * Traits of this clock:
> + * prepare - clk_(un)prepare only ensures parent is (un)prepared
> + * enable - clk_enable and clk_disable are functional & control gating
> + * rate - inherits rate from parent. ÂNo clk_set_rate support
> + * parent - fixed parent. ÂNo clk_set_parent support
> + */
> +
> +#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
> +
> +static void clk_gate_set_bit(struct clk_gate *gate)
> +{
> + Â Â Â u32 reg;
> + Â Â Â unsigned long flags = 0;
> +
> + Â Â Â if (gate->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(gate->lock, flags);
> +
> + Â Â Â reg = readl(gate->reg);
> + Â Â Â reg |= BIT(gate->bit_idx);
> + Â Â Â writel(reg, gate->reg);
> +
> + Â Â Â if (gate->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(gate->lock, flags);
> +}
> +
> +static void clk_gate_clear_bit(struct clk_gate *gate)
> +{
> + Â Â Â u32 reg;
> + Â Â Â unsigned long flags = 0;
> +
> + Â Â Â if (gate->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(gate->lock, flags);
> +
> + Â Â Â reg = readl(gate->reg);
> + Â Â Â reg &= ~BIT(gate->bit_idx);
> + Â Â Â writel(reg, gate->reg);
> +
> + Â Â Â if (gate->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(gate->lock, flags);
> +}
> +
> +static int clk_gate_enable(struct clk_hw *hw)
> +{
> + Â Â Â struct clk_gate *gate = to_clk_gate(hw);
> +
> + Â Â Â if (gate->flags & CLK_GATE_SET_TO_DISABLE)
> + Â Â Â Â Â Â Â clk_gate_clear_bit(gate);
> + Â Â Â else
> + Â Â Â Â Â Â Â clk_gate_set_bit(gate);
> +
> + Â Â Â return 0;
> +}
> +EXPORT_SYMBOL_GPL(clk_gate_enable);
> +
> +static void clk_gate_disable(struct clk_hw *hw)
> +{
> + Â Â Â struct clk_gate *gate = to_clk_gate(hw);
> +
> + Â Â Â if (gate->flags & CLK_GATE_SET_TO_DISABLE)
> + Â Â Â Â Â Â Â clk_gate_set_bit(gate);
> + Â Â Â else
> + Â Â Â Â Â Â Â clk_gate_clear_bit(gate);
> +}
> +EXPORT_SYMBOL_GPL(clk_gate_disable);
> +
> +static int clk_gate_is_enabled(struct clk_hw *hw)
> +{
> + Â Â Â u32 reg;
> + Â Â Â unsigned long flags = 0;
> + Â Â Â struct clk_gate *gate = to_clk_gate(hw);
> +
> + Â Â Â if (gate->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(gate->lock, flags);
> +
> + Â Â Â reg = readl(gate->reg);
> +
> + Â Â Â if (gate->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(gate->lock, flags);
> +
> + Â Â Â /* if a set bit disables this clk, flip it before masking */
> + Â Â Â if (gate->flags & CLK_GATE_SET_TO_DISABLE)
> + Â Â Â Â Â Â Â reg ^= BIT(gate->bit_idx);
> +
> + Â Â Â reg &= BIT(gate->bit_idx);
> +
> + Â Â Â return reg ? 1 : 0;
> +}
> +EXPORT_SYMBOL_GPL(clk_gate_is_enabled);
> +
> +struct clk_ops clk_gate_ops = {
> + Â Â Â .enable = clk_gate_enable,
> + Â Â Â .disable = clk_gate_disable,
> + Â Â Â .is_enabled = clk_gate_is_enabled,
> +};
> +EXPORT_SYMBOL_GPL(clk_gate_ops);
> +
> +struct clk *clk_register_gate(struct device *dev, const char *name,
> + Â Â Â Â Â Â Â const char *parent_name, unsigned long flags,
> + Â Â Â Â Â Â Â void __iomem *reg, u8 bit_idx,
> + Â Â Â Â Â Â Â u8 clk_gate_flags, spinlock_t *lock)
> +{
> + Â Â Â struct clk_gate *gate;
> + Â Â Â struct clk *clk;
> +
> + Â Â Â gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
> +
> + Â Â Â if (!gate) {
> + Â Â Â Â Â Â Â pr_err("%s: could not allocate gated clk\n", __func__);
> + Â Â Â Â Â Â Â return NULL;
> + Â Â Â }
> +
> + Â Â Â /* struct clk_gate assignments */
> + Â Â Â gate->reg = reg;
> + Â Â Â gate->bit_idx = bit_idx;
> + Â Â Â gate->flags = clk_gate_flags;
> + Â Â Â gate->lock = lock;
> +
> + Â Â Â if (parent_name) {
> + Â Â Â Â Â Â Â gate->parent[0] = kstrdup(parent_name, GFP_KERNEL);
> + Â Â Â Â Â Â Â if (!gate->parent[0])
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â clk = clk_register(dev, name,
> + Â Â Â Â Â Â Â Â Â Â Â &clk_gate_ops, &gate->hw,
> + Â Â Â Â Â Â Â Â Â Â Â gate->parent,
> + Â Â Â Â Â Â Â Â Â Â Â (parent_name ? 1 : 0),
> + Â Â Â Â Â Â Â Â Â Â Â flags);
> + Â Â Â if (clk)
> + Â Â Â Â Â Â Â return clk;
> +out:
> + Â Â Â kfree(gate->parent[0]);
> + Â Â Â kfree(gate);
> +
> + Â Â Â return NULL;
> +}
> diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
> new file mode 100644
> index 0000000..6fc0878
> --- /dev/null
> +++ b/drivers/clk/clk-mux.c
> @@ -0,0 +1,123 @@
> +/*
> + * Copyright (C) 2011 Sascha Hauer, Pengutronix <s.hauer@xxxxxxxxxxxxxx>
> + * Copyright (C) 2011 Richard Zhao, Linaro <richard.zhao@xxxxxxxxxx>
> + * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@xxxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * Simple multiplexer clock implementation
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/clk-provider.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/io.h>
> +#include <linux/err.h>
> +
> +/*
> + * DOC: basic adjustable multiplexer clock that cannot gate
> + *
> + * Traits of this clock:
> + * prepare - clk_prepare only ensures that parents are prepared
> + * enable - clk_enable only ensures that parents are enabled
> + * rate - rate is only affected by parent switching. ÂNo clk_set_rate support
> + * parent - parent is adjustable through clk_set_parent
> + */
> +
> +#define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
> +
> +static u8 clk_mux_get_parent(struct clk_hw *hw)
> +{
> + Â Â Â struct clk_mux *mux = to_clk_mux(hw);
> + Â Â Â u32 val;
> + Â Â Â unsigned long flags = 0;
> +
> + Â Â Â if (mux->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(mux->lock, flags);
> +
> + Â Â Â /*
> + Â Â Â Â* FIXME need a mux-specific flag to determine if val is bitwise or numeric
> + Â Â Â Â* e.g. sys_clkin_ck's clksel field is 3 bits wide, but ranges from 0x1
> + Â Â Â Â* to 0x7 (index starts at one)
> + Â Â Â Â* OTOH, pmd_trace_clk_mux_ck uses a separate bit for each clock, so
> + Â Â Â Â* val = 0x4 really means "bit 2, index starts at bit 0"
> + Â Â Â Â*/
> + Â Â Â val = readl(mux->reg) >> mux->shift;
> + Â Â Â val &= (1 << mux->width) - 1;
> +
> + Â Â Â if (mux->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(mux->lock, flags);
> +
> + Â Â Â if (val && (mux->flags & CLK_MUX_INDEX_BIT))
> + Â Â Â Â Â Â Â val = ffs(val) - 1;
> +
> + Â Â Â if (val && (mux->flags & CLK_MUX_INDEX_ONE))
> + Â Â Â Â Â Â Â val--;
> +
> + Â Â Â if (val >= __clk_get_num_parents(hw->clk))
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â return val;
> +}
> +EXPORT_SYMBOL_GPL(clk_mux_get_parent);
> +
> +static int clk_mux_set_parent(struct clk_hw *hw, u8 index)
> +{
> + Â Â Â struct clk_mux *mux = to_clk_mux(hw);
> + Â Â Â u32 val;
> + Â Â Â unsigned long flags = 0;
> +
> + Â Â Â if (mux->flags & CLK_MUX_INDEX_BIT)
> + Â Â Â Â Â Â Â index = (1 << ffs(index));
> +
> + Â Â Â if (mux->flags & CLK_MUX_INDEX_ONE)
> + Â Â Â Â Â Â Â index++;
> +
> + Â Â Â if (mux->lock)
> + Â Â Â Â Â Â Â spin_lock_irqsave(mux->lock, flags);
> +
> + Â Â Â val = readl(mux->reg);
> + Â Â Â val &= ~(((1 << mux->width) - 1) << mux->shift);
> + Â Â Â val |= index << mux->shift;
> + Â Â Â writel(val, mux->reg);
> +
> + Â Â Â if (mux->lock)
> + Â Â Â Â Â Â Â spin_unlock_irqrestore(mux->lock, flags);
> +
> + Â Â Â return 0;
> +}
> +EXPORT_SYMBOL_GPL(clk_mux_set_parent);
> +
> +struct clk_ops clk_mux_ops = {
> + Â Â Â .get_parent = clk_mux_get_parent,
> + Â Â Â .set_parent = clk_mux_set_parent,
> +};
> +EXPORT_SYMBOL_GPL(clk_mux_ops);
> +
> +struct clk *clk_register_mux(struct device *dev, const char *name,
> + Â Â Â Â Â Â Â char **parent_names, u8 num_parents, unsigned long flags,
> + Â Â Â Â Â Â Â void __iomem *reg, u8 shift, u8 width,
> + Â Â Â Â Â Â Â u8 clk_mux_flags, spinlock_t *lock)
> +{
> + Â Â Â struct clk_mux *mux;
> +
> + Â Â Â mux = kmalloc(sizeof(struct clk_mux), GFP_KERNEL);
> +
> + Â Â Â if (!mux) {
> + Â Â Â Â Â Â Â pr_err("%s: could not allocate mux clk\n", __func__);
> + Â Â Â Â Â Â Â return ERR_PTR(-ENOMEM);
> + Â Â Â }
> +
> + Â Â Â /* struct clk_mux assignments */
> + Â Â Â mux->reg = reg;
> + Â Â Â mux->shift = shift;
> + Â Â Â mux->width = width;
> + Â Â Â mux->flags = clk_mux_flags;
> + Â Â Â mux->lock = lock;
> +
> + Â Â Â return clk_register(dev, name, &clk_mux_ops, &mux->hw,
> + Â Â Â Â Â Â Â Â Â Â Â parent_names, num_parents, flags);
> +}
> diff --git a/include/linux/clk-private.h b/include/linux/clk-private.h
> index 33bf6a7..9d5c4b1 100644
> --- a/include/linux/clk-private.h
> +++ b/include/linux/clk-private.h
> @@ -45,6 +45,130 @@ struct clk {
> Â#endif
> Â};
>
> +/*
> + * DOC: Basic clock implementations common to many platforms
> + *
> + * Each basic clock hardware type is comprised of a structure describing the
> + * clock hardware, implementations of the relevant callbacks in struct clk_ops,
> + * unique flags for that hardware type, a registration function and an
> + * alternative macro for static initialization
> + */
> +
> +extern struct clk_ops clk_fixed_rate_ops;
> +
> +#define DEFINE_CLK_FIXED_RATE(_name, _flags, _rate, Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _fixed_rate_flags) Â Â Â Â Â Â Â\
> + Â Â Â static struct clk _name; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static char *_name##_parent_names[] = {}; Â Â Â Â Â Â Â \
> + Â Â Â static struct clk_fixed_rate _name##_hw = { Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .hw = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â .clk = &_name, Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .fixed_rate = _rate, Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .flags = _fixed_rate_flags, Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk _name = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .name = #_name, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .ops = &clk_fixed_rate_ops, Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .hw = &_name##_hw.hw, Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .parent_names = _name##_parent_names, Â Â Â Â Â \
> + Â Â Â Â Â Â Â .num_parents = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â Â Â Â Â ARRAY_SIZE(_name##_parent_names), Â Â Â \
> + Â Â Â Â Â Â Â .flags = _flags, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â };
> +
> +extern struct clk_ops clk_gate_ops;
> +
> +#define DEFINE_CLK_GATE(_name, _parent_name, _parent_ptr, Â Â Â\
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _flags, _reg, _bit_idx, Â Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _gate_flags, _lock) Â Â Â Â Â Â \
> + Â Â Â static struct clk _name; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static char *_name##_parent_names[] = { Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â _parent_name, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk *_name##_parents[] = { Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â _parent_ptr, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk_gate _name##_hw = { Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .hw = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â .clk = &_name, Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .reg = _reg, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .bit_idx = _bit_idx, Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .flags = _gate_flags, Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .lock = _lock, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk _name = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .name = #_name, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .ops = &clk_gate_ops, Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .hw = &_name##_hw.hw, Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .parent_names = _name##_parent_names, Â Â Â Â Â \
> + Â Â Â Â Â Â Â .num_parents = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â Â Â Â Â ARRAY_SIZE(_name##_parent_names), Â Â Â \
> + Â Â Â Â Â Â Â .parents = _name##_parents, Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .flags = _flags, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â };
> +
> +extern struct clk_ops clk_divider_ops;
> +
> +#define DEFINE_CLK_DIVIDER(_name, _parent_name, _parent_ptr, Â \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _flags, _reg, _shift, _width, Â \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _divider_flags, _lock) Â Â Â Â Â\
> + Â Â Â static struct clk _name; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static char *_name##_parent_names[] = { Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â _parent_name, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk *_name##_parents[] = { Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â _parent_ptr, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk_divider _name##_hw = { Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .hw = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â .clk = &_name, Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .reg = _reg, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .shift = _shift, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .width = _width, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .flags = _divider_flags, Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .lock = _lock, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk _name = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .name = #_name, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .ops = &clk_divider_ops, Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .hw = &_name##_hw.hw, Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .parent_names = _name##_parent_names, Â Â Â Â Â \
> + Â Â Â Â Â Â Â .num_parents = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â Â Â Â Â ARRAY_SIZE(_name##_parent_names), Â Â Â \
> + Â Â Â Â Â Â Â .parents = _name##_parents, Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .flags = _flags, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â };
> +
> +extern struct clk_ops clk_mux_ops;
> +
> +#define DEFINE_CLK_MUX(_name, _parent_names, _parents, _flags, \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _reg, _shift, _width, Â Â Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _mux_flags, _lock) Â Â Â Â Â Â Â\
> + Â Â Â static struct clk _name; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk_mux _name##_hw = { Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .hw = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â .clk = &_name, Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â }, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .reg = _reg, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .shift = _shift, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .width = _width, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .flags = _mux_flags, Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .lock = _lock, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â }; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â static struct clk _name = { Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .name = #_name, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .ops = &clk_mux_ops, Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .hw = &_name##_hw.hw, Â Â Â Â Â Â Â Â Â Â Â Â Â \
> + Â Â Â Â Â Â Â .parent_names = _parent_names, Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .num_parents = Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â Â Â Â Â ARRAY_SIZE(_parent_names), Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .parents = _parents, Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â Â Â Â Â .flags = _flags, Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> + Â Â Â };
> +
> Â/**
> Â* __clk_init - initialize the data structures in a struct clk
> Â* @dev: Â Â Â device initializing this clk, placeholder for now
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index 09dea1f..853d526 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -129,6 +129,133 @@ struct clk_ops {
>    Âvoid      Â(*init)(struct clk_hw *hw);
> Â};
>
> +/*
> + * DOC: Basic clock implementations common to many platforms
> + *
> + * Each basic clock hardware type is comprised of a structure describing the
> + * clock hardware, implementations of the relevant callbacks in struct clk_ops,
> + * unique flags for that hardware type, a registration function and an
> + * alternative macro for static initialization
> + */
> +
> +/**
> + * struct clk_fixed_rate - fixed-rate clock
> + * @hw: Â Â Â Â Â Â Â Âhandle between common and hardware-specific interfaces
> + * @fixed_rate: Â Â Â Âconstant frequency of clock
> + */
> +struct clk_fixed_rate {
> +    struct     Âclk_hw hw;
> +    unsigned long  fixed_rate;
> + Â Â Â u8 Â Â Â Â Â Â Âflags;
> +};
> +
> +struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
> + Â Â Â Â Â Â Â const char *parent_name, unsigned long flags,
> + Â Â Â Â Â Â Â unsigned long fixed_rate);
> +
> +/**
> + * struct clk_gate - gating clock
> + *
> + * @hw: Â Â Â Â Â Â Â Âhandle between common and hardware-specific interfaces
> + * @reg: Â Â Â register controlling gate
> + * @bit_idx: Â single bit controlling gate
> + * @flags: Â Â hardware-specific flags
> + * @lock: Â Â Âregister lock
> + *
> + * Clock which can gate its output. ÂImplements .enable & .disable
> + *
> + * Flags:
> + * CLK_GATE_SET_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
> + */
> +struct clk_gate {
> + Â Â Â struct clk_hw hw;
> +    void __iomem  Â*reg;
> + Â Â Â u8 Â Â Â Â Â Â Âbit_idx;
> + Â Â Â u8 Â Â Â Â Â Â Âflags;
> +    spinlock_t   Â*lock;
> +    char      Â*parent[1];
> +};
> +
> +#define CLK_GATE_SET_TO_DISABLE Â Â Â Â Â Â Â ÂBIT(0)
> +
> +struct clk *clk_register_gate(struct device *dev, const char *name,
> + Â Â Â Â Â Â Â const char *parent_name, unsigned long flags,
> + Â Â Â Â Â Â Â void __iomem *reg, u8 bit_idx,
> + Â Â Â Â Â Â Â u8 clk_gate_flags, spinlock_t *lock);
> +
> +/**
> + * struct clk_divider - adjustable divider clock
> + *
> + * @hw: Â Â Â Â Â Â Â Âhandle between common and hardware-specific interfaces
> + * @reg: Â Â Â register containing the divider
> + * @shift: Â Â shift to the divider bit field
> + * @width: Â Â width of the divider bit field
> + * @lock: Â Â Âregister lock
> + *
> + * Clock with an adjustable divider affecting its output frequency. ÂImplements
> + * .recalc_rate, .set_rate and .round_rate
> + *
> + * 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
> + * Â Â invalid
> + * CLK_DIVIDER_POWER_OF_TWO - clock divisor is 2 raised to the value read from
> + * Â Â the hardware register
> + */
> +struct clk_divider {
> +    struct clk_hw  hw;
> +    void __iomem  Â*reg;
> + Â Â Â u8 Â Â Â Â Â Â Âshift;
> + Â Â Â u8 Â Â Â Â Â Â Âwidth;
> + Â Â Â u8 Â Â Â Â Â Â Âflags;
> +    spinlock_t   Â*lock;
> +    char      Â*parent[1];
> +};
> +
> +#define CLK_DIVIDER_ONE_BASED Â Â Â Â ÂBIT(0)
> +#define CLK_DIVIDER_POWER_OF_TWO Â Â Â BIT(1)
> +
> +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,
> + Â Â Â Â Â Â Â u8 clk_divider_flags, spinlock_t *lock);
> +
> +/**
> + * struct clk_mux - multiplexer clock
> + *
> + * @hw: Â Â Â Â Â Â Â Âhandle between common and hardware-specific interfaces
> + * @reg: Â Â Â register controlling multiplexer
> + * @shift: Â Â shift to multiplexer bit field
> + * @width: Â Â width of mutliplexer bit field
> + * @num_clks: Ânumber of parent clocks
> + * @lock: Â Â Âregister lock
> + *
> + * Clock with multiple selectable parents. ÂImplements .get_parent, .set_parent
> + * and .recalc_rate
> + *
> + * Flags:
> + * CLK_MUX_INDEX_ONE - register index starts at 1, not 0
> + * CLK_MUX_INDEX_BITWISE - register index is a single bit (power of two)
> + */
> +struct clk_mux {
> +    struct clk_hw  hw;
> +    void __iomem  Â*reg;
> + Â Â Â u8 Â Â Â Â Â Â Âshift;
> + Â Â Â u8 Â Â Â Â Â Â Âwidth;
> + Â Â Â u8 Â Â Â Â Â Â Âflags;
> +    spinlock_t   Â*lock;
> +};
> +
> +#define CLK_MUX_INDEX_ONE Â Â Â Â Â Â ÂBIT(0)
> +#define CLK_MUX_INDEX_BIT Â Â Â Â Â Â ÂBIT(1)
> +
> +struct clk *clk_register_mux(struct device *dev, const char *name,
> + Â Â Â Â Â Â Â char **parent_names, u8 num_parents, unsigned long flags,
> + Â Â Â Â Â Â Â void __iomem *reg, u8 shift, u8 width,
> + Â Â Â Â Â Â Â u8 clk_mux_flags, spinlock_t *lock);
>
> Â/**
> Â* clk_register - allocate a new clock, register it and return an opaque cookie
> --
> 1.7.5.4
>
>
> _______________________________________________
> linaro-dev mailing list
> linaro-dev@xxxxxxxxxxxxxxxx
> http://lists.linaro.org/mailman/listinfo/linaro-dev
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_