xref: /OK3568_Linux_fs/u-boot/board/freescale/mpc8313erdb/mpc8313erdb.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) Freescale Semiconductor, Inc. 2006-2007
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Author: Scott Wood <scottwood@freescale.com>
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun #if defined(CONFIG_OF_LIBFDT)
11*4882a593Smuzhiyun #include <linux/libfdt.h>
12*4882a593Smuzhiyun #endif
13*4882a593Smuzhiyun #include <pci.h>
14*4882a593Smuzhiyun #include <mpc83xx.h>
15*4882a593Smuzhiyun #include <vsc7385.h>
16*4882a593Smuzhiyun #include <ns16550.h>
17*4882a593Smuzhiyun #include <nand.h>
18*4882a593Smuzhiyun #if defined(CONFIG_MPC83XX_GPIO) && !defined(CONFIG_SPL_BUILD)
19*4882a593Smuzhiyun #include <asm/gpio.h>
20*4882a593Smuzhiyun #endif
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
23*4882a593Smuzhiyun 
board_early_init_f(void)24*4882a593Smuzhiyun int board_early_init_f(void)
25*4882a593Smuzhiyun {
26*4882a593Smuzhiyun #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC
27*4882a593Smuzhiyun 	volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
30*4882a593Smuzhiyun 		gd->flags |= GD_FLG_SILENT;
31*4882a593Smuzhiyun #endif
32*4882a593Smuzhiyun #if defined(CONFIG_MPC83XX_GPIO) && !defined(CONFIG_SPL_BUILD)
33*4882a593Smuzhiyun 	mpc83xx_gpio_init_f();
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	return 0;
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun 
board_early_init_r(void)39*4882a593Smuzhiyun int board_early_init_r(void)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun #if defined(CONFIG_MPC83XX_GPIO) && !defined(CONFIG_SPL_BUILD)
42*4882a593Smuzhiyun 	mpc83xx_gpio_init_r();
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	return 0;
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun 
checkboard(void)48*4882a593Smuzhiyun int checkboard(void)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun 	puts("Board: Freescale MPC8313ERDB\n");
51*4882a593Smuzhiyun 	return 0;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #ifndef CONFIG_SPL_BUILD
55*4882a593Smuzhiyun static struct pci_region pci_regions[] = {
56*4882a593Smuzhiyun 	{
57*4882a593Smuzhiyun 		.bus_start = CONFIG_SYS_PCI1_MEM_BASE,
58*4882a593Smuzhiyun 		.phys_start = CONFIG_SYS_PCI1_MEM_PHYS,
59*4882a593Smuzhiyun 		.size = CONFIG_SYS_PCI1_MEM_SIZE,
60*4882a593Smuzhiyun 		.flags = PCI_REGION_MEM | PCI_REGION_PREFETCH
61*4882a593Smuzhiyun 	},
62*4882a593Smuzhiyun 	{
63*4882a593Smuzhiyun 		.bus_start = CONFIG_SYS_PCI1_MMIO_BASE,
64*4882a593Smuzhiyun 		.phys_start = CONFIG_SYS_PCI1_MMIO_PHYS,
65*4882a593Smuzhiyun 		.size = CONFIG_SYS_PCI1_MMIO_SIZE,
66*4882a593Smuzhiyun 		.flags = PCI_REGION_MEM
67*4882a593Smuzhiyun 	},
68*4882a593Smuzhiyun 	{
69*4882a593Smuzhiyun 		.bus_start = CONFIG_SYS_PCI1_IO_BASE,
70*4882a593Smuzhiyun 		.phys_start = CONFIG_SYS_PCI1_IO_PHYS,
71*4882a593Smuzhiyun 		.size = CONFIG_SYS_PCI1_IO_SIZE,
72*4882a593Smuzhiyun 		.flags = PCI_REGION_IO
73*4882a593Smuzhiyun 	}
74*4882a593Smuzhiyun };
75*4882a593Smuzhiyun 
pci_init_board(void)76*4882a593Smuzhiyun void pci_init_board(void)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun 	volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
79*4882a593Smuzhiyun 	volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
80*4882a593Smuzhiyun 	volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
81*4882a593Smuzhiyun 	struct pci_region *reg[] = { pci_regions };
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	/* Enable all 3 PCI_CLK_OUTPUTs. */
84*4882a593Smuzhiyun 	clk->occr |= 0xe0000000;
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	/*
87*4882a593Smuzhiyun 	 * Configure PCI Local Access Windows
88*4882a593Smuzhiyun 	 */
89*4882a593Smuzhiyun 	pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
90*4882a593Smuzhiyun 	pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
93*4882a593Smuzhiyun 	pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	mpc83xx_pci_init(1, reg);
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /*
99*4882a593Smuzhiyun  * Miscellaneous late-boot configurations
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  * If a VSC7385 microcode image is present, then upload it.
102*4882a593Smuzhiyun */
misc_init_r(void)103*4882a593Smuzhiyun int misc_init_r(void)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun 	int rc = 0;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #ifdef CONFIG_VSC7385_IMAGE
108*4882a593Smuzhiyun 	if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
109*4882a593Smuzhiyun 		CONFIG_VSC7385_IMAGE_SIZE)) {
110*4882a593Smuzhiyun 		puts("Failure uploading VSC7385 microcode.\n");
111*4882a593Smuzhiyun 		rc = 1;
112*4882a593Smuzhiyun 	}
113*4882a593Smuzhiyun #endif
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	return rc;
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,bd_t * bd)119*4882a593Smuzhiyun int ft_board_setup(void *blob, bd_t *bd)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	ft_cpu_setup(blob, bd);
122*4882a593Smuzhiyun #ifdef CONFIG_PCI
123*4882a593Smuzhiyun 	ft_pci_setup(blob, bd);
124*4882a593Smuzhiyun #endif
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	return 0;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun #endif
129*4882a593Smuzhiyun #else /* CONFIG_SPL_BUILD */
board_init_f(ulong bootflag)130*4882a593Smuzhiyun void board_init_f(ulong bootflag)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun 	board_early_init_f();
133*4882a593Smuzhiyun 	NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500),
134*4882a593Smuzhiyun 		     CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
135*4882a593Smuzhiyun 	puts("NAND boot... ");
136*4882a593Smuzhiyun 	timer_init();
137*4882a593Smuzhiyun 	dram_init();
138*4882a593Smuzhiyun 	relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC_SP, (gd_t *)gd,
139*4882a593Smuzhiyun 		      CONFIG_SYS_NAND_U_BOOT_RELOC);
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun 
board_init_r(gd_t * gd,ulong dest_addr)142*4882a593Smuzhiyun void board_init_r(gd_t *gd, ulong dest_addr)
143*4882a593Smuzhiyun {
144*4882a593Smuzhiyun 	nand_boot();
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun 
putc(char c)147*4882a593Smuzhiyun void putc(char c)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun 	if (gd->flags & GD_FLG_SILENT)
150*4882a593Smuzhiyun 		return;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	if (c == '\n')
153*4882a593Smuzhiyun 		NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r');
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c);
156*4882a593Smuzhiyun }
157*4882a593Smuzhiyun #endif
158