Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 4 | * Kevin Lam <kevin.lam@freescale.com> |
| 5 | * Joe D'Abbraccio <joe.d'abbraccio@freescale.com> |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | db22961 | 2019-08-01 09:46:42 -0600 | [diff] [blame] | 9 | #include <env.h> |
Anton Vorontsov | 3628a93 | 2009-06-10 00:25:30 +0400 | [diff] [blame] | 10 | #include <hwconfig.h> |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 11 | #include <i2c.h> |
Simon Glass | 0ffd9db | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 12 | #include <init.h> |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 13 | #include <asm/io.h> |
Kumar Gala | b7c3ccf | 2010-04-20 10:02:24 -0500 | [diff] [blame] | 14 | #include <asm/fsl_mpc83xx_serdes.h> |
Jean-Christophe PLAGNIOL-VILLARD | 5fc8a4b | 2008-04-02 13:41:21 +0200 | [diff] [blame] | 15 | #include <fdt_support.h> |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 16 | #include <spd_sdram.h> |
Timur Tabi | 3e1d49a | 2008-02-08 13:15:55 -0600 | [diff] [blame] | 17 | #include <vsc7385.h> |
Anton Vorontsov | 3628a93 | 2009-06-10 00:25:30 +0400 | [diff] [blame] | 18 | #include <fsl_esdhc.h> |
Timur Tabi | 3e1d49a | 2008-02-08 13:15:55 -0600 | [diff] [blame] | 19 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 22 | #if defined(CONFIG_SYS_DRAM_TEST) |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 23 | int |
| 24 | testdram(void) |
| 25 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 26 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
| 27 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 28 | uint *p; |
| 29 | |
| 30 | printf("Testing DRAM from 0x%08x to 0x%08x\n", |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 31 | CONFIG_SYS_MEMTEST_START, |
| 32 | CONFIG_SYS_MEMTEST_END); |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 33 | |
| 34 | printf("DRAM test phase 1:\n"); |
| 35 | for (p = pstart; p < pend; p++) |
| 36 | *p = 0xaaaaaaaa; |
| 37 | |
| 38 | for (p = pstart; p < pend; p++) { |
| 39 | if (*p != 0xaaaaaaaa) { |
| 40 | printf("DRAM test fails at: %08x\n", (uint) p); |
| 41 | return 1; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | printf("DRAM test phase 2:\n"); |
| 46 | for (p = pstart; p < pend; p++) |
| 47 | *p = 0x55555555; |
| 48 | |
| 49 | for (p = pstart; p < pend; p++) { |
| 50 | if (*p != 0x55555555) { |
| 51 | printf("DRAM test fails at: %08x\n", (uint) p); |
| 52 | return 1; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | printf("DRAM test passed.\n"); |
| 57 | return 0; |
| 58 | } |
| 59 | #endif |
| 60 | |
Peter Tyser | cb4731f | 2009-06-30 17:15:50 -0500 | [diff] [blame] | 61 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 62 | void ddr_enable_ecc(unsigned int dram_size); |
| 63 | #endif |
| 64 | int fixed_sdram(void); |
| 65 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 66 | int dram_init(void) |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 67 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 69 | u32 msize = 0; |
| 70 | |
| 71 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 72 | return -ENXIO; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 73 | |
| 74 | #if defined(CONFIG_SPD_EEPROM) |
| 75 | msize = spd_sdram(); |
| 76 | #else |
| 77 | msize = fixed_sdram(); |
| 78 | #endif |
| 79 | |
Peter Tyser | cb4731f | 2009-06-30 17:15:50 -0500 | [diff] [blame] | 80 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 81 | /* Initialize DDR ECC byte */ |
| 82 | ddr_enable_ecc(msize * 1024 * 1024); |
| 83 | #endif |
| 84 | /* return total bus DDR size(bytes) */ |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 85 | gd->ram_size = msize * 1024 * 1024; |
| 86 | |
| 87 | return 0; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | #if !defined(CONFIG_SPD_EEPROM) |
| 91 | /************************************************************************* |
| 92 | * fixed sdram init -- doesn't use serial presence detect. |
| 93 | ************************************************************************/ |
| 94 | int fixed_sdram(void) |
| 95 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 96 | immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
| 97 | u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 98 | u32 msize_log2 = __ilog2(msize); |
| 99 | |
Mario Six | 805cac1 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 100 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 101 | im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); |
| 102 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 104 | udelay(50000); |
| 105 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 107 | udelay(1000); |
| 108 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 109 | im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 110 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 111 | udelay(1000); |
| 112 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 114 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 115 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 116 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 117 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
| 118 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 119 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
| 120 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
| 121 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 122 | sync(); |
| 123 | udelay(1000); |
| 124 | |
| 125 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 126 | udelay(2000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 127 | return CONFIG_SYS_DDR_SIZE; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 128 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 129 | #endif /*!CONFIG_SYS_SPD_EEPROM */ |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 130 | |
| 131 | int checkboard(void) |
| 132 | { |
| 133 | puts("Board: Freescale MPC837xERDB\n"); |
| 134 | return 0; |
| 135 | } |
| 136 | |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 137 | int board_early_init_f(void) |
| 138 | { |
| 139 | #ifdef CONFIG_FSL_SERDES |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 141 | u32 spridr = in_be32(&immr->sysconf.spridr); |
| 142 | |
| 143 | /* we check only part num, and don't look for CPU revisions */ |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 144 | switch (PARTID_NO_E(spridr)) { |
| 145 | case SPR_8377: |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 146 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
| 147 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 148 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 149 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 150 | break; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 151 | case SPR_8378: |
Anton Vorontsov | 642016b | 2008-10-02 18:31:53 +0400 | [diff] [blame] | 152 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 153 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 154 | break; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 155 | case SPR_8379: |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 156 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
| 157 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 158 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA, |
Anton Vorontsov | 2b3c004 | 2008-03-24 17:40:43 +0300 | [diff] [blame] | 159 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 160 | break; |
| 161 | default: |
| 162 | printf("serdes not configured: unknown CPU part number: " |
| 163 | "%04x\n", spridr >> 16); |
| 164 | break; |
| 165 | } |
| 166 | #endif /* CONFIG_FSL_SERDES */ |
| 167 | return 0; |
| 168 | } |
| 169 | |
Anton Vorontsov | 3628a93 | 2009-06-10 00:25:30 +0400 | [diff] [blame] | 170 | #ifdef CONFIG_FSL_ESDHC |
| 171 | int board_mmc_init(bd_t *bd) |
| 172 | { |
| 173 | struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR; |
Sinan Akman | 8dc24e0 | 2015-01-20 20:47:01 -0500 | [diff] [blame] | 174 | char buffer[HWCONFIG_BUFFER_SIZE] = {0}; |
| 175 | int esdhc_hwconfig_enabled = 0; |
| 176 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 177 | if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0) |
Sinan Akman | 8dc24e0 | 2015-01-20 20:47:01 -0500 | [diff] [blame] | 178 | esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer); |
Anton Vorontsov | 3628a93 | 2009-06-10 00:25:30 +0400 | [diff] [blame] | 179 | |
Sinan Akman | 8dc24e0 | 2015-01-20 20:47:01 -0500 | [diff] [blame] | 180 | if (esdhc_hwconfig_enabled == 0) |
Anton Vorontsov | 3628a93 | 2009-06-10 00:25:30 +0400 | [diff] [blame] | 181 | return 0; |
| 182 | |
| 183 | clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD); |
| 184 | clrsetbits_be32(&im->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD); |
| 185 | |
| 186 | return fsl_esdhc_mmc_init(bd); |
| 187 | } |
| 188 | #endif |
| 189 | |
Timur Tabi | 3e1d49a | 2008-02-08 13:15:55 -0600 | [diff] [blame] | 190 | /* |
| 191 | * Miscellaneous late-boot configurations |
| 192 | * |
| 193 | * If a VSC7385 microcode image is present, then upload it. |
| 194 | */ |
| 195 | int misc_init_r(void) |
| 196 | { |
| 197 | int rc = 0; |
| 198 | |
| 199 | #ifdef CONFIG_VSC7385_IMAGE |
| 200 | if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE, |
| 201 | CONFIG_VSC7385_IMAGE_SIZE)) { |
| 202 | puts("Failure uploading VSC7385 microcode.\n"); |
| 203 | rc = 1; |
| 204 | } |
| 205 | #endif |
| 206 | |
| 207 | return rc; |
| 208 | } |
| 209 | |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 210 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 211 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 212 | int ft_board_setup(void *blob, bd_t *bd) |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 213 | { |
| 214 | #ifdef CONFIG_PCI |
| 215 | ft_pci_setup(blob, bd); |
| 216 | #endif |
| 217 | ft_cpu_setup(blob, bd); |
Sriram Dash | 9fd465c | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 218 | fsl_fdt_fixup_dr_usb(blob, bd); |
Anton Vorontsov | 3628a93 | 2009-06-10 00:25:30 +0400 | [diff] [blame] | 219 | fdt_fixup_esdhc(blob, bd); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 220 | |
| 221 | return 0; |
Kim Phillips | 1cb07e6 | 2008-01-16 00:38:05 -0600 | [diff] [blame] | 222 | } |
| 223 | #endif /* CONFIG_OF_BOARD_SETUP */ |