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