public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv3 2/4] armv7: Add ST-Ericsson u8500 arch
Date: Tue, 12 Apr 2011 09:25:01 +0200	[thread overview]
Message-ID: <4DA3FE4D.9080003@aribaud.net> (raw)
In-Reply-To: <1302589067-3688-3-git-send-email-john.rigby@linaro.org>

Hi John,

Le 12/04/2011 08:17, John Rigby a ?crit :

> diff --git a/arch/arm/cpu/armv7/u8500/lowlevel.S b/arch/arm/cpu/armv7/u8500/lowlevel.S
> new file mode 100644
> index 0000000..0e3f8fc
> --- /dev/null
> +++ b/arch/arm/cpu/armv7/u8500/lowlevel.S
> @@ -0,0 +1,33 @@
> +/*
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that 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, write to the Free Software
> + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */

Please add a copyright notice identifying the right holder(s). Readers 
*must* be able to tell who the rights holders are and how to contact 
them -- don't assume the file is too simple to qualify.

> diff --git a/arch/arm/cpu/armv7/u8500/timer.c b/arch/arm/cpu/armv7/u8500/timer.c
> new file mode 100644
> index 0000000..8850fd5
> --- /dev/null
> +++ b/arch/arm/cpu/armv7/u8500/timer.c
> @@ -0,0 +1,167 @@
> +/*
> + * Copyright (C) 2010 Linaro Limited
> + * John Rigby<john.rigby@linaro.org>
> + *
> + * Based on original from Linux kernel source and
> + * internal ST-Ericsson U-Boot source.
> + * (C) Copyright 2009 Alessandro Rubini
> + * (C) Copyright 2010 ST-Ericsson
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that 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, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include<common.h>
> +#include<asm/io.h>
> +#include<asm/arch/hardware.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +/*
> + * The MTU device has some interrupt control registers
> + * followed by 4 timers.
> + */
> +
> +/* The timers */
> +struct u8500_mtu_timer {
> +	u32 lr;			/* Load value */
> +	u32 cv;			/* Current value */
> +	u32 cr;			/* Control reg */
> +	u32 bglr;		/* ??? */
> +};
> +
> +/* The MTU that contains the timers */
> +struct u8500_mtu {
> +	u32 imsc;		/* Interrupt mask set/clear */
> +	u32 ris;		/* Raw interrupt status */
> +	u32 mis;		/* Masked interrupt status */
> +	u32 icr;		/* Interrupt clear register */
> +	struct u8500_mtu_timer pt[4];
> +};
> +
> +/* bits for the control register */
> +#define MTU_CR_ONESHOT		0x01	/* if 0 = wraps reloading from BGLR */
> +#define MTU_CR_32BITS		0x02
> +
> +#define MTU_CR_PRESCALE_1	0x00
> +#define MTU_CR_PRESCALE_16	0x04
> +#define MTU_CR_PRESCALE_256	0x08
> +#define MTU_CR_PRESCALE_MASK	0x0c
> +
> +#define MTU_CR_PERIODIC		0x40	/* if 0 = free-running */
> +#define MTU_CR_ENA		0x80
> +
> +/*
> + * The MTU is clocked at 133 MHz by default. (V1 and later)
> + */
> +#define TIMER_CLOCK		(133 * 1000 * 1000 / 16)
> +#define COUNT_TO_USEC(x)	((x) * 16 / 133)
> +#define USEC_TO_COUNT(x)	((x) * 133 / 16)
> +#define TICKS_PER_HZ		(TIMER_CLOCK / CONFIG_SYS_HZ)
> +#define TICKS_TO_HZ(x)		((x) / TICKS_PER_HZ)
> +#define TIMER_LOAD_VAL		0xffffffff
> +
> +/*
> + * MTU timer to use (from 0 to 3).
> + * Linux ux500 timer0 on MTU0 and timer0 on MTU1

If you really mean the same timer for both, please explicitly state 
"timer0 for both MTU0 and MTU1", otherwise fix.

> + */
> +#define MTU_TIMER 2
> +
> +static struct u8500_mtu_timer *timer_base =
> +	&((struct u8500_mtu *)U8500_MTU0_BASE_V1)->pt[MTU_TIMER];
> +
> +/* macro to read the 32 bit timer: since it decrements, we invert read value */
> +#define READ_TIMER() (~readl(&timer_base->cv))
> +
> +/* Configure a free-running, auto-wrap counter with /16 prescaler */
> +int timer_init(void)
> +{
> +	writel(MTU_CR_ENA | MTU_CR_PRESCALE_16 | MTU_CR_32BITS,
> +	&timer_base->cr);
> +	reset_timer();
> +	return 0;
> +}
> +
> +ulong get_timer_masked(void)
> +{
> +	/* current tick value */
> +	ulong now = TICKS_TO_HZ(READ_TIMER());
> +
> +	if (now>= gd->lastinc)	/* normal (non rollover) */
> +		gd->tbl += (now - gd->lastinc);
> +	else			/* rollover */
> +		gd->tbl += (TICKS_TO_HZ(TIMER_LOAD_VAL) - gd->lastinc) + now;
> +	gd->lastinc = now;
> +	return gd->tbl;
> +}
> +
> +/* Delay x useconds */
> +void __udelay(ulong usec)
> +{
> +	long tmo = usec * (TIMER_CLOCK / 1000) / 1000;
> +	ulong now, last = READ_TIMER();
> +
> +	while (tmo>  0) {
> +		now = READ_TIMER();
> +		if (now>  last)	/* normal (non rollover) */
> +			tmo -= now - last;
> +		else		/* rollover */
> +			tmo -= TIMER_LOAD_VAL - last + now;
> +		last = now;
> +	}
> +}
> +
> +ulong get_timer(ulong base)
> +{
> +	return get_timer_masked() - base;
> +}
> +
> +void set_timer(ulong t)
> +{
> +	gd->tbl = t;
> +}
> +
> +void reset_timer_masked(void)
> +{
> +	gd->lastinc = TICKS_TO_HZ(READ_TIMER());
> +	gd->tbl = 0;		/* reset ticks to 0 */
> +}
> +
> +void reset_timer(void)
> +{
> +	reset_timer_masked();
> +}

