All of lore.kernel.org
 help / color / mirror / Atom feed
From: hjk@linutronix.de (Hans J. Koch)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/7 v4] Add the clock framework for Telechips TCC8xxx processors.
Date: Fri, 16 Apr 2010 15:09:58 +0200	[thread overview]
Message-ID: <20100416130957.GB1998@bluebox.local> (raw)
In-Reply-To: <20100414133507.GB21526@n2100.arm.linux.org.uk>

On Wed, Apr 14, 2010 at 02:35:07PM +0100, Russell King - ARM Linux wrote:
> On Wed, Mar 31, 2010 at 04:50:58PM +0200, Hans J. Koch wrote:
> > +static void __clk_disable(struct clk *clk)
> > +{
> > +	if (!clk)
> > +		return;
> > +
> > +	BUG_ON(clk->refcount == 0);
> > +
> > +	if (!(--clk->refcount) && clk->disable)
> > +		clk->disable(clk);
> > +	__clk_disable(clk->parent);
> > +}
> > +
> > +static int __clk_enable(struct clk *clk)
> > +{
> > +	if (!clk)
> > +		return -EINVAL;
> > +
> > +	__clk_enable(clk->parent);
> 
> Here, every enable of the child clock causes the parent to be enabled
> one more time.  This is a bad idea in conjunction with...

Something went completely wrong here. These functions should recursively
enable/disable the parents when their refcount changes from/to zero. It's
mentioned in the comments, but not implemented.

> 
> > +
> > +	if (clk->refcount++ == 0 && clk->enable)
> > +		clk->enable(clk);
> > +
> > +	return 0;
> > +}
> 
> > +/* Set the clock's parent to another clock source */
> > +int clk_set_parent(struct clk *clk, struct clk *parent)
> > +{
> > +	int ret = -EINVAL;
> > +
> > +	if (!clk)
> > +		return ret;
> > +	if (!clk->set_parent || !parent)
> > +		return ret;
> > +
> > +	mutex_lock(&clocks_mutex);
> > +	ret = clk->set_parent(clk, parent);
> > +	if (ret == 0)
> > +		clk->parent = parent;
> 
> ... reparenting of clocks.
> 
> Reparenting is much easier to deal with if you only enable/disable the
> parent clock on the first enable and last disable of the child clock.
> Then you can do:
> 
> 	if (clk->refcount)
> 		__clk_enable(parent);
> 	ret = clk->set_parent(clk, parent);
> 	if (ret == 0) {
> 		old = clk->parent;
> 		clk->parent = parent;
> 	} else {
> 		old = parent;
> 	}
> 	if (clk->refcount)
> 		__clk_disable(old);
> 
> here, which will keep the refcounts straight.

Yep, you're right. With __clk_enable and __clk_disable fixed as mentioned
above, it looks a bit different. I hope I got it right this time...

> 
> > +	mutex_unlock(&clocks_mutex);
> > +
> > +	return ret;
> > +}
> > +EXPORT_SYMBOL_GPL(clk_set_parent);
> 
> >  /* Clock controller registers */
> > -#define CKC_BASE		(APB1_PERI_BASE_VIRT + 0x6000)
> > -#define CKC_BASE_PHYS		(APB1_PERI_BASE + 0x6000)
> > +#define CKC_BASE	(void __iomem *)(APB1_PERI_BASE_VIRT + 0x6000)
> 
> This has the possibility of causing unexpected side effects.  With any
> macro which is more than just a number, it's always worth adding a set
> of parens around it to ensure that evaluation happens in the order you
> expect.

Fixed.

Thanks a lot for your review. I'll reply to this mail with the fixed version
of this patch. If it looks OK to you, I'll rebase the whole series to current
mainline (it's still -rc3 now) and submit v5 of the whole lot.

Thanks,
Hans

  reply	other threads:[~2010-04-16 13:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-31 14:45 [PATCH 0/7 v4] Add basic support for Telechips TCC8xxx SoCs Hans J. Koch
2010-03-31 14:49 ` [PATCH 1/7 v4] Introduce plat-tcc Hans J. Koch
2010-03-31 14:50 ` [PATCH 2/7 v4] Add the clock framework for Telechips TCC8xxx processors Hans J. Koch
2010-04-14 13:35   ` Russell King - ARM Linux
2010-04-16 13:09     ` Hans J. Koch [this message]
2010-04-16 13:13       ` Hans J. Koch
2010-03-31 14:52 ` [PATCH 3/7 v4] Introduce plat-tcc irq framework Hans J. Koch
2010-03-31 14:53 ` [PATCH 4/7 v4] Add TCC8xxx system timer Hans J. Koch
2010-03-31 14:54 ` [PATCH 5/7 v4] Basic IO mappings for mach-tcc8k Hans J. Koch
2010-03-31 14:54 ` [PATCH 6/7 v4] Add common platform devices for TCC8xxx SoCs Hans J. Koch
2010-03-31 14:55 ` [PATCH 7/7 v4] Add board support for Telechips TCC8000-SDK board Hans J. Koch

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=20100416130957.GB1998@bluebox.local \
    --to=hjk@linutronix.de \
    --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.