All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 09/25] arm: marvell: Rework timer.c to make it usable for other MVEBU platforms
Date: Tue,  5 Aug 2014 09:09:55 +0200	[thread overview]
Message-ID: <1407222612-1048-10-git-send-email-sr@denx.de> (raw)
In-Reply-To: <1407222612-1048-1-git-send-email-sr@denx.de>

This patch does the following:
- Rename defines and registers to not use kirkwood
- Remove unused defines
- Use clrsetbits() accessor functions
- Coding style cleanup
- Clear 25MHZ bit in timer controller register init for Armada XP

There is no functional change for kirkwood. At least not intentionally.

This will be used by the upcoming Armada XP support.

Signed-off-by: Stefan Roese <sr@denx.de>
---

Changes in v2: None

 arch/arm/include/asm/arch-kirkwood/soc.h |  2 +-
 arch/arm/mvebu-common/timer.c            | 90 ++++++++++++++------------------
 2 files changed, 41 insertions(+), 51 deletions(-)

diff --git a/arch/arm/include/asm/arch-kirkwood/soc.h b/arch/arm/include/asm/arch-kirkwood/soc.h
index bc207f5..4261c35 100644
--- a/arch/arm/include/asm/arch-kirkwood/soc.h
+++ b/arch/arm/include/asm/arch-kirkwood/soc.h
@@ -33,7 +33,7 @@
 #define KW_SPI_BASE			(KW_REGISTER(0x10600))
 #define KW_CPU_WIN_BASE			(KW_REGISTER(0x20000))
 #define KW_CPU_REG_BASE			(KW_REGISTER(0x20100))
-#define KW_TIMER_BASE			(KW_REGISTER(0x20300))
+#define MVEBU_TIMER_BASE			(KW_REGISTER(0x20300))
 #define KW_REG_PCIE_BASE		(KW_REGISTER(0x40000))
 #define KW_USB20_BASE			(KW_REGISTER(0x50000))
 #define KW_EGIGA0_BASE			(KW_REGISTER(0x72000))
diff --git a/arch/arm/mvebu-common/timer.c b/arch/arm/mvebu-common/timer.c
index b7aa645..40c4bc2 100644
--- a/arch/arm/mvebu-common/timer.c
+++ b/arch/arm/mvebu-common/timer.c
@@ -9,73 +9,66 @@
 #include <asm/io.h>
 #include <asm/arch/soc.h>
 
-#define UBOOT_CNTR	0	/* counter to use for uboot timer */
-
-/* Timer reload and current value registers */
-struct kwtmr_val {
-	u32 reload;	/* Timer reload reg */
-	u32 val;	/* Timer value reg */
-};
-
-/* Timer registers */
-struct kwtmr_registers {
-	u32 ctrl;	/* Timer control reg */
-	u32 pad[3];
-	struct kwtmr_val tmr[2];
-	u32 wdt_reload;
-	u32 wdt_val;
-};
-
-struct kwtmr_registers *kwtmr_regs = (struct kwtmr_registers *)KW_TIMER_BASE;
+#define UBOOT_CNTR	0	/* counter to use for U-Boot timer */
 
 /*
  * ARM Timers Registers Map
  */
-#define CNTMR_CTRL_REG			&kwtmr_regs->ctrl
-#define CNTMR_RELOAD_REG(tmrnum)	&kwtmr_regs->tmr[tmrnum].reload
-#define CNTMR_VAL_REG(tmrnum)		&kwtmr_regs->tmr[tmrnum].val
+#define CNTMR_CTRL_REG			&tmr_regs->ctrl
+#define CNTMR_RELOAD_REG(tmrnum)	&tmr_regs->tmr[tmrnum].reload
+#define CNTMR_VAL_REG(tmrnum)		&tmr_regs->tmr[tmrnum].val
 
 /*
  * ARM Timers Control Register
  * CPU_TIMERS_CTRL_REG (CTCR)
  */
 #define CTCR_ARM_TIMER_EN_OFFS(cntr)	(cntr * 2)
