]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/sparc/cpu/leon2/cpu_init.c
1 /* Initializes CPU and basic hardware such as memory
2 * controllers, IRQ controller and system timer 0.
4 * (C) Copyright 2007, 2015
5 * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com
7 * SPDX-License-Identifier: GPL-2.0+
16 #define TIMER_BASE_CLK 1000000
17 #define US_PER_TICK (1000000 / CONFIG_SYS_HZ)
19 DECLARE_GLOBAL_DATA_PTR
;
22 * Breath some life into the CPU...
24 * Set up the memory map,
25 * initialize a bunch of registers.
27 * Run from FLASH/PROM:
28 * - until memory controller is set up, only registers available
29 * - no global variables available for writing
30 * - constants available
35 LEON2_regs
*leon2
= (LEON2_regs
*) LEON2_PREGS
;
37 /* initialize the IRQMP */
38 leon2
->Interrupt_Force
= 0;
39 leon2
->Interrupt_Pending
= 0;
40 leon2
->Interrupt_Clear
= 0xfffe; /* clear all old pending interrupts */
41 leon2
->Interrupt_Mask
= 0xfffe0000; /* mask all IRQs */
46 #ifdef LEON2_IO_PORT_DIR
47 leon2
->PIO_Direction
= LEON2_IO_PORT_DIR
;
49 #ifdef LEON2_IO_PORT_DATA
50 leon2
->PIO_Data
= LEON2_IO_PORT_DATA
;
52 #ifdef LEON2_IO_PORT_INT
53 leon2
->PIO_Interrupt
= LEON2_IO_PORT_INT
;
55 leon2
->PIO_Interrupt
= 0;
59 void cpu_init_f2(void)
64 int arch_cpu_init(void)
66 gd
->cpu_clk
= CONFIG_SYS_CLK_FREQ
;
67 gd
->bus_clk
= CONFIG_SYS_CLK_FREQ
;
68 gd
->ram_size
= CONFIG_SYS_SDRAM_SIZE
;
74 * initialize higher level parts of CPU like time base and timers
78 LEON2_regs
*leon2
= (LEON2_regs
*) LEON2_PREGS
;
80 /* initialize prescaler common to all timers to 1MHz */
81 leon2
->Scaler_Counter
= leon2
->Scaler_Reload
=
82 (((CONFIG_SYS_CLK_FREQ
/ 1000) + 500) / 1000) - 1;
87 /* Uses Timer 0 to get accurate
88 * pauses. Max 2 raised to 32 ticks
91 void cpu_wait_ticks(unsigned long ticks
)
93 unsigned long start
= get_timer(0);
94 while (get_timer(start
) < ticks
) ;
97 /* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz.
98 * Return irq number for timer int or a negative number for
101 int timer_interrupt_init_cpu(void)
103 LEON2_regs
*leon2
= (LEON2_regs
*) LEON2_PREGS
;
105 /* SYS_HZ ticks per second */
106 leon2
->Timer_Counter_1
= 0;
107 leon2
->Timer_Reload_1
= (TIMER_BASE_CLK
/ CONFIG_SYS_HZ
) - 1;
108 leon2
->Timer_Control_1
=
109 (LEON2_TIMER_CTRL_EN
| LEON2_TIMER_CTRL_RS
| LEON2_TIMER_CTRL_LD
);
111 return LEON2_TIMER1_IRQNO
;
114 ulong
get_tbclk(void)
116 return TIMER_BASE_CLK
;
120 * This function is intended for SHORT delays only.
122 unsigned long cpu_usec2ticks(unsigned long usec
)
124 if (usec
< US_PER_TICK
)
126 return usec
/ US_PER_TICK
;
129 unsigned long cpu_ticks2usec(unsigned long ticks
)
131 return ticks
* US_PER_TICK
;