LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Haavard Skinnemoen <hskinnemoen@atmel.com>
To: David Brownell <david-b@pacbell.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Andrew Victor <linux@maxim.org.za>,
	Nicolas Ferre <nicolas.ferre@rfo.atmel.com>
Subject: Re: [patch 2.6.25-rc2-git 1/2] atmel_tc library
Date: Sun, 24 Feb 2008 18:45:54 +0100	[thread overview]
Message-ID: <20080224184554.2c863f63@siona> (raw)
In-Reply-To: <200802221723.24003.david-b@pacbell.net>

On Fri, 22 Feb 2008 17:23:23 -0800
David Brownell <david-b@pacbell.net> wrote:

> Create <linux/atmel_tc.h> based on <asm-arm/arch-at91/at91-tc.h> and the
> at91sam9263 and at32ap7000 datasheets.  Most AT91 and AT32 SOCs have one
> or two of these TC blocks, which include three 16-bit timers that can be
> interconnected in various ways.
> 
> These TC blocks can be used for external interfacing (such as PWM and
> measurement), or used as somewhat quirky sixteen-bit timers.
> 
> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
> ---

Sorry for the delay...some late comments coming up.

> Note that this won't be usable until the AT91 and AT32 platforms
> incorporate patches to configure the relevant platform devices.
> Those changes are probably 2.6.26 material.

Right...and there are a few funny dependencies we need to watch out
for. AVR32 currently uses one of the TC blocks as a system timer. That
code needs to be ripped out, but that will cause a fourfold increase in
the power consumption of the AP7000 CPU. So I want to keep the window
between ripping out the old code and using the new code as small as
possible.

I see the following possibilities:
  * I switch avr32 over to use the new code after it has been merged
    into mainline. This means the new code won't be tested on avr32
    until near the end of the next merge window -- not good.
  * I forward the patches that switch avr32 over to Andrew so that they
    can be included in -mm right after the tclib support. Not a bad
    option, but I'm planning to do more AVR32 PM work before 2.6.26, so
    there might be conflicts.
  * I take the whole thing through my avr32 git tree.
  * I (or someone else) set up a new git tree for tclib + AT91 and
    AVR32 platform support and ask Stephen to pull it into the -next
    tree. Or, once it's stable, rmk and I can both pull it into our
    respective trees. But that obviously means no rebasing and funny
    games from that point on...

I think the last option is the best one. What do you think?

> +#if defined(CONFIG_AVR32)
> +/* AVR32 has these divide PBB */
> +const u8 atmel_tc_divisors[5] = { 0, 4, 8, 16, 32, };
> +EXPORT_SYMBOL(atmel_tc_divisors);
> +
> +#elif defined(CONFIG_ARCH_AT91)
> +/* AT91 has these divide MCK */
> +const u8 atmel_tc_divisors[5] = { 2, 8, 32, 128, 0, };
> +EXPORT_SYMBOL(atmel_tc_divisors);
> +
> +#endif
> +
> +/* we "know" that there will be either one or two TC blocks */
> +static struct platform_device *blocks[2];

You seem to know more about future Atmel chips than I do :-P

I'm not a huge fan of such static limitations. Is there any way we can
turn it into a list? That probably means defining a struct atmel_tc
around each platform_device, but that might be nice to have for other
reasons too.

> +/**
> + * atmel_tc_alloc - allocate a specified TC block
> + * @block: which block to allocate
> + * @iomem: used to return its IO memory resource
> + *
> + * Caller allocates a block.  If it is available, its I/O space is requested
> + * and returned through the iomem pointer, and the device node for the block
> + * is returned.  When it is not available, NULL is returned.

Any reason why it can't ioremap() the registers as well? Most drivers
probably want that.

> + * On some platforms, each TC channel has its own clocks and IRQs.  Drivers
> + * should clk_get() and clk_enable() "t0_clk", "t1_clk, and "t2_clk".
> + * In the same vein, they should platform_get_irq() for irqs 0, 1, and 2.
> + * On other platforms, only irq 0 and "t0_clk" will be available; drivers
> + * should handle with both configurations.

Sounds complicated. I think it would be better if tclib did all the
clk_get() calls and stored each clock into the atmel_tc struct so that
the driver can simply clk_enable() each channel (which may point to the
same clock.)

> +struct platform_device *atmel_tc_alloc(unsigned block, struct resource **iomem)
> +{
> +	struct platform_device	*tc;
> +	struct resource		*r;
> +
> +	if (block >= ARRAY_SIZE(blocks) || !iomem)
> +		return NULL;
> +
> +	tc = blocks[block];
> +	if (tc) {
> +		r = platform_get_resource(tc, IORESOURCE_MEM, 0);
> +		if (r)
> +			r = request_mem_region(r->start, 256, NULL);

Shouldn't you use the real resource size instead of some magic number?

> +static struct platform_driver tc_driver = {
> +	.driver.name	= "atmel_tcb",

Wow, I didn't know that was possible...

> +#define ATMEL_TC_BMR	0xc4		/* TC Block Mode Register */
> +#define     ATMEL_TC_TC0XC0S	(3 << 0)	/* external clock 0 source */
> +#define        ATMEL_TC_TC0XC0S_TCLK0	(0 << 0)

Hmm. Indentation using spaces? I didn't know you were into that sort of
thing ;-)

Anyway, my main issue is that I think we should add a data structure
with information about each device, similar to struct ssc_device in the
atmel-ssc driver. How about something like this?

struct atmel_tc_block {
	void __iomem		*regs;	/* non-NULL when busy */
	struct platform_device	*pdev;
	struct clk		*clk[3];
	struct list_head	node;
};

Haavard

  reply	other threads:[~2008-02-24 17:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-23  1:23 David Brownell
2008-02-24 17:45 ` Haavard Skinnemoen [this message]
2008-02-24 22:55   ` David Brownell
2008-02-25  0:26     ` Haavard Skinnemoen
2008-02-25  1:03       ` David Brownell
2008-02-25 11:43         ` Haavard Skinnemoen
2008-02-25 18:06           ` David Brownell
2008-02-26  9:08             ` Haavard Skinnemoen
2008-02-26  9:17               ` David Brownell

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=20080224184554.2c863f63@siona \
    --to=hskinnemoen@atmel.com \
    --cc=akpm@linux-foundation.org \
    --cc=david-b@pacbell.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@maxim.org.za \
    --cc=nicolas.ferre@rfo.atmel.com \
    --subject='Re: [patch 2.6.25-rc2-git 1/2] atmel_tc library' \
    /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

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).