]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/sparc/cpu/leon2/cpu_init.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / sparc / cpu / leon2 / cpu_init.c
CommitLineData
b330990c
DH
1/* Initializes CPU and basic hardware such as memory
2 * controllers, IRQ controller and system timer 0.
3 *
4 * (C) Copyright 2007
5 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com
6 *
1a459660 7 * SPDX-License-Identifier: GPL-2.0+
b330990c
DH
8 */
9
10#include <common.h>
11#include <asm/asi.h>
12#include <asm/leon.h>
13
14#include <config.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18/* reset CPU (jump to 0, without reset) */
19void start(void);
20
21struct {
22 gd_t gd_area;
23 bd_t bd;
24} global_data;
25
26/*
27 * Breath some life into the CPU...
28 *
29 * Set up the memory map,
30 * initialize a bunch of registers.
31 *
32 * Run from FLASH/PROM:
6052cbab 33 * - until memory controller is set up, only registers available
b330990c 34 * - no global variables available for writing
6052cbab 35 * - constants available
b330990c
DH
36 */
37
38void cpu_init_f(void)
39{
40 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
41
42 /* initialize the IRQMP */
43 leon2->Interrupt_Force = 0;
44 leon2->Interrupt_Pending = 0;
45 leon2->Interrupt_Clear = 0xfffe; /* clear all old pending interrupts */
46 leon2->Interrupt_Mask = 0xfffe0000; /* mask all IRQs */
47
48 /* cache */
49
50 /* I/O port setup */
51#ifdef LEON2_IO_PORT_DIR
52 leon2->PIO_Direction = LEON2_IO_PORT_DIR;
53#endif
54#ifdef LEON2_IO_PORT_DATA
55 leon2->PIO_Data = LEON2_IO_PORT_DATA;
56#endif
57#ifdef LEON2_IO_PORT_INT
58 leon2->PIO_Interrupt = LEON2_IO_PORT_INT;
59#else
60 leon2->PIO_Interrupt = 0;
61#endif
62}
63
64void cpu_init_f2(void)
65{
66
67}
68
69/*
70 * initialize higher level parts of CPU like time base and timers
71 */
72int cpu_init_r(void)
73{
74 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
75
76 /* initialize prescaler common to all timers to 1MHz */
77 leon2->Scaler_Counter = leon2->Scaler_Reload =
78 (((CONFIG_SYS_CLK_FREQ / 1000) + 500) / 1000) - 1;
79
80 return (0);
81}
82
83/* Uses Timer 0 to get accurate
84 * pauses. Max 2 raised to 32 ticks
85 *
86 */
87void cpu_wait_ticks(unsigned long ticks)
88{
89 unsigned long start = get_timer(0);
90 while (get_timer(start) < ticks) ;
91}
92
93/* initiate and setup timer0 interrupt to 1MHz
94 * Return irq number for timer int or a negative number for
95 * dealing with self
96 */
97int timer_interrupt_init_cpu(void)
98{
99 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
100
101 /* 1ms ticks */
102 leon2->Timer_Counter_1 = 0;
103 leon2->Timer_Reload_1 = 999; /* (((1000000 / 100) - 1)) */
104 leon2->Timer_Control_1 =
105 (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
106
107 return LEON2_TIMER1_IRQNO;
108}
109
110/*
111 * This function is intended for SHORT delays only.
112 */
113unsigned long cpu_usec2ticks(unsigned long usec)
114{
115 /* timer set to 1kHz ==> 1 clk tick = 1 msec */
116 if (usec < 1000)
117 return 1;
118 return (usec / 1000);
119}
120
121unsigned long cpu_ticks2usec(unsigned long ticks)
122{
123 /* 1tick = 1usec */
124 return ticks * 1000;
125}