xref: /openbmc/u-boot/board/freescale/mpc8308rdb/mpc8308rdb.c (revision e895a4b06f9062f052d438df7f4766b3decdb3d4)
15fb17030SIlya Yanok /*
25fb17030SIlya Yanok  * Copyright (C) 2010 Freescale Semiconductor, Inc.
35fb17030SIlya Yanok  * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com
45fb17030SIlya Yanok  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
65fb17030SIlya Yanok  */
75fb17030SIlya Yanok 
85fb17030SIlya Yanok #include <common.h>
95fb17030SIlya Yanok #include <hwconfig.h>
105fb17030SIlya Yanok #include <i2c.h>
11ea1ea54eSIra W. Snyder #include <spi.h>
125fb17030SIlya Yanok #include <libfdt.h>
135fb17030SIlya Yanok #include <fdt_support.h>
145fb17030SIlya Yanok #include <pci.h>
155fb17030SIlya Yanok #include <mpc83xx.h>
165fb17030SIlya Yanok #include <vsc7385.h>
175fb17030SIlya Yanok #include <netdev.h>
18db1fc7d2SIra W. Snyder #include <fsl_esdhc.h>
195fb17030SIlya Yanok #include <asm/io.h>
205fb17030SIlya Yanok #include <asm/fsl_serdes.h>
215fb17030SIlya Yanok #include <asm/fsl_mpc83xx_serdes.h>
225fb17030SIlya Yanok 
235fb17030SIlya Yanok DECLARE_GLOBAL_DATA_PTR;
245fb17030SIlya Yanok 
25ea1ea54eSIra W. Snyder /*
26ea1ea54eSIra W. Snyder  * The following are used to control the SPI chip selects for the SPI command.
27ea1ea54eSIra W. Snyder  */
28ea1ea54eSIra W. Snyder #ifdef CONFIG_MPC8XXX_SPI
29ea1ea54eSIra W. Snyder 
30ea1ea54eSIra W. Snyder #define SPI_CS_MASK	0x00400000
31ea1ea54eSIra W. Snyder 
32ea1ea54eSIra W. Snyder int spi_cs_is_valid(unsigned int bus, unsigned int cs)
33ea1ea54eSIra W. Snyder {
34ea1ea54eSIra W. Snyder 	return bus == 0 && cs == 0;
35ea1ea54eSIra W. Snyder }
36ea1ea54eSIra W. Snyder 
37ea1ea54eSIra W. Snyder void spi_cs_activate(struct spi_slave *slave)
38ea1ea54eSIra W. Snyder {
39ea1ea54eSIra W. Snyder 	immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
40ea1ea54eSIra W. Snyder 
41ea1ea54eSIra W. Snyder 	/* active low */
42ea1ea54eSIra W. Snyder 	clrbits_be32(&immr->gpio[0].dat, SPI_CS_MASK);
43ea1ea54eSIra W. Snyder }
44ea1ea54eSIra W. Snyder 
45ea1ea54eSIra W. Snyder void spi_cs_deactivate(struct spi_slave *slave)
46ea1ea54eSIra W. Snyder {
47ea1ea54eSIra W. Snyder 	immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
48ea1ea54eSIra W. Snyder 
49ea1ea54eSIra W. Snyder 	/* inactive high */
50ea1ea54eSIra W. Snyder 	setbits_be32(&immr->gpio[0].dat, SPI_CS_MASK);
51ea1ea54eSIra W. Snyder }
52ea1ea54eSIra W. Snyder #endif /* CONFIG_MPC8XXX_SPI */
53ea1ea54eSIra W. Snyder 
54db1fc7d2SIra W. Snyder #ifdef CONFIG_FSL_ESDHC
55db1fc7d2SIra W. Snyder int board_mmc_init(bd_t *bd)
56db1fc7d2SIra W. Snyder {
57db1fc7d2SIra W. Snyder 	return fsl_esdhc_mmc_init(bd);
58db1fc7d2SIra W. Snyder }
59db1fc7d2SIra W. Snyder #endif
60db1fc7d2SIra W. Snyder 
615fb17030SIlya Yanok static u8 read_board_info(void)
625fb17030SIlya Yanok {
635fb17030SIlya Yanok 	u8 val8;
645fb17030SIlya Yanok 	i2c_set_bus_num(0);
655fb17030SIlya Yanok 
665fb17030SIlya Yanok 	if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0)
675fb17030SIlya Yanok 		return val8;
685fb17030SIlya Yanok 	else
695fb17030SIlya Yanok 		return 0;
705fb17030SIlya Yanok }
715fb17030SIlya Yanok 
725fb17030SIlya Yanok int checkboard(void)
735fb17030SIlya Yanok {
745fb17030SIlya Yanok 	static const char * const rev_str[] = {
755fb17030SIlya Yanok 		"1.0",
765fb17030SIlya Yanok 		"<reserved>",
775fb17030SIlya Yanok 		"<reserved>",
785fb17030SIlya Yanok 		"<reserved>",
795fb17030SIlya Yanok 		"<unknown>",
805fb17030SIlya Yanok 	};
815fb17030SIlya Yanok 	u8 info;
825fb17030SIlya Yanok 	int i;
835fb17030SIlya Yanok 
845fb17030SIlya Yanok 	info = read_board_info();
855fb17030SIlya Yanok 	i = (!info) ? 4 : info & 0x03;
865fb17030SIlya Yanok 
875fb17030SIlya Yanok 	printf("Board: Freescale MPC8308RDB Rev %s\n", rev_str[i]);
885fb17030SIlya Yanok 
895fb17030SIlya Yanok 	return 0;
905fb17030SIlya Yanok }
915fb17030SIlya Yanok 
925fb17030SIlya Yanok static struct pci_region pcie_regions_0[] = {
935fb17030SIlya Yanok 	{
945fb17030SIlya Yanok 		.bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
955fb17030SIlya Yanok 		.phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
965fb17030SIlya Yanok 		.size = CONFIG_SYS_PCIE1_MEM_SIZE,
975fb17030SIlya Yanok 		.flags = PCI_REGION_MEM,
985fb17030SIlya Yanok 	},
995fb17030SIlya Yanok 	{
1005fb17030SIlya Yanok 		.bus_start = CONFIG_SYS_PCIE1_IO_BASE,
1015fb17030SIlya Yanok 		.phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
1025fb17030SIlya Yanok 		.size = CONFIG_SYS_PCIE1_IO_SIZE,
1035fb17030SIlya Yanok 		.flags = PCI_REGION_IO,
1045fb17030SIlya Yanok 	},
1055fb17030SIlya Yanok };
1065fb17030SIlya Yanok 
1075fb17030SIlya Yanok void pci_init_board(void)
1085fb17030SIlya Yanok {
1095fb17030SIlya Yanok 	immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
1105fb17030SIlya Yanok 	sysconf83xx_t *sysconf = &immr->sysconf;
1115fb17030SIlya Yanok 	law83xx_t *pcie_law = sysconf->pcielaw;
1125fb17030SIlya Yanok 	struct pci_region *pcie_reg[] = { pcie_regions_0 };
1135fb17030SIlya Yanok 
1145fb17030SIlya Yanok 	fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
1155fb17030SIlya Yanok 					FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
1165fb17030SIlya Yanok 
1175fb17030SIlya Yanok 	/* Deassert the resets in the control register */
1185fb17030SIlya Yanok 	out_be32(&sysconf->pecr1, 0xE0008000);
1195fb17030SIlya Yanok 	udelay(2000);
1205fb17030SIlya Yanok 
1215fb17030SIlya Yanok 	/* Configure PCI Express Local Access Windows */
1225fb17030SIlya Yanok 	out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
1235fb17030SIlya Yanok 	out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
1245fb17030SIlya Yanok 
1256aa3d3bfSPeter Tyser 	mpc83xx_pcie_init(1, pcie_reg);
1265fb17030SIlya Yanok }
1275fb17030SIlya Yanok /*
1285fb17030SIlya Yanok  * Miscellaneous late-boot configurations
1295fb17030SIlya Yanok  *
1305fb17030SIlya Yanok  * If a VSC7385 microcode image is present, then upload it.
1315fb17030SIlya Yanok */
1325fb17030SIlya Yanok int misc_init_r(void)
1335fb17030SIlya Yanok {
134ea1ea54eSIra W. Snyder #ifdef CONFIG_MPC8XXX_SPI
135ea1ea54eSIra W. Snyder 	immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
136ea1ea54eSIra W. Snyder 	sysconf83xx_t *sysconf = &immr->sysconf;
137ea1ea54eSIra W. Snyder 
138ea1ea54eSIra W. Snyder 	/*
139ea1ea54eSIra W. Snyder 	 * Set proper bits in SICRH to allow SPI on header J8
140ea1ea54eSIra W. Snyder 	 *
141ea1ea54eSIra W. Snyder 	 * NOTE: this breaks the TSEC2 interface, attached to the Vitesse
142ea1ea54eSIra W. Snyder 	 * switch. The pinmux configuration does not have a fine enough
143ea1ea54eSIra W. Snyder 	 * granularity to support both simultaneously.
144ea1ea54eSIra W. Snyder 	 */
145ea1ea54eSIra W. Snyder 	clrsetbits_be32(&sysconf->sicrh, SICRH_GPIO_A_TSEC2, SICRH_GPIO_A_GPIO);
146ea1ea54eSIra W. Snyder 	puts("WARNING: SPI enabled, TSEC2 support is broken\n");
147ea1ea54eSIra W. Snyder 
148ea1ea54eSIra W. Snyder 	/* Set header J8 SPI chip select output, disabled */
149ea1ea54eSIra W. Snyder 	setbits_be32(&immr->gpio[0].dir, SPI_CS_MASK);
150ea1ea54eSIra W. Snyder 	setbits_be32(&immr->gpio[0].dat, SPI_CS_MASK);
151ea1ea54eSIra W. Snyder #endif
152ea1ea54eSIra W. Snyder 
1535fb17030SIlya Yanok #ifdef CONFIG_VSC7385_IMAGE
1545fb17030SIlya Yanok 	if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
1555fb17030SIlya Yanok 		CONFIG_VSC7385_IMAGE_SIZE)) {
1565fb17030SIlya Yanok 		puts("Failure uploading VSC7385 microcode.\n");
1575fb17030SIlya Yanok 		return 1;
1585fb17030SIlya Yanok 	}
1595fb17030SIlya Yanok #endif
1605fb17030SIlya Yanok 
1615fb17030SIlya Yanok 	return 0;
1625fb17030SIlya Yanok }
1635fb17030SIlya Yanok #if defined(CONFIG_OF_BOARD_SETUP)
164*e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd)
1655fb17030SIlya Yanok {
1665fb17030SIlya Yanok 	ft_cpu_setup(blob, bd);
1675fb17030SIlya Yanok 	fdt_fixup_dr_usb(blob, bd);
168db1fc7d2SIra W. Snyder 	fdt_fixup_esdhc(blob, bd);
169*e895a4b0SSimon Glass 
170*e895a4b0SSimon Glass 	return 0;
1715fb17030SIlya Yanok }
1725fb17030SIlya Yanok #endif
1735fb17030SIlya Yanok 
1745fb17030SIlya Yanok int board_eth_init(bd_t *bis)
1755fb17030SIlya Yanok {
1765fb17030SIlya Yanok 	int rv, num_if = 0;
1775fb17030SIlya Yanok 
1785fb17030SIlya Yanok 	/* Initialize TSECs first */
17965ea7589SIlya Yanok 	rv = cpu_eth_init(bis);
18065ea7589SIlya Yanok 	if (rv >= 0)
1815fb17030SIlya Yanok 		num_if += rv;
1825fb17030SIlya Yanok 	else
1835fb17030SIlya Yanok 		printf("ERROR: failed to initialize TSECs.\n");
1845fb17030SIlya Yanok 
18565ea7589SIlya Yanok 	rv = pci_eth_init(bis);
18665ea7589SIlya Yanok 	if (rv >= 0)
1875fb17030SIlya Yanok 		num_if += rv;
1885fb17030SIlya Yanok 	else
1895fb17030SIlya Yanok 		printf("ERROR: failed to initialize PCI Ethernet.\n");
1905fb17030SIlya Yanok 
1915fb17030SIlya Yanok 	return num_if;
1925fb17030SIlya Yanok }
193