From: mturquette@linaro.org (Michael Turquette)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/3] clk: meson: Add support for Meson clock controller
Date: Fri, 10 Apr 2015 16:31:35 -0700 [thread overview]
Message-ID: <20150410233135.18916.85534@quantum> (raw)
In-Reply-To: <1425313322-18567-2-git-send-email-carlo@caione.org>
Quoting Carlo Caione (2015-03-02 08:22:00)
> +static int meson_clk_cpu_set_rate(struct clk_hw *hw, unsigned long rate,
> + unsigned long parent_rate)
> +{
> + struct meson_clk_cpu *clk_cpu = to_meson_clk_cpu_hw(hw);
> + unsigned int div, sel, N = 0;
> + u32 reg;
> +
> + div = DIV_ROUND_UP(parent_rate, rate);
> +
> + if (div <= 3) {
> + sel = div - 1;
> + } else {
> + sel = 3;
> + N = div / 2;
> + }
> +
> + reg = readl(clk_cpu->base + clk_cpu->reg_off + MESON_CPU_CLK_CNTL1);
> + reg = PARM_SET(MESON_N_WIDTH, MESON_N_SHIFT, reg, N);
> + writel(reg, clk_cpu->base + clk_cpu->reg_off + MESON_CPU_CLK_CNTL1);
> +
> + reg = readl(clk_cpu->base + clk_cpu->reg_off + MESON_CPU_CLK_CNTL);
> + reg = PARM_SET(MESON_SEL_WIDTH, MESON_SEL_SHIFT, reg, sel);
> + writel(reg, clk_cpu->base + clk_cpu->reg_off + MESON_CPU_CLK_CNTL);
> +
> + return 0;
> +}
<snip>
> +static int meson_clk_cpu_pre_rate_change(struct meson_clk_cpu *clk_cpu,
> + struct clk_notifier_data *ndata)
> +{
> + u32 cpu_clk_cntl;
> +
> + spin_lock(clk_cpu->lock);
> +
> + /* switch MUX1 to xtal */
> + cpu_clk_cntl = readl(clk_cpu->base + clk_cpu->reg_off
> + + MESON_CPU_CLK_CNTL);
> + cpu_clk_cntl &= ~MESON_CPU_CLK_MUX1;
> + writel(cpu_clk_cntl, clk_cpu->base + clk_cpu->reg_off
> + + MESON_CPU_CLK_CNTL);
> + udelay(100);
> +
> + /* switch MUX2 to sys-pll */
> + cpu_clk_cntl |= MESON_CPU_CLK_MUX2;
> + writel(cpu_clk_cntl, clk_cpu->base + clk_cpu->reg_off
> + + MESON_CPU_CLK_CNTL);
> +
> + spin_unlock(clk_cpu->lock);
> +
> + return 0;
> +}
> +
> +static int meson_clk_cpu_post_rate_change(struct meson_clk_cpu *clk_cpu,
> + struct clk_notifier_data *ndata)
> +{
> + u32 cpu_clk_cntl;
> +
> + spin_lock(clk_cpu->lock);
> +
> + /* switch MUX1 to divisors' output */
> + cpu_clk_cntl = readl(clk_cpu->base + clk_cpu->reg_off
> + + MESON_CPU_CLK_CNTL);
> + cpu_clk_cntl |= MESON_CPU_CLK_MUX1;
> + writel(cpu_clk_cntl, clk_cpu->base + clk_cpu->reg_off
> + + MESON_CPU_CLK_CNTL);
> + udelay(100);
> +
> + spin_unlock(clk_cpu->lock);
> +
> + return 0;
> +}
> +
> +/*
> + * This clock notifier is called when the frequency of the of the parent
> + * PLL clock is to be changed. We use the xtal input as temporary parent
> + * while the PLL frequency is stabilized.
> + */
> +static int meson_clk_cpu_notifier_cb(struct notifier_block *nb,
> + unsigned long event, void *data)
> +{
> + struct clk_notifier_data *ndata = data;
> + struct meson_clk_cpu *clk_cpu = to_meson_clk_cpu_nb(nb);
> + int ret = 0;
> +
> + if (event == PRE_RATE_CHANGE)
> + ret = meson_clk_cpu_pre_rate_change(clk_cpu, ndata);
> + else if (event == POST_RATE_CHANGE)
> + ret = meson_clk_cpu_post_rate_change(clk_cpu, ndata);
> +
> + return notifier_from_errno(ret);
> +}
Why use a notifier for this? Could you simply call
meson_clk_cpu_{pre,post}_rate_change directly from
meson_clk_cpu_set_rate?
Regards,
Mike
next prev parent reply other threads:[~2015-04-10 23:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-02 16:21 [PATCH 0/3] clk: meson: Add clock controller Carlo Caione
2015-03-02 16:22 ` [PATCH 1/3] clk: meson: Add support for Meson " Carlo Caione
2015-04-10 23:31 ` Michael Turquette [this message]
2015-04-22 7:31 ` Carlo Caione
2015-05-01 8:00 ` Carlo Caione
2015-03-02 16:22 ` [PATCH 2/3] clk: meson: Document bindings for Meson8b " Carlo Caione
2015-03-02 16:22 ` [PATCH 3/3] clk: meson8b: Add support for Meson8b clocks Carlo Caione
2015-03-15 21:03 ` [PATCH 0/3] clk: meson: Add clock controller Carlo Caione
2015-04-10 23:40 ` Michael Turquette
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=20150410233135.18916.85534@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.