blob: cef3216a6fe58a01e3d7737a5c771f7f629afadd [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 Glasscb3ef682019-11-14 12:57:50 -070013#include <eeprom.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060014#include <env.h>
Simon Glass807765b2019-12-28 10:44:54 -070015#include <fdt_support.h>
Simon Glass2cf431c2019-11-14 12:57:47 -070016#include <init.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050017#include <ioports.h>
18#include <mpc83xx.h>
19#include <i2c.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050020#include <miiphy.h>
21#include <command.h>
Simon Glass401d1c42020-10-30 21:38:53 -060022#include <asm/global_data.h>
Simon Glassc05ed002020-05-10 11:40:11 -060023#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090024#include <linux/libfdt.h>
Simon Glass3db71102019-11-14 12:57:16 -070025#include <u-boot/crc.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050026#if defined(CONFIG_PCI)
27#include <pci.h>
28#endif
Kim Phillips1c274c42007-07-25 19:25:33 -050029#include <asm/mmu.h>
Kim Phillips1c274c42007-07-25 19:25:33 -050030
Simon Glass088454c2017-03-31 08:40:25 -060031DECLARE_GLOBAL_DATA_PTR;
32
Kim Phillips1c274c42007-07-25 19:25:33 -050033const qe_iop_conf_t qe_iop_conf_tab[] = {
34 /* UCC3 */
35 {1, 0, 1, 0, 1}, /* TxD0 */
36 {1, 1, 1, 0, 1}, /* TxD1 */
37 {1, 2, 1, 0, 1}, /* TxD2 */
38 {1, 3, 1, 0, 1}, /* TxD3 */
39 {1, 9, 1, 0, 1}, /* TxER */
40 {1, 12, 1, 0, 1}, /* TxEN */
41 {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
42
43 {1, 4, 2, 0, 1}, /* RxD0 */
44 {1, 5, 2, 0, 1}, /* RxD1 */
45 {1, 6, 2, 0, 1}, /* RxD2 */
46 {1, 7, 2, 0, 1}, /* RxD3 */
47 {1, 8, 2, 0, 1}, /* RxER */
48 {1, 10, 2, 0, 1}, /* RxDV */
49 {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
50 {1, 11, 2, 0, 1}, /* COL */
51 {1, 13, 2, 0, 1}, /* CRS */
52
53 /* UCC2 */
54 {0, 18, 1, 0, 1}, /* TxD0 */
55 {0, 19, 1, 0, 1}, /* TxD1 */
56 {0, 20, 1, 0, 1}, /* TxD2 */
57 {0, 21, 1, 0, 1}, /* TxD3 */
58 {0, 27, 1, 0, 1}, /* TxER */
59 {0, 30, 1, 0, 1}, /* TxEN */
60 {3, 23, 2, 0, 1}, /* TxCLK->CLK3 */
61
62 {0, 22, 2, 0, 1}, /* RxD0 */
63 {0, 23, 2, 0, 1}, /* RxD1 */
64 {0, 24, 2, 0, 1}, /* RxD2 */
65 {0, 25, 2, 0, 1}, /* RxD3 */
66 {0, 26, 1, 0, 1}, /* RxER */
67 {0, 28, 2, 0, 1}, /* Rx_DV */
68 {3, 21, 2, 0, 1}, /* RxCLK->CLK16 */
69 {0, 29, 2, 0, 1}, /* COL */
70 {0, 31, 2, 0, 1}, /* CRS */
71
72 {3, 4, 3, 0, 2}, /* MDIO */
73 {3, 5, 1, 0, 2}, /* MDC */
74
75 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
76};
77
Kim Phillips1c274c42007-07-25 19:25:33 -050078int fixed_sdram(void);
79
Simon Glassf1683aa2017-04-06 12:47:05 -060080int dram_init(void)
Kim Phillips1c274c42007-07-25 19:25:33 -050081{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020082 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips1c274c42007-07-25 19:25:33 -050083 u32 msize = 0;
84
85 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass088454c2017-03-31 08:40:25 -060086 return -ENXIO;
Kim Phillips1c274c42007-07-25 19:25:33 -050087
88 /* DDR SDRAM - Main SODIMM */
Mario Six8a81bfd2019-01-21 09:18:15 +010089 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Kim Phillips1c274c42007-07-25 19:25:33 -050090
91 msize = fixed_sdram();
92
Simon Glass088454c2017-03-31 08:40:25 -060093 /* set total bus SDRAM size(bytes) -- DDR */
94 gd->ram_size = msize * 1024 * 1024;
95
96 return 0;
Kim Phillips1c274c42007-07-25 19:25:33 -050097}
98
99/*************************************************************************
100 * fixed sdram init -- doesn't use serial presence detect.
101 ************************************************************************/
102int fixed_sdram(void)
103{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500105 u32 msize = 0;
106 u32 ddr_size;
107 u32 ddr_size_log2;
108
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200109 msize = CONFIG_SYS_DDR_SIZE;
Kim Phillips1c274c42007-07-25 19:25:33 -0500110 for (ddr_size = msize << 20, ddr_size_log2 = 0;
111 (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
112 if (ddr_size & 1) {
113 return -1;
114 }
115 }
116 im->sysconf.ddrlaw[0].ar =
117 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
119 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
120 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
121 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
122 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
123 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
124 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
125 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
126 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
127 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
128 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
129 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Kim Phillips1c274c42007-07-25 19:25:33 -0500130 __asm__ __volatile__ ("sync");
131 udelay(200);
132
133 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
134 __asm__ __volatile__ ("sync");
135 return msize;
136}
137
138int checkboard(void)
139{
140 puts("Board: Freescale MPC8323ERDB\n");
141 return 0;
142}
143
144static struct pci_region pci_regions[] = {
145 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200146 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
147 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
148 size: CONFIG_SYS_PCI1_MEM_SIZE,
Kim Phillips1c274c42007-07-25 19:25:33 -0500149 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
150 },
151 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
153 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
154 size: CONFIG_SYS_PCI1_MMIO_SIZE,
Kim Phillips1c274c42007-07-25 19:25:33 -0500155 flags: PCI_REGION_MEM
156 },
157 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200158 bus_start: CONFIG_SYS_PCI1_IO_BASE,
159 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
160 size: CONFIG_SYS_PCI1_IO_SIZE,
Kim Phillips1c274c42007-07-25 19:25:33 -0500161 flags: PCI_REGION_IO
162 }
163};
164
165void pci_init_board(void)
166{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200167 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500168 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
169 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
170 struct pci_region *reg[] = { pci_regions };
171
172 /* Enable all 3 PCI_CLK_OUTPUTs. */
173 clk->occr |= 0xe0000000;
174
175 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200176 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500177 pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
178
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200179 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Kim Phillips1c274c42007-07-25 19:25:33 -0500180 pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
181
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500182 mpc83xx_pci_init(1, reg);
Kim Phillips1c274c42007-07-25 19:25:33 -0500183}
184
185#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900186int ft_board_setup(void *blob, struct bd_info *bd)
Kim Phillips1c274c42007-07-25 19:25:33 -0500187{
Kim Phillips1c274c42007-07-25 19:25:33 -0500188 ft_cpu_setup(blob, bd);
Kim Phillips1c274c42007-07-25 19:25:33 -0500189#ifdef CONFIG_PCI
190 ft_pci_setup(blob, bd);
191#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600192
193 return 0;
Kim Phillips1c274c42007-07-25 19:25:33 -0500194}
Kim Phillips3fde9e82007-08-15 22:30:33 -0500195#endif
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400196
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200197#if defined(CONFIG_SYS_I2C_MAC_OFFSET)
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400198int mac_read_from_eeprom(void)
199{
200 uchar buf[28];
201 char str[18];
202 int i = 0;
203 unsigned int crc = 0;
204 unsigned char enetvar[32];
205
206 /* Read MAC addresses from EEPROM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200207 if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, CONFIG_SYS_I2C_MAC_OFFSET, buf, 28)) {
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400208 printf("\nEEPROM @ 0x%02x read FAILED!!!\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200209 CONFIG_SYS_I2C_EEPROM_ADDR);
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400210 } else {
Wolfgang Denkf4ea9f82013-07-14 19:42:40 +0200211 uint32_t crc_buf;
212
213 memcpy(&crc_buf, &buf[24], sizeof(uint32_t));
214
215 if (crc32(crc, buf, 24) == crc_buf) {
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400216 printf("Reading MAC from EEPROM\n");
217 for (i = 0; i < 4; i++) {
218 if (memcmp(&buf[i * 6], "\0\0\0\0\0\0", 6)) {
219 sprintf(str,
220 "%02X:%02X:%02X:%02X:%02X:%02X",
221 buf[i * 6], buf[i * 6 + 1],
222 buf[i * 6 + 2], buf[i * 6 + 3],
223 buf[i * 6 + 4], buf[i * 6 + 5]);
224 sprintf((char *)enetvar,
225 i ? "eth%daddr" : "ethaddr", i);
Simon Glass382bee52017-08-03 12:22:09 -0600226 env_set((char *)enetvar, str);
Michael Barkowski5b2793a2008-03-27 14:34:43 -0400227 }
228 }
229 }
230 }
231 return 0;
232}
233#endif /* CONFIG_I2C_MAC_OFFSET */