Please remove these reset_timer functions and in the client code. 
Resetting a timer is never useful for timing loops. Client code that 
resets the timer must be fixed.

Amicalement,
-- 
Albert.

  reply	other threads:[~2011-04-12  7:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-22 20:40 [U-Boot] [PATCH 0/4] ST-Ericsson U8500 support John Rigby
2011-03-22 20:40 ` [U-Boot] [PATCH 1/4] p101x: extra init for u8500 John Rigby
2011-03-22 20:40 ` [U-Boot] [PATCH 2/4] armv7: Add ST-Ericsson u8500 arch John Rigby
2011-04-11 18:04   ` Wolfgang Denk
2011-03-22 20:40 ` [U-Boot] [PATCH 3/4] I2C: add driver of st-ericsson u8500 i2c John Rigby
2011-03-23  7:00   ` Heiko Schocher
2011-03-22 20:40 ` [U-Boot] [PATCH 4/4] armv7: Add support for ST-Ericsson U8500 href platform John Rigby
2011-03-22 20:46 ` [U-Boot] [PATCH 0/4] ST-Ericsson U8500 support John Rigby
2011-04-02 16:19 ` [U-Boot] [PATCHv2 " John Rigby
2011-04-11 17:33   ` John Rigby
2011-04-11 19:52     ` Albert ARIBAUD
2011-04-12  6:17   ` [U-Boot] [PATCHv3 " John Rigby
2011-04-28 14:47     ` John Rigby
2011-04-28 15:40       ` Albert ARIBAUD
2011-04-28 18:41         ` John Rigby
2011-05-12 13:41           ` John Rigby
2011-04-12  6:17   ` [U-Boot] [PATCHv3 1/4] Serial: p1011: new vendor init options John Rigby
2011-04-12  6:17   ` [U-Boot] [PATCHv3 2/4] armv7: Add ST-Ericsson u8500 arch John Rigby
2011-04-12  7:25     ` Albert ARIBAUD [this message]
2011-04-12  6:17   ` [U-Boot] [PATCHv3 3/4] I2C: Add driver for ST-Ericsson U8500 i2c John Rigby
2011-04-12  6:47     ` Heiko Schocher
2011-04-12  6:17   ` [U-Boot] [PATCHv3 4/4] armv7: Add support for ST-Ericsson U8500 href platform John Rigby
2011-04-19 20:42   ` [U-Boot] [PATCHv4 1/4] Serial: p1011: new vendor init options John Rigby
2011-04-19 20:59     ` Kumar Gala
2011-04-19 20:42   ` [U-Boot] [PATCHv4 2/4] armv7: Add ST-Ericsson u8500 arch John Rigby
2011-05-19 21:54     ` John Rigby
2011-06-01 17:34     ` Albert ARIBAUD
2011-04-19 20:42   ` [U-Boot] [PATCHv4 3/4] I2C: Add driver for ST-Ericsson U8500 i2c John Rigby
2011-04-28 18:52     ` John Rigby
2011-04-29  5:34       ` Heiko Schocher
2011-06-01 17:34     ` Albert ARIBAUD
2011-04-19 20:42   ` [U-Boot] [PATCHv4 4/4] armv7: Add support for ST-Ericsson U8500 href platform John Rigby
2011-06-01 17:35     ` Albert ARIBAUD
2011-05-12  8:05   ` [U-Boot] [PATCH 1/4] Serial: pl011: new vendor init options John Rigby
2011-05-12 17:10     ` Wolfgang Denk
2011-04-02 16:19 ` [U-Boot] [PATCHv2 1/4] p101x: extra init for u8500 John Rigby
2011-04-11 17:48   ` Wolfgang Denk
2011-04-02 16:19 ` [U-Boot] [PATCHv2 2/4] armv7: Add ST-Ericsson u8500 arch John Rigby
2011-04-02 16:19 ` [U-Boot] [PATCHv2 3/4] I2C: add driver of st-ericsson u8500 i2c John Rigby
2011-04-04  5:45   ` Heiko Schocher
2011-04-02 16:19 ` [U-Boot] [PATCHv2 4/4] armv7: Add support for ST-Ericsson U8500 href platform John Rigby
2011-04-11 18:09   ` Wolfgang Denk

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=4DA3FE4D.9080003@aribaud.net \
    --to=albert.u.boot@aribaud.net \
    --cc=u-boot@lists.denx.de \
    /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