Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2013 Freescale Semiconductor, Inc. |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 7 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 10 | #include <asm/processor.h> |
| 11 | #include <asm/mmu.h> |
| 12 | #include <asm/cache.h> |
| 13 | #include <asm/immap_85xx.h> |
| 14 | #include <asm/io.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 15 | #include <env.h> |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 16 | #include <miiphy.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 17 | #include <linux/libfdt.h> |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 18 | #include <fdt_support.h> |
| 19 | #include <fsl_mdio.h> |
| 20 | #include <tsec.h> |
| 21 | #include <mmc.h> |
| 22 | #include <netdev.h> |
| 23 | #include <pci.h> |
York Sun | 37562f6 | 2013-10-22 12:39:02 -0700 | [diff] [blame] | 24 | #include <fsl_ifc.h> |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 25 | #include <asm/fsl_pci.h> |
| 26 | |
| 27 | #include "cpld.h" |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | int checkboard(void) |
| 32 | { |
| 33 | struct cpu_type *cpu = gd->arch.cpu; |
| 34 | struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE); |
| 35 | |
| 36 | printf("Board: %sPCIe, ", cpu->name); |
| 37 | printf("CPLD Ver: 0x%02x\n", in_8(&cpld_data->cpldver)); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | int board_early_init_f(void) |
| 43 | { |
Jaiprakash Singh | dd88806 | 2015-03-20 19:28:27 -0700 | [diff] [blame] | 44 | struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL}; |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 45 | |
| 46 | /* Clock configuration to access CPLD using IFC(GPCM) */ |
Jaiprakash Singh | dd88806 | 2015-03-20 19:28:27 -0700 | [diff] [blame] | 47 | setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT); |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | int board_early_init_r(void) |
| 53 | { |
| 54 | const unsigned long flashbase = CONFIG_SYS_FLASH_BASE; |
York Sun | 220c346 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 55 | int flash_esel = find_tlb_idx((void *)flashbase, 1); |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * Remap Boot flash region to caching-inhibited |
| 59 | * so that flash can be erased properly. |
| 60 | */ |
| 61 | |
| 62 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 63 | flush_dcache(); |
| 64 | invalidate_icache(); |
| 65 | |
York Sun | 220c346 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 66 | if (flash_esel == -1) { |
| 67 | /* very unlikely unless something is messed up */ |
| 68 | puts("Error: Could not find TLB for FLASH BASE\n"); |
| 69 | flash_esel = 1; /* give our best effort to continue */ |
| 70 | } else { |
| 71 | /* invalidate existing TLB entry for flash */ |
| 72 | disable_tlb(flash_esel); |
| 73 | } |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 74 | |
| 75 | set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, |
| 76 | MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 77 | 0, flash_esel, BOOKE_PAGESZ_64M, 1); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | #ifdef CONFIG_PCI |
| 83 | void pci_init_board(void) |
| 84 | { |
| 85 | fsl_pcie_init_board(0); |
| 86 | } |
| 87 | #endif /* ifdef CONFIG_PCI */ |
| 88 | |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 89 | int board_eth_init(bd_t *bis) |
| 90 | { |
Bin Meng | e1bd42d | 2016-01-11 22:41:13 -0800 | [diff] [blame] | 91 | #ifdef CONFIG_TSEC_ENET |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 92 | struct fsl_pq_mdio_info mdio_info; |
| 93 | struct tsec_info_struct tsec_info[2]; |
| 94 | int num = 0; |
| 95 | |
| 96 | #ifdef CONFIG_TSEC1 |
| 97 | SET_STD_TSEC_INFO(tsec_info[num], 1); |
| 98 | num++; |
| 99 | #endif |
| 100 | #ifdef CONFIG_TSEC2 |
| 101 | SET_STD_TSEC_INFO(tsec_info[num], 2); |
| 102 | num++; |
| 103 | #endif |
| 104 | if (!num) { |
| 105 | printf("No TSECs initialized\n"); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /* Register 1G MDIO bus */ |
| 110 | mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR; |
| 111 | mdio_info.name = DEFAULT_MII_NAME; |
| 112 | |
| 113 | fsl_pq_mdio_init(bis, &mdio_info); |
| 114 | |
| 115 | tsec_eth_init(bis, tsec_info, num); |
Bin Meng | e1bd42d | 2016-01-11 22:41:13 -0800 | [diff] [blame] | 116 | #endif |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 117 | |
| 118 | return pci_eth_init(bis); |
| 119 | } |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 120 | |
| 121 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 122 | void fdt_del_sec(void *blob, int offset) |
| 123 | { |
| 124 | int nodeoff = 0; |
| 125 | |
| 126 | while ((nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,sec-v6.0", |
| 127 | CONFIG_SYS_CCSRBAR_PHYS + CONFIG_SYS_FSL_SEC_OFFSET |
Alex Porosanu | b4848d0 | 2016-04-29 15:17:59 +0300 | [diff] [blame] | 128 | + offset * CONFIG_SYS_FSL_SEC_IDX_OFFSET)) >= 0) { |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 129 | fdt_del_node(blob, nodeoff); |
| 130 | offset++; |
| 131 | } |
| 132 | } |
| 133 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 134 | int ft_board_setup(void *blob, bd_t *bd) |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 135 | { |
| 136 | phys_addr_t base; |
| 137 | phys_size_t size; |
| 138 | struct cpu_type *cpu; |
| 139 | |
| 140 | cpu = gd->arch.cpu; |
| 141 | |
| 142 | ft_cpu_setup(blob, bd); |
| 143 | |
Simon Glass | da1a134 | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 144 | base = env_get_bootm_low(); |
| 145 | size = env_get_bootm_size(); |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 146 | |
| 147 | #if defined(CONFIG_PCI) |
| 148 | FT_FSL_PCI_SETUP; |
| 149 | #endif |
| 150 | |
| 151 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 152 | if (cpu->soc_ver == SVR_C291) |
| 153 | fdt_del_sec(blob, 1); |
| 154 | else if (cpu->soc_ver == SVR_C292) |
| 155 | fdt_del_sec(blob, 2); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 156 | |
| 157 | return 0; |
Mingkai Hu | e04004b | 2013-07-04 17:33:43 +0800 | [diff] [blame] | 158 | } |
| 159 | #endif |