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+
17 #define TIMER_BASE_CLK 1000000
18 #define US_PER_TICK (1000000 / CONFIG_SYS_HZ)
20 DECLARE_GLOBAL_DATA_PTR;
23 * Breath some life into the CPU...
25 * Set up the memory map,
26 * initialize a bunch of registers.
28 * Run from FLASH/PROM:
29 * - until memory controller is set up, only registers available
30 * - no global variables available for writing
31 * - constants available
36 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
38 /* initialize the IRQMP */
39 leon2->Interrupt_Force = 0;
40 leon2->Interrupt_Pending = 0;
41 leon2->Interrupt_Clear = 0xfffe; /* clear all old pending interrupts */
42 leon2->Interrupt_Mask = 0xfffe0000; /* mask all IRQs */
47 #ifdef LEON2_IO_PORT_DIR
48 leon2->PIO_Direction = LEON2_IO_PORT_DIR;
50 #ifdef LEON2_IO_PORT_DATA
51 leon2->PIO_Data = LEON2_IO_PORT_DATA;
53 #ifdef LEON2_IO_PORT_INT
54 leon2->PIO_Interrupt = LEON2_IO_PORT_INT;
56 leon2->PIO_Interrupt = 0;
60 leon2->Timer_Control_1 = leon2->Timer_Control_2 = 0;
63 int arch_cpu_init(void)
65 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
66 gd->bus_clk = CONFIG_SYS_CLK_FREQ;
67 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
73 * initialize higher level parts of CPU
80 /* Uses Timer 0 to get accurate
81 * pauses. Max 2 raised to 32 ticks
84 void cpu_wait_ticks(unsigned long ticks)
86 unsigned long start = get_timer(0);
87 while (get_timer(start) < ticks) ;
90 /* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz.
91 * Return irq number for timer int or a negative number for
94 int timer_interrupt_init_cpu(void)
96 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
98 /* SYS_HZ ticks per second */
99 leon2->Timer_Counter_1 = 0;
100 leon2->Timer_Reload_1 = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1;
101 leon2->Timer_Control_1 =
102 (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
104 return LEON2_TIMER1_IRQNO;
108 * This function is intended for SHORT delays only.
110 unsigned long cpu_usec2ticks(unsigned long usec)
112 if (usec < US_PER_TICK)
114 return usec / US_PER_TICK;
117 unsigned long cpu_ticks2usec(unsigned long ticks)
119 return ticks * US_PER_TICK;
124 LEON2_regs *leon2 = (LEON2_regs *)LEON2_PREGS;
126 /* initialize prescaler common to all timers to 1MHz */
127 leon2->Scaler_Counter = leon2->Scaler_Reload =
128 (((CONFIG_SYS_CLK_FREQ / 1000) + 500) / 1000) - 1;
130 /* SYS_HZ ticks per second */
131 leon2->Timer_Counter_1 = 0;
132 leon2->Timer_Reload_1 = (CONFIG_SYS_TIMER_RATE / CONFIG_SYS_HZ) - 1;
133 leon2->Timer_Control_1 = LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS |
136 CONFIG_SYS_TIMER_COUNTER = (void *)&leon2->Timer_Counter_1;