-#define CTCR_ARM_TIMER_EN_MASK(cntr)	(1 << CTCR_ARM_TIMER_EN_OFFS)
 #define CTCR_ARM_TIMER_EN(cntr)		(1 << CTCR_ARM_TIMER_EN_OFFS(cntr))
-#define CTCR_ARM_TIMER_DIS(cntr)	(0 << CTCR_ARM_TIMER_EN_OFFS(cntr))
 
 #define CTCR_ARM_TIMER_AUTO_OFFS(cntr)	((cntr * 2) + 1)
-#define CTCR_ARM_TIMER_AUTO_MASK(cntr)	(1 << 1)
 #define CTCR_ARM_TIMER_AUTO_EN(cntr)	(1 << CTCR_ARM_TIMER_AUTO_OFFS(cntr))
-#define CTCR_ARM_TIMER_AUTO_DIS(cntr)	(0 << CTCR_ARM_TIMER_AUTO_OFFS(cntr))
 
-/*
- * ARM Timer\Watchdog Reload Register
- * CNTMR_RELOAD_REG (TRR)
- */
-#define TRG_ARM_TIMER_REL_OFFS		0
-#define TRG_ARM_TIMER_REL_MASK		0xffffffff
+/* Only Armada XP have the 25MHz enable bit (Kirkwood doesn't) */
+#if defined(CONFIG_ARMADA_XP)
+#define CTCR_ARM_TIMER_25MHZ_OFFS(cntr)	(cntr + 11)
+#define CTCR_ARM_TIMER_25MHZ(cntr)	(1 << CTCR_ARM_TIMER_25MHZ_OFFS(cntr))
+#else
+#define CTCR_ARM_TIMER_25MHZ(cntr)	0
+#endif
 
-/*
- * ARM Timer\Watchdog Register
- * CNTMR_VAL_REG (TVRG)
- */
-#define TVR_ARM_TIMER_OFFS		0
-#define TVR_ARM_TIMER_MASK		0xffffffff
-#define TVR_ARM_TIMER_MAX		0xffffffff
 #define TIMER_LOAD_VAL 			0xffffffff
 
-#define READ_TIMER			(readl(CNTMR_VAL_REG(UBOOT_CNTR)) /	\
-					 (CONFIG_SYS_TCLK / 1000))
+#define timestamp			gd->arch.tbl
+#define lastdec				gd->arch.lastinc
+
+/* Timer reload and current value registers */
+struct kwtmr_val {
+	u32 reload;	/* Timer reload reg */
+	u32 val;	/* Timer value reg */
+};
+
+/* Timer registers */
+struct kwtmr_registers {
+	u32 ctrl;	/* Timer control reg */
+	u32 pad[3];
+	struct kwtmr_val tmr[4];
+	u32 wdt_reload;
+	u32 wdt_val;
+};
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define timestamp gd->arch.tbl
-#define lastdec gd->arch.lastinc
+static struct kwtmr_registers *tmr_regs =
+	(struct kwtmr_registers *)MVEBU_TIMER_BASE;
+
+static inline ulong read_timer(void)
+{
+	return readl(CNTMR_VAL_REG(UBOOT_CNTR))	/ (CONFIG_SYS_TCLK / 1000);
+}
 
 ulong get_timer_masked(void)
 {
-	ulong now = READ_TIMER;
+	ulong now = read_timer();
 
 	if (lastdec >= now) {
 		/* normal mode */
@@ -119,20 +112,17 @@ void __udelay(unsigned long usec)
  */
 int timer_init(void)
 {
-	unsigned int cntmrctrl;
-
 	/* load value into timer */
 	writel(TIMER_LOAD_VAL, CNTMR_RELOAD_REG(UBOOT_CNTR));
 	writel(TIMER_LOAD_VAL, CNTMR_VAL_REG(UBOOT_CNTR));
 
 	/* enable timer in auto reload mode */
-	cntmrctrl = readl(CNTMR_CTRL_REG);
-	cntmrctrl |= CTCR_ARM_TIMER_EN(UBOOT_CNTR);
-	cntmrctrl |= CTCR_ARM_TIMER_AUTO_EN(UBOOT_CNTR);
-	writel(cntmrctrl, CNTMR_CTRL_REG);
+	clrsetbits_le32(CNTMR_CTRL_REG, CTCR_ARM_TIMER_25MHZ(UBOOT_CNTR),
+			CTCR_ARM_TIMER_EN(UBOOT_CNTR) |
+			CTCR_ARM_TIMER_AUTO_EN(UBOOT_CNTR));
 
 	/* init the timestamp and lastdec value */
-	lastdec = READ_TIMER;
+	lastdec = read_timer();
 	timestamp = 0;
 
 	return 0;
-- 
2.0.4

  parent reply	other threads:[~2014-08-05  7:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05  7:09 [U-Boot] [PATCH v2 0/25] Add Marvell Armada XP MV78460 SoC support Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 01/25] sf: Add M25PX64 SPI NOR flash ID Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 02/25] arm: kirkwood: spi.h: Add some missing parenthesis Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 03/25] spi: kirkwood_spi.c: Some fixes and cleanup Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 04/25] spi: kirkwood_spi.c: Make global variable static Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 05/25] spi: kirkwood_spi.c: cosmetic: Fix minor coding style issues Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 06/25] arm: kirkwood: Move some SoC files into new arch/arm/mvebu-common Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 07/25] arm: marvell: Move arch/kirkwood.h to arch/soc.h Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 08/25] arm: marvell: Move arch-kirkwood/spi.h to arch-mvebu/spi.h Stefan Roese
