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