blob: e89d5d4955959a443644af182a8b89701d5e2f3f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dave Liu8bd522c2008-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 Liu8bd522c2008-01-11 18:48:24 +08007 */
8
9#include <common.h>
Anton Vorontsovb8b71ff2009-06-10 00:25:36 +040010#include <hwconfig.h>
Dave Liu8bd522c2008-01-11 18:48:24 +080011#include <i2c.h>
Simon Glass2cf431c2019-11-14 12:57:47 -070012#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060013#include <net.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Simon Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090016#include <linux/libfdt.h>
Anton Vorontsov25f5f0d2008-07-08 21:00:04 +040017#include <fdt_support.h>
Dave Liu8bd522c2008-01-11 18:48:24 +080018#include <pci.h>
19#include <mpc83xx.h>
Ben Warren10efa022008-08-31 20:37:00 -070020#include <netdev.h>
Anton Vorontsov8f11e342009-01-08 04:26:17 +030021#include <asm/io.h>
Anton Vorontsov2e950042009-11-24 20:12:12 +030022#include <ns16550.h>
23#include <nand.h>
Dave Liu8bd522c2008-01-11 18:48:24 +080024
25DECLARE_GLOBAL_DATA_PTR;
26
27int board_early_init_f(void)
28{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020029 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu8bd522c2008-01-11 18:48:24 +080030
31 if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
32 gd->flags |= GD_FLG_SILENT;
33
34 return 0;
35}
36
Anton Vorontsov2e950042009-11-24 20:12:12 +030037#ifndef CONFIG_NAND_SPL
38
Dave Liu8bd522c2008-01-11 18:48:24 +080039static u8 read_board_info(void)
40{
41 u8 val8;
42 i2c_set_bus_num(0);
43
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020044 if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0)
Dave Liu8bd522c2008-01-11 18:48:24 +080045 return val8;
46 else
47 return 0;
48}
49
50int checkboard(void)
51{
52 static const char * const rev_str[] = {
53 "0.0",
54 "0.1",
55 "1.0",
56 "1.1",
57 "<unknown>",
58 };
59 u8 info;
60 int i;
61
62 info = read_board_info();
63 i = (!info) ? 4: info & 0x03;
64
65 printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]);
66
67 return 0;
68}
69
70static struct pci_region pci_regions[] = {
71 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072 bus_start: CONFIG_SYS_PCI_MEM_BASE,
73 phys_start: CONFIG_SYS_PCI_MEM_PHYS,
74 size: CONFIG_SYS_PCI_MEM_SIZE,
Dave Liu8bd522c2008-01-11 18:48:24 +080075 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
76 },
77 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020078 bus_start: CONFIG_SYS_PCI_MMIO_BASE,
79 phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
80 size: CONFIG_SYS_PCI_MMIO_SIZE,
Dave Liu8bd522c2008-01-11 18:48:24 +080081 flags: PCI_REGION_MEM
82 },
83 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020084 bus_start: CONFIG_SYS_PCI_IO_BASE,
85 phys_start: CONFIG_SYS_PCI_IO_PHYS,
86 size: CONFIG_SYS_PCI_IO_SIZE,
Dave Liu8bd522c2008-01-11 18:48:24 +080087 flags: PCI_REGION_IO
88 }
89};
90
Anton Vorontsov8f11e342009-01-08 04:26:17 +030091static struct pci_region pcie_regions_0[] = {
92 {
93 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
94 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
95 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
96 .flags = PCI_REGION_MEM,
97 },
98 {
99 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
100 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
101 .size = CONFIG_SYS_PCIE1_IO_SIZE,
102 .flags = PCI_REGION_IO,
103 },
104};
105
106static struct pci_region pcie_regions_1[] = {
107 {
108 .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
109 .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
110 .size = CONFIG_SYS_PCIE2_MEM_SIZE,
111 .flags = PCI_REGION_MEM,
112 },
113 {
114 .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
115 .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
116 .size = CONFIG_SYS_PCIE2_IO_SIZE,
117 .flags = PCI_REGION_IO,
118 },
119};
120
Dave Liu8bd522c2008-01-11 18:48:24 +0800121void pci_init_board(void)
122{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200123 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov8f11e342009-01-08 04:26:17 +0300124 volatile sysconf83xx_t *sysconf = &immr->sysconf;
Dave Liu8bd522c2008-01-11 18:48:24 +0800125 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
126 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
Anton Vorontsov8f11e342009-01-08 04:26:17 +0300127 volatile law83xx_t *pcie_law = sysconf->pcielaw;
Dave Liu8bd522c2008-01-11 18:48:24 +0800128 struct pci_region *reg[] = { pci_regions };
Anton Vorontsov8f11e342009-01-08 04:26:17 +0300129 struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
Dave Liu8bd522c2008-01-11 18:48:24 +0800130
131 /* Enable all 3 PCI_CLK_OUTPUTs. */
132 clk->occr |= 0xe0000000;
133
134 /*
135 * Configure PCI Local Access Windows
136 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200137 pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
Dave Liu8bd522c2008-01-11 18:48:24 +0800138 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
139
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200140 pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
Dave Liu8bd522c2008-01-11 18:48:24 +0800141 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
142
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500143 mpc83xx_pci_init(1, reg);
Anton Vorontsov8f11e342009-01-08 04:26:17 +0300144
145 /* Configure the clock for PCIE controller */
146 clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
147 SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
148
149 /* Deassert the resets in the control register */
150 out_be32(&sysconf->pecr1, 0xE0008000);
151 out_be32(&sysconf->pecr2, 0xE0008000);
152 udelay(2000);
153
154 /* Configure PCI Express Local Access Windows */
155 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
156 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
157
158 out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
159 out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
160
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500161 mpc83xx_pcie_init(2, pcie_reg);
Dave Liu8bd522c2008-01-11 18:48:24 +0800162}
163
164#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900165void fdt_tsec1_fixup(void *fdt, struct bd_info *bd)
Anton Vorontsov25f5f0d2008-07-08 21:00:04 +0400166{
Anton Vorontsov25f5f0d2008-07-08 21:00:04 +0400167 const char disabled[] = "disabled";
168 const char *path;
169 int ret;
170
Anton Vorontsovb8b71ff2009-06-10 00:25:36 +0400171 if (hwconfig_arg_cmp("board_type", "tsec1")) {
Anton Vorontsov021f6df2008-07-10 17:20:51 +0400172 return;
Anton Vorontsovb8b71ff2009-06-10 00:25:36 +0400173 } else if (!hwconfig_arg_cmp("board_type", "ulpi")) {
174 printf("NOTICE: No or unknown board_type hwconfig specified.\n"
175 " Assuming board with TSEC1.\n");
Anton Vorontsov021f6df2008-07-10 17:20:51 +0400176 return;
Anton Vorontsov25f5f0d2008-07-08 21:00:04 +0400177 }
178
179 ret = fdt_path_offset(fdt, "/aliases");
180 if (ret < 0) {
181 printf("WARNING: can't find /aliases node\n");
182 return;
183 }
184
185 path = fdt_getprop(fdt, ret, "ethernet0", NULL);
186 if (!path) {
187 printf("WARNING: can't find ethernet0 alias\n");
188 return;
189 }
190
191 do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1);
192}
193
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900194int ft_board_setup(void *blob, struct bd_info *bd)
Dave Liu8bd522c2008-01-11 18:48:24 +0800195{
196 ft_cpu_setup(blob, bd);
197#ifdef CONFIG_PCI
198 ft_pci_setup(blob, bd);
199#endif
Sriram Dasha5c289b2016-09-16 17:12:15 +0530200 fsl_fdt_fixup_dr_usb(blob, bd);
Anton Vorontsov25f5f0d2008-07-08 21:00:04 +0400201 fdt_tsec1_fixup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600202
203 return 0;
Dave Liu8bd522c2008-01-11 18:48:24 +0800204}
205#endif
Ben Warren10efa022008-08-31 20:37:00 -0700206
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900207int board_eth_init(struct bd_info *bis)
Ben Warren10efa022008-08-31 20:37:00 -0700208{
209 cpu_eth_init(bis); /* Initialize TSECs first */
210 return pci_eth_init(bis);
211}
Anton Vorontsov2e950042009-11-24 20:12:12 +0300212
213#else /* CONFIG_NAND_SPL */
214
215int checkboard(void)
216{
217 puts("Board: Freescale MPC8315ERDB\n");
218 return 0;
219}
220
221void board_init_f(ulong bootflag)
222{
223 board_early_init_f();
Simon Glass2d6bf752020-12-22 19:30:19 -0700224 ns16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500),
Anton Vorontsov2e950042009-11-24 20:12:12 +0300225 CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
226 puts("NAND boot... ");
Simon Glass70e2aaf2017-03-28 10:27:24 -0600227 timer_init();
Simon Glassf1683aa2017-04-06 12:47:05 -0600228 dram_init();
Anton Vorontsov2e950042009-11-24 20:12:12 +0300229 relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC + 0x10000, (gd_t *)gd,
230 CONFIG_SYS_NAND_U_BOOT_RELOC);
231}
232
233void board_init_r(gd_t *gd, ulong dest_addr)
234{
235 nand_boot();
236}
237
238void putc(char c)
239{
240 if (gd->flags & GD_FLG_SILENT)
241 return;
242
243 if (c == '\n')
Simon Glass2d6bf752020-12-22 19:30:19 -0700244 ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r');
Anton Vorontsov2e950042009-11-24 20:12:12 +0300245
Simon Glass2d6bf752020-12-22 19:30:19 -0700246 ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c);
Anton Vorontsov2e950042009-11-24 20:12:12 +0300247}
248
249#endif /* CONFIG_NAND_SPL */