1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2004,2009-2011 Freescale Semiconductor, Inc.
4  * Jeff Brown
5  * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
6  */
7 
8 /*
9  * cpu_init.c - low level cpu init
10  */
11 
12 #include <config.h>
13 #include <common.h>
14 #include <mpc86xx.h>
15 #include <asm/mmu.h>
16 #include <asm/fsl_law.h>
17 #include <asm/fsl_serdes.h>
18 #include <asm/mp.h>
19 
20 extern void srio_init(void);
21 
22 DECLARE_GLOBAL_DATA_PTR;
23 
24 /*
25  * Breathe some life into the CPU...
26  *
27  * Set up the memory map
28  * initialize a bunch of registers
29  */
30 
31 void cpu_init_f(void)
32 {
33 	/* Pointer is writable since we allocated a register for it */
34 	gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
35 
36 	/* Clear initial global data */
37 	memset ((void *) gd, 0, sizeof (gd_t));
38 
39 #ifdef CONFIG_FSL_LAW
40 	init_laws();
41 #endif
42 
43 	setup_bats();
44 
45 	init_early_memctl_regs();
46 
47 #if defined(CONFIG_FSL_DMA)
48 	dma_init();
49 #endif
50 
51 	/* enable the timebase bit in HID0 */
52 	set_hid0(get_hid0() | 0x4000000);
53 
54 	/* enable EMCP, SYNCBE | ABE bits in HID1 */
55 	set_hid1(get_hid1() | 0x80000C00);
56 }
57 
58 /*
59  * initialize higher level parts of CPU like timers
60  */
61 int cpu_init_r(void)
62 {
63 	/* needs to be in ram since code uses global static vars */
64 	fsl_serdes_init();
65 
66 #ifdef CONFIG_SYS_SRIO
67 	srio_init();
68 #endif
69 
70 #if defined(CONFIG_MP)
71 	setup_mp();
72 #endif
73 	return 0;
74 }
75 
76 #ifdef CONFIG_ADDR_MAP
77 /* Initialize address mapping array */
78 void init_addr_map(void)
79 {
80 	int i;
81 	ppc_bat_t bat = DBAT0;
82 	phys_size_t size;
83 	unsigned long upper, lower;
84 
85 	for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++, bat++) {
86 		if (read_bat(bat, &upper, &lower) != -1) {
87 			if (!BATU_VALID(upper))
88 				size = 0;
89 			else
90 				size = BATU_SIZE(upper);
91 			addrmap_set_entry(BATU_VADDR(upper), BATL_PADDR(lower),
92 					  size, i);
93 		}
94 #ifdef CONFIG_HIGH_BATS
95 		/* High bats are not contiguous with low BAT numbers */
96 		if (bat == DBAT3)
97 			bat = DBAT4 - 1;
98 #endif
99 	}
100 }
101 #endif
102