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