xref: /rk3399_rockchip-uboot/board/freescale/mpc8315erdb/mpc8315erdb.c (revision 10efa024b8ffd9e6aaca63da8bddfdffdc672274)
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  *
78bd522ceSDave Liu  * See file CREDITS for list of people who contributed to this
88bd522ceSDave Liu  * project.
98bd522ceSDave Liu  *
108bd522ceSDave Liu  * This program is free software; you can redistribute it and/or
118bd522ceSDave Liu  * modify it under the terms of the GNU General Public License as
128bd522ceSDave Liu  * published by the Free Software Foundation; either version 2 of
138bd522ceSDave Liu  * the License, or (at your option) any later version.
148bd522ceSDave Liu  *
158bd522ceSDave Liu  * This program is distributed in the hope that it will be useful,
168bd522ceSDave Liu  * but WITHOUT ANY WARRANTY; without even the implied warranty of
178bd522ceSDave Liu  * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE.  See the
188bd522ceSDave Liu  * GNU General Public License for more details.
198bd522ceSDave Liu  *
208bd522ceSDave Liu  * You should have received a copy of the GNU General Public License
218bd522ceSDave Liu  * along with this program; if not, write to the Free Software
228bd522ceSDave Liu  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
238bd522ceSDave Liu  * MA 02111-1307 USA
248bd522ceSDave Liu  */
258bd522ceSDave Liu 
268bd522ceSDave Liu #include <common.h>
278bd522ceSDave Liu #include <i2c.h>
288bd522ceSDave Liu #include <libfdt.h>
2925f5f0d4SAnton Vorontsov #include <fdt_support.h>
308bd522ceSDave Liu #include <pci.h>
318bd522ceSDave Liu #include <mpc83xx.h>
32*10efa024SBen Warren #include <netdev.h>
338bd522ceSDave Liu 
348bd522ceSDave Liu DECLARE_GLOBAL_DATA_PTR;
358bd522ceSDave Liu 
368bd522ceSDave Liu int board_early_init_f(void)
378bd522ceSDave Liu {
388bd522ceSDave Liu 	volatile immap_t *im = (immap_t *)CFG_IMMR;
398bd522ceSDave Liu 
408bd522ceSDave Liu 	if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
418bd522ceSDave Liu 		gd->flags |= GD_FLG_SILENT;
428bd522ceSDave Liu 
438bd522ceSDave Liu 	return 0;
448bd522ceSDave Liu }
458bd522ceSDave Liu 
468bd522ceSDave Liu static u8 read_board_info(void)
478bd522ceSDave Liu {
488bd522ceSDave Liu 	u8 val8;
498bd522ceSDave Liu 	i2c_set_bus_num(0);
508bd522ceSDave Liu 
518bd522ceSDave Liu 	if (i2c_read(CFG_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0)
528bd522ceSDave Liu 		return val8;
538bd522ceSDave Liu 	else
548bd522ceSDave Liu 		return 0;
558bd522ceSDave Liu }
568bd522ceSDave Liu 
578bd522ceSDave Liu int checkboard(void)
588bd522ceSDave Liu {
598bd522ceSDave Liu 	static const char * const rev_str[] = {
608bd522ceSDave Liu 		"0.0",
618bd522ceSDave Liu 		"0.1",
628bd522ceSDave Liu 		"1.0",
638bd522ceSDave Liu 		"1.1",
648bd522ceSDave Liu 		"<unknown>",
658bd522ceSDave Liu 	};
668bd522ceSDave Liu 	u8 info;
678bd522ceSDave Liu 	int i;
688bd522ceSDave Liu 
698bd522ceSDave Liu 	info = read_board_info();
708bd522ceSDave Liu 	i = (!info) ? 4: info & 0x03;
718bd522ceSDave Liu 
728bd522ceSDave Liu 	printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]);
738bd522ceSDave Liu 
748bd522ceSDave Liu 	return 0;
758bd522ceSDave Liu }
768bd522ceSDave Liu 
778bd522ceSDave Liu static struct pci_region pci_regions[] = {
788bd522ceSDave Liu 	{
798bd522ceSDave Liu 		bus_start: CFG_PCI_MEM_BASE,
808bd522ceSDave Liu 		phys_start: CFG_PCI_MEM_PHYS,
818bd522ceSDave Liu 		size: CFG_PCI_MEM_SIZE,
828bd522ceSDave Liu 		flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
838bd522ceSDave Liu 	},
848bd522ceSDave Liu 	{
858bd522ceSDave Liu 		bus_start: CFG_PCI_MMIO_BASE,
868bd522ceSDave Liu 		phys_start: CFG_PCI_MMIO_PHYS,
878bd522ceSDave Liu 		size: CFG_PCI_MMIO_SIZE,
888bd522ceSDave Liu 		flags: PCI_REGION_MEM
898bd522ceSDave Liu 	},
908bd522ceSDave Liu 	{
918bd522ceSDave Liu 		bus_start: CFG_PCI_IO_BASE,
928bd522ceSDave Liu 		phys_start: CFG_PCI_IO_PHYS,
938bd522ceSDave Liu 		size: CFG_PCI_IO_SIZE,
948bd522ceSDave Liu 		flags: PCI_REGION_IO
958bd522ceSDave Liu 	}
968bd522ceSDave Liu };
978bd522ceSDave Liu 
988bd522ceSDave Liu void pci_init_board(void)
998bd522ceSDave Liu {
1008bd522ceSDave Liu 	volatile immap_t *immr = (volatile immap_t *)CFG_IMMR;
1018bd522ceSDave Liu 	volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
1028bd522ceSDave Liu 	volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
1038bd522ceSDave Liu 	struct pci_region *reg[] = { pci_regions };
1048bd522ceSDave Liu 	int warmboot;
1058bd522ceSDave Liu 
1068bd522ceSDave Liu 	/* Enable all 3 PCI_CLK_OUTPUTs. */
1078bd522ceSDave Liu 	clk->occr |= 0xe0000000;
1088bd522ceSDave Liu 
1098bd522ceSDave Liu 	/*
1108bd522ceSDave Liu 	 * Configure PCI Local Access Windows
1118bd522ceSDave Liu 	 */
1128bd522ceSDave Liu 	pci_law[0].bar = CFG_PCI_MEM_PHYS & LAWBAR_BAR;
1138bd522ceSDave Liu 	pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
1148bd522ceSDave Liu 
1158bd522ceSDave Liu 	pci_law[1].bar = CFG_PCI_IO_PHYS & LAWBAR_BAR;
1168bd522ceSDave Liu 	pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
1178bd522ceSDave Liu 
1188bd522ceSDave Liu 	warmboot = gd->bd->bi_bootflags & BOOTFLAG_WARM;
1198bd522ceSDave Liu 	warmboot |= immr->pmc.pmccr1 & PMCCR1_POWER_OFF;
1208bd522ceSDave Liu 
1218bd522ceSDave Liu 	mpc83xx_pci_init(1, reg, warmboot);
1228bd522ceSDave Liu }
1238bd522ceSDave Liu 
1248bd522ceSDave Liu #if defined(CONFIG_OF_BOARD_SETUP)
12525f5f0d4SAnton Vorontsov void fdt_tsec1_fixup(void *fdt, bd_t *bd)
12625f5f0d4SAnton Vorontsov {
12725f5f0d4SAnton Vorontsov 	char *mpc8315erdb = getenv("mpc8315erdb");
12825f5f0d4SAnton Vorontsov 	const char disabled[] = "disabled";
12925f5f0d4SAnton Vorontsov 	const char *path;
13025f5f0d4SAnton Vorontsov 	int ret;
13125f5f0d4SAnton Vorontsov 
132021f6df6SAnton Vorontsov 	if (!mpc8315erdb)
133021f6df6SAnton Vorontsov 		return;
134021f6df6SAnton Vorontsov 
13525f5f0d4SAnton Vorontsov 	if (!strcmp(mpc8315erdb, "tsec1")) {
13625f5f0d4SAnton Vorontsov 		return;
13725f5f0d4SAnton Vorontsov 	} else if (strcmp(mpc8315erdb, "ulpi")) {
13825f5f0d4SAnton Vorontsov 		printf("WARNING: wrong `mpc8315erdb' environment "
13925f5f0d4SAnton Vorontsov 		       "variable specified: `%s'. Should be `ulpi' "
14025f5f0d4SAnton Vorontsov 		       "or `tsec1'.\n", mpc8315erdb);
14125f5f0d4SAnton Vorontsov 		return;
14225f5f0d4SAnton Vorontsov 	}
14325f5f0d4SAnton Vorontsov 
14425f5f0d4SAnton Vorontsov 	ret = fdt_path_offset(fdt, "/aliases");
14525f5f0d4SAnton Vorontsov 	if (ret < 0) {
14625f5f0d4SAnton Vorontsov 		printf("WARNING: can't find /aliases node\n");
14725f5f0d4SAnton Vorontsov 		return;
14825f5f0d4SAnton Vorontsov 	}
14925f5f0d4SAnton Vorontsov 
15025f5f0d4SAnton Vorontsov 	path = fdt_getprop(fdt, ret, "ethernet0", NULL);
15125f5f0d4SAnton Vorontsov 	if (!path) {
15225f5f0d4SAnton Vorontsov 		printf("WARNING: can't find ethernet0 alias\n");
15325f5f0d4SAnton Vorontsov 		return;
15425f5f0d4SAnton Vorontsov 	}
15525f5f0d4SAnton Vorontsov 
15625f5f0d4SAnton Vorontsov 	do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1);
15725f5f0d4SAnton Vorontsov }
15825f5f0d4SAnton Vorontsov 
1598bd522ceSDave Liu void ft_board_setup(void *blob, bd_t *bd)
1608bd522ceSDave Liu {
1618bd522ceSDave Liu 	ft_cpu_setup(blob, bd);
1628bd522ceSDave Liu #ifdef CONFIG_PCI
1638bd522ceSDave Liu 	ft_pci_setup(blob, bd);
1648bd522ceSDave Liu #endif
16525f5f0d4SAnton Vorontsov 	fdt_fixup_dr_usb(blob, bd);
16625f5f0d4SAnton Vorontsov 	fdt_tsec1_fixup(blob, bd);
1678bd522ceSDave Liu }
1688bd522ceSDave Liu #endif
169*10efa024SBen Warren 
170*10efa024SBen Warren int board_eth_init(bd_t *bis)
171*10efa024SBen Warren {
172*10efa024SBen Warren 	cpu_eth_init(bis);	/* Initialize TSECs first */
173*10efa024SBen Warren 	return pci_eth_init(bis);
174*10efa024SBen Warren }
175