linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 2/7] ARM: mmp: parse timer configuration from DT
Date: Fri, 29 Jul 2011 10:40:45 -0600	[thread overview]
Message-ID: <20110729164045.GK11164@ponder.secretlab.ca> (raw)
In-Reply-To: <1311835293-18125-3-git-send-email-haojian.zhuang@marvell.com>

On Thu, Jul 28, 2011 at 02:41:28PM +0800, Haojian Zhuang wrote:
> Parse timer configuration from DT. Now we can merge pxa910_timer and
> mmp2_timer into mmp_timer. Since most configuration between these two
> timers are same. The difference is recorded in DT.
> 
> Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
> ---
>  .../devicetree/bindings/arm/marvell/timer.txt      |   24 +++++++++
>  arch/arm/mach-mmp/common.h                         |    2 +
>  arch/arm/mach-mmp/time.c                           |   50 +++++++++++++++++++-
>  3 files changed, 75 insertions(+), 1 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/arm/marvell/timer.txt
> 
> diff --git a/Documentation/devicetree/bindings/arm/marvell/timer.txt b/Documentation/devicetree/bindings/arm/marvell/timer.txt
> new file mode 100644
> index 0000000..24a6f97
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/marvell/timer.txt
> @@ -0,0 +1,24 @@
> +* Timer Controller Binding for ARCH-MMP
> +
> +This binding specifies what properties must be available in device tree
> +representation of an ARCH-MMP compliant timer controller.
> +
> +Required properties:
> +
> +	- compatible: Specifies the compatibility list of the timer controller.
> +	  The type shall be <string> and the value shall be
> +	  "mrvl,pxa168-timer".
> +
> +	- mrvl,clk-conf: Specifies the address and value of timer 
> +	  configuration register.
> +	  The type shall be <prop-encoded-array>. The first value indicates
> +	  the physical address of timer configuration register. The second
> +	  value indicates data should be written to timer configuration
> +	  register.
> +
> +* Example
> +
> +	mmp_timer: {
> +		compatible = "mrvl,pxa168-timer";
> +		mrvl,clk-conf = <0xd4000034 0x33>;
> +	};
> diff --git a/arch/arm/mach-mmp/common.h b/arch/arm/mach-mmp/common.h
> index 1c563c2..890c664 100644
> --- a/arch/arm/mach-mmp/common.h
> +++ b/arch/arm/mach-mmp/common.h
> @@ -2,6 +2,8 @@
>  
>  struct sys_timer;
>  
> +extern struct sys_timer mmp_timer;
> +
>  extern void timer_init(int irq);
>  
>  extern void __init icu_init_irq(void);
> diff --git a/arch/arm/mach-mmp/time.c b/arch/arm/mach-mmp/time.c
> index 99833b9..5a90b27 100644
> --- a/arch/arm/mach-mmp/time.c
> +++ b/arch/arm/mach-mmp/time.c
> @@ -25,6 +25,8 @@
>  
>  #include <linux/io.h>
>  #include <linux/irq.h>
> +#include <linux/of.h>
> +#include <linux/of_irq.h>
>  #include <linux/sched.h>
>  
>  #include <asm/sched_clock.h>
> @@ -150,7 +152,7 @@ static void __init timer_config(void)
>  
>  	__raw_writel(cer & ~0x1, TIMERS_VIRT_BASE + TMR_CER); /* disable */
>  
> -	ccr &= (cpu_is_mmp2()) ? TMR_CCR_CS_0(0) : TMR_CCR_CS_0(3);
> +	ccr &= TMR_CCR_CS_0(0);
>  	__raw_writel(ccr, TIMERS_VIRT_BASE + TMR_CCR);
>  
>  	/* free-running mode */
> @@ -187,3 +189,49 @@ void __init timer_init(int irq)
>  	clocksource_register_hz(&cksrc, CLOCK_TICK_RATE);
>  	clockevents_register_device(&ckevt);
>  }
> +
> +#ifdef CONFIG_OF
> +static void __init mmp_timer_init(void)
> +{
> +	struct device_node *np;
> +	const __be32 *clk_offs;
> +	void __iomem *conf;
> +	unsigned int addr = 0, offs = 0;
> +	int size, irq;
> +
> +	np = of_find_compatible_node(NULL, NULL, "mrvl,pxa168-timer");
> +
> +	BUG_ON(!np);
> +
> +	of_node_get(np);
> +	irq = irq_of_parse_and_map(np, 0);
> +
> +	clk_offs = of_get_property(np, "mrvl,clk-conf", &size);
> +	if ((clk_offs == NULL) || (size != sizeof(int) * 2)) {

sizeof(u32)

I would recommend using of_property_read_u32_array() which does the
sanity checking for you.

> +		pr_warn("mmp-timer: mrvl,clk-conf property is wrong\n");
> +		goto out;
> +	}
> +	addr = be32_to_cpu(*clk_offs) & PAGE_MASK;
> +	offs = be32_to_cpu(*clk_offs) - addr;
> +	conf = ioremap(addr, PAGE_SIZE);

base addresses should be in a 'reg' property.  I would put the
register region into a 'reg' tuple so that of_iomap() works, and then
encode just the offset/config-value pair into mrvl,clk-conf.

> +	if (conf == NULL) {
> +		pr_warn("mmp-timer: failed on mapping 0x%x\n", (uint32_t)conf);
> +		goto out;
> +	}
> +	/* reset and configure */
> +	__raw_writel(APBC_APBCLK | APBC_RST, conf + offs);
> +	__raw_writel(be32_to_cpu(*++clk_offs), conf + offs);
> +	__raw_readl(conf + offs);
> +	iounmap(conf);
> +
> +	timer_init(irq);
> +	return;
> +out:
> +	of_node_put(np);
> +	return;
> +}
> +
> +struct sys_timer mmp_timer = {
> +	.init	= mmp_timer_init,
> +};
> +#endif
> -- 
> 1.5.6.5
> 

  parent reply	other threads:[~2011-07-29 16:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-28  6:41 [PATCH v2 00/07] enable devicetree on arch-mmp Haojian Zhuang
2011-07-28  6:41 ` [PATCH v2 1/7] ARM: mmp: parse irq from DT Haojian Zhuang
2011-07-28  6:41   ` [PATCH v2 2/7] ARM: mmp: parse timer configuration " Haojian Zhuang
2011-07-28  6:41     ` [PATCH v2 3/7] ARM: mmp: support DT on both dkb and brownstone Haojian Zhuang
2011-07-28  6:41       ` [PATCH v2 4/7] tty: serial: support device tree in pxa Haojian Zhuang
2011-07-28  6:41         ` [PATCH v2 5/7] tty: serial: check ops before registering console Haojian Zhuang
2011-07-28  6:41           ` [PATCH v2 6/7] i2c: pxa: support i2c controller from DT Haojian Zhuang
2011-07-28  6:41             ` [PATCH v2 7/7] i2c: pxa: support to parse property Haojian Zhuang
2011-07-29 16:52             ` [PATCH v2 6/7] i2c: pxa: support i2c controller from DT Grant Likely
2011-07-29 16:55               ` Russell King - ARM Linux
2011-07-30 14:29                 ` Mitch Bradley
2011-07-30 15:37                   ` Russell King - ARM Linux
2011-07-31  0:38                     ` Grant Likely
2011-07-29 16:45         ` [PATCH v2 4/7] tty: serial: support device tree in pxa Grant Likely
2011-07-29 16:49           ` Russell King - ARM Linux
2011-07-29 16:53             ` Grant Likely
2011-08-01  2:50             ` Haojian Zhuang
2011-08-01  8:27               ` Russell King - ARM Linux
2011-07-29 16:42       ` [PATCH v2 3/7] ARM: mmp: support DT on both dkb and brownstone Grant Likely
2011-08-01  2:48         ` Haojian Zhuang
2011-07-29 16:40     ` Grant Likely [this message]
2011-07-29 16:36   ` [PATCH v2 1/7] ARM: mmp: parse irq from DT Grant Likely
2011-08-01  2:47     ` Haojian Zhuang
2011-08-01 14:10       ` Grant Likely
2011-08-01 14:42         ` Haojian Zhuang
2011-08-01 14:43           ` Grant Likely
2011-08-01  8:26   ` Russell King - ARM Linux

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=20110729164045.GK11164@ponder.secretlab.ca \
    --to=grant.likely@secretlab.ca \
    --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).