Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2013 |
| 3 | * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 26 | #include <env.h> |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 27 | #include <pci.h> |
| 28 | #include <asm/processor.h> |
| 29 | #include <asm/mmu.h> |
| 30 | #include <asm/cache.h> |
| 31 | #include <asm/immap_85xx.h> |
| 32 | #include <asm/fsl_pci.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 33 | #include <fsl_ddr_sdram.h> |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 34 | #include <asm/fsl_serdes.h> |
| 35 | #include <asm/io.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 36 | #include <linux/libfdt.h> |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 37 | #include <fdt_support.h> |
| 38 | #include <fsl_mdio.h> |
| 39 | #include <tsec.h> |
| 40 | #include <asm/fsl_law.h> |
| 41 | #include <netdev.h> |
| 42 | #include <i2c.h> |
| 43 | #include <pca9698.h> |
| 44 | #include <watchdog.h> |
| 45 | #include "../common/dp501.h" |
| 46 | #include "controlcenterd-id.h" |
| 47 | |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 48 | enum { |
| 49 | HWVER_100 = 0, |
| 50 | HWVER_110 = 1, |
| 51 | HWVER_120 = 2, |
| 52 | }; |
| 53 | |
| 54 | struct ihs_fpga { |
| 55 | u32 reflection_low; /* 0x0000 */ |
| 56 | u32 versions; /* 0x0004 */ |
| 57 | u32 fpga_version; /* 0x0008 */ |
| 58 | u32 fpga_features; /* 0x000c */ |
Dirk Eibach | c42e119 | 2015-10-28 11:46:29 +0100 | [diff] [blame] | 59 | u32 reserved[4]; /* 0x0010 */ |
| 60 | u32 control; /* 0x0020 */ |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #ifndef CONFIG_TRAILBLAZER |
| 64 | static struct pci_device_id hydra_supported[] = { |
| 65 | { 0x6d5e, 0xcdc0 }, |
| 66 | {} |
| 67 | }; |
| 68 | |
| 69 | static void hydra_initialize(void); |
| 70 | #endif |
| 71 | |
| 72 | int board_early_init_f(void) |
| 73 | { |
| 74 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 75 | ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR); |
| 76 | |
| 77 | /* Reset eLBC_DIU and SPI_eLBC in case we are booting from SD */ |
| 78 | clrsetbits_be32(&gur->pmuxcr, 0x00600000, 0x80000000); |
| 79 | |
| 80 | /* Set pmuxcr to allow both i2c1 and i2c2 */ |
| 81 | setbits_be32(&gur->pmuxcr, 0x00001000); |
| 82 | |
| 83 | /* Set pmuxcr to enable GPIO 3_11-3_13 */ |
| 84 | setbits_be32(&gur->pmuxcr, 0x00000010); |
| 85 | |
| 86 | /* Set pmuxcr to enable GPIO 2_31,3_9+10 */ |
| 87 | setbits_be32(&gur->pmuxcr, 0x00000020); |
| 88 | |
| 89 | /* Set pmuxcr to enable GPIO 2_28-2_30 */ |
| 90 | setbits_be32(&gur->pmuxcr, 0x000000c0); |
| 91 | |
| 92 | /* Set pmuxcr to enable GPIO 3_20-3_22 */ |
| 93 | setbits_be32(&gur->pmuxcr2, 0x03000000); |
| 94 | |
| 95 | /* Set pmuxcr to enable IRQ0-2 */ |
| 96 | clrbits_be32(&gur->pmuxcr, 0x00000300); |
| 97 | |
| 98 | /* Set pmuxcr to disable IRQ3-11 */ |
| 99 | setbits_be32(&gur->pmuxcr, 0x000000F0); |
| 100 | |
| 101 | /* Read back the register to synchronize the write. */ |
| 102 | in_be32(&gur->pmuxcr); |
| 103 | |
| 104 | /* Set the pin muxing to enable ETSEC2. */ |
| 105 | clrbits_be32(&gur->pmuxcr2, 0x001F8000); |
| 106 | |
| 107 | #ifdef CONFIG_TRAILBLAZER |
| 108 | /* |
| 109 | * GPIO3_10 SPERRTRIGGER |
| 110 | */ |
| 111 | setbits_be32(&pgpio->gpdir, 0x00200000); |
| 112 | clrbits_be32(&pgpio->gpdat, 0x00200000); |
| 113 | udelay(100); |
| 114 | setbits_be32(&pgpio->gpdat, 0x00200000); |
| 115 | udelay(100); |
| 116 | clrbits_be32(&pgpio->gpdat, 0x00200000); |
| 117 | #endif |
| 118 | |
| 119 | /* |
| 120 | * GPIO3_11 CPU-TO-FPGA-RESET# |
| 121 | */ |
| 122 | setbits_be32(&pgpio->gpdir, 0x00100000); |
| 123 | clrbits_be32(&pgpio->gpdat, 0x00100000); |
| 124 | |
| 125 | /* |
| 126 | * GPIO3_21 CPU-STATUS-WATCHDOG-TRIGGER# |
| 127 | */ |
| 128 | setbits_be32(&pgpio->gpdir, 0x00000400); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | int checkboard(void) |
| 134 | { |
| 135 | printf("Board: ControlCenter DIGITAL\n"); |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | int misc_init_r(void) |
| 141 | { |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * A list of PCI and SATA slots |
| 147 | */ |
| 148 | enum slot_id { |
| 149 | SLOT_PCIE1 = 1, |
| 150 | SLOT_PCIE2, |
| 151 | SLOT_PCIE3, |
| 152 | SLOT_PCIE4, |
| 153 | SLOT_PCIE5, |
| 154 | SLOT_SATA1, |
| 155 | SLOT_SATA2 |
| 156 | }; |
| 157 | |
| 158 | /* |
| 159 | * This array maps the slot identifiers to their names on the P1022DS board. |
| 160 | */ |
| 161 | static const char * const slot_names[] = { |
| 162 | [SLOT_PCIE1] = "Slot 1", |
| 163 | [SLOT_PCIE2] = "Slot 2", |
| 164 | [SLOT_PCIE3] = "Slot 3", |
| 165 | [SLOT_PCIE4] = "Slot 4", |
| 166 | [SLOT_PCIE5] = "Mini-PCIe", |
| 167 | [SLOT_SATA1] = "SATA 1", |
| 168 | [SLOT_SATA2] = "SATA 2", |
| 169 | }; |
| 170 | |
| 171 | /* |
| 172 | * This array maps a given SERDES configuration and SERDES device to the PCI or |
| 173 | * SATA slot that it connects to. This mapping is hard-coded in the FPGA. |
| 174 | */ |
| 175 | static u8 serdes_dev_slot[][SATA2 + 1] = { |
| 176 | [0x01] = { [PCIE3] = SLOT_PCIE4, [PCIE2] = SLOT_PCIE5 }, |
| 177 | [0x02] = { [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 }, |
| 178 | [0x09] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE4, |
| 179 | [PCIE2] = SLOT_PCIE5 }, |
| 180 | [0x16] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2, |
| 181 | [PCIE2] = SLOT_PCIE3, |
| 182 | [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 }, |
| 183 | [0x17] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2, |
| 184 | [PCIE2] = SLOT_PCIE3 }, |
| 185 | [0x1a] = { [PCIE1] = SLOT_PCIE1, [PCIE2] = SLOT_PCIE3, |
| 186 | [PCIE2] = SLOT_PCIE3, |
| 187 | [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 }, |
| 188 | [0x1c] = { [PCIE1] = SLOT_PCIE1, |
| 189 | [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 }, |
| 190 | [0x1e] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE3 }, |
| 191 | [0x1f] = { [PCIE1] = SLOT_PCIE1 }, |
| 192 | }; |
| 193 | |
| 194 | |
| 195 | /* |
| 196 | * Returns the name of the slot to which the PCIe or SATA controller is |
| 197 | * connected |
| 198 | */ |
| 199 | const char *board_serdes_name(enum srds_prtcl device) |
| 200 | { |
| 201 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 202 | u32 pordevsr = in_be32(&gur->pordevsr); |
| 203 | unsigned int srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> |
| 204 | MPC85xx_PORDEVSR_IO_SEL_SHIFT; |
| 205 | enum slot_id slot = serdes_dev_slot[srds_cfg][device]; |
| 206 | const char *name = slot_names[slot]; |
| 207 | |
| 208 | if (name) |
| 209 | return name; |
| 210 | else |
| 211 | return "Nothing"; |
| 212 | } |
| 213 | |
| 214 | void hw_watchdog_reset(void) |
| 215 | { |
| 216 | ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR); |
| 217 | |
| 218 | clrbits_be32(&pgpio->gpdat, 0x00000400); |
| 219 | setbits_be32(&pgpio->gpdat, 0x00000400); |
| 220 | } |
| 221 | |
| 222 | #ifdef CONFIG_TRAILBLAZER |
| 223 | int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 224 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 225 | return run_command(env_get("bootcmd"), flag); |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | int board_early_init_r(void) |
| 229 | { |
| 230 | ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR); |
| 231 | |
| 232 | /* |
| 233 | * GPIO3_12 PPC_SYSTEMREADY# |
| 234 | */ |
| 235 | setbits_be32(&pgpio->gpdir, 0x00080000); |
| 236 | setbits_be32(&pgpio->gpodr, 0x00080000); |
| 237 | clrbits_be32(&pgpio->gpdat, 0x00080000); |
| 238 | |
| 239 | return ccdm_compute_self_hash(); |
| 240 | } |
| 241 | |
| 242 | int last_stage_init(void) |
| 243 | { |
| 244 | startup_ccdm_id_module(); |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | #else |
| 249 | void pci_init_board(void) |
| 250 | { |
| 251 | fsl_pcie_init_board(0); |
| 252 | |
| 253 | hydra_initialize(); |
| 254 | } |
| 255 | |
| 256 | int board_early_init_r(void) |
| 257 | { |
| 258 | unsigned int k = 0; |
| 259 | ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR); |
| 260 | |
| 261 | /* wait for FPGA configuration to finish */ |
| 262 | while (!pca9698_get_value(0x22, 11) && (k++ < 30)) |
| 263 | udelay(100000); |
| 264 | |
| 265 | if (k > 30) { |
| 266 | puts("FPGA configuration timed out.\n"); |
| 267 | } else { |
| 268 | /* clear FPGA reset */ |
| 269 | udelay(1000); |
| 270 | setbits_be32(&pgpio->gpdat, 0x00100000); |
| 271 | } |
| 272 | |
| 273 | /* give time for PCIe link training */ |
| 274 | udelay(100000); |
| 275 | |
| 276 | /* |
| 277 | * GPIO3_12 PPC_SYSTEMREADY# |
| 278 | */ |
| 279 | setbits_be32(&pgpio->gpdir, 0x00080000); |
| 280 | setbits_be32(&pgpio->gpodr, 0x00080000); |
| 281 | clrbits_be32(&pgpio->gpdat, 0x00080000); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | int last_stage_init(void) |
| 287 | { |
| 288 | /* Turn on Parade DP501 */ |
| 289 | pca9698_direction_output(0x22, 7, 1); |
| 290 | udelay(500000); |
| 291 | |
| 292 | dp501_powerup(0x08); |
| 293 | |
| 294 | startup_ccdm_id_module(); |
| 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * Initialize on-board and/or PCI Ethernet devices |
| 301 | * |
| 302 | * Returns: |
| 303 | * <0, error |
| 304 | * 0, no ethernet devices found |
| 305 | * >0, number of ethernet devices initialized |
| 306 | */ |
| 307 | int board_eth_init(bd_t *bis) |
| 308 | { |
| 309 | struct fsl_pq_mdio_info mdio_info; |
| 310 | struct tsec_info_struct tsec_info[2]; |
| 311 | unsigned int num = 0; |
| 312 | |
| 313 | #ifdef CONFIG_TSEC1 |
| 314 | SET_STD_TSEC_INFO(tsec_info[num], 1); |
| 315 | num++; |
| 316 | #endif |
| 317 | #ifdef CONFIG_TSEC2 |
| 318 | SET_STD_TSEC_INFO(tsec_info[num], 2); |
| 319 | num++; |
| 320 | #endif |
| 321 | |
| 322 | mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR; |
| 323 | mdio_info.name = DEFAULT_MII_NAME; |
| 324 | fsl_pq_mdio_init(bis, &mdio_info); |
| 325 | |
| 326 | return tsec_eth_init(bis, tsec_info, num) + pci_eth_init(bis); |
| 327 | } |
| 328 | |
| 329 | #ifdef CONFIG_OF_BOARD_SETUP |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 330 | int ft_board_setup(void *blob, bd_t *bd) |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 331 | { |
| 332 | phys_addr_t base; |
| 333 | phys_size_t size; |
| 334 | |
| 335 | ft_cpu_setup(blob, bd); |
| 336 | |
Simon Glass | da1a134 | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 337 | base = env_get_bootm_low(); |
| 338 | size = env_get_bootm_size(); |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 339 | |
| 340 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 341 | |
| 342 | #ifdef CONFIG_HAS_FSL_DR_USB |
Sriram Dash | 9fd465c | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 343 | fsl_fdt_fixup_dr_usb(blob, bd); |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 344 | #endif |
| 345 | |
| 346 | FT_FSL_PCI_SETUP; |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 347 | |
| 348 | return 0; |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 349 | } |
| 350 | #endif |
| 351 | |
| 352 | static void hydra_initialize(void) |
| 353 | { |
| 354 | unsigned int i; |
| 355 | pci_dev_t devno; |
| 356 | |
| 357 | /* Find and probe all the matching PCI devices */ |
| 358 | for (i = 0; (devno = pci_find_devices(hydra_supported, i)) >= 0; i++) { |
| 359 | u32 val; |
| 360 | struct ihs_fpga *fpga; |
| 361 | u32 versions; |
| 362 | u32 fpga_version; |
| 363 | u32 fpga_features; |
| 364 | |
| 365 | unsigned hardware_version; |
| 366 | unsigned feature_uart_channels; |
| 367 | unsigned feature_sb_channels; |
| 368 | |
| 369 | /* Try to enable I/O accesses and bus-mastering */ |
| 370 | val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; |
| 371 | pci_write_config_dword(devno, PCI_COMMAND, val); |
| 372 | |
| 373 | /* Make sure it worked */ |
| 374 | pci_read_config_dword(devno, PCI_COMMAND, &val); |
| 375 | if (!(val & PCI_COMMAND_MEMORY)) { |
| 376 | puts("Can't enable I/O memory\n"); |
| 377 | continue; |
| 378 | } |
| 379 | if (!(val & PCI_COMMAND_MASTER)) { |
| 380 | puts("Can't enable bus-mastering\n"); |
| 381 | continue; |
| 382 | } |
| 383 | |
| 384 | /* read FPGA details */ |
| 385 | fpga = pci_map_bar(devno, PCI_BASE_ADDRESS_0, |
| 386 | PCI_REGION_MEM); |
| 387 | |
Dirk Eibach | c42e119 | 2015-10-28 11:46:29 +0100 | [diff] [blame] | 388 | /* disable sideband clocks */ |
| 389 | writel(1, &fpga->control); |
| 390 | |
Dirk Eibach | 3a72cbf | 2014-07-03 09:28:14 +0200 | [diff] [blame] | 391 | versions = readl(&fpga->versions); |
| 392 | fpga_version = readl(&fpga->fpga_version); |
| 393 | fpga_features = readl(&fpga->fpga_features); |
Dirk Eibach | 762d3df | 2013-06-26 15:55:17 +0200 | [diff] [blame] | 394 | |
| 395 | hardware_version = versions & 0xf; |
| 396 | feature_uart_channels = (fpga_features >> 6) & 0x1f; |
| 397 | feature_sb_channels = fpga_features & 0x1f; |
| 398 | |
| 399 | printf("FPGA%d: ", i); |
| 400 | |
| 401 | switch (hardware_version) { |
| 402 | case HWVER_100: |
| 403 | printf("HW-Ver 1.00\n"); |
| 404 | break; |
| 405 | |
| 406 | case HWVER_110: |
| 407 | printf("HW-Ver 1.10\n"); |
| 408 | break; |
| 409 | |
| 410 | case HWVER_120: |
| 411 | printf("HW-Ver 1.20\n"); |
| 412 | break; |
| 413 | |
| 414 | default: |
| 415 | printf("HW-Ver %d(not supported)\n", |
| 416 | hardware_version); |
| 417 | break; |
| 418 | } |
| 419 | |
| 420 | printf(" FPGA V %d.%02d, features:", |
| 421 | fpga_version / 100, fpga_version % 100); |
| 422 | |
| 423 | printf(" %d uart channel(s)", feature_uart_channels); |
| 424 | printf(" %d sideband channel(s)\n", feature_sb_channels); |
| 425 | } |
| 426 | } |
| 427 | #endif |