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> |
| 25 | |
| 26 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 27 | #include <libfdt.h> |
| 28 | #endif |
| 29 | |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 30 | extern int ivm_read_eeprom (void); |
| 31 | |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | const uint sdram_table[] = |
| 35 | { |
| 36 | 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x0ff77c00, |
| 37 | 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 38 | /* 0x08 Burst Read */ |
| 39 | 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00, |
| 40 | 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05, |
| 41 | /* 0x10 Load mode register */ |
| 42 | 0x0ffffc34, 0x0ff57c04, 0x0ffffc04, 0x1ffffc05, |
| 43 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 44 | /* 0x18 Single Write */ |
| 45 | 0x0f07fc04, 0x0ffffc00, 0x00bd7c04, 0x0ffffc04, |
| 46 | 0x0ff77c04, 0x1ffffc05, 0xfffffc04, 0xfffffc04, |
| 47 | /* 0x20 Burst Write */ |
| 48 | 0x0f07fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00, |
| 49 | 0x00fffc00, 0x00fffc04, 0x0ffffc04, 0x0ff77c04, |
| 50 | 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 51 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 52 | /* 0x30 Precharge all and Refresh */ |
| 53 | 0x0ff77c04, 0x0ffffc04, 0x0ff5fc84, 0x0ffffc04, |
| 54 | 0x0ffffc04, 0x0ffffc84, 0x1ffffc05, 0xfffffc04, |
| 55 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 56 | /* 0x3C Exception */ |
| 57 | 0x7ffffc04, 0xfffffc07, 0xfffffc04, 0xfffffc04, |
| 58 | }; |
| 59 | |
| 60 | int checkboard (void) |
| 61 | { |
| 62 | puts ("Board: Keymile mgsuvd\n"); |
| 63 | return (0); |
| 64 | } |
| 65 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 66 | phys_size_t initdram (int board_type) |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 67 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 69 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 70 | long int size; |
| 71 | |
| 72 | upmconfig (UPMB, (uint *) sdram_table, |
| 73 | sizeof (sdram_table) / sizeof (uint)); |
| 74 | |
| 75 | /* |
| 76 | * Preliminary prescaler for refresh (depends on number of |
| 77 | * banks): This value is selected for four cycles every 62.4 us |
| 78 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 79 | * bank. It will be adjusted after memory sizing. |
| 80 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * The following value is used as an address (i.e. opcode) for |
| 85 | * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If |
| 86 | * the port size is 32bit the SDRAM does NOT "see" the lower two |
| 87 | * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for |
| 88 | * MICRON SDRAMs: |
| 89 | * -> 0 00 010 0 010 |
| 90 | * | | | | +- Burst Length = 4 |
| 91 | * | | | +----- Burst Type = Sequential |
| 92 | * | | +------- CAS Latency = 2 |
| 93 | * | +----------- Operating Mode = Standard |
| 94 | * +-------------- Write Burst Mode = Programmed Burst Length |
| 95 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 96 | memctl->memc_mar = CONFIG_SYS_MAR; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Map controller banks 1 to the SDRAM banks 1 at |
| 100 | * preliminary addresses - these have to be modified after the |
| 101 | * SDRAM size has been determined. |
| 102 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM; |
| 104 | memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM; |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 105 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | memctl->memc_mbmr = CONFIG_SYS_MBMR & (~(MBMR_PTBE)); /* no refresh yet */ |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 107 | |
| 108 | udelay (200); |
| 109 | |
| 110 | /* perform SDRAM initializsation sequence */ |
| 111 | |
| 112 | memctl->memc_mcr = 0x80802830; /* SDRAM bank 0 */ |
| 113 | udelay (1); |
| 114 | memctl->memc_mcr = 0x80802110; /* SDRAM bank 0 - execute twice */ |
| 115 | udelay (1); |
| 116 | |
| 117 | memctl->memc_mbmr |= MBMR_PTBE; /* enable refresh */ |
| 118 | |
| 119 | udelay (1000); |
| 120 | |
| 121 | /* |
| 122 | * Check Bank 0 Memory Size for re-configuration |
| 123 | * |
| 124 | */ |
| 125 | size = get_ram_size(SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE); |
| 126 | |
| 127 | udelay (1000); |
| 128 | |
| 129 | debug ("SDRAM Bank 0: %ld MB\n", size >> 20); |
| 130 | |
| 131 | return (size); |
| 132 | } |
| 133 | |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 134 | /* |
| 135 | * Early board initalization. |
| 136 | */ |
| 137 | int board_early_init_r(void) |
| 138 | { |
| 139 | /* setup the UPIOx */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | *(char *)(CONFIG_SYS_PIGGY_BASE + 0x02) = 0xc0; |
| 141 | *(char *)(CONFIG_SYS_PIGGY_BASE + 0x03) = 0x35; |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Heiko Schocher | 8f64da7 | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 145 | int hush_init_var (void) |
| 146 | { |
| 147 | ivm_read_eeprom (); |
| 148 | return 0; |
| 149 | } |
| 150 | |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 151 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 152 | /* |
| 153 | * update "memory" property in the blob |
| 154 | */ |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 155 | void ft_blob_update (void *blob, bd_t *bd) |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 156 | { |
| 157 | int ret, nodeoffset = 0; |
| 158 | ulong brg_data[1] = {0}; |
| 159 | ulong memory_data[2] = {0}; |
| 160 | ulong flash_data[4] = {0}; |
| 161 | |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 162 | memory_data[0] = cpu_to_be32 (bd->bi_memstart); |
| 163 | memory_data[1] = cpu_to_be32 (bd->bi_memsize); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 164 | |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 165 | nodeoffset = fdt_path_offset (blob, "/memory"); |
| 166 | if (nodeoffset >= 0) { |
| 167 | ret = fdt_setprop (blob, nodeoffset, "reg", memory_data, |
| 168 | sizeof (memory_data)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 169 | if (ret < 0) |
Matvejchikov Ilya | 2726941 | 2008-07-06 13:57:58 +0400 | [diff] [blame] | 170 | printf("ft_blob_update(): cannot set /memory/reg " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 171 | "property err:%s\n", fdt_strerror (ret)); |
| 172 | } else { |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 173 | /* memory node is required in dts */ |
| 174 | printf("ft_blob_update(): cannot find /memory node " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 175 | "err:%s\n", fdt_strerror (nodeoffset)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 178 | flash_data[2] = cpu_to_be32 (bd->bi_flashstart); |
| 179 | flash_data[3] = cpu_to_be32 (bd->bi_flashsize); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 180 | nodeoffset = fdt_path_offset (blob, "/localbus"); |
| 181 | if (nodeoffset >= 0) { |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 182 | ret = fdt_setprop (blob, nodeoffset, "ranges", flash_data, |
| 183 | sizeof (flash_data)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 184 | if (ret < 0) |
Matvejchikov Ilya | 2726941 | 2008-07-06 13:57:58 +0400 | [diff] [blame] | 185 | printf("ft_blob_update(): cannot set /localbus/ranges " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 186 | "property err:%s\n", fdt_strerror (ret)); |
| 187 | } else { |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 188 | /* memory node is required in dts */ |
| 189 | printf("ft_blob_update(): cannot find /localbus node " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 190 | "err:%s\n", fdt_strerror (nodeoffset)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 191 | } |
| 192 | /* BRG */ |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 193 | brg_data[0] = cpu_to_be32 (bd->bi_busfreq); |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 194 | nodeoffset = fdt_path_offset (blob, "/soc/cpm"); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 195 | if (nodeoffset >= 0) { |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 196 | ret = fdt_setprop (blob, nodeoffset, "brg-frequency", brg_data, |
| 197 | sizeof (brg_data)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 198 | if (ret < 0) |
Matvejchikov Ilya | 2726941 | 2008-07-06 13:57:58 +0400 | [diff] [blame] | 199 | printf("ft_blob_update(): cannot set /soc/cpm/brg-frequency " |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 200 | "property err:%s\n", fdt_strerror(ret)); |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 201 | } else { |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 202 | /* memory node is required in dts */ |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 203 | printf("ft_blob_update(): cannot find /soc/cpm node " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 204 | "err:%s\n", fdt_strerror (nodeoffset)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 205 | } |
| 206 | /* MAC Adresse */ |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 207 | nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet"); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 208 | if (nodeoffset >= 0) { |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 209 | ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr, |
| 210 | sizeof (uchar) * 6); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 211 | if (ret < 0) |
Matvejchikov Ilya | 2726941 | 2008-07-06 13:57:58 +0400 | [diff] [blame] | 212 | printf("ft_blob_update(): cannot set /soc/cpm/scc/mac-address " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 213 | "property err:%s\n", fdt_strerror (ret)); |
| 214 | } else { |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 215 | /* memory node is required in dts */ |
Heiko Schocher | 82afabf | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 216 | printf("ft_blob_update(): cannot find /soc/cpm/ethernet node " |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 217 | "err:%s\n", fdt_strerror (nodeoffset)); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
| 221 | void ft_board_setup(void *blob, bd_t *bd) |
| 222 | { |
Heiko Schocher | cac9cf7 | 2008-10-17 12:15:05 +0200 | [diff] [blame^] | 223 | ft_cpu_setup (blob, bd); |
| 224 | ft_blob_update (blob, bd); |
Heiko Schocher | 381e4e6 | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 225 | } |
| 226 | #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */ |
Heiko Schocher | 9661bf9 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 227 | |
| 228 | int i2c_soft_read_pin (void) |
| 229 | { |
| 230 | int val; |
| 231 | |
| 232 | *(unsigned short *)(I2C_BASE_DIR) &= ~SDA_CONF; |
| 233 | udelay(1); |
| 234 | val = *(unsigned char *)(I2C_BASE_PORT); |
| 235 | |
| 236 | return ((val & SDA_BIT) == SDA_BIT); |
| 237 | } |