common: Move pci_init_board() out of common.h
[pandora-u-boot.git] / board / freescale / mpc8323erdb / mpc8323erdb.c
1 /*
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>
13 #include <env.h>
14 #include <init.h>
15 #include <ioports.h>
16 #include <mpc83xx.h>
17 #include <i2c.h>
18 #include <miiphy.h>
19 #include <command.h>
20 #include <linux/libfdt.h>
21 #include <u-boot/crc.h>
22 #if defined(CONFIG_PCI)
23 #include <pci.h>
24 #endif
25 #include <asm/mmu.h>
26
27 DECLARE_GLOBAL_DATA_PTR;
28
29 const qe_iop_conf_t qe_iop_conf_tab[] = {
30         /* UCC3 */
31         {1,  0, 1, 0, 1}, /* TxD0 */
32         {1,  1, 1, 0, 1}, /* TxD1 */
33         {1,  2, 1, 0, 1}, /* TxD2 */
34         {1,  3, 1, 0, 1}, /* TxD3 */
35         {1,  9, 1, 0, 1}, /* TxER */
36         {1, 12, 1, 0, 1}, /* TxEN */
37         {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
38
39         {1,  4, 2, 0, 1}, /* RxD0 */
40         {1,  5, 2, 0, 1}, /* RxD1 */
41         {1,  6, 2, 0, 1}, /* RxD2 */
42         {1,  7, 2, 0, 1}, /* RxD3 */
43         {1,  8, 2, 0, 1}, /* RxER */
44         {1, 10, 2, 0, 1}, /* RxDV */
45         {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
46         {1, 11, 2, 0, 1}, /* COL */
47         {1, 13, 2, 0, 1}, /* CRS */
48
49         /* UCC2 */
50         {0, 18, 1, 0, 1}, /* TxD0 */
51         {0, 19, 1, 0, 1}, /* TxD1 */
52         {0, 20, 1, 0, 1}, /* TxD2 */
53         {0, 21, 1, 0, 1}, /* TxD3 */
54         {0, 27, 1, 0, 1}, /* TxER */
55         {0, 30, 1, 0, 1}, /* TxEN */
56         {3, 23, 2, 0, 1}, /* TxCLK->CLK3 */
57
58         {0, 22, 2, 0, 1}, /* RxD0 */
59         {0, 23, 2, 0, 1}, /* RxD1 */
60         {0, 24, 2, 0, 1}, /* RxD2 */
61         {0, 25, 2, 0, 1}, /* RxD3 */
62         {0, 26, 1, 0, 1}, /* RxER */
63         {0, 28, 2, 0, 1}, /* Rx_DV */
64         {3, 21, 2, 0, 1}, /* RxCLK->CLK16 */
65         {0, 29, 2, 0, 1}, /* COL */
66         {0, 31, 2, 0, 1}, /* CRS */
67
68         {3,  4, 3, 0, 2}, /* MDIO */
69         {3,  5, 1, 0, 2}, /* MDC */
70
71         {0,  0, 0, 0, QE_IOP_TAB_END}, /* END of table */
72 };
73
74 int fixed_sdram(void);
75
76 int dram_init(void)
77 {
78         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
79         u32 msize = 0;
80
81         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
82                 return -ENXIO;
83
84         /* DDR SDRAM - Main SODIMM */
85         im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
86
87         msize = fixed_sdram();
88
89         /* set total bus SDRAM size(bytes)  -- DDR */
90         gd->ram_size = msize * 1024 * 1024;
91
92         return 0;
93 }
94
95 /*************************************************************************
96  *  fixed sdram init -- doesn't use serial presence detect.
97  ************************************************************************/
98 int fixed_sdram(void)
99 {
100         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
101         u32 msize = 0;
102         u32 ddr_size;
103         u32 ddr_size_log2;
104
105         msize = CONFIG_SYS_DDR_SIZE;
106         for (ddr_size = msize << 20, ddr_size_log2 = 0;
107              (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
108                 if (ddr_size & 1) {
109                         return -1;
110                 }
111         }
112         im->sysconf.ddrlaw[0].ar =
113             LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
114         im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
115         im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
116         im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
117         im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
118         im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
119         im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
120         im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
121         im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
122         im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
123         im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
124         im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
125         im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
126         __asm__ __volatile__ ("sync");
127         udelay(200);
128
129         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
130         __asm__ __volatile__ ("sync");
131         return msize;
132 }
133
134 int checkboard(void)
135 {
136         puts("Board: Freescale MPC8323ERDB\n");
137         return 0;
138 }
139
140 static struct pci_region pci_regions[] = {
141         {
142                 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
143                 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
144                 size: CONFIG_SYS_PCI1_MEM_SIZE,
145                 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
146         },
147         {
148                 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
149                 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
150                 size: CONFIG_SYS_PCI1_MMIO_SIZE,
151                 flags: PCI_REGION_MEM
152         },
153         {
154                 bus_start: CONFIG_SYS_PCI1_IO_BASE,
155                 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
156                 size: CONFIG_SYS_PCI1_IO_SIZE,
157                 flags: PCI_REGION_IO
158         }
159 };
160
161 void pci_init_board(void)
162 {
163         volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
164         volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
165         volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
166         struct pci_region *reg[] = { pci_regions };
167
168         /* Enable all 3 PCI_CLK_OUTPUTs. */
169         clk->occr |= 0xe0000000;
170
171         /* Configure PCI Local Access Windows */
172         pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
173         pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
174
175         pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
176         pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
177
178         mpc83xx_pci_init(1, reg);
179 }
180
181 #if defined(CONFIG_OF_BOARD_SETUP)
182 int ft_board_setup(void *blob, bd_t *bd)
183 {
184         ft_cpu_setup(blob, bd);
185 #ifdef CONFIG_PCI
186         ft_pci_setup(blob, bd);
187 #endif
188
189         return 0;
190 }
191 #endif
192
193 #if defined(CONFIG_SYS_I2C_MAC_OFFSET)
194 int mac_read_from_eeprom(void)
195 {
196         uchar buf[28];
197         char str[18];
198         int i = 0;
199         unsigned int crc = 0;
200         unsigned char enetvar[32];
201
202         /* Read MAC addresses from EEPROM */
203         if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, CONFIG_SYS_I2C_MAC_OFFSET, buf, 28)) {
204                 printf("\nEEPROM @ 0x%02x read FAILED!!!\n",
205                        CONFIG_SYS_I2C_EEPROM_ADDR);
206         } else {
207                 uint32_t crc_buf;
208
209                 memcpy(&crc_buf, &buf[24], sizeof(uint32_t));
210
211                 if (crc32(crc, buf, 24) == crc_buf) {
212                         printf("Reading MAC from EEPROM\n");
213                         for (i = 0; i < 4; i++) {
214                                 if (memcmp(&buf[i * 6], "\0\0\0\0\0\0", 6)) {
215                                         sprintf(str,
216                                                 "%02X:%02X:%02X:%02X:%02X:%02X",
217                                                 buf[i * 6], buf[i * 6 + 1],
218                                                 buf[i * 6 + 2], buf[i * 6 + 3],
219                                                 buf[i * 6 + 4], buf[i * 6 + 5]);
220                                         sprintf((char *)enetvar,
221                                                 i ? "eth%daddr" : "ethaddr", i);
222                                         env_set((char *)enetvar, str);
223                                 }
224                         }
225                 }
226         }
227         return 0;
228 }
229 #endif                          /* CONFIG_I2C_MAC_OFFSET */