From: sebastian.hesselbarth@gmail.com (Sebastian Hesselbarth)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/5] clk: berlin: add support for clocks
Date: Wed, 23 Apr 2014 19:03:07 +0200 [thread overview]
Message-ID: <5357F24B.8070405@gmail.com> (raw)
In-Reply-To: <1398261667-12621-2-git-send-email-alexandre.belloni@free-electrons.com>
On 04/23/2014 04:01 PM, Alexandre Belloni wrote:
> Add support for clocks having their own register set.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> drivers/clk/berlin/Makefile | 2 +-
> drivers/clk/berlin/clk.c | 132 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 133 insertions(+), 1 deletion(-)
> create mode 100644 drivers/clk/berlin/clk.c
>
> diff --git a/drivers/clk/berlin/Makefile b/drivers/clk/berlin/Makefile
> index 94859513de90..9bfa58eaf25a 100644
> --- a/drivers/clk/berlin/Makefile
> +++ b/drivers/clk/berlin/Makefile
> @@ -1,4 +1,4 @@
> -obj-y += pll.o
> +obj-y += pll.o clk.o
> obj-$(CONFIG_MACH_BERLIN_BG2) += pll-berlin2.o
> obj-$(CONFIG_MACH_BERLIN_BG2CD) += pll-berlin2.o
> obj-$(CONFIG_MACH_BERLIN_BG2Q) += pll-berlin2q.o
> diff --git a/drivers/clk/berlin/clk.c b/drivers/clk/berlin/clk.c
> new file mode 100644
> index 000000000000..a0e688e5bead
> --- /dev/null
> +++ b/drivers/clk/berlin/clk.c
> @@ -0,0 +1,132 @@
> +/*
> + * Copyright (c) 2014 Marvell Technology Group Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +#include <linux/bitops.h>
> +#include <linux/clk-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/slab.h>
> +
> +#include "common.h"
> +
> +#define CLKEN (1 << 0)
Alexandre,
please use BIT(n) instead of (1 << n).
> +#define CLKPLLSEL_MASK 7
> +#define CLKPLLSEL_SHIFT 1
> +#define CLKPLLSWITCH (1 << 4)
> +#define CLKSWITCH (1 << 5)
> +#define CLKD3SWITCH (1 << 6)
> +#define CLKSEL_MASK 7
> +#define CLKSEL_SHIFT 7
In general, I would change the above defines to CLK_SEL_MASK, i.e.
add a _ after CLK. While at it (as it can be seen from the code
below), also rename CLK_D3SWITCH to CLK_DIV3_SWITCH.
> +
> +struct berlin_clk {
> + struct clk_hw hw;
> + void __iomem *base;
> +};
> +
> +#define to_berlin_clk(hw) container_of(hw, struct berlin_clk, hw)
> +
> +static u8 clk_div[] = {1, 2, 4, 6, 8, 12, 1, 1};
> +
> +static unsigned long berlin_clk_recalc_rate(struct clk_hw *hw,
> + unsigned long parent_rate)
> +{
> + u32 val, divider;
> + struct berlin_clk *clk = to_berlin_clk(hw);
> +
> + val = readl_relaxed(clk->base);
> + if (val & CLKD3SWITCH)
> + divider = 3;
> + else {
> + if (val & CLKSWITCH) {
> + val >>= CLKSEL_SHIFT;
> + val &= CLKSEL_MASK;
> + divider = clk_div[val];
> + } else
> + divider = 1;
> + }
> +
There are stylistic issues:
if-else with one part being enclosed in {} requires both parts
to be enclosed in those curly brackets, i.e.
if (foo)
bar;
else {
foobar;
barfoo;
}
has to become
if (foo) {
bar;
} else {
foobar;
barfoo;
}
How about writing the above
> + val = readl_relaxed(clk->base);
> + if (val & CLKD3SWITCH)
> + divider = 3;
> + else {
> + if (val & CLKSWITCH) {
> + val >>= CLKSEL_SHIFT;
> + val &= CLKSEL_MASK;
> + divider = clk_div[val];
> + } else
> + divider = 1;
> + }
> + return parent_rate / divider;
> +}
> +
> +static u8 berlin_clk_get_parent(struct clk_hw *hw)
> +{
> + u32 val;
> + struct berlin_clk *clk = to_berlin_clk(hw);
> +
> + val = readl_relaxed(clk->base);
> + if (val & CLKPLLSWITCH) {
> + val >>= CLKPLLSEL_SHIFT;
> + val &= CLKPLLSEL_MASK;
> + return val;
> + }
> +
> + return 0;
> +}
> +
> +static const struct clk_ops berlin_clk_ops = {
> + .recalc_rate = berlin_clk_recalc_rate,
> + .get_parent = berlin_clk_get_parent,
> +};
> +
> +static void __init berlin_clk_setup(struct device_node *np)
> +{
> + struct clk_init_data init;
> + struct berlin_clk *bclk;
> + struct clk *clk;
> + const char **parent_names;
> + int nparents, i, ret;
> +
> + bclk = kzalloc(sizeof(*bclk), GFP_KERNEL);
> + if (WARN_ON(!bclk))
> + return;
> +
> + bclk->base = of_iomap(np, 0);
> + if (WARN_ON(!bclk->base))
> + goto exit;
> +
> + nparents = of_clk_get_parent_count(np);
> + if (WARN_ON(!nparents))
> + goto exit;
> +
> + parent_names = kzalloc((sizeof(char *) * nparents), GFP_KERNEL);
> + if (WARN_ON(!parent_names))
> + goto exit;
> +
> + init.name = np->name;
> + init.ops = &berlin_clk_ops;
> + for (i = 0; i < nparents; i++) {
> + parent_names[i] = of_clk_get_parent_name(np, i);
> + if (!parent_names[i])
> + break;
> + }
> + init.parent_names = parent_names;
> + init.num_parents = i;
> +
> + bclk->hw.init = &init;
> +
> + clk = clk_register(NULL, &bclk->hw);
> + kfree(parent_names);
> + if (WARN_ON(IS_ERR(clk)))
> + goto exit;
> +
> + ret = of_clk_add_provider(np, of_clk_src_simple_get, clk);
> + WARN_ON(ret);
> +
> + return;
> +exit:
> + kfree(bclk);
> +}
> +
> +CLK_OF_DECLARE(berlin_clk, "marvell,berlin-clk", berlin_clk_setup);
>
WARNING: multiple messages have this Message-ID (diff)
From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Alexandre Belloni <alexandre.belloni@free-electrons.com>,
Mike Turquette <mturquette@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] clk: berlin: add support for clocks
Date: Wed, 23 Apr 2014 19:03:07 +0200 [thread overview]
Message-ID: <5357F24B.8070405@gmail.com> (raw)
In-Reply-To: <1398261667-12621-2-git-send-email-alexandre.belloni@free-electrons.com>
On 04/23/2014 04:01 PM, Alexandre Belloni wrote:
> Add support for clocks having their own register set.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> drivers/clk/berlin/Makefile | 2 +-
> drivers/clk/berlin/clk.c | 132 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 133 insertions(+), 1 deletion(-)
> create mode 100644 drivers/clk/berlin/clk.c
>
> diff --git a/drivers/clk/berlin/Makefile b/drivers/clk/berlin/Makefile
> index 94859513de90..9bfa58eaf25a 100644
> --- a/drivers/clk/berlin/Makefile
> +++ b/drivers/clk/berlin/Makefile
> @@ -1,4 +1,4 @@
> -obj-y += pll.o
> +obj-y += pll.o clk.o
> obj-$(CONFIG_MACH_BERLIN_BG2) += pll-berlin2.o
> obj-$(CONFIG_MACH_BERLIN_BG2CD) += pll-berlin2.o
> obj-$(CONFIG_MACH_BERLIN_BG2Q) += pll-berlin2q.o
> diff --git a/drivers/clk/berlin/clk.c b/drivers/clk/berlin/clk.c
> new file mode 100644
> index 000000000000..a0e688e5bead
> --- /dev/null
> +++ b/drivers/clk/berlin/clk.c
> @@ -0,0 +1,132 @@
> +/*
> + * Copyright (c) 2014 Marvell Technology Group Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +#include <linux/bitops.h>
> +#include <linux/clk-provider.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/slab.h>
> +
> +#include "common.h"
> +
> +#define CLKEN (1 << 0)
Alexandre,
please use BIT(n) instead of (1 << n).
> +#define CLKPLLSEL_MASK 7
> +#define CLKPLLSEL_SHIFT 1
> +#define CLKPLLSWITCH (1 << 4)
> +#define CLKSWITCH (1 << 5)
> +#define CLKD3SWITCH (1 << 6)
> +#define CLKSEL_MASK 7
> +#define CLKSEL_SHIFT 7
In general, I would change the above defines to CLK_SEL_MASK, i.e.
add a _ after CLK. While at it (as it can be seen from the code
below), also rename CLK_D3SWITCH to CLK_DIV3_SWITCH.
> +
> +struct berlin_clk {
> + struct clk_hw hw;
> + void __iomem *base;
> +};
> +
> +#define to_berlin_clk(hw) container_of(hw, struct berlin_clk, hw)
> +
> +static u8 clk_div[] = {1, 2, 4, 6, 8, 12, 1, 1};
> +
> +static unsigned long berlin_clk_recalc_rate(struct clk_hw *hw,
> + unsigned long parent_rate)
> +{
> + u32 val, divider;
> + struct berlin_clk *clk = to_berlin_clk(hw);
> +
> + val = readl_relaxed(clk->base);
> + if (val & CLKD3SWITCH)
> + divider = 3;
> + else {
> + if (val & CLKSWITCH) {
> + val >>= CLKSEL_SHIFT;
> + val &= CLKSEL_MASK;
> + divider = clk_div[val];
> + } else
> + divider = 1;
> + }
> +
There are stylistic issues:
if-else with one part being enclosed in {} requires both parts
to be enclosed in those curly brackets, i.e.
if (foo)
bar;
else {
foobar;
barfoo;
}
has to become
if (foo) {
bar;
} else {
foobar;
barfoo;
}
How about writing the above
> + val = readl_relaxed(clk->base);
> + if (val & CLKD3SWITCH)
> + divider = 3;
> + else {
> + if (val & CLKSWITCH) {
> + val >>= CLKSEL_SHIFT;
> + val &= CLKSEL_MASK;
> + divider = clk_div[val];
> + } else
> + divider = 1;
> + }
> + return parent_rate / divider;
> +}
> +
> +static u8 berlin_clk_get_parent(struct clk_hw *hw)
> +{
> + u32 val;
> + struct berlin_clk *clk = to_berlin_clk(hw);
> +
> + val = readl_relaxed(clk->base);
> + if (val & CLKPLLSWITCH) {
> + val >>= CLKPLLSEL_SHIFT;
> + val &= CLKPLLSEL_MASK;
> + return val;
> + }
> +
> + return 0;
> +}
> +
> +static const struct clk_ops berlin_clk_ops = {
> + .recalc_rate = berlin_clk_recalc_rate,
> + .get_parent = berlin_clk_get_parent,
> +};
> +
> +static void __init berlin_clk_setup(struct device_node *np)
> +{
> + struct clk_init_data init;
> + struct berlin_clk *bclk;
> + struct clk *clk;
> + const char **parent_names;
> + int nparents, i, ret;
> +
> + bclk = kzalloc(sizeof(*bclk), GFP_KERNEL);
> + if (WARN_ON(!bclk))
> + return;
> +
> + bclk->base = of_iomap(np, 0);
> + if (WARN_ON(!bclk->base))
> + goto exit;
> +
> + nparents = of_clk_get_parent_count(np);
> + if (WARN_ON(!nparents))
> + goto exit;
> +
> + parent_names = kzalloc((sizeof(char *) * nparents), GFP_KERNEL);
> + if (WARN_ON(!parent_names))
> + goto exit;
> +
> + init.name = np->name;
> + init.ops = &berlin_clk_ops;
> + for (i = 0; i < nparents; i++) {
> + parent_names[i] = of_clk_get_parent_name(np, i);
> + if (!parent_names[i])
> + break;
> + }
> + init.parent_names = parent_names;
> + init.num_parents = i;
> +
> + bclk->hw.init = &init;
> +
> + clk = clk_register(NULL, &bclk->hw);
> + kfree(parent_names);
> + if (WARN_ON(IS_ERR(clk)))
> + goto exit;
> +
> + ret = of_clk_add_provider(np, of_clk_src_simple_get, clk);
> + WARN_ON(ret);
> +
> + return;
> +exit:
> + kfree(bclk);
> +}
> +
> +CLK_OF_DECLARE(berlin_clk, "marvell,berlin-clk", berlin_clk_setup);
>
next prev parent reply other threads:[~2014-04-23 17:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 14:01 [PATCH 0/5] Berlin: add clock support Alexandre Belloni
2014-04-23 14:01 ` Alexandre Belloni
2014-04-23 14:01 ` [PATCH 1/5] clk: berlin: add support for clocks Alexandre Belloni
2014-04-23 14:01 ` Alexandre Belloni
2014-04-23 17:03 ` Sebastian Hesselbarth [this message]
2014-04-23 17:03 ` Sebastian Hesselbarth
2014-04-23 17:10 ` Sebastian Hesselbarth
2014-04-23 17:10 ` Sebastian Hesselbarth
2014-04-23 14:01 ` [PATCH 2/5] clk: berlin: add berlin clocks DT bindings documentation Alexandre Belloni
2014-04-23 14:01 ` Alexandre Belloni
2014-04-23 17:21 ` Sebastian Hesselbarth
2014-04-23 17:21 ` Sebastian Hesselbarth
2014-04-23 14:01 ` [PATCH 3/5] ARM: berlin/dt: add sdio clocks to BG2 Alexandre Belloni
2014-04-23 14:01 ` Alexandre Belloni
2014-04-23 14:01 ` [PATCH 4/5] ARM: berlin/dt: add sdio clocks to BG2CD Alexandre Belloni
2014-04-23 14:01 ` Alexandre Belloni
2014-04-23 22:51 ` Antoine Ténart
2014-04-23 22:51 ` Antoine Ténart
2014-04-23 14:01 ` [PATCH 5/5] ARM: berlin/dt: add sdio clocks to BG2Q Alexandre Belloni
2014-04-23 14:01 ` Alexandre Belloni
2014-04-23 22:49 ` Antoine Ténart
2014-04-23 22:49 ` Antoine Ténart
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=5357F24B.8070405@gmail.com \
--to=sebastian.hesselbarth@gmail.com \
--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.