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 /* Default Plug&Play I/O area */
18 #ifndef CONFIG_AMBAPP_IOAREA
19 #define CONFIG_AMBAPP_IOAREA AMBA_DEFAULT_IOAREA
22 #define TIMER_BASE_CLK 1000000
23 #define US_PER_TICK (1000000 / CONFIG_SYS_HZ)
25 DECLARE_GLOBAL_DATA_PTR;
27 /* reset CPU (jump to 0, without reset) */
30 /* find & initialize the memory controller */
31 int init_memory_ctrl(void);
33 ambapp_dev_irqmp *irqmp = NULL;
34 ambapp_dev_mctrl memctrl;
35 ambapp_dev_gptimer *gptimer = NULL;
36 unsigned int gptimer_irq = 0;
37 int leon3_snooping_avail = 0;
45 * Breath some life into the CPU...
47 * Run from FLASH/PROM:
48 * - until memory controller is set up, only registers available
49 * - memory controller has already been setup up, stack can be used
50 * - no global variables available for writing
51 * - constants available
58 /* Routine called from start.S,
60 * Run from FLASH/PROM:
61 * - memory controller has already been setup up, stack can be used
62 * - global variables available for read/writing
63 * - constants avaiable
65 void cpu_init_f2(void)
67 /* Initialize the AMBA Plug & Play bus structure, the bus
68 * structure represents the AMBA bus that the CPU is located at.
70 ambapp_bus_init(CONFIG_AMBAPP_IOAREA, CONFIG_SYS_CLK_FREQ, &ambapp_plb);
74 * initialize higher level parts of CPU like time base and timers
80 ambapp_dev_gptimer *timer = NULL;
81 unsigned int bus_freq;
84 * Find AMBA APB IRQMP Controller,
86 if (ambapp_apb_find(&ambapp_plb, VENDOR_GAISLER,
87 GAISLER_IRQMP, 0, &apbdev) != 1) {
88 panic("%s: IRQ controller not found\n", __func__);
91 irqmp = (ambapp_dev_irqmp *)apbdev.address;
93 /* initialize the IRQMP */
94 irqmp->ilevel = 0xf; /* all IRQ off */
97 irqmp->iclear = 0xfffe; /* clear all old pending interrupts */
98 for (cpu = 0; cpu < 16; cpu++) {
99 /* mask and clear force for all IRQs on CPU[N] */
100 irqmp->cpu_mask[cpu] = 0;
101 irqmp->cpu_force[cpu] = 0;
106 while (ambapp_apb_find(&ambapp_plb, VENDOR_GAISLER, GAISLER_GPTIMER,
107 index, &apbdev) == 1) {
108 timer = (ambapp_dev_gptimer *)apbdev.address;
109 if (gptimer == NULL) {
111 gptimer_irq = apbdev.irq;
114 /* Different buses may have different frequency, the
115 * frequency of the bus tell in which frequency the timer
116 * prescaler operates.
118 bus_freq = ambapp_bus_freq(&ambapp_plb, apbdev.ahb_bus_index);
120 /* initialize prescaler common to all timers to 1MHz */
121 timer->scalar = timer->scalar_reload =
122 (((bus_freq / 1000) + 500) / 1000) - 1;
127 printf("%s: gptimer not found!\n", __func__);
133 /* Uses Timer 0 to get accurate
134 * pauses. Max 2 raised to 32 ticks
137 void cpu_wait_ticks(unsigned long ticks)
139 unsigned long start = get_timer(0);
140 while (get_timer(start) < ticks) ;
143 /* initiate and setup timer0 interrupt to configured HZ. Base clock is 1MHz.
144 * Return irq number for timer int or a negative number for
147 int timer_interrupt_init_cpu(void)
149 /* SYS_HZ ticks per second */
150 gptimer->e[0].val = 0;
151 gptimer->e[0].rld = (TIMER_BASE_CLK / CONFIG_SYS_HZ) - 1;
154 LEON3_GPTIMER_RL | LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
159 ulong get_tbclk(void)
161 return TIMER_BASE_CLK;
165 * This function is intended for SHORT delays only.
167 unsigned long cpu_usec2ticks(unsigned long usec)
169 if (usec < US_PER_TICK)
171 return usec / US_PER_TICK;
174 unsigned long cpu_ticks2usec(unsigned long ticks)
176 return ticks * US_PER_TICK;