Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 23 | #include <common.h> |
| 24 | #include <mpc8xx.h> |
Heiko Schocher | 9e29919 | 2008-10-17 12:15:55 +0200 | [diff] [blame] | 25 | #include <asm/io.h> |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 26 | |
| 27 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 28 | #include <libfdt.h> |
| 29 | #endif |
| 30 | |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 31 | extern int ivm_read_eeprom (void); |
| 32 | |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | const uint sdram_table[] = |
| 36 | { |
| 37 | 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x0ff77c00, |
| 38 | 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 39 | /* 0x08 Burst Read */ |
| 40 | 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00, |
| 41 | 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05, |
| 42 | /* 0x10 Load mode register */ |
| 43 | 0x0ffffc34, 0x0ff57c04, 0x0ffffc04, 0x1ffffc05, |
| 44 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 45 | /* 0x18 Single Write */ |
| 46 | 0x0f07fc04, 0x0ffffc00, 0x00bd7c04, 0x0ffffc04, |
| 47 | 0x0ff77c04, 0x1ffffc05, 0xfffffc04, 0xfffffc04, |
| 48 | /* 0x20 Burst Write */ |
| 49 | 0x0f07fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00, |
| 50 | 0x00fffc00, 0x00fffc04, 0x0ffffc04, 0x0ff77c04, |
| 51 | 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 52 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 53 | /* 0x30 Precharge all and Refresh */ |
| 54 | 0x0ff77c04, 0x0ffffc04, 0x0ff5fc84, 0x0ffffc04, |
| 55 | 0x0ffffc04, 0x0ffffc84, 0x1ffffc05, 0xfffffc04, |
| 56 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 57 | /* 0x3C Exception */ |
| 58 | 0x7ffffc04, 0xfffffc07, 0xfffffc04, 0xfffffc04, |
| 59 | }; |
| 60 | |
| 61 | int checkboard (void) |
| 62 | { |
| 63 | puts ("Board: Keymile mgsuvd\n"); |
| 64 | return (0); |
| 65 | } |
| 66 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 67 | phys_size_t initdram (int board_type) |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 68 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 69 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 70 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 71 | long int size; |
| 72 | |
| 73 | upmconfig (UPMB, (uint *) sdram_table, |
| 74 | sizeof (sdram_table) / sizeof (uint)); |
| 75 | |
| 76 | /* |
| 77 | * Preliminary prescaler for refresh (depends on number of |
| 78 | * banks): This value is selected for four cycles every 62.4 us |
| 79 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 80 | * bank. It will be adjusted after memory sizing. |
| 81 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 82 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * The following value is used as an address (i.e. opcode) for |
| 86 | * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If |
| 87 | * the port size is 32bit the SDRAM does NOT "see" the lower two |
| 88 | * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for |
| 89 | * MICRON SDRAMs: |
| 90 | * -> 0 00 010 0 010 |
| 91 | * | | | | +- Burst Length = 4 |
| 92 | * | | | +----- Burst Type = Sequential |
| 93 | * | | +------- CAS Latency = 2 |
| 94 | * | +----------- Operating Mode = Standard |
| 95 | * +-------------- Write Burst Mode = Programmed Burst Length |
| 96 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | memctl->memc_mar = CONFIG_SYS_MAR; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Map controller banks 1 to the SDRAM banks 1 at |
| 101 | * preliminary addresses - these have to be modified after the |
| 102 | * SDRAM size has been determined. |
| 103 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM; |
| 105 | memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 106 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 107 | memctl->memc_mbmr = CONFIG_SYS_MBMR & (~(MBMR_PTBE)); /* no refresh yet */ |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 108 | |
| 109 | udelay (200); |
| 110 | |
| 111 | /* perform SDRAM initializsation sequence */ |
| 112 | |
| 113 | memctl->memc_mcr = 0x80802830; /* SDRAM bank 0 */ |
| 114 | udelay (1); |
| 115 | memctl->memc_mcr = 0x80802110; /* SDRAM bank 0 - execute twice */ |
| 116 | udelay (1); |
| 117 | |
| 118 | memctl->memc_mbmr |= MBMR_PTBE; /* enable refresh */ |
| 119 | |
| 120 | udelay (1000); |
| 121 | |
| 122 | /* |
| 123 | * Check Bank 0 Memory Size for re-configuration |
| 124 | * |
| 125 | */ |
| 126 | size = get_ram_size(SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE); |
| 127 | |
| 128 | udelay (1000); |
| 129 | |
| 130 | debug ("SDRAM Bank 0: %ld MB\n", size >> 20); |
| 131 | |
| 132 | return (size); |
| 133 | } |
| 134 | |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 135 | /* |
| 136 | * Early board initalization. |
| 137 | */ |
| 138 | int board_early_init_r(void) |
| 139 | { |
| 140 | /* setup the UPIOx */ |
Heiko Schocher | 9e29919 | 2008-10-17 12:15:55 +0200 | [diff] [blame] | 141 | out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x02), 0xc0); |
| 142 | out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x03), 0x35); |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 146 | int hush_init_var (void) |
| 147 | { |
| 148 | ivm_read_eeprom (); |
| 149 | return 0; |
| 150 | } |
| 151 | |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 152 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 153 | extern int fdt_set_node_and_value (void *blob, |
| 154 | char *nodename, |
| 155 | char *regname, |
| 156 | void *var, |
| 157 | int size); |
| 158 | |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 159 | /* |
| 160 | * update "memory" property in the blob |
| 161 | */ |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 162 | void ft_blob_update (void *blob, bd_t *bd) |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 163 | { |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 164 | ulong brg_data[1] = {0}; |
| 165 | ulong memory_data[2] = {0}; |
| 166 | ulong flash_data[4] = {0}; |
| 167 | |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 168 | memory_data[0] = cpu_to_be32 (bd->bi_memstart); |
| 169 | memory_data[1] = cpu_to_be32 (bd->bi_memsize); |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 170 | fdt_set_node_and_value (blob, "/memory", "reg", memory_data, |
| 171 | sizeof (memory_data)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 172 | |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 173 | flash_data[2] = cpu_to_be32 (bd->bi_flashstart); |
| 174 | flash_data[3] = cpu_to_be32 (bd->bi_flashsize); |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 175 | fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data, |
| 176 | sizeof (flash_data)); |
| 177 | |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 178 | /* BRG */ |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 179 | brg_data[0] = cpu_to_be32 (bd->bi_busfreq); |
Heiko Schocher | 6250f0f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 180 | fdt_set_node_and_value (blob, "/soc/cpm", "brg-frequency", brg_data, |
| 181 | sizeof (brg_data)); |
| 182 | |
| 183 | /* MAC adr */ |
| 184 | fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address", |
| 185 | bd->bi_enetaddr, sizeof (u8) * 6); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void ft_board_setup(void *blob, bd_t *bd) |
| 189 | { |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 190 | ft_cpu_setup (blob, bd); |
| 191 | ft_blob_update (blob, bd); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 192 | } |
| 193 | #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */ |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 194 | |
| 195 | int i2c_soft_read_pin (void) |
| 196 | { |
| 197 | int val; |
| 198 | |
| 199 | *(unsigned short *)(I2C_BASE_DIR) &= ~SDA_CONF; |
| 200 | udelay(1); |
| 201 | val = *(unsigned char *)(I2C_BASE_PORT); |
| 202 | |
| 203 | return ((val & SDA_BIT) == SDA_BIT); |
| 204 | } |