blob: 003e95cb6ba07ada6cdc8d87742d9f90dde9668e [file] [log] [blame]
Kim Phillips1c274c42007-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 Glass9fb625c2019-08-01 09:46:51 -060013#include <env.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050014#include <ioports.h>
15#include <mpc83xx.h>
16#include <i2c.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050017#include <miiphy.h>
18#include <command.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090019#include <linux/libfdt.h>
Simon Glass3db71102019-11-14 12:57:16 -070020#include <u-boot/crc.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050021#if defined(CONFIG_PCI)
22#include <pci.h>
23#endif
Kim Phillips1c274c42007-07-25 19:25:33 -050024#include <asm/mmu.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050025
Simon Glass088454c2017-03-31 08:40:25 -060026DECLARE_GLOBAL_DATA_PTR;
27
Kim Phillips1c274c42007-07-25 19:25:33 -050028const qe_iop_conf_t qe_iop_conf_tab[] = {
29 /* UCC3 */
30 {1, 0, 1, 0, 1}, /* TxD0 */
31 {1, 1, 1, 0, 1}, /* TxD1 */
32 {1, 2, 1, 0, 1}, /* TxD2 */
33 {1, 3, 1, 0, 1}, /* TxD3 */
34 {1, 9, 1, 0, 1}, /* TxER */
35 {1, 12, 1, 0, 1}, /* TxEN */
36 {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
37
38 {1, 4, 2, 0, 1}, /* RxD0 */
39 {1, 5, 2, 0, 1}, /* RxD1 */
40 {1, 6, 2, 0, 1}, /* RxD2 */
41 {1, 7, 2, 0, 1}, /* RxD3 */
42 {1, 8, 2, 0, 1}, /* RxER */
43 {1, 10, 2, 0, 1}, /* RxDV */
44 {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
45 {1, 11, 2, 0, 1}, /* COL */
46 {1, 13, 2, 0, 1}, /* CRS */
47
48 /* UCC2 */
49 {0, 18, 1, 0, 1}, /* TxD0 */
50 {0, 19, 1, 0, 1}, /* TxD1 */
51 {0, 20, 1, 0, 1}, /* TxD2 */
52 {0, 21, 1, 0, 1}, /* TxD3 */
53 {0, 27, 1, 0, 1}, /* TxER */
54 {0, 30, 1, 0, 1}, /* TxEN */
55 {3, 23, 2, 0, 1}, /* TxCLK->CLK3 */
56
57 {0, 22, 2, 0, 1}, /* RxD0 */
58 {0, 23, 2, 0, 1}, /* RxD1 */
59 {0, 24, 2, 0, 1}, /* RxD2 */
60 {0, 25, 2, 0, 1}, /* RxD3 */
61 {0, 26, 1, 0, 1}, /* RxER */
62 {0, 28, 2, 0, 1}, /* Rx_DV */
63 {3, 21, 2, 0, 1}, /* RxCLK->CLK16 */
64 {0, 29, 2, 0, 1}, /* COL */
65 {0, 31, 2, 0, 1}, /* CRS */
66
67 {3, 4, 3, 0, 2}, /* MDIO */
68 {3, 5, 1, 0, 2}, /* MDC */
69
70 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
71};
72
Kim Phillips1c274c42007-07-25 19:25:33 -050073int fixed_sdram(void);
74
Simon Glassf1683aa2017-04-06 12:47:05 -060075int dram_init(void)
Kim Phillips1c274c42007-07-25 19:25:33 -050076{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020077 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips1c274c42007-07-25 19:25:33 -050078 u32 msize = 0;
79
80 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass088454c2017-03-31 08:40:25 -060081 return -ENXIO;
Kim Phillips1c274c42007-07-25 19:25:33 -050082
83 /* DDR SDRAM - Main SODIMM */
Mario Six8a81bfd2019-01-21 09:18:15 +010084 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Kim Phillips1c274c42007-07-25 19:25:33 -050085
86 msize = fixed_sdram();
87
Simon Glass088454c2017-03-31 08:40:25 -060088 /* set total bus SDRAM size(bytes) -- DDR */
89 gd->ram_size = msize * 1024 * 1024;
90
91 return 0;
Kim Phillips1c274c42007-07-25 19:25:33 -050092}
93
94/*************************************************************************
95 * fixed sdram init -- doesn't use serial presence detect.
96 ************************************************************************/
97int fixed_sdram(void)
98{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020099 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500100 u32 msize = 0;
101 u32 ddr_size;
102 u32 ddr_size_log2;
103
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104 msize = CONFIG_SYS_DDR_SIZE;
Kim Phillips1c274c42007-07-25 19:25:33 -0500105 for (ddr_size = msize << 20, ddr_size_log2 = 0;
106 (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
107 if (ddr_size & 1) {
108 return -1;
109 }
110 }
111 im->sysconf.ddrlaw[0].ar =
112 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200113 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
114 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
115 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
116 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
117 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
118 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
119 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
120 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
121 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
122 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
123 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
124 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Kim Phillips1c274c42007-07-25 19:25:33 -0500125 __asm__ __volatile__ ("sync");
126 udelay(200);
127
128 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
129 __asm__ __volatile__ ("sync");
130 return msize;
131}
132
133int checkboard(void)
134{
135 puts("Board: Freescale MPC8323ERDB\n");
136 return 0;
137}
138
139static struct pci_region pci_regions[] = {
140 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200141 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
142 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
143 size: CONFIG_SYS_PCI1_MEM_SIZE,
Kim Phillips1c274c42007-07-25 19:25:33 -0500144 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
145 },
146 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200147 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
148 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
149 size: CONFIG_SYS_PCI1_MMIO_SIZE,
Kim Phillips1c274c42007-07-25 19:25:33 -0500150 flags: PCI_REGION_MEM
151 },
152 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200153 bus_start: CONFIG_SYS_PCI1_IO_BASE,
154 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
155 size: CONFIG_SYS_PCI1_IO_SIZE,
Kim Phillips1c274c42007-07-25 19:25:33 -0500156 flags: PCI_REGION_IO
157 }
158};
159
160void pci_init_board(void)
161{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200162 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500163 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
164 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
165 struct pci_region *reg[] = { pci_regions };
166
167 /* Enable all 3 PCI_CLK_OUTPUTs. */
168 clk->occr |= 0xe0000000;
169
170 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500172 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
173
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200174 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500175 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
176
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500177 mpc83xx_pci_init(1, reg);
Kim Phillips1c274c42007-07-25 19:25:33 -0500178}
179
180#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600181int ft_board_setup(void *blob, bd_t *bd)
Kim Phillips1c274c42007-07-25 19:25:33 -0500182{
Kim Phillips1c274c42007-07-25 19:25:33 -0500183 ft_cpu_setup(blob, bd);
Kim Phillips1c274c42007-07-25 19:25:33 -0500184#ifdef CONFIG_PCI
185 ft_pci_setup(blob, bd);
186#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600187
188 return 0;
Kim Phillips1c274c42007-07-25 19:25:33 -0500189}
Kim Phillips3fde9e82007-08-15 22:30:33 -0500190#endif
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400191
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200192#if defined(CONFIG_SYS_I2C_MAC_OFFSET)
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400193int mac_read_from_eeprom(void)
194{
195 uchar buf[28];
196 char str[18];
197 int i = 0;
198 unsigned int crc = 0;
199 unsigned char enetvar[32];
200
201 /* Read MAC addresses from EEPROM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200202 if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, CONFIG_SYS_I2C_MAC_OFFSET, buf, 28)) {
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400203 printf("\nEEPROM @ 0x%02x read FAILED!!!\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200204 CONFIG_SYS_I2C_EEPROM_ADDR);
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400205 } else {
Wolfgang Denkf4ea9f82013-07-14 19:42:40 +0200206 uint32_t crc_buf;
207
208 memcpy(&crc_buf, &buf[24], sizeof(uint32_t));
209
210 if (crc32(crc, buf, 24) == crc_buf) {
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400211 printf("Reading MAC from EEPROM\n");
212 for (i = 0; i < 4; i++) {
213 if (memcmp(&buf[i * 6], "\0\0\0\0\0\0", 6)) {
214 sprintf(str,
215 "%02X:%02X:%02X:%02X:%02X:%02X",
216 buf[i * 6], buf[i * 6 + 1],
217 buf[i * 6 + 2], buf[i * 6 + 3],
218 buf[i * 6 + 4], buf[i * 6 + 5]);
219 sprintf((char *)enetvar,
220 i ? "eth%daddr" : "ethaddr", i);
Simon Glass382bee52017-08-03 12:22:09 -0600221 env_set((char *)enetvar, str);
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400222 }
223 }
224 }
225 }
226 return 0;
227}
228#endif /* CONFIG_I2C_MAC_OFFSET */