From: viresh.kumar@st.com (Viresh KUMAR)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 05/11] ST SPEAr: Added clock framework for SPEAr platform and machines
Date: Fri, 12 Mar 2010 09:49:07 +0530 [thread overview]
Message-ID: <4B99C0BB.7080900@st.com> (raw)
In-Reply-To: <63386a3d1003102300q23ea536bje956f8d5c7e333a2@mail.gmail.com>
On 3/11/2010 12:30 PM, Linus Walleij wrote:
> 2010/3/3 Viresh KUMAR <viresh.kumar@st.com>:
>
>> +{
>> + unsigned int val;
>> +
>> + if (!clk->en_reg)
>> + return -EFAULT;
>> +
>> + val = readl(clk->en_reg);
>> + if (unlikely(clk->flags & RESET_TO_ENABLE))
>> + val &= ~(1 << clk->en_reg_bit);
>> + else
>> + val |= 1 << clk->en_reg_bit;
>> + writel(val, clk->en_reg);
>
> I don't understand one bit of this. What happens if the RESET_TO_ENABLE
> flag is set for the clock? The exact same bit is &-masked and then
> immediately |:ed to 1 again. Then it is written to the register. Practical
> effect: absolutely none.
>
> Is there a writel(val, clk->en_reg); missing from the unlikely() execution
> path?
Already explained by shiraz.
>
>> +
>> + return 0;
>> +}
>> +
>> +static void generic_clk_disable(struct clk *clk)
>> +{
>> + unsigned int val;
>> +
>> + if (!clk->en_reg)
>> + return;
>> +
>> + val = readl(clk->en_reg);
>> + if (unlikely(clk->flags & RESET_TO_ENABLE))
>> + val |= 1 << clk->en_reg_bit;
>> + else
>> + val &= ~(1 << clk->en_reg_bit);
>
> Same issue here...
>
>> +
>> + writel(val, clk->en_reg);
>> +}
>> +
>> +/* generic clk ops */
>> +static struct clkops generic_clkops = {
>> + .enable = generic_clk_enable,
>> + .disable = generic_clk_disable,
>> +};
>> +
>> +/*
>> + * clk_enable - inform the system when the clock source should be running.
>> + * @clk: clock source
>> + *
>> + * If the clock can not be enabled/disabled, this should return success.
>> + *
>> + * Returns success (0) or negative errno.
>> + */
>> +int clk_enable(struct clk *clk)
>> +{
>> + unsigned long flags;
>> + int ret = 0;
>> +
>> + if (!clk || IS_ERR(clk))
>> + return -EFAULT;
>> +
>> + spin_lock_irqsave(&clocks_lock, flags);
>> + if (clk->usage_count++ == 0) {
>
> Isnt if (++clk.>usage_count == 1) easier to understand, or is it just me?
> BTW doing this:
> clk->usage_count++;
> if (clk->usage_count == 1)
> will not use more memory, the compiler optimize this, so choose the
> version you think is most readable. If you think this is very readable, by
> all means keep it.
>
I will simplify it, to make it more readable.
>> + if (clk->ops && clk->ops->enable)
>> + ret = clk->ops->enable(clk);
>> + }
>> + spin_unlock_irqrestore(&clocks_lock, flags);
>> +
>> + return ret;
>> +}
>> +EXPORT_SYMBOL(clk_enable);
>> +
>> +/*
>> + * clk_disable - inform the system when the clock source is no longer required.
>> + * @clk: clock source
>> + *
>> + * Inform the system that a clock source is no longer required by
>> + * a driver and may be shut down.
>> + *
>> + * Implementation detail: if the clock source is shared between
>> + * multiple drivers, clk_enable() calls must be balanced by the
>> + * same number of clk_disable() calls for the clock source to be
>> + * disabled.
>> + */
>> +void clk_disable(struct clk *clk)
>> +{
>> + unsigned long flags;
>> +
>> + if (!clk || IS_ERR(clk))
>> + return;
>> +
>> + WARN_ON(clk->usage_count == 0);
>> +
>> + spin_lock_irqsave(&clocks_lock, flags);
>> + if (--clk->usage_count == 0) {
>
> Same readability issue here.
I will simplify it, to make it more readable.
>
>> + if (!clk || IS_ERR(clk) || !parent || IS_ERR(parent))
>> + return -EFAULT;
>> + if (clk->usage_count == 0)
>> + return -EBUSY;
>
> Why will the clk_set_parent() call fail if there are *no* users of the clock?
> Should it not be the other way around? Or what am I misunderstanding here?
>
My mistake. should be !=.
>> + if (!clk->pclk_sel)
>> + return -EPERM;
>> + if (clk->pclk == parent)
>> + return 0;
>> +
>> + for (i = 0; i < clk->pclk_sel->pclk_count; i++) {
>> + if (clk->pclk_sel->pclk_info[i].pclk == parent) {
>> + found = 1;
>> + break;
>> + }
>> + }
>> +
>> + if (!found)
>> + return -EPERM;
>
> What about -ENODEV or so? (I don't know what people typically
> use for clocks that don't exist.)
Will correct it to return correct error.
>
>> + */
>> +void recalc_root_clocks(void)
>> +{
>> + propagate_rate(&root_clks);
>> +}
>
> I understand (I think) how speed change can propagate through the clocks.
> However I think it will be hard to notify users that the clock rate has changed,
> because there is nothing in the clk framework that supports that. If you have
> drivers with dynamic clocks, do you have any plans on how you will
> notify drivers?
>
> OMAP uses CPUfreq but that is really about the CPU. As it happens, all
> their clk:s always change frequency at the same operating points as the
> CPU. So they can have pre/post calls from CPUfreq in their code, but
> this will not work with things like PrimeCells where other users of the cell
> may not have operating points correlated with CPU operating points.
>
> (I'm not requesting you to solve this problem, more to be aware of it.)
>
already answered by shiraz.
>> diff --git a/arch/arm/plat-spear/include/plat/clkdev.h b/arch/arm/plat-spear/include/plat/clkdev.h
>> +/* clk values */
>> +#define KHZ (1000)
>> +#define MHZ (1000000)
>
> This looks far to generic to be hidden in some weird special architecture.
> And I *think* the preferred way to encode frequencies in the kernel is raw
> Hertz measure with all the extra zeroes.
>
> Doing
> .foo = MHZ *48;
>
> Is a bit awkward, don't you think it's better to do:
> #define MHZ(f) f * 1000000
> .foo = MHZ(48);
>
> If you absolutely want to do this, I would suggest to add the KHZ and MHZ
> macros to some global kernel file but I honestly cannot say which one.
> Perhaps inlcude/linux/clk.h?
>
I will better remove them.
regards,
viresh kumar.
next prev parent reply other threads:[~2010-03-12 4:19 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-03 5:07 [PATCH 00/11] Adding Support for SPEAr Platform under ARM architecture Viresh KUMAR
2010-03-03 5:07 ` [PATCH 01/11] ST SPEAr: Added ARM PrimeXsys System Controller SP810 header file Viresh KUMAR
2010-03-03 5:07 ` [PATCH 02/11] ST SPEAr: Added basic header files for SPEAr3xx machine family Viresh KUMAR
2010-03-03 5:07 ` [PATCH 03/11] ST SPEAr: Added basic header files for SPEAr6xx " Viresh KUMAR
2010-03-03 5:07 ` [PATCH 04/11] ST SPEAr: Added basic header files for SPEAr platform Viresh KUMAR
2010-03-03 5:07 ` [PATCH 05/11] ST SPEAr: Added clock framework for SPEAr platform and machines Viresh KUMAR
2010-03-03 5:07 ` [PATCH 06/11] ST SPEAr: Added source files for SPEAr platform Viresh KUMAR
2010-03-03 5:07 ` [PATCH 07/11] ST SPEAr: Added source files for SPEAr3xx machine family Viresh KUMAR
2010-03-03 5:07 ` [PATCH 08/11] ST SPEAr: Added source files for SPEAr6xx " Viresh KUMAR
2010-03-03 5:07 ` [PATCH 09/11] ST SPEAr: Added support for SPEAr platform and machines in arch/arm/ Viresh KUMAR
2010-03-03 5:07 ` [PATCH 10/11] ST SPEAr: Added default configuration files for SPEAr machines Viresh KUMAR
2010-03-03 5:07 ` [PATCH 11/11] ST SPEAr: Updated Maintainers and added Documentation/arm/SPEAr Viresh KUMAR
2010-03-11 20:18 ` [PATCH 10/11] ST SPEAr: Added default configuration files for SPEAr machines Linus Walleij
2010-03-11 20:26 ` Russell King - ARM Linux
2010-03-12 4:12 ` Viresh KUMAR
2010-03-09 6:46 ` [PATCH 07/11] ST SPEAr: Added source files for SPEAr3xx machine family Linus Walleij
2010-03-09 7:05 ` Viresh KUMAR
2010-03-10 5:15 ` Linus Walleij
2010-03-10 6:10 ` viresh kumar
2010-03-11 10:41 ` Russell King - ARM Linux
2010-03-12 5:19 ` Viresh KUMAR
2010-03-11 11:22 ` [PATCH 06/11] ST SPEAr: Added source files for SPEAr platform Linus Walleij
2010-03-11 7:00 ` [PATCH 05/11] ST SPEAr: Added clock framework for SPEAr platform and machines Linus Walleij
2010-03-11 10:18 ` Shiraz HASHIM
2010-03-12 8:46 ` Linus Walleij
2010-03-12 4:19 ` Viresh KUMAR [this message]
2010-03-11 10:28 ` Russell King - ARM Linux
2010-03-12 4:22 ` Viresh KUMAR
2010-03-10 5:40 ` [PATCH 04/11] ST SPEAr: Added basic header files for SPEAr platform Linus Walleij
2010-03-10 6:32 ` Viresh KUMAR
2010-03-10 9:31 ` Linus Walleij
2010-03-10 10:11 ` Viresh KUMAR
2010-03-10 14:16 ` Paul Mundt
2010-03-10 16:36 ` Thomas Gleixner
2010-03-10 22:16 ` Tony Lindgren
2010-03-10 23:29 ` Paul Mundt
2010-03-10 23:42 ` Thomas Gleixner
2010-03-11 6:43 ` Linus Walleij
2010-03-11 9:47 ` Shiraz HASHIM
2010-03-11 11:26 ` Linus Walleij
2010-03-09 20:42 ` [PATCH 02/11] ST SPEAr: Added basic header files for SPEAr3xx machine family Linus Walleij
2010-03-10 6:01 ` Viresh KUMAR
2010-03-10 6:07 ` Linus Walleij
2010-03-11 10:33 ` Russell King - ARM Linux
2010-03-12 4:39 ` Viresh KUMAR
2010-03-09 20:14 ` [PATCH 01/11] ST SPEAr: Added ARM PrimeXsys System Controller SP810 header file Linus Walleij
2010-03-10 5:09 ` Viresh KUMAR
2010-03-11 10:45 ` Russell King - ARM Linux
2010-03-12 5:19 ` Viresh KUMAR
2010-03-07 15:54 ` [PATCH 00/11] Adding Support for SPEAr Platform under ARM architecture viresh kumar
2010-03-08 13:48 ` Armando VISCONTI
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=4B99C0BB.7080900@st.com \
--to=viresh.kumar@st.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).