blob: f8e4599f13f7634053b8dcaa3df5e6225bdd3089 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dave Liu19b247e2008-01-11 18:48:24 +08002/*
3 * Copyright (C) 2007 Freescale Semiconductor, Inc.
4 *
5 * Author: Scott Wood <scottwood@freescale.com>
6 * Dave Liu <daveliu@freescale.com>
Dave Liu19b247e2008-01-11 18:48:24 +08007 */
8
9#include <common.h>
Anton Vorontsovd398b7e2009-06-10 00:25:36 +040010#include <hwconfig.h>
Dave Liu19b247e2008-01-11 18:48:24 +080011#include <i2c.h>
Simon Glass18afe102019-11-14 12:57:47 -070012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Simon Glassdbd79542020-05-10 11:40:11 -060014#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Anton Vorontsov13c16a12008-07-08 21:00:04 +040016#include <fdt_support.h>
Dave Liu19b247e2008-01-11 18:48:24 +080017#include <pci.h>
18#include <mpc83xx.h>
Ben Warren052a5ea2008-08-31 20:37:00 -070019#include <netdev.h>
Anton Vorontsov0db0be22009-01-08 04:26:17 +030020#include <asm/io.h>
Anton Vorontsovec821752009-11-24 20:12:12 +030021#include <ns16550.h>
22#include <nand.h>
Dave Liu19b247e2008-01-11 18:48:24 +080023
24DECLARE_GLOBAL_DATA_PTR;
25
26int board_early_init_f(void)
27{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020028 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu19b247e2008-01-11 18:48:24 +080029
30 if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
31 gd->flags |= GD_FLG_SILENT;
32
33 return 0;
34}
35
Anton Vorontsovec821752009-11-24 20:12:12 +030036#ifndef CONFIG_NAND_SPL
37
Dave Liu19b247e2008-01-11 18:48:24 +080038static u8 read_board_info(void)
39{
40 u8 val8;
41 i2c_set_bus_num(0);
42
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043 if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0)
Dave Liu19b247e2008-01-11 18:48:24 +080044 return val8;
45 else
46 return 0;
47}
48
49int checkboard(void)
50{
51 static const char * const rev_str[] = {
52 "0.0",
53 "0.1",
54 "1.0",
55 "1.1",
56 "<unknown>",
57 };
58 u8 info;
59 int i;
60
61 info = read_board_info();
62 i = (!info) ? 4: info & 0x03;
63
64 printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]);
65
66 return 0;
67}
68
69static struct pci_region pci_regions[] = {
70 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071 bus_start: CONFIG_SYS_PCI_MEM_BASE,
72 phys_start: CONFIG_SYS_PCI_MEM_PHYS,
73 size: CONFIG_SYS_PCI_MEM_SIZE,
Dave Liu19b247e2008-01-11 18:48:24 +080074 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
75 },
76 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020077 bus_start: CONFIG_SYS_PCI_MMIO_BASE,
78 phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
79 size: CONFIG_SYS_PCI_MMIO_SIZE,
Dave Liu19b247e2008-01-11 18:48:24 +080080 flags: PCI_REGION_MEM
81 },
82 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020083 bus_start: CONFIG_SYS_PCI_IO_BASE,
84 phys_start: CONFIG_SYS_PCI_IO_PHYS,
85 size: CONFIG_SYS_PCI_IO_SIZE,
Dave Liu19b247e2008-01-11 18:48:24 +080086 flags: PCI_REGION_IO
87 }
88};
89
Anton Vorontsov0db0be22009-01-08 04:26:17 +030090static struct pci_region pcie_regions_0[] = {
91 {
92 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
93 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
94 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
95 .flags = PCI_REGION_MEM,
96 },
97 {
98 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
99 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
100 .size = CONFIG_SYS_PCIE1_IO_SIZE,
101 .flags = PCI_REGION_IO,
102 },
103};
104
105static struct pci_region pcie_regions_1[] = {
106 {
107 .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
108 .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
109 .size = CONFIG_SYS_PCIE2_MEM_SIZE,
110 .flags = PCI_REGION_MEM,
111 },
112 {
113 .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
114 .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
115 .size = CONFIG_SYS_PCIE2_IO_SIZE,
116 .flags = PCI_REGION_IO,
117 },
118};
119
Dave Liu19b247e2008-01-11 18:48:24 +0800120void pci_init_board(void)
121{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200122 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov0db0be22009-01-08 04:26:17 +0300123 volatile sysconf83xx_t *sysconf = &immr->sysconf;
Dave Liu19b247e2008-01-11 18:48:24 +0800124 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
125 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
Anton Vorontsov0db0be22009-01-08 04:26:17 +0300126 volatile law83xx_t *pcie_law = sysconf->pcielaw;
Dave Liu19b247e2008-01-11 18:48:24 +0800127 struct pci_region *reg[] = { pci_regions };
Anton Vorontsov0db0be22009-01-08 04:26:17 +0300128 struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
Dave Liu19b247e2008-01-11 18:48:24 +0800129
130 /* Enable all 3 PCI_CLK_OUTPUTs. */
131 clk->occr |= 0xe0000000;
132
133 /*
134 * Configure PCI Local Access Windows
135 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
Dave Liu19b247e2008-01-11 18:48:24 +0800137 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
138
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
Dave Liu19b247e2008-01-11 18:48:24 +0800140 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
141
Peter Tysere2283322010-09-14 19:13:50 -0500142 mpc83xx_pci_init(1, reg);
Anton Vorontsov0db0be22009-01-08 04:26:17 +0300143
144 /* Configure the clock for PCIE controller */
145 clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
146 SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
147
148 /* Deassert the resets in the control register */
149 out_be32(&sysconf->pecr1, 0xE0008000);
150 out_be32(&sysconf->pecr2, 0xE0008000);
151 udelay(2000);
152
153 /* Configure PCI Express Local Access Windows */
154 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
155 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
156
157 out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
158 out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
159
Peter Tysere2283322010-09-14 19:13:50 -0500160 mpc83xx_pcie_init(2, pcie_reg);
Dave Liu19b247e2008-01-11 18:48:24 +0800161}
162
163#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900164void fdt_tsec1_fixup(void *fdt, struct bd_info *bd)
Anton Vorontsov13c16a12008-07-08 21:00:04 +0400165{
Anton Vorontsov13c16a12008-07-08 21:00:04 +0400166 const char disabled[] = "disabled";
167 const char *path;
168 int ret;
169
Anton Vorontsovd398b7e2009-06-10 00:25:36 +0400170 if (hwconfig_arg_cmp("board_type", "tsec1")) {
Anton Vorontsov87481782008-07-10 17:20:51 +0400171 return;
Anton Vorontsovd398b7e2009-06-10 00:25:36 +0400172 } else if (!hwconfig_arg_cmp("board_type", "ulpi")) {
173 printf("NOTICE: No or unknown board_type hwconfig specified.\n"
174 " Assuming board with TSEC1.\n");
Anton Vorontsov87481782008-07-10 17:20:51 +0400175 return;
Anton Vorontsov13c16a12008-07-08 21:00:04 +0400176 }
177
178 ret = fdt_path_offset(fdt, "/aliases");
179 if (ret < 0) {
180 printf("WARNING: can't find /aliases node\n");
181 return;
182 }
183
184 path = fdt_getprop(fdt, ret, "ethernet0", NULL);
185 if (!path) {
186 printf("WARNING: can't find ethernet0 alias\n");
187 return;
188 }
189
190 do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1);
191}
192
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900193int ft_board_setup(void *blob, struct bd_info *bd)
Dave Liu19b247e2008-01-11 18:48:24 +0800194{
195 ft_cpu_setup(blob, bd);
196#ifdef CONFIG_PCI
197 ft_pci_setup(blob, bd);
198#endif
Sriram Dash9fd465c2016-09-16 17:12:15 +0530199 fsl_fdt_fixup_dr_usb(blob, bd);
Anton Vorontsov13c16a12008-07-08 21:00:04 +0400200 fdt_tsec1_fixup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600201
202 return 0;
Dave Liu19b247e2008-01-11 18:48:24 +0800203}
204#endif
Ben Warren052a5ea2008-08-31 20:37:00 -0700205
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900206int board_eth_init(struct bd_info *bis)
Ben Warren052a5ea2008-08-31 20:37:00 -0700207{
208 cpu_eth_init(bis); /* Initialize TSECs first */
209 return pci_eth_init(bis);
210}
Anton Vorontsovec821752009-11-24 20:12:12 +0300211
212#else /* CONFIG_NAND_SPL */
213
214int checkboard(void)
215{
216 puts("Board: Freescale MPC8315ERDB\n");
217 return 0;
218}
219
220void board_init_f(ulong bootflag)
221{
222 board_early_init_f();
223 NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500),
224 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
225 puts("NAND boot... ");
Simon Glass4c974d72017-03-28 10:27:24 -0600226 timer_init();
Simon Glassd35f3382017-04-06 12:47:05 -0600227 dram_init();
Anton Vorontsovec821752009-11-24 20:12:12 +0300228 relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC + 0x10000, (gd_t *)gd,
229 CONFIG_SYS_NAND_U_BOOT_RELOC);
230}
231
232void board_init_r(gd_t *gd, ulong dest_addr)
233{
234 nand_boot();
235}
236
237void putc(char c)
238{
239 if (gd->flags & GD_FLG_SILENT)
240 return;
241
242 if (c == '\n')
243 NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r');
244
245 NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c);
246}
247
248#endif /* CONFIG_NAND_SPL */