All of lore.kernel.org
 help / color / mirror / Atom feed
From: mturquette@linaro.org (Mike Turquette)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 01/11] clk: sunxi: register factors clocks behind composite
Date: Tue, 17 Dec 2013 18:55:27 -0800	[thread overview]
Message-ID: <20131218025527.23538.28216@quantum> (raw)
In-Reply-To: <1387327503-15651-2-git-send-email-emilio@elopez.com.ar>

Quoting Emilio L?pez (2013-12-17 16:44:53)
> This commit reworks factors clock registration to be done behind a
> composite clock. This allows us to additionally add a gate, mux or
> divisors, as it will be needed by some future PLLs.
> 
> Signed-off-by: Emilio L?pez <emilio@elopez.com.ar>
> Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> ---
>  drivers/clk/sunxi/clk-factors.c | 63 +--------------------------------------
>  drivers/clk/sunxi/clk-factors.h | 16 +++++-----
>  drivers/clk/sunxi/clk-sunxi.c   | 66 ++++++++++++++++++++++++++++++++++++++---
>  3 files changed, 72 insertions(+), 73 deletions(-)
> 
> diff --git a/drivers/clk/sunxi/clk-factors.c b/drivers/clk/sunxi/clk-factors.c
> index f05207a..9e23264 100644
> --- a/drivers/clk/sunxi/clk-factors.c
> +++ b/drivers/clk/sunxi/clk-factors.c
> @@ -30,14 +30,6 @@
>   * parent - fixed parent.  No clk_set_parent support
>   */
>  
> -struct clk_factors {
> -       struct clk_hw hw;
> -       void __iomem *reg;
> -       struct clk_factors_config *config;
> -       void (*get_factors) (u32 *rate, u32 parent, u8 *n, u8 *k, u8 *m, u8 *p);
> -       spinlock_t *lock;
> -};
> -
>  #define to_clk_factors(_hw) container_of(_hw, struct clk_factors, hw)
>  
>  #define SETMASK(len, pos)              (((1U << (len)) - 1) << (pos))
> @@ -120,61 +112,8 @@ static int clk_factors_set_rate(struct clk_hw *hw, unsigned long rate,
>         return 0;
>  }
>  
> -static const struct clk_ops clk_factors_ops = {
> +const struct clk_ops clk_factors_ops = {
>         .recalc_rate = clk_factors_recalc_rate,
>         .round_rate = clk_factors_round_rate,
>         .set_rate = clk_factors_set_rate,
>  };
> -
> -/**
> - * clk_register_factors - register a factors clock with
> - * the clock framework
> - * @dev: device registering this clock
> - * @name: name of this clock
> - * @parent_name: name of clock's parent
> - * @flags: framework-specific flags
> - * @reg: register address to adjust factors
> - * @config: shift and width of factors n, k, m and p
> - * @get_factors: function to calculate the factors for a given frequency
> - * @lock: shared register lock for this clock
> - */
> -struct clk *clk_register_factors(struct device *dev, const char *name,
> -                                const char *parent_name,
> -                                unsigned long flags, void __iomem *reg,
> -                                struct clk_factors_config *config,
> -                                void (*get_factors)(u32 *rate, u32 parent,
> -                                                    u8 *n, u8 *k, u8 *m, u8 *p),
> -                                spinlock_t *lock)
> -{
> -       struct clk_factors *factors;
> -       struct clk *clk;
> -       struct clk_init_data init;
> -
> -       /* allocate the factors */
> -       factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
> -       if (!factors) {
> -               pr_err("%s: could not allocate factors clk\n", __func__);
> -               return ERR_PTR(-ENOMEM);
> -       }
> -
> -       init.name = name;
> -       init.ops = &clk_factors_ops;
> -       init.flags = flags;
> -       init.parent_names = (parent_name ? &parent_name : NULL);
> -       init.num_parents = (parent_name ? 1 : 0);
> -
> -       /* struct clk_factors assignments */
> -       factors->reg = reg;
> -       factors->config = config;
> -       factors->lock = lock;
> -       factors->hw.init = &init;
> -       factors->get_factors = get_factors;
> -
> -       /* register the clock */
> -       clk = clk_register(dev, &factors->hw);
> -
> -       if (IS_ERR(clk))
> -               kfree(factors);
> -
> -       return clk;
> -}
> diff --git a/drivers/clk/sunxi/clk-factors.h b/drivers/clk/sunxi/clk-factors.h
> index f49851c..02e1a43 100644
> --- a/drivers/clk/sunxi/clk-factors.h
> +++ b/drivers/clk/sunxi/clk-factors.h
> @@ -17,11 +17,13 @@ struct clk_factors_config {
>         u8 pwidth;
>  };
>  
> -struct clk *clk_register_factors(struct device *dev, const char *name,
> -                                const char *parent_name,
> -                                unsigned long flags, void __iomem *reg,
> -                                struct clk_factors_config *config,
> -                                void (*get_factors) (u32 *rate, u32 parent_rate,
> -                                                     u8 *n, u8 *k, u8 *m, u8 *p),
> -                                spinlock_t *lock);
> +struct clk_factors {
> +       struct clk_hw hw;
> +       void __iomem *reg;
> +       struct clk_factors_config *config;
> +       void (*get_factors) (u32 *rate, u32 parent, u8 *n, u8 *k, u8 *m, u8 *p);
> +       spinlock_t *lock;
> +};
> +
> +extern const struct clk_ops clk_factors_ops;
>  #endif
> diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
> index 8fc1375..6f756f4 100644
> --- a/drivers/clk/sunxi/clk-sunxi.c
> +++ b/drivers/clk/sunxi/clk-sunxi.c
> @@ -255,7 +255,11 @@ static void sun4i_get_apb1_factors(u32 *freq, u32 parent_rate,
>   * sunxi_factors_clk_setup() - Setup function for factor clocks
>   */
>  
> +#define SUNXI_FACTORS_MUX_MASK 0x3
> +
>  struct factors_data {
> +       int enable;
> +       int mux;
>         struct clk_factors_config *table;
>         void (*getter) (u32 *rate, u32 parent_rate, u8 *n, u8 *k, u8 *m, u8 *p);
>  };
> @@ -306,16 +310,70 @@ static void __init sunxi_factors_clk_setup(struct device_node *node,
>                                            struct factors_data *data)
>  {
>         struct clk *clk;
> +       struct clk_factors *factors;
> +       struct clk_gate *gate = NULL;
> +       struct clk_mux *mux = NULL;
> +       struct clk_hw *gate_hw = NULL;
> +       struct clk_hw *mux_hw = NULL;
>         const char *clk_name = node->name;
> -       const char *parent;
> +       const char *parents[5];

Seems like 5 is a magic number? I guess this type of clock always has
the same number of parents? Might be good to use a preprocessor macro
here.

Otherwise the patch looks good to me.

Regards,
Mike

>         void *reg;
> +       int i = 0;
>  
>         reg = of_iomap(node, 0);
>  
> -       parent = of_clk_get_parent_name(node, 0);
> +       /* if we have a mux, we will have >1 parents */
> +       while (i < 5 && (parents[i] = of_clk_get_parent_name(node, i)) != NULL)
> +               i++;
> +
> +       factors = kzalloc(sizeof(struct clk_factors), GFP_KERNEL);
> +       if (!factors)
> +               return;
>  
> -       clk = clk_register_factors(NULL, clk_name, parent, 0, reg,
> -                                  data->table, data->getter, &clk_lock);
> +       /* Add a gate if this factor clock can be gated */
> +       if (data->enable) {
> +               gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL);
> +               if (!gate) {
> +                       kfree(factors);
> +                       return;
> +               }
> +
> +               /* set up gate properties */
> +               gate->reg = reg;
> +               gate->bit_idx = data->enable;
> +               gate->lock = &clk_lock;
> +               gate_hw = &gate->hw;
> +       }
> +
> +       /* Add a mux if this factor clock can be muxed */
> +       if (data->mux) {
> +               mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL);
> +               if (!mux) {
> +                       kfree(factors);
> +                       kfree(gate);
> +                       return;
> +               }
> +
> +               /* set up gate properties */
> +               mux->reg = reg;
> +               mux->shift = data->mux;
> +               mux->mask = SUNXI_FACTORS_MUX_MASK;
> +               mux->lock = &clk_lock;
> +               mux_hw = &mux->hw;
> +       }
> +
> +       /* set up factors properties */
> +       factors->reg = reg;
> +       factors->config = data->table;
> +       factors->get_factors = data->getter;
> +       factors->lock = &clk_lock;
> +
> +       clk = clk_register_composite(NULL, clk_name,
> +                       parents, i,
> +                       mux_hw, &clk_mux_ops,
> +                       &factors->hw, &clk_factors_ops,
> +                       gate_hw, &clk_gate_ops,
> +                       i ? 0 : CLK_IS_ROOT);
>  
>         if (!IS_ERR(clk)) {
>                 of_clk_add_provider(node, of_clk_src_simple_get, clk);
> -- 
> 1.8.5.1
> 

  reply	other threads:[~2013-12-18  2:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18  0:44 [PATCH v2 00/11] clk: sunxi: PLL4/5/6, mod0 and mbus support Emilio López
2013-12-18  0:44 ` [PATCH v2 01/11] clk: sunxi: register factors clocks behind composite Emilio López
2013-12-18  2:55   ` Mike Turquette [this message]
2013-12-18 11:27     ` Emilio López
2013-12-18  0:44 ` [PATCH v2 02/11] clk: sunxi: add gating support to PLL1 Emilio López
2013-12-18  2:57   ` Mike Turquette
2013-12-18  0:44 ` [PATCH v2 03/11] ARM: sunxi: add PLL4 support Emilio López
2013-12-18  0:44 ` [PATCH v2 04/11] clk: sunxi: make factors_clk_setup return the clock it registers Emilio López
2013-12-18  3:01   ` Mike Turquette
2013-12-18 11:34     ` Emilio López
2013-12-18  0:44 ` [PATCH v2 05/11] clk: sunxi: add PLL5 and PLL6 support Emilio López
2013-12-19  4:59   ` Mike Turquette
2013-12-21  2:26     ` Emilio López
2013-12-18  0:44 ` [PATCH v2 06/11] ARM: " Emilio López
2013-12-18  0:44 ` [PATCH v2 07/11] clk: sunxi: mod0 support Emilio López
2013-12-19  4:59   ` Mike Turquette
2013-12-18  0:45 ` [PATCH v2 08/11] ARM: sun4i: dt: mod0 clocks Emilio López
2013-12-18  9:48   ` Maxime Ripard
2013-12-18 11:40     ` Emilio López
2013-12-18  0:45 ` [PATCH v2 09/11] ARM: sun5i: " Emilio López
2013-12-18  0:45 ` [PATCH v2 10/11] ARM: sun7i: " Emilio López
2013-12-18  0:45 ` [PATCH v2 11/11] ARM: sunxi: dt: add nodes for the mbus clock Emilio López

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131218025527.23538.28216@quantum \
    --to=mturquette@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.