nios2: Switch to generic timer
PATCH 1/2 nios2: Switch to generic timer
Zap almost all of the ad-hoc timer code from interrupts.c and use the code in lib/time.c instead.
--- arch/nios2/cpu/interrupts.c | 132 ++++++++++++---------------------------- arch/nios2/lib/Makefile | 1 - arch/nios2/lib/time.c | 22 ------- common/board_f.c | 2 +- include/configs/nios2-generic.h | 9 +-- 5 files changed, 42 insertions(+), 124 deletions(-) delete mode 100644 arch/nios2/lib/time.c
arch/nios2/cpu/interrupts.c +38 -94
@@ -8,7 +8,6 @@* SPDX-License-Identifier: GPL-2.0+ */ -#include <asm/nios2.h> #include <asm/types.h> #include <asm/io.h>
@@ -20,14 +19,14 @@#include <status_led.h> #endif -typedef volatile struct { -unsigned status;/* Timer status reg */ -unsigned control;/* Timer control reg */ -unsigned periodl;/* Timeout period low */ -unsigned periodh;/* Timeout period high */ -unsigned snapl;/* Snapshot low */ -unsigned snaph;/* Snapshot high */ -}nios_timer_t ; +struct nios_timer { +u32 status;/* Timer status reg */ +u32 control;/* Timer control reg */ +u32 periodl;/* Timeout period low */ +u32 periodh;/* Timeout period high */ +u32 snapl;/* Snapshot low */ +u32 snaph;/* Snapshot high */ +};/* status register */ #define NIOS_TIMER_TO (1 << 0)/* Timeout */
@@ -39,8 +38,8 @@ typedef volatile struct {#define NIOS_TIMER_START (1 << 2)/* Start timer */ #define NIOS_TIMER_STOP (1 << 3)/* Stop timer */ -#if defined(CONFIG_SYS_NIOS_TMRBASE ) && !defined(CONFIG_SYS_NIOS_TMRIRQ ) -#error CONFIG_SYS_NIOS_TMRIRQ not defined (see documentation) +#if defined(CONFIG_SYS_TIMER_BASE ) && !defined(CONFIG_SYS_TIMER_IRQ ) +#error CONFIG_SYS_TIMER_IRQ not defined (see documentation)#endif /****************************************************************************/
@@ -54,80 +53,15 @@ struct irq_action {static struct irq_action vecs[32 ];/*************************************************************************/ -volatile ulong timestamp =0 ; - -void reset_timer (void ) -{ -nios_timer_t *tmr =(nios_timer_t *)CONFIG_SYS_NIOS_TMRBASE ; - -/* From Embedded Peripherals Handbook: -* -* "When the hardware is configured with Writeable period -* disabled, writing to one of the period_n registers causes -* the counter to reset to the fixed Timeout Period specified -*@system generation time." -* -* Here we force a reload to prevent early timeouts from -* get_timer() when the interrupt period is greater than -* than 1 msec. -* -* Simply write to periodl with its own value to force an -* internal counter reload, THEN reset the timestamp. -*/ -writel (readl (&tmr->periodl), &tmr->periodl); - timestamp =0 ; - -/* From Embedded Peripherals Handbook: -* -* "Writing to one of the period_n registers stops the internal -* counter, except when the hardware is configured with Start/Stop -* control bits off. If Start/Stop control bits is off, writing -* either register does not stop the counter." -* -* In order to accomodate either configuration, the control -* register is re-written. If the counter is stopped, it will -* be restarted. If it is running, the write is essentially -* a nop. -*/ -writel (NIOS_TIMER_ITO |NIOS_TIMER_CONT |NIOS_TIMER_START , - &tmr->control); - -} - -ulong get_timer (ulong base) -{ -WATCHDOG_RESET (); -return (timestamp - base); -} - -/* -* This function is derived from Blackfin code (read timebase as long long). -* On Nios2 it just returns the timer value. -*/ -unsigned long long get_ticks (void ) -{ -return get_timer (0 ); -} +static volatile ulong timestamp;/* -* This function is derived from Blackfin code. -* On Nios2 it returns the number of timer ticks per second. -*/ -ulong get_tbclk (void ) -{ -ulong tbclk; - - tbclk =CONFIG_SYS_HZ ; -return tbclk; -} - -/* The board must handle this interrupt if a timer is not +* The board must handle this interrupt if a timer is not * provided. */ -#if defined(CONFIG_SYS_NIOS_TMRBASE )void tmr_isr (void *arg) { -nios_timer_t *tmr = (nios_timer_t *)arg; +struct nios_timer *tmr = (struct nios_timer *)arg;/* Interrupt is cleared by writing anything to the * status register. */
@@ -138,24 +72,38 @@ void tmr_isr (void *arg)#endif } -static void tmr_init (void ) +unsigned long notrace timer_read_counter (void ) +{ +struct nios_timer *tmr = (struct nios_timer *)CONFIG_SYS_TIMER_BASE ; +u32 val; + +/* Trigger update */ +writel (0x0 , &tmr->snapl); + +/* Read timer value */ + val =readl (&tmr->snapl) &0xffff ; + val |= (readl (&tmr->snaph) &0xffff ) <<16 ; + +return ~val; +} + +int timer_init (void ) { -nios_timer_t *tmr =(nios_timer_t *)CONFIG_SYS_NIOS_TMRBASE ; +struct nios_timer *tmr = (struct nios_timer *)CONFIG_SYS_TIMER_BASE ;writel (0 , &tmr->status);writel (0 , &tmr->control);writel (NIOS_TIMER_STOP , &tmr->control); -#if defined(CONFIG_SYS_NIOS_TMRCNT ) -writel (CONFIG_SYS_NIOS_TMRCNT &0xffff , &tmr->periodl); -writel ((CONFIG_SYS_NIOS_TMRCNT >>16 ) &0xffff , &tmr->periodh); -#endif -writel (NIOS_TIMER_ITO |NIOS_TIMER_CONT |NIOS_TIMER_START , - &tmr->control); -irq_install_handler (CONFIG_SYS_NIOS_TMRIRQ , tmr_isr, (void *)tmr); -} +writel (0xffff , &tmr->periodl); +writel (0xffff , &tmr->periodh); -#endif /* CONFIG_SYS_NIOS_TMRBASE */ +writel (NIOS_TIMER_CONT |NIOS_TIMER_START , &tmr->control); +/* FIXME */ +irq_install_handler (CONFIG_SYS_TIMER_IRQ , tmr_isr, (void *)tmr); + +return 0 ; +}/*************************************************************************/ int disable_interrupts (void )
@@ -245,10 +193,6 @@ int interrupt_init (void) vecs[i].count =0 ; } -#if defined(CONFIG_SYS_NIOS_TMRBASE ) -tmr_init (); -#endif -enable_interrupts ();return (0 ); }
arch/nios2/lib/Makefile +0 -1
@@ -8,4 +8,3 @@ obj-y += cache.o obj-$(CONFIG_CMD_BOOTM) += bootm.o obj-y += libgcc.o -obj-y += time.o
arch/nios2/lib/time.c deleted +0 -22
@@ -1,22 +0,0 @@ -/* -* (C) Copyright 2003, Psyent Corporation <www.psyent.com> -* Scott McNutt <[email protected]> -* -* SPDX-License-Identifier: GPL-2.0+ -*/ - -#include <common.h> -#include <watchdog.h> - - -extern void dly_clks (unsigned long ticks ); - -void __udelay (unsigned long usec) -{ -/* The Nios core doesn't have a timebase, so we do our -* best for now and call a low-level loop that counts -* cpu clocks. -*/ -unsigned long cnt = (CONFIG_SYS_CLK_FREQ /1000000 ) * usec; -dly_clks (cnt); -}
common/board_f.c +1 -1
@@ -792,7 +792,7 @@ static init_fnc_t init_sequence_f[] = {/* TODO: can we rename this to timer_init()? */ init_timebase,#endif -#if defined(CONFIG_ARM ) || defined(CONFIG_MIPS ) || defined(CONFIG_BLACKFIN ) +#if defined(CONFIG_ARM ) || defined(CONFIG_MIPS ) || defined(CONFIG_BLACKFIN ) || defined(CONFIG_NIOS2 ) timer_init, /* initialize timer */#endif #ifdef CONFIG_SYS_ALLOC_DPRAM
include/configs/nios2-generic.h +3 -6
@@ -38,12 +38,9 @@/* * TIMER */ -#define CONFIG_SYS_LOW_RES_TIMER -#define CONFIG_SYS_NIOS_TMRBASE CONFIG_SYS_TIMER_BASE -#define CONFIG_SYS_NIOS_TMRIRQ CONFIG_SYS_TIMER_IRQ -#define CONFIG_SYS_NIOS_TMRMS 10/* Desired period (msec)*/ -#define CONFIG_SYS_NIOS_TMRCNT \ - (CONFIG_SYS_NIOS_TMRMS * (CONFIG_SYS_TIMER_FREQ / 1000) - 1) +#define CONFIG_SYS_TIMER_COUNTS_DOWN +#define CONFIG_SYS_TIMER_RATE CONFIG_SYS_TIMER_FREQ +#define CONFIG_SYS_NIOS_TMRMS 10/* FIXME: Desired period (msec)*/ /* * STATUS LED
Signature · 1 line
2.1.4
PATCH 2/2 nios2: Split timer code into timer.c
Move the timer code from interrupts.c into timer.c . Eliminate the installation of timer interrupt handler, which is no longer used.
--- arch/nios2/cpu/Makefile | 2 +- arch/nios2/cpu/interrupts.c | 84 +---------------------------------------- arch/nios2/cpu/timer.c | 69 +++++++++++++++++++++++++++++++++ include/configs/nios2-generic.h | 3 +- 4 files changed, 72 insertions(+), 86 deletions(-) create mode 100644 arch/nios2/cpu/timer.c
arch/nios2/cpu/Makefile +1 -1
@@ -7,5 +7,5 @@ extra-y = start.o obj-y = exceptions.o -obj-y += cpu.o interrupts.o sysid.o traps.o +obj-y += cpu.o interrupts.o sysid.o timer.o traps.o obj-y += fdt.o
arch/nios2/cpu/interrupts.c +1 -83
97 lines not on this page · raw message
arch/nios2/cpu/timer.c new file +69 -0
69 lines not on this page · raw message
include/configs/nios2-generic.h +1 -2
@@ -40,7 +40,6 @@*/ #define CONFIG_SYS_TIMER_COUNTS_DOWN #define CONFIG_SYS_TIMER_RATE CONFIG_SYS_TIMER_FREQ -#define CONFIG_SYS_NIOS_TMRMS 10/* FIXME: Desired period (msec)*/ /* * STATUS LED
@@ -59,7 +58,7 @@#define STATUS_LED_BIT 0/* Bit-0 on GPIO */ #define STATUS_LED_STATE 1/* Blinking */ -#define STATUS_LED_PERIOD (500 / CONFIG_SYS_NIOS_TMRMS)/* 500 msec */ +#define STATUS_LED_PERIOD (CONFIG_SYS_HZ / 2)/* 500 msec */ /* * BOOTP options
Signature · 1 line
2.1.4
PATCH 2/2 nios2: Split timer code into timer.c
Hi Marek,
On 09/04/2015 05:51 PM, Marek Vasut wrote
Quoted 33 lines
arch/nios2/cpu/timer.c new file +27
-0@@ -0,0 +1,69 @@ +/* +* (C) Copyright 2000-2002 +* Wolfgang Denk, DENX Software Engineering, wd at denx.de. +* +* (C) Copyright 2004, Psyent Corporation <www.psyent.com> +* Scott McNutt <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <asm/nios2.h> +#include <asm/types.h> +#include <asm/io.h> + +struct nios_timer { +u32 status;/* Timer status reg */ +u32 control;/* Timer control reg */ +u32 periodl;/* Timeout period low */ +u32 periodh;/* Timeout period high */ +u32 snapl;/* Snapshot low */ +u32 snaph;/* Snapshot high */ +}; + +/* status register */ +#define NIOS_TIMER_TO (1 << 0)/* Timeout */ +#define NIOS_TIMER_RUN (1 << 1)/* Timer running */
arch/nios2/cpu/timer.c line 37
Quoted 10 lines
arch/nios2/cpu/timer.c new file +10
-0+ +/* control register */ +#define NIOS_TIMER_ITO (1 << 0)/* Timeout int ena */ +#define NIOS_TIMER_CONT (1 << 1)/* Continuous mode */ +#define NIOS_TIMER_START (1 << 2)/* Start timer */ +#define NIOS_TIMER_STOP (1 << 3)/* Stop timer */ + +#if defined(CONFIG_SYS_TIMER_BASE ) && !defined(CONFIG_SYS_TIMER_IRQ ) +#error CONFIG_SYS_TIMER_IRQ not defined (see documentation) +#endif
Since the timer interrupt is removed, there is no need to perform the check.
Best regards,
Thomas Chou
PATCH 1/2 nios2: Switch to generic timer
In reply to Marek VasutHi Marek,
Quoted 4 lines · Marek Vasut
Zap almost all of the ad-hoc timer code from
interrupts.cand use the code inlib/time.cinstead.Signed-off-by Marek Vasut <[email protected]>
Quoted 8 lines
--- arch/nios2/cpu/interrupts.c | 132 ++++++++++++---------------------------- arch/nios2/lib/Makefile | 1 - arch/nios2/lib/time.c | 22 ------- common/board_f.c | 2 +- include/configs/nios2-generic.h | 9 +-- 5 files changed, 42 insertions(+), 124 deletions(-)delete mode 100644
arch/nios2/lib/time.c
The patch cannot apply to board_f.c due to conflict in
commit 2e88bb28d8061286d2f1cabcac224df15b941b82
NDS32: Generic Board Support and Unsupport
Tested on 3c120 devboard with qsys ghrd. But the status led didn't blink.
Best regards,
Thomas Chou
PATCH 1/2 nios2: Switch to generic timer
Quoted 1 line · Thomas Chou
Hi Marek,
Hi!
Quoted 16 lines · Marek Vasut
Quoted 6 lines
Zap almost all of the ad-hoc timer code from
interrupts.cand use the code inlib/time.cinstead.Signed-off-by Marek Vasut <[email protected]>---
Quoted 8 lines
arch/nios2/cpu/interrupts.c | 132 ++++++++++++---------------------------- arch/nios2/lib/Makefile | 1 - arch/nios2/lib/time.c | 22 ------- common/board_f.c | 2 +- include/configs/nios2-generic.h | 9 +-- 5 files changed, 42 insertions(+), 124 deletions(-)delete mode 100644
arch/nios2/lib/time.c
Quoted 4 lines
The patch cannot apply to
board_f.cdue to conflict incommit
2e88bb28d8061286d2f1cabcac224df15b941b82
NDS32: Generic Board Support and Unsupport
Aw, right, looks trivial. Thanks :)
Quoted 1 line
Tested on 3c120 devboard with qsys ghrd. But the status led didn't blink.
I think I removed this led nonsense somewhere along the way indeed. This is a timer code, not some LED blinking code afterall, so it should not be poluted by such stuff.
Where can I get this board btw? I've been using DE0-NANO for my NIOS fiddling thus far.
Best regards,
Marek Vasut
PATCH 1/2 nios2: Switch to generic timer
Hi Marek,
Quoted 3 lines · Marek Vasut
I think I removed this led nonsense somewhere along the way indeed. This is a timer code, not some LED blinking code afterall, so it should not be poluted by such stuff.
I will look into this today. It was late last night.
Quoted 3 lines
Where can I get this board btw? I've been using DE0-NANO for my NIOS fiddling thus far.
There are LEDs on the DE0-nano. Did you try them?
The 3c120 dev board is a cycloneIII based dev board from Altera, which is used as the "golden hardware reference design" for nios2 linux development. It is a bit old though. Maybe you can ask one from Altera.
https://www.altera.com/products/boards_and_kits/dev-kits/altera/kit-cyc3.html
Best regards,
Thomas Chou
PATCH 1/2 nios2: Switch to generic timer
Quoted 1 line · Thomas Chou
Hi Marek,
Hi!
Quoted 11 lines · Marek Vasut
Quoted 3 lines
I think I removed this led nonsense somewhere along the way indeed. This is a timer code, not some LED blinking code afterall, so it should not be poluted by such stuff.
I will look into this today. It was late last night.
Quoted 2 lines
Where can I get this board btw? I've been using DE0-NANO for my NIOS fiddling thus far.
There are LEDs on the DE0-nano. Did you try them?
Yes, but I didn't hook them up in this design experiment.
Quoted 6 lines
The 3c120 dev board is a cycloneIII based dev board from Altera, which is used as the "golden hardware reference design" for nios2 linux development. It is a bit old though. Maybe you can ask one from Altera.
https://www.altera.com/products/boards_and_kits/dev-kits/altera/kit-cyc3.ht
ml
Maybe, but it seems that NIOS is in good hands, so I might just be a casual contributor here :)
Best regards,
Marek Vasut
PATCH 1/1 nios2: configure STATUS_LED_BOOT
In reply to Marek VasutDefine STATUS_LED_BOOT. So the boot LED will be initialized in board_init_r(), and show the boot progress.
Though the boot LED is set to blinking in board_init_r(), only the powerpc and nios2 really support blinking. All other archs just turn the LED on and can not blink.
After the commit "nios2: Switch to generic timer", with the removal of call to status_led_tick(), nios2 can not blink LED. But it doesn't really matter, because U-Boot usually runs a very short time. It should be enough to turn boot LED on and off during boot process.
--- include/configs/nios2-generic.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/configs/nios2-generic.h +2 -1
@@ -58,8 +58,9 @@#define LED_PIO_RSTVAL 0xff#define STATUS_LED_BIT 0/* Bit-0 on GPIO */ -#define STATUS_LED_STATE 1/* Blinking */ +#define STATUS_LED_STATE STATUS_LED_ON#define STATUS_LED_PERIOD (CONFIG_SYS_HZ / 2)/* 500 msec */ +#define STATUS_LED_BOOT STATUS_LED_BIT/* * BOOTP options
Signature · 1 line
2.1.4
PATCH 1/1 nios2: configure STATUS_LED_BOOT
Quoted 23 lines · Thomas Chou
Define
STATUS_LED_BOOT. So the boot LED will be initialized inboard_init_r(), and show the boot progress.Though the boot LED is set to blinking in
board_init_r(), only the powerpc and nios2 really support blinking. All other archs just turn the LED on and can not blink.After the commit "nios2: Switch to generic timer", with the removal of call to
status_led_tick(), nios2 can not blink LED. But it doesn't really matter, because U-Boot usually runs a very short time. It should be enough to turn boot LED on and off during boot process.Signed-off-by Thomas Chou <[email protected]>--- include/configs/nios2-generic.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/include/configs/nios2-generic.hindex 10f9a34..66ad2f0 100644
include/configs/nios2-generic.h line 66
Quoted 10 lines
include/configs/nios2-generic.h +2
-1@@ -58,8 +58,9 @@#define LED_PIO_RSTVAL 0xff#define STATUS_LED_BIT 0/* Bit-0 on GPIO */ -#define STATUS_LED_STATE 1/* Blinking */ +#define STATUS_LED_STATE STATUS_LED_ON#define STATUS_LED_PERIOD (CONFIG_SYS_HZ / 2)/* 500 msec */ +#define STATUS_LED_BOOT STATUS_LED_BIT/* * BOOTP options
Idea: Maybe you can add a __weak hook into the generic timer code to blink the LED ?
Best regards,
Marek Vasut
PATCH 1/1 nios2: configure STATUS_LED_BOOT
Hi Marek,
Quoted 2 lines · Marek Vasut
Idea: Maybe you can add a
__weakhook into the generic timer code to blink the LED ?
Thanks for the idea. I will look into it later.
Cheers,
Thomas Chou
PATCH 1/1 nios2: configure STATUS_LED_BOOT
Quoted 7 lines · Thomas Chou
Hi Marek,
Quoted 2 lines · Marek Vasut
Idea: Maybe you can add a
__weakhook into the generic timer code to blink the LED ?Thanks for the idea. I will look into it later.
Sure, thanks :)
Best regards,
Marek Vasut
PATCH 1/1 nios2: configure STATUS_LED_BOOT
In reply to Thomas ChouQuoted 13 lines · Thomas Chou
Define
STATUS_LED_BOOT. So the boot LED will be initialized inboard_init_r(), and show the boot progress.Though the boot LED is set to blinking in
board_init_r(), only the powerpc and nios2 really support blinking. All other archs just turn the LED on and can not blink.After the commit "nios2: Switch to generic timer", with the removal of call to
status_led_tick(), nios2 can not blink LED. But it doesn't really matter, because U-Boot usually runs a very short time. It should be enough to turn boot LED on and off during boot process.
Quoted 4 lines
Signed-off-by Thomas Chou <[email protected]>--- include/configs/nios2-generic.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Applied to u-boot-nios.
PATCH 1/2 nios2: Switch to generic timer
In reply to Marek VasutHi Marek,
Quoted 6 lines · Marek Vasut
Quoted 4 lines
The patch cannot apply to
board_f.cdue to conflict incommit
2e88bb28d8061286d2f1cabcac224df15b941b82
NDS32: Generic Board Support and UnsupportAw, right, looks trivial. Thanks :)
Could you please rebase and submit this series again?
Best regards,
Thomas
PATCH 1/2 nios2: Switch to generic timer
Quoted 1 line · Thomas Chou
Hi Marek,
Hi!
Quoted 9 lines · Marek Vasut
Quoted 6 lines
Quoted 4 lines
The patch cannot apply to
board_f.cdue to conflict incommit
2e88bb28d8061286d2f1cabcac224df15b941b82
NDS32: Generic Board Support and UnsupportAw, right, looks trivial. Thanks :)
Could you please rebase and submit this series again?
Yes, that's my plan shortly. We're aiming for after 2015.10 release with all these NIOS changes, so this is not urgent, right ?
Best regards,
Marek Vasut
PATCH 1/2 nios2: Switch to generic timer
Hi Marek,
Quoted 4 lines · Marek Vasut
Quoted 1 line
Could you please rebase and submit this series again?
Yes, that's my plan shortly. We're aiming for after 2015.10 release with all these NIOS changes, so this is not urgent, right ?
Yes, they will be after 2015.10. No hurry. I just hope to set them down to u-boot-nios before I am distracted away. It will also help others to test more easily. :)
Best regards,
Thomas Chou