From e17c5200c7e9a802783a53d4f4457fa68f7fa074 Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Wed, 28 Oct 2015 14:29:32 +0200 Subject: sparc: Initial ground work for generic board initialization Initial ground work in preperation for generic board initialization code for the SPARC architecture. Signed-off-by: Francois Retief --- arch/sparc/cpu/leon3/cpu_init.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index b140da31b13..a0526cd36c5 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -27,19 +27,11 @@ DECLARE_GLOBAL_DATA_PTR; -/* reset CPU (jump to 0, without reset) */ -void start(void); - ambapp_dev_irqmp *irqmp = NULL; ambapp_dev_gptimer *gptimer = NULL; unsigned int gptimer_irq = 0; int leon3_snooping_avail = 0; -struct { - gd_t gd_area; - bd_t bd; -} global_data; - /* * Breath some life into the CPU... * @@ -71,6 +63,15 @@ void cpu_init_f2(void) ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb); } +int arch_cpu_init(void) +{ + gd->cpu_clk = CONFIG_SYS_CLK_FREQ; + gd->bus_clk = CONFIG_SYS_CLK_FREQ; + gd->ram_size = CONFIG_SYS_SDRAM_SIZE; + + return 0; +} + /* * initialize higher level parts of CPU like time base and timers */ -- cgit v1.2.3 From d67269ba70f471a33ea64fcddc698cacce14e14a Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Wed, 28 Oct 2015 15:48:41 +0200 Subject: sparc: leon3: Move snoop detection from startup.S to arch_cpu_init() Signed-off-by: Francois Retief --- arch/sparc/cpu/leon3/cpu_init.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index a0526cd36c5..421859e0e2c 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -30,7 +30,6 @@ DECLARE_GLOBAL_DATA_PTR; ambapp_dev_irqmp *irqmp = NULL; ambapp_dev_gptimer *gptimer = NULL; unsigned int gptimer_irq = 0; -int leon3_snooping_avail = 0; /* * Breath some life into the CPU... @@ -63,12 +62,24 @@ void cpu_init_f2(void) ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb); } +/* If cache snooping is available in hardware the result will be set + * to 0x800000, otherwise 0. + */ +static unsigned int snoop_detect(void) +{ + unsigned int result; + asm("lda [%%g0] 2, %0" : "=r"(result)); + return result & 0x00800000; +} + int arch_cpu_init(void) { gd->cpu_clk = CONFIG_SYS_CLK_FREQ; gd->bus_clk = CONFIG_SYS_CLK_FREQ; gd->ram_size = CONFIG_SYS_SDRAM_SIZE; + gd->arch.snooping_available = snoop_detect(); + return 0; } -- cgit v1.2.3 From 574be25ea1b88ff1b7d213584b04b754f187e25d Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Thu, 29 Oct 2015 12:58:52 +0200 Subject: sparc: leon3: Move ambapp_bus_init() call to arch_cpu_init() function Signed-off-by: Francois Retief --- arch/sparc/cpu/leon3/cpu_init.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index 421859e0e2c..20a6a256f04 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -56,10 +56,6 @@ void cpu_init_f(void) */ void cpu_init_f2(void) { - /* Initialize the AMBA Plug & Play bus structure, the bus - * structure represents the AMBA bus that the CPU is located at. - */ - ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb); } /* If cache snooping is available in hardware the result will be set @@ -80,6 +76,11 @@ int arch_cpu_init(void) gd->arch.snooping_available = snoop_detect(); + /* Initialize the AMBA Plug & Play bus structure, the bus + * structure represents the AMBA bus that the CPU is located at. + */ + ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb); + return 0; } -- cgit v1.2.3 From cb31eaa4b3e870e4520dd0ce6f9ce326dc9cf50b Mon Sep 17 00:00:00 2001 From: Daniel Hellstrom Date: Wed, 22 Sep 2010 17:42:29 +0200 Subject: sparc: leon3: Clear all unused GPTIMER registers. Signed-off-by: Daniel Hellstrom --- arch/sparc/cpu/leon3/cpu_init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index 20a6a256f04..0ce2f89dffa 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -90,7 +90,7 @@ int arch_cpu_init(void) int cpu_init_r(void) { ambapp_apbdev apbdev; - int index, cpu; + int index, cpu, ntimers, i; ambapp_dev_gptimer *timer = NULL; unsigned int bus_freq; @@ -135,6 +135,14 @@ int cpu_init_r(void) timer->scalar = timer->scalar_reload = (((bus_freq / 1000) + 500) / 1000) - 1; + /* Clear All Timers */ + ntimers = timer->config & 0x7; + for (i = 0; i < ntimers; i++) { + timer->e[i].ctrl = GPTIMER_CTRL_IP; + timer->e[i].rld = 0; + timer->e[i].ctrl = GPTIMER_CTRL_LD; + } + index++; } if (!gptimer) { -- cgit v1.2.3 From a62bba15b5a02accb8f6de3b47a525eab4f50302 Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Thu, 29 Oct 2015 00:02:48 +0200 Subject: sparc: leon3: Updates for generic board initialization Reworked the LEON3 start.S code to call board_init_f function at startup. Also implemented the relocate_code function in assembly to relocate the monitor and setup the stack pointer before calling relocated board_init_r. Add the CONFIG_SYS_GENERIC_BOARD variable to all the LEON3 boards. Signed-off-by: Francois Retief --- arch/sparc/cpu/leon3/cpu_init.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index 0ce2f89dffa..9c7665783cb 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -47,17 +47,6 @@ void cpu_init_f(void) #endif } -/* Routine called from start.S, - * - * Run from FLASH/PROM: - * - memory controller has already been setup up, stack can be used - * - global variables available for read/writing - * - constants avaiable - */ -void cpu_init_f2(void) -{ -} - /* If cache snooping is available in hardware the result will be set * to 0x800000, otherwise 0. */ -- cgit v1.2.3 From c97088c3cfa84e7e53fddd26896f145cc8c431a2 Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Wed, 28 Oct 2015 15:18:22 +0200 Subject: sparc: Update cpu_init.c to use generic timer infrastructure Introduce the CONFIG_SYS_TIMER_* macros in include/asm/config.h to make use of the generic timer infrastructure in lib/time.c. Created a timer_init() function to initialize the timer hardware and update the #ifdef in board_init_f to allow this function to be called during the start-up sequence. Signed-off-by: Francois Retief --- arch/sparc/cpu/leon3/cpu_init.c | 131 +++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 56 deletions(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index 9c7665783cb..88f82c95a8b 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -22,14 +23,17 @@ #define CONFIG_AMBAPP_IOAREA AMBA_DEFAULT_IOAREA #endif +/* Select which TIMER that will become the time base */ +#ifndef CONFIG_SYS_GRLIB_GPTIMER_INDEX +#define CONFIG_SYS_GRLIB_GPTIMER_INDEX 0 +#endif + #define TIMER_BASE_CLK 1000000 #define US_PER_TICK (1000000 / CONFIG_SYS_HZ) DECLARE_GLOBAL_DATA_PTR; ambapp_dev_irqmp *irqmp = NULL; -ambapp_dev_gptimer *gptimer = NULL; -unsigned int gptimer_irq = 0; /* * Breath some life into the CPU... @@ -59,6 +63,9 @@ static unsigned int snoop_detect(void) int arch_cpu_init(void) { + ambapp_apbdev apbdev; + int index; + gd->cpu_clk = CONFIG_SYS_CLK_FREQ; gd->bus_clk = CONFIG_SYS_CLK_FREQ; gd->ram_size = CONFIG_SYS_SDRAM_SIZE; @@ -70,6 +77,35 @@ int arch_cpu_init(void) */ ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb); + /* Initialize/clear all the timers in the system. + */ + for (index = 0; ambapp_apb_find(&ambapp_plb, VENDOR_GAISLER, + GAISLER_GPTIMER, index, &apbdev) == 1; index++) { + ambapp_dev_gptimer *timer; + unsigned int bus_freq; + int i, ntimers; + + timer = (ambapp_dev_gptimer *)apbdev.address; + + /* Different buses may have different frequency, the + * frequency of the bus tell in which frequency the timer + * prescaler operates. + */ + bus_freq = ambapp_bus_freq(&ambapp_plb, apbdev.ahb_bus_index); + + /* Initialize prescaler common to all timers to 1MHz */ + timer->scalar = timer->scalar_reload = + (((bus_freq / 1000) + 500) / 1000) - 1; + + /* Clear all timers */ + ntimers = timer->config & 0x7; + for (i = 0; i < ntimers; i++) { + timer->e[i].ctrl = GPTIMER_CTRL_IP; + timer->e[i].rld = 0; + timer->e[i].ctrl = GPTIMER_CTRL_LD; + } + } + return 0; } @@ -79,9 +115,7 @@ int arch_cpu_init(void) int cpu_init_r(void) { ambapp_apbdev apbdev; - int index, cpu, ntimers, i; - ambapp_dev_gptimer *timer = NULL; - unsigned int bus_freq; + int cpu; /* * Find AMBA APB IRQMP Controller, @@ -104,40 +138,6 @@ int cpu_init_r(void) irqmp->cpu_force[cpu] = 0; } - /* timer */ - index = 0; - while (ambapp_apb_find(&ambapp_plb, VENDOR_GAISLER, GAISLER_GPTIMER, - index, &apbdev) == 1) { - timer = (ambapp_dev_gptimer *)apbdev.address; - if (gptimer == NULL) { - gptimer = timer; - gptimer_irq = apbdev.irq; - } - - /* Different buses may have different frequency, the - * frequency of the bus tell in which frequency the timer - * prescaler operates. - */ - bus_freq = ambapp_bus_freq(&ambapp_plb, apbdev.ahb_bus_index); - - /* initialize prescaler common to all timers to 1MHz */ - timer->scalar = timer->scalar_reload = - (((bus_freq / 1000) + 500) / 1000) - 1; - - /* Clear All Timers */ - ntimers = timer->config & 0x7; - for (i = 0; i < ntimers; i++) { - timer->e[i].ctrl = GPTIMER_CTRL_IP; - timer->e[i].rld = 0; - timer->e[i].ctrl = GPTIMER_CTRL_LD; - } - - index++; - } - if (!gptimer) { - printf("%s: gptimer not found!\n", __func__); - return 1; - } return 0; } @@ -151,25 +151,9 @@ void cpu_wait_ticks(unsigned long ticks) while (get_timer(start) < ticks) ; } -/* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz. - * Return irq number for timer int or a negative number for - * dealing with self - */ int timer_interrupt_init_cpu(void) { - /* SYS_HZ ticks per second */ - gptimer->e[0].val = 0; - gptimer->e[0].rld = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1; - gptimer->e[0].ctrl = - (GPTIMER_CTRL_EN | GPTIMER_CTRL_RS | - GPTIMER_CTRL_LD | GPTIMER_CTRL_IE); - - return gptimer_irq; -} - -ulong get_tbclk(void) -{ - return TIMER_BASE_CLK; + return -1; } /* @@ -186,3 +170,38 @@ unsigned long cpu_ticks2usec(unsigned long ticks) { return ticks * US_PER_TICK; } + +int timer_init(void) +{ + ambapp_dev_gptimer_element *tmr; + ambapp_dev_gptimer *gptimer; + ambapp_apbdev apbdev; + unsigned bus_freq; + + if (ambapp_apb_find(&ambapp_plb, VENDOR_GAISLER, GAISLER_GPTIMER, + CONFIG_SYS_GRLIB_GPTIMER_INDEX, &apbdev) != 1) { + panic("%s: gptimer not found!\n", __func__); + return -1; + } + + gptimer = (ambapp_dev_gptimer *) apbdev.address; + + /* Different buses may have different frequency, the + * frequency of the bus tell in which frequency the timer + * prescaler operates. + */ + bus_freq = ambapp_bus_freq(&ambapp_plb, apbdev.ahb_bus_index); + + /* initialize prescaler common to all timers to 1MHz */ + gptimer->scalar = gptimer->scalar_reload = + (((bus_freq / 1000) + 500) / 1000) - 1; + + tmr = (ambapp_dev_gptimer_element *)&gptimer->e[0]; + + tmr->val = 0; + tmr->rld = ~0; + tmr->ctrl = GPTIMER_CTRL_EN | GPTIMER_CTRL_RS | GPTIMER_CTRL_LD; + + CONFIG_SYS_TIMER_COUNTER = (void *)&tmr->val; + return 0; +} -- cgit v1.2.3 From f376c42f3b28862326ea378b0b6cc6b9b699d0c0 Mon Sep 17 00:00:00 2001 From: Daniel Hellstrom Date: Fri, 22 Jan 2010 12:02:40 +0100 Subject: sparc: leon3: Added busy wait function, made wait_ms() work when IRQ is disabled Signed-off-by: Daniel Hellstrom --- arch/sparc/cpu/leon3/cpu_init.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index 88f82c95a8b..9e294bfd0eb 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -141,14 +142,41 @@ int cpu_init_r(void) return 0; } +/* Busy wait a number of ms */ +void cpu_wait_ms_busy(unsigned long ms) +{ + unsigned int ms_delay; + volatile unsigned int tmp; + + /* ~10-20 cycles per decrement */ + ms_delay = leon_cpu_freq / (1000 * 10); + do { + /* Wait ~1ms */ + tmp = ms_delay; + while (tmp-- > 0) + ; + } while (--ms > 0); +} + /* Uses Timer 0 to get accurate * pauses. Max 2 raised to 32 ticks * */ void cpu_wait_ticks(unsigned long ticks) { - unsigned long start = get_timer(0); - while (get_timer(start) < ticks) ; + unsigned long start; + + if (interrupt_is_enabled()) { + start = get_timer(0); + while (get_timer(start) < ticks) + ; + } else { + /* Interrupts disabled, this means that we cannot + * use get_timer(), it relies on IRQ. Instead the + * CPU frequency is used. + */ + cpu_wait_ms_busy(ticks2usec(ticks) / 1000); + } } int timer_interrupt_init_cpu(void) -- cgit v1.2.3 From 7a4fb11b85939b47738283c3a7ae7f461468e274 Mon Sep 17 00:00:00 2001 From: Francois Retief Date: Sat, 21 Nov 2015 23:15:07 +0200 Subject: sparc: Remove non-generic board init files: board.c, time.c Remove the board.c and time.c files and all associated non-generic board initialization code. Signed-off-by: Francois Retief --- arch/sparc/cpu/leon3/cpu_init.c | 60 ----------------------------------------- 1 file changed, 60 deletions(-) (limited to 'arch/sparc/cpu/leon3/cpu_init.c') diff --git a/arch/sparc/cpu/leon3/cpu_init.c b/arch/sparc/cpu/leon3/cpu_init.c index 9e294bfd0eb..f25388cf841 100644 --- a/arch/sparc/cpu/leon3/cpu_init.c +++ b/arch/sparc/cpu/leon3/cpu_init.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -29,9 +28,6 @@ #define CONFIG_SYS_GRLIB_GPTIMER_INDEX 0 #endif -#define TIMER_BASE_CLK 1000000 -#define US_PER_TICK (1000000 / CONFIG_SYS_HZ) - DECLARE_GLOBAL_DATA_PTR; ambapp_dev_irqmp *irqmp = NULL; @@ -142,63 +138,7 @@ int cpu_init_r(void) return 0; } -/* Busy wait a number of ms */ -void cpu_wait_ms_busy(unsigned long ms) -{ - unsigned int ms_delay; - volatile unsigned int tmp; - - /* ~10-20 cycles per decrement */ - ms_delay = leon_cpu_freq / (1000 * 10); - do { - /* Wait ~1ms */ - tmp = ms_delay; - while (tmp-- > 0) - ; - } while (--ms > 0); -} - -/* Uses Timer 0 to get accurate - * pauses. Max 2 raised to 32 ticks - * - */ -void cpu_wait_ticks(unsigned long ticks) -{ - unsigned long start; - - if (interrupt_is_enabled()) { - start = get_timer(0); - while (get_timer(start) < ticks) ; - } else { - /* Interrupts disabled, this means that we cannot - * use get_timer(), it relies on IRQ. Instead the - * CPU frequency is used. - */ - cpu_wait_ms_busy(ticks2usec(ticks) / 1000); - } -} - -int timer_interrupt_init_cpu(void) -{ - return -1; -} - -/* - * This function is intended for SHORT delays only. - */ -unsigned long cpu_usec2ticks(unsigned long usec) -{ - if (usec < US_PER_TICK) - return 1; - return usec / US_PER_TICK; -} - -unsigned long cpu_ticks2usec(unsigned long ticks) -{ - return ticks * US_PER_TICK; -} - int timer_init(void) { ambapp_dev_gptimer_element *tmr; -- cgit v1.2.3