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