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