2014-08-23  7:14   ` Jagan Teki
2014-08-05  7:09 ` Stefan Roese [this message]
2014-08-05  7:09 ` [U-Boot] [PATCH v2 10/25] arm: mvebu: Add common mbus functions to use on Marvell SoCs Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 11/25] spi: kirkwood_spi.c: Compile MPP (pin-mux) only for kirkwood SoC's Stefan Roese
2014-08-23  7:14   ` Jagan Teki
2014-08-05  7:09 ` [U-Boot] [PATCH v2 12/25] arm: marvell: Extract kirkwood gpio functions into new common file gpio.c Stefan Roese
2014-08-05  7:09 ` [U-Boot] [PATCH v2 13/25] spi: kirkwood_spi.c: Change KW_SPI_BASE to MVEBU_SPI_BASE Stefan Roese
2014-08-23  7:15   ` Jagan Teki
2014-08-05  7:10 ` [U-Boot] [PATCH v2 14/25] arm: kirkwood: Change naming of dram functions from km_foo() to mvebu_foo() Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 15/25] net: mvneta.c: Add support for the ethernet controller of the Marvell Armada XP SoC Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 16/25] net: phy.h: Make PHY autonegotiation timeout configurable Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 17/25] i2c: mvtwsi: Add support for Marvell Armada XP Stefan Roese
2014-08-11  5:19   ` Heiko Schocher
2014-08-05  7:10 ` [U-Boot] [PATCH v2 18/25] arm: armada-xp: Add basic support for Marvell Armada XP SoC Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 19/25] arm: armada-xp: Add basic support for the Marvell DB-MV784MP-GP board Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 20/25] arm: armada-xp: Add basic support for the maxBCM board Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 21/25] arm: kirkwood: Remove some dead code from cpu.c Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 22/25] tools/kwboot: Sync with latest barebox version to support Armada XP Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 23/25] tools: Compile kwboot for Marvell Armada XP as those SoCs are now supported Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 24/25] tools: kwbimage: Add image version 1 support for Armada XP / 370 Stefan Roese
2014-08-05  7:10 ` [U-Boot] [PATCH v2 25/25] Makefile: Add CONFIG_BUILD_TARGET to automatically build an special image Stefan Roese
2014-08-06 10:14 ` [U-Boot] [PATCH v2 0/25] Add Marvell Armada XP MV78460 SoC support Prafulla Wadaskar
2014-08-23  7:20 ` Jagan Teki

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=1407222612-1048-10-git-send-email-sr@denx.de \
    --to=sr@denx.de \
    --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 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.