Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 3 | * Dave Liu <daveliu@freescale.com> |
| 4 | * |
| 5 | * CREDITS: Kim Phillips contribute to LIBFDT code |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <i2c.h> |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/fsl_serdes.h> |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 17 | #include <spd_sdram.h> |
Kim Phillips | 3204c7c | 2007-12-20 15:57:28 -0600 | [diff] [blame] | 18 | #if defined(CONFIG_OF_LIBFDT) |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 19 | #include <libfdt.h> |
| 20 | #endif |
| 21 | #if defined(CONFIG_PQ_MDS_PIB) |
| 22 | #include "../common/pq-mds-pib.h" |
| 23 | #endif |
| 24 | |
| 25 | int board_early_init_f(void) |
| 26 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | u8 *bcsr = (u8 *)CONFIG_SYS_BCSR; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 28 | |
| 29 | /* Enable flash write */ |
| 30 | bcsr[0x9] &= ~0x04; |
| 31 | /* Clear all of the interrupt of BCSR */ |
| 32 | bcsr[0xe] = 0xff; |
| 33 | |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 34 | #ifdef CONFIG_FSL_SERDES |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 35 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 36 | u32 spridr = in_be32(&immr->sysconf.spridr); |
| 37 | |
| 38 | /* we check only part num, and don't look for CPU revisions */ |
Dave Liu | 1f2f86e | 2008-03-31 17:05:12 +0800 | [diff] [blame] | 39 | switch (PARTID_NO_E(spridr)) { |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 40 | case SPR_8377: |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 41 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
| 42 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 43 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 44 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 45 | break; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 46 | case SPR_8378: |
Anton Vorontsov | 642016b | 2008-10-02 18:31:53 +0400 | [diff] [blame^] | 47 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 48 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 49 | break; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 50 | case SPR_8379: |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 51 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
| 52 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 53 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA, |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 54 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 55 | break; |
| 56 | default: |
| 57 | printf("serdes not configured: unknown CPU part number: " |
| 58 | "%04x\n", spridr >> 16); |
| 59 | break; |
| 60 | } |
| 61 | #endif /* CONFIG_FSL_SERDES */ |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | int board_early_init_r(void) |
| 66 | { |
| 67 | #ifdef CONFIG_PQ_MDS_PIB |
| 68 | pib_init(); |
| 69 | #endif |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
| 74 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 75 | #endif |
| 76 | int fixed_sdram(void); |
| 77 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 78 | phys_size_t initdram(int board_type) |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 79 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 80 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 81 | u32 msize = 0; |
| 82 | |
| 83 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
| 84 | return -1; |
| 85 | |
| 86 | #if defined(CONFIG_SPD_EEPROM) |
| 87 | msize = spd_sdram(); |
| 88 | #else |
| 89 | msize = fixed_sdram(); |
| 90 | #endif |
| 91 | |
| 92 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
| 93 | /* Initialize DDR ECC byte */ |
| 94 | ddr_enable_ecc(msize * 1024 * 1024); |
| 95 | #endif |
| 96 | |
| 97 | /* return total bus DDR size(bytes) */ |
| 98 | return (msize * 1024 * 1024); |
| 99 | } |
| 100 | |
| 101 | #if !defined(CONFIG_SPD_EEPROM) |
| 102 | /************************************************************************* |
| 103 | * fixed sdram init -- doesn't use serial presence detect. |
| 104 | ************************************************************************/ |
| 105 | int fixed_sdram(void) |
| 106 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 107 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
| 108 | u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 109 | u32 msize_log2 = __ilog2(msize); |
| 110 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 111 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 112 | im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); |
| 113 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 114 | #if (CONFIG_SYS_DDR_SIZE != 512) |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 115 | #warning Currenly any ddr size other than 512 is not supported |
| 116 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 118 | udelay(50000); |
| 119 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 121 | udelay(1000); |
| 122 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 123 | im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 124 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 125 | udelay(1000); |
| 126 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 127 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 128 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 129 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 130 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 131 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
| 132 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 133 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
| 134 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
| 135 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 136 | __asm__ __volatile__("sync"); |
| 137 | udelay(1000); |
| 138 | |
| 139 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 140 | udelay(2000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 141 | return CONFIG_SYS_DDR_SIZE; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 142 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 143 | #endif /*!CONFIG_SYS_SPD_EEPROM */ |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 144 | |
| 145 | int checkboard(void) |
| 146 | { |
| 147 | puts("Board: Freescale MPC837xEMDS\n"); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 152 | void ft_board_setup(void *blob, bd_t *bd) |
| 153 | { |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 154 | ft_cpu_setup(blob, bd); |
| 155 | #ifdef CONFIG_PCI |
| 156 | ft_pci_setup(blob, bd); |
| 157 | #endif |
| 158 | } |
| 159 | #endif /* CONFIG_OF_BOARD_SETUP */ |