blob: 3cde715e96b706dc9392c6e9480e4676a949b807 [file] [log] [blame]
Kim Phillipsb22fc902007-07-25 19:25:33 -05001/*
2 * Copyright (C) 2007 Freescale Semiconductor, Inc.
3 *
4 * Michael Barkowski <michael.barkowski@freescale.com>
5 * Based on mpc832xmds file by Dave Liu <daveliu@freescale.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
10 */
11
12#include <common.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -070013#include <eeprom.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060014#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070015#include <fdt_support.h>
Simon Glass18afe102019-11-14 12:57:47 -070016#include <init.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050017#include <ioports.h>
18#include <mpc83xx.h>
19#include <i2c.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050020#include <miiphy.h>
21#include <command.h>
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090023#include <linux/libfdt.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070024#include <u-boot/crc.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050025#if defined(CONFIG_PCI)
26#include <pci.h>
27#endif
Kim Phillipsb22fc902007-07-25 19:25:33 -050028#include <asm/mmu.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050029
Simon Glass39f90ba2017-03-31 08:40:25 -060030DECLARE_GLOBAL_DATA_PTR;
31
Kim Phillipsb22fc902007-07-25 19:25:33 -050032const qe_iop_conf_t qe_iop_conf_tab[] = {
33 /* UCC3 */
34 {1, 0, 1, 0, 1}, /* TxD0 */
35 {1, 1, 1, 0, 1}, /* TxD1 */
36 {1, 2, 1, 0, 1}, /* TxD2 */
37 {1, 3, 1, 0, 1}, /* TxD3 */
38 {1, 9, 1, 0, 1}, /* TxER */
39 {1, 12, 1, 0, 1}, /* TxEN */
40 {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
41
42 {1, 4, 2, 0, 1}, /* RxD0 */
43 {1, 5, 2, 0, 1}, /* RxD1 */
44 {1, 6, 2, 0, 1}, /* RxD2 */
45 {1, 7, 2, 0, 1}, /* RxD3 */
46 {1, 8, 2, 0, 1}, /* RxER */
47 {1, 10, 2, 0, 1}, /* RxDV */
48 {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
49 {1, 11, 2, 0, 1}, /* COL */
50 {1, 13, 2, 0, 1}, /* CRS */
51
52 /* UCC2 */
53 {0, 18, 1, 0, 1}, /* TxD0 */
54 {0, 19, 1, 0, 1}, /* TxD1 */
55 {0, 20, 1, 0, 1}, /* TxD2 */
56 {0, 21, 1, 0, 1}, /* TxD3 */
57 {0, 27, 1, 0, 1}, /* TxER */
58 {0, 30, 1, 0, 1}, /* TxEN */
59 {3, 23, 2, 0, 1}, /* TxCLK->CLK3 */
60
61 {0, 22, 2, 0, 1}, /* RxD0 */
62 {0, 23, 2, 0, 1}, /* RxD1 */
63 {0, 24, 2, 0, 1}, /* RxD2 */
64 {0, 25, 2, 0, 1}, /* RxD3 */
65 {0, 26, 1, 0, 1}, /* RxER */
66 {0, 28, 2, 0, 1}, /* Rx_DV */
67 {3, 21, 2, 0, 1}, /* RxCLK->CLK16 */
68 {0, 29, 2, 0, 1}, /* COL */
69 {0, 31, 2, 0, 1}, /* CRS */
70
71 {3, 4, 3, 0, 2}, /* MDIO */
72 {3, 5, 1, 0, 2}, /* MDC */
73
74 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
75};
76
Kim Phillipsb22fc902007-07-25 19:25:33 -050077int fixed_sdram(void);
78
Simon Glassd35f3382017-04-06 12:47:05 -060079int dram_init(void)
Kim Phillipsb22fc902007-07-25 19:25:33 -050080{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillipsb22fc902007-07-25 19:25:33 -050082 u32 msize = 0;
83
84 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass39f90ba2017-03-31 08:40:25 -060085 return -ENXIO;
Kim Phillipsb22fc902007-07-25 19:25:33 -050086
87 /* DDR SDRAM - Main SODIMM */
Mario Sixc9f92772019-01-21 09:18:15 +010088 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Kim Phillipsb22fc902007-07-25 19:25:33 -050089
90 msize = fixed_sdram();
91
Simon Glass39f90ba2017-03-31 08:40:25 -060092 /* set total bus SDRAM size(bytes) -- DDR */
93 gd->ram_size = msize * 1024 * 1024;
94
95 return 0;
Kim Phillipsb22fc902007-07-25 19:25:33 -050096}
97
98/*************************************************************************
99 * fixed sdram init -- doesn't use serial presence detect.
100 ************************************************************************/
101int fixed_sdram(void)
102{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500104 u32 msize = 0;
105 u32 ddr_size;
106 u32 ddr_size_log2;
107
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108 msize = CONFIG_SYS_DDR_SIZE;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500109 for (ddr_size = msize << 20, ddr_size_log2 = 0;
110 (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
111 if (ddr_size & 1) {
112 return -1;
113 }
114 }
115 im->sysconf.ddrlaw[0].ar =
116 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
118 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
119 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
120 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
121 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
122 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
123 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
124 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
125 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
126 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
127 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
128 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500129 __asm__ __volatile__ ("sync");
130 udelay(200);
131
132 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
133 __asm__ __volatile__ ("sync");
134 return msize;
135}
136
137int checkboard(void)
138{
139 puts("Board: Freescale MPC8323ERDB\n");
140 return 0;
141}
142
143static struct pci_region pci_regions[] = {
144 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200145 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
146 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
147 size: CONFIG_SYS_PCI1_MEM_SIZE,
Kim Phillipsb22fc902007-07-25 19:25:33 -0500148 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
149 },
150 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
152 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
153 size: CONFIG_SYS_PCI1_MMIO_SIZE,
Kim Phillipsb22fc902007-07-25 19:25:33 -0500154 flags: PCI_REGION_MEM
155 },
156 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157 bus_start: CONFIG_SYS_PCI1_IO_BASE,
158 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
159 size: CONFIG_SYS_PCI1_IO_SIZE,
Kim Phillipsb22fc902007-07-25 19:25:33 -0500160 flags: PCI_REGION_IO
161 }
162};
163
164void pci_init_board(void)
165{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500167 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
168 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
169 struct pci_region *reg[] = { pci_regions };
170
171 /* Enable all 3 PCI_CLK_OUTPUTs. */
172 clk->occr |= 0xe0000000;
173
174 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200175 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500176 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
177
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200178 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500179 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
180
Peter Tysere2283322010-09-14 19:13:50 -0500181 mpc83xx_pci_init(1, reg);
Kim Phillipsb22fc902007-07-25 19:25:33 -0500182}
183
184#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900185int ft_board_setup(void *blob, struct bd_info *bd)
Kim Phillipsb22fc902007-07-25 19:25:33 -0500186{
Kim Phillipsb22fc902007-07-25 19:25:33 -0500187 ft_cpu_setup(blob, bd);
Kim Phillipsb22fc902007-07-25 19:25:33 -0500188#ifdef CONFIG_PCI
189 ft_pci_setup(blob, bd);
190#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600191
192 return 0;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500193}
Kim Phillips21416812007-08-15 22:30:33 -0500194#endif
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400195
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200196#if defined(CONFIG_SYS_I2C_MAC_OFFSET)
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400197int mac_read_from_eeprom(void)
198{
199 uchar buf[28];
200 char str[18];
201 int i = 0;
202 unsigned int crc = 0;
203 unsigned char enetvar[32];
204
205 /* Read MAC addresses from EEPROM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206 if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, CONFIG_SYS_I2C_MAC_OFFSET, buf, 28)) {
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400207 printf("\nEEPROM @ 0x%02x read FAILED!!!\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200208 CONFIG_SYS_I2C_EEPROM_ADDR);
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400209 } else {
Wolfgang Denkc950cb12013-07-14 19:42:40 +0200210 uint32_t crc_buf;
211
212 memcpy(&crc_buf, &buf[24], sizeof(uint32_t));
213
214 if (crc32(crc, buf, 24) == crc_buf) {
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400215 printf("Reading MAC from EEPROM\n");
216 for (i = 0; i < 4; i++) {
217 if (memcmp(&buf[i * 6], "\0\0\0\0\0\0", 6)) {
218 sprintf(str,
219 "%02X:%02X:%02X:%02X:%02X:%02X",
220 buf[i * 6], buf[i * 6 + 1],
221 buf[i * 6 + 2], buf[i * 6 + 3],
222 buf[i * 6 + 4], buf[i * 6 + 5]);
223 sprintf((char *)enetvar,
224 i ? "eth%daddr" : "ethaddr", i);
Simon Glass6a38e412017-08-03 12:22:09 -0600225 env_set((char *)enetvar, str);
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400226 }
227 }
228 }
229 }
230 return 0;
231}
232#endif /* CONFIG_I2C_MAC_OFFSET */