blob: e5aecc4e1f28b82f91f8e843412f5f832801d6a8 [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 Glass5e6201b2019-08-01 09:46:51 -060013#include <env.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050014#include <ioports.h>
15#include <mpc83xx.h>
16#include <i2c.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050017#include <miiphy.h>
18#include <command.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090019#include <linux/libfdt.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050020#if defined(CONFIG_PCI)
21#include <pci.h>
22#endif
Kim Phillipsb22fc902007-07-25 19:25:33 -050023#include <asm/mmu.h>
Kim Phillipsb22fc902007-07-25 19:25:33 -050024
Simon Glass39f90ba2017-03-31 08:40:25 -060025DECLARE_GLOBAL_DATA_PTR;
26
Kim Phillipsb22fc902007-07-25 19:25:33 -050027const qe_iop_conf_t qe_iop_conf_tab[] = {
28 /* UCC3 */
29 {1, 0, 1, 0, 1}, /* TxD0 */
30 {1, 1, 1, 0, 1}, /* TxD1 */
31 {1, 2, 1, 0, 1}, /* TxD2 */
32 {1, 3, 1, 0, 1}, /* TxD3 */
33 {1, 9, 1, 0, 1}, /* TxER */
34 {1, 12, 1, 0, 1}, /* TxEN */
35 {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
36
37 {1, 4, 2, 0, 1}, /* RxD0 */
38 {1, 5, 2, 0, 1}, /* RxD1 */
39 {1, 6, 2, 0, 1}, /* RxD2 */
40 {1, 7, 2, 0, 1}, /* RxD3 */
41 {1, 8, 2, 0, 1}, /* RxER */
42 {1, 10, 2, 0, 1}, /* RxDV */
43 {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
44 {1, 11, 2, 0, 1}, /* COL */
45 {1, 13, 2, 0, 1}, /* CRS */
46
47 /* UCC2 */
48 {0, 18, 1, 0, 1}, /* TxD0 */
49 {0, 19, 1, 0, 1}, /* TxD1 */
50 {0, 20, 1, 0, 1}, /* TxD2 */
51 {0, 21, 1, 0, 1}, /* TxD3 */
52 {0, 27, 1, 0, 1}, /* TxER */
53 {0, 30, 1, 0, 1}, /* TxEN */
54 {3, 23, 2, 0, 1}, /* TxCLK->CLK3 */
55
56 {0, 22, 2, 0, 1}, /* RxD0 */
57 {0, 23, 2, 0, 1}, /* RxD1 */
58 {0, 24, 2, 0, 1}, /* RxD2 */
59 {0, 25, 2, 0, 1}, /* RxD3 */
60 {0, 26, 1, 0, 1}, /* RxER */
61 {0, 28, 2, 0, 1}, /* Rx_DV */
62 {3, 21, 2, 0, 1}, /* RxCLK->CLK16 */
63 {0, 29, 2, 0, 1}, /* COL */
64 {0, 31, 2, 0, 1}, /* CRS */
65
66 {3, 4, 3, 0, 2}, /* MDIO */
67 {3, 5, 1, 0, 2}, /* MDC */
68
69 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
70};
71
Kim Phillipsb22fc902007-07-25 19:25:33 -050072int fixed_sdram(void);
73
Simon Glassd35f3382017-04-06 12:47:05 -060074int dram_init(void)
Kim Phillipsb22fc902007-07-25 19:25:33 -050075{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020076 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillipsb22fc902007-07-25 19:25:33 -050077 u32 msize = 0;
78
79 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass39f90ba2017-03-31 08:40:25 -060080 return -ENXIO;
Kim Phillipsb22fc902007-07-25 19:25:33 -050081
82 /* DDR SDRAM - Main SODIMM */
Mario Sixc9f92772019-01-21 09:18:15 +010083 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Kim Phillipsb22fc902007-07-25 19:25:33 -050084
85 msize = fixed_sdram();
86
Simon Glass39f90ba2017-03-31 08:40:25 -060087 /* set total bus SDRAM size(bytes) -- DDR */
88 gd->ram_size = msize * 1024 * 1024;
89
90 return 0;
Kim Phillipsb22fc902007-07-25 19:25:33 -050091}
92
93/*************************************************************************
94 * fixed sdram init -- doesn't use serial presence detect.
95 ************************************************************************/
96int fixed_sdram(void)
97{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillipsb22fc902007-07-25 19:25:33 -050099 u32 msize = 0;
100 u32 ddr_size;
101 u32 ddr_size_log2;
102
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 msize = CONFIG_SYS_DDR_SIZE;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500104 for (ddr_size = msize << 20, ddr_size_log2 = 0;
105 (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
106 if (ddr_size & 1) {
107 return -1;
108 }
109 }
110 im->sysconf.ddrlaw[0].ar =
111 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
113 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
114 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
115 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
116 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
117 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
118 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
119 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
120 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
121 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
122 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
123 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500124 __asm__ __volatile__ ("sync");
125 udelay(200);
126
127 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
128 __asm__ __volatile__ ("sync");
129 return msize;
130}
131
132int checkboard(void)
133{
134 puts("Board: Freescale MPC8323ERDB\n");
135 return 0;
136}
137
138static struct pci_region pci_regions[] = {
139 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
141 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
142 size: CONFIG_SYS_PCI1_MEM_SIZE,
Kim Phillipsb22fc902007-07-25 19:25:33 -0500143 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
144 },
145 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
147 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
148 size: CONFIG_SYS_PCI1_MMIO_SIZE,
Kim Phillipsb22fc902007-07-25 19:25:33 -0500149 flags: PCI_REGION_MEM
150 },
151 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200152 bus_start: CONFIG_SYS_PCI1_IO_BASE,
153 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
154 size: CONFIG_SYS_PCI1_IO_SIZE,
Kim Phillipsb22fc902007-07-25 19:25:33 -0500155 flags: PCI_REGION_IO
156 }
157};
158
159void pci_init_board(void)
160{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200161 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500162 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
163 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
164 struct pci_region *reg[] = { pci_regions };
165
166 /* Enable all 3 PCI_CLK_OUTPUTs. */
167 clk->occr |= 0xe0000000;
168
169 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500171 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
172
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200173 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500174 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
175
Peter Tysere2283322010-09-14 19:13:50 -0500176 mpc83xx_pci_init(1, reg);
Kim Phillipsb22fc902007-07-25 19:25:33 -0500177}
178
179#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600180int ft_board_setup(void *blob, bd_t *bd)
Kim Phillipsb22fc902007-07-25 19:25:33 -0500181{
Kim Phillipsb22fc902007-07-25 19:25:33 -0500182 ft_cpu_setup(blob, bd);
Kim Phillipsb22fc902007-07-25 19:25:33 -0500183#ifdef CONFIG_PCI
184 ft_pci_setup(blob, bd);
185#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600186
187 return 0;
Kim Phillipsb22fc902007-07-25 19:25:33 -0500188}
Kim Phillips21416812007-08-15 22:30:33 -0500189#endif
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400190
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200191#if defined(CONFIG_SYS_I2C_MAC_OFFSET)
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400192int mac_read_from_eeprom(void)
193{
194 uchar buf[28];
195 char str[18];
196 int i = 0;
197 unsigned int crc = 0;
198 unsigned char enetvar[32];
199
200 /* Read MAC addresses from EEPROM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200201 if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, CONFIG_SYS_I2C_MAC_OFFSET, buf, 28)) {
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400202 printf("\nEEPROM @ 0x%02x read FAILED!!!\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200203 CONFIG_SYS_I2C_EEPROM_ADDR);
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400204 } else {
Wolfgang Denkc950cb12013-07-14 19:42:40 +0200205 uint32_t crc_buf;
206
207 memcpy(&crc_buf, &buf[24], sizeof(uint32_t));
208
209 if (crc32(crc, buf, 24) == crc_buf) {
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400210 printf("Reading MAC from EEPROM\n");
211 for (i = 0; i < 4; i++) {
212 if (memcmp(&buf[i * 6], "\0\0\0\0\0\0", 6)) {
213 sprintf(str,
214 "%02X:%02X:%02X:%02X:%02X:%02X",
215 buf[i * 6], buf[i * 6 + 1],
216 buf[i * 6 + 2], buf[i * 6 + 3],
217 buf[i * 6 + 4], buf[i * 6 + 5]);
218 sprintf((char *)enetvar,
219 i ? "eth%daddr" : "ethaddr", i);
Simon Glass6a38e412017-08-03 12:22:09 -0600220 env_set((char *)enetvar, str);
Michael Barkowskie6c56b62008-03-27 14:34:43 -0400221 }
222 }
223 }
224 }
225 return 0;
226}
227#endif /* CONFIG_I2C_MAC_OFFSET */