Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * Author: Scott Wood <scottwood@freescale.com> |
| 6 | * Dave Liu <daveliu@freescale.com> |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Anton Vorontsov | b8b71ff | 2009-06-10 00:25:36 +0400 | [diff] [blame] | 10 | #include <hwconfig.h> |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 11 | #include <i2c.h> |
Simon Glass | 2cf431c | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <net.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
Anton Vorontsov | 25f5f0d | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 17 | #include <fdt_support.h> |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 18 | #include <pci.h> |
| 19 | #include <mpc83xx.h> |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 20 | #include <netdev.h> |
Anton Vorontsov | 8f11e34 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 21 | #include <asm/io.h> |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 22 | #include <ns16550.h> |
| 23 | #include <nand.h> |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | int board_early_init_f(void) |
| 28 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 29 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 30 | |
| 31 | if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) |
| 32 | gd->flags |= GD_FLG_SILENT; |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 37 | #ifndef CONFIG_NAND_SPL |
| 38 | |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 39 | static u8 read_board_info(void) |
| 40 | { |
| 41 | u8 val8; |
| 42 | i2c_set_bus_num(0); |
| 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | if (i2c_read(CONFIG_SYS_I2C_PCF8574A_ADDR, 0, 0, &val8, 1) == 0) |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 45 | return val8; |
| 46 | else |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | int checkboard(void) |
| 51 | { |
| 52 | static const char * const rev_str[] = { |
| 53 | "0.0", |
| 54 | "0.1", |
| 55 | "1.0", |
| 56 | "1.1", |
| 57 | "<unknown>", |
| 58 | }; |
| 59 | u8 info; |
| 60 | int i; |
| 61 | |
| 62 | info = read_board_info(); |
| 63 | i = (!info) ? 4: info & 0x03; |
| 64 | |
| 65 | printf("Board: Freescale MPC8315ERDB Rev %s\n", rev_str[i]); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static struct pci_region pci_regions[] = { |
| 71 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | bus_start: CONFIG_SYS_PCI_MEM_BASE, |
| 73 | phys_start: CONFIG_SYS_PCI_MEM_PHYS, |
| 74 | size: CONFIG_SYS_PCI_MEM_SIZE, |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 75 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 76 | }, |
| 77 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | bus_start: CONFIG_SYS_PCI_MMIO_BASE, |
| 79 | phys_start: CONFIG_SYS_PCI_MMIO_PHYS, |
| 80 | size: CONFIG_SYS_PCI_MMIO_SIZE, |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 81 | flags: PCI_REGION_MEM |
| 82 | }, |
| 83 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 84 | bus_start: CONFIG_SYS_PCI_IO_BASE, |
| 85 | phys_start: CONFIG_SYS_PCI_IO_PHYS, |
| 86 | size: CONFIG_SYS_PCI_IO_SIZE, |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 87 | flags: PCI_REGION_IO |
| 88 | } |
| 89 | }; |
| 90 | |
Anton Vorontsov | 8f11e34 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 91 | static struct pci_region pcie_regions_0[] = { |
| 92 | { |
| 93 | .bus_start = CONFIG_SYS_PCIE1_MEM_BASE, |
| 94 | .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS, |
| 95 | .size = CONFIG_SYS_PCIE1_MEM_SIZE, |
| 96 | .flags = PCI_REGION_MEM, |
| 97 | }, |
| 98 | { |
| 99 | .bus_start = CONFIG_SYS_PCIE1_IO_BASE, |
| 100 | .phys_start = CONFIG_SYS_PCIE1_IO_PHYS, |
| 101 | .size = CONFIG_SYS_PCIE1_IO_SIZE, |
| 102 | .flags = PCI_REGION_IO, |
| 103 | }, |
| 104 | }; |
| 105 | |
| 106 | static struct pci_region pcie_regions_1[] = { |
| 107 | { |
| 108 | .bus_start = CONFIG_SYS_PCIE2_MEM_BASE, |
| 109 | .phys_start = CONFIG_SYS_PCIE2_MEM_PHYS, |
| 110 | .size = CONFIG_SYS_PCIE2_MEM_SIZE, |
| 111 | .flags = PCI_REGION_MEM, |
| 112 | }, |
| 113 | { |
| 114 | .bus_start = CONFIG_SYS_PCIE2_IO_BASE, |
| 115 | .phys_start = CONFIG_SYS_PCIE2_IO_PHYS, |
| 116 | .size = CONFIG_SYS_PCIE2_IO_SIZE, |
| 117 | .flags = PCI_REGION_IO, |
| 118 | }, |
| 119 | }; |
| 120 | |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 121 | void pci_init_board(void) |
| 122 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 123 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
Anton Vorontsov | 8f11e34 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 124 | volatile sysconf83xx_t *sysconf = &immr->sysconf; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 125 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 126 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
Anton Vorontsov | 8f11e34 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 127 | volatile law83xx_t *pcie_law = sysconf->pcielaw; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 128 | struct pci_region *reg[] = { pci_regions }; |
Anton Vorontsov | 8f11e34 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 129 | struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, }; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 130 | |
| 131 | /* Enable all 3 PCI_CLK_OUTPUTs. */ |
| 132 | clk->occr |= 0xe0000000; |
| 133 | |
| 134 | /* |
| 135 | * Configure PCI Local Access Windows |
| 136 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 137 | pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 138 | pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB; |
| 139 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 141 | pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB; |
| 142 | |
Peter Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 143 | mpc83xx_pci_init(1, reg); |
Anton Vorontsov | 8f11e34 | 2009-01-08 04:26:17 +0300 | [diff] [blame] | 144 | |
| 145 | /* Configure the clock for PCIE controller */ |
| 146 | clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM, |
| 147 | SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1); |
| 148 | |
| 149 | /* Deassert the resets in the control register */ |
| 150 | out_be32(&sysconf->pecr1, 0xE0008000); |
| 151 | out_be32(&sysconf->pecr2, 0xE0008000); |
| 152 | udelay(2000); |
| 153 | |
| 154 | /* Configure PCI Express Local Access Windows */ |
| 155 | out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR); |
| 156 | out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 157 | |
| 158 | out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR); |
| 159 | out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB); |
| 160 | |
Peter Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 161 | mpc83xx_pcie_init(2, pcie_reg); |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 165 | void fdt_tsec1_fixup(void *fdt, struct bd_info *bd) |
Anton Vorontsov | 25f5f0d | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 166 | { |
Anton Vorontsov | 25f5f0d | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 167 | const char disabled[] = "disabled"; |
| 168 | const char *path; |
| 169 | int ret; |
| 170 | |
Anton Vorontsov | b8b71ff | 2009-06-10 00:25:36 +0400 | [diff] [blame] | 171 | if (hwconfig_arg_cmp("board_type", "tsec1")) { |
Anton Vorontsov | 021f6df | 2008-07-10 17:20:51 +0400 | [diff] [blame] | 172 | return; |
Anton Vorontsov | b8b71ff | 2009-06-10 00:25:36 +0400 | [diff] [blame] | 173 | } else if (!hwconfig_arg_cmp("board_type", "ulpi")) { |
| 174 | printf("NOTICE: No or unknown board_type hwconfig specified.\n" |
| 175 | " Assuming board with TSEC1.\n"); |
Anton Vorontsov | 021f6df | 2008-07-10 17:20:51 +0400 | [diff] [blame] | 176 | return; |
Anton Vorontsov | 25f5f0d | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | ret = fdt_path_offset(fdt, "/aliases"); |
| 180 | if (ret < 0) { |
| 181 | printf("WARNING: can't find /aliases node\n"); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | path = fdt_getprop(fdt, ret, "ethernet0", NULL); |
| 186 | if (!path) { |
| 187 | printf("WARNING: can't find ethernet0 alias\n"); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | do_fixup_by_path(fdt, path, "status", disabled, sizeof(disabled), 1); |
| 192 | } |
| 193 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 194 | int ft_board_setup(void *blob, struct bd_info *bd) |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 195 | { |
| 196 | ft_cpu_setup(blob, bd); |
| 197 | #ifdef CONFIG_PCI |
| 198 | ft_pci_setup(blob, bd); |
| 199 | #endif |
Sriram Dash | a5c289b | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 200 | fsl_fdt_fixup_dr_usb(blob, bd); |
Anton Vorontsov | 25f5f0d | 2008-07-08 21:00:04 +0400 | [diff] [blame] | 201 | fdt_tsec1_fixup(blob, bd); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 202 | |
| 203 | return 0; |
Dave Liu | 8bd522c | 2008-01-11 18:48:24 +0800 | [diff] [blame] | 204 | } |
| 205 | #endif |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 206 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 207 | int board_eth_init(struct bd_info *bis) |
Ben Warren | 10efa02 | 2008-08-31 20:37:00 -0700 | [diff] [blame] | 208 | { |
| 209 | cpu_eth_init(bis); /* Initialize TSECs first */ |
| 210 | return pci_eth_init(bis); |
| 211 | } |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 212 | |
| 213 | #else /* CONFIG_NAND_SPL */ |
| 214 | |
| 215 | int checkboard(void) |
| 216 | { |
| 217 | puts("Board: Freescale MPC8315ERDB\n"); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | void board_init_f(ulong bootflag) |
| 222 | { |
| 223 | board_early_init_f(); |
Simon Glass | 2d6bf75 | 2020-12-22 19:30:19 -0700 | [diff] [blame] | 224 | ns16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 225 | CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); |
| 226 | puts("NAND boot... "); |
Simon Glass | 70e2aaf | 2017-03-28 10:27:24 -0600 | [diff] [blame] | 227 | timer_init(); |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 228 | dram_init(); |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 229 | relocate_code(CONFIG_SYS_NAND_U_BOOT_RELOC + 0x10000, (gd_t *)gd, |
| 230 | CONFIG_SYS_NAND_U_BOOT_RELOC); |
| 231 | } |
| 232 | |
| 233 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 234 | { |
| 235 | nand_boot(); |
| 236 | } |
| 237 | |
| 238 | void putc(char c) |
| 239 | { |
| 240 | if (gd->flags & GD_FLG_SILENT) |
| 241 | return; |
| 242 | |
| 243 | if (c == '\n') |
Simon Glass | 2d6bf75 | 2020-12-22 19:30:19 -0700 | [diff] [blame] | 244 | ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 245 | |
Simon Glass | 2d6bf75 | 2020-12-22 19:30:19 -0700 | [diff] [blame] | 246 | ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); |
Anton Vorontsov | 2e95004 | 2009-11-24 20:12:12 +0300 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | #endif /* CONFIG_NAND_SPL */ |