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