Heiko Schocher | 30c0feb | 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 | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 23 | #include <common.h> |
| 24 | #include <mpc8xx.h> |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 25 | #include <net.h> |
Heiko Schocher | 012a95f | 2008-10-17 12:15:55 +0200 | [diff] [blame] | 26 | #include <asm/io.h> |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 27 | |
| 28 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 29 | #include <libfdt.h> |
| 30 | #endif |
| 31 | |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 32 | #include "../common/common.h" |
Heiko Schocher | e5b6c2e | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 33 | |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | const uint sdram_table[] = |
| 37 | { |
| 38 | 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x0ff77c00, |
| 39 | 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 40 | /* 0x08 Burst Read */ |
| 41 | 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00, |
| 42 | 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05, |
| 43 | /* 0x10 Load mode register */ |
| 44 | 0x0ffffc34, 0x0ff57c04, 0x0ffffc04, 0x1ffffc05, |
| 45 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 46 | /* 0x18 Single Write */ |
| 47 | 0x0f07fc04, 0x0ffffc00, 0x00bd7c04, 0x0ffffc04, |
| 48 | 0x0ff77c04, 0x1ffffc05, 0xfffffc04, 0xfffffc04, |
| 49 | /* 0x20 Burst Write */ |
| 50 | 0x0f07fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00, |
| 51 | 0x00fffc00, 0x00fffc04, 0x0ffffc04, 0x0ff77c04, |
| 52 | 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 53 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 54 | /* 0x30 Precharge all and Refresh */ |
| 55 | 0x0ff77c04, 0x0ffffc04, 0x0ff5fc84, 0x0ffffc04, |
| 56 | 0x0ffffc04, 0x0ffffc84, 0x1ffffc05, 0xfffffc04, |
| 57 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 58 | /* 0x3C Exception */ |
| 59 | 0x7ffffc04, 0xfffffc07, 0xfffffc04, 0xfffffc04, |
| 60 | }; |
| 61 | |
| 62 | int checkboard (void) |
| 63 | { |
Heiko Schocher | 643e7c0 | 2009-03-12 07:37:34 +0100 | [diff] [blame] | 64 | puts ("Board: Keymile "); |
| 65 | #if defined(CONFIG_KMSUPX4) |
| 66 | puts ("kmsupx4"); |
| 67 | #else |
| 68 | puts ("mgsuvd"); |
| 69 | #endif |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 70 | if (ethernet_present ()) |
| 71 | puts (" with PIGGY."); |
| 72 | puts ("\n"); |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 73 | return (0); |
| 74 | } |
| 75 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 76 | phys_size_t initdram (int board_type) |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 77 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 79 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 80 | long int size; |
| 81 | |
| 82 | upmconfig (UPMB, (uint *) sdram_table, |
| 83 | sizeof (sdram_table) / sizeof (uint)); |
| 84 | |
| 85 | /* |
| 86 | * Preliminary prescaler for refresh (depends on number of |
| 87 | * banks): This value is selected for four cycles every 62.4 us |
| 88 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 89 | * bank. It will be adjusted after memory sizing. |
| 90 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * The following value is used as an address (i.e. opcode) for |
| 95 | * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If |
| 96 | * the port size is 32bit the SDRAM does NOT "see" the lower two |
| 97 | * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for |
| 98 | * MICRON SDRAMs: |
| 99 | * -> 0 00 010 0 010 |
| 100 | * | | | | +- Burst Length = 4 |
| 101 | * | | | +----- Burst Type = Sequential |
| 102 | * | | +------- CAS Latency = 2 |
| 103 | * | +----------- Operating Mode = Standard |
| 104 | * +-------------- Write Burst Mode = Programmed Burst Length |
| 105 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | memctl->memc_mar = CONFIG_SYS_MAR; |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 107 | |
| 108 | /* |
| 109 | * Map controller banks 1 to the SDRAM banks 1 at |
| 110 | * preliminary addresses - these have to be modified after the |
| 111 | * SDRAM size has been determined. |
| 112 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM; |
| 114 | memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM; |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 115 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 116 | memctl->memc_mbmr = CONFIG_SYS_MBMR & (~(MBMR_PTBE)); /* no refresh yet */ |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 117 | |
| 118 | udelay (200); |
| 119 | |
| 120 | /* perform SDRAM initializsation sequence */ |
| 121 | |
| 122 | memctl->memc_mcr = 0x80802830; /* SDRAM bank 0 */ |
| 123 | udelay (1); |
| 124 | memctl->memc_mcr = 0x80802110; /* SDRAM bank 0 - execute twice */ |
| 125 | udelay (1); |
| 126 | |
| 127 | memctl->memc_mbmr |= MBMR_PTBE; /* enable refresh */ |
| 128 | |
| 129 | udelay (1000); |
| 130 | |
| 131 | /* |
| 132 | * Check Bank 0 Memory Size for re-configuration |
| 133 | * |
| 134 | */ |
| 135 | size = get_ram_size(SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE); |
| 136 | |
| 137 | udelay (1000); |
| 138 | |
| 139 | debug ("SDRAM Bank 0: %ld MB\n", size >> 20); |
| 140 | |
| 141 | return (size); |
| 142 | } |
| 143 | |
Heiko Schocher | f72af11 | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 144 | /* |
| 145 | * Early board initalization. |
| 146 | */ |
| 147 | int board_early_init_r(void) |
| 148 | { |
| 149 | /* setup the UPIOx */ |
Heiko Schocher | 2f6ea29 | 2010-01-07 08:55:50 +0100 | [diff] [blame] | 150 | /* General Unit Reset disabled, Flash Bank enabled, UnitLed on */ |
| 151 | out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x02), 0xc2); |
| 152 | /* SCC4 enable, halfduplex, FCC1 powerdown, ANDI enable*/ |
Heiko Schocher | 012a95f | 2008-10-17 12:15:55 +0200 | [diff] [blame] | 153 | out_8((u8 *)(CONFIG_SYS_PIGGY_BASE + 0x03), 0x35); |
Heiko Schocher | f72af11 | 2008-03-07 08:15:28 +0100 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
Heiko Schocher | e5b6c2e | 2008-10-15 09:41:00 +0200 | [diff] [blame] | 157 | int hush_init_var (void) |
| 158 | { |
| 159 | ivm_read_eeprom (); |
| 160 | return 0; |
| 161 | } |
| 162 | |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 163 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
| 164 | /* |
Heiko Schocher | 2f6ea29 | 2010-01-07 08:55:50 +0100 | [diff] [blame] | 165 | * update "brg" property in the blob |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 166 | */ |
Heiko Schocher | 997f523 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 167 | void ft_blob_update (void *blob, bd_t *bd) |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 168 | { |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 169 | ulong brg_data[1] = {0}; |
Heiko Schocher | 1eedd3f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 170 | |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 171 | /* BRG */ |
Heiko Schocher | 997f523 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 172 | brg_data[0] = cpu_to_be32 (bd->bi_busfreq); |
Heiko Schocher | 1eedd3f | 2008-10-17 16:11:52 +0200 | [diff] [blame] | 173 | fdt_set_node_and_value (blob, "/soc/cpm", "brg-frequency", brg_data, |
| 174 | sizeof (brg_data)); |
| 175 | |
| 176 | /* MAC adr */ |
| 177 | fdt_set_node_and_value (blob, "/soc/cpm/ethernet", "mac-address", |
Heiko Schocher | 875f4728 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 178 | bd->bi_enetaddr, sizeof (u8) * 6); |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void ft_board_setup(void *blob, bd_t *bd) |
| 182 | { |
Heiko Schocher | 997f523 | 2008-10-17 12:15:05 +0200 | [diff] [blame] | 183 | ft_cpu_setup (blob, bd); |
| 184 | ft_blob_update (blob, bd); |
Heiko Schocher | 30c0feb | 2008-01-11 01:12:06 +0100 | [diff] [blame] | 185 | } |
| 186 | #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */ |
Heiko Schocher | 65138e1 | 2008-10-15 09:36:03 +0200 | [diff] [blame] | 187 | |
| 188 | int i2c_soft_read_pin (void) |
| 189 | { |
| 190 | int val; |
| 191 | |
| 192 | *(unsigned short *)(I2C_BASE_DIR) &= ~SDA_CONF; |
| 193 | udelay(1); |
| 194 | val = *(unsigned char *)(I2C_BASE_PORT); |
| 195 | |
| 196 | return ((val & SDA_BIT) == SDA_BIT); |
| 197 | } |