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