]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/sparc/cpu/leon2/cpu_init.c
sparc: Initial ground work for generic board initialization
[people/ms/u-boot.git] / arch / sparc / cpu / leon2 / cpu_init.c
1 /* Initializes CPU and basic hardware such as memory
2 * controllers, IRQ controller and system timer 0.
3 *
4 * (C) Copyright 2007, 2015
5 * Daniel Hellstrom, Cobham Gaisler, daniel@gaisler.com
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10 #include <common.h>
11 #include <asm/asi.h>
12 #include <asm/leon.h>
13
14 #include <config.h>
15
16 #define TIMER_BASE_CLK 1000000
17 #define US_PER_TICK (1000000 / CONFIG_SYS_HZ)
18
19 DECLARE_GLOBAL_DATA_PTR;
20
21 /*
22 * Breath some life into the CPU...
23 *
24 * Set up the memory map,
25 * initialize a bunch of registers.
26 *
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
31 */
32
33 void cpu_init_f(void)
34 {
35 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
36
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 */
42
43 /* cache */
44
45 /* I/O port setup */
46 #ifdef LEON2_IO_PORT_DIR
47 leon2->PIO_Direction = LEON2_IO_PORT_DIR;
48 #endif
49 #ifdef LEON2_IO_PORT_DATA
50 leon2->PIO_Data = LEON2_IO_PORT_DATA;
51 #endif
52 #ifdef LEON2_IO_PORT_INT
53 leon2->PIO_Interrupt = LEON2_IO_PORT_INT;
54 #else
55 leon2->PIO_Interrupt = 0;
56 #endif
57 }
58
59 void cpu_init_f2(void)
60 {
61
62 }
63
64 int arch_cpu_init(void)
65 {
66 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
67 gd->bus_clk = CONFIG_SYS_CLK_FREQ;
68 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
69
70 return 0;
71 }
72
73 /*
74 * initialize higher level parts of CPU like time base and timers
75 */
76 int cpu_init_r(void)
77 {
78 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
79
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;
83
84 return (0);
85 }
86
87 /* Uses Timer 0 to get accurate
88 * pauses. Max 2 raised to 32 ticks
89 *
90 */
91 void cpu_wait_ticks(unsigned long ticks)
92 {
93 unsigned long start = get_timer(0);
94 while (get_timer(start) < ticks) ;
95 }
96
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
99 * dealing with self
100 */
101 int timer_interrupt_init_cpu(void)
102 {
103 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
104
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);
110
111 return LEON2_TIMER1_IRQNO;
112 }
113
114 ulong get_tbclk(void)
115 {
116 return TIMER_BASE_CLK;
117 }
118
119 /*
120 * This function is intended for SHORT delays only.
121 */
122 unsigned long cpu_usec2ticks(unsigned long usec)
123 {
124 if (usec < US_PER_TICK)
125 return 1;
126 return usec / US_PER_TICK;
127 }
128
129 unsigned long cpu_ticks2usec(unsigned long ticks)
130 {
131 return ticks * US_PER_TICK;
132 }