From: pgaikwad@nvidia.com (Prashant Gaikwad)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] clk: Add composite clock type
Date: Sat, 5 Jan 2013 08:19:52 +0530 [thread overview]
Message-ID: <50E794D0.7040907@nvidia.com> (raw)
In-Reply-To: <50E75538.5010706@codeaurora.org>
On Saturday 05 January 2013 03:48 AM, Stephen Boyd wrote:
> On 01/03/13 21:51, Prashant Gaikwad wrote:
>> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
>> index f0b269a..baf7608 100644
>> --- a/drivers/clk/Makefile
>> +++ b/drivers/clk/Makefile
>> @@ -2,7 +2,8 @@
>> obj-$(CONFIG_HAVE_CLK) += clk-devres.o
>> obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o
>> obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \
>> - clk-mux.o clk-divider.o clk-fixed-factor.o
>> + clk-mux.o clk-divider.o clk-fixed-factor.o \
>> + clk-composite.o
> This list is getting a little out of hand. Should we sort it
> alphabetically and put each file on one line?
Do you want me to do it in this patch?
>
>> # SoCs specific
>> obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
>> obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
>> diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
>> new file mode 100644
>> index 0000000..8634dbf
>> --- /dev/null
>> +++ b/drivers/clk/clk-composite.c
>> @@ -0,0 +1,208 @@
>> +/*
>> + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
>> + *
>> + * 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/clk.h>
>> +#include <linux/clk-provider.h>
>> +#include <linux/err.h>
>> +#include <linux/slab.h>
>> +
>> +#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
>> +
>> +static u8 clk_composite_get_parent(struct clk_hw *hw)
>> +{
>> + struct clk_composite *composite = to_clk_composite(hw);
>> + const struct clk_ops *mux_ops = composite->mux_ops;
>> + struct clk_hw *mux_hw = composite->mux_hw;
>> +
>> + mux_hw->clk = hw->clk;
> Looks like this is already done down in the register function. Why are
> we doing it again here and in each op?
Some ops gets called during clk_init which is before clk_register returns.
>> +
>> + return mux_ops->get_parent(mux_hw);
>> +}
> [snip]
>> +struct clk *clk_register_composite(struct device *dev, const char *name,
>> + const char **parent_names, int num_parents,
>> + struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
>> + struct clk_hw *div_hw, const struct clk_ops *div_ops,
>> + struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
>> + unsigned long flags)
>> +{
>> + struct clk *clk;
>> + struct clk_init_data init;
>> + struct clk_composite *composite;
>> + struct clk_ops *clk_composite_ops;
>> +
>> + composite = kzalloc(sizeof(struct clk_ops), GFP_KERNEL);
> sizeof(*composite) != sizeof(struct clk_ops)
Thanks.
>> + if (!composite) {
>> + pr_err("%s: could not allocate composite clk\n", __func__);
>> + return ERR_PTR(-ENOMEM);
>> + }
>> +
>> + init.name = name;
>> + init.flags = flags | CLK_IS_BASIC;
>> + init.parent_names = parent_names;
>> + init.num_parents = num_parents;
>> +
>> + /* allocate the clock ops */
>> + clk_composite_ops = kzalloc(sizeof(struct clk_ops), GFP_KERNEL);
> This one looks right though. Perhaps you should change style to use
> sizeof(*clk_composite_ops) so that the above mistake doesn't happen.
Sure.
>> + if (!clk_composite_ops) {
>> + pr_err("%s: could not allocate clk ops\n", __func__);
>> + kfree(composite);
>> + return ERR_PTR(-ENOMEM);
>> + }
>> +
>> + if (mux_hw && mux_ops) {
>> + if (!mux_ops->get_parent || !mux_ops->set_parent) {
>> + clk = ERR_PTR(-EINVAL);
>> + goto err;
>> + }
>> +
>> + composite->mux_hw = mux_hw;
>> + composite->mux_ops = mux_ops;
>> + clk_composite_ops->get_parent = clk_composite_get_parent;
>> + clk_composite_ops->set_parent = clk_composite_set_parent;
>> + }
>> +
>> + if (div_hw && div_ops) {
>> + if (!div_ops->recalc_rate || !div_ops->round_rate ||
>> + !div_ops->set_rate) {
>> + clk = ERR_PTR(-EINVAL);
>> + goto err;
>> + }
>> +
>> + composite->div_hw = div_hw;
>> + composite->div_ops = div_ops;
>> + clk_composite_ops->recalc_rate = clk_composite_recalc_rate;
>> + clk_composite_ops->round_rate = clk_composite_round_rate;
>> + clk_composite_ops->set_rate = clk_composite_set_rate;
>> + }
>> +
>> + if (gate_hw && gate_ops) {
>> + if (!gate_ops->is_enabled || !gate_ops->enable ||
>> + !gate_ops->disable) {
>> + clk = ERR_PTR(-EINVAL);
>> + goto err;
>> + }
>> +
>> + composite->gate_hw = gate_hw;
>> + composite->gate_ops = gate_ops;
>> + clk_composite_ops->is_enabled = clk_composite_is_enabled;
>> + clk_composite_ops->enable = clk_composite_enable;
>> + clk_composite_ops->disable = clk_composite_disable;
>> + }
>> +
>> + init.ops = clk_composite_ops;
>> + composite->hw.init = &init;
>> +
>> + clk = clk_register(NULL, &composite->hw);
> Please pass dev here.
Yes.
>> + if (IS_ERR(clk))
>> + goto err;
>> +
>> + if (composite->mux_hw)
>> + composite->mux_hw->clk = clk;
>> +
>> + if (composite->div_hw)
>> + composite->div_hw->clk = clk;
>> +
>> + if (composite->gate_hw)
>> + composite->gate_hw->clk = clk;
>> +
>> + return clk;
>> +
>> +err:
>> + kfree(clk_composite_ops);
>> + kfree(composite);
>> + return clk;
>> +}
>>
WARNING: multiple messages have this Message-ID (diff)
From: Prashant Gaikwad <pgaikwad@nvidia.com>
To: Stephen Boyd <sboyd@codeaurora.org>
Cc: "mturquette@linaro.org" <mturquette@linaro.org>,
Stephen Warren <swarren@nvidia.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 1/2] clk: Add composite clock type
Date: Sat, 5 Jan 2013 08:19:52 +0530 [thread overview]
Message-ID: <50E794D0.7040907@nvidia.com> (raw)
In-Reply-To: <50E75538.5010706@codeaurora.org>
On Saturday 05 January 2013 03:48 AM, Stephen Boyd wrote:
> On 01/03/13 21:51, Prashant Gaikwad wrote:
>> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
>> index f0b269a..baf7608 100644
>> --- a/drivers/clk/Makefile
>> +++ b/drivers/clk/Makefile
>> @@ -2,7 +2,8 @@
>> obj-$(CONFIG_HAVE_CLK) += clk-devres.o
>> obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o
>> obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \
>> - clk-mux.o clk-divider.o clk-fixed-factor.o
>> + clk-mux.o clk-divider.o clk-fixed-factor.o \
>> + clk-composite.o
> This list is getting a little out of hand. Should we sort it
> alphabetically and put each file on one line?
Do you want me to do it in this patch?
>
>> # SoCs specific
>> obj-$(CONFIG_ARCH_BCM2835) += clk-bcm2835.o
>> obj-$(CONFIG_ARCH_NOMADIK) += clk-nomadik.o
>> diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
>> new file mode 100644
>> index 0000000..8634dbf
>> --- /dev/null
>> +++ b/drivers/clk/clk-composite.c
>> @@ -0,0 +1,208 @@
>> +/*
>> + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
>> + *
>> + * 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/clk.h>
>> +#include <linux/clk-provider.h>
>> +#include <linux/err.h>
>> +#include <linux/slab.h>
>> +
>> +#define to_clk_composite(_hw) container_of(_hw, struct clk_composite, hw)
>> +
>> +static u8 clk_composite_get_parent(struct clk_hw *hw)
>> +{
>> + struct clk_composite *composite = to_clk_composite(hw);
>> + const struct clk_ops *mux_ops = composite->mux_ops;
>> + struct clk_hw *mux_hw = composite->mux_hw;
>> +
>> + mux_hw->clk = hw->clk;
> Looks like this is already done down in the register function. Why are
> we doing it again here and in each op?
Some ops gets called during clk_init which is before clk_register returns.
>> +
>> + return mux_ops->get_parent(mux_hw);
>> +}
> [snip]
>> +struct clk *clk_register_composite(struct device *dev, const char *name,
>> + const char **parent_names, int num_parents,
>> + struct clk_hw *mux_hw, const struct clk_ops *mux_ops,
>> + struct clk_hw *div_hw, const struct clk_ops *div_ops,
>> + struct clk_hw *gate_hw, const struct clk_ops *gate_ops,
>> + unsigned long flags)
>> +{
>> + struct clk *clk;
>> + struct clk_init_data init;
>> + struct clk_composite *composite;
>> + struct clk_ops *clk_composite_ops;
>> +
>> + composite = kzalloc(sizeof(struct clk_ops), GFP_KERNEL);
> sizeof(*composite) != sizeof(struct clk_ops)
Thanks.
>> + if (!composite) {
>> + pr_err("%s: could not allocate composite clk\n", __func__);
>> + return ERR_PTR(-ENOMEM);
>> + }
>> +
>> + init.name = name;
>> + init.flags = flags | CLK_IS_BASIC;
>> + init.parent_names = parent_names;
>> + init.num_parents = num_parents;
>> +
>> + /* allocate the clock ops */
>> + clk_composite_ops = kzalloc(sizeof(struct clk_ops), GFP_KERNEL);
> This one looks right though. Perhaps you should change style to use
> sizeof(*clk_composite_ops) so that the above mistake doesn't happen.
Sure.
>> + if (!clk_composite_ops) {
>> + pr_err("%s: could not allocate clk ops\n", __func__);
>> + kfree(composite);
>> + return ERR_PTR(-ENOMEM);
>> + }
>> +
>> + if (mux_hw && mux_ops) {
>> + if (!mux_ops->get_parent || !mux_ops->set_parent) {
>> + clk = ERR_PTR(-EINVAL);
>> + goto err;
>> + }
>> +
>> + composite->mux_hw = mux_hw;
>> + composite->mux_ops = mux_ops;
>> + clk_composite_ops->get_parent = clk_composite_get_parent;
>> + clk_composite_ops->set_parent = clk_composite_set_parent;
>> + }
>> +
>> + if (div_hw && div_ops) {
>> + if (!div_ops->recalc_rate || !div_ops->round_rate ||
>> + !div_ops->set_rate) {
>> + clk = ERR_PTR(-EINVAL);
>> + goto err;
>> + }
>> +
>> + composite->div_hw = div_hw;
>> + composite->div_ops = div_ops;
>> + clk_composite_ops->recalc_rate = clk_composite_recalc_rate;
>> + clk_composite_ops->round_rate = clk_composite_round_rate;
>> + clk_composite_ops->set_rate = clk_composite_set_rate;
>> + }
>> +
>> + if (gate_hw && gate_ops) {
>> + if (!gate_ops->is_enabled || !gate_ops->enable ||
>> + !gate_ops->disable) {
>> + clk = ERR_PTR(-EINVAL);
>> + goto err;
>> + }
>> +
>> + composite->gate_hw = gate_hw;
>> + composite->gate_ops = gate_ops;
>> + clk_composite_ops->is_enabled = clk_composite_is_enabled;
>> + clk_composite_ops->enable = clk_composite_enable;
>> + clk_composite_ops->disable = clk_composite_disable;
>> + }
>> +
>> + init.ops = clk_composite_ops;
>> + composite->hw.init = &init;
>> +
>> + clk = clk_register(NULL, &composite->hw);
> Please pass dev here.
Yes.
>> + if (IS_ERR(clk))
>> + goto err;
>> +
>> + if (composite->mux_hw)
>> + composite->mux_hw->clk = clk;
>> +
>> + if (composite->div_hw)
>> + composite->div_hw->clk = clk;
>> +
>> + if (composite->gate_hw)
>> + composite->gate_hw->clk = clk;
>> +
>> + return clk;
>> +
>> +err:
>> + kfree(clk_composite_ops);
>> + kfree(composite);
>> + return clk;
>> +}
>>
next prev parent reply other threads:[~2013-01-05 2:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-04 5:51 [PATCH 1/2] clk: Add composite clock type Prashant Gaikwad
2013-01-04 5:51 ` Prashant Gaikwad
2013-01-04 5:51 ` [PATCH 2/2] clk: tegra30: Convert clk out to composite clk Prashant Gaikwad
2013-01-04 5:51 ` Prashant Gaikwad
2013-01-04 16:25 ` Stephen Warren
2013-01-04 16:25 ` Stephen Warren
2013-01-05 2:53 ` Prashant Gaikwad
2013-01-05 2:53 ` Prashant Gaikwad
2013-01-04 22:18 ` [PATCH 1/2] clk: Add composite clock type Stephen Boyd
2013-01-04 22:18 ` Stephen Boyd
2013-01-05 2:49 ` Prashant Gaikwad [this message]
2013-01-05 2:49 ` Prashant Gaikwad
2013-01-10 21:06 ` Stephen Boyd
2013-01-10 21:06 ` Stephen Boyd
2013-01-18 21:09 ` Mike Turquette
2013-01-18 21:09 ` Mike 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=50E794D0.7040907@nvidia.com \
--to=pgaikwad@nvidia.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.