18bd522ceSDave Liu /*
28bd522ceSDave Liu * Copyright (C) 2007 Freescale Semiconductor, Inc.
38bd522ceSDave Liu *
48bd522ceSDave Liu * Author: Scott Wood <scottwood@freescale.com>
58bd522ceSDave Liu * Dave Liu <daveliu@freescale.com>
68bd522ceSDave Liu *
71a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
88bd522ceSDave Liu */
98bd522ceSDave Liu
108bd522ceSDave Liu #include <common.h>
11b8b71ffbSAnton Vorontsov #include <hwconfig.h>
128bd522ceSDave Liu #include <i2c.h>
13*0e00a84cSMasahiro Yamada #include <linux/libfdt.h>
1425f5f0d4SAnton Vorontsov #include <fdt_support.h>
158bd522ceSDave Liu #include <pci.h>
168bd522ceSDave Liu #include <mpc83xx.h>
1710efa024SBen Warren #include <netdev.h>
188f11e34bSAnton Vorontsov #include <asm/io.h>
192e95004dSAnton Vorontsov #include <ns16550.h>
202e95004dSAnton Vorontsov #include <nand.h>
218bd522ceSDave Liu
228bd522ceSDave Liu DECLARE_GLOBAL_DATA_PTR;
238bd522ceSDave Liu
board_early_init_f(void)248bd522ceSDave Liu int board_early_init_f(void)
258bd522ceSDave Liu {
266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
278bd522ceSDave Liu
288bd522ceSDave Liu if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
298bd522ceSDave Liu gd->flags |= GD_FLG_SILENT;
308bd522ceSDave Liu
318bd522ceSDave Liu return 0;
328bd522ceSDave Liu }
338bd522ceSDave Liu
342e95004dSAnton Vorontsov #ifndef CONFIG_NAND_SPL
352e95004dSAnton Vorontsov
read_board_info(void)368bd522ceSDave Liu static u8 read_board_info(void)
378bd522ceSDave Liu {
388bd522ceSDave Liu u8 val8;
398bd522ceSDave Liu i2c_set_bus_num(0);
408bd522ceSDave Liu
416d0f6bcfSJean-Christophe PLAGNIOL-VILLARD if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0)
428bd522ceSDave Liu return val8;
438bd522ceSDave Liu else
448bd522ceSDave Liu return 0;
458bd522ceSDave Liu }
468bd522ceSDave Liu
checkboard(void)478bd522ceSDave Liu int checkboard(void)
488bd522ceSDave Liu {
498bd522ceSDave Liu static const char * const rev_str[] = {
508bd522ceSDave Liu "0.0",
518bd522ceSDave Liu "0.1",
528bd522ceSDave Liu "1.0",
538bd522ceSDave Liu "1.1",
548bd522ceSDave Liu "<unknown>",
558bd522ceSDave Liu };
568bd522ceSDave Liu u8 info;
578bd522ceSDave Liu int i;
588bd522ceSDave Liu
598bd522ceSDave Liu info = read_board_info();
608bd522ceSDave Liu i = (!info) ? 4: info & 0x03;
618bd522ceSDave Liu
628bd522ceSDave Liu printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]);
638bd522ceSDave Liu
648bd522ceSDave Liu return 0;
658bd522ceSDave Liu }
668bd522ceSDave Liu
678bd522ceSDave Liu static struct pci_region pci_regions[] = {
688bd522ceSDave Liu {
696d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MEM_BASE,
706d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MEM_PHYS,
716d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MEM_SIZE,
728bd522ceSDave Liu flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
738bd522ceSDave Liu },
748bd522ceSDave Liu {
756d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_MMIO_BASE,
766d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
776d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_MMIO_SIZE,
788bd522ceSDave Liu flags: PCI_REGION_MEM
798bd522ceSDave Liu },
808bd522ceSDave Liu {
816d0f6bcfSJean-Christophe PLAGNIOL-VILLARD bus_start: CONFIG_SYS_PCI_IO_BASE,
826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD phys_start: CONFIG_SYS_PCI_IO_PHYS,
836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD size: CONFIG_SYS_PCI_IO_SIZE,
848bd522ceSDave Liu flags: PCI_REGION_IO
858bd522ceSDave Liu }
868bd522ceSDave Liu };
878bd522ceSDave Liu
888f11e34bSAnton Vorontsov static struct pci_region pcie_regions_0[] = {
898f11e34bSAnton Vorontsov {
908f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
918f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
928f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE1_MEM_SIZE,
938f11e34bSAnton Vorontsov .flags = PCI_REGION_MEM,
948f11e34bSAnton Vorontsov },
958f11e34bSAnton Vorontsov {
968f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
978f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
988f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE1_IO_SIZE,
998f11e34bSAnton Vorontsov .flags = PCI_REGION_IO,
1008f11e34bSAnton Vorontsov },
1018f11e34bSAnton Vorontsov };
1028f11e34bSAnton Vorontsov
1038f11e34bSAnton Vorontsov static struct pci_region pcie_regions_1[] = {
1048f11e34bSAnton Vorontsov {
1058f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
1068f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
1078f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE2_MEM_SIZE,
1088f11e34bSAnton Vorontsov .flags = PCI_REGION_MEM,
1098f11e34bSAnton Vorontsov },
1108f11e34bSAnton Vorontsov {
1118f11e34bSAnton Vorontsov .bus_start = CONFIG_SYS_PCIE2_IO_BASE,
1128f11e34bSAnton Vorontsov .phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
1138f11e34bSAnton Vorontsov .size = CONFIG_SYS_PCIE2_IO_SIZE,
1148f11e34bSAnton Vorontsov .flags = PCI_REGION_IO,
1158f11e34bSAnton Vorontsov },
1168f11e34bSAnton Vorontsov };
1178f11e34bSAnton Vorontsov
pci_init_board(void)1188bd522ceSDave Liu void pci_init_board(void)
1198bd522ceSDave Liu {
1206d0f6bcfSJean-Christophe PLAGNIOL-VILLARD volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
1218f11e34bSAnton Vorontsov volatile sysconf83xx_t *sysconf = &immr->sysconf;
1228bd522ceSDave Liu volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
1238bd522ceSDave Liu volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
1248f11e34bSAnton Vorontsov volatile law83xx_t *pcie_law = sysconf->pcielaw;
1258bd522ceSDave Liu struct pci_region *reg[] = { pci_regions };
1268f11e34bSAnton Vorontsov struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
1278bd522ceSDave Liu
1288bd522ceSDave Liu /* Enable all 3 PCI_CLK_OUTPUTs. */
1298bd522ceSDave Liu clk->occr |= 0xe0000000;
1308bd522ceSDave Liu
1318bd522ceSDave Liu /*
1328bd522ceSDave Liu * Configure PCI Local Access Windows
1338bd522ceSDave Liu */
1346d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
1358bd522ceSDave Liu pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
1368bd522ceSDave Liu
1376d0f6bcfSJean-Christophe PLAGNIOL-VILLARD pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
1388bd522ceSDave Liu pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
1398bd522ceSDave Liu
1406aa3d3bfSPeter Tyser mpc83xx_pci_init(1, reg);
1418f11e34bSAnton Vorontsov
1428f11e34bSAnton Vorontsov /* Configure the clock for PCIE controller */
1438f11e34bSAnton Vorontsov clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
1448f11e34bSAnton Vorontsov SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
1458f11e34bSAnton Vorontsov
1468f11e34bSAnton Vorontsov /* Deassert the resets in the control register */
1478f11e34bSAnton Vorontsov out_be32(&sysconf->pecr1, 0xE0008000);
1488f11e34bSAnton Vorontsov out_be32(&sysconf->pecr2, 0xE0008000);
1498f11e34bSAnton Vorontsov udelay(2000);
1508f11e34bSAnton Vorontsov
1518f11e34bSAnton Vorontsov /* Configure PCI Express Local Access Windows */
1528f11e34bSAnton Vorontsov out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
1538f11e34bSAnton Vorontsov out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
1548f11e34bSAnton Vorontsov
1558f11e34bSAnton Vorontsov out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
1568f11e34bSAnton Vorontsov out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
1578f11e34bSAnton Vorontsov
1586aa3d3bfSPeter Tyser mpc83xx_pcie_init(2, pcie_reg);
1598bd522ceSDave Liu }
1608bd522ceSDave Liu
1618bd522ceSDave Liu #if defined(CONFIG_OF_BOARD_SETUP)
fdt_tsec1_fixup(void * fdt,bd_t * bd)16225f5f0d4SAnton Vorontsov void fdt_tsec1_fixup(void *fdt, bd_t *bd)
16325f5f0d4SAnton Vorontsov {
16425f5f0d4SAnton Vorontsov const char disabled[] = "disabled";
16525f5f0d4SAnton Vorontsov const char *path;
16625f5f0d4SAnton Vorontsov int ret;
16725f5f0d4SAnton Vorontsov
168b8b71ffbSAnton Vorontsov if (hwconfig_arg_cmp("board_type", "tsec1")) {
169021f6df6SAnton Vorontsov return;
170b8b71ffbSAnton Vorontsov } else if (!hwconfig_arg_cmp("board_type", "ulpi")) {
171b8b71ffbSAnton Vorontsov printf("NOTICE: No or unknown board_type hwconfig specified.\n"
172b8b71ffbSAnton Vorontsov " Assuming board with TSEC1.\n");
17325f5f0d4SAnton Vorontsov return;
17425f5f0d4SAnton Vorontsov }
17525f5f0d4SAnton Vorontsov
17625f5f0d4SAnton Vorontsov ret = fdt_path_offset(fdt, "/aliases");
17725f5f0d4SAnton Vorontsov if (ret < 0) {
17825f5f0d4SAnton Vorontsov printf("WARNING: can't find /aliases node\n");
17925f5f0d4SAnton Vorontsov return;
18025f5f0d4SAnton Vorontsov }
18125f5f0d4SAnton Vorontsov
18225f5f0d4SAnton Vorontsov path = fdt_getprop(fdt, ret, "ethernet0", NULL);
18325f5f0d4SAnton Vorontsov if (!path) {
18425f5f0d4SAnton Vorontsov printf("WARNING: can't find ethernet0 alias\n");
18525f5f0d4SAnton Vorontsov return;
18625f5f0d4SAnton Vorontsov }
18725f5f0d4SAnton Vorontsov
18825f5f0d4SAnton Vorontsov do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1);
18925f5f0d4SAnton Vorontsov }
19025f5f0d4SAnton Vorontsov
ft_board_setup(void * blob,bd_t * bd)191e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd)
1928bd522ceSDave Liu {
1938bd522ceSDave Liu ft_cpu_setup(blob, bd);
1948bd522ceSDave Liu #ifdef CONFIG_PCI
1958bd522ceSDave Liu ft_pci_setup(blob, bd);
1968bd522ceSDave Liu #endif
197a5c289b9SSriram Dash fsl_fdt_fixup_dr_usb(blob, bd);
19825f5f0d4SAnton Vorontsov fdt_tsec1_fixup(blob, bd);
199e895a4b0SSimon Glass
200e895a4b0SSimon Glass return 0;
2018bd522ceSDave Liu }
2028bd522ceSDave Liu #endif
20310efa024SBen Warren
board_eth_init(bd_t * bis)20410efa024SBen Warren int board_eth_init(bd_t *bis)
20510efa024SBen Warren {
20610efa024SBen Warren cpu_eth_init(bis); /* Initialize TSECs first */
20710efa024SBen Warren return pci_eth_init(bis);
20810efa024SBen Warren }
2092e95004dSAnton Vorontsov
2102e95004dSAnton Vorontsov #else /* CONFIG_NAND_SPL */
2112e95004dSAnton Vorontsov
checkboard(void)2122e95004dSAnton Vorontsov int checkboard(void)
2132e95004dSAnton Vorontsov {
2142e95004dSAnton Vorontsov puts("Board: Freescale MPC8315ERDB\n");
2152e95004dSAnton Vorontsov return 0;
2162e95004dSAnton Vorontsov }
2172e95004dSAnton Vorontsov
board_init_f(ulong bootflag)2182e95004dSAnton Vorontsov void board_init_f(ulong bootflag)
2192e95004dSAnton Vorontsov {
2202e95004dSAnton Vorontsov board_early_init_f();
2212e95004dSAnton Vorontsov NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500),
2222e95004dSAnton Vorontsov CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE);
2232e95004dSAnton Vorontsov puts("NAND boot... ");
22470e2aaf3SSimon Glass timer_init();
225f1683aa7SSimon Glass dram_init();
2262e95004dSAnton Vorontsov relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC + 0x10000, (gd_t *)gd,
2272e95004dSAnton Vorontsov CONFIG_SYS_NAND_U_BOOT_RELOC);
2282e95004dSAnton Vorontsov }
2292e95004dSAnton Vorontsov
board_init_r(gd_t * gd,ulong dest_addr)2302e95004dSAnton Vorontsov void board_init_r(gd_t *gd, ulong dest_addr)
2312e95004dSAnton Vorontsov {
2322e95004dSAnton Vorontsov nand_boot();
2332e95004dSAnton Vorontsov }
2342e95004dSAnton Vorontsov
putc(char c)2352e95004dSAnton Vorontsov void putc(char c)
2362e95004dSAnton Vorontsov {
2372e95004dSAnton Vorontsov if (gd->flags & GD_FLG_SILENT)
2382e95004dSAnton Vorontsov return;
2392e95004dSAnton Vorontsov
2402e95004dSAnton Vorontsov if (c == '\n')
2412e95004dSAnton Vorontsov NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r');
2422e95004dSAnton Vorontsov
2432e95004dSAnton Vorontsov NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c);
2442e95004dSAnton Vorontsov }
2452e95004dSAnton Vorontsov
2462e95004dSAnton Vorontsov #endif /* CONFIG_NAND_SPL */
247