1 /* Initializes CPU and basic hardware such as memory
2 * controllers, IRQ controller and system timer 0.
5 * Daniel Hellstrom, Gaisler Research, 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;
21 /* reset CPU (jump to 0, without reset) */
30 * Breath some life into the CPU...
32 * Set up the memory map,
33 * initialize a bunch of registers.
35 * Run from FLASH/PROM:
36 * - until memory controller is set up, only registers available
37 * - no global variables available for writing
38 * - constants available
43 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
45 /* initialize the IRQMP */
46 leon2->Interrupt_Force = 0;
47 leon2->Interrupt_Pending = 0;
48 leon2->Interrupt_Clear = 0xfffe; /* clear all old pending interrupts */
49 leon2->Interrupt_Mask = 0xfffe0000; /* mask all IRQs */
54 #ifdef LEON2_IO_PORT_DIR
55 leon2->PIO_Direction = LEON2_IO_PORT_DIR;
57 #ifdef LEON2_IO_PORT_DATA
58 leon2->PIO_Data = LEON2_IO_PORT_DATA;
60 #ifdef LEON2_IO_PORT_INT
61 leon2->PIO_Interrupt = LEON2_IO_PORT_INT;
63 leon2->PIO_Interrupt = 0;
67 void cpu_init_f2(void)
73 * initialize higher level parts of CPU like time base and timers
77 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
79 /* initialize prescaler common to all timers to 1MHz */
80 leon2->Scaler_Counter = leon2->Scaler_Reload =
81 (((CONFIG_SYS_CLK_FREQ / 1000) + 500) / 1000) - 1;
86 /* Uses Timer 0 to get accurate
87 * pauses. Max 2 raised to 32 ticks
90 void cpu_wait_ticks(unsigned long ticks)
92 unsigned long start = get_timer(0);
93 while (get_timer(start) < ticks) ;
96 /* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz.
97 * Return irq number for timer int or a negative number for
100 int timer_interrupt_init_cpu(void)
102 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
104 /* SYS_HZ ticks per second */
105 leon2->Timer_Counter_1 = 0;
106 leon2->Timer_Reload_1 = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1;
107 leon2->Timer_Control_1 =
108 (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
110 return LEON2_TIMER1_IRQNO;
113 ulong get_tbclk(void)
115 return TIMER_BASE_CLK;
119 * This function is intended for SHORT delays only.
121 unsigned long cpu_usec2ticks(unsigned long usec)
123 if (usec < US_PER_TICK)
125 return usec / US_PER_TICK;
128 unsigned long cpu_ticks2usec(unsigned long ticks)
130 return ticks * US_PER_TICK;