Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * Author: Scott Wood <scottwood@freescale.com> |
| 5 | * Dave Liu <daveliu@freescale.com> |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
Anton Vorontsov | d398b7e | 2009-06-10 00:25:36 +0400 | [diff] [blame] | 27 | #include <hwconfig.h> |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 28 | #include <i2c.h> |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 29 | #include <libfdt.h> |
Anton Vorontsov | 13c16a1 | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 30 | #include <fdt_support.h> |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 31 | #include <pci.h> |
| 32 | #include <mpc83xx.h> |
Ben Warren | 052a5ea | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 33 | #include <netdev.h> |
Anton Vorontsov | 0db0be2 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 34 | #include <asm/io.h> |
Anton Vorontsov | ec82175 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 35 | #include <ns16550.h> |
| 36 | #include <nand.h> |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 37 | |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
| 39 | |
| 40 | int board_early_init_f(void) |
| 41 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 43 | |
| 44 | if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) |
| 45 | gd->flags |= GD_FLG_SILENT; |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Anton Vorontsov | ec82175 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 50 | #ifndef CONFIG_NAND_SPL |
| 51 | |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 52 | static u8 read_board_info(void) |
| 53 | { |
| 54 | u8 val8; |
| 55 | i2c_set_bus_num(0); |
| 56 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0) |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 58 | return val8; |
| 59 | else |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int checkboard(void) |
| 64 | { |
| 65 | static const char * const rev_str[] = { |
| 66 | "0.0", |
| 67 | "0.1", |
| 68 | "1.0", |
| 69 | "1.1", |
| 70 | "<unknown>", |
| 71 | }; |
| 72 | u8 info; |
| 73 | int i; |
| 74 | |
| 75 | info = read_board_info(); |
| 76 | i = (!info) ? 4: info & 0x03; |
| 77 | |
| 78 | printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static struct pci_region pci_regions[] = { |
| 84 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | bus_start: CONFIG_SYS_PCI_MEM_BASE, |
| 86 | phys_start: CONFIG_SYS_PCI_MEM_PHYS, |
| 87 | size: CONFIG_SYS_PCI_MEM_SIZE, |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 88 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 89 | }, |
| 90 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | bus_start: CONFIG_SYS_PCI_MMIO_BASE, |
| 92 | phys_start: CONFIG_SYS_PCI_MMIO_PHYS, |
| 93 | size: CONFIG_SYS_PCI_MMIO_SIZE, |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 94 | flags: PCI_REGION_MEM |
| 95 | }, |
| 96 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | bus_start: CONFIG_SYS_PCI_IO_BASE, |
| 98 | phys_start: CONFIG_SYS_PCI_IO_PHYS, |
| 99 | size: CONFIG_SYS_PCI_IO_SIZE, |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 100 | flags: PCI_REGION_IO |
| 101 | } |
| 102 | }; |
| 103 | |
Anton Vorontsov | 0db0be2 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 104 | static struct pci_region pcie_regions_0[] = { |
| 105 | { |
| 106 | .bus_start = CONFIG_SYS_PCIE1_MEM_BASE, |
| 107 | .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS, |
| 108 | .size = CONFIG_SYS_PCIE1_MEM_SIZE, |
| 109 | .flags = PCI_REGION_MEM, |
| 110 | }, |
| 111 | { |
| 112 | .bus_start = CONFIG_SYS_PCIE1_IO_BASE, |
| 113 | .phys_start = CONFIG_SYS_PCIE1_IO_PHYS, |
| 114 | .size = CONFIG_SYS_PCIE1_IO_SIZE, |
| 115 | .flags = PCI_REGION_IO, |
| 116 | }, |
| 117 | }; |
| 118 | |
| 119 | static struct pci_region pcie_regions_1[] = { |
| 120 | { |
| 121 | .bus_start = CONFIG_SYS_PCIE2_MEM_BASE, |
| 122 | .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS, |
| 123 | .size = CONFIG_SYS_PCIE2_MEM_SIZE, |
| 124 | .flags = PCI_REGION_MEM, |
| 125 | }, |
| 126 | { |
| 127 | .bus_start = CONFIG_SYS_PCIE2_IO_BASE, |
| 128 | .phys_start = CONFIG_SYS_PCIE2_IO_PHYS, |
| 129 | .size = CONFIG_SYS_PCIE2_IO_SIZE, |
| 130 | .flags = PCI_REGION_IO, |
| 131 | }, |
| 132 | }; |
| 133 | |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 134 | void pci_init_board(void) |
| 135 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 136 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
Anton Vorontsov | 0db0be2 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 137 | volatile sysconf83xx_t *sysconf = &immr->sysconf; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 138 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 139 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
Anton Vorontsov | 0db0be2 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 140 | volatile law83xx_t *pcie_law = sysconf->pcielaw; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 141 | struct pci_region *reg[] = { pci_regions }; |
Anton Vorontsov | 0db0be2 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 142 | struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 143 | int warmboot; |
| 144 | |
| 145 | /* Enable all 3 PCI_CLK_OUTPUTs. */ |
| 146 | clk->occr |= 0xe0000000; |
| 147 | |
| 148 | /* |
| 149 | * Configure PCI Local Access Windows |
| 150 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 151 | pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 152 | pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; |
| 153 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 155 | pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; |
| 156 | |
| 157 | warmboot = gd->bd->bi_bootflags & BOOTFLAG_WARM; |
| 158 | warmboot |= immr->pmc.pmccr1 & PMCCR1_POWER_OFF; |
| 159 | |
| 160 | mpc83xx_pci_init(1, reg, warmboot); |
Anton Vorontsov | 0db0be2 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 161 | |
| 162 | /* Configure the clock for PCIE controller */ |
| 163 | clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM, |
| 164 | SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1); |
| 165 | |
| 166 | /* Deassert the resets in the control register */ |
| 167 | out_be32(&sysconf->pecr1, 0xE0008000); |
| 168 | out_be32(&sysconf->pecr2, 0xE0008000); |
| 169 | udelay(2000); |
| 170 | |
| 171 | /* Configure PCI Express Local Access Windows */ |
| 172 | out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR); |
| 173 | out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 174 | |
| 175 | out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR); |
| 176 | out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 177 | |
| 178 | mpc83xx_pcie_init(2, pcie_reg, warmboot); |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | #if defined(CONFIG_OF_BOARD_SETUP) |
Anton Vorontsov | 13c16a1 | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 182 | void fdt_tsec1_fixup(void *fdt, bd_t *bd) |
| 183 | { |
Anton Vorontsov | 13c16a1 | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 184 | const char disabled[] = "disabled"; |
| 185 | const char *path; |
| 186 | int ret; |
| 187 | |
Anton Vorontsov | d398b7e | 2009-06-10 00:25:36 +0400 | [diff] [blame] | 188 | if (hwconfig_arg_cmp("board_type", "tsec1")) { |
Anton Vorontsov | 8748178 | 2008-07-10 17:20:51 +0400 | [diff] [blame] | 189 | return; |
Anton Vorontsov | d398b7e | 2009-06-10 00:25:36 +0400 | [diff] [blame] | 190 | } else if (!hwconfig_arg_cmp("board_type", "ulpi")) { |
| 191 | printf("NOTICE: No or unknown board_type hwconfig specified.\n" |
| 192 | " Assuming board with TSEC1.\n"); |
Anton Vorontsov | 8748178 | 2008-07-10 17:20:51 +0400 | [diff] [blame] | 193 | return; |
Anton Vorontsov | 13c16a1 | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | ret = fdt_path_offset(fdt, "/aliases"); |
| 197 | if (ret < 0) { |
| 198 | printf("WARNING: can't find /aliases node\n"); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | path = fdt_getprop(fdt, ret, "ethernet0", NULL); |
| 203 | if (!path) { |
| 204 | printf("WARNING: can't find ethernet0 alias\n"); |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1); |
| 209 | } |
| 210 | |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 211 | void ft_board_setup(void *blob, bd_t *bd) |
| 212 | { |
| 213 | ft_cpu_setup(blob, bd); |
| 214 | #ifdef CONFIG_PCI |
| 215 | ft_pci_setup(blob, bd); |
| 216 | #endif |
Anton Vorontsov | 13c16a1 | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 217 | fdt_fixup_dr_usb(blob, bd); |
| 218 | fdt_tsec1_fixup(blob, bd); |
Dave Liu | 19b247e | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 219 | } |
| 220 | #endif |
Ben Warren | 052a5ea | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 221 | |
| 222 | int board_eth_init(bd_t *bis) |
| 223 | { |
| 224 | cpu_eth_init(bis); /* Initialize TSECs first */ |
| 225 | return pci_eth_init(bis); |
| 226 | } |
Anton Vorontsov | ec82175 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 227 | |
| 228 | #else /* CONFIG_NAND_SPL */ |
| 229 | |
| 230 | int checkboard(void) |
| 231 | { |
| 232 | puts("Board: Freescale MPC8315ERDB\n"); |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | void board_init_f(ulong bootflag) |
| 237 | { |
| 238 | board_early_init_f(); |
| 239 | NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), |
| 240 | CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); |
| 241 | puts("NAND boot... "); |
| 242 | init_timebase(); |
| 243 | initdram(0); |
| 244 | relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC + 0x10000, (gd_t *)gd, |
| 245 | CONFIG_SYS_NAND_U_BOOT_RELOC); |
| 246 | } |
| 247 | |
| 248 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 249 | { |
| 250 | nand_boot(); |
| 251 | } |
| 252 | |
| 253 | void putc(char c) |
| 254 | { |
| 255 | if (gd->flags & GD_FLG_SILENT) |
| 256 | return; |
| 257 | |
| 258 | if (c == '\n') |
| 259 | NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r'); |
| 260 | |
| 261 | NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c); |
| 262 | } |
| 263 | |
| 264 | #endif /* CONFIG_NAND_SPL */ |