Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Freescale Semiconductor, Inc. |
| 3 | * Dave Liu <daveliu@freescale.com> |
| 4 | * |
| 5 | * Copyright (C) 2007 Logic Product Development, Inc. |
| 6 | * Peter Barada <peterb@logicpd.com> |
| 7 | * |
| 8 | * Copyright (C) 2007 MontaVista Software, Inc. |
| 9 | * Anton Vorontsov <avorontsov@ru.mvista.com> |
| 10 | * |
| 11 | * (C) Copyright 2008 |
| 12 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | */ |
| 19 | |
| 20 | #include <common.h> |
| 21 | #include <ioports.h> |
| 22 | #include <mpc83xx.h> |
| 23 | #include <i2c.h> |
| 24 | #include <miiphy.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/mmu.h> |
Heiko Schocher | 5d87e45 | 2009-02-24 11:30:48 +0100 | [diff] [blame] | 27 | #include <asm/processor.h> |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 28 | #include <pci.h> |
| 29 | #include <libfdt.h> |
| 30 | |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 31 | #include "../common/common.h" |
| 32 | |
Heiko Schocher | 7b651bc | 2009-02-24 11:30:40 +0100 | [diff] [blame] | 33 | extern void disable_addr_trans (void); |
| 34 | extern void enable_addr_trans (void); |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 35 | const qe_iop_conf_t qe_iop_conf_tab[] = { |
| 36 | /* port pin dir open_drain assign */ |
| 37 | |
| 38 | /* MDIO */ |
| 39 | {0, 1, 3, 0, 2}, /* MDIO */ |
| 40 | {0, 2, 1, 0, 1}, /* MDC */ |
| 41 | |
| 42 | /* UCC4 - UEC */ |
| 43 | {1, 14, 1, 0, 1}, /* TxD0 */ |
| 44 | {1, 15, 1, 0, 1}, /* TxD1 */ |
| 45 | {1, 20, 2, 0, 1}, /* RxD0 */ |
| 46 | {1, 21, 2, 0, 1}, /* RxD1 */ |
| 47 | {1, 18, 1, 0, 1}, /* TX_EN */ |
| 48 | {1, 26, 2, 0, 1}, /* RX_DV */ |
| 49 | {1, 27, 2, 0, 1}, /* RX_ER */ |
| 50 | {1, 24, 2, 0, 1}, /* COL */ |
| 51 | {1, 25, 2, 0, 1}, /* CRS */ |
| 52 | {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */ |
| 53 | {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */ |
| 54 | |
| 55 | /* DUART - UART2 */ |
| 56 | {5, 0, 1, 0, 2}, /* UART2_SOUT */ |
| 57 | {5, 2, 1, 0, 1}, /* UART2_RTS */ |
| 58 | {5, 3, 2, 0, 2}, /* UART2_SIN */ |
| 59 | {5, 1, 2, 0, 3}, /* UART2_CTS */ |
| 60 | |
| 61 | /* END of table */ |
| 62 | {0, 0, 0, 0, QE_IOP_TAB_END}, |
| 63 | }; |
| 64 | |
Heiko Schocher | 4674318 | 2009-02-24 11:30:34 +0100 | [diff] [blame] | 65 | static int board_init_i2c_busses (void) |
| 66 | { |
| 67 | I2C_MUX_DEVICE *dev = NULL; |
| 68 | uchar *buf; |
| 69 | |
| 70 | /* Set up the Bus for the DTTs */ |
| 71 | buf = (unsigned char *) getenv ("dtt_bus"); |
| 72 | if (buf != NULL) |
| 73 | dev = i2c_mux_ident_muxstring (buf); |
| 74 | if (dev == NULL) { |
| 75 | printf ("Error couldn't add Bus for DTT\n"); |
| 76 | printf ("please setup dtt_bus to where your\n"); |
| 77 | printf ("DTT is found.\n"); |
| 78 | } |
| 79 | return 0; |
| 80 | } |
| 81 | |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 82 | int board_early_init_r (void) |
| 83 | { |
Heiko Schocher | 5d87e45 | 2009-02-24 11:30:48 +0100 | [diff] [blame] | 84 | unsigned short svid; |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * Because of errata in the UCCs, we have to write to the reserved |
| 88 | * registers to slow the clocks down. |
| 89 | */ |
Heiko Schocher | 5d87e45 | 2009-02-24 11:30:48 +0100 | [diff] [blame] | 90 | svid = SVR_REV(mfspr (SVR)); |
| 91 | switch (svid) { |
| 92 | case 0x0020: |
| 93 | setbits_be32((void *)(CONFIG_SYS_IMMR + 0x14a8), 0x0c003000); |
| 94 | break; |
| 95 | case 0x0021: |
| 96 | clrsetbits_be32((void *)(CONFIG_SYS_IMMR + 0x14ac), |
| 97 | 0x00000050, 0x000000a0); |
| 98 | break; |
| 99 | } |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 100 | /* enable the PHY on the PIGGY */ |
| 101 | setbits (8, (void *)(CONFIG_SYS_PIGGY_BASE + 0x10003), 0x01); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Heiko Schocher | 4674318 | 2009-02-24 11:30:34 +0100 | [diff] [blame] | 106 | int misc_init_r (void) |
| 107 | { |
| 108 | /* add board specific i2c busses */ |
| 109 | board_init_i2c_busses (); |
| 110 | return 0; |
| 111 | } |
| 112 | |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 113 | int fixed_sdram(void) |
| 114 | { |
| 115 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
| 116 | u32 msize = 0; |
| 117 | u32 ddr_size; |
| 118 | u32 ddr_size_log2; |
| 119 | |
Heiko Schocher | 7b651bc | 2009-02-24 11:30:40 +0100 | [diff] [blame] | 120 | im->sysconf.ddrlaw[0].ar = LAWAR_EN | 0x1e; |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 121 | im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 122 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
| 123 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 124 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 125 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 126 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 127 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
| 128 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 129 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
| 130 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
| 131 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
| 132 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL; |
| 133 | udelay (200); |
| 134 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 135 | |
Heiko Schocher | 7b651bc | 2009-02-24 11:30:40 +0100 | [diff] [blame] | 136 | msize = CONFIG_SYS_DDR_SIZE << 20; |
| 137 | disable_addr_trans (); |
| 138 | msize = get_ram_size (CONFIG_SYS_DDR_BASE, msize); |
| 139 | enable_addr_trans (); |
| 140 | msize /= (1024 * 1024); |
| 141 | if (CONFIG_SYS_DDR_SIZE != msize) { |
| 142 | for (ddr_size = msize << 20, ddr_size_log2 = 0; |
| 143 | (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) |
| 144 | if (ddr_size & 1) |
| 145 | return -1; |
| 146 | im->sysconf.ddrlaw[0].ar = |
| 147 | LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE); |
| 148 | im->ddr.csbnds[0].csbnds = (((msize / 16) - 1) & 0xff); |
| 149 | } |
| 150 | |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 151 | return msize; |
| 152 | } |
| 153 | |
| 154 | phys_size_t initdram (int board_type) |
| 155 | { |
Peter Tyser | cb4731f | 2009-06-30 17:15:50 -0500 | [diff] [blame] | 156 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 157 | extern void ddr_enable_ecc (unsigned int dram_size); |
| 158 | #endif |
| 159 | volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
| 160 | u32 msize = 0; |
| 161 | |
| 162 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) |
| 163 | return -1; |
| 164 | |
| 165 | /* DDR SDRAM - Main SODIMM */ |
| 166 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR; |
| 167 | msize = fixed_sdram (); |
| 168 | |
Peter Tyser | cb4731f | 2009-06-30 17:15:50 -0500 | [diff] [blame] | 169 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 170 | /* |
| 171 | * Initialize DDR ECC byte |
| 172 | */ |
| 173 | ddr_enable_ecc (msize * 1024 * 1024); |
| 174 | #endif |
| 175 | |
| 176 | /* return total bus SDRAM size(bytes) -- DDR */ |
| 177 | return (msize * 1024 * 1024); |
| 178 | } |
| 179 | |
| 180 | int checkboard (void) |
| 181 | { |
Heiko Schocher | d19a6ec | 2008-11-21 08:29:40 +0100 | [diff] [blame] | 182 | puts ("Board: Keymile kmeter1"); |
| 183 | if (ethernet_present ()) |
| 184 | puts (" with PIGGY."); |
| 185 | puts ("\n"); |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | #if defined(CONFIG_OF_BOARD_SETUP) |
Heiko Schocher | 875f4728 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 190 | /* |
| 191 | * update "/localbus/ranges" property in the blob |
| 192 | */ |
| 193 | void ft_blob_update (void *blob, bd_t *bd) |
| 194 | { |
| 195 | ulong *flash_data = NULL; |
| 196 | flash_info_t *info; |
| 197 | ulong flash_reg[6] = {0}; |
| 198 | int len; |
| 199 | int size = 0; |
| 200 | int i = 0; |
| 201 | |
| 202 | len = fdt_get_node_and_value (blob, "/localbus", "ranges", |
| 203 | (void *)&flash_data); |
| 204 | |
| 205 | if (flash_data == NULL) { |
| 206 | printf ("%s: error /localbus/ranges entry\n", __FUNCTION__); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | /* update Flash addr, size */ |
| 211 | while ( i < (len / 4)) { |
| 212 | switch (flash_data[i]) { |
| 213 | case 0: |
| 214 | info = flash_get_info(CONFIG_SYS_FLASH_BASE); |
| 215 | size = info->size; |
| 216 | info = flash_get_info(CONFIG_SYS_FLASH_BASE_1); |
| 217 | size += info->size; |
| 218 | flash_data[i + 1] = 0; |
| 219 | flash_data[i + 2] = cpu_to_be32 (CONFIG_SYS_FLASH_BASE); |
| 220 | flash_data[i + 3] = cpu_to_be32 (size); |
| 221 | break; |
| 222 | default: |
| 223 | break; |
| 224 | } |
| 225 | i += 4; |
| 226 | } |
| 227 | fdt_set_node_and_value (blob, "/localbus", "ranges", flash_data, |
| 228 | len); |
| 229 | |
| 230 | info = flash_get_info(CONFIG_SYS_FLASH_BASE); |
Heiko Schocher | 38c0a76 | 2009-07-28 14:53:44 +0200 | [diff] [blame] | 231 | size = info->size; |
Heiko Schocher | 875f4728 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 232 | flash_reg[2] = cpu_to_be32 (size); |
| 233 | flash_reg[4] = flash_reg[2]; |
| 234 | info = flash_get_info(CONFIG_SYS_FLASH_BASE_1); |
| 235 | flash_reg[5] = cpu_to_be32 (info->size); |
| 236 | fdt_set_node_and_value (blob, "/localbus/flash@f0000000,0", "reg", flash_reg, |
| 237 | sizeof (flash_reg)); |
| 238 | } |
| 239 | |
| 240 | |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 241 | void ft_board_setup (void *blob, bd_t *bd) |
| 242 | { |
| 243 | ft_cpu_setup (blob, bd); |
Heiko Schocher | 875f4728 | 2009-07-09 12:04:18 +0200 | [diff] [blame] | 244 | ft_blob_update (blob, bd); |
Heiko Schocher | 3f8dcb5 | 2008-11-20 09:57:47 +0100 | [diff] [blame] | 245 | } |
| 246 | #endif |
Heiko Schocher | 4674318 | 2009-02-24 11:30:34 +0100 | [diff] [blame] | 247 | |
| 248 | #if defined(CONFIG_HUSH_INIT_VAR) |
| 249 | extern int ivm_read_eeprom (void); |
| 250 | int hush_init_var (void) |
| 251 | { |
| 252 | ivm_read_eeprom (); |
| 253 | return 0; |
| 254 | } |
| 255 | #